Skip to content

[6.0][immediate] Load Foundation early enough for bridging #75634

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

Merged

Conversation

benlangmuir
Copy link
Contributor

  • Explanation: Some bridged Foundation types require Foundation to be loaded in the process before we ever reach certain code paths. Swift scripts using such types were crashing, because they were loading Foundation too late. This change unconditionally loads Foundation early in the frontend process when in scripting mode to workaround this issue.
  • Scope: Only affects running swift scripts, and only on Darwin. For scripts that import Foundation the only difference is we dlopen it earlier. For scripts that don't use Foundation they will now dlopen Foundation, because it's too early in the process to detect whether it's needed. The risk to such scripts is mitigated because failure to load Foundation is only a warning not an error.
  • Issues: rdar://129528115
  • Original PRs: [immediate] Load Foundation early enough for bridging #75594
  • Risk: The risk of regression from this change is low and scope is limited. The primary risk for this change is that we could make future changes to the compiler that introduce swift bridging calls earlier in the process and cause this bug to return. That should be caught by CI running tests with --param use_os_stdlib, but that isn't in PR test configs so it may not be caught immediately. We have multiple options to fix this bug more thoroughly for the future though either in the runtime/Foundation or in the immediate mode JIT, but they are all much more involved changes.
  • Testing: Tested manually on macOS 15 beta and macOS 13.6. On 13.6, also checked multiple configurations (arm64, arm64 with SIP disabled, x86_64). There's a lit test included that will run with --param use_os_stdlib.
  • Reviewers: @mikeash

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
(cherry picked from commit 8a824d7)
@benlangmuir benlangmuir added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.0 labels Aug 1, 2024
@benlangmuir benlangmuir requested a review from a team as a code owner August 1, 2024 22:25
@benlangmuir
Copy link
Contributor Author

@swift-ci please test

@fredriss
Copy link
Contributor

fredriss commented Aug 2, 2024

Given this obviously only affects immediate mode, I'm approving it.

@fredriss fredriss enabled auto-merge August 2, 2024 00:21
@fredriss fredriss merged commit e570e35 into swiftlang:release/6.0 Aug 2, 2024
5 checks passed
@benlangmuir benlangmuir deleted the script-load-foundation-early-6 branch August 2, 2024 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants