Skip to content

Commit 20a11a7

Browse files
Replace eq type dicts with undefined. Fix #1058
1 parent ae3dd64 commit 20a11a7

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
* [#1034](https://github.com/clash-lang/clash-compiler/issues/1034): Error (10137): object "pllLock" on lhs must have a variable data type
8787
* [#1046](https://github.com/clash-lang/clash-compiler/issues/1046): Don't confuse term/type namespaces in 'lookupIdSubst'
8888
* [#1041](https://github.com/clash-lang/clash-compiler/issues/1041): Nested product types incorrectly decomposed into ports
89+
* [#1058](https://github.com/clash-lang/clash-compiler/issues/1058): Prevent substitution warning when using type equalities in top entities
8990

9091
* Fixes without issue reports:
9192
* Fix bug in `rnfX` defined for `Down` ([baef30e](https://github.com/clash-lang/clash-compiler/commit/baef30eae03dc02ba847ffbb8fae7f365c5287c2))

clash-lib/src/Clash/Normalize/Util.hs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import Data.Bifunctor (bimap)
3737
import Data.Either (lefts)
3838
import qualified Data.List as List
3939
import qualified Data.Map as Map
40+
import Data.Maybe (fromMaybe)
4041
import qualified Data.HashMap.Strict as HashMapS
4142
import Data.Text (Text)
4243
import qualified Data.Text as Text
@@ -51,7 +52,7 @@ import Clash.Core.FreeVars
5152
import Clash.Core.Name (Name(nameOcc,nameUniq))
5253
import Clash.Core.Pretty (showPpr)
5354
import Clash.Core.Subst
54-
(deShadowTerm, extendTvSubstList, mkSubst, substTm)
55+
(deShadowTerm, extendTvSubstList, mkSubst, substTm, extendIdSubstList)
5556
import Clash.Core.Term
5657
(Context, CoreContext(AppArg), PrimInfo (..), Term (..), WorkInfo (..),
5758
TickInfo(NameMod), NameMod(PrefixName), collectArgs, collectArgsTicks)
@@ -407,7 +408,7 @@ normalizeTopLvlBndr isTop nm (nm',sp,inl,tm) = makeCachedU nm (extra.normalized)
407408
-- into a loop. Deshadowing freshens all the bindings
408409
-- to avoid this.
409410
let tm1 = deShadowTerm emptyInScopeSet tm
410-
tm2 = if isTop then substWithTyEq [] [] tm1 else tm1
411+
tm2 = if isTop then fromMaybe tm1 (substWithTyEq [] [] [] tm1) else tm1
411412
old <- Lens.use curFun
412413
tm3 <- rewriteExpr ("normalization",normalization) (nmS,tm2) (nm',sp)
413414
curFun .= old
@@ -428,18 +429,24 @@ normalizeTopLvlBndr isTop nm (nm',sp,inl,tm) = makeCachedU nm (extra.normalized)
428429
substWithTyEq
429430
:: [TyVar]
430431
-> [(TyVar,Type)]
432+
-> [Id]
431433
-> Term
432-
-> Term
433-
substWithTyEq tvs cvs (TyLam tv e) = substWithTyEq (tv:tvs) cvs e
434-
substWithTyEq tvs cvs (Lam v e)
434+
-> Maybe Term
435+
-- ^ 'Nothing' if 'substWithTyEq' didn't have to substitute anything
436+
substWithTyEq tvs cvs ids_ (TyLam tv e) = substWithTyEq (tv:tvs) cvs ids_ e
437+
substWithTyEq tvs cvs ids_ (Lam v e)
435438
| TyConApp (nameUniq -> tcUniq) [_,VarTy tv, ty] <- tyView (varType v)
436439
, tcUniq == getKey eqTyConKey
437440
, tv `elem` tvs
438-
= substWithTyEq (tvs List.\\ [tv]) ((tv,ty):cvs) e
439-
substWithTyEq tvs cvs@(_:_) e =
440-
let e1 = List.foldl' (flip TyLam) e tvs
441-
in substTm "substWithTyEq" (extendTvSubstList (mkSubst emptyInScopeSet) cvs) e1
442-
substWithTyEq tvs _ e = List.foldl' (flip TyLam) e tvs
441+
= substWithTyEq (tvs List.\\ [tv]) ((tv,ty):cvs) (v:ids_) e
442+
substWithTyEq tvs cvs@(_:_) ids_ e =
443+
let
444+
e1 = List.foldl' (flip TyLam) e tvs
445+
subst0 = extendTvSubstList (mkSubst emptyInScopeSet) cvs
446+
subst1 = extendIdSubstList subst0 [(v, removedTm (varType v)) | v <- ids_]
447+
in
448+
Just (substTm "substWithTyEq" subst1 e1)
449+
substWithTyEq _ _ _ _ = Nothing
443450

444451
-- | Rewrite a term according to the provided transformation
445452
rewriteExpr :: (String,NormRewrite) -- ^ Transformation to apply

0 commit comments

Comments
 (0)