Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit 870b910

Browse files
committed
Correctly refresh the SAT inner worker
This is a little over-eager, but it's good enough Cherry-picked from #265 in order to fix #264
1 parent f260af5 commit 870b910

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/Core/Optimise/SAT.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import Data.Semigroup
6060
import Data.Maybe
6161
import Data.List
6262

63-
6463
-- | Do the static argument transformation on a whole program.
6564
staticArgsPass :: (MonadNamey m, IsVar a) => [Stmt a] -> m [Stmt a]
6665
staticArgsPass = traverse staticArg_stmt
@@ -174,13 +173,13 @@ doStaticArgs the_func the_type the_body =
174173
mkShadow worker =
175174
let go_dynamic args = do
176175
inside <- mkApps (Ref worker worker_ty) worker_ty args
177-
pure $ foldr Lam inside args
176+
refresh $ foldr Lam inside args
178177

179178
go (Static (TypeArgument _ k):xs) = do
180-
x <- fromVar . mkTyvar <$> genName
179+
x <- fresh' TypeVar
181180
Lam (TypeArgument x k) <$> go xs
182181
go (Static (TermArgument _ k):xs) = do
183-
x <- fromVar . mkVal <$> genName
182+
x <- fresh' ValueVar
184183
Lam (TermArgument x k) <$> go xs
185184
go [] = go_dynamic non_static_bndrs
186185
go _ = error "NonStatic binder in static_binders"
@@ -229,11 +228,11 @@ isStatic _ _ = NonStatic
229228
mkApps :: forall a m. (IsVar a, MonadNamey m) => Atom -> Type -> [Argument a] -> m (Term a)
230229
mkApps at _ [] = pure $ Atom at
231230
mkApps at (ForallTy Irrelevant _ t) (TermArgument x tau:xs) = do
232-
this_app <- fromVar . mkVal <$> genName
231+
this_app <- fresh' ValueVar
233232
Let (One (this_app, t, App at (Ref (toVar x) tau))) <$>
234233
mkApps (Ref (toVar this_app) t) t xs
235234
mkApps at (ForallTy r _ t) (TypeArgument v _:xs) = do
236-
this_app <- fromVar . mkVal <$> genName
235+
this_app <- fresh' ValueVar
237236
let t' =
238237
case r of
239238
Relevant binder -> substituteInType (VarMap.singleton binder (VarTy (toVar v))) t

tests/lua/opt_sat_inline.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
do
2+
local E = { __tag = "E" }
3+
local function foldr_sat(zero, x)
4+
if x.__tag ~= "T" then return zero end
5+
local tmp = x[1]
6+
local tmp0 = tmp._2._2
7+
return foldr_sat(tmp._1 + foldr_sat(zero, tmp0._2), tmp0._1)
8+
end
9+
foldr_sat(0, E)
10+
end

tests/lua/opt_sat_inline.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
external val (+) : int -> int -> int = "function(x, y) return x + y end"
2+
3+
type sz_tree 'a =
4+
| E
5+
| T of 'a * int * sz_tree 'a * sz_tree 'a
6+
7+
let rec foldr f zero = function
8+
| E -> zero
9+
| T (x, _, l, r) -> foldr f (f x (foldr f zero r)) l
10+
11+
let _ = foldr (+) 0 E

0 commit comments

Comments
 (0)