-
Notifications
You must be signed in to change notification settings - Fork 911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add stubs for more unimplemented reflect methods #2574
Conversation
// Method represents a single method. | ||
type Method struct { | ||
// Name is the method name. | ||
Name string | ||
|
||
// PkgPath is the package path that qualifies a lower case (unexported) | ||
// method name. It is empty for upper case (exported) method names. | ||
// The combination of PkgPath and Name uniquely identifies a method | ||
// in a method set. | ||
// See https://golang.org/ref/spec#Uniqueness_of_identifiers | ||
PkgPath string | ||
|
||
Type Type // method type | ||
Func Value // func with receiver as first argument | ||
Index int // index for Type.Method | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from Go source
if e.Kind == 0 { | ||
return "reflect: call of " + e.Method + " on zero Value" | ||
} | ||
return "reflect: call of " + e.Method + " on " + e.Kind.String() + " Value" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from Go source
src/reflect/value.go
Outdated
@@ -187,7 +187,7 @@ func (v Value) Bool() bool { | |||
return uintptr(v.value) != 0 | |||
} | |||
default: | |||
panic(&ValueError{"Bool"}) | |||
panic(&ValueError{Method: "Bool"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how all the spacing got messed up here. Happy to fix this up if this is something you'd like to merge.
@@ -788,10 +788,14 @@ type stringHeader struct { | |||
|
|||
type ValueError struct { | |||
Method string | |||
Kind Kind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to match the ValueError from Go
src/reflect/type.go
Outdated
// panic("unimplemented: (reflect.Type).PkgPath()") | ||
return "<unimplemented>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need this to return a string for protocol buffers to work, but I'm happy to put the panic back in so the code at least compiles.
Copying source from upstream is fine, just make sure the file has copyright headers. I haven't looked at reflect, so I'm not the person to comment, but: |
Do you also plan to implement reflect methods required by gob? https://tinygo.org/docs/reference/lang-support/stdlib/#encodinggob |
Will do, not sure how unimplemented methods are currently tested.
I do not. If you look at my change, I'm not implementing any methods, only adding unimplemented stubs so that the default code generated by protoc compiles. That code will still fail at runtime. |
Oh, I didn't realize you were just adding stubs. Changed title to reflect what you said. You can add smoke tests that only verify compilation, and I've done that before, but I'm not sure it's worth it in this case. |
@dkegel-fastly Would it be possible to approve the 3 workflows for this PR? I'd like to know if my change passes all the tests. |
that is kind of a surprising failure... |
7063e0e
to
ff89b75
Compare
@dkegel-fastly I've rebased on the latest dev, can you approve the tests again? |
Great, looks like all the tests are passing. Anything else I need to do to get this merged in? |
Check with @dgryski, he may have suggestions. In slack, he wrote "I wonder if stubbing more of reflect would allow text/template to build and be used for simple things (that don't use the bits we faked)". I just checked tinygo building example_test.go from upstream's text/template against dev and against your branch. Resulting errors (ones you got rid of are marked with a dash):
Whew. Well, getting text/template to build its example_test.go means stubbing another ten methods. That's a lot. Is there some open source package that your patch rescues? That might help. |
Yes! This patch, combined with https://github.com/planetscale/vtprotobuf, allows tinygo programs to use Protocol Buffers*. I'm also happy to add stubs for the rest of those methods if it will mean this gets merged.
|
ff89b75
to
5619df0
Compare
Closing in favor of #2624. |
I'm current working on solving #447 by getting https://github.com/protocolbuffers/protobuf-go to compile with TinyGo. In combination with https://github.com/planetscale/vtprotobuf, I think there's a chance I get the code generated by protoc to compile and run without any changes.
This is my first attempt to "implement" some of the missing methods in the reflect package. This is my first time contributing to TinyGo, so I have no idea if I'm doing things correctly. Please let me know!
I've included some code copied directly from the Go source code. Is this allowed? How do I mark that code?