]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: implement compiler helper functions without using under
authorRobert Griesemer <gri@golang.org>
Wed, 3 Nov 2021 19:39:43 +0000 (12:39 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 4 Nov 2021 02:57:53 +0000 (02:57 +0000)
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 <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/type.go

index 33d3d3642c63f7bfa4bddbdf1e7adb1f72dd636c..300c81f5fac84a6afd4004bbdb51329e160e966f 100644 (file)
@@ -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
+}