Captured-variable assignment produces invalid Hull when not constant-folded

Aperta
#626 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
haskell
Ambito
compilers

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, x is 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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di argotorg/solcore

Tutte le issue di argotorg/solcore

Issue simili

Altre issue su Haskell

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.