Drop the unused init@ field from classes with a self identifier
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- fsharp, javascript, python
- Ambito
- compilers
Direzione di ricerca
Start by tracing how Fable represents class fields and constructor parameters in its AST, then follow the code that emits the init@ field for JavaScript and Python. Check the constructor handling described in #5235, including how precompiled classes signal a self identifier. Done means the unused field, parameter, argument, and assignment are omitted from generated output while that signal remains available.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
F# adds a hidden init@<line> field to a class whose constructor has a self identifier (type P() as this or new () as self). .NET uses it to throw InvalidOperationException when this is used before the object is fully initialised. The check is a FailInit() call inside the member bodies, so M throws when called from P's constructor:
type P() as this =
let x = this.M()
member _.M() = 1
member _.X = x
Fable emits the field and sets it, but never reads it. The typed tree Fable gets from FCS doesn't contain the FailInit() check, so there is nothing to translate. On JS:
export class P {
constructor() {
const this$ = new FSharpRef(defaultOf());
this$.contents = this;
this.x = (P__M(this$.contents) | 0);
this["init@3"] = 1;
}
}
export function P__M(_) {
return 1;
}
With an explicit constructor (#5235), the field is also a constructor parameter:
export class E {
constructor(Count, init$00408$002D1) {
this.Count = (Count | 0);
this["init@8-1"] = (init$00408$002D1 | 0);
}
}
export function E_$ctor_Z524259A4(a) {
const self = new FSharpRef(defaultOf());
let this$_1;
const this$ = new E(a, 0);
self.contents = this$;
this$["init@8-1"] = 1;
// ...
}
Python emits the same shape (self.init_004039 = init_004039).
Since Fable can't use the field, we could drop it from the output: the class fields, the constructor parameter, the argument in the record construction and the Set. That saves a property per object and a write per construction.
Something to check when doing it: #5235 uses the init@ field of a precompiled class to detect that its constructor has a self identifier, because precompiled libraries don't keep constructor bodies. Removing it from the Fable AST must not remove that signal.
- Lingua principale
- F#
- Stelle
- 3.2k
- Fork
- 335
- Merge medio
- 19h 39m
- PR unite (30g)
- 158
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fable-compiler/Fable
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
fable-compiler/Fable#5280 ·
I maintainer di solito rispondono entro 1 giorno
-
agentic-workflows automation repo-assist
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
fable-compiler/Fable#4531 ·
I maintainer di solito rispondono entro 1 giorno
-
agentic-workflows automation repo-assist
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
fable-compiler/Fable#4522 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
fable-compiler/Fable#5286 ·
I maintainer di solito rispondono entro 1 giorno
-
for loop bound still differs from .NET for reassigned mutable arraysForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 36/100
fable-compiler/Fable#5285 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di fable-compiler/Fable
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
tree-sitter/tree-sitter-cpp#381 ·
-
[P2] Interpreter: Array.prototype.findLastIndex starts at the wrong index for long array-likesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
new issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
llvm/llvm-project#240065 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
CanadaHonk/porffor#452 ·