From f7c6fa709e05830cad484422f04f2b123f54a3dc Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 21 Aug 2025 09:28:32 -0400 Subject: [PATCH] [dev.simd] simd/_gen/unify: fix some missing environments There were a couples places where we failed to provide a reasonable variable environment for YAML encoding. I think this only affects encoding "!repeat" nodes, which aren't common in practice and a bit of a disaster, which is how this went unnoticed. Change-Id: I1a37c00d5eaa1ee8e86d119a2fd73f6a28d69008 Reviewed-on: https://go-review.googlesource.com/c/go/+/698115 Auto-Submit: Austin Clements Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI --- src/simd/_gen/unify/trace.go | 2 ++ src/simd/_gen/unify/yaml.go | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/simd/_gen/unify/trace.go b/src/simd/_gen/unify/trace.go index b0aa35255e..d28e9b6f87 100644 --- a/src/simd/_gen/unify/trace.go +++ b/src/simd/_gen/unify/trace.go @@ -132,10 +132,12 @@ func (t *tracer) traceUnify(v, w *Value, e envSet) { return } + t.enc.e = e // Interpret values w.r.t. e t.logf("Unify\n%s\nwith\n%s\nin\n%s", yamlf(" ", t.enc.value(v)), yamlf(" ", t.enc.value(w)), yamlf(" ", t.enc.env(e))) + t.enc.e = envSet{} if t.saveTree { if t.node == nil { diff --git a/src/simd/_gen/unify/yaml.go b/src/simd/_gen/unify/yaml.go index dadcd71dd7..a7a1d986e4 100644 --- a/src/simd/_gen/unify/yaml.go +++ b/src/simd/_gen/unify/yaml.go @@ -316,6 +316,9 @@ func (dec *yamlDecoder) value(node *yaml.Node) (vOut *Value, errOut error) { // Undo any effects on the environment. We *do* keep any named // variables that were added to the vars map in case they were // introduced within the element. + // + // TODO: If we change how we implement repeat nodes, we might be + // able to drop yamlEncoder.env and yamlDecoder.env. dec.env = origEnv // Add a generator function gen = append(gen, func(e envSet) (*Value, envSet) { @@ -444,7 +447,7 @@ func (c Closure) String() string { } func (v *Value) MarshalYAML() (any, error) { - enc := &yamlEncoder{} + enc := &yamlEncoder{e: topEnv} return enc.value(v), nil } -- 2.52.0