Skip to content

Commit 7323263

Browse files
committed
AST: avoid unnecessarily calling getStartLoc() to avoid exponential growth of the stack trace
Issuing multiple getStartLoc() from sub-expression can exponentially grow the stack trace. When the expression under analysis is complex enough, this could be a user-noticeable hang. This patch fixes UnresolvedDotExpr::getStartLoc() by 'refactoring' the result of SubExpr->getStartLoc() to a local variable. rdar://52982457
1 parent 3e8f631 commit 7323263

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

include/swift/AST/Expr.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,8 +2387,9 @@ class UnresolvedDotExpr : public Expr {
23872387
}
23882388

23892389
SourceLoc getStartLoc() const {
2390-
if (SubExpr->getStartLoc().isValid())
2391-
return SubExpr->getStartLoc();
2390+
auto SubLoc = SubExpr->getStartLoc();
2391+
if (SubLoc.isValid())
2392+
return SubLoc;
23922393
else if (DotLoc.isValid())
23932394
return DotLoc;
23942395
else

test/IDE/coloring_52982457.swift

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// RUN: %target-swift-ide-test -syntax-coloring -source-filename %s | %FileCheck %s
2+
// RUN: %target-swift-ide-test -syntax-coloring -typecheck -source-filename %s | %FileCheck %s
3+
4+
func migrate() -> EitherIO<Error, Prelude.Unit> {
5+
// CHECK: <kw>func</kw> migrate() -> <type>EitherIO</type><<type>Error</type>, <type>Prelude</type>.<type>Unit</type>> {
6+
return self.execute(
7+
"""
8+
"""
9+
)
10+
.flatMap(const(execute(
11+
"""
12+
"""
13+
)))
14+
.flatMap(const(execute(
15+
"""
16+
"""
17+
)))
18+
.flatMap(const(execute(
19+
"""
20+
"""
21+
)))
22+
.flatMap(const(execute(
23+
"""
24+
"""
25+
)))
26+
.flatMap(const(execute(
27+
"""
28+
"""
29+
)))
30+
.flatMap(const(execute(
31+
"""
32+
"""
33+
)))
34+
.flatMap(const(execute(
35+
"""
36+
"""
37+
)))
38+
.flatMap(const(execute(
39+
"""
40+
"""
41+
)))
42+
.flatMap(const(execute(
43+
"""
44+
"""
45+
)))
46+
.flatMap(const(execute(
47+
"""
48+
"""
49+
)))
50+
.flatMap(const(execute(
51+
"""
52+
"""
53+
)))
54+
.flatMap(const(execute(
55+
"""
56+
"""
57+
)))
58+
.flatMap(const(execute(
59+
"""
60+
"""
61+
)))
62+
.flatMap(const(execute(
63+
"""
64+
"""
65+
)))
66+
.flatMap(const(execute(
67+
"""
68+
"""
69+
)))
70+
.flatMap(const(execute(
71+
"""
72+
"""
73+
)))
74+
.flatMap(const(execute(
75+
"""
76+
"""
77+
)))
78+
.flatMap(const(execute(
79+
"""
80+
"""
81+
)))
82+
.flatMap(const(execute(
83+
"""
84+
"""
85+
)))
86+
.flatMap(const(execute(
87+
"""
88+
"""
89+
)))
90+
.flatMap(const(execute(
91+
"""
92+
"""
93+
)))
94+
.flatMap(const(execute(
95+
"""
96+
"""
97+
)))
98+
.flatMap(const(execute(
99+
"""
100+
"""
101+
)))
102+
.flatMap(const(execute(
103+
"""
104+
"""
105+
)))
106+
.flatMap(const(execute(
107+
"""
108+
"""
109+
)))
110+
.flatMap(const(execute(
111+
"""
112+
"""
113+
)))
114+
.map(const(unit))
115+
}

0 commit comments

Comments
 (0)