Skip to content

Invalid (unstable, ill-formed, ...) const code is evaluated even after emitting error #76064

@RalfJung

Description

@RalfJung
Member

Nightly-only ICEs are exposed on stable because array lengths are evaluated even when they are invalid:

struct Bug([u8; panic!(1)]);

This first emits an error that a feature flag is missing, but then const-evaluates the array length anyway and later leads to an ICE. This is not a stability hole (there's an error, the code will not compile), but it's an ICE on stable, so it's a bug.

While the ICE should also be fixed, the underlying problem is that we should not const-evaluate code that failed stability checking (and there are possibly other kinds of checks to which this applies as well)

@oli-obk proposed some solutions:

Cc @rust-lang/wg-const-eval

Activity

added
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
C-bugCategory: This is a bug.
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Aug 29, 2020
ecstatic-morse

ecstatic-morse commented on Aug 30, 2020

@ecstatic-morse
Contributor

Putting this on ConstQualifs seems reasonable. It seems better than adding more cruft to mir::Body at first glance. Currently each field of ConstQualifs is tied to an implementer of the Qualif trait but this isn't a hard requirement.

RalfJung

RalfJung commented on Nov 2, 2020

@RalfJung
MemberAuthor

Once this is fixed, we can hopefully also get rid of the TransmuteSizeDiff hack. I am not sure if we carry any other similar hacks that we still carry around.

RalfJung

RalfJung commented on Nov 7, 2020

@RalfJung
MemberAuthor

@oli-obk the solution at #78809, if I understand correctly, does not fix TransmuteSizeDiff... should that become a separate issue once this one is closed, or is there some reason that TransmuteSizeDiff cannot be fixed by adding a similar ErrorReported to the transmute size check?

oli-obk

oli-obk commented on Nov 9, 2020

@oli-obk
Contributor

It does indeed not fix TransmuteSizeDiff. We'll need to investigate what actually causes a transmute size check failure to not affect tainted_by_errors. We can likely fix this in a similar manner. Though we also have other bugs like { let x; &x } getting all the way to interning when it fails due to a dangling pointer. We'll be collecting more and more error flags to keep track of. I'm not sure how to address this properly. Maybe we'll need more Result<T, ErrorReported> on queries that don't return an enum which has an error variant (like ty::Err or ConstKind::Err)

added a commit that references this issue on Nov 9, 2020
3e012e2

8 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @RalfJung@oli-obk@jonas-schievink@ecstatic-morse@rust-lang-glacier-bot

      Issue actions

        Invalid (unstable, ill-formed, ...) const code is evaluated even after emitting error · Issue #76064 · rust-lang/rust