rust-lang / rust-lang/rust

Strictly proof not tainted by errors in `TypeckResults`

Open
#126,381 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I get here from #125888.

For now there is a hack when calling tcx.typeck():
https://github.com/rust-lang/rust/blob/76c73827dcd0b363e60b22c3cef64bde4171bf17/compiler/rustc_hir_typeck/src/writeback.rs#L125-L130

so that in returned TypeckResults, the tainted_by_errors may be None even though there is actually some errors. And this could cause many ICEs, because some functions trust that there is no type errors, and whenever it encounters an error, it won't throw an error report and just panic (#125888 is an example).


In this tainted_by_errors function, I try to change the condition to if self.dcx().err_count_excluding_lint_errs() > 0, then return the ErrorGuaranteed, and find that it could resolve 62 ICEs.

Resolved ICE list


    [crashes] tests/crashes/110630.rs
    [crashes] tests/crashes/111709.rs
    [crashes] tests/crashes/111709-2.rs
    [crashes] tests/crashes/112623.rs
    [crashes] tests/crashes/113379.rs
    [crashes] tests/crashes/114663.rs
    [crashes] tests/crashes/115808.rs
    [crashes] tests/crashes/117795.rs
    [crashes] tests/crashes/118545.rs
    [crashes] tests/crashes/119701.rs
    [crashes] tests/crashes/119729.rs
    [crashes] tests/crashes/119786.rs
    [crashes] tests/crashes/120793-2.rs
    [crashes] tests/crashes/120793.rs
    [crashes] tests/crashes/120792.rs
    [crashes] tests/crashes/120873.rs
    [crashes] tests/crashes/121097.rs
    [crashes] tests/crashes/121127.rs
    [crashes] tests/crashes/121063.rs
    [crashes] tests/crashes/121052.rs
    [crashes] tests/crashes/121411.rs
    [crashes] tests/crashes/121429.rs
    [crashes] tests/crashes/121613-2.rs
    [crashes] tests/crashes/121613.rs
    [crashes] tests/crashes/121623.rs
    [crashes] tests/crashes/121816.rs
    [crashes] tests/crashes/121957-1.rs
    [crashes] tests/crashes/121957-2.rs
    [crashes] tests/crashes/122044.rs
    [crashes] tests/crashes/122587-1.rs
    [crashes] tests/crashes/121858.rs
    [crashes] tests/crashes/122259.rs
    [crashes] tests/crashes/122630.rs
    [crashes] tests/crashes/122681.rs
    [crashes] tests/crashes/122904-2.rs
    [crashes] tests/crashes/122904.rs
    [crashes] tests/crashes/122909.rs
    [crashes] tests/crashes/123255.rs
    [crashes] tests/crashes/123276.rs
    [crashes] tests/crashes/123690.rs
    [crashes] tests/crashes/124004.rs
    [crashes] tests/crashes/124021.rs
    [crashes] tests/crashes/124083.rs
    [crashes] tests/crashes/124164.rs
    [crashes] tests/crashes/124262.rs
    [crashes] tests/crashes/124182.rs
    [crashes] tests/crashes/124340.rs
    [crashes] tests/crashes/124563.rs
    [crashes] tests/crashes/124583.rs
    [crashes] tests/crashes/124436.rs
    [crashes] tests/crashes/124894.rs
    [crashes] tests/crashes/125155.rs
    [crashes] tests/crashes/125185.rs
    [crashes] tests/crashes/125553.rs
    [crashes] tests/crashes/125758.rs
    [crashes] tests/crashes/125801.rs
    [crashes] tests/crashes/125768.rs
    [crashes] tests/crashes/125769.rs
    [crashes] tests/crashes/125874.rs
    [crashes] tests/crashes/125888.rs
    [crashes] tests/crashes/125914.rs
    [crashes] tests/crashes/125992.rs

https://github.com/rust-lang/rust/blob/f6b4b71ef10307201b52c17b0f9dcf9557cd90ba/compiler/rustc_infer/src/infer/mod.rs#L1152-L1172


But it will also break many ui tests, because as the hack said, it will affect diagnostic spans pretty negatively. So I think a proper way to resolve that is return a new defined enum rather than Option, such as

https://github.com/rust-lang/rust/blob/f6b4b71ef10307201b52c17b0f9dcf9557cd90ba/compiler/rustc_middle/src/ty/typeck_results.rs#L161-L163

enum TaintedByErrors {
    Normal(ErrorGuaranteed),
    Opaque(ErrorGuaranteed),
    StrictlyNoError,
}

So that we can choose to either early return or do more diagnostics.

@rustbot label +I-ICE +T-compiler

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the writeback hack in compiler/rustc_hir_typeck/src/writeback.rs and inspect tainted_by_errors in compiler/rustc_infer/src/infer/mod.rs. Read the TypeckResults representation in compiler/rustc_middle/src/ty/typeck_results.rs, then review the listed ICE and UI tests. Done means distinguishing strict no-error results from results that should preserve diagnostic behavior without allowing ICEs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.