Skip to content

Commit 162851b

Browse files
cjhopmanfacebook-github-bot
authored andcommitted
Add back the third parameter to Evaluator
Summary: This actually existed before and was removed > 3 years ago with the reasoning: "It didn't really let you do anything more, since the value was &'a AnyLifetime<'e>, so 'e couldn't outlive 'a. At the same time, you could pick the 'a freely, so you didn't ever need them to be different." That's only true though when the type we put there is covariant in 'e. If it's invariant (like if it holds a `RefCell<&'e mut X>`) then it cannot fit easily there without a separate lifetime. Reviewed By: JakobDegen Differential Revision: D54214064 fbshipit-source-id: 162e12e007f794c0ea3aaaaf2af4f281e8ca396d
1 parent 2e547de commit 162851b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+242
-210
lines changed

starlark/src/assert/assert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn asserts_star(builder: &mut crate::environment::GlobalsBuilder) {
139139
fn fails<'v>(
140140
f: Value<'v>,
141141
msg: &str,
142-
eval: &mut Evaluator<'v, '_>,
142+
eval: &mut Evaluator<'v, '_, '_>,
143143
) -> anyhow::Result<NoneType> {
144144
let _ = msg;
145145
match f.invoke_pos(&[], eval) {

starlark/src/debug/adapter/implementation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct DapAdapterEvalHookImpl {
8787

8888
fn evaluate_expr<'v>(
8989
state: &SharedAdapterState,
90-
eval: &mut Evaluator<'v, '_>,
90+
eval: &mut Evaluator<'v, '_, '_>,
9191
expr: String,
9292
) -> anyhow::Result<Value<'v>> {
9393
// We don't want to trigger breakpoints during an evaluate,
@@ -106,8 +106,8 @@ fn evaluate_expr<'v>(
106106
res
107107
}
108108

109-
impl<'a> BeforeStmtFuncDyn<'a> for DapAdapterEvalHookImpl {
110-
fn call<'v>(&mut self, span_loc: FileSpanRef, eval: &mut Evaluator<'v, 'a>) {
109+
impl<'a, 'e: 'a> BeforeStmtFuncDyn<'a, 'e> for DapAdapterEvalHookImpl {
110+
fn call<'v>(&mut self, span_loc: FileSpanRef, eval: &mut Evaluator<'v, 'a, 'e>) {
111111
let stop = if self.state.disable_breakpoints.load(Ordering::SeqCst) > 0 {
112112
false
113113
} else {
@@ -175,7 +175,7 @@ impl DapAdapterEvalHookImpl {
175175
}
176176

177177
impl DapAdapterEvalHook for DapAdapterEvalHookImpl {
178-
fn add_dap_hooks<'v, 'a>(self: Box<Self>, eval: &mut Evaluator<'v, 'a>) {
178+
fn add_dap_hooks(self: Box<Self>, eval: &mut Evaluator<'_, '_, '_>) {
179179
eval.before_stmt_for_dap((self as Box<dyn BeforeStmtFuncDyn>).into());
180180
}
181181
}

starlark/src/debug/adapter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ pub fn resolve_breakpoints(
431431
/// things there).
432432
pub trait DapAdapterEvalHook: Debug + Send + 'static {
433433
/// Hooks the evaluator for this DapAdapter.
434-
fn add_dap_hooks<'v, 'a>(self: Box<Self>, eval: &mut Evaluator<'v, 'a>);
434+
fn add_dap_hooks(self: Box<Self>, eval: &mut Evaluator<'_, '_, '_>);
435435
}
436436

437437
/// The DAP capabilities that the adapter supports.

starlark/src/debug/evaluate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::syntax::AstModule;
2323
use crate::values::FrozenStringValue;
2424
use crate::values::Value;
2525

26-
impl<'v, 'a> Evaluator<'v, 'a> {
26+
impl<'v> Evaluator<'v, '_, '_> {
2727
/// Evaluate statements in the existing context. This function is designed for debugging,
2828
/// not production use.
2929
///
@@ -121,7 +121,7 @@ mod tests {
121121
fn debugger(builder: &mut GlobalsBuilder) {
122122
fn debug_evaluate<'v>(
123123
code: String,
124-
eval: &mut Evaluator<'v, '_>,
124+
eval: &mut Evaluator<'v, '_, '_>,
125125
) -> anyhow::Result<Value<'v>> {
126126
let ast = AstModule::parse("interactive", code, &Dialect::Extended)
127127
.map_err(crate::Error::into_anyhow)?;

starlark/src/debug/inspect.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) fn to_scope_names_by_local_slot_id<'v>(x: Value<'v>) -> Option<&'v [F
3333
}
3434
}
3535

36-
impl<'v, 'a> Evaluator<'v, 'a> {
36+
impl<'v> Evaluator<'v, '_, '_> {
3737
/// Obtain the local variables currently in scope. When at top-level these will be
3838
/// [`Module`](crate::environment::Module) variables, otherwise local definitions. The precise number of variables
3939
/// may change over time due to optimisation. The only legitimate use of this function is for debugging.
@@ -42,7 +42,9 @@ impl<'v, 'a> Evaluator<'v, 'a> {
4242
}
4343
}
4444

45-
fn inspect_local_variables<'v>(eval: &Evaluator<'v, '_>) -> Option<SmallMap<String, Value<'v>>> {
45+
fn inspect_local_variables<'v>(
46+
eval: &Evaluator<'v, '_, '_>,
47+
) -> Option<SmallMap<String, Value<'v>>> {
4648
// First we find the first entry on the call_stack which contains a Def (and thus has locals)
4749
let xs = eval.call_stack.to_function_values();
4850
let names = xs
@@ -62,7 +64,7 @@ fn inspect_local_variables<'v>(eval: &Evaluator<'v, '_>) -> Option<SmallMap<Stri
6264
Some(res)
6365
}
6466

65-
fn inspect_module_variables<'v>(eval: &Evaluator<'v, '_>) -> SmallMap<String, Value<'v>> {
67+
fn inspect_module_variables<'v>(eval: &Evaluator<'v, '_, '_>) -> SmallMap<String, Value<'v>> {
6668
let mut res = SmallMap::new();
6769
for (name, slot) in eval.module_env.mutable_names().all_names_and_slots() {
6870
if let Some(v) = eval.module_env.slots().get_slot(slot) {
@@ -91,7 +93,9 @@ mod tests {
9193
Ok(eval.call_stack().into_frames().map(ToString::to_string))
9294
}
9395

94-
fn debug_inspect_variables<'v>(eval: &mut Evaluator<'v, '_>) -> anyhow::Result<Dict<'v>> {
96+
fn debug_inspect_variables<'v>(
97+
eval: &mut Evaluator<'v, '_, '_>,
98+
) -> anyhow::Result<Dict<'v>> {
9599
let mut sm = SmallMap::new();
96100
for (k, v) in eval.local_variables() {
97101
sm.insert_hashed(eval.heap().alloc_str(&k).get_hashed(), v);

starlark/src/eval/bc/bytecode.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Bc {
9494
#[inline(always)]
9595
pub(crate) fn run<'v, EC: EvaluationCallbacks>(
9696
&self,
97-
eval: &mut Evaluator<'v, '_>,
97+
eval: &mut Evaluator<'v, '_, '_>,
9898
ec: &mut EC,
9999
) -> Result<Value<'v>, EvalException> {
100100
debug_assert!(eval.current_frame.is_inititalized());
@@ -117,21 +117,21 @@ impl Bc {
117117
/// Execute one instruction.
118118
#[cfg_attr(not(debug_assertions), inline(always))]
119119
fn step<'v, 'b, EC: EvaluationCallbacks>(
120-
eval: &mut Evaluator<'v, '_>,
120+
eval: &mut Evaluator<'v, '_, '_>,
121121
ec: &mut EC,
122122
frame: BcFramePtr<'v>,
123123
ip: BcPtrAddr<'b>,
124124
) -> InstrControl<'v, 'b> {
125125
let opcode = ip.get_opcode();
126126
// println!("{}: {:?}", self.current_ip, opcode);
127127

128-
struct HandlerImpl<'v, 'a, 'y, 'b> {
129-
eval: &'y mut Evaluator<'v, 'a>,
128+
struct HandlerImpl<'v, 'a, 'e, 'y, 'b> {
129+
eval: &'y mut Evaluator<'v, 'a, 'e>,
130130
frame: BcFramePtr<'v>,
131131
ip: BcPtrAddr<'b>,
132132
}
133133

134-
impl<'v, 'a, 'y, 'b> BcOpcodeHandler<InstrControl<'v, 'b>> for HandlerImpl<'v, 'a, 'y, 'b> {
134+
impl<'v, 'a, 'e, 'y, 'b> BcOpcodeHandler<InstrControl<'v, 'b>> for HandlerImpl<'v, 'a, 'e, 'y, 'b> {
135135
#[cfg_attr(not(debug_assertions), inline(always))]
136136
fn handle<I: BcInstr>(self) -> InstrControl<'v, 'b> {
137137
let HandlerImpl { eval, frame, ip } = self;
@@ -147,7 +147,7 @@ fn step<'v, 'b, EC: EvaluationCallbacks>(
147147
/// Execute the code block, either a module, a function body or a loop body.
148148
// Do not inline this function because it is called from two places: function and loop.
149149
pub(crate) fn run_block<'v, EC: EvaluationCallbacks>(
150-
eval: &mut Evaluator<'v, '_>,
150+
eval: &mut Evaluator<'v, '_, '_>,
151151
ec: &mut EC,
152152
mut ip: BcPtrAddr,
153153
) -> Result<Value<'v>, EvalException> {

starlark/src/eval/bc/frame.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,12 @@ unsafe impl<'v> Trace<'v> for BcFramePtr<'v> {
319319
}
320320

321321
#[inline(always)]
322-
fn alloca_raw<'v, 'a, R>(
323-
eval: &mut Evaluator<'v, 'a>,
322+
fn alloca_raw<'v, 'a, 'e, R>(
323+
eval: &mut Evaluator<'v, 'a, 'e>,
324324
local_count: u32,
325325
max_stack_size: u32,
326326
max_loop_depth: LoopDepth,
327-
k: impl FnOnce(&mut Evaluator<'v, 'a>, BcFramePtr<'v>) -> R,
327+
k: impl FnOnce(&mut Evaluator<'v, 'a, 'e>, BcFramePtr<'v>) -> R,
328328
) -> R {
329329
assert_eq!(mem::align_of::<BcFrame>() % mem::size_of::<usize>(), 0);
330330
assert_eq!(mem::size_of::<Value>(), mem::size_of::<usize>());
@@ -349,12 +349,12 @@ fn alloca_raw<'v, 'a, R>(
349349
///
350350
/// After callback finishes, previous frame is restored.
351351
#[inline(always)]
352-
pub(crate) fn alloca_frame<'v, 'a, R>(
353-
eval: &mut Evaluator<'v, 'a>,
352+
pub(crate) fn alloca_frame<'v, 'a, 'e, R>(
353+
eval: &mut Evaluator<'v, 'a, 'e>,
354354
local_count: u32,
355355
max_stack_size: u32,
356356
loop_depth: LoopDepth,
357-
k: impl FnOnce(&mut Evaluator<'v, 'a>) -> R,
357+
k: impl FnOnce(&mut Evaluator<'v, 'a, 'e>) -> R,
358358
) -> R {
359359
alloca_raw(
360360
eval,

starlark/src/eval/bc/instr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(crate) trait BcInstr: Sized + 'static {
4444

4545
/// Execute the instruction.
4646
fn run<'v, 'b>(
47-
eval: &mut Evaluator<'v, '_>,
47+
eval: &mut Evaluator<'v, '_, '_>,
4848
frame: BcFramePtr<'v>,
4949
ip: BcPtrAddr<'b>,
5050
arg: &Self::Arg,

0 commit comments

Comments
 (0)