Skip to content

Prevent silgen for macro expansions with type errors (#81396) #81409

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

hnrklssn
Copy link
Contributor

@hnrklssn hnrklssn commented May 9, 2025

  • Explanation:
    There is a bug in type checking where function bodies in macro expansions originating on nodes imported from clang (such as _SwiftifyImport) are not type checked. If such a function in a macro expansion has a type error and is called, no error will be emitted, and the compiler will crash in silgen. While we need to fix the type checker eventually, for now we are working around it by specifically type checking these functions right before silgen, and stopping if an error has occurred.
  • Scope:
    This will only affect code using the new MacrosOnImports feature, meaning they either use SafeInteropWrappers, or manually add a call to a swift macro using __attribute__((swift_attr("@my_macro"))).
  • Issues:
    rdar://150940383
  • Original PRs:
    Prevent silgen for macro expansions with type errors #81396)'
  • Risk:
    This should only affect code that would otherwise cause a crash.
  • Testing:
    Lit tests, manual testing
  • Reviewers:
    @DougGregor

Due to a bug in how macros on nodes imported from clang are evaluated,
their function body is not always type checked. This forces type
checking before silgen of a macro originating on a node imported from
clang, to prevent crashing in silgen.

rdar://150940383
(cherry picked from commit efd70b1)
@hnrklssn hnrklssn requested a review from a team as a code owner May 9, 2025 17:41
@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 9, 2025

@swift-ci please test

@hnrklssn hnrklssn requested a review from DougGregor May 9, 2025 17:41
@delcypher
Copy link
Contributor

delcypher commented May 13, 2025

@swiftlang/swift-branch-managers Can this please be approved and merged?

@devincoughlin devincoughlin merged commit 4ace71d into swiftlang:release/6.2 May 13, 2025
5 checks passed
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