Skip to content

[3.1] Improve compile-time performance of string interpolation #7146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

DougGregor
Copy link
Member

Constraint generation for interpolated string literals was
meticulously producing a constraint system that included all of the
generated calls to init(stringInterpolationSegment:). While accurate,
this is completely unnecessary (because the
ExpressibleByStringInterpolation protocol allows anything to be
interpolated) and leads to large, intertwined constraint systems
where:

(1) There are two additional type variables per string interpolation
segment, and
(2) Those type variables form a bridge between the string
interpolation's type variable and the type variables of each string
interpolation segment, and
(3) init(stringInterpolationSegment:) tends to be overloaded (17 overloads on String!)

which left each string interpolation as a large connected component
with big disjunctions.

Drop the calls to init(stringInterpolationSegment:) from the
constraint system. This eliminates two type
variables per segment (due to (1) going away), and breaks the bridge
described in (2), so that each string interpolation segment is
treated as an separate connected component and, therefore, will be
solved independently. The actual resolution of
init(stringInterpolationSegment:) overloads is pushed to the
constraint application phase, where we are only dealing with concrete
types and much smaller constraint systems. Still, eliminate 16 concrete-type overloads of String.init(stringInterpolationSegment:) in favor of 3 generic ones.

Fixes rdar://problem/29389887.

Remove 16 concrete init(stringInterpolationSegment:) overloads and
replace them with 3 generic overloads, significantly reducing the
exponential blow-up from larger string interpolations.

Fixes rdar://problem/29389887.

(cherry picked from commit f6cac54)
…eholders.

The type checker introduces fresh type variables for editor
placeholders that are encountered in the source. If there are many
such editor placeholders, we'll create a large number of type
variables with very little context, which can cause poor scaling in
the type checker. Since we get very little information out of these
type variables, artificially limit the number of type variables we
create (to 2) and rotate through them.

Another piece of rdar://problem/29389887.

(cherry picked from commit 207fffc)
…rals.

Constraint generation for interpolated string literals was
meticulously producing a constraint system that included all of the
generated calls to init(stringInterpolationSegment:). While accurate,
this is completely unnecessary (because the
ExpressibleByStringInterpolation protocol allows *anything* to be
interpolated) and leads to large, intertwined constraint systems
where:

(1) There are two additional type variables per string interpolation
segment, and
(2) Those type variables form a bridge between the string
interpolation's type variable and the type variables of each string
interpolation segment, and
(3) init(stringInterpolationSegment:) tends to be overloaded (4
overloads, down from 17 due to
2935301)

which left each string interpolation as a large connected component
with big disjunctions.

Drop the calls to init(stringInterpolationSegment:) from the
constraint system. This eliminates two type
variables per segment (due to (1) going away), and breaks the bridge
described in (2), so that each string interpolation segment is
treated as an separate connected component and, therefore, will be
solved independently. The actual resolution of
init(stringInterpolationSegment:) overloads is pushed to the
constraint application phase, where we are only dealing with concrete
types and *much* smaller constraint systems.

Fixes rdar://problem/29389887 more thoroughly.

(cherry picked from commit 21ee10b)
…ement.

NFC; the prior commit eliminated all uses of this locator path element.

(cherry picked from commit 4127f70)
@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - aebe73a
Test requested by - @DougGregor

@DougGregor
Copy link
Member Author

Stack trace printing failed? Weird.

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - aebe73a
Test requested by - @DougGregor

@ematejska
Copy link
Contributor

@swift-ci please test Linux

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - aebe73a
Test requested by - @ematejska

@DougGregor
Copy link
Member Author

We need a 3.1 cherry-pick of apple/swift-lldb@dbb730e for this to work

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@DougGregor DougGregor merged commit 228feb1 into swiftlang:swift-3.1-branch Jan 31, 2017
@DougGregor DougGregor deleted the string-interpolation-typecheck-perf branch January 31, 2017 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants