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

Avoid stack overflow when printing unevaluated const #72341

Closed

Conversation

Aaron1011
Copy link
Member

Fixes #68104

When printing the DefPath for an unevaluated const, we may end up trying
to print the same const again. To avoid infinite recursion, we use the
'verbose' format when we try to re-entrantly print a const. This ensures
that the pretty-printing process will always terminate.

Fixes rust-lang#68104

When printing the DefPath for an unevaluated const, we may end up trying
to print the same const again. To avoid infinite recursion, we use the
'verbose' format when we try to re-entrantly print a const. This ensures
that the pretty-printing process will always terminate.
@rust-highfive
Copy link
Collaborator

r? @eddyb

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 19, 2020
@Aaron1011 Aaron1011 changed the title Avoid stack overflowing when printing unevaluated const Avoid stack overflow when printing unevaluated const May 19, 2020
Comment on lines +5 to +6
// Braces around const expression causes crash
impl Num<{5}> {
Copy link
Member

Choose a reason for hiding this comment

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

The braces shouldn't matter, I wonder if this is a bug (cc @varkor).
What you want is to use an expression, like 2+3, so that it definitely requires evaluation.

Copy link
Contributor

Choose a reason for hiding this comment

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

We currently don't look into blocks for literals, It seems like we only do it for params at the moment

Copy link
Contributor

@lcnr lcnr May 25, 2020

Choose a reason for hiding this comment

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

Will get a PR ready which cleans this up.

edit: we may not actually want this for now, as being more aggressive here may mask some otherwise found issues with ConstKind::Unevaluated.

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't need braces here: arbitrary expressions should work, and {5} is an expression.

Copy link
Member Author

Choose a reason for hiding this comment

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

The braces are needed to trigger the original ICE, so I included them in the test

// const. This ensures that we never end up trying to recursively
// print a const that we're already printing.
// See issue #68104 for more details
self = with_no_const_path(|| {
Copy link
Member

Choose a reason for hiding this comment

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

Can you try with_forced_impl_filename_line instead? It should also work since I believe the problem here is the pretty-printing of impl paths.

Wait. Hang on. Why would this ever print paths?!

The bug is probably in metadata encoding/decoding. AnonConsts shouldn't turn into DefKind::Const.

@eddyb eddyb added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 25, 2020
@varkor varkor added the F-const_generics `#![feature(const_generics)]` label May 25, 2020
@Aaron1011
Copy link
Member Author

Closing in favor of #72600 as per @eddyb's comment: #72341 (comment)

@Aaron1011 Aaron1011 closed this May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_generics `#![feature(const_generics)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specialized impl for a type with const generics in another crate causes a stack overflow in rustc
5 participants