@@ -52,28 +52,28 @@ explained in terms of how it works in a `const` context.
52
52
## Caller Location in ` const `
53
53
54
54
There are two main phases to returning the caller location in a const context: walking up the stack
55
- to find it and allocating a const value to return.
55
+ to find the right location and allocating a const value to return.
56
+
57
+ ### Finding the right ` Location `
56
58
57
59
In a const context we "walk up the stack" from where the intrinsic is invoked, stopping when we
58
60
reach the first function call in the stack which does * not* have the attribute. This walk is in
59
- [ ` InterpCx::find_closest_untracked_caller_location() ` ] [ const-find-closest ] which returns
60
- ` Option<Span> ` .
61
-
62
- If the caller of the current function is untracked, it returns ` None ` . We use the span for the
63
- intrinsic's callsite in this case.
61
+ [ ` InterpCx::find_closest_untracked_caller_location() ` ] [ const-find-closest ] .
64
62
65
- Otherwise it searches by iterating in reverse over [ ` Frame ` ] [ const-frame ] s in the [ InterpCx::stack] ,
63
+ Starting at the bottom, we iterate up over stack [ ` Frame ` ] [ const-frame ] s in the [ InterpCx::stack] ,
66
64
calling [ ` InstanceDef::requires_caller_location ` ] [ requires-location ] on the
67
- [ ` Frame::instance ` ] [ frame-instance ] 's def until it finds a ` false ` return. It then returns the span
68
- of the prior still-tracked frame which is the "topmost" tracked function.
65
+ [ ` Instance ` s from each ` Frame ` ] [ frame-instance ] . We stop once we find one that returns ` false ` and
66
+ return the span of the * previous* frame which was the "topmost" tracked function.
67
+
68
+ ### Allocating a static ` Location `
69
69
70
- We use the same code in both contexts to allocate a static value for each ` Location ` . This is
71
- performed by the [ ` TyCtxt::const_caller_location() ` ] [ const-location-query ] query. Internally this
72
- calls [ ` InterpCx::alloc_caller_location() ` ] [ alloc-location ] and results in a unique
70
+ Once we have a ` Span ` we need to allocate static memory for the ` Location ` , which is performed by
71
+ the [ ` TyCtxt::const_caller_location() ` ] [ const-location-query ] query. Internally this calls
72
+ [ ` InterpCx::alloc_caller_location() ` ] [ alloc-location ] and results in a unique
73
73
[ memory kind] [ location-memory-kind ] . The SSA codegen backend is able to emit code for these same
74
- values.
74
+ values, and we use this code there as well. .
75
75
76
- Once our location has been allocated in static memory we return a pointer to it.
76
+ Once our ` Location ` has been allocated in static memory, our intrinsic returns a reference to it.
77
77
78
78
## Generating code for ` #[track_caller] ` callees
79
79
@@ -157,8 +157,8 @@ probably the best we can do without modifying fully-stabilized type signatures.
157
157
158
158
The ` #[track_caller] ` attribute is checked alongside other codegen attrs to ensure the function:
159
159
160
- * is not a foreign import (e.g. in an ` extern {...} ` block)
161
160
* has ` "Rust" ` ABI (as opposed to ` "C" ` , etc...)
161
+ * is not a foreign import (e.g. in an ` extern {...} ` block)
162
162
* is not a closure
163
163
* is not ` #[naked] `
164
164
@@ -168,13 +168,13 @@ used in both const and codegen contexts to ensure correct propagation.
168
168
169
169
### Traits
170
170
171
- When applied to a trait method prototype , the attribute takes effect on all implementations of the
172
- trait method. When applied to a default trait method implementation, the attribute takes effect on
173
- that implementation * and * any overrides. It is valid to apply the attribute to a regular
174
- implementation of a trait method, regardless of whether the defining trait does. It is a no-op to
175
- apply the attribute to trait methods with the attribute in the trait definition, but a valid one .
171
+ When applied to trait method implementations , the attribute works as it does for regular functions.
172
+
173
+ When applied to a trait method prototype, the attribute applies to all implementations of the
174
+ method. When applied to a default trait method implementation, the attribute takes effect on
175
+ that implementation * and * any overrides .
176
176
177
- Example :
177
+ Examples :
178
178
179
179
``` rust
180
180
#![feature(track_caller)]
0 commit comments