]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.simd] simd/_gen/unify: fix some missing environments
authorAustin Clements <austin@google.com>
Thu, 21 Aug 2025 13:28:32 +0000 (09:28 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 21 Aug 2025 14:49:35 +0000 (07:49 -0700)
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 <austin@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/simd/_gen/unify/trace.go
src/simd/_gen/unify/yaml.go

index b0aa35255e466b4e9b34eaabbc4cb4986765eb74..d28e9b6f879612cd0c61b88f809ce2745c1342b8 100644 (file)
@@ -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 {
index dadcd71dd7b64e3fd7a423ba53d1776b0a4e998f..a7a1d986e4cb19f2a55e70e8ce02baa91c8c10b4 100644 (file)
@@ -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
 }