Skip to content

[NFC] [Parse/SILGen] Switch statement silgen cleanup #19039

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 2 commits into from
Aug 29, 2018

Conversation

gregomni
Copy link
Contributor

General cleanup, mostly via combining functions with single callees into their callers and simplifying where that can result in cleaner code.

And then fix name lookup of parsing where guards in switch cases so that the where expression references the correct bound pattern variables instead of always those from the first pattern. Which gets rid of the managed value juggling in SILGen for those expressions.

…atements correctly bind to the current pattern instead of always to the first pattern. Thus the hacky var decl juggling in where clauses in SILGen can be deleted.
@gregomni
Copy link
Contributor Author

@swift-ci Please smoke test.

@slavapestov
Copy link
Contributor

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor

('Debug' build has a known failure right now, its not your fault)

@@ -21,7 +21,7 @@ func test3(arg: Int?) {
case let .some(x) where x == 0:
print(x)
case let .some(xRenamed) where xRenamed == 1,
let .some(x) where xRenamed == 2: // FIXME: This 'x' in '.some(x)' isn't properly renamed in 'casebind_2' case.
let .some(x) where x == 2: // FIXME: This 'x' in '.some(x)' isn't properly renamed in 'casebind_2' case.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you look into what's going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, can do! But this is a pre-existing refactoring bug. The user would expect all the xs to become xRenamed but the .some(x) in the second pattern is a different decl and so it doesn't change. This PR makes it so that the x in the second where clause is the same decl as that second .some(x), so it doesn't change either.

So more 'correct', but still not the user expectation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok, makes sense then. I was just wondering why the behavior changes.

@jrose-apple
Copy link
Contributor

I know @gottesmm is working in this area, so you may want to hold off until he's pushed SIL ownership all the way through SILGenPattern.

@gregomni
Copy link
Contributor Author

@gottesmm I don't think that I touched anything near the RAII or forwarding/unforwarding ownership stuff here, but if you'd prefer, I'm fine to hold off merging.

@jckarter
Copy link
Contributor

IMO these cleanups still look valuable.

@jrose-apple
Copy link
Contributor

Ah, yeah, I didn't mean that they weren't valuable, just that there might be a merge conflict that'd be easier to resolve in the other direction. But I just remembered that Michael's on vacation, so his WIP shouldn't block this PR.

@slavapestov
Copy link
Contributor

Yeah, I think you should go ahead and merge this, @gregomni.

@gregomni gregomni merged commit 586d167 into swiftlang:master Aug 29, 2018
@gregomni gregomni deleted the switch-cleanup branch September 22, 2018 15:33
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.

4 participants