Skip to content

Fix #856: Handle try/catch cases as catch cases if possible. #1315

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 30, 2016

Conversation

nicolasstucki
Copy link
Contributor

Previously they were all lifted into a match with the came cases.
Now the first cases are handled directly by by the catch. If one
of the cases can not be handled the old scheme is applied to to it
and all subsequent cases.

@nicolasstucki
Copy link
Contributor Author

Review by @DarkDimius

@DarkDimius DarkDimius self-assigned this Jun 12, 2016

/** Is this pattern node a catch-all or type-test pattern? */
private def isCatchCase(cdef: CaseDef)(implicit ctx: Context): Boolean = cdef match {
case CaseDef(Typed(Ident(nme.WILDCARD), tpt), _, _) => isSimpleThrowable(tpt.tpe)
Copy link
Contributor

Choose a reason for hiding this comment

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

what about guards? Since this PR they will not be desugared by patmat, and will reach the backend and be ignored there.

@DarkDimius
Copy link
Contributor

@nicolasstucki please ping me when ready for next review round. Thanks.

* try { <code> }
* catch {
* <tryCases> // Cases that can be handled by catch
* <paterMatchCases> // Cases starting with first one that can't be handled by catch
Copy link
Member

@smarter smarter Jun 24, 2016

Choose a reason for hiding this comment

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

Typo: patternMatchCases

Copy link
Member

Choose a reason for hiding this comment

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

Oh, same elsewhere, so I guess it's not a typo but intentional, still seems a bit weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was indeed a typo. Must have copy pasted it around.

@nicolasstucki nicolasstucki force-pushed the optimize-try-cases branch 2 times, most recently from a48f1df to bcda17d Compare June 24, 2016 08:51
@nicolasstucki
Copy link
Contributor Author

@DarkDimius this PR is ready for another round of review.

override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = tree match {
case Try(_, cases, _) =>
cases.foreach {
case CaseDef(Typed(_, _), guard, _) => assert(guard.isEmpty, "Try case should not a guard.")
Copy link
Contributor

Choose a reason for hiding this comment

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

A synonym of have is missing. Same on the next line.

Previously they were all lifted into a match with the came cases.
Now the first cases are handled directly by by the catch. If one
of the cases can not be handled the old scheme is applied to to it
and all subsequent cases.
@DarkDimius
Copy link
Contributor

LGTM, Thanks!

@DarkDimius DarkDimius merged commit b35eff9 into scala:master Jun 30, 2016
@nicolasstucki nicolasstucki deleted the optimize-try-cases branch July 5, 2016 11:32
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