@@ -25,6 +25,7 @@ import Language.PureScript.AST
25import Language.PureScript.Crash
25import Language.PureScript.Crash
26import Language.PureScript.Errors
26import Language.PureScript.Errors
27import Language.PureScript.Externs
27import Language.PureScript.Externs
28+import Language.PureScript.Kinds
28import Language.PureScript.Linter.Imports
29import Language.PureScript.Linter.Imports
29import Language.PureScript.Names
30import Language.PureScript.Names
30import Language.PureScript.Sugar.Names.Env
31import Language.PureScript.Sugar.Names.Env
@@ -98,6 +99,9 @@ desugarImportsWithEnv externs modules = do
98 exportedRefs :: Ord a => (DeclarationRef -> Maybe a) -> M.Map a ModuleName
99 exportedRefs :: Ord a => (DeclarationRef -> Maybe a) -> M.Map a ModuleName
99 exportedRefs f = M.fromList $ (, efModuleName) <$> mapMaybe f efExports
100 exportedRefs f = M.fromList $ (, efModuleName) <$> mapMaybe f efExports
102+ exportedKinds :: M.Map (ProperName 'KindName) ModuleName
103+ exportedKinds = exportedRefs getKindRef
101 updateEnv :: ([Module], Env) -> Module -> m ([Module], Env)
105 updateEnv :: ([Module], Env) -> Module -> m ([Module], Env)
102 updateEnv (ms, env) m@(Module ss _ mn _ refs) = do
106 updateEnv (ms, env) m@(Module ss _ mn _ refs) = do
103 members <- findExportable m
107 members <- findExportable m
@@ -128,6 +132,7 @@ elaborateExports exps (Module ss coms mn decls refs) =
128 ++ go TypeClassRef exportedTypeClasses
132 ++ go TypeClassRef exportedTypeClasses
129 ++ go ValueRef exportedValues
133 ++ go ValueRef exportedValues
130 ++ go ValueOpRef exportedValueOps
134 ++ go ValueOpRef exportedValueOps
135+ ++ go KindRef exportedKinds
131 ++ maybe [] (filter isModuleRef) refs
136 ++ maybe [] (filter isModuleRef) refs
@@ -165,17 +170,24 @@ renameInModule imports (Module ss coms mn decls exps) =
165 updateDecl (_, bound) d@(PositionedDeclaration pos _ _) =
170 updateDecl (_, bound) d@(PositionedDeclaration pos _ _) =
166 return ((Just pos, bound), d)
171 return ((Just pos, bound), d)
167 updateDecl (pos, bound) (DataDeclaration dtype name args dctors) =
172 updateDecl (pos, bound) (DataDeclaration dtype name args dctors) =
173+ (,) (pos, bound) <$> (DataDeclaration dtype name <$> updateTypeArguments pos args
168− (,) (pos, bound) <$> (DataDeclaration dtype name args <$> traverse (sndM (traverse (updateTypesEverywhere pos))) dctors)
174+ <*> traverse (sndM (traverse (updateTypesEverywhere pos))) dctors)
169 updateDecl (pos, bound) (TypeSynonymDeclaration name ps ty) =
175 updateDecl (pos, bound) (TypeSynonymDeclaration name ps ty) =
170− (,) (pos, bound) <$> (TypeSynonymDeclaration name ps <$> updateTypesEverywhere pos ty)
176+ (,) (pos, bound) <$> (TypeSynonymDeclaration name <$> updateTypeArguments pos ps
177+ <*> updateTypesEverywhere pos ty)
171 updateDecl (pos, bound) (TypeClassDeclaration className args implies deps ds) =
178 updateDecl (pos, bound) (TypeClassDeclaration className args implies deps ds) =
172− (,) (pos, bound) <$> (TypeClassDeclaration className args <$> updateConstraints pos implies <*> pure deps <*> pure ds)
179+ (,) (pos, bound) <$> (TypeClassDeclaration className <$> updateTypeArguments pos args
180+ <*> updateConstraints pos implies
173 updateDecl (pos, bound) (TypeInstanceDeclaration name cs cn ts ds) =
183 updateDecl (pos, bound) (TypeInstanceDeclaration name cs cn ts ds) =
174 (,) (pos, bound) <$> (TypeInstanceDeclaration name <$> updateConstraints pos cs <*> updateClassName cn pos <*> traverse (updateTypesEverywhere pos) ts <*> pure ds)
184 (,) (pos, bound) <$> (TypeInstanceDeclaration name <$> updateConstraints pos cs <*> updateClassName cn pos <*> traverse (updateTypesEverywhere pos) ts <*> pure ds)
175 updateDecl (pos, bound) (TypeDeclaration name ty) =
185 updateDecl (pos, bound) (TypeDeclaration name ty) =
176 (,) (pos, bound) <$> (TypeDeclaration name <$> updateTypesEverywhere pos ty)
186 (,) (pos, bound) <$> (TypeDeclaration name <$> updateTypesEverywhere pos ty)
177 updateDecl (pos, bound) (ExternDeclaration name ty) =
187 updateDecl (pos, bound) (ExternDeclaration name ty) =
178 (,) (pos, name : bound) <$> (ExternDeclaration name <$> updateTypesEverywhere pos ty)
188 (,) (pos, name : bound) <$> (ExternDeclaration name <$> updateTypesEverywhere pos ty)
189+ updateDecl (pos, bound) (ExternDataDeclaration name ki) =
190+ (,) (pos, bound) <$> (ExternDataDeclaration name <$> updateKindsEverywhere pos ki)
179 updateDecl (pos, bound) (TypeFixityDeclaration fixity alias op) =
191 updateDecl (pos, bound) (TypeFixityDeclaration fixity alias op) =
180 (,) (pos, bound) <$> (TypeFixityDeclaration fixity <$> updateTypeName alias pos <*> pure op)
192 (,) (pos, bound) <$> (TypeFixityDeclaration fixity <$> updateTypeName alias pos <*> pure op)
181 updateDecl (pos, bound) (ValueFixityDeclaration fixity (Qualified mn' (Left alias)) op) =
193 updateDecl (pos, bound) (ValueFixityDeclaration fixity (Qualified mn' (Left alias)) op) =
@@ -238,6 +250,19 @@ renameInModule imports (Module ss coms mn decls exps) =
238 letBoundVariable (PositionedDeclaration _ _ d) = letBoundVariable d
250 letBoundVariable (PositionedDeclaration _ _ d) = letBoundVariable d
239 letBoundVariable _ = Nothing
251 letBoundVariable _ = Nothing
253+ updateKindsEverywhere :: Maybe SourceSpan -> Kind -> m Kind
254+ updateKindsEverywhere pos = everywhereOnKindsM updateKind
256+ updateKind :: Kind -> m Kind
257+ updateKind (NamedKind name) = NamedKind <$> updateKindName name pos
258+ updateKind k = return k
261+ :: (Traversable f, Traversable g)
263+ -> f (a, g Kind) -> m (f (a, g Kind))
264+ updateTypeArguments pos = traverse (sndM (traverse (updateKindsEverywhere pos)))
241 updateTypesEverywhere :: Maybe SourceSpan -> Type -> m Type
266 updateTypesEverywhere :: Maybe SourceSpan -> Type -> m Type
242 updateTypesEverywhere pos = everywhereOnTypesM updateType
267 updateTypesEverywhere pos = everywhereOnTypesM updateType
@@ -245,16 +270,17 @@ renameInModule imports (Module ss coms mn decls exps) =
245 updateType (TypeOp name) = TypeOp <$> updateTypeOpName name pos
270 updateType (TypeOp name) = TypeOp <$> updateTypeOpName name pos
246 updateType (TypeConstructor name) = TypeConstructor <$> updateTypeName name pos
271 updateType (TypeConstructor name) = TypeConstructor <$> updateTypeName name pos
247 updateType (ConstrainedType cs t) = ConstrainedType <$> traverse updateInConstraint cs <*> pure t
272 updateType (ConstrainedType cs t) = ConstrainedType <$> traverse updateInConstraint cs <*> pure t
273+ updateType (KindedType t k) = KindedType t <$> updateKindsEverywhere pos k
248 updateType t = return t
274 updateType t = return t
249 updateInConstraint :: Constraint -> m Constraint
275 updateInConstraint :: Constraint -> m Constraint
250 updateInConstraint (Constraint name ts info) =
276 updateInConstraint (Constraint name ts info) =
251 Constraint <$> updateClassName name pos <*> pure ts <*> pure info
277 Constraint <$> updateClassName name pos <*> pure ts <*> pure info
253 updateConstraints :: Maybe SourceSpan -> [Constraint] -> m [Constraint]
279 updateConstraints :: Maybe SourceSpan -> [Constraint] -> m [Constraint]
254− updateConstraints pos = traverse $ \(Constraint name ts info) ->
280+ updateConstraints pos = traverse $ \(Constraint name ts info) ->
255− Constraint
281+ Constraint
256− <$> updateClassName name pos
282+ <$> updateClassName name pos
257− <*> traverse (updateTypesEverywhere pos) ts
283+ <*> traverse (updateTypesEverywhere pos) ts
258 <*> pure info
284 <*> pure info
260 updateTypeName
286 updateTypeName
@@ -290,6 +316,12 @@ renameInModule imports (Module ss coms mn decls exps) =
290 -> m (Qualified (OpName 'ValueOpName))
316 -> m (Qualified (OpName 'ValueOpName))
291 updateValueOpName = update (importedValueOps imports) ValOpName
317 updateValueOpName = update (importedValueOps imports) ValOpName
320+ :: Qualified (ProperName 'KindName)
322+ -> m (Qualified (ProperName 'KindName))
323+ updateKindName = update (importedKinds imports) KiName
293 -- Update names so unqualified references become qualified, and locally
325 -- Update names so unqualified references become qualified, and locally
294 -- qualified references are replaced with their canoncial qualified names
326 -- qualified references are replaced with their canoncial qualified names
295 -- (e.g. M.Map -> Data.Map.Map).
327 -- (e.g. M.Map -> Data.Map.Map).