@@ -5849,6 +5849,10 @@ open class SyntaxRewriter {
5849
5849
// nodes are being collected.
5850
5850
var newLayout : ContiguousArray < RawSyntax ? > ?
5851
5851
5852
+ // Rewritten children just to keep their 'SyntaxArena' alive until they are
5853
+ // wrapped with 'Syntax'
5854
+ var rewrittens : ContiguousArray < Syntax > = [ ]
5855
+
5852
5856
let syntaxNode = node. _syntaxNode
5853
5857
5854
5858
// Incrementing i manually is faster than using .enumerated()
@@ -5887,6 +5891,7 @@ open class SyntaxRewriter {
5887
5891
5888
5892
// Now that we know we have a new layout in which we collect rewritten
5889
5893
// nodes, add it.
5894
+ rewrittens. append ( rewritten)
5890
5895
newLayout!. append ( rewritten. raw)
5891
5896
} else {
5892
5897
// The node was not changed by the rewriter. Only store it if a previous
@@ -5902,10 +5907,12 @@ open class SyntaxRewriter {
5902
5907
5903
5908
// Sanity check, ensure the new children are the same length.
5904
5909
assert ( newLayout. count == node. raw. layoutView!. children. count)
5905
-
5910
+
5906
5911
let newRaw = node. raw. layoutView!. replacingLayout ( with: Array ( newLayout) , arena: . default)
5907
- let newNode = SyntaxType ( Syntax ( SyntaxData . forRoot ( newRaw) ) ) !
5908
- return newNode
5912
+ // 'withExtendedLifetime' to keep 'SyntaxArena's of them alive until here.
5913
+ return withExtendedLifetime ( rewrittens) {
5914
+ SyntaxType ( Syntax ( SyntaxData . forRoot ( newRaw) ) ) !
5915
+ }
5909
5916
} else {
5910
5917
// No child node was rewritten. So no need to change this node as well.
5911
5918
return node
0 commit comments