Skip to content

[Sema] Limit inout capture to @noescape contexts #2354

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 1 commit into from
Jun 1, 2016

Conversation

dduan
Copy link
Contributor

@dduan dduan commented Apr 30, 2016

What's in this pull request?

This patch adds limits to inout captures as specified in SE-0035.

The following diagnostics have been added:

  1. implicit capture of inout arguments by closure literals that may escape (not
    mark by @NoEscape) is now invalid. This also includes implicit capture of
    self.
  2. nested functions with inout captures cannot be used as arguments not marked
    @NoEscape.
  3. nested function with inout captures cannot be a return value.

This change eliminates the need for the shadowing mechanism created for inout.

The shadow copy and InOutDeshadowing SIL pass has not been eliminated yet. It's WIP and should come in a later PR.

Resolved bug number: (SR-807)


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
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

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

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

@lattner
Copy link
Contributor

lattner commented May 3, 2016

@jckarter can you take a look at this?

@jckarter jckarter self-assigned this May 3, 2016
for (auto D : llvm::makeArrayRef(SF.Decls).slice(StartElem)) {
D->walk(walker);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be able to check this during applySolution instead of walking the entire source file again. When we finishApply on a call that has a local function DeclRef as an argument, we can either check the local function's captures immediately if they've been computed, or else remember whether the function reference was @noescape or not and then diagnose when we computeCaptures later.

@jckarter
Copy link
Contributor

jckarter commented May 3, 2016

@swift-ci Please test

@lattner
Copy link
Contributor

lattner commented May 4, 2016

Awesome, all tests pass. I can't wait for InOutDeshadowing to bite the dust :-)

@dduan
Copy link
Contributor Author

dduan commented May 27, 2016

@swift-ci Please test

@jckarter
Copy link
Contributor

@dduan Thanks for the revision! Linux failure looks unrelated. I'll review the code in a bit.

@dduan
Copy link
Contributor Author

dduan commented May 27, 2016

Reviewing myself: I don't like stashing those states in decl. Would love some alternative spots!

@jckarter

On May 27, 2016, at 8:55 AM, Joe Groff notifications@github.com wrote:

@dduan Thanks for the revision! Linux failure looks unrelated. I'll review the code in a bit.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@@ -4598,6 +4600,8 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {

/// Location of the 'throws' token.
SourceLoc ThrowsLoc;
llvm::DenseSet<ApplyExpr *> OccurancesAsEcscapingArg;
Copy link
Contributor

Choose a reason for hiding this comment

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

Spelling nitpick: "Occurrence"

@jckarter
Copy link
Contributor

Looks great, aside from the spelling comment.

@@ -4627,6 +4631,18 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
void setGenericParams(GenericParamList *GenericParams);

public:
llvm::DenseSet<ApplyExpr *> getEscapingArgOccurance() {
return OccurancesAsEcscapingArg;
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra c in "Escaping"

@jckarter
Copy link
Contributor

I agree. Since this info is only needed during Sema, you could move it to a DenseMap in the TypeChecker object.

@dduan
Copy link
Contributor Author

dduan commented May 28, 2016

@swift-ci please test

@dduan
Copy link
Contributor Author

dduan commented May 28, 2016

@jckarter I moved the stash from AbstractFunctionDecl to TypeChecker.

@jckarter
Copy link
Contributor

@dduan Looks great. Do you mind squashing the commits?

The following diagnostics have been added:

1. implicit capture of inout arguments by closure literals that may escape (
   not mark by @NoEscape) is now invalid. This also includes implicit capture
   of `self`.
2. nested functions with inout captures cannot be used as arguments not marked
   @NoEscape.
3. nested function with inout captures cannot be a return value.

This change eliminates the need for the shadowing mechanism created for inouts.
@dduan
Copy link
Contributor Author

dduan commented Jun 1, 2016

@jckarter done

@swift-ci please test and merge

@swift-ci swift-ci merged commit 2848482 into swiftlang:master Jun 1, 2016
@jckarter
Copy link
Contributor

jckarter commented Jun 1, 2016

Thanks!

@lattner
Copy link
Contributor

lattner commented Jun 4, 2016

Should I mark SE-0035 as "implemented"?

lattner added a commit to swiftlang/swift-evolution that referenced this pull request Jun 30, 2016
@dduan dduan deleted the se0035-pr branch January 5, 2017 22:05
MaxDesiatov pushed a commit that referenced this pull request Apr 19, 2021
[pull] swiftwasm from main
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