Skip to content

Commit

Permalink
Workaround for exotic cases of shadowing.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Feb 25, 2025
1 parent c93f301 commit 7818cdc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Futhark/Internalise/Monomorphise.hs
Original file line number Diff line number Diff line change
Expand Up @@ -829,15 +829,27 @@ dimMapping t1 t2 r1 r2 = execState (matchDims onDims t1 t2) mempty
onExps bound e1 e2
pure e1

onExps bound (Var v _ _) e = do
case lookup (qualLeaf v) named1 of
Just rexp -> onExps bound (unReplaced rexp) e
Nothing ->
-- XXX: It is intentional that we throw away the 'bound'
-- information after looking up ExpReplacements, as there are
-- cases (particularly including the function types that occur
-- after lambda lifting) where some troublesome shadowing occurs,
-- and the names are not actually locally bound. We cannot just
-- ignore the bound information entirely, and expect that any
-- instantiation uses only names in scope at the outer level, due
-- to truly exotic cases like entry-lifted.fut, where the real
-- sizes were not visible to the type checker. Arguably that is
-- the thing that should be fixed, but it requires fiddling with
-- the defunctorisation of size-lifted types.

onExps bound (Var v _ _) e
| Just rexp <- lookup (qualLeaf v) named1 =
onExps mempty (unReplaced rexp) e
| otherwise =
unless (any (`elem` bound) $ freeVarsInExp e) $
modify (M.insert (qualLeaf v) e)
onExps bound e (Var v _ _)
onExps _bound e (Var v _ _)
| Just rexp <- lookup (qualLeaf v) named2 =
onExps bound e (unReplaced rexp)
onExps mempty e (unReplaced rexp)
onExps bound e1 e2
| Just es <- similarExps e1 e2 =
mapM_ (uncurry $ onExps bound) es
Expand Down

0 comments on commit 7818cdc

Please sign in to comment.