Strict mode is not in fact strict
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Esamina il percorso di riduzione di --strict intorno a happySpecReduce_2 e confrontalo con i costruttori generati HappyAbsSyn_1, HappyAbsSyn_2 e HappyAbsSyn_3. Confronta il comportamento generato con e senza --coerce, quindi controlla la descrizione della modalità strict nella guida utente; il lavoro è completato quando la modalità strict valuta ogni risultato semantico fino al WHNF promesso e la documentazione corrisponde.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Lets look at a typical bit of generated happy code (without using --coerce):
happyReduce_1 = happySpecReduce_2 17 happyReduction_1
happyReduction_1 (HappyAbsSyn_2 happy_var2) (HappyAbsSyn_1 happy_var1) =
HappyAbsSyn_3 (foobar happy_var1 happy_var2)
So the crucial question is: does the result of foobar above get reduced to weak head normal form?
The answer is no. Therefore the title of the issue: this is insufficiently strict.
It's also contrary to what the user guide says.
This option causes the right hand side of each production (the semantic value) to be evaluated eagerly at the moment the production is reduced. If the lazy behaviour is not required, then using this option will improve performance and may reduce space leaks.
Lets see why it is not strict...
happySpecReduce_2 nt fd ... =
let r = fn v1 v2
in happySeq r ...
Ok, so in --strict mode happySeq = seq and so it does reduce fn v1 v2 to WHNF. But what is fn in practice? In the (typical) example above it is
HappyAbsSyn_3 (foobar happy_var1 happy_var2)
which is already in WHNF! So this does nothing. And crucially it does not reduce foobar to WHNF.
Why not? Because HappyAbsSyn_3 itself is a constructor with a single non-strict field:
data HappyAbsSyn t1 t2 t3 = ... | HappyAbsSyn_1 t1 | HappyAbsSyn_2 ts | HappyAbsSyn_3 t3
So perhaps the fix is simple: make the HappyAbsSyn_X constructors have strict fields?
Presumably at some point in happy's history this strict mode did actually do something, but I'm guessing some change later introduced the non-strict HappyAbsSyn constructors and foiled the strictness. Maybe?
On the other hand the --coerce mode, when combined with --strict does look like it will actually be strict. Since in this mode the non-strict HappyAbsSyn_X constructors are replaced by very-much-strict unsafeCoerce# "functions". In one real world parser, comparing --strict --ghc vs --strict --ghc --coerce nets substantial memory reductions. And previously ghc-debug's thunk analysis showed that there were huge numbers of thunks originating from the generated reduction functions.
- Lingua principale
- Haskell
- Stelle
- 323
- Fork
- 88
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la 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 haskell/happy
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
Tutte le issue di haskell/happy
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
haskell/bytestring#730 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
seal-harness/seal-harness#399 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
fmidue/codeworld-tasks#124 ·
-
allow haskell-src-exts-1.24Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
reflex-frp/reflex#563 ·