@@ -9,6 +9,11 @@ use rustc_macros::HashStable;
9
9
10
10
use std:: fmt;
11
11
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.
12
17
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
13
18
#[ derive( HashStable , Lift ) ]
14
19
pub struct Instance < ' tcx > {
@@ -18,10 +23,26 @@ pub struct Instance<'tcx> {
18
23
19
24
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
20
25
pub enum InstanceDef < ' tcx > {
26
+ /// A user-defined callable item.
27
+ ///
28
+ /// This includes:
29
+ /// - `fn` items
30
+ /// - closures
31
+ /// - generators
21
32
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.
22
39
Intrinsic ( DefId ) ,
23
40
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.
25
46
VtableShim ( DefId ) ,
26
47
27
48
/// `fn()` pointer where the function itself cannot be turned into a pointer.
@@ -37,27 +58,31 @@ pub enum InstanceDef<'tcx> {
37
58
/// (the definition of the function itself).
38
59
ReifyShim ( DefId ) ,
39
60
40
- /// `<fn() as FnTrait>::call_*`
61
+ /// `<fn() as FnTrait>::call_*` (generated `FnTrait` implementation for `fn()` pointers).
62
+ ///
41
63
/// `DefId` is `FnTrait::call_*`.
42
64
///
43
65
/// NB: the (`fn` pointer) type must currently be monomorphic to avoid double substitution
44
66
/// problems with the MIR shim bodies. `Instance::resolve` enforces this.
45
67
// FIXME(#69925) support polymorphic MIR shim bodies properly instead.
46
68
FnPtrShim ( DefId , Ty < ' tcx > ) ,
47
69
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`.
50
71
///
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).
53
77
Virtual ( DefId , usize ) ,
54
78
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 } ,
59
83
60
84
/// `core::ptr::drop_in_place::<T>`.
85
+ ///
61
86
/// The `DefId` is for `core::ptr::drop_in_place`.
62
87
/// The `Option<Ty<'tcx>>` is either `Some(T)`, or `None` for empty drop
63
88
/// glue.
@@ -67,7 +92,12 @@ pub enum InstanceDef<'tcx> {
67
92
// FIXME(#69925) support polymorphic MIR shim bodies properly instead.
68
93
DropGlue ( DefId , Option < Ty < ' tcx > > ) ,
69
94
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.
71
101
///
72
102
/// NB: the type must currently be monomorphic to avoid double substitution
73
103
/// problems with the MIR shim bodies. `Instance::resolve` enforces this.
0 commit comments