diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-27T22·52+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-06T07·45+0000 |
commit | 8982e16e26b8f271c66210e6657e2d70000f3141 (patch) | |
tree | 0ab8547b824b8378b32fad2b529a2388bc00cf11 /tvix/eval/src/compiler/scope.rs | |
parent | f6de4434c3838431c8d5c0782f786c07ac46b212 (diff) |
refactor(tvix/eval): thread dynamic upvalues through all contexts r/4657
With this change, encountering a dynamic upvalue will thread through all contexts starting from the lowest context that has a non-empty `with`-stack. The additional upvalues are not actually used yet, so the effective behaviour remains mostly the same. This is done in preparation for an upcoming change, which will implement proper dynamic resolution for complex cases of nested dynamic upvalues. Yes, this whole upvalue + dynamic values thing is a little bit mind-bending, but we would like to not give up being able to resolve a large chunk of the scoping behaviour statically. Change-Id: Ia58cdd47d79212390a6503ef13cef46b6b3e19a2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6321 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to '')
-rw-r--r-- | tvix/eval/src/compiler/scope.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/tvix/eval/src/compiler/scope.rs b/tvix/eval/src/compiler/scope.rs index e295731e3258..3061e08ead25 100644 --- a/tvix/eval/src/compiler/scope.rs +++ b/tvix/eval/src/compiler/scope.rs @@ -81,7 +81,7 @@ pub enum LocalPosition { /// Represents the different ways in which upvalues can be captured in /// closures or thunks. -#[derive(Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub enum Upvalue { /// This upvalue captures a local from the stack. Stack(StackIdx), @@ -91,7 +91,14 @@ pub enum Upvalue { /// This upvalue captures a dynamically resolved value (i.e. /// `with`). - Dynamic(SmolStr), + /// + /// It stores the identifier with which to perform a dynamic + /// lookup, as well as the optional upvalue index in the enclosing + /// function (if any). + Dynamic { + name: SmolStr, + up: Option<UpvalueIdx>, + }, } /// Represents a scope known during compilation, which can be resolved |