Skip to content

Commit

Permalink
Fix #1960.
Browse files Browse the repository at this point in the history
This is a somewhat hacky fix, in that it crashes the compiler. But
that is better than generating invalid code.
  • Loading branch information
athas committed Nov 10, 2023
1 parent 558c8e3 commit 5d4af4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
`let` bindings, although the type checker will reject any that are
refutable (#2017).

* Avoid generating invalid code in cases where deduplicated sum types
are exposed through entry points (#1960).

## [0.25.7]

### Added
Expand Down
11 changes: 9 additions & 2 deletions src/Futhark/Internalise/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Control.Monad
import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.State
import Data.List (find)
import Data.Map.Strict qualified as M
import Futhark.IR.SOACS
import Futhark.MonadFreshNames
Expand Down Expand Up @@ -137,8 +138,14 @@ lookupSubst v = do
-- | Add opaque types. If the types are already known, they will not
-- be added.
addOpaques :: OpaqueTypes -> InternaliseM ()
addOpaques ts = modify $ \s ->
s {stateTypes = stateTypes s <> ts}
addOpaques ts@(OpaqueTypes ts') = modify $ \s ->
-- TODO: handle this better (#1960)
case find (knownButDifferent (stateTypes s)) ts' of
Just (x, _) -> error $ "addOpaques: multiple incompatible definitions of type " <> nameToString x
Nothing -> s {stateTypes = stateTypes s <> ts}
where
knownButDifferent (OpaqueTypes old_ts) (v, def) =
any (\(v_old, v_def) -> v == v_old && def /= v_def) old_ts

-- | Add a function definition to the program being constructed.
addFunDef :: FunDef SOACS -> InternaliseM ()
Expand Down

0 comments on commit 5d4af4f

Please sign in to comment.