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

Judge type error when compiling go source code to wasm #691

Closed
elvin-du opened this issue Nov 5, 2019 · 7 comments
Closed

Judge type error when compiling go source code to wasm #691

elvin-du opened this issue Nov 5, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@elvin-du
Copy link

elvin-du commented Nov 5, 2019

My cmds are as follows。

tinygo build -target wasm -o main.wasm main.go
# main.go
main.go:33:55: cannot use length (variable of type int) as uintptr value in struct literal

my go codes as follows:

//go:export Get
func Get() {
....
	length := len([]byte("dmx"))

	str := reflect.StringHeader{Data: uintptr(ptr), Len: length}
	.....
}

reflect.StringHeader definition as follows:

type StringHeader struct {
	Data uintptr
	Len  int
}

Len type is int。

@niaow
Copy link
Member

niaow commented Nov 5, 2019

So the issues here is that the definition of StringHeader is different between Go and TinyGo at the moment. TinyGo defines StringHeader as:

type StringHeader struct {
	Data uintptr
	Len  uintptr
}

We may need to try to make some hacky workaround to get this to work. . .

@aykevl
Copy link
Member

aykevl commented Nov 5, 2019

See the documentation (emphasis mine):

StringHeader is the runtime representation of a string. It cannot be used safely or portably and its representation may change in a later release. Moreover, the Data field is not sufficient to guarantee the data it references will not be garbage collected, so programs must keep a separate, correctly typed pointer to the underlying data.

So technically the code that fails to compile is inherently unportable. However, the the only architecture where int and uintptr have a different size is on AVR. Perhaps we can change the type on non-AVR systems to be int for compatibility?

@deadprogram
Copy link
Member

I'm not sure if this is a bug exactly. What would be the correct category for this issue?

@deadprogram
Copy link
Member

What is the status of this issue/question?

@deadprogram deadprogram added the enhancement New feature or request label Jan 21, 2020
@deadprogram
Copy link
Member

I am going to close this due to age and that it is somewhat ambiguous. Please reopen if needed. Thank you.

@sananguliyev
Copy link

I have the same issue:

# github.com/cespare/xxhash
../../../go/pkg/mod/github.com/cespare/[email protected]/xxhash_unsafe.go:27:11: cannot use len(s) (value of type int) as uintptr value in assignment
../../../go/pkg/mod/github.com/cespare/[email protected]/xxhash_unsafe.go:28:11: cannot use len(s) (value of type int) as uintptr value in assignment

@aykevl
Copy link
Member

aykevl commented Jan 11, 2023

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

No branches or pull requests

5 participants