Skip to content
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

WIP: Fix codegen bug for mixed range and literal patterns #21313

Closed
wants to merge 2 commits into from

Conversation

edwardw
Copy link
Contributor

@edwardw edwardw commented Jan 17, 2015

If there are both range and literal patterns in the same column of a
match expression, rustc may generate incorrect code. This patch fixes
it.

Closes #18060

@rust-highfive
Copy link
Collaborator

r? @pcwalton

(rust_highfive has picked a reviewer for you, use r? to override)

@edwardw
Copy link
Contributor Author

edwardw commented Jan 18, 2015

cc @jakub-

ast::PatTup(ref pats) => pats.iter().all(|p| all_wild_pat(&**p)),
_ => false,
}
}
Copy link

Choose a reason for hiding this comment

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

I think this should be made more general by checking the usefulness of a wild pattern (PatWildSingle) against a matrix of a single pattern pat, much like we check reachability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But this is in trans already so the reachability has been checked (and passed) in typeck, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I misread your comment. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jakub-, it works except that a constant pattern such as:

  enum A { AA }
  const B: A = A::AA;
  match A::AA {
    B => ()
  }

triggers const pattern should've been rewritten error condition in your check_match::pat_constructors function. I'm not terribly familiar with it. Any thoughts?

Copy link

Choose a reason for hiding this comment

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

@edwardw I think you'll have to use arm_pats rather than arms for that check. arm_pats have already had the const patterns inlined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works like a charm. Please review again, thanks.

@flaper87
Copy link
Contributor

@edwardw could you use a more descriptive title for the commit and PR ?

@edwardw edwardw changed the title Fix #18060 Edward Wang Fix codegen bug for mixed range and literal patterns Jan 19, 2015
@edwardw edwardw changed the title Edward Wang Fix codegen bug for mixed range and literal patterns Fix codegen bug for mixed range and literal patterns Jan 19, 2015
@edwardw
Copy link
Contributor Author

edwardw commented Jan 19, 2015

@flaper87 done.

@pnkfelix
Copy link
Member

@bors: r+ a87e04c

@bors
Copy link
Contributor

bors commented Jan 20, 2015

⌛ Testing commit a87e04c with merge a52c28d...

@bors
Copy link
Contributor

bors commented Jan 20, 2015

💔 Test failed - auto-mac-32-opt

for match expressions to address comments.
If there are both range and literal patterns in the same column of a
match expression, rustc may generate incorrect code. This patch fixes
it.

Closes rust-lang#18060
@edwardw
Copy link
Contributor Author

edwardw commented Jan 21, 2015

The patch has been redone and the test expanded. Please review again.

@edwardw
Copy link
Contributor Author

edwardw commented Jan 21, 2015

On a side note, the latest commit can probably be used as a template to simplify trans::_match itself, especially those pretty obscure enter_* family of functions.

@edwardw
Copy link
Contributor Author

edwardw commented Jan 22, 2015

r? @jakub- @nikomatsakis

@rust-highfive rust-highfive assigned ghost and unassigned pcwalton Jan 22, 2015
@pnkfelix
Copy link
Member

@bors: r+ d55c3fa

@bors
Copy link
Contributor

bors commented Jan 23, 2015

⌛ Testing commit d55c3fa with merge 57ae298...

@bors
Copy link
Contributor

bors commented Jan 23, 2015

💔 Test failed - auto-mac-64-opt

@edwardw edwardw changed the title Fix codegen bug for mixed range and literal patterns WIP: Fix codegen bug for mixed range and literal patterns Jan 28, 2015
@edwardw edwardw closed this Feb 10, 2015
@edwardw edwardw deleted the match-18060 branch February 10, 2015 01:41
@ghost
Copy link

ghost commented Feb 19, 2015

Oh, just realised this hadn't landed yet.

@edwardw Did you manage to identify what the problem with your PR was? Otherwise I'll try to pick it up. :) It's a bit embarrassing to have this codegen issue in 1.0, IMHO.

@edwardw edwardw restored the match-18060 branch February 19, 2015 12:10
@edwardw
Copy link
Contributor Author

edwardw commented Feb 19, 2015

@jakub-, my patch had a regression, namely, std::num::from_str_radix("-123.456", 10) fails if the string literal has a negative sign in it. And I've restored the branch if you'd like to resurrect it. Thanks!

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.

Wrong reordering of match arms with ranges
6 participants