From c445c7d0d846ede33cd773c7aaa7b6646f34a71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 5 May 2024 17:06:57 +0100 Subject: [PATCH] internal/core/debug: simplify label code following a TODO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support for `::` definitions has been gone since February 2023 via https://cuelang.org/cl/546886. Signed-off-by: Daniel Martí Change-Id: I7de49b46f43fef95feb62e95b2ec53e12870ef05 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194287 Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo Reviewed-by: Marcel van Lohuizen --- internal/core/debug/compact.go | 6 ++--- internal/core/debug/debug.go | 43 ++++++++++++++-------------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/internal/core/debug/compact.go b/internal/core/debug/compact.go index 760ab89c19b..deac6a2cf48 100644 --- a/internal/core/debug/compact.go +++ b/internal/core/debug/compact.go @@ -117,16 +117,14 @@ func (w *compactPrinter) node(n adt.Node) { w.string("]") case *adt.Field: - s := w.labelString(x.Label) - w.string(s) + w.label(x.Label) w.string(x.ArcType.Suffix()) w.string(":") w.node(x.Value) case *adt.LetField: w.string("let ") - s := w.labelString(x.Label) - w.string(s) + w.label(x.Label) if x.IsMulti { w.string("m") } diff --git a/internal/core/debug/debug.go b/internal/core/debug/debug.go index 9563823ac56..97356b7fb78 100644 --- a/internal/core/debug/debug.go +++ b/internal/core/debug/debug.go @@ -86,7 +86,22 @@ func (w *printer) string(s string) { } func (w *printer) label(f adt.Feature) { - w.string(w.labelString(f)) + switch { + case f.IsHidden(): + ident := f.IdentString(w.index) + if pkgName := f.PkgID(w.index); pkgName != "_" { + ident = fmt.Sprintf("%s(%s)", ident, pkgName) + } + w.string(ident) + + case f.IsLet(): + ident := f.RawString(w.index) + ident = strings.Replace(ident, "\x00", "#", 1) + w.string(ident) + + default: + w.string(f.SelectorString(w.index)) + } } func (w *printer) ident(f adt.Feature) { @@ -129,26 +144,6 @@ func (w *printer) printShared(v *adt.Vertex) (x *adt.Vertex, ok bool) { return v, false } -// TODO: fold into label once :: is no longer supported. -func (w *printer) labelString(f adt.Feature) string { - switch { - case f.IsHidden(): - ident := f.IdentString(w.index) - if pkgName := f.PkgID(w.index); pkgName != "_" { - ident = fmt.Sprintf("%s(%s)", ident, pkgName) - } - return ident - - case f.IsLet(): - ident := f.RawString(w.index) - ident = strings.Replace(ident, "\x00", "#", 1) - return ident - - default: - return f.SelectorString(w.index) - } -} - func (w *printer) shortError(errs errors.Error) { for { msg, args := errs.Msg() @@ -360,8 +355,7 @@ func (w *printer) node(n adt.Node) { w.string("\n]") case *adt.Field: - s := w.labelString(x.Label) - w.string(s) + w.label(x.Label) w.string(x.ArcType.Suffix()) w.string(":") w.string(" ") @@ -369,8 +363,7 @@ func (w *printer) node(n adt.Node) { case *adt.LetField: w.string("let ") - s := w.labelString(x.Label) - w.string(s) + w.label(x.Label) if x.IsMulti { w.string("multi") }