Skip to content

[SE-0458] Bring implementation in line with the latest proposal revision #79424

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
merged 5 commits into from
Feb 17, 2025

Conversation

DougGregor
Copy link
Member

Several improvements to bring the implementation of the strict memory safety mode (SE-0458) into line with the latest proposal revision:

  • Don't require @unsafe annotation on declarations with unsafe types in their signatures
  • Diagnose types that have unsafe storage but are neither @safe nor @unsafe, with Fix-Its to guide the user
  • Diagnose unsafe types in the superclass of a class
  • Import C struct/unions as unsafe when they involve unsafe storage

…scriminator

We found another case where we aren't getting a closure discriminator,
so disable this again in non-asserts builds while we investigate.
Tracked by rdar://143590572.
Since we infer unsafety from a use of a declaration that involves unsafe types
in its signature, there isn't a reason to require @unsafe on declaration to
restate it. This matches recent revisions of SE-0458.
When a type definition involves unsafe types in its storage, require it
to be explicitly marked @unsafe or @safe.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor enabled auto-merge February 16, 2025 22:05
@DougGregor DougGregor merged commit c2e36de into swiftlang:main Feb 17, 2025
3 checks passed
@DougGregor DougGregor deleted the se-0458-match-proposal branch February 17, 2025 03:43

// Escapable and non-escapable annotations imply that the declaration is
// safe.
if (hasNonEscapableAttr(recordDecl) || hasEscapableAttr(recordDecl))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking for the attribute explicitly, we should use the ClangTypeEscapability request.
This will do a couple additional things:

  • Inject escapability annotations for the STL
  • Calculate the correct escapability for template instantiations (e.g., std::vector<non-escapable> is escapable) considering the conditional escapability annotations
  • For aggregate types it attempts to infer the escapability based on the fields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened PR: #79434

Xazax-hun pushed a commit that referenced this pull request Feb 18, 2025
After PR #79424 was merged the compiler proper is doing inference on
what C++ types should be considered unsafe. Remove the duplicated (and
slightly divergent) logic from the importer as we no longer need it and
we should have a consistent view of what is considered unsafe. The only
divergence left is the old logic that renames some methods to have
"Unsafe" in their names. In the future, we want to get rid of this
behavior (potentially under a new interop version).
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