Skip to content

[6.2 🍒][cxx-interop] Fix assertion failure from unavailable typedef + enum pattern #81699

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

j-hui
Copy link
Contributor

@j-hui j-hui commented May 22, 2025

Explanation: ClangImporter currently uses some pretty fragile heuristics to determine whether a typedef is involved in the definition of a {CF,NS}_OPTIONS type. Those heuristics lead it to mistakenly recognize unavailable {CF,NS}_ENUMs as {CF,NS}_OPTIONS. The resulting import logic turns out to work out all fine, except for the fact that there is an assertion that does not account for this possibility. This patch broadens that assertion slightly to also allow {CF,NS}_ENUMs along this code path.

Risk: Low, this patch set consists of some refactoring (to minimize the actual functional change) and then slightly broadens the scope of an assertion. This fixes an assertion failure that happens in internal CI.

Problem: rdar://150399978

Reviewed By: @egorzhdan

Original PR: #81625

j-hui added 4 commits May 21, 2025 18:54
…nction

Also renames it to findOptionSetEnum() to make it a bit clearer at face
value that the returned ImportedType will contain a Swift enum.

Also refactors some nearby instances of

  if (auto e = dyn_cast<ElaboratedType>(t))
      t = e->desugar();

into a helper function, desugarIfElaborated().

(cherry picked from commit c7070e7)
…EnumInfo.cpp

It's at home there alongside other ObjC enum-specific logic, rather than
in the middle of ImportDecl.cpp (since it isn't directly or exclusively
related to importing decls).

(cherry picked from commit 5aa5bcf)
The NS_OPTIONS macro sometimes uses a pattern where it loosely
associates a typedef with an anonymous enum via a shared underlying
integer type (emphasis on "loosely"). The typedef is marked as
unavailable in Swift so as to not cause name ambiguity when we associate
the anonymous enum with said typedef. We use unavailability as
a heuristic during the import process, but that conflates NS_OPTIONS
with NS_ENUMs that can be marked as unavailable for entirely unrelated
reasons.

That in and of itself is fine, because the import logic is general
enough to handle both cases, but we have an assertion that seems to be
unaware of this scenario, and trips on unavailable NS_ENUMs. (In those
cases, the typedef points to the enum rather than the underlying integer
type.) This patch fixes the assertion to be resilient against such cases
by looking through the enum a typedef refers to.

rdar://150399978
(cherry picked from commit 80db054)
@j-hui j-hui requested a review from a team as a code owner May 22, 2025 02:02
@j-hui
Copy link
Contributor Author

j-hui commented May 22, 2025

@swift-ci please test

@j-hui j-hui merged commit 3db1314 into swiftlang:release/6.2 May 22, 2025
5 checks passed
@j-hui j-hui deleted the cherry-pick-6.2/fix-unavailable-enum branch May 22, 2025 16:47
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.

2 participants