Skip to content

[SILGen] Simpler impl of multiple matching patterns in case w/ variable bindings #5094

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
Oct 3, 2016

Conversation

gregomni
Copy link
Contributor

@gregomni gregomni commented Oct 2, 2016

Backed off of the implementation with a shared body block, which got messy really fast with multiple patterns containing address-only values to pass in, as it led to separated stack alloc/cleanup requirements and passing stack alloc’d values as block args, aliasing of addresses for stack cleanup verifying, etc. A mess.

This now does the conservative thing of repeating the body in each matching pattern block.

This can probably be profitably revisited in the future if @rjmccall 's recently suggested changes to make all SIL types into scalars gets implemented, which would make doing the shared body block style much easier (at least as far as SILGen is concerned).

Resolves SR-2555.

…riable bindings

Backed off of the implementation with a shared body block, which got
messy really fast with multiple patterns containing address-only values
to pass in, as it led to separated stack alloc/cleanup requirements and
passing stack alloc’d values as block args, aliasing of addresses for
stack cleanup verifying, etc. A mess.

This now does the conservative thing of repeating the body in each
matching pattern block.
@gregomni
Copy link
Contributor Author

gregomni commented Oct 3, 2016

@swift-ci Please smoke test and merge

@swift-ci swift-ci merged commit d38df12 into swiftlang:master Oct 3, 2016
@rjmccall
Copy link
Contributor

rjmccall commented Oct 3, 2016

That's unfortunate. Re-emitting the whole case block is potentially a really big hit.

I guess it'll do for now.

@jckarter
Copy link
Contributor

We can't do this, because we're not set up to re-emit AST nodes in general, nor do we want to. This breaks if you have any closures or var decls in the case body, e.g.:

func foo(x: Foo) {
  switch x {
  case .a(let x), .b(let x):
    let y = x
  }
}

which is breaking some of our users at Apple. I'm going to have to revert this.

jckarter added a commit to jckarter/swift that referenced this pull request Nov 16, 2016
… with variable bindings"

This reverts commit 9508fdc from swiftlang#5094. Reemitting
case bodies doesn't work if the body contains nested closures or
declarations, since SILGen expects these to only ever be visited once.
@jrose-apple
Copy link
Contributor

What's the plan for SR-2555, then? The old code apparently wasn't correct either.

@jckarter
Copy link
Contributor

jckarter commented Nov 17, 2016

Hopefully @gregomni is still working on this. A few weeks after this PR, he posted to swift-dev about fixing some of the issues he alluded to in the PR description, extending IRGen and the SIL verifier to understand phi'ed stack slots.

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