* Revert "refactor: Remove deps functions in ArrayTemplates (#1093)"

This reverts commit 861ba26f52.

* test: Regression test for issue #1261
This commit is contained in:
Erik Svedäng 2021-09-04 15:07:52 +02:00 committed by GitHub
parent 74d7d5767b
commit d0a98a5065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -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]) =

View File

@ -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])