From a20a3e249605cda389f7039e0fccaabf709c47b3 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 13 May 2024 16:24:53 -0400 Subject: [PATCH 1/3] x/text: update x/tools for go/ssa range-over-func fix CL 584295 added a quick fix to a panic in go/ssa when it encounters range-over-func. This CL imports that fix. A principled fix will land in CL 555075. Fixes golang/go#67348 Change-Id: I49dd63d4845d0fc804b6e7d0353584a57aea19fc Reviewed-on: https://go-review.googlesource.com/c/text/+/584977 LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov --- go.mod | 9 ++++----- go.sum | 13 ++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index ff064ec7..b49ccc63 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,8 @@ module golang.org/x/text go 1.18 -require golang.org/x/tools v0.6.0 // tagx:ignore +require golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // tagx:ignore -require ( - golang.org/x/mod v0.8.0 // indirect; tagx:ignore - golang.org/x/sys v0.5.0 // indirect; tagx:ignore -) +require golang.org/x/mod v0.17.0 // indirect; tagx:ignore + +require golang.org/x/sync v0.7.0 // indirect diff --git a/go.sum b/go.sum index 44d387ef..d046f937 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,6 @@ -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= From 59e1219a5f3786e7011dc4816d0dbb09fee91bc8 Mon Sep 17 00:00:00 2001 From: aimuz Date: Wed, 8 May 2024 09:41:50 +0000 Subject: [PATCH 2/3] message: optimize lookupAndFormat function for better performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit optimizes the lookupAndFormat function to reduce code redundancy and improve performance. Benchmarks show a significant performance increase across various Sprintf and Fprint functions. benchstat old.txt new.txt goos: darwin goarch: arm64 pkg: golang.org/x/text/message │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ SprintfPadding-12 333.0n ± 1% 216.0n ± 1% -35.15% (p=0.000 n=10) SprintfEmpty-12 307.3n ± 1% 170.9n ± 1% -44.38% (p=0.000 n=10) SprintfString-12 313.5n ± 1% 178.9n ± 2% -42.91% (p=0.000 n=10) SprintfTruncateString-12 315.6n ± 1% 182.3n ± 2% -42.23% (p=0.000 n=10) SprintfQuoteString-12 320.1n ± 0% 198.6n ± 1% -37.96% (p=0.000 n=10) SprintfInt-12 325.0n ± 1% 203.1n ± 1% -37.51% (p=0.000 n=10) SprintfIntInt-12 340.2n ± 1% 233.2n ± 2% -31.47% (p=0.000 n=10) SprintfPrefixedInt-12 335.2n ± 1% 226.2n ± 1% -32.54% (p=0.000 n=10) SprintfFloat-12 330.1n ± 1% 209.7n ± 1% -36.48% (p=0.000 n=10) SprintfComplex-12 365.1n ± 1% 276.0n ± 2% -24.41% (p=0.000 n=10) SprintfBoolean-12 311.8n ± 0% 178.6n ± 3% -42.72% (p=0.000 n=10) SprintfHexString-12 328.1n ± 1% 204.8n ± 2% -37.56% (p=0.000 n=10) SprintfHexBytes-12 334.0n ± 2% 216.4n ± 1% -35.20% (p=0.000 n=10) SprintfBytes-12 340.8n ± 7% 213.9n ± 1% -37.25% (p=0.000 n=10) SprintfStringer-12 662.5n ± 3% 453.2n ± 1% -31.59% (p=0.000 n=10) SprintfStructure-12 373.8n ± 6% 275.7n ± 1% -26.23% (p=0.000 n=10) ManyArgs-12 485.1n ± 4% 425.4n ± 1% -12.30% (p=0.000 n=10) FprintInt-12 265.8n ± 2% 262.0n ± 1% -1.41% (p=0.011 n=10) FprintfBytes-12 348.4n ± 1% 258.8n ± 1% -25.70% (p=0.000 n=10) FprintIntNoAlloc-12 262.0n ± 2% 261.2n ± 2% ~ (p=0.565 n=10) geomean 342.4n 233.7n -31.75% Change-Id: Id9999469f3fd0ca0290a5cb81f42fff81277b451 GitHub-Last-Rev: 904d624b132ac1a49cdd908e9b95ff2b16a5f7a0 GitHub-Pull-Request: golang/text#51 Reviewed-on: https://go-review.googlesource.com/c/text/+/584095 Reviewed-by: Dmitri Shuralyov Reviewed-by: Marcel van Lohuizen Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- message/message.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/message/message.go b/message/message.go index 48d76630..91a97264 100644 --- a/message/message.go +++ b/message/message.go @@ -138,21 +138,20 @@ func (p *Printer) Printf(key Reference, a ...interface{}) (n int, err error) { func lookupAndFormat(p *printer, r Reference, a []interface{}) { p.fmt.Reset(a) - var id, msg string switch v := r.(type) { case string: - id, msg = v, v + if p.catContext.Execute(v) == catalog.ErrNotFound { + p.Render(v) + return + } case key: - id, msg = v.id, v.fallback - default: - panic("key argument is not a Reference") - } - - if p.catContext.Execute(id) == catalog.ErrNotFound { - if p.catContext.Execute(msg) == catalog.ErrNotFound { - p.Render(msg) + if p.catContext.Execute(v.id) == catalog.ErrNotFound && + p.catContext.Execute(v.fallback) == catalog.ErrNotFound { + p.Render(v.fallback) return } + default: + panic("key argument is not a Reference") } } From 9c2f3a21352d1ff4e47776534e3f334b39ec0183 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Thu, 9 May 2024 19:08:14 +0000 Subject: [PATCH 3/3] cmd/gotext: fix segfault in extract & rewrite commands If extract or rewrite are called with no arguments it results in a segmentation fault, since we dereference the out flag that was not defined for these commands. Fixes golang/go#62697 Change-Id: I697943b7c221431d0361bcec74c18183f6e141ea GitHub-Last-Rev: 313ddfad2b9a43d4fbaa875fa4dd3110dcf38083 GitHub-Pull-Request: golang/text#46 Reviewed-on: https://go-review.googlesource.com/c/text/+/529255 Reviewed-by: Marcel van Lohuizen Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov --- cmd/gotext/main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/gotext/main.go b/cmd/gotext/main.go index ed0f7eca..5171eb15 100644 --- a/cmd/gotext/main.go +++ b/cmd/gotext/main.go @@ -48,11 +48,18 @@ func config() (*pipeline.Config, error) { if err != nil { return nil, wrap(err, "invalid srclang") } + + // Use a default value since rewrite and extract don't have an out flag. + genFile := "" + if out != nil { + genFile = *out + } + return &pipeline.Config{ SourceLanguage: tag, Supported: getLangs(), TranslationsPattern: `messages\.(.*)\.json$`, - GenFile: *out, + GenFile: genFile, Dir: *dir, }, nil }