Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/next/76821.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pkg math/big, method (*Int) Divide(*Int, *Int, *Int, RoundingMode) (*Int, *Int) #76821
pkg math/big, const Trunc = 2 #76821
pkg math/big, const Trunc RoundingMode #76821
pkg math/big, const Floor = 4 #76821
pkg math/big, const Floor RoundingMode #76821
pkg math/big, const Round = 0 #76821
pkg math/big, const Round RoundingMode #76821
pkg math/big, const Ceil = 5 #76821
pkg math/big, const Ceil RoundingMode #76821
1 change: 1 addition & 0 deletions api/next/79042.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg go/constant, func StringLen(Value) int64 #79042
1 change: 1 addition & 0 deletions doc/next/6-stdlib/99-minor/go/constant/79042.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The new [StringLen] function returns the length of a string [Value]. For an [Unknown] value, the length is 0.
3 changes: 3 additions & 0 deletions doc/next/6-stdlib/99-minor/math/big/76821.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- go.dev/issue/76821 -->
[Int] now has method [Int.Divide] to compute quotient and remainder of two [Int] values.
It supports rounding modes [Trunc], [Floor], [Round] and [Ceil].
2 changes: 2 additions & 0 deletions src/cmd/compile/internal/importer/genmeth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build goexperiment.genericmethods

package importer

import (
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/noder/unified.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
)

// uirVersion is the unified IR version to use for encoding/decoding.
// Use V4 for generic methods. Revert to V3 if the GOEXPERIMENT is enabled.
// Use V4 for generic methods if the GOEXPERIMENT is enabled.
var uirVersion = func() pkgbits.Version {
if buildcfg.Experiment.GenericMethods {
return pkgbits.V3
return pkgbits.V4
}
return pkgbits.V4
return pkgbits.V3
}()

// localPkgReader holds the package reader used for reading the local
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
if isString(t) && id == _Len {
if x.mode() == constant_ {
mode = constant_
val = constant.MakeInt64(int64(len(constant.StringVal(x.val))))
val = constant.MakeInt64(constant.StringLen(x.val))
} else {
mode = value
}
Expand Down
19 changes: 9 additions & 10 deletions src/cmd/compile/internal/types2/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ func (check *Checker) overflow(x *operand, opPos syntax.Pos) {
return
}

const maxLen = int(2e9) // cmd/internal/obj.MaxSymSize
// Disable the length check for now, as calling constant.StringVal
// eagerly constructs the string and can lead to significant memory
// usage increase. We may want a StringLen function.
// TODO(go.dev/issue/78346): reenable the check.
if false && x.val.Kind() == constant.String && len(constant.StringVal(x.val)) > maxLen {
check.errorf(atPos(opPos), InvalidConstVal, "constant string too long (%d bytes > %d bytes)",
len(constant.StringVal(x.val)), maxLen)
x.val = constant.MakeUnknown()
return
// String values must not become arbitrarily long (go.dev/issue/78346).
const maxLen = int64(2e9) // cmd/internal/obj.MaxSymSize
if x.val.Kind() == constant.String {
len := constant.StringLen(x.val)
if len > maxLen {
check.errorf(atPos(opPos), InvalidConstVal, "constant string too long (%d bytes > %d bytes)", len, maxLen)
x.val = constant.MakeUnknown()
return
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
if isString(typ) {
valid = true
if x.mode() == constant_ {
length = int64(len(constant.StringVal(x.val)))
length = constant.StringLen(x.val)
}
// an indexed string always yields a byte value
// (not a constant) even if the string and the
Expand Down Expand Up @@ -302,7 +302,7 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
}
valid = true
if x.mode() == constant_ {
length = int64(len(constant.StringVal(x.val)))
length = constant.StringLen(x.val)
}
// spec: "For untyped string operands the result
// is a non-constant value of type string."
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83
golang.org/x/arch v0.23.1-0.20260109160903-657d90bd6695
golang.org/x/build v0.0.0-20260122183339-3ba88df37c64
golang.org/x/mod v0.35.0
golang.org/x/mod v0.36.1-0.20260513122029-343ee60345a1
golang.org/x/sync v0.20.0
golang.org/x/sys v0.44.0
golang.org/x/telemetry v0.0.0-20260409153401-be6f6cb8b1fa
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ golang.org/x/arch v0.23.1-0.20260109160903-657d90bd6695 h1:q45HsUyFzBjBk4mHGgUew
golang.org/x/arch v0.23.1-0.20260109160903-657d90bd6695/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
golang.org/x/build v0.0.0-20260122183339-3ba88df37c64 h1:BNhBATNmH/VtzGolB+ksQPPvn6ZyffiR8TmKenqNo+A=
golang.org/x/build v0.0.0-20260122183339-3ba88df37c64/go.mod h1:3QmSbNil8ZWqC94m80Glej1v8b92gYzPIQPTtSa0c+4=
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
golang.org/x/mod v0.36.1-0.20260513122029-343ee60345a1 h1:C0TwvxhsI0bHc1TbK4QEa5PCMrHiST7y/lpX4MVW3KM=
golang.org/x/mod v0.36.1-0.20260513122029-343ee60345a1/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/go/internal/modload/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1989,8 +1989,10 @@ func UpdateGoModFromReqs(ld *Loader, ctx context.Context, opts WriteOpts) (befor
// Update require blocks.
if gover.Compare(goVersion, gover.SeparateIndirectVersion) < 0 {
modFile.SetRequire(list)
} else {
} else if gover.Compare(goVersion, gover.SimplifyRequireVersion) < 0 {
modFile.SetRequireSeparateIndirect(list)
} else {
modFile.SetRequireAtMostTwo(list)
}
modFile.Cleanup()
after, err = modFile.Format()
Expand Down
155 changes: 155 additions & 0 deletions src/cmd/go/testdata/script/mod_simplify_require.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# If go.mod has go 1.27 or higher, multiple require blocks should be
# consolidated. Even those with comments.

cp go.mod.127 go.mod
go mod tidy
cmp go.mod go.mod.127tidy

# If go.mod has go 1.26, blocks with comments should be preserved.
cp go.mod.126 go.mod
go mod tidy
cmp go.mod go.mod.126tidy

-- go.mod.127 --
module example.com/m

go 1.27

require example.com/a v1.0.0

// Block comment
require (
example.com/b v1.0.0
)

// Another block comment
require (
example.com/d v1.0.0 // an inline comment
example.com/c v1.0.0 // indirect
)

// A third block comment
require (
example.com/e v1.0.0 // indirect
)

replace (
example.com/a v1.0.0 => ./a
example.com/b v1.0.0 => ./b
example.com/c v1.0.0 => ./c
example.com/d v1.0.0 => ./d
example.com/e v1.0.0 => ./e
)
-- go.mod.127tidy --
module example.com/m

go 1.27

// Block comment
//
// Another block comment
require (
example.com/a v1.0.0
example.com/b v1.0.0
example.com/d v1.0.0 // an inline comment
)

// A third block comment
require (
example.com/c v1.0.0 // indirect
example.com/e v1.0.0 // indirect
)

replace (
example.com/a v1.0.0 => ./a
example.com/b v1.0.0 => ./b
example.com/c v1.0.0 => ./c
example.com/d v1.0.0 => ./d
example.com/e v1.0.0 => ./e
)
-- go.mod.126 --
module example.com/m

go 1.26

require example.com/a v1.0.0

// Block comment
require (
example.com/b v1.0.0
example.com/d v1.0.0
)

require example.com/c v1.0.0 // indirect

replace (
example.com/a v1.0.0 => ./a
example.com/b v1.0.0 => ./b
example.com/c v1.0.0 => ./c
example.com/d v1.0.0 => ./d
example.com/e v1.0.0 => ./e
)
-- go.mod.126tidy --
module example.com/m

go 1.26

require example.com/a v1.0.0

// Block comment
require (
example.com/b v1.0.0
example.com/d v1.0.0
)

require (
example.com/c v1.0.0 // indirect
example.com/e v1.0.0 // indirect
)

replace (
example.com/a v1.0.0 => ./a
example.com/b v1.0.0 => ./b
example.com/c v1.0.0 => ./c
example.com/d v1.0.0 => ./d
example.com/e v1.0.0 => ./e
)
-- m.go --
package m
import _ "example.com/a"
import _ "example.com/b"
import _ "example.com/d"

-- a/go.mod --
module example.com/a
go 1.26
require example.com/c v1.0.0
require example.com/e v1.0.0
-- a/a.go --
package a
import _ "example.com/c"
import _ "example.com/e"

-- b/go.mod --
module example.com/b
go 1.26
-- b/b.go --
package b

-- c/go.mod --
module example.com/c
go 1.26
-- c/c.go --
package c

-- d/go.mod --
module example.com/d
go 1.26
-- d/d.go --
package d

-- e/go.mod --
module example.com/e
go 1.26
-- e/e.go --
package e
Loading
Loading