@@ -43,129 +43,289 @@ public protocol SyntaxParseable: SyntaxProtocol {
4343
4444extension AccessorDeclSyntax : SyntaxParseable {
4545 public static func parse( from parser: inout Parser ) -> Self {
46+ // Keep the parser alive so that the arena in which `raw` is allocated
47+ // doesn’t get deallocated before we have a chance to create a syntax node
48+ // from it. We can’t use `parser.arena` as the parameter to
49+ // `Syntax(raw:arena:)` because the node might have been re-used during an
50+ // incremental parse and would then live in a different arena than
51+ // `parser.arena`.
52+ defer {
53+ withExtendedLifetime ( parser) {
54+ }
55+ }
4656 let node = parser. parseAccessorDecl ( )
4757 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
48- return Syntax ( raw: raw) . cast ( Self . self)
58+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
4959 }
5060}
5161
5262extension AttributeSyntax : SyntaxParseable {
5363 public static func parse( from parser: inout Parser ) -> Self {
64+ // Keep the parser alive so that the arena in which `raw` is allocated
65+ // doesn’t get deallocated before we have a chance to create a syntax node
66+ // from it. We can’t use `parser.arena` as the parameter to
67+ // `Syntax(raw:arena:)` because the node might have been re-used during an
68+ // incremental parse and would then live in a different arena than
69+ // `parser.arena`.
70+ defer {
71+ withExtendedLifetime ( parser) {
72+ }
73+ }
5474 let node = parser. parseAttribute ( )
5575 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
56- return Syntax ( raw: raw) . cast ( Self . self)
76+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
5777 }
5878}
5979
6080extension CatchClauseSyntax : SyntaxParseable {
6181 public static func parse( from parser: inout Parser ) -> Self {
82+ // Keep the parser alive so that the arena in which `raw` is allocated
83+ // doesn’t get deallocated before we have a chance to create a syntax node
84+ // from it. We can’t use `parser.arena` as the parameter to
85+ // `Syntax(raw:arena:)` because the node might have been re-used during an
86+ // incremental parse and would then live in a different arena than
87+ // `parser.arena`.
88+ defer {
89+ withExtendedLifetime ( parser) {
90+ }
91+ }
6292 let node = parser. parseCatchClause ( )
6393 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
64- return Syntax ( raw: raw) . cast ( Self . self)
94+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
6595 }
6696}
6797
6898extension ClosureParameterSyntax : SyntaxParseable {
6999 public static func parse( from parser: inout Parser ) -> Self {
100+ // Keep the parser alive so that the arena in which `raw` is allocated
101+ // doesn’t get deallocated before we have a chance to create a syntax node
102+ // from it. We can’t use `parser.arena` as the parameter to
103+ // `Syntax(raw:arena:)` because the node might have been re-used during an
104+ // incremental parse and would then live in a different arena than
105+ // `parser.arena`.
106+ defer {
107+ withExtendedLifetime ( parser) {
108+ }
109+ }
70110 let node = parser. parseClosureParameter ( )
71111 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
72- return Syntax ( raw: raw) . cast ( Self . self)
112+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
73113 }
74114}
75115
76116extension CodeBlockItemSyntax : SyntaxParseable {
77117 public static func parse( from parser: inout Parser ) -> Self {
118+ // Keep the parser alive so that the arena in which `raw` is allocated
119+ // doesn’t get deallocated before we have a chance to create a syntax node
120+ // from it. We can’t use `parser.arena` as the parameter to
121+ // `Syntax(raw:arena:)` because the node might have been re-used during an
122+ // incremental parse and would then live in a different arena than
123+ // `parser.arena`.
124+ defer {
125+ withExtendedLifetime ( parser) {
126+ }
127+ }
78128 let node = parser. parseNonOptionalCodeBlockItem ( )
79129 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
80- return Syntax ( raw: raw) . cast ( Self . self)
130+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
81131 }
82132}
83133
84134extension DeclSyntax : SyntaxParseable {
85135 public static func parse( from parser: inout Parser ) -> Self {
136+ // Keep the parser alive so that the arena in which `raw` is allocated
137+ // doesn’t get deallocated before we have a chance to create a syntax node
138+ // from it. We can’t use `parser.arena` as the parameter to
139+ // `Syntax(raw:arena:)` because the node might have been re-used during an
140+ // incremental parse and would then live in a different arena than
141+ // `parser.arena`.
142+ defer {
143+ withExtendedLifetime ( parser) {
144+ }
145+ }
86146 let node = parser. parseDeclaration ( )
87147 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
88- return Syntax ( raw: raw) . cast ( Self . self)
148+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
89149 }
90150}
91151
92152extension EnumCaseParameterSyntax : SyntaxParseable {
93153 public static func parse( from parser: inout Parser ) -> Self {
154+ // Keep the parser alive so that the arena in which `raw` is allocated
155+ // doesn’t get deallocated before we have a chance to create a syntax node
156+ // from it. We can’t use `parser.arena` as the parameter to
157+ // `Syntax(raw:arena:)` because the node might have been re-used during an
158+ // incremental parse and would then live in a different arena than
159+ // `parser.arena`.
160+ defer {
161+ withExtendedLifetime ( parser) {
162+ }
163+ }
94164 let node = parser. parseEnumCaseParameter ( )
95165 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
96- return Syntax ( raw: raw) . cast ( Self . self)
166+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
97167 }
98168}
99169
100170extension ExprSyntax : SyntaxParseable {
101171 public static func parse( from parser: inout Parser ) -> Self {
172+ // Keep the parser alive so that the arena in which `raw` is allocated
173+ // doesn’t get deallocated before we have a chance to create a syntax node
174+ // from it. We can’t use `parser.arena` as the parameter to
175+ // `Syntax(raw:arena:)` because the node might have been re-used during an
176+ // incremental parse and would then live in a different arena than
177+ // `parser.arena`.
178+ defer {
179+ withExtendedLifetime ( parser) {
180+ }
181+ }
102182 let node = parser. parseExpression ( )
103183 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
104- return Syntax ( raw: raw) . cast ( Self . self)
184+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
105185 }
106186}
107187
108188extension FunctionParameterSyntax : SyntaxParseable {
109189 public static func parse( from parser: inout Parser ) -> Self {
190+ // Keep the parser alive so that the arena in which `raw` is allocated
191+ // doesn’t get deallocated before we have a chance to create a syntax node
192+ // from it. We can’t use `parser.arena` as the parameter to
193+ // `Syntax(raw:arena:)` because the node might have been re-used during an
194+ // incremental parse and would then live in a different arena than
195+ // `parser.arena`.
196+ defer {
197+ withExtendedLifetime ( parser) {
198+ }
199+ }
110200 let node = parser. parseFunctionParameter ( )
111201 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
112- return Syntax ( raw: raw) . cast ( Self . self)
202+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
113203 }
114204}
115205
116206extension GenericParameterClauseSyntax : SyntaxParseable {
117207 public static func parse( from parser: inout Parser ) -> Self {
208+ // Keep the parser alive so that the arena in which `raw` is allocated
209+ // doesn’t get deallocated before we have a chance to create a syntax node
210+ // from it. We can’t use `parser.arena` as the parameter to
211+ // `Syntax(raw:arena:)` because the node might have been re-used during an
212+ // incremental parse and would then live in a different arena than
213+ // `parser.arena`.
214+ defer {
215+ withExtendedLifetime ( parser) {
216+ }
217+ }
118218 let node = parser. parseGenericParameters ( )
119219 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
120- return Syntax ( raw: raw) . cast ( Self . self)
220+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
121221 }
122222}
123223
124224extension MemberDeclBlockSyntax : SyntaxParseable {
125225 public static func parse( from parser: inout Parser ) -> Self {
226+ // Keep the parser alive so that the arena in which `raw` is allocated
227+ // doesn’t get deallocated before we have a chance to create a syntax node
228+ // from it. We can’t use `parser.arena` as the parameter to
229+ // `Syntax(raw:arena:)` because the node might have been re-used during an
230+ // incremental parse and would then live in a different arena than
231+ // `parser.arena`.
232+ defer {
233+ withExtendedLifetime ( parser) {
234+ }
235+ }
126236 let node = parser. parseMemberDeclList ( )
127237 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
128- return Syntax ( raw: raw) . cast ( Self . self)
238+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
129239 }
130240}
131241
132242extension PatternSyntax : SyntaxParseable {
133243 public static func parse( from parser: inout Parser ) -> Self {
244+ // Keep the parser alive so that the arena in which `raw` is allocated
245+ // doesn’t get deallocated before we have a chance to create a syntax node
246+ // from it. We can’t use `parser.arena` as the parameter to
247+ // `Syntax(raw:arena:)` because the node might have been re-used during an
248+ // incremental parse and would then live in a different arena than
249+ // `parser.arena`.
250+ defer {
251+ withExtendedLifetime ( parser) {
252+ }
253+ }
134254 let node = parser. parsePattern ( )
135255 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
136- return Syntax ( raw: raw) . cast ( Self . self)
256+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
137257 }
138258}
139259
140260extension SourceFileSyntax : SyntaxParseable {
141261 public static func parse( from parser: inout Parser ) -> Self {
262+ // Keep the parser alive so that the arena in which `raw` is allocated
263+ // doesn’t get deallocated before we have a chance to create a syntax node
264+ // from it. We can’t use `parser.arena` as the parameter to
265+ // `Syntax(raw:arena:)` because the node might have been re-used during an
266+ // incremental parse and would then live in a different arena than
267+ // `parser.arena`.
268+ defer {
269+ withExtendedLifetime ( parser) {
270+ }
271+ }
142272 let node = parser. parseSourceFile ( )
143273 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
144- return Syntax ( raw: raw) . cast ( Self . self)
274+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
145275 }
146276}
147277
148278extension StmtSyntax : SyntaxParseable {
149279 public static func parse( from parser: inout Parser ) -> Self {
280+ // Keep the parser alive so that the arena in which `raw` is allocated
281+ // doesn’t get deallocated before we have a chance to create a syntax node
282+ // from it. We can’t use `parser.arena` as the parameter to
283+ // `Syntax(raw:arena:)` because the node might have been re-used during an
284+ // incremental parse and would then live in a different arena than
285+ // `parser.arena`.
286+ defer {
287+ withExtendedLifetime ( parser) {
288+ }
289+ }
150290 let node = parser. parseStatement ( )
151291 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
152- return Syntax ( raw: raw) . cast ( Self . self)
292+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
153293 }
154294}
155295
156296extension SwitchCaseSyntax : SyntaxParseable {
157297 public static func parse( from parser: inout Parser ) -> Self {
298+ // Keep the parser alive so that the arena in which `raw` is allocated
299+ // doesn’t get deallocated before we have a chance to create a syntax node
300+ // from it. We can’t use `parser.arena` as the parameter to
301+ // `Syntax(raw:arena:)` because the node might have been re-used during an
302+ // incremental parse and would then live in a different arena than
303+ // `parser.arena`.
304+ defer {
305+ withExtendedLifetime ( parser) {
306+ }
307+ }
158308 let node = parser. parseSwitchCase ( )
159309 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
160- return Syntax ( raw: raw) . cast ( Self . self)
310+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
161311 }
162312}
163313
164314extension TypeSyntax : SyntaxParseable {
165315 public static func parse( from parser: inout Parser ) -> Self {
316+ // Keep the parser alive so that the arena in which `raw` is allocated
317+ // doesn’t get deallocated before we have a chance to create a syntax node
318+ // from it. We can’t use `parser.arena` as the parameter to
319+ // `Syntax(raw:arena:)` because the node might have been re-used during an
320+ // incremental parse and would then live in a different arena than
321+ // `parser.arena`.
322+ defer {
323+ withExtendedLifetime ( parser) {
324+ }
325+ }
166326 let node = parser. parseType ( )
167327 let raw = RawSyntax ( parser. parseRemainder ( into: node) )
168- return Syntax ( raw: raw) . cast ( Self . self)
328+ return Syntax ( raw: raw, rawNodeArena : raw . arena ) . cast ( Self . self)
169329 }
170330}
171331
0 commit comments