Skip to content

Commit 362b219

Browse files
committed
Revert "Merge pull request swiftlang#26937 from rintaro/syntaxparse-leakfix"
This reverts commit e49401b, reversing changes made to bd222ad.
1 parent f302da0 commit 362b219

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4125,7 +4125,7 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
41254125
ParserPosition startPosition = getParserPosition();
41264126
llvm::Optional<SyntaxParsingContext> TmpCtxt;
41274127
TmpCtxt.emplace(SyntaxContext);
4128-
TmpCtxt->setBackTracking();
4128+
TmpCtxt->setTransparent();
41294129

41304130
SourceLoc TypeAliasLoc = consumeToken(tok::kw_typealias);
41314131
SourceLoc EqualLoc;
@@ -4164,13 +4164,13 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
41644164
}
41654165

41664166
if (Flags.contains(PD_InProtocol) && !genericParams && !Tok.is(tok::equal)) {
4167+
TmpCtxt->setBackTracking();
41674168
TmpCtxt.reset();
41684169
// If we're in a protocol and don't see an '=' this looks like leftover Swift 2
41694170
// code intending to be an associatedtype.
41704171
backtrackToPosition(startPosition);
41714172
return parseDeclAssociatedType(Flags, Attributes);
41724173
}
4173-
TmpCtxt->setTransparent();
41744174
TmpCtxt.reset();
41754175

41764176
auto *TAD = new (Context) TypeAliasDecl(TypeAliasLoc, EqualLoc, Id, IdLoc,

lib/Parse/ParseStmt.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ ParserStatus Parser::parseExprOrStmt(ASTNode &Result) {
123123

124124
if (Tok.is(tok::pound) && Tok.isAtStartOfLine() &&
125125
peekToken().is(tok::code_complete)) {
126-
SyntaxParsingContext CCCtxt(SyntaxContext, SyntaxContextKind::Decl);
127126
consumeToken();
128127
if (CodeCompletion)
129128
CodeCompletion->completeAfterPoundDirective();

lib/Parse/SyntaxParsingContext.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,17 @@ ParsedRawSyntaxNode SyntaxParsingContext::finalizeSourceFile() {
256256
Layout[1] = std::move(Parts.back());
257257
Parts = Parts.drop_back();
258258

259-
assert(llvm::all_of(Parts, [](const ParsedRawSyntaxNode& node) {
260-
return node.getKind() == SyntaxKind::CodeBlockItem;
261-
}) && "all top level element must be 'CodeBlockItem'");
259+
for (auto RawNode : Parts) {
260+
if (RawNode.getKind() != SyntaxKind::CodeBlockItem) {
261+
// FIXME: Skip toplevel garbage nodes for now. we shouldn't emit them in
262+
// the first place.
263+
if (RawNode.isRecorded())
264+
getSyntaxCreator().finalizeNode(RawNode.getOpaqueNode());
265+
continue;
266+
}
267+
268+
AllTopLevel.push_back(RawNode);
269+
}
262270

263271
Layout[0] = Recorder.recordRawSyntax(SyntaxKind::CodeBlockItemList, Parts);
264272

test/Syntax/serialize_tupletype.swift.result

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
null,
1818
null,
1919
{
20-
"id": 33,
20+
"id": 1,
2121
"tokenKind": {
2222
"kind": "kw_typealias"
2323
},
@@ -48,7 +48,7 @@
4848
"presence": "Present"
4949
},
5050
{
51-
"id": 34,
51+
"id": 2,
5252
"tokenKind": {
5353
"kind": "identifier",
5454
"text": "x"
@@ -64,11 +64,11 @@
6464
},
6565
null,
6666
{
67-
"id": 32,
67+
"id": 34,
6868
"kind": "TypeInitializerClause",
6969
"layout": [
7070
{
71-
"id": 1,
71+
"id": 3,
7272
"tokenKind": {
7373
"kind": "equal"
7474
},
@@ -82,11 +82,11 @@
8282
"presence": "Present"
8383
},
8484
{
85-
"id": 31,
85+
"id": 33,
8686
"kind": "TupleType",
8787
"layout": [
8888
{
89-
"id": 18,
89+
"id": 20,
9090
"tokenKind": {
9191
"kind": "l_paren"
9292
},
@@ -95,16 +95,16 @@
9595
"presence": "Present"
9696
},
9797
{
98-
"id": 29,
98+
"id": 31,
9999
"kind": "TupleTypeElementList",
100100
"layout": [
101101
{
102-
"id": 24,
102+
"id": 26,
103103
"kind": "TupleTypeElement",
104104
"layout": [
105105
null,
106106
{
107-
"id": 19,
107+
"id": 21,
108108
"tokenKind": {
109109
"kind": "identifier",
110110
"text": "b"
@@ -115,7 +115,7 @@
115115
},
116116
null,
117117
{
118-
"id": 20,
118+
"id": 22,
119119
"tokenKind": {
120120
"kind": "colon"
121121
},
@@ -129,11 +129,11 @@
129129
"presence": "Present"
130130
},
131131
{
132-
"id": 22,
132+
"id": 24,
133133
"kind": "SimpleTypeIdentifier",
134134
"layout": [
135135
{
136-
"id": 21,
136+
"id": 23,
137137
"tokenKind": {
138138
"kind": "identifier",
139139
"text": "Int"
@@ -149,7 +149,7 @@
149149
null,
150150
null,
151151
{
152-
"id": 23,
152+
"id": 25,
153153
"tokenKind": {
154154
"kind": "comma"
155155
},
@@ -166,12 +166,12 @@
166166
"presence": "Present"
167167
},
168168
{
169-
"id": 28,
169+
"id": 30,
170170
"kind": "TupleTypeElement",
171171
"layout": [
172172
null,
173173
{
174-
"id": 25,
174+
"id": 27,
175175
"tokenKind": {
176176
"kind": "kw__"
177177
},
@@ -181,7 +181,7 @@
181181
},
182182
null,
183183
{
184-
"id": 20,
184+
"id": 22,
185185
"tokenKind": {
186186
"kind": "colon"
187187
},
@@ -195,11 +195,11 @@
195195
"presence": "Present"
196196
},
197197
{
198-
"id": 27,
198+
"id": 29,
199199
"kind": "SimpleTypeIdentifier",
200200
"layout": [
201201
{
202-
"id": 26,
202+
"id": 28,
203203
"tokenKind": {
204204
"kind": "identifier",
205205
"text": "String"
@@ -222,7 +222,7 @@
222222
"presence": "Present"
223223
},
224224
{
225-
"id": 30,
225+
"id": 32,
226226
"tokenKind": {
227227
"kind": "r_paren"
228228
},

0 commit comments

Comments
 (0)