diff options
| author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2024-10-01 02:30:39 +0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-10-07 19:12:01 +0000 |
| commit | 7e2487cf65f749528c17adf95ad2a82196f48de2 (patch) | |
| tree | b462c4e17332df68960840185895145233f74cc3 /src/cmd/compile/internal/noder/reader.go | |
| parent | 6a3f39a9b856c7fd063d9bc10c1e43f074fa8867 (diff) | |
| download | go-7e2487cf65f749528c17adf95ad2a82196f48de2.tar.xz | |
cmd/compile: avoid dynamic type when possible
If the expression type is a single compile-time known type, use that
type instead of the dynamic one, so the later passes of the compiler
could skip un-necessary runtime calls.
Thanks Youlin Feng for writing the original test case.
Change-Id: I3f65ab90f041474a9731338a82136c1d394c1773
Reviewed-on: https://go-review.googlesource.com/c/go/+/616975
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/reader.go')
| -rw-r--r-- | src/cmd/compile/internal/noder/reader.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 55fbf860df..39ac1400a0 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -3242,7 +3242,11 @@ func (r *reader) exprType() ir.Node { dt := ir.NewDynamicType(pos, rtype) dt.ITab = itab - return typed(typ, dt) + dt = typed(typ, dt).(*ir.DynamicType) + if st := dt.ToStatic(); st != nil { + return st + } + return dt } func (r *reader) op() ir.Op { |
