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

Should we deeply normalize during writeback, or at the post-typeck places that need a "structurally resolved" type? #3

Open
compiler-errors opened this issue Apr 13, 2023 · 2 comments
Labels
A-normalization not-blocking-coherence An issue we can resolve after stabilizing the new solver during coherence

Comments

@compiler-errors
Copy link
Member

compiler-errors commented Apr 13, 2023

fn foo(x: [u8; 4]) {
    match x[2] {
        b' ' | 0x9..=0xd8 => {
            panic!()
        }
        _ => {}
    }
}

This code currently ICEs with:

error: internal compiler error: broken MIR in DefId(0:3 ~ test[3886]::foo) (Le((*_2), const 216_u8)): unexpected comparison types <usize as std::slice::SliceIndex<[u8]>>::Output and u8
 --> /home/gh-compiler-errors/test.rs:3:16
  |
3 |         b' ' | 0x9..=0xd8 => {
  |                ^^^^^^^^^^
  |

This is because we expect for the types in the writeback results to have been normalized deeply, and other code (e.g. MIR build, MIR validation, late lints, reachability and dead code analysis) expect that Ty::kind calls "just work" without any further normalization.


We can either:

  1. Deeply normalize during writeback (e.g. compiler-errors/rust@b0600ae), or
  2. Normalize at every site that relies on a "structurally resolved" type mentioned above.
@compiler-errors
Copy link
Member Author

Similarly, during writeback we "fix up" some expressions so that we can emit MIR built-in operations for things like add and index. This does not happen during writeback if we have projections, though, e.g.:

const fn first_eq_second(x: [u32; 2]) -> bool {
    x[0] == x[1]
}

This remains a call to Index::index and fails to const-check:

error[E0015]: cannot call non-const operator in constant functions
 --> <source>:2:5
  |
2 |     x[0] == x[1]
  |     ^^^^
  |
  = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
  = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable

@lcnr
Copy link

lcnr commented May 26, 2023

We currently normalize in writeback after hir typeck with the new solver to avoid dealing with unnormalized projections during lints and in the MIR.

@lcnr lcnr added the not-blocking-coherence An issue we can resolve after stabilizing the new solver during coherence label Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-normalization not-blocking-coherence An issue we can resolve after stabilizing the new solver during coherence
Projects
None yet
Development

No branches or pull requests

2 participants