Skip to content
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

Support fuction reflect for wasm #575

Open
TerryGuo opened this issue Sep 20, 2019 · 14 comments
Open

Support fuction reflect for wasm #575

TerryGuo opened this issue Sep 20, 2019 · 14 comments
Labels
enhancement New feature or request reflection Needs further work on reflection

Comments

@TerryGuo
Copy link

Hi there,

We are trying to implement function reflect for wasm target. It seems wasm has some limitations stopping us to do so. Do you guys have any thoughts on this topic? Or is this an impossible mission?

BR,
Terry

By fucntion reflect, I mean code like below:

package main

import "reflect"

func foo(x int) int {
	return x
}

func bar(f reflect.Value) {
	in := []reflect.Value{reflect.ValueOf(12345)}
	out := f.Call(in)
	println(out[0].Int())
}

func main() {
	f := reflect.ValueOf(foo)
	bar(f)
}
@niaow
Copy link
Member

niaow commented Sep 20, 2019

We do not currently support using reflection for function calls. This should eventually be supported, but this is one of the more complex pieces of functionality in reflect and nobody has quite gotten around to it. It is possible that this could be implemented by having the compiler generate wrappers.

@deadprogram deadprogram added the enhancement New feature or request label Sep 20, 2019
@TerryGuo
Copy link
Author

Thanks Jaden. We will give your suggestion a try.

@kwunyeung
Copy link

I got the following errors while compiling. Does it relate to this issue?

# encoding/asn1
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:537:47: v.Type().NumMethod undefined (type reflect.Type has no field or method NumMethod)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:549:14: DeepEqual not declared by package reflect
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:558:14: DeepEqual not declared by package reflect
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:479:93: t.Field(startingField).Tag.Get undefined (type string has no field or method Get)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:483:103: t.Field(i + startingField).Tag.Get undefined (type string has no field or method Get)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/common.go:174:26: t.Name undefined (type reflect.Type has no field or method Name)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:658:80: ifaceType.NumMethod undefined (type reflect.Type has no field or method NumMethod)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:810:115: fieldType.Name undefined (type reflect.Type has no field or method Name)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:831:12: Copy not declared by package reflect
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:919:104: field.Tag.Get undefined (type string has no field or method Get)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:932:12: Copy not declared by package reflect

@niaow
Copy link
Member

niaow commented Sep 24, 2019

No that is a seperate issue - reflect is incomplete and anything relying on complex functionality is unlikely to work yet

@northka
Copy link

northka commented Mar 11, 2020

I got the following errors while compiling. Does it relate to this issue?

# encoding/asn1
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:537:47: v.Type().NumMethod undefined (type reflect.Type has no field or method NumMethod)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:549:14: DeepEqual not declared by package reflect
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:558:14: DeepEqual not declared by package reflect
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:479:93: t.Field(startingField).Tag.Get undefined (type string has no field or method Get)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/marshal.go:483:103: t.Field(i + startingField).Tag.Get undefined (type string has no field or method Get)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/common.go:174:26: t.Name undefined (type reflect.Type has no field or method Name)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:658:80: ifaceType.NumMethod undefined (type reflect.Type has no field or method NumMethod)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:810:115: fieldType.Name undefined (type reflect.Type has no field or method Name)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:831:12: Copy not declared by package reflect
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:919:104: field.Tag.Get undefined (type string has no field or method Get)
../../../../usr/local/Cellar/[email protected]/1.12.9/libexec/src/encoding/asn1/asn1.go:932:12: Copy not declared by package reflect

I met the same problem
hope to fixed the problem faster

@aykevl
Copy link
Member

aykevl commented Mar 11, 2020

@northka I've started work on that in #907.

@deadprogram
Copy link
Member

Since the issue from #907 was solved differently can this issue now be closed?

@dgryski
Copy link
Member

dgryski commented Mar 23, 2023

WASI (and tinygo in general) now supports reflection.

@aykevl
Copy link
Member

aykevl commented May 3, 2023

@dgryski I don't think this is actually fixed: the bug is about .Call() which is not yet supported.

@dgryski
Copy link
Member

dgryski commented May 3, 2023

Oh good point. I was responding to the second issue about encoding/asn1.

@deadprogram
Copy link
Member

This is part of the v0.28 release so now closing this issue. Thanks!

@deadprogram deadprogram removed the next-release Will be part of next release label Jun 14, 2023
@aykevl
Copy link
Member

aykevl commented Jun 17, 2023

It's not actually fixed yet in 0.28, function calls in reflect are not yet supported.

@aykevl aykevl reopened this Jun 17, 2023
@Sexual
Copy link

Sexual commented Oct 20, 2023

Any updated plans to support reflect.FuncOf? This is something we really need.

@deadprogram deadprogram added the reflection Needs further work on reflection label May 1, 2024
@T-J-A
Copy link

T-J-A commented Jul 16, 2024

Is there any movement on this? This is something I'd really love to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request reflection Needs further work on reflection
Projects
None yet
Development

No branches or pull requests

9 participants