Skip to content

Commit d0a98a5

Browse files
authored
fix: #1261 (#1272)
* Revert "refactor: Remove deps functions in ArrayTemplates (#1093)" This reverts commit 861ba26. * test: Regression test for issue #1261
1 parent 74d7d57 commit d0a98a5

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/ArrayTemplates.hs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ templateEFilter = defineTypeParameterizedTemplate templateCreator path t docs
103103
_ -> declaration " ((($a*)a.data)[insertIndex++]) = (($a*)a.data)[i];" deleteCall
104104
)
105105
)
106-
( \(FuncTy [RefTy ft@(FuncTy fArgTys@[RefTy _ _] BoolTy _) _, _] _ _) ->
106+
( \(FuncTy [RefTy ft@(FuncTy fArgTys@[RefTy insideType _] BoolTy _) _, _] _ _) ->
107107
[defineFunctionTypeAlias ft, defineFunctionTypeAlias (FuncTy (lambdaEnvTy : fArgTys) BoolTy StaticLifetimeTy)]
108+
++ depsForDeleteFunc typeEnv env insideType
108109
)
109110

110111
templatePushBack :: (String, Binder)
@@ -329,7 +330,9 @@ templateAset = defineTypeParameterizedTemplate templateCreator path t docs
329330
"}"
330331
]
331332
)
332-
(const [])
333+
( \(FuncTy [_, _, insideTy] _ _) ->
334+
depsForDeleteFunc typeEnv env insideTy
335+
)
333336

334337
templateAsetBang :: (String, Binder)
335338
templateAsetBang = defineTypeParameterizedTemplate templateCreator path t docs
@@ -361,7 +364,9 @@ templateAsetBang = defineTypeParameterizedTemplate templateCreator path t docs
361364
"}"
362365
]
363366
)
364-
(const [])
367+
( \(FuncTy [RefTy arrayType _, _, _] _ _) ->
368+
depsForDeleteFunc typeEnv env arrayType
369+
)
365370

366371
-- | This function can set uninitialized memory in an array (used together with 'allocate').
367372
-- | It will NOT try to free the value that is already at location 'n'.
@@ -402,12 +407,14 @@ templateLength = defineTypeParameterizedTemplate templateCreator path t docs
402407
t = FuncTy [RefTy (StructTy (ConcreteNameTy (SymPath [] "Array")) [VarTy "t"]) (VarTy "q")] IntTy StaticLifetimeTy
403408
docs = "gets the length of the array."
404409
templateCreator = TemplateCreator $
405-
\_ _ ->
410+
\typeEnv env ->
406411
Template
407412
t
408413
(const (toTemplate "int $NAME (Array *a)"))
409414
(const (toTemplate "$DECL { return (*a).len; }"))
410-
(const [])
415+
( \(FuncTy [RefTy arrayType _] _ _) ->
416+
depsForDeleteFunc typeEnv env arrayType
417+
)
411418

412419
templateAllocate :: (String, Binder)
413420
templateAllocate = defineTypeParameterizedTemplate templateCreator path t docs
@@ -416,7 +423,7 @@ templateAllocate = defineTypeParameterizedTemplate templateCreator path t docs
416423
t = FuncTy [IntTy] (StructTy (ConcreteNameTy (SymPath [] "Array")) [VarTy "t"]) StaticLifetimeTy
417424
docs = "allocates an uninitialized array. You can initialize members using [`aset-uninitialized`](#aset-uninitialized)."
418425
templateCreator = TemplateCreator $
419-
\_ _ ->
426+
\typeEnv env ->
420427
Template
421428
t
422429
(const (toTemplate "Array $NAME (int n)"))
@@ -435,7 +442,9 @@ templateAllocate = defineTypeParameterizedTemplate templateCreator path t docs
435442
]
436443
)
437444
)
438-
(const [])
445+
( \(FuncTy [_] arrayType _) ->
446+
depsForDeleteFunc typeEnv env arrayType
447+
)
439448

440449
templateDeleteArray :: (String, Binder)
441450
templateDeleteArray = defineTypeParameterizedTemplate templateCreator path t docs
@@ -453,7 +462,9 @@ templateDeleteArray = defineTypeParameterizedTemplate templateCreator path t doc
453462
++ deleteTy typeEnv env arrayType
454463
++ [TokC "}\n"]
455464
)
456-
(const [])
465+
( \(FuncTy [StructTy (ConcreteNameTy (SymPath [] "Array")) [insideType]] UnitTy _) ->
466+
depsForDeleteFunc typeEnv env insideType
467+
)
457468

458469
deleteTy :: TypeEnv -> Env -> Ty -> [Token]
459470
deleteTy typeEnv env (StructTy _ [innerType]) =

test/regression.carp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
(deftype (HitRecord a) [t a])
8484
(deftype (CurrentHit a) [hr (Maybe (HitRecord a))])
8585

86+
;; create dependencies (deleters) for Map when only referring to it with 'the' (issue 1261)
87+
(deftype AType [s String])
88+
(defn weird [m]
89+
(the (Map String AType) m))
90+
8691
;; nested polymorphic types are resolved and emitted (#1293)
8792
(defmodule Bar
8893
(deftype (Baz a) [it a])

0 commit comments

Comments
 (0)