[immediate] Load Foundation early enough for bridging

Foundation needs to be loaded early in the process for Swift's runtime
to properly initialize bridging support; otherwise it may cause issues
like unrecognized selectors. When scripting, load Foundation early in
performFrontend before any swift code runs.

rdar://129528115
This commit is contained in:
Ben Langmuir
2024-07-31 11:54:05 -07:00
parent 66e2f972ab
commit 8a824d70a0
5 changed files with 65 additions and 0 deletions

View File

@@ -1955,6 +1955,13 @@ int swift::performFrontend(ArrayRef<const char *> Args,
return finishDiagProcessing(1, /*verifierEnabled*/ false);
}
// Scripts that use the Foundation framework need it loaded early for bridging
// to work correctly on Darwin platforms. On other platforms this is a no-op.
if (Invocation.getFrontendOptions().RequestedAction ==
FrontendOptions::ActionType::Immediate) {
loadFoundationIfNeeded(Instance->getDiags());
}
// Don't ask clients to report bugs when running a script in immediate mode.
// When a script asserts the compiler reports the error with the same
// stacktrace as a compiler crash. From here we can't tell which is which,