feat(tvix/eval): print lambda memory adresses in disassembler

This makes it easier to track exactly which lambda is which when
inspecting e.g. the concrete representation of a thunk.

At runtime all lambdas live in an Rc. To make this print the right
address, the construction of these Rcs had to be moved up right to the
point where the lambda is first emitted (and disassembled).

Change-Id: I6070e6c8ac55f0bd697966c4e7c5565c20d19106
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6435
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2022-09-03 14:52:24 +03:00 committed by tazjin
parent d3421c1cb9
commit 48d5f4fd57
4 changed files with 30 additions and 32 deletions

View file

@ -900,19 +900,17 @@ impl Compiler<'_> {
// Pop the lambda context back off, and emit the finished
// lambda as a constant.
let compiled = self.contexts.pop().unwrap();
let lambda = Rc::new(compiled.lambda);
#[cfg(feature = "disassembler")]
{
crate::disassembler::disassemble_chunk(&compiled.lambda.chunk);
crate::disassembler::disassemble_lambda(lambda.clone());
}
// If the function is not a closure, just emit it directly and
// move on.
if compiled.lambda.upvalue_count == 0 {
self.emit_constant(
Value::Closure(Closure::new(Rc::new(compiled.lambda))),
&node,
);
if lambda.upvalue_count == 0 {
self.emit_constant(Value::Closure(Closure::new(lambda)), &node);
return;
}
@ -920,9 +918,7 @@ impl Compiler<'_> {
// number of operands that allow the runtime to close over the
// upvalues and leave a blueprint in the constant index from
// which the runtime closure can be constructed.
let blueprint_idx = self
.chunk()
.push_constant(Value::Blueprint(Rc::new(compiled.lambda)));
let blueprint_idx = self.chunk().push_constant(Value::Blueprint(lambda));
self.push_op(OpCode::OpClosure(blueprint_idx), &node);
self.emit_upvalue_data(outer_slot, compiled.scope.upvalues);
@ -955,23 +951,22 @@ impl Compiler<'_> {
self.end_scope(node);
let thunk = self.contexts.pop().unwrap();
let lambda = Rc::new(thunk.lambda);
#[cfg(feature = "disassembler")]
{
crate::disassembler::disassemble_chunk(&thunk.lambda.chunk);
crate::disassembler::disassemble_lambda(lambda.clone());
}
// Emit the thunk directly if it does not close over the
// environment.
if thunk.lambda.upvalue_count == 0 {
self.emit_constant(Value::Thunk(Thunk::new(Rc::new(thunk.lambda))), node);
if lambda.upvalue_count == 0 {
self.emit_constant(Value::Thunk(Thunk::new(lambda)), node);
return;
}
// Otherwise prepare for runtime construction of the thunk.
let blueprint_idx = self
.chunk()
.push_constant(Value::Blueprint(Rc::new(thunk.lambda)));
let blueprint_idx = self.chunk().push_constant(Value::Blueprint(lambda));
self.push_op(OpCode::OpThunk(blueprint_idx), node);
self.emit_upvalue_data(outer_slot, thunk.scope.upvalues);