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

refactor reflect.SliceHeader uses to allow tinygo cross-compilation #2161

Merged
merged 6 commits into from
Mar 28, 2024

Conversation

orsinium
Copy link
Contributor

@orsinium orsinium commented Mar 25, 2024

The Len and Cap fields of reflect.SliceHeader are int in Go and uintptr in TinyGo. The PR adjusts all places that set these fields to be compatible with both Go and TinyGo.

Related issue: #1854

Signed-off-by: gram <git@orsinium.dev>
Signed-off-by: gram <git@orsinium.dev>
@ncruces
Copy link
Collaborator

ncruces commented Mar 25, 2024

Do we need this now that we floor on 1.20?
I've been meaning to do a pass on APIs like unsafe.SliceData.

Signed-off-by: gram <git@orsinium.dev>
@orsinium
Copy link
Contributor Author

Do we need this now that we floor on 1.20?

What does it mean? Do you ask me? Sorry, I'm out of the loop. I build my changes on top of the latest main branch.

I've been meaning to do a pass on APIs like unsafe.SliceData.

It would be great to get rid of it eventually since it is deprecated but I'd be glad if we can get Wazero compiling to TinyGo without blocking it with refactoring. The fork we have for TinyGo is already far behind the upstream, and keeping it up-to-date is hard.

@ncruces
Copy link
Collaborator

ncruces commented Mar 25, 2024

What does it mean? Do you ask me? Sorry, I'm out of the loop. I build my changes on top of the latest main branch.

wazero has a policy of supporting current Go version minus 2. Today, that means Go 1.20.

unsafe.SliceData was introduced in 1.20. It couldn't be used when the reflect.SliceHeader code was originally written, but it can now.

Does TinyGo support unsafe.SliceData? If so, that's the correct change. I don't mind doing that change myself if it helps you. But maybe this doesn't apply to all cases where reflect.SliceHeader is being used.

Copy link
Collaborator

@ncruces ncruces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK… so, I'm sorry.

I see that in most places were using the deprecated reflect.SliceHeader to skirt around a go vet warning: possible misuse of unsafe.Pointer.

So we need to pick our poison. If we do stick with reflect.SliceHeader, we should remove the TODOs for updating to unsafe.Slice.

I'm still pretty sure this is skirting around the rules, not fixing anything, otherwise this would be a fine way to avoid the "you're reviving a uintptr which might break the GC and you really shouldn't" problems we were having.

Anyway, this is a longer, hairier, discussion which shouldn't block this PR.

internal/wasm/memory.go Outdated Show resolved Hide resolved
internal/engine/wazevo/backend/isa/amd64/stack.go Outdated Show resolved Hide resolved
@orsinium
Copy link
Contributor Author

@ncruces applied code suggestions ✅

@evacchi
Copy link
Contributor

evacchi commented Mar 28, 2024

since reflect_{go,tinygo}.go are new I think we can rename reflect_go.go to reflect.go so that it is clearer that's the default

Signed-off-by: gram <git@orsinium.dev>
@orsinium
Copy link
Contributor Author

Applied suggestion ✅

@evacchi evacchi changed the title Tinygo support for places that use reflect.SliceHeader refactor reflect.SliceHeader uses to allow tinygo cross-compilation Mar 28, 2024
@evacchi
Copy link
Contributor

evacchi commented Mar 28, 2024

merging this, but I am not sure why tinygo is reaching this sub-package at all. It would be worth investigating if it's possible to drop the entire surface of the compiler.

@evacchi evacchi merged commit 199c858 into tetratelabs:main Mar 28, 2024
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants