Skip to content

Conversation

@atrick
Copy link
Contributor

@atrick atrick commented May 10, 2018

It turns out that it's necessary to special case exclusivity Builtins and add flags to SIL instructions because of a couple circumstances:

Swift 3 mode exclusivity warnings will continue to be warnings.
The standard library will continue building in Swift 3 mode (for the foreseeable future).

atrick added 4 commits May 10, 2018 11:46
This flag supports promoting KeyPath access violations to an error in
Swift 4+, while building the standard library in Swift 3 mode. This is
only necessary as long as the standard library continues to build in
Swift 3 mode. Once the standard library build migrates, it can all be
ripped out.

<rdar://problem/40115738> [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.
Modify IRGen to emit builtin access markers with an error flag in
Swift 3 mode.

KeyPath enforcement is required by user code in Swift 4+ mode, but is
implemented within the standard library. A [builtin] flag marks the
special case for access generated by Builtins so that they are
always enforced as an error regardless of the language mode.

This is necessary for Swift 4.2 because the standard library continues
to build in Swift 3 mode. Once the standard library build migrates,
this is all irrelevant.

This does not actually affect existing Swift 3 code, since the KeyPath
feature wasn't introduced until Swift 4.

<rdar://problem/40115738> [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.
I noticed this during testing, but it has nothing to do with the other changes
in this PR. This static violation has always been present as a warning and would
continue to be a warning after my changes.
@atrick
Copy link
Contributor Author

atrick commented May 10, 2018

@swift-ci test.

@atrick atrick changed the title [4.2] enforce keypath exclusivity as error [4.2-04-30] enforce keypath exclusivity as error May 10, 2018
@atrick atrick requested a review from gottesmm May 10, 2018 20:01
@atrick
Copy link
Contributor Author

atrick commented May 10, 2018

@devincoughlin, is this ok in principle? @gottesmm is reviewing the implementation for CCC.

@atrick
Copy link
Contributor Author

atrick commented May 10, 2018

=== CCC Information ===

Explanation: All exclusivity violations should be errors in Swift 4.2
when building in Swift 4 mode. This was not yet true for KeyPaths
because they are enforced at runtime within the standard library which
still builds in Swift 3 mode.

Scope of Issue: Code that uses KeyPaths in a way that violates
exclusivity will now trap at runtime with detailed diagnostics.

KeyPaths are a Swift 4 language feature. However, it is possible that
projects are still building in Swift 3 mode but have added KeyPaths to
the project. KeyPath exclusivity violations will now be reported at
runtime as errors regardless of the language mode. This is necessary
for Swift 4 projects, and desirable for Swift 3 projects.

Origination: Both the KeyPath and exclusivity feature were introduced
in Swift 4.0, but KeyPaths that violated exclusivity were not
enforced. In 4.2 we recently introduced enforcement of KeyPath
exclusivity, but it was still only a warning:

commit 08e6624
Merge: 9a8a9d4 abab49e
Author: Andrew Trick [email protected]
Date: Fri Apr 20 08:29:01 2018

Merge pull request #16051 from atrick/exclusive-key-path-fix

[Exclusivity] Enforce exclusive access for class offsets in KeyPaths

Risk: Swift 3 mode projects that violate exclusivity with KeyPaths
could now trap at runtime with detailed diagnostics. This is a
desirable outcome anyway, since this code needs to be fixed.

Reviewed By: Michael Gottesman

Testing: Several unit tests are checked in. We have bots that test the
SCK with a special exclusivity verification mode.

Directions for QA: N/A

@atrick
Copy link
Contributor Author

atrick commented May 10, 2018

4.2 pr: #16506

@atrick
Copy link
Contributor Author

atrick commented May 10, 2018

rdar://40115738 [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.

@atrick atrick merged commit 22f6eb1 into swiftlang:swift-4.2-branch-04-30-2018 May 10, 2018
@atrick atrick deleted the 4.2-04-30-enforce-keypath-exclusivity-as-error branch June 20, 2018 00:11
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