Skip to content

[DNM] Fix SILGenPattern fallthrough issues. #22988

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

Closed

Conversation

gottesmm
Copy link
Contributor

This PR attempts to first provide vardecls on all CaseStmts and use those to fix the SILGenPattern fallthrough issue.

rdar://problem/47467128

@gottesmm gottesmm requested a review from jrose-apple February 28, 2019 18:30
@gottesmm gottesmm force-pushed the type-check-silgenpattern-fix branch from 51d047f to a934627 Compare March 1, 2019 01:07
@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 1, 2019

@jrose-apple I made the change to just store the VarDecl copies into the CaseStmt. I am still I think running into name binding issues since in the following simple test case, the var decl in the .first, .third case seems to not resolve to the appropriate address only slot. Your thoughts?

enum Either<T> {
case first(T)
case second(T)
case third(T)
}

func main<T : BinaryInteger>(_ v: Either<T>) {
  switch v {
  case .first(let count), .third(let count):
    print(count)
  case .second(let count):
    print(count)
  }
}

main(Either.first(10))

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 1, 2019

From reading the AST, I think the problem is that in the body of the case stmts we are generating declref_expr instead of unresolved_declref_expr when parsing.

@jrose-apple
Copy link
Contributor

I'm not sure how to fix that. The parser does do some eager decl binding in parseExprIdentifier, and it ought to be safe to turn that off within cases (it's already turned off sometimes, as you can see), but that's suddenly a bigger change than this was originally. You should probably ask Doug and Rintaro if you want to go down that route.

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 1, 2019

Maybe the thing to do is to create the vardecls in the parser. Then we can keep the optimizations.

@jrose-apple
Copy link
Contributor

That could work too, haven't thought through how difficult it would be. It'll make copying the types over trickier, though.

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 1, 2019

@DougGregor @rintaro

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 1, 2019

@jrose-apple I don't think it will be an issue since we start by processing the cases. I can just take the first case label there and use that to seed the case stmt.

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 1, 2019

and then I can change the short cut in the body to reference the case stmts var decls directly. So we still have the optimization.

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 6, 2019

I have gone down the path I mentioned in this PR in #23056. Closing!

@gottesmm gottesmm closed this Mar 6, 2019
@gottesmm gottesmm deleted the type-check-silgenpattern-fix branch March 6, 2019 19:13
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.

2 participants