From d4569cb5046882dd5d4c8f3b187d167119186fa5 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 22 Oct 2022 23:55:21 +0300 Subject: feat(tvix/eval): initial attempt at setting lambda names When compiling a lambda, take the name of the outer slot (if available) and store it as the name on the lambda. These names are then shown in the observer, and nowhere else (so far). It is of course common for these things to thread through many different context levels (e.g. `f = a: b: c: ...`), in this setup only the outermost closure or thunk gains the name, but it's better than nothing. Change-Id: I681ba74e624f2b9e7a147144a27acf364fe6ccc7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7065 Reviewed-by: grfn Autosubmit: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/value/function.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'tvix/eval/src/value') diff --git a/tvix/eval/src/value/function.rs b/tvix/eval/src/value/function.rs index bb33e2962ad5..f282928df9f9 100644 --- a/tvix/eval/src/value/function.rs +++ b/tvix/eval/src/value/function.rs @@ -2,6 +2,7 @@ use std::{collections::HashMap, hash::Hash, rc::Rc}; use codemap::Span; +use smol_str::SmolStr; use crate::{chunk::Chunk, upvalues::Upvalues}; @@ -38,10 +39,15 @@ impl Formals { /// OpThunkSuspended referencing it. At runtime `Lambda` is usually wrapped /// in `Rc` to avoid copying the `Chunk` it holds (which can be /// quite large). -#[derive(Debug, PartialEq)] +#[derive(Debug, Default, PartialEq)] pub struct Lambda { pub(crate) chunk: Chunk, + /// Name of the function (equivalent to the name of the + /// identifier (e.g. a value in a let-expression or an attribute + /// set entry) it is located in). + pub(crate) name: Option, + /// Number of upvalues which the code in this Lambda closes /// over, and which need to be initialised at /// runtime. Information about the variables is emitted using @@ -51,14 +57,6 @@ pub struct Lambda { } impl Lambda { - pub fn new_anonymous() -> Self { - Lambda { - chunk: Default::default(), - upvalue_count: 0, - formals: None, - } - } - pub fn chunk(&mut self) -> &mut Chunk { &mut self.chunk } -- cgit 1.4.1