Captured-variable assignment produces invalid Hull when not constant-folded
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 57/100
Direzione di ricerca
Start with the linked Hull emission code in src/Solcore/Backend/EmitHull.hs, especially how captured-variable reads and assignment targets are emitted. Reproduce the failure with the provided CaptureAssignment example, then compare normal partial evaluation with --pe-fuel 0. Done when the compiler emits valid bindings for supported captured-variable assignments or rejects unsupported ones at the source level.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Assigning to a captured variable can produce an invalid Hull when the closure call is not folded to a constant during partial evaluation.
Source:
import * from std;
contract CaptureAssignment {
function main() returns (word) {
let x: word;
assembly { x := calldataload(0) }
let f = lam () -> word {
x = 42;
return x;
};
let result: word = f();
return result + x;
}
}
Result:
sol-core succeeds, but yule fails:
Type error:
Undefined variable: x
The lifted function contains the following, with generated names shortened:
function lambda_impl(env: Closure{word}) -> word {
x := 42
return 42
}
x is captured in env, but the assignment still targets an undeclared x. [Hull emission substitutes captured-variable reads, but emits assignment targets using their original names.](https://github.com/argotorg/solcore/blob/5992f406d77f1a1eef011481bfb6d77bc3b65c6f/src/Solcore/Backend/EmitHull.hs#L350-L386)
Replacing the runtime initializer with let x: word = 41; makes the example compile normally: partial evaluation folds the result to 83, and the lifted function is removed. Adding --pe-fuel 0 exposes the same error again.
The compiler should generate valid bindings for supported assignments, or reject unsupported assignments at the source level. Correctness should not depend on constant folding removing the closure.
Related fixes:
- [#625](https://github.com/argotorg/solcore/pull/625) addresses a different cause: variables referenced only inside assembly are omitted from capture analysis. Here,
xis already captured, and its assignment and read inside the closure are ordinary source statements. The assembly block only supplies runtime input.
- Lingua principale
- Haskell
- Stelle
- 115
- Fork
- 11
- Merge medio
- 20h 29m
- PR unite (30g)
- 2
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
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 argotorg/solcore
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
user feedback: Rename `lam` to `lambda` and give the unit type a nameForse già presa @rodrigogribeiro l’ha presa 50 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 57/100
Tutte le issue di argotorg/solcore
Issue simili
-
Allow QuickCheck 2.17Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
-
15-minutes 5-minutes algorithm any-language beginner-friendly c cpp csharp easy go good first issue hacktoberfest help wanted java javascript kotlin python rust swift typescript
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
Huerte/algo-solutions-python#260 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
IntersectMBO/cardano-ledger#6276 ·
I maintainer di solito rispondono entro 1 giorno