Skip to content

Implement withoutActuallyEscaping verification #15046

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

Conversation

aschwaighofer
Copy link
Contributor

Check that an withoutActuallyEscaping(noescape_closure) { // scope} closure
has not escaped in the scope using the is_escaping_closure %closure
instruction.

rdar://35525730

Will be used to verify that withoutActuallyEscaping's block does not
escape the closure.

``%escaping = is_escaping_closure %closure`` tests the reference count. If the
closure is not uniquely referenced it prints out and error message and
returns true. Otherwise, it returns false. The returned result can be
used with a ``cond_fail %escaping`` instruction to abort the program.

rdar://35525730
Check that an ``withoutActuallyEscaping(noescape_closure) { // scope}`` closure
has not escaped in the scope using the ``is_escaping_closure %closure``
instruction.

rdar://35525730
@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 7, 2018

Build failed
Swift Test Linux Platform
Git Sha - 89e972f

auto *fatalErr = reinterpret_cast<const unsigned char *>("Fatal error");
auto *message = reinterpret_cast<const unsigned char *>(
"closure argument was escaped in withoutActuallyEscaping block");
_swift_stdlib_reportFatalErrorInFile(fatalErr, 11, message, 62, filename,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use strlen here (LLVM should be able to fold it away).

Aside: maybe we should rename this callback to not have "fatal" in it, since it doesn't abort itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@swift-ci
Copy link
Contributor

swift-ci commented Mar 7, 2018

Build failed
Swift Test OS X Platform
Git Sha - 89e972f

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please smoke test

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test source compatibility

@aschwaighofer
Copy link
Contributor Author

NSDictionary.enumerateKeysAndObjects' withoutActuallyEscaping is escaping a noescape closure. https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSDictionary.swift#L486

The code can be made correct by moving the code that uses the returned closure into withoutActuallyEscaping.

@aschwaighofer
Copy link
Contributor Author

Foundation/NSIndexSet.swift has the same issue.

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.

Sweet 👍

auto *fatalErr = reinterpret_cast<const unsigned char *>("Fatal error");
auto *message = reinterpret_cast<const unsigned char *>(
"closure argument was escaped in withoutActuallyEscaping block");
_swift_stdlib_reportFatalErrorInFile(fatalErr, 11, message, 62, filename,
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@rudkx
Copy link
Contributor

rudkx commented Mar 8, 2018

👍🏻👍🏻

@aschwaighofer
Copy link
Contributor Author

Please test with following PR:
swiftlang/swift-corelibs-foundation#1463
@swift-ci Please test linux

@swift-ci
Copy link
Contributor

swift-ci commented Mar 8, 2018

Build failed
Swift Test Linux Platform
Git Sha - 89e972f

@aschwaighofer
Copy link
Contributor Author

The successful source compatibility suite run is here: https://ci.swift.org/view/Pull%20Request/job/swift-PR-source-compat-suite/837/

@aschwaighofer
Copy link
Contributor Author

Please test with following PR:
swiftlang/swift-corelibs-foundation#1463
@swift-ci Please test linux

@swift-ci
Copy link
Contributor

swift-ci commented Mar 8, 2018

Build failed
Swift Test Linux Platform
Git Sha - b960275

@aschwaighofer
Copy link
Contributor Author

Please test with following PR:
swiftlang/swift-corelibs-foundation#1463
@swift-ci Please test linux

@aschwaighofer
Copy link
Contributor Author

swiftlang/swift-corelibs-foundation#1463 has to be merged first to prevent breakage

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test mac os x

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test macos

@swift-ci
Copy link
Contributor

swift-ci commented Mar 8, 2018

Build failed
Swift Test OS X Platform
Git Sha - 89e972f

@aschwaighofer aschwaighofer merged commit 1e4f55d into swiftlang:master Mar 9, 2018
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.

5 participants