Skip to content

[Sema] Implement @_nonEphemeral #27705

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

Closed
wants to merge 3 commits into from

Conversation

hamishknight
Copy link
Contributor

This PR contains a subset of the changes in #27695, specifically just the implementation for the @_nonEphemeral attribute and the diagnosis of invalid temporary pointers conversions passed to it.

This includes all array-to-pointer and string-to-pointer conversions, and most inout-to-pointer conversions with the exception of:

  • Global and static variables
  • Stored properties on such variables that are accessed directly (e.g excluding ones with property observers, ones on classes, protocols, and resilient types in general)
  • Force unwraps of any of the above

If landed, this will leave #27695 with just the changes required to start producing warnings in user code (by annotating the standard library + inferring the attribute in various places).

@hamishknight
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 6fe0857f685d1dab42933f27a80376e8bce0f59f

@hamishknight
Copy link
Contributor Author

@swift-ci please test Linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 6fe0857f685d1dab42933f27a80376e8bce0f59f

hamishknight and others added 3 commits October 20, 2019 13:42
This non-user-facing attribute is used to denote pointer parameters
which do not accept pointers produced from temporary pointer conversions
such as array-to-pointer, string-to-pointer, and in some cases
inout-to-pointer.
Diagnose ephemeral conversions that are passed to @_nonEphemeral
parameters. Currently, this defaults to a warning with a frontend flag
to upgrade to an error. Hopefully this will become an error by default
in a future language version.
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

From the type-checker/diagnostics perspective this looks good to me! I'm not really sure whether adding a new underscored attribute is the best way to go about it though.

It's already possible to determine that solver converts some type to a pointer implicitly and that it happened as part of the argument-to-parameter conversion. Maybe I just don't understand what is the intended use of this attribute...

@hamishknight
Copy link
Contributor Author

@xedin Thanks for looking through this! The goal of the attribute is to allow us to selectively mark parameters which shouldn't accept temporary pointer arguments (you can take a look at the last two commits of #27695 to see which decls I'm planning on marking).

We still want all other pointer parameters to continue accepting these temporary pointer conversions, as we don't know whether or not such conversions will be unsound (though the implementation of a SIL pass will help catch a bunch of cases there).

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

I only did a quick scan through this, but it looks like an excellent way to stage in the work.

@hamishknight
Copy link
Contributor Author

Merged as a part of #27695.

@hamishknight hamishknight deleted the just-the-health branch November 5, 2019 02:24
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.

4 participants