mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 12:03:41 +00:00
compiler: implement method-set based AssignableTo and Implements (#5304)
* reflect: implement method-set based AssignableTo and Implements Based on the design from #4376 by aykevl. Fixes #4277, fixes #3580. Co-authored-by: Ayke van Laethem <aykevanlaethem@gmail.com> * builder: update expected binary sizes for reflect changes * Make interface checks similar to invoke, allowing typeImplementsMethodSet and method info to be dropped when reflect is not present * Add more tests that BigGo reflect tests * Even more pruning * Add go/token and net/url to passing tests * Prune even further, I am less happy with this, though * Update size test now that we are smaller * Skip some tests * elide method lists * format, oops * fix tests * Add a panic, pull out constant to keep in sync * Add debug info * Remove code that was leftover from a previous refactor --------- Co-authored-by: Ayke van Laethem <aykevanlaethem@gmail.com>
This commit is contained in:
Vendored
-29
@@ -7,7 +7,6 @@ target triple = "armv7m-none-eabi"
|
||||
@"reflect/types.typeid:basic:int16" = external constant i8
|
||||
@"reflect/types.type:basic:int" = linkonce_odr constant { i8, ptr } { i8 2, ptr @"reflect/types.type:pointer:basic:int" }, align 4
|
||||
@"reflect/types.type:pointer:basic:int" = linkonce_odr constant { i8, ptr } { i8 21, ptr @"reflect/types.type:basic:int" }, align 4
|
||||
@"reflect/methods.NeverImplementedMethod()" = linkonce_odr constant i8 0
|
||||
@"reflect/methods.Double() int" = linkonce_odr constant i8 0
|
||||
@"Number$methodset" = linkonce_odr unnamed_addr constant { i32, [1 x ptr], { ptr } } { i32 1, [1 x ptr] [ptr @"reflect/methods.Double() int"], { ptr } { ptr @"(Number).Double$invoke" } }
|
||||
@"reflect/types.type:named:Number" = linkonce_odr constant { ptr, i8, ptr, ptr } { ptr @"Number$methodset", i8 34, ptr @"reflect/types.type:pointer:named:Number", ptr @"reflect/types.type:basic:int" }, align 4
|
||||
@@ -16,10 +15,7 @@ target triple = "armv7m-none-eabi"
|
||||
declare i1 @runtime.typeAssert(ptr, ptr)
|
||||
declare void @runtime.printuint8(i8)
|
||||
declare void @runtime.printint16(i16)
|
||||
declare void @runtime.printint32(i32)
|
||||
declare void @runtime.printptr(i32)
|
||||
declare void @runtime.printnl()
|
||||
declare void @runtime.nilPanic(ptr)
|
||||
|
||||
define void @printInterfaces() {
|
||||
call void @printInterface(ptr @"reflect/types.type:basic:int", ptr inttoptr (i32 5 to ptr))
|
||||
@@ -30,25 +26,6 @@ define void @printInterfaces() {
|
||||
}
|
||||
|
||||
define void @printInterface(ptr %typecode, ptr %value) {
|
||||
%isUnmatched = call i1 @Unmatched$typeassert(ptr %typecode)
|
||||
br i1 %isUnmatched, label %typeswitch.Unmatched, label %typeswitch.notUnmatched
|
||||
|
||||
typeswitch.Unmatched:
|
||||
%unmatched = ptrtoint ptr %value to i32
|
||||
call void @runtime.printptr(i32 %unmatched)
|
||||
call void @runtime.printnl()
|
||||
ret void
|
||||
|
||||
typeswitch.notUnmatched:
|
||||
%isDoubler = call i1 @Doubler$typeassert(ptr %typecode)
|
||||
br i1 %isDoubler, label %typeswitch.Doubler, label %typeswitch.notDoubler
|
||||
|
||||
typeswitch.Doubler:
|
||||
%doubler.result = call i32 @"Doubler.Double$invoke"(ptr %value, ptr %typecode, ptr undef)
|
||||
call void @runtime.printint32(i32 %doubler.result)
|
||||
ret void
|
||||
|
||||
typeswitch.notDoubler:
|
||||
%isByte = call i1 @runtime.typeAssert(ptr %typecode, ptr nonnull @"reflect/types.typeid:basic:uint8")
|
||||
br i1 %isByte, label %typeswitch.byte, label %typeswitch.notByte
|
||||
|
||||
@@ -86,10 +63,4 @@ define i32 @"(Number).Double$invoke"(ptr %receiverPtr, ptr %context) {
|
||||
|
||||
declare i32 @"Doubler.Double$invoke"(ptr %receiver, ptr %typecode, ptr %context) #0
|
||||
|
||||
declare i1 @Doubler$typeassert(ptr %typecode) #1
|
||||
|
||||
declare i1 @Unmatched$typeassert(ptr %typecode) #2
|
||||
|
||||
attributes #0 = { "tinygo-invoke"="reflect/methods.Double() int" "tinygo-methods"="reflect/methods.Double() int" }
|
||||
attributes #1 = { "tinygo-methods"="reflect/methods.Double() int" }
|
||||
attributes #2 = { "tinygo-methods"="reflect/methods.NeverImplementedMethod()" }
|
||||
|
||||
Reference in New Issue
Block a user