-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Support polymorphic InstanceDef's by avoiding double substitution. #69925
Comments
So @davidtwco, @eddyb and I spent a while discussing this on Zulip in an effort to better understand what's going on. Folks might find this topic or this topic helpful. Let me try to summarize my understanding of (a) how things work and (b) the problem: Currently, an The problem is that for some kinds of Note: Some of the text below is kind of confused in its particulars, so striking out, but still relevant-ish.
There is no "easy" fix here, but there are some refatorings to be done. One very simple fix is to (a) not generate drop-glue variants until we have a "fully monomorphic" (or "ground") type that never requires substitution. This is #69036. This "staves off" the problem by not creating the problematic Another might be refactoring how we represent types to be more like chalk, where we would have some type Have to stop now, but there would be other possibilities too. (e.g., extending |
This comment has been minimized.
This comment has been minimized.
No, I think I was wrong and didn't quite understand correctly (good to write things out, I suppose). In particular, In any case, the core problem is still (in my mind) one of namespaces: The "public signature" of an In some cases, the body of the MIR is also expressed in terms of the generics G. But in other cases (notably drop-glue) the body of the MIR is expressed in terms of the generics G1. This is causing use ICEs and confusion because we do the wrong substitutions. In particular, the example of For the moment, we are documenting this situation and working around it, but not changing the underlying mismatch. Fixing that underlying mismatch is desirable but hard -- i.e., a longer term proposition -- and that is precisely what this issue represents. |
codegen/mir: support polymorphic `InstanceDef`s cc rust-lang#69925 This PR modifies the use of `subst_and_normalize_erasing_regions` on parts of the MIR bodies returned from `instance_mir`, so that `InstanceDef::CloneShim` and `InstanceDef::DropGlue` (where there is a type) do not perform substitutions. This avoids double substitutions and enables polymorphic `InstanceDef`s. r? @eddyb cc @nikomatsakis
codegen/mir: support polymorphic `InstanceDef`s cc rust-lang#69925 This PR modifies the use of `subst_and_normalize_erasing_regions` on parts of the MIR bodies returned from `instance_mir`, so that `InstanceDef::CloneShim` and `InstanceDef::DropGlue` (where there is a type) do not perform substitutions. This avoids double substitutions and enables polymorphic `InstanceDef`s. r? @eddyb cc @nikomatsakis
…nstancedef-fnptrshim, r=nikomatsakis shim: monomorphic `FnPtrShim`s during construction Fixes rust-lang#69925. This PR adjusts MIR shim construction so that substitutions are applied to function pointer shims during construction, rather than during codegen (as determined by `substs_for_mir_body`). r? @eddyb
…nstancedef-fnptrshim, r=nikomatsakis shim: monomorphic `FnPtrShim`s during construction Fixes rust-lang#69925. This PR adjusts MIR shim construction so that substitutions are applied to function pointer shims during construction, rather than during codegen (as determined by `substs_for_mir_body`). r? @eddyb
…nstancedef-fnptrshim, r=nikomatsakis shim: monomorphic `FnPtrShim`s during construction Fixes rust-lang#69925. This PR adjusts MIR shim construction so that substitutions are applied to function pointer shims during construction, rather than during codegen (as determined by `substs_for_mir_body`). r? @eddyb
…nstancedef-fnptrshim, r=nikomatsakis shim: monomorphic `FnPtrShim`s during construction Fixes rust-lang#69925. This PR adjusts MIR shim construction so that substitutions are applied to function pointer shims during construction, rather than during codegen (as determined by `substs_for_mir_body`). r? @eddyb
#69036 papers over a problem in the use of MIR shim bodies, (i.e. applying
Instance
'ssubsts
), by preventingInstance::resolve
from succeeding if any substitution could later occur.A MIR shim's body already encapsulates the final types (i.e. monomorphic for codegen, modulo "polymorphization" work), so we shouldn't substitute it any further (in codegen, miri, or MIR inlining).
Once we address this, we could inline (or codegen, given "polymorphization") slightly polymorphic variants of these shims, but
Instance::resolve
would still need to enforce the minimum requirements for the shim MIR body being built in the first place, i.e.:Instance::resolve(drop_in_place::<T>)
should returnNone
Instance::resolve(drop_in_place::<Vec<T>>)
could succeedcc @nikomatsakis @davidtwco
The text was updated successfully, but these errors were encountered: