Rename type synonyms properly.

This commit is contained in:
Iavor Diatchki 2017-12-01 10:29:42 -08:00
parent 3443331f06
commit 2272a59314
7 changed files with 48 additions and 8 deletions

View File

@ -43,9 +43,13 @@ instantiateModule func newName tpMap vpMap =
env <- computeEnv func tpMap vpNames
let renamedExports = inst env (mExports func)
renamedTySyns = fmap (inst env) (mTySyns func)
renamedNewtypes = fmap (inst env) (mNewtypes func)
let rnMp :: Inst a => (a -> Name) -> Map Name a -> Map Name a
rnMp f m = Map.fromList [ (f x, x) | a <- Map.elems m
, let x = inst env a ]
renamedExports = inst env (mExports func)
renamedTySyns = rnMp tsName (mTySyns func)
renamedNewtypes = rnMp ntName (mNewtypes func)
su = listSubst
[ (TVBound tp, t) | (tp,t) <- Map.toList (tyParamMap env) ]
@ -256,7 +260,7 @@ instance Inst (ExportSpec Name) where
instV x = Map.findWithDefault x x (funNameMap env)
instance Inst TySyn where
inst env ts = TySyn { tsName = Map.findWithDefault x x (tyNameMap env)
inst env ts = TySyn { tsName = instTyName env x
, tsParams = tsParams ts
, tsConstraints = inst env (tsConstraints ts)
, tsDef = inst env (tsDef ts)
@ -265,7 +269,7 @@ instance Inst TySyn where
where x = tsName ts
instance Inst Newtype where
inst env nt = Newtype { ntName = Map.findWithDefault x x (tyNameMap env)
inst env nt = Newtype { ntName = instTyName env x
, ntParams = ntParams nt
, ntConstraints = inst env (ntConstraints nt)
, ntFields = [ (f,inst env t) | (f,t) <- ntFields nt ]
@ -273,7 +277,8 @@ instance Inst Newtype where
}
where x = ntName nt
instTyName :: Env -> Name -> Name
instTyName env x = Map.findWithDefault x x (tyNameMap env)

View File

@ -36,8 +36,8 @@ checkModuleInstance func inst =
-- the full dependencies, the actual imports
-- might be ambiguous, but that shouldn't
-- matters as names have been already resolved
, mTySyns = Map.union (mTySyns inst) (mTySyns m)
, mNewtypes = Map.union (mNewtypes inst) (mNewtypes m)
, mTySyns = Map.union (mTySyns inst) (mTySyns m)
, mNewtypes = Map.union (mNewtypes inst) (mNewtypes m)
, mParamTypes = mParamTypes inst
, mParamConstraints = mParamConstraints inst
, mParamFuns = mParamFuns inst

1
tests/modsys/T13.icry Normal file
View File

@ -0,0 +1 @@
:module T13::Main

View File

@ -0,0 +1,4 @@
Loading module Cryptol
Loading module T13::A
Loading module T13::B
Loading module T13::Main

11
tests/modsys/T13/A.cry Normal file
View File

@ -0,0 +1,11 @@
module T13::A where
parameter
type T : #
type constraint (2 >= T)
f : [8] -> [8]
type X = T + 1
g = f

13
tests/modsys/T13/B.cry Normal file
View File

@ -0,0 +1,13 @@
module T13::B = T13::A where
/*
parameter
type T : #
type constraint (2 >= T)
*/
type T = 1
f x = x

View File

@ -0,0 +1,6 @@
module T13::Main where
import T13::B
h : [X]
h = zero