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

type parameter V/#2 (V/2) out of range when substituting with MIR inlining enabled #78529

Closed
tmiasko opened this issue Oct 29, 2020 · 3 comments · Fixed by #78674
Closed

type parameter V/#2 (V/2) out of range when substituting with MIR inlining enabled #78529

tmiasko opened this issue Oct 29, 2020 · 3 comments · Fixed by #78674
Labels
A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tmiasko
Copy link
Contributor

tmiasko commented Oct 29, 2020

env RUSTFLAGS=-Zmir-opt-level=2 cargo check -Zbuild-std --target x86_64-unknown-linux-gnu

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:528:17: type parameter `V/#2` (V/2) out of range when substituting, substs=[fn() -> collections::btree::node::Root<K, V> {collections::btree::node::Root::<K, V>::new_leaf}, ()]

thread 'rustc' panicked at 'Box<Any>', /rustc/0da6d42f297642a60f2640ec313b879b376b9ad8/compiler/rustc_errors/src/lib.rs:891:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.49.0-nightly (0da6d42f2 2020-10-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z force-unstable-if-unmarked -Z mir-opt-level=2 -C embed-bitcode=no -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<collections::btree::map::BTreeMap<K, V> as core::clone::Clone>::clone::clone_subtree`
#1 [optimized_mir] optimizing MIR for `<collections::btree::map::BTreeMap<K, V> as core::clone::Clone>::clone`

Regressed in #68965, cc @eddyb.

@tmiasko tmiasko added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 29, 2020
@jonas-schievink jonas-schievink added the A-mir-opt-inlining Area: MIR inlining label Oct 29, 2020
@tmiasko
Copy link
Contributor Author

tmiasko commented Oct 29, 2020

Inlining now uses instance_mir instead of optimized_mir and attempts to inline things it didn't inline before, but as far as I can see some of those require a different treatment of substs, i.e., substs_for_mir_body.

pub struct D<A, B> {
    a: *mut Option<A>,
    b: *mut Vec<B>,
}

impl<A, B> Drop for D<A, B> {
    fn drop(&mut self) {
        unsafe {
            std::ptr::drop_in_place(self.a);
            std::ptr::drop_in_place(self.b);
        }
    }
}
$ rustc --crate-type=lib -Zmir-opt-level=2 a.rs
error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:528:17: type parameter `B/#1` (B/1) out of range when substituting, substs=[std::vec::Vec<B>]
...
query stack during panic:
#0 [optimized_mir] optimizing MIR for `<D<A, B> as std::ops::Drop>::drop`

@chengniansun
Copy link

chengniansun commented Nov 2, 2020

Not sure whether the following is a duplicate to this bug. If not I will file another one.

trait CollectionFamily {
    type Member<T>;
}
fn floatify() {
    Family as CollectionFamily
}
error[E0425]: cannot find value `Family` in this scope
 --> reduced_mutant.rs:5:5
  |
5 |     Family as CollectionFamily
  |     ^^^^^^ not found in this scope

error[E0658]: generic associated types are unstable
 --> reduced_mutant.rs:2:5
  |
2 |     type Member<T>;
  |     ^^^^^^^^^^^^^^^
  |
  = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
  = help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

warning: trait objects without an explicit `dyn` are deprecated
 --> reduced_mutant.rs:5:15
  |
5 |     Family as CollectionFamily
  |               ^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn CollectionFamily`
  |
  = note: `#[warn(bare_trait_objects)]` on by default

error[E0601]: `main` function not found in crate `reduced_mutant`
 --> reduced_mutant.rs:1:1
  |
1 | / trait CollectionFamily {
2 | |     type Member<T>;
3 | | }
4 | | fn floatify() {
5 | |     Family as CollectionFamily
6 | | }
  | |_^ consider adding a `main` function to `reduced_mutant.rs`

error[E0191]: the value of the associated type `Member` (from trait `CollectionFamily`) must be specified
 --> reduced_mutant.rs:5:15
  |
2 |     type Member<T>;
  |     --------------- `Member` defined here
...
5 |     Family as CollectionFamily
  |               ^^^^^^^^^^^^^^^^ help: specify the associated type: `CollectionFamily<Member = Type>`

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:529:17: type parameter `T/#1` (T/1) out of range when substituting, substs=[Self]

thread 'rustc' panicked at 'Box<Any>', /rustc/4f7612ac1499258025077f1fd05d2f429f9accfb/compiler/rustc_errors/src/lib.rs:888:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.49.0-nightly (4f7612ac1 2020-10-31) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [object_safety_violations] determine object safety of trait `CollectionFamily`
#1 [typeck] type-checking `floatify`
end of query stack
error: aborting due to 5 previous errors; 1 warning emitted

Some errors have detailed explanations: E0191, E0425, E0601, E0658.
For more information about an error, try `rustc --explain E0191`.

NOTE: The bug is found by our work-in-progress compiler testing tool Kira, and the test program is reduced/minimized by Perses

@tmiasko
Copy link
Contributor Author

tmiasko commented Nov 2, 2020

@chengniansun that would be a different issue.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 6, 2020
… r=oli-obk

inliner: Use substs_for_mir_body

Changes from 68965 extended the kind of instances that are being
inlined. For some of those, the `instance_mir` returns a MIR body that
is already expressed in terms of the types found in substitution array,
and doesn't need further substitution.

Use `substs_for_mir_body` to take that into account.

Resolves rust-lang#78529.
Resolves rust-lang#78560.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 8, 2020
… r=oli-obk

inliner: Use substs_for_mir_body

Changes from 68965 extended the kind of instances that are being
inlined. For some of those, the `instance_mir` returns a MIR body that
is already expressed in terms of the types found in substitution array,
and doesn't need further substitution.

Use `substs_for_mir_body` to take that into account.

Resolves rust-lang#78529.
Resolves rust-lang#78560.
@bors bors closed this as completed in b4589a8 Nov 9, 2020
bjorn3 pushed a commit to bjorn3/rust that referenced this issue Nov 27, 2020
… r=oli-obk

inliner: Use substs_for_mir_body

Changes from 68965 extended the kind of instances that are being
inlined. For some of those, the `instance_mir` returns a MIR body that
is already expressed in terms of the types found in substitution array,
and doesn't need further substitution.

Use `substs_for_mir_body` to take that into account.

Resolves rust-lang#78529.
Resolves rust-lang#78560.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants