File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,10 @@ class HiddenLibSyntaxAction : public SyntaxParseActions {
61
61
// / been created by the explicit action.
62
62
OpaqueSyntaxNode getLibSyntaxNodeFor (OpaqueSyntaxNode explicitNode);
63
63
64
+ bool isReleaseNeeded () {
65
+ return ExplicitAction == LibSyntaxAction || !areBothLibSyntax ();
66
+ }
67
+
64
68
// / Returns the underlying libSyntax SyntaxTreeCreator.
65
69
std::shared_ptr<SyntaxTreeCreator> getLibSyntaxAction () {
66
70
return LibSyntaxAction;
Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ class LibSyntaxGenerator {
55
55
auto Children = Node.getDeferredChildren ();
56
56
57
57
auto Recorded = Recorder.recordRawSyntax (Kind, Children);
58
- auto Raw = static_cast <RawSyntax *>(Recorded.getOpaqueNode ());
58
+ RC<RawSyntax> Raw {static_cast <RawSyntax *>(Recorded.getOpaqueNode ()) };
59
+ Raw->Release (); // -1 since it's transfer of ownership.
59
60
return make<SyntaxNode>(Raw);
60
61
}
61
62
@@ -68,6 +69,13 @@ class LibSyntaxGenerator {
68
69
auto Raw = static_cast <RawSyntax *>(Actions->getLibSyntaxNodeFor (Node));
69
70
return make<SyntaxNode>(Raw);
70
71
}
72
+
73
+ void releaseLibSyntaxNodeIfNeededFor (OpaqueSyntaxNode Node) {
74
+ if (!Actions->isReleaseNeeded ())
75
+ return ;
76
+ auto Raw = static_cast <RawSyntax *>(Actions->getLibSyntaxNodeFor (Node));
77
+ Raw->Release ();
78
+ }
71
79
};
72
80
} // namespace swift
73
81
Original file line number Diff line number Diff line change @@ -280,6 +280,7 @@ ParsedRawSyntaxNode SyntaxParsingContext::finalizeRoot() {
280
280
return ParsedRawSyntaxNode::null (); // already finalized.
281
281
}
282
282
ParsedRawSyntaxNode root = finalizeSourceFile ();
283
+ getSyntaxCreator ().releaseLibSyntaxNodeIfNeededFor (root.getOpaqueNode ());
283
284
284
285
// Clear the parts because we will call this function again when destroying
285
286
// the root context.
@@ -353,6 +354,10 @@ SyntaxParsingContext::~SyntaxParsingContext() {
353
354
// Remove all parts in this context.
354
355
case AccumulationMode::Discard: {
355
356
auto &nodes = getStorage ();
357
+ for (auto i = nodes.begin ()+Offset, e = nodes.end (); i != e; ++i)
358
+ if (i->isRecorded ())
359
+ getSyntaxCreator ().releaseLibSyntaxNodeIfNeededFor (i->getOpaqueNode ());
360
+
356
361
nodes.erase (nodes.begin ()+Offset, nodes.end ());
357
362
break ;
358
363
}
You can’t perform that action at this time.
0 commit comments