From: Robert Griesemer Date: Wed, 3 Nov 2021 19:39:43 +0000 (-0700) Subject: cmd/compile/internal/types2: implement compiler helper functions without using under X-Git-Tag: go1.18beta1~553 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2cf85b1fb8b3b6629b834016735ddeaaf7b96fda;p=gostls13.git cmd/compile/internal/types2: implement compiler helper functions without using under These functions are exported for the compiler and are used after type checking is finished. There is no need to call under() in their implementations; they can rely entirely on the public API. This opens the door to moving them into the compiler eventually. They may also be slightly more efficient. Change-Id: Ib4f83d2dcf82e3c319c3147e01ecaea684553ea5 Reviewed-on: https://go-review.googlesource.com/c/go/+/361214 Trust: Robert Griesemer Reviewed-by: Robert Findley --- diff --git a/src/cmd/compile/internal/types2/type.go b/src/cmd/compile/internal/types2/type.go index 33d3d3642c..300c81f5fa 100644 --- a/src/cmd/compile/internal/types2/type.go +++ b/src/cmd/compile/internal/types2/type.go @@ -81,10 +81,32 @@ func asTypeParam(t Type) *TypeParam { return u } -// Exported for the compiler. +// Helper functions exported for the compiler. +// These functions assume type checking has completed +// and Type.Underlying() is returning the fully set up +// underlying type. Do not use internally. -func AsPointer(t Type) *Pointer { return asPointer(t) } -func AsNamed(t Type) *Named { return asNamed(t) } -func AsSignature(t Type) *Signature { return asSignature(t) } -func AsInterface(t Type) *Interface { return asInterface(t) } -func AsTypeParam(t Type) *TypeParam { return asTypeParam(t) } +func AsPointer(t Type) *Pointer { + u, _ := t.Underlying().(*Pointer) + return u +} + +func AsNamed(t Type) *Named { + u, _ := t.(*Named) + return u +} + +func AsSignature(t Type) *Signature { + u, _ := t.Underlying().(*Signature) + return u +} + +func AsInterface(t Type) *Interface { + u, _ := t.Underlying().(*Interface) + return u +} + +func AsTypeParam(t Type) *TypeParam { + u, _ := t.Underlying().(*TypeParam) + return u +}