Skip to content

Commit 61a9ebf

Browse files
committed
ast_types: fix possible memory leak with TAstDiag
Summary ======= Fix a compiler memory leak involving diagnostics. Only long running processes, such as `nimsuggest`, were affected to a significant degree. Details ======= While diagnostics mustn't hold a tree directly holding a reference to the diagnostic itself (which is the assumption the decision to use `TAstDiag` as `.acyclic` was based on), it's possible (and valid) for a diagnostic to contain a tree that holds a reference to a symbol, which in turn holds a reference to the tree containing the diagnostic (a reference cycle). Due to the `.acyclic` marker on `TAstDiag`, all reference cycles in which a `TAstDiag` is a contributor were never freed. The `.acyclic` marker is removed, fixing the problem.
1 parent efa5d09 commit 61a9ebf

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

compiler/ast/ast_types.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,9 +1278,7 @@ type
12781278
adSemDeprecatedCompilerOptArg # warning promoted to error
12791279

12801280
PAstDiag* = ref TAstDiag
1281-
TAstDiag* {.acyclic.} = object
1282-
## A diagnostic must never store a tree that references the diagnostic
1283-
## itself.
1281+
TAstDiag* = object
12841282
# xxx: consider splitting storage type vs message
12851283
# xxx: consider breaking up diag into smaller types
12861284
# xxx: try to shrink the int/int128 etc types for counts/ordinals

0 commit comments

Comments
 (0)