Skip to content

Commit 11d20b8

Browse files
author
Nathan Hawes
committed
[IDE] Avoid name binding in sourcekitd's syntactic requests
It looks like we recently started binding extensions to their nominals in order to continue to compute access levels via ValueDecl::getFormalAccess() after an assertion was added to enforce that bindExtensions had been called before anything tried to call ExtensionDecl::getBoundNominal() - which getFormalAccess() depends on. Sourcekitd's syntactic requests are made on every keypress in the editor though, so we shouldn't do any name binding (which may require module loading) to keep them as fast as possible. This patch restores the old inferAccessLevel() functions we used prior to the switch to ValueDecl::getFormalAccess() (plus a few fixes) that does as much as it can syntactically, without any name binding, and simply doesn't report the access level in cases where it couldn't be computed without name-binding. This also fixes an assertion hit we were getting trying to bind extensions in inactive ifconfig clauses, which ASTScope doesn't support. Resolves rdar://problem/57202584
1 parent 77daaf3 commit 11d20b8

11 files changed

+353
-61
lines changed

lib/IDE/SyntaxModel.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,6 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
904904
pushStructureNode(SN, NTD);
905905

906906
} else if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
907-
// Normally bindExtension() would take care of computing the extended
908-
// nominal. It must be done before asking for generic parameters.
909-
if (!inInactiveClause || ASTScope::areInactiveIfConfigClausesSupported())
910-
ED->computeExtendedNominal();
911907
SyntaxStructureNode SN;
912908
setDecl(SN, D);
913909
SN.Kind = SyntaxStructureKind::Extension;

test/SourceKit/DocumentStructure/Inputs/main.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,9 @@ public init() {
147147
deinit {
148148
fatalError()
149149
}
150+
151+
#if false
152+
extension Result {
153+
func foo() {}
154+
}
155+
#endif

test/SourceKit/DocumentStructure/access_parse.swift.response

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,6 @@
777777
},
778778
{
779779
key.kind: source.lang.swift.decl.extension,
780-
key.accessibility: source.lang.swift.accessibility.internal,
781780
key.name: "DefAccess",
782781
key.offset: 1399,
783782
key.length: 43,
@@ -788,7 +787,6 @@
788787
key.substructure: [
789788
{
790789
key.kind: source.lang.swift.decl.function.method.instance,
791-
key.accessibility: source.lang.swift.accessibility.internal,
792790
key.name: "defFunc()",
793791
key.offset: 1423,
794792
key.length: 17,
@@ -801,7 +799,6 @@
801799
},
802800
{
803801
key.kind: source.lang.swift.decl.extension,
804-
key.accessibility: source.lang.swift.accessibility.internal,
805802
key.name: "PubAccess",
806803
key.offset: 1443,
807804
key.length: 43,
@@ -812,7 +809,6 @@
812809
key.substructure: [
813810
{
814811
key.kind: source.lang.swift.decl.function.method.instance,
815-
key.accessibility: source.lang.swift.accessibility.internal,
816812
key.name: "defFunc()",
817813
key.offset: 1467,
818814
key.length: 17,
@@ -825,7 +821,6 @@
825821
},
826822
{
827823
key.kind: source.lang.swift.decl.extension,
828-
key.accessibility: source.lang.swift.accessibility.internal,
829824
key.name: "IntAccess",
830825
key.offset: 1487,
831826
key.length: 43,
@@ -836,7 +831,6 @@
836831
key.substructure: [
837832
{
838833
key.kind: source.lang.swift.decl.function.method.instance,
839-
key.accessibility: source.lang.swift.accessibility.internal,
840834
key.name: "defFunc()",
841835
key.offset: 1511,
842836
key.length: 17,
@@ -849,7 +843,6 @@
849843
},
850844
{
851845
key.kind: source.lang.swift.decl.extension,
852-
key.accessibility: source.lang.swift.accessibility.internal,
853846
key.name: "PrivAccess",
854847
key.offset: 1531,
855848
key.length: 44,
@@ -860,7 +853,6 @@
860853
key.substructure: [
861854
{
862855
key.kind: source.lang.swift.decl.function.method.instance,
863-
key.accessibility: source.lang.swift.accessibility.internal,
864856
key.name: "defFunc()",
865857
key.offset: 1556,
866858
key.length: 17,

test/SourceKit/DocumentStructure/structure.swift.empty.response

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2348,
3+
key.length: 2472,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -223,7 +223,6 @@
223223
},
224224
{
225225
key.kind: source.lang.swift.decl.extension,
226-
key.accessibility: source.lang.swift.accessibility.internal,
227226
key.name: "OuterCls",
228227
key.offset: 377,
229228
key.length: 45,
@@ -234,7 +233,6 @@
234233
key.substructure: [
235234
{
236235
key.kind: source.lang.swift.decl.class,
237-
key.accessibility: source.lang.swift.accessibility.internal,
238236
key.name: "InnerCls2",
239237
key.offset: 402,
240238
key.length: 18,
@@ -558,7 +556,6 @@
558556
},
559557
{
560558
key.kind: source.lang.swift.decl.extension,
561-
key.accessibility: source.lang.swift.accessibility.internal,
562559
key.name: "Foo",
563560
key.offset: 999,
564561
key.length: 58,
@@ -569,7 +566,6 @@
569566
key.substructure: [
570567
{
571568
key.kind: source.lang.swift.decl.function.method.instance,
572-
key.accessibility: source.lang.swift.accessibility.internal,
573569
key.name: "anExtendedFooFunction()",
574570
key.offset: 1019,
575571
key.length: 36,
@@ -1466,6 +1462,81 @@
14661462
]
14671463
}
14681464
]
1465+
},
1466+
{
1467+
key.kind: source.lang.swift.decl.function.free,
1468+
key.accessibility: source.lang.swift.accessibility.public,
1469+
key.name: "init()",
1470+
key.offset: 2356,
1471+
key.length: 27,
1472+
key.nameoffset: 2356,
1473+
key.namelength: 6,
1474+
key.bodyoffset: 2364,
1475+
key.bodylength: 18,
1476+
key.attributes: [
1477+
{
1478+
key.offset: 2349,
1479+
key.length: 6,
1480+
key.attribute: source.decl.attribute.public
1481+
}
1482+
],
1483+
key.substructure: [
1484+
{
1485+
key.kind: source.lang.swift.expr.call,
1486+
key.name: "fatalError",
1487+
key.offset: 2369,
1488+
key.length: 12,
1489+
key.nameoffset: 2369,
1490+
key.namelength: 10,
1491+
key.bodyoffset: 2380,
1492+
key.bodylength: 0
1493+
}
1494+
]
1495+
},
1496+
{
1497+
key.kind: source.lang.swift.decl.function.free,
1498+
key.accessibility: source.lang.swift.accessibility.private,
1499+
key.name: "deinit",
1500+
key.offset: 2385,
1501+
key.length: 27,
1502+
key.nameoffset: 2385,
1503+
key.namelength: 6,
1504+
key.bodyoffset: 2393,
1505+
key.bodylength: 18,
1506+
key.substructure: [
1507+
{
1508+
key.kind: source.lang.swift.expr.call,
1509+
key.name: "fatalError",
1510+
key.offset: 2398,
1511+
key.length: 12,
1512+
key.nameoffset: 2398,
1513+
key.namelength: 10,
1514+
key.bodyoffset: 2409,
1515+
key.bodylength: 0
1516+
}
1517+
]
1518+
},
1519+
{
1520+
key.kind: source.lang.swift.decl.extension,
1521+
key.name: "Result",
1522+
key.offset: 2425,
1523+
key.length: 38,
1524+
key.nameoffset: 2435,
1525+
key.namelength: 6,
1526+
key.bodyoffset: 2443,
1527+
key.bodylength: 19,
1528+
key.substructure: [
1529+
{
1530+
key.kind: source.lang.swift.decl.function.method.instance,
1531+
key.name: "foo()",
1532+
key.offset: 2447,
1533+
key.length: 13,
1534+
key.nameoffset: 2452,
1535+
key.namelength: 5,
1536+
key.bodyoffset: 2459,
1537+
key.bodylength: 0
1538+
}
1539+
]
14691540
}
14701541
],
14711542
key.diagnostics: [
@@ -1502,6 +1573,20 @@
15021573
key.sourcetext: "func "
15031574
}
15041575
]
1576+
},
1577+
{
1578+
key.line: 143,
1579+
key.column: 12,
1580+
key.severity: source.diagnostic.severity.error,
1581+
key.description: "initializers may only be declared within a type",
1582+
key.diagnostic_stage: source.diagnostic.stage.swift.parse
1583+
},
1584+
{
1585+
key.line: 147,
1586+
key.column: 1,
1587+
key.severity: source.diagnostic.severity.error,
1588+
key.description: "deinitializers may only be declared within a class",
1589+
key.diagnostic_stage: source.diagnostic.stage.swift.parse
15051590
}
15061591
]
15071592
}

test/SourceKit/DocumentStructure/structure.swift.foobar.response

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2348,
3+
key.length: 2472,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -223,7 +223,6 @@
223223
},
224224
{
225225
key.kind: source.lang.swift.decl.extension,
226-
key.accessibility: source.lang.swift.accessibility.internal,
227226
key.name: "OuterCls",
228227
key.offset: 377,
229228
key.length: 45,
@@ -234,7 +233,6 @@
234233
key.substructure: [
235234
{
236235
key.kind: source.lang.swift.decl.class,
237-
key.accessibility: source.lang.swift.accessibility.internal,
238236
key.name: "InnerCls2",
239237
key.offset: 402,
240238
key.length: 18,
@@ -558,7 +556,6 @@
558556
},
559557
{
560558
key.kind: source.lang.swift.decl.extension,
561-
key.accessibility: source.lang.swift.accessibility.internal,
562559
key.name: "Foo",
563560
key.offset: 999,
564561
key.length: 58,
@@ -569,7 +566,6 @@
569566
key.substructure: [
570567
{
571568
key.kind: source.lang.swift.decl.function.method.instance,
572-
key.accessibility: source.lang.swift.accessibility.internal,
573569
key.name: "anExtendedFooFunction()",
574570
key.offset: 1019,
575571
key.length: 36,
@@ -1466,6 +1462,81 @@
14661462
]
14671463
}
14681464
]
1465+
},
1466+
{
1467+
key.kind: source.lang.swift.decl.function.free,
1468+
key.accessibility: source.lang.swift.accessibility.public,
1469+
key.name: "init()",
1470+
key.offset: 2356,
1471+
key.length: 27,
1472+
key.nameoffset: 2356,
1473+
key.namelength: 6,
1474+
key.bodyoffset: 2364,
1475+
key.bodylength: 18,
1476+
key.attributes: [
1477+
{
1478+
key.offset: 2349,
1479+
key.length: 6,
1480+
key.attribute: source.decl.attribute.public
1481+
}
1482+
],
1483+
key.substructure: [
1484+
{
1485+
key.kind: source.lang.swift.expr.call,
1486+
key.name: "fatalError",
1487+
key.offset: 2369,
1488+
key.length: 12,
1489+
key.nameoffset: 2369,
1490+
key.namelength: 10,
1491+
key.bodyoffset: 2380,
1492+
key.bodylength: 0
1493+
}
1494+
]
1495+
},
1496+
{
1497+
key.kind: source.lang.swift.decl.function.free,
1498+
key.accessibility: source.lang.swift.accessibility.private,
1499+
key.name: "deinit",
1500+
key.offset: 2385,
1501+
key.length: 27,
1502+
key.nameoffset: 2385,
1503+
key.namelength: 6,
1504+
key.bodyoffset: 2393,
1505+
key.bodylength: 18,
1506+
key.substructure: [
1507+
{
1508+
key.kind: source.lang.swift.expr.call,
1509+
key.name: "fatalError",
1510+
key.offset: 2398,
1511+
key.length: 12,
1512+
key.nameoffset: 2398,
1513+
key.namelength: 10,
1514+
key.bodyoffset: 2409,
1515+
key.bodylength: 0
1516+
}
1517+
]
1518+
},
1519+
{
1520+
key.kind: source.lang.swift.decl.extension,
1521+
key.name: "Result",
1522+
key.offset: 2425,
1523+
key.length: 38,
1524+
key.nameoffset: 2435,
1525+
key.namelength: 6,
1526+
key.bodyoffset: 2443,
1527+
key.bodylength: 19,
1528+
key.substructure: [
1529+
{
1530+
key.kind: source.lang.swift.decl.function.method.instance,
1531+
key.name: "foo()",
1532+
key.offset: 2447,
1533+
key.length: 13,
1534+
key.nameoffset: 2452,
1535+
key.namelength: 5,
1536+
key.bodyoffset: 2459,
1537+
key.bodylength: 0
1538+
}
1539+
]
14691540
}
14701541
],
14711542
key.diagnostics: [
@@ -1505,6 +1576,22 @@
15051576
key.sourcetext: "func "
15061577
}
15071578
]
1579+
},
1580+
{
1581+
key.line: 143,
1582+
key.column: 12,
1583+
key.filepath: "-foobar",
1584+
key.severity: source.diagnostic.severity.error,
1585+
key.description: "initializers may only be declared within a type",
1586+
key.diagnostic_stage: source.diagnostic.stage.swift.parse
1587+
},
1588+
{
1589+
key.line: 147,
1590+
key.column: 1,
1591+
key.filepath: "-foobar",
1592+
key.severity: source.diagnostic.severity.error,
1593+
key.description: "deinitializers may only be declared within a class",
1594+
key.diagnostic_stage: source.diagnostic.stage.swift.parse
15081595
}
15091596
]
15101597
}

test/SourceKit/DocumentStructure/structure.swift.invalid.response

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
},
1717
{
1818
key.kind: source.lang.swift.decl.extension,
19-
key.accessibility: source.lang.swift.accessibility.internal,
2019
key.name: "OuterCls",
2120
key.offset: 12,
2221
key.length: 43,
@@ -27,7 +26,6 @@
2726
key.substructure: [
2827
{
2928
key.kind: source.lang.swift.decl.class,
30-
key.accessibility: source.lang.swift.accessibility.internal,
3129
key.name: "InnerCls1",
3230
key.offset: 35,
3331
key.length: 18,

0 commit comments

Comments
 (0)