diff --git a/modules/mesh-delivery-sdk/seatgen/form.go b/modules/mesh-delivery-sdk/seatgen/form.go index a0eae3929..ef311a3e4 100644 --- a/modules/mesh-delivery-sdk/seatgen/form.go +++ b/modules/mesh-delivery-sdk/seatgen/form.go @@ -77,15 +77,16 @@ func formsOf(m *Module, d seatdef.Definition) string { return out } -// fieldsDigest is the digest of the names and types of every value, event, accept and answer of the seat and of every -// type they reach; the field `form` itself is not counted. +// fieldsDigest is the digest of the names and types of the fields of every value, event, accept and answer of the seat +// and of every type they reach, one short digest per type (`=`, sorted, space-separated), so the compare +// tells a type whose fields changed from one added or removed whole; the field `form` itself is not counted. func fieldsDigest(tp *typer) string { kinds := map[string]*typ{} for _, t := range tp.types { kinds[t.name] = t.t } seen := map[string]bool{} - var lines []string + lines := map[string][]string{} var walk func(t *typ) var visit func(name string) walk = func(t *typ) { @@ -110,13 +111,13 @@ func fieldsDigest(tp *typer) string { return } if t.kind != "struct" { - lines = append(lines, name+" = "+goType(t, kinds, true)+" "+strings.Join(t.enum, "|")) + lines[name] = append(lines[name], "= "+goType(t, kinds, true)+" "+strings.Join(t.enum, "|")) } else { for _, f := range t.fields { if f.json == formField { continue } - lines = append(lines, fmt.Sprintf("%s.%s %s %v %s", name, f.json, goType(f.t, kinds, f.required), f.required, strings.Join(f.t.enum, "|"))) + lines[name] = append(lines[name], fmt.Sprintf("%s %s %v %s", f.json, goType(f.t, kinds, f.required), f.required, strings.Join(f.t.enum, "|"))) } } walk(t) @@ -124,9 +125,12 @@ func fieldsDigest(tp *typer) string { for _, n := range append(append([]string{}, tp.readBy...), tp.accepts...) { visit(n) } - sort.Strings(lines) - sum := sha256.Sum256([]byte(strings.Join(lines, "\n"))) - return hex.EncodeToString(sum[:]) + var out []string + for _, name := range sortedKeys(lines) { + sum := sha256.Sum256([]byte(strings.Join(lines[name], "\n"))) + out = append(out, name+"="+hex.EncodeToString(sum[:6])) + } + return strings.Join(out, " ") } // writeForms writes the seat's forms and the digest of its fields. @@ -164,8 +168,9 @@ var ( digestLine = goregexp.MustCompile(`generatedFieldsDigest\s*=\s*"([^"]*)"`) ) -// formUnraised says whether a contract the tree holds was generated from other fields at the same forms as the one -// written now: a definition whose fields changed with its form unchanged (design 47 H2 §780). A contract in the tree +// formUnraised says whether a contract the tree holds was generated at the same forms as the one written now from a +// type whose fields differ: a definition whose fields changed with its form unchanged (design 47 H2 §780). A type +// added or removed whole changes no reader's value. A contract in the tree // that carries no digest yet (generated before forms) is not judged. func formUnraised(dir, p string, want []byte) (bool, error) { got, err := os.ReadFile(filepath.Join(dir, p)) @@ -177,5 +182,19 @@ func formUnraised(dir, p string, want []byte) (bool, error) { if of == nil || od == nil || nf == nil || nd == nil { return false, nil } - return string(od[1]) != string(nd[1]) && string(of[1]) == string(nf[1]), nil + if string(of[1]) != string(nf[1]) { + return false, nil + } + old := map[string]string{} + for _, kv := range strings.Fields(string(od[1])) { + k, v, _ := strings.Cut(kv, "=") + old[k] = v + } + for _, kv := range strings.Fields(string(nd[1])) { + k, v, _ := strings.Cut(kv, "=") + if was, ok := old[k]; ok && was != v { + return true, nil + } + } + return false, nil }