Consider two variables. One is a term variable:
termVar :: Var Term
termVar = Id {
varName = fakeName {nameUniq=unique, nameOcc="term"}
, varUniq = unique
, varType = ConstTy (TyCon fakeName)
, idScope = LocalId
}
and the other a type variable
typeVar :: Var Type
typeVar = TyVar {
varName = fakeName {nameUniq=unique, nameOcc="type"}
, varUniq = unique
, varType = ConstTy (TyCon fakeName)
}
We'd expect that deshadowing Var termVar with an inScopeSet of just typeVar should be a no-op, as their uniques live in different name spaces. (In fact, it's not even possible to have both termVar and typeVar in an InScopeSet, as it only stores uniques!). deShadowTerm currently behaves differently though:
>>> deShadowTerm (extendInScopeSet emptyInScopeSet typeVar) (Var termVar)
Var (TyVar {varName = Name {nameSort = User, nameOcc = "type", nameUniq = 20, nameLoc = UnhelpfulSpan "<no location info>"}, varUniq = 20, varType = ConstTy (TyCon (Name {nameSort = User, nameOcc = "fake", nameUniq = 0, nameLoc = UnhelpfulSpan "<no location info>"}))})
instead of:
>>> deShadowTerm (extendInScopeSet emptyInScopeSet typeVar) (Var termVar)
Var (Id {varName = Name {nameSort = User, nameOcc = "term", nameUniq = 20, nameLoc = UnhelpfulSpan "<no location info>"}, varUniq = 20, varType = ConstTy (TyCon (Name {nameSort = User, nameOcc = "fake", nameUniq = 0, nameLoc = UnhelpfulSpan "<no location info>"})), idScope = LocalId})
The culprit seems to be anti space-leak measures in lookupIdSubst:
|
| Just v' <- lookupInScope inScope v = Var (coerce v') |
It should refuse to substitute TyVars with Ids.
Consider two variables. One is a term variable:
and the other a type variable
We'd expect that deshadowing
Var termVarwith aninScopeSetof justtypeVarshould be a no-op, as their uniques live in different name spaces. (In fact, it's not even possible to have bothtermVarandtypeVarin an InScopeSet, as it only stores uniques!).deShadowTermcurrently behaves differently though:instead of:
The culprit seems to be anti space-leak measures in
lookupIdSubst:clash-compiler/clash-lib/src/Clash/Core/Subst.hs
Line 512 in a009fe4
It should refuse to substitute
TyVars withIds.