@@ -9,6 +9,11 @@ use rustc_macros::HashStable;
99
1010use std:: fmt;
1111
12+ /// A monomorphized `InstanceDef`.
13+ ///
14+ /// Monomorphization happens on-the-fly and no monomorphized MIR is ever created. Instead, this type
15+ /// simply couples a potentially generic `InstanceDef` with some substs, and codegen and const eval
16+ /// will do all required substitution as they run.
1217#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
1318#[ derive( HashStable , Lift ) ]
1419pub struct Instance < ' tcx > {
@@ -18,10 +23,26 @@ pub struct Instance<'tcx> {
1823
1924#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
2025pub enum InstanceDef < ' tcx > {
26+ /// A user-defined callable item.
27+ ///
28+ /// This includes:
29+ /// - `fn` items
30+ /// - closures
31+ /// - generators
2132 Item ( DefId ) ,
33+
34+ /// An intrinsic `fn` item (with `"rust-intrinsic"` or `"platform-intrinsic"` ABI).
35+ ///
36+ /// Alongside `Virtual`, this is the only `InstanceDef` that does not have its own callable MIR.
37+ /// Instead, codegen and const eval "magically" evaluate calls to intrinsics purely in the
38+ /// caller.
2239 Intrinsic ( DefId ) ,
2340
24- /// `<T as Trait>::method` where `method` receives unsizeable `self: Self`.
41+ /// `<T as Trait>::method` where `method` receives unsizeable `self: Self` (part of the
42+ /// `unsized_locals` feature).
43+ ///
44+ /// The generated shim will take `Self` via `*mut Self` - conceptually this is `&owned Self` -
45+ /// and dereference the argument to call the original function.
2546 VtableShim ( DefId ) ,
2647
2748 /// `fn()` pointer where the function itself cannot be turned into a pointer.
@@ -37,27 +58,31 @@ pub enum InstanceDef<'tcx> {
3758 /// (the definition of the function itself).
3859 ReifyShim ( DefId ) ,
3960
40- /// `<fn() as FnTrait>::call_*`
61+ /// `<fn() as FnTrait>::call_*` (generated `FnTrait` implementation for `fn()` pointers).
62+ ///
4163 /// `DefId` is `FnTrait::call_*`.
4264 ///
4365 /// NB: the (`fn` pointer) type must currently be monomorphic to avoid double substitution
4466 /// problems with the MIR shim bodies. `Instance::resolve` enforces this.
4567 // FIXME(#69925) support polymorphic MIR shim bodies properly instead.
4668 FnPtrShim ( DefId , Ty < ' tcx > ) ,
4769
48- /// `<dyn Trait as Trait>::fn`, "direct calls" of which are implicitly
49- /// codegen'd as virtual calls.
70+ /// Dynamic dispatch to `<dyn Trait as Trait>::fn`.
5071 ///
51- /// NB: if this is reified to a `fn` pointer, a `ReifyShim` is used
52- /// (see `ReifyShim` above for more details on that).
72+ /// This `InstanceDef` does not have callable MIR. Calls to `Virtual` instances must be
73+ /// codegen'd as virtual calls through the vtable.
74+ ///
75+ /// If this is reified to a `fn` pointer, a `ReifyShim` is used (see `ReifyShim` above for more
76+ /// details on that).
5377 Virtual ( DefId , usize ) ,
5478
55- /// `<[mut closure] as FnOnce>::call_once`
56- ClosureOnceShim {
57- call_once : DefId ,
58- } ,
79+ /// `<[FnMut closure] as FnOnce>::call_once`.
80+ ///
81+ /// The `DefId` is the ID of the ` call_once` method in `FnOnce`.
82+ ClosureOnceShim { call_once : DefId } ,
5983
6084 /// `core::ptr::drop_in_place::<T>`.
85+ ///
6186 /// The `DefId` is for `core::ptr::drop_in_place`.
6287 /// The `Option<Ty<'tcx>>` is either `Some(T)`, or `None` for empty drop
6388 /// glue.
@@ -67,7 +92,12 @@ pub enum InstanceDef<'tcx> {
6792 // FIXME(#69925) support polymorphic MIR shim bodies properly instead.
6893 DropGlue ( DefId , Option < Ty < ' tcx > > ) ,
6994
70- ///`<T as Clone>::clone` shim.
95+ /// Compiler-generated `<T as Clone>::clone` implementation.
96+ ///
97+ /// For all types that automatically implement `Copy`, a trivial `Clone` impl is provided too.
98+ /// Additionally, arrays, tuples, and closures get a `Clone` shim even if they aren't `Copy`.
99+ ///
100+ /// The `DefId` is for `Clone::clone`, the `Ty` is the type `T` with the builtin `Clone` impl.
71101 ///
72102 /// NB: the type must currently be monomorphic to avoid double substitution
73103 /// problems with the MIR shim bodies. `Instance::resolve` enforces this.
0 commit comments