Skip to content

SE-0103 Noescape by default #3853

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 6 commits into from
Jul 29, 2016
Merged

Conversation

milseman
Copy link
Member

@milseman milseman commented Jul 29, 2016

What's in this pull request?

[noescape by defaul] make noescape the default

This makes @noescape be the default semantics for
function types in argument positions, for everything except property
setters. Property setters are naturally escaping, so they keep their
escaping-by-default behavior.

There is some further (non-source-breaking) work to be done for
SE-0103:

- We need the withoutActuallyEscaping function
- Improve diagnostics and QoI to at least @noescape's standards
- Deprecate / drop @noescape, right now we allow it
- Update internal code completion printing to be contextual
- Add more tests to explore tricky corner cases
- Small regressions in fixits in attr/attr_availability.swift
- Use @autoclosure @escaping instead of @autoclosure(escaping)

Resolved bug number: (SR-1952)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

A smoke test on macOS does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library only for macOS. Simulator standard libraries and
    device standard libraries are not built.
  3. lldb is not built.
  4. The test and validation-test targets are run only for macOS. The optimized
    version of these tests are not run.

A smoke test on Linux does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library incrementally.
  3. lldb is built incrementally.
  4. The swift test and validation-test targets are run. The optimized version of these
    tests are not run.
  5. lldb is tested.

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@milseman
Copy link
Member Author

@swift-ci please test

@milseman
Copy link
Member Author

There might be some gtest failures, which I didn't see originally but I see locally after rebasing. But, this should be close and I'll try to fix those if they repro on the bots.

@lattner
Copy link
Contributor

lattner commented Jul 29, 2016

Awesome, thank you for working on this!

@@ -463,7 +463,8 @@ class TestClassWithThrows : HasThrowing, HasThrowingProtocol {
// HAS_THROWING: Begin completions
// HAS_THROWING-DAG: Decl[InstanceMethod]/Super: func foo() throws {|}; name=foo() throws
// HAS_THROWING-DAG: Decl[InstanceMethod]/Super: override func bar() throws {|}; name=bar() throws
// HAS_THROWING-DAG: Decl[InstanceMethod]/Super: override func baz(x: () throws -> ()) rethrows {|}; name=baz(x: () throws -> ()) rethrows
// FIXME: make the below require to print @escaping
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue & radar?

@gribozavr
Copy link
Contributor

Library changes and changes to library tests LGTM.

@milseman
Copy link
Member Author

@swift-ci please smoke test

@milseman
Copy link
Member Author

I fixed up the benchmarks and applied feedback. Unfortunately, I'm not sure about the corelibs-foundation failures. I'll try to fix them up blind in swiftlang/swift-corelibs-foundation#492

@tanadeau
Copy link
Contributor

Another item on the TODO list would be to change @autoclosure(escaping) to @autoclosure @escaping.

@milseman
Copy link
Member Author

Linux failures are corelibs-foundtaion, which I'll be fixing soon.

milseman added 6 commits July 29, 2016 13:48
Emits the error and fixit on parameter @NoEscape to move it to the
type, even if the type itself is also correctly attributed as
@NoEscape. This will become important when @NoEscape is the default to
keep our nice and friendly fixits.
Changes diangostic messages from referring specifically to @NoEscape,
which is going away, to 'non-escaping'. Introduces better diagnostics
and fixits for adding @escaping to closures that escape.
The isExplicitlyEscaping bit, though useful for printing,
unfortunately puts us in a position where we have different bit
patterns for the same type, and thus lose much of our type equivalence
checking for overriding, protocol conformance, etc., even if we were
to take subtyping into account. We need to drop it, relying on the
existing noescape bit alone to determine the type's semantics (at
least, as long as we continue to encode this information in the type
system).

This is a partial fix; we will now be excessively printing @escaping,
but the subsequent commits will correct this. For printing, we will
instead need to be more context-aware.
Adds an explicit @escaping throughout the standard library, validation
test suite, and tests. This will be necessary as soon as noescape is
the default for closure parameters.
This flips the switch to have @NoEscape be the default semantics for
function types in argument positions, for everything except property
setters. Property setters are naturally escaping, so they keep their
escaping-by-default behavior.

Adds contentual printing, and updates the test cases.

There is some further (non-source-breaking) work to be done for
SE-0103:

- We need the withoutActuallyEscaping function
- Improve diagnostics and QoI to at least @NoEscape's standards
- Deprecate / drop @NoEscape, right now we allow it
- Update internal code completion printing to be contextual
- Add more tests to explore tricky corner cases
- Small regressions in fixits in attr/attr_availability.swift
Adds @escaping to internal benchmark code to fix it. References SR for
known limitation. Use stdlib coding style for arguments.
@milseman milseman force-pushed the noescape_by_default branch from 71a911f to 25ac879 Compare July 29, 2016 20:49
@milseman
Copy link
Member Author

And XCTest update: swiftlang/swift-corelibs-xctest#146

@milseman
Copy link
Member Author

Validation tests pass for me with those PRs on Linux. OS X already passed. I'll have to watch CI carefully.

@DougGregor DougGregor merged commit 8219d4f into swiftlang:master Jul 29, 2016
milseman added a commit to milseman/swift that referenced this pull request Jul 29, 2016
…efault"

This reverts commit 8219d4f, reversing
changes made to e37d048.
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.

6 participants