diff options
author | Vincent Ambo <mail@tazj.in> | 2022-10-22T20·55+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-10-23T15·58+0000 |
commit | d4569cb5046882dd5d4c8f3b187d167119186fa5 (patch) | |
tree | 21165efc7ac2f1f7d49435bdd480a66db9c16c1f /tvix/eval/src/compiler | |
parent | 1050a1d650d6304a8fe68691c2eb6042b9c3ef00 (diff) |
feat(tvix/eval): initial attempt at setting lambda names r/5186
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 <grfn@gws.fyi> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/compiler')
-rw-r--r-- | tvix/eval/src/compiler/mod.rs | 10 | ||||
-rw-r--r-- | tvix/eval/src/compiler/scope.rs | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 2ab76623864b..2985c7e90e0b 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -54,7 +54,7 @@ struct LambdaCtx { impl LambdaCtx { fn new() -> Self { LambdaCtx { - lambda: Lambda::new_anonymous(), + lambda: Lambda::default(), scope: Default::default(), captures_with_stack: false, } @@ -62,7 +62,7 @@ impl LambdaCtx { fn inherit(&self) -> Self { LambdaCtx { - lambda: Lambda::new_anonymous(), + lambda: Lambda::default(), scope: self.scope.inherit(), captures_with_stack: false, } @@ -897,7 +897,13 @@ impl Compiler<'_> { N: ToSpan, F: FnOnce(&mut Compiler, LocalIdx), { + let name = self.scope()[outer_slot].name(); self.new_context(); + + // Set the (optional) name of the current slot on the lambda that is + // being compiled. + self.context_mut().lambda.name = name; + let span = self.span_for(node); let slot = self.scope_mut().declare_phantom(span, false); self.scope_mut().begin_scope(); 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<SmolStr> { + 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 { |