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/compiler/scope.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tvix/eval/src/compiler/scope.rs') diff --git a/tvix/eval/src/compiler/scope.rs b/tvix/eval/src/compiler/scope.rs index 9269a3c44c76..83fba6eed73c 100644 --- a/tvix/eval/src/compiler/scope.rs +++ b/tvix/eval/src/compiler/scope.rs @@ -15,6 +15,8 @@ use std::{ ops::Index, }; +use smol_str::SmolStr; + use crate::opcode::{StackIdx, UpvalueIdx}; #[derive(Debug)] @@ -71,6 +73,14 @@ impl Local { } } + /// Retrieve the name of the given local (if available). + pub fn name(&self) -> Option { + match &self.name { + LocalName::Phantom => None, + LocalName::Ident(name) => Some(SmolStr::new(name)), + } + } + /// Is this local intentionally ignored? (i.e. name starts with `_`) pub fn is_ignored(&self) -> bool { match &self.name { -- cgit 1.4.1