Skip to content

Commit

Permalink
Fix #2124.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas authored and sortraev committed Mar 27, 2024
1 parent 428f148 commit 8a2710c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

* Ignore type suffixes when unifying expressions (#2124).

## [0.25.14]

### Added
Expand Down
12 changes: 10 additions & 2 deletions src/Language/Futhark/Prop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,12 +1376,20 @@ similarSlices slice1 slice2

-- | If these two expressions are structurally similar at top level as
-- sizes, produce their subexpressions (which are not necessarily
-- similar, but you can check for that!). This is the machinery
-- underlying expresssion unification.
-- similar, but you can check for that!). This is the machinery
-- underlying expresssion unification. We assume that the expressions
-- have the same type.
similarExps :: Exp -> Exp -> Maybe [(Exp, Exp)]
similarExps e1 e2 | bareExp e1 == bareExp e2 = Just []
similarExps e1 e2 | Just e1' <- stripExp e1 = similarExps e1' e2
similarExps e1 e2 | Just e2' <- stripExp e2 = similarExps e1 e2'
similarExps (IntLit x _ _) (Literal v _) =
case v of
SignedValue (Int8Value y) | x == toInteger y -> Just []
SignedValue (Int16Value y) | x == toInteger y -> Just []
SignedValue (Int32Value y) | x == toInteger y -> Just []
SignedValue (Int64Value y) | x == toInteger y -> Just []
_ -> Nothing
similarExps
(AppExp (BinOp (op1, _) _ (x1, _) (y1, _) _) _)
(AppExp (BinOp (op2, _) _ (x2, _) (y2, _) _) _)
Expand Down
4 changes: 3 additions & 1 deletion src/Language/Futhark/TypeChecker/Unify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,10 @@ newDimOnMismatch loc t1 t2 = do
pure (t, M.elems seen)
where
r = RigidCond t1 t2
same (e1, e2) =
maybe False (all same) $ similarExps e1 e2
onDims _ d1 d2
| d1 == d2 = pure d1
| same (d1, d2) = pure d1
| otherwise = do
-- Remember mismatches we have seen before and reuse the
-- same new size.
Expand Down
5 changes: 5 additions & 0 deletions tests/issue2124.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Ignore suffixes when computing differences when possible.

def main b : [10]i64 =
if b then iota 10 : [10]i64
else iota 10i64 : [10]i64

0 comments on commit 8a2710c

Please sign in to comment.