aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
diff options
context:
space:
mode:
authorMark Freeman <mark@golang.org>2026-03-26 16:30:20 -0400
committerMark Freeman <mark@golang.org>2026-03-30 08:19:14 -0700
commit3524089944a7a4ed0e0a8395a10b9a7376df4595 (patch)
tree2539c92a9f3a77c558111c10c164e570b09c6b5f /src/cmd/compile/internal/noder
parent4d1f503396fa30da1e7b841de2f464c8bf8940e0 (diff)
downloadgo-3524089944a7a4ed0e0a8395a10b9a7376df4595.tar.xz
cmd/compile/internal/noder: add is[Concrete|Generic]Method helpers
The isGenericMethod helper will be necessary for upcoming changes to UIR, though it's not currently used. Since all generic methods are concrete methods, we also define the isConcreteMethod helper to illustrate the subset relationship between the two classes of methods. We use this helper for encoding method dictionaries. Change-Id: Ib7cdd7224fc733553726c8f86c0fe59ad60bff67 Reviewed-on: https://go-review.googlesource.com/c/go/+/759781 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder')
-rw-r--r--src/cmd/compile/internal/noder/writer.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go
index 2c648d661d..6b78013d8d 100644
--- a/src/cmd/compile/internal/noder/writer.go
+++ b/src/cmd/compile/internal/noder/writer.go
@@ -2229,7 +2229,7 @@ func (w *writer) methodExpr(expr *syntax.SelectorExpr, recv types2.Type, sel *ty
w.p.fatalf(expr, "isInterface inconsistency: %v and %v", recv, sig.Recv().Type())
}
- if !isInterface(recv) {
+ if isConcreteMethod(sig) {
if named, ok := types2.Unalias(deref2(recv)).(*types2.Named); ok {
obj, targs := splitNamed(named)
info := w.p.objInstIdx(obj, targs, w.dict)
@@ -2608,6 +2608,26 @@ func isInterface(typ types2.Type) bool {
return ok
}
+// isConcreteMethod reports whether typ is a concrete method. That is,
+// it's a method with a receiver that isn't an interface type.
+func isConcreteMethod(typ types2.Type) bool {
+ sig, ok := typ.(*types2.Signature)
+ return ok && sig.Recv() != nil && !isInterface(sig.Recv().Type())
+}
+
+// TODO(mark): Use isGenericMethod. It is included now to help justify
+// the existence of isConcreteMethod.
+
+// isGenericMethod reports whether typ is a generic method. That is,
+// it's a method with type parameters apart from those which may or
+// may not appear on the receiver type.
+//
+// Note that generic methods are always concrete methods.
+func isGenericMethod(typ types2.Type) bool {
+ sig, ok := typ.(*types2.Signature)
+ return ok && sig.Recv() != nil && sig.TypeParams().Len() > 0
+}
+
// op writes an Op into the bitstream.
func (w *writer) op(op ir.Op) {
// TODO(mdempsky): Remove in favor of explicit codes? Would make