diff --git a/src/ArrayTemplates.hs b/src/ArrayTemplates.hs index ce91e30e..dd5c0fa3 100644 --- a/src/ArrayTemplates.hs +++ b/src/ArrayTemplates.hs @@ -103,8 +103,9 @@ templateEFilter = defineTypeParameterizedTemplate templateCreator path t docs _ -> declaration " ((($a*)a.data)[insertIndex++]) = (($a*)a.data)[i];" deleteCall ) ) - ( \(FuncTy [RefTy ft@(FuncTy fArgTys@[RefTy _ _] BoolTy _) _, _] _ _) -> + ( \(FuncTy [RefTy ft@(FuncTy fArgTys@[RefTy insideType _] BoolTy _) _, _] _ _) -> [defineFunctionTypeAlias ft, defineFunctionTypeAlias (FuncTy (lambdaEnvTy : fArgTys) BoolTy StaticLifetimeTy)] + ++ depsForDeleteFunc typeEnv env insideType ) templatePushBack :: (String, Binder) @@ -329,7 +330,9 @@ templateAset = defineTypeParameterizedTemplate templateCreator path t docs "}" ] ) - (const []) + ( \(FuncTy [_, _, insideTy] _ _) -> + depsForDeleteFunc typeEnv env insideTy + ) templateAsetBang :: (String, Binder) templateAsetBang = defineTypeParameterizedTemplate templateCreator path t docs @@ -361,7 +364,9 @@ templateAsetBang = defineTypeParameterizedTemplate templateCreator path t docs "}" ] ) - (const []) + ( \(FuncTy [RefTy arrayType _, _, _] _ _) -> + depsForDeleteFunc typeEnv env arrayType + ) -- | This function can set uninitialized memory in an array (used together with 'allocate'). -- | It will NOT try to free the value that is already at location 'n'. @@ -402,12 +407,14 @@ templateLength = defineTypeParameterizedTemplate templateCreator path t docs t = FuncTy [RefTy (StructTy (ConcreteNameTy (SymPath [] "Array")) [VarTy "t"]) (VarTy "q")] IntTy StaticLifetimeTy docs = "gets the length of the array." templateCreator = TemplateCreator $ - \_ _ -> + \typeEnv env -> Template t (const (toTemplate "int $NAME (Array *a)")) (const (toTemplate "$DECL { return (*a).len; }")) - (const []) + ( \(FuncTy [RefTy arrayType _] _ _) -> + depsForDeleteFunc typeEnv env arrayType + ) templateAllocate :: (String, Binder) templateAllocate = defineTypeParameterizedTemplate templateCreator path t docs @@ -416,7 +423,7 @@ templateAllocate = defineTypeParameterizedTemplate templateCreator path t docs t = FuncTy [IntTy] (StructTy (ConcreteNameTy (SymPath [] "Array")) [VarTy "t"]) StaticLifetimeTy docs = "allocates an uninitialized array. You can initialize members using [`aset-uninitialized`](#aset-uninitialized)." templateCreator = TemplateCreator $ - \_ _ -> + \typeEnv env -> Template t (const (toTemplate "Array $NAME (int n)")) @@ -435,7 +442,9 @@ templateAllocate = defineTypeParameterizedTemplate templateCreator path t docs ] ) ) - (const []) + ( \(FuncTy [_] arrayType _) -> + depsForDeleteFunc typeEnv env arrayType + ) templateDeleteArray :: (String, Binder) templateDeleteArray = defineTypeParameterizedTemplate templateCreator path t docs @@ -453,7 +462,9 @@ templateDeleteArray = defineTypeParameterizedTemplate templateCreator path t doc ++ deleteTy typeEnv env arrayType ++ [TokC "}\n"] ) - (const []) + ( \(FuncTy [StructTy (ConcreteNameTy (SymPath [] "Array")) [insideType]] UnitTy _) -> + depsForDeleteFunc typeEnv env insideType + ) deleteTy :: TypeEnv -> Env -> Ty -> [Token] deleteTy typeEnv env (StructTy _ [innerType]) = diff --git a/test/regression.carp b/test/regression.carp index 4eb728a2..6d0ba14f 100644 --- a/test/regression.carp +++ b/test/regression.carp @@ -83,6 +83,11 @@ (deftype (HitRecord a) [t a]) (deftype (CurrentHit a) [hr (Maybe (HitRecord a))]) +;; create dependencies (deleters) for Map when only referring to it with 'the' (issue 1261) +(deftype AType [s String]) +(defn weird [m] + (the (Map String AType) m)) + ;; nested polymorphic types are resolved and emitted (#1293) (defmodule Bar (deftype (Baz a) [it a])