-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[embedded] Support _findStringSwitchCaseWithCache in Embedded Swift #78915
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
[embedded] Support _findStringSwitchCaseWithCache in Embedded Swift #78915
Conversation
@swift-ci please test |
@@ -1929,7 +1929,11 @@ OptionalBridgedFunction BridgedPassContext::lookupStdlibFunction(BridgedStringRe | |||
|
|||
SILDeclRef declRef(decl, SILDeclRef::Kind::Func); | |||
SILOptFunctionBuilder funcBuilder(*invocation->getTransform()); | |||
return {funcBuilder.getOrCreateFunction(SILLocation(decl), declRef, NotForDefinition)}; | |||
SILFunction *function = funcBuilder.getOrCreateFunction(SILLocation(decl), declRef, NotForDefinition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not good to hide such kind of logic in a bridging function.
Instead it's better to explicitly call Context.loadFunction
at the call site (in the optimize
function in this case).
let f = context.lookupStdlibFunction(name: "_findStringSwitchCaseWithCache") { | ||
worklist.pushIfNotVisited(f) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a reasonable approach
…CaseWithCache in MPO instead
…y DFE, let late DFE collect it if unused
c0b1526
to
500f8ad
Compare
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
ObjectOutliner has an optimization that replaces calls to findStringSwitchCase with _findStringSwitchCaseWithCache. This currently causes a "missing symbol" linker error in Embedded Swift, because this replacement happens without loading the body of the function from the stdlib. See the attached testcase that shows the problem (only happens under -O).
This PR fixes that with two changes:
(1) Calling lookupStdlibFunction under Embedded Swift now triggers loading the body (deserialization) + its dependencies.
(2) The above alone is not a full fix, because ObjectOutliner is a late SIL optimization, and so deserializing stdlib code causes un-specialized code to get added to the module, causing later problems (we don't expect any unspecialized code to be used in Embedded Swift after MandatoryPerformanceOptimizations are run). To fix that, we eagerly link in _findStringSwitchCaseWithCache whenever findStringSwitchCase is present as part of MandatoryPerformanceOptimizations.
Suggestions for a better approach are welcome :)
rdar://143587257