You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: investigate relaxation of mono-checker restrictions for generic methods #81699
is not accepted by the compiler because an instantiation of T with a type X would lead to the instantiation of T with T[X] and then with T[T[X]] and so forth because when T[X] is instantiated, the method m is created, which produces (returns) the type T[T[X]] and with that all that type's methods must be created. The monomorphization checker prevents such infinite expansion by reporting an error (playground). The immediate creation of all the methods for an instantiated type is needed because the type may be used with an interface, possibly in another package, unbeknownst to the compiler, and then all methods must be present.
However, if m is written as a top-level generic function (rather than a method)
the problem disappears because T[T[X]] doesn't imply the instantiation of another function (taking that argument) unless that function is called.
The Go 1.27 release introduced generic methods. Generic methods cannot be used to satisfy interface methods (there is currently no way to declare a generic interface method). Thus, such generic methods could be modeled/implemented by the compiler as generic functions (which don't have the mono-checker restriction).
Thus it may be possible to remove the mono-checker restriction for generic methods.
Activity
gabyhelp commentedon Sep 23, 2026
Related Issues
Related Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
mrkfrmn commentedon Sep 23, 2026
Let's also link #80172, but the gist was (to me):
Suppose there is a method I'd like to have:
I could imagine users declaring unused type parameters to "opt out" of dynamic dispatch:
And this type argument introduces burden for callers.
It seems there should be some other way to constrain the method to static use.