Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2067. #2072

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Somewhat obscure simplification error caused by neglecting to update
metadata when removing dead scatter outputs.

* Compiler crash due to the type checker forgetting to respect the
explicitly ascribed non-consuming diet of loop parameters (#2067).

## [0.25.11]

### Added
Expand Down
11 changes: 6 additions & 5 deletions src/Language/Futhark/TypeChecker/Consumption.hs
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,9 @@ boundFreeInExp e = do
-- functions.
type Loop = (Pat ParamType, Exp, LoopFormBase Info VName, Exp)

-- | Mark bindings of consumed names as Consume.
updateParamDiet :: Names -> Pat ParamType -> Pat ParamType
-- | Mark bindings of consumed names as Consume, except those under a
-- 'PatAscription', which are left unchanged.
updateParamDiet :: (VName -> Bool) -> Pat ParamType -> Pat ParamType
updateParamDiet cons = recurse
where
recurse (Wildcard (Info t) wloc) =
Expand All @@ -568,7 +569,7 @@ updateParamDiet cons = recurse
recurse (PatAttr attr p ploc) =
PatAttr attr (recurse p) ploc
recurse (Id name (Info t) iloc)
| name `S.member` cons =
| cons name =
let t' = t `setUniqueness` Consume
in Id name (Info t') iloc
| otherwise =
Expand All @@ -587,7 +588,7 @@ updateParamDiet cons = recurse
convergeLoopParam :: Loc -> Pat ParamType -> Names -> TypeAliases -> CheckM (Pat ParamType)
convergeLoopParam loop_loc param body_cons body_als = do
let -- Make the pattern Consume where needed.
param' = updateParamDiet (S.filter (`elem` patNames param) body_cons) param
param' = updateParamDiet (`S.member` S.filter (`elem` patNames param) body_cons) param

-- Check that the new values of consumed merge parameters do not
-- alias something bound outside the loop, AND that anything
Expand Down Expand Up @@ -653,7 +654,7 @@ checkLoop loop_loc (param, arg, form, body) = do
-- use to infer the proper diet of the parameter.
((body', body_cons), body_als) <-
noConsumable
. bindingParam (fmap (second (const Consume)) param)
. bindingParam (updateParamDiet (const True) param)
. bindingLoopForm form'
$ do
((body', body_als), body_cons) <- contain $ checkExp body
Expand Down
7 changes: 7 additions & 0 deletions tests/uniqueness/uniqueness-error65.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- From #2067.
-- ==
-- error: "xs".*not consumable

def main (xs: *[]i32) =
loop xs : []i32 for i < 10 do
xs with [i] = i+1