Skip to content

Commit

Permalink
Increment level for each function parameter.
Browse files Browse the repository at this point in the history
This addresses a *really* obscure bug related to inferring parameters
of the form

  (A: [length A]t)

which can cause type normalisation to go into an infinite loop in some
cases (because of the type annotation on the 'A' variable).
  • Loading branch information
athas committed Dec 5, 2023
1 parent 545114c commit bf57ad9
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Language/Futhark/TypeChecker/Terms.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ letGeneralise defname defloc tparams params restype =
let keep_type_vars = overloadedTypeVars now_substs

cur_lvl <- curLevel
let candidate k (lvl, _) = (k `S.notMember` keep_type_vars) && lvl >= cur_lvl
let candidate k (lvl, _) = (k `S.notMember` keep_type_vars) && lvl >= (cur_lvl - length params)
new_substs = M.filterWithKey candidate now_substs

(tparams', RetType ret_dims restype') <-
Expand Down
2 changes: 1 addition & 1 deletion src/Language/Futhark/TypeChecker/Terms/Pat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ bindingParams tps orig_ps m = do
checkTypeParams tps $ \tps' -> bindingTypeParams tps' $ do
let descend ps' (p : ps) =
checkPat [] p NoneInferred $ \p' ->
binding (patIdents $ fmap toStruct p') $ descend (p' : ps') ps
binding (patIdents $ fmap toStruct p') $ incLevel $ descend (p' : ps') ps
descend ps' [] = m tps' $ reverse ps'

descend [] orig_ps
2 changes: 1 addition & 1 deletion tests/shapes/funshape2.fut
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- ==
-- error: Causality check
-- error: scope violation

def main xs = (\f' -> f' (filter (>0) xs)) (\_ -> 0)
2 changes: 1 addition & 1 deletion tests/shapes/size-inference4.fut
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
-- parameter. Written in a convoluted way to ensure this is checked
-- even for lambdas that are never let-generalised.
-- ==
-- error: refers to size "n"
-- error: scope violation

def f : i32 = const 2 ((\xs n -> (zip xs (iota n) : [](i64, i64))))
2 changes: 1 addition & 1 deletion tests/shapes/size-inference5.fut
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Like size-inference4.fut, but with a let-binding.
-- ==
-- error: refers to size "n"
-- error: scope violation

def f xs n = zip xs (iota n)

0 comments on commit bf57ad9

Please sign in to comment.