Skip to content

Commit

Permalink
Try to only float a single copy of a definition
Browse files Browse the repository at this point in the history
  • Loading branch information
dolio committed Nov 9, 2021
1 parent 9b40a29 commit 1b6bbae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions parser-typechecker/src/Unison/Runtime/ANF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,16 @@ lamFloater
:: (Var v, Monoid a)
=> Bool -> Term v a -> Maybe v -> a -> [v] -> Term v a -> FloatM v a v
lamFloater closed tm mv a vs bd
= state $ \(cvs, ctx, dcmp) ->
let v = ABT.freshIn cvs $ fromMaybe (typed Var.Float) mv
in (v, ( Set.insert v cvs
, ctx <> [(v, lam' a vs bd)]
, floatDecomp closed v tm dcmp))
= state $ \trip@(cvs, ctx, dcmp) -> case find p ctx of
Just (v, _) -> (v, trip)
Nothing ->
let v = ABT.freshIn cvs $ fromMaybe (typed Var.Float) mv
in (v, ( Set.insert v cvs
, ctx <> [(v, lam' a vs bd)]
, floatDecomp closed v tm dcmp))
where
tgt = unannotate (lam' a vs bd)
p (_, flam) = unannotate flam == tgt

floatDecomp
:: Bool -> v -> Term v a -> [(v, Term v a)] -> [(v, Term v a)]
Expand Down
3 changes: 2 additions & 1 deletion unison-src/transcripts/bug-strange-closure.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,8 @@ rendered = Pretty.get (docFormatConsole doc.guide)
1
(Term.Term
(Any
'(x ->
(_
x ->
sqr
x))))),
!Lit
Expand Down

0 comments on commit 1b6bbae

Please sign in to comment.