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

Fix gce ICE when encountering ill-formed consts #119060

Closed
wants to merge 1 commit into from

Conversation

sjwang05
Copy link
Contributor

Fixes #118545

@rustbot
Copy link
Collaborator

rustbot commented Dec 18, 2023

r? @WaffleLapkin

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 18, 2023
@WaffleLapkin
Copy link
Member

r? compiler-errors

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

This needs a better explanation for why this ICE occurs, since I think downgrading this span bug to a delayed span bug is a bit surprising solution to the ICE... so I'd rather have the other options exhausted first.

Specifically, why does it lead to an unevaluable const in the first place? Why is it not causing a validation error earlier?

@rustbot rustbot 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 Dec 18, 2023
@sjwang05
Copy link
Contributor Author

sjwang05 commented Dec 18, 2023

As I understand it, a validation error does get created during wf_checking, but due to #117159, item_types_checking still occurs despite the errors, leading to try_const_eval_resolve being called and ICEing when encountering the bad const.

@sjwang05
Copy link
Contributor Author

sjwang05 commented Jan 8, 2024

Sorry for sitting on this PR for this long, and sorry for forgetting to update labels when I last replied. I've added a comment explaining why we delay the bug instead of ICEing immediately--I'm not sure if there's a less hacky solution to this ICE, though I'd hardly say I'm familiar with this part of the compiler.

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 8, 2024
@compiler-errors
Copy link
Member

There's still no explanation why this is happening. All it does is link to #118545 and #117159. I expected this to have at least some type of PR description that explains why this is a valid solution.

I've thought a bit about this, and I don't believe we should fix this. GCE is very unstable currently, and this PR, as far as I understand, simply hides the fact that we're calling const_eval_resolve on constants that are not valid.

Until we have a better story about not calling resolve on unevaluated consts that are not WF and valid, I think we should just leave this ICE. It's not possible to encounter it without the feature gate enabled.

@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot 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 Jan 9, 2024
@sjwang05
Copy link
Contributor Author

sjwang05 commented Jan 19, 2024

I looked into it a little more, and it seems like the root of the problem is us creating ConstEquate predicates containing unevaluatable consts in in super_combine_consts. We subsequently ICE when trying to evaluate these predicates: #118545 ICEs when calling try_const_eval_resolve in process_obligation--we create a ConstEquate predicate equating the two instances of not_one:

#![feature(generic_const_exprs)]

struct Checked<const F: fn(usize) -> bool>;

fn not_one(val: usize) -> bool {
    val != 1
}

const _: Checked<not_one> = Checked::<not_one>;

and #119731 ICEs when calling try_const_eval_resolve in evaluate_predicate_recursively--we try to equate the two v4s in const v2: v11 = [[256; v4]; v4];.

Until we have a better story about not calling resolve on unevaluated consts that are not WF and valid, I think we should just leave this ICE. It's not possible to encounter it without the feature gate enabled.

That makes sense--the only "better" solution I could come up with is replacing the two occurrences of try_const_eval_resolve with const_eval_resolve and calling delay_as_bug in the case of Ok(None), which seems only marginally less hacky, e.g.:

match self.selcx.infcx.const_eval_resolve(...) {
    Ok(Some(val)) => Ok(ty::Const::new_value(tcx, val, c.ty())),
    Ok(None) => {
        let span = tcx.def_span(unevaluated.def);
        let reported = tcx.dcx().create_err(UnableToConstructConstantValue {
            span,
            unevaluated,
        }).delay_as_bug();
        Err(ErrorHandled::Reported(reported.into(), span))
    }
    Err(e) => Err(e),
}

I honestly have no clue how to prevent the creation of ConstEquate predicates containing unevaluatable consts--do you have any suggestions or ideas? If not, I'm willing to close this PR if you see fit. Thanks for your help and patience through all this.

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 19, 2024
@compiler-errors
Copy link
Member

Given that this is only reachable with GCE, which is both incomplete and needing a large overhaul, I'm not comfortable merging more hacks to fix one-off ICEs. Sorry for delaying this for so long, but I'm just gonna close this. Thanks for the contribution anyways!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: gce: unable to construct a constant value for the unevaluated constant UnevaluatedConst {..}
4 participants