Repository navigation
Thread.spawn passes its entry point as a C function pointer (@cdecl) - #71
Merged
Merged
Conversation
tslang_thread_spawn took the entry point as an Opaque and the caller cast the function to one, because a function-typed parameter of a declared function reached C as three pointers. The compiler's @cdecl (TypeScriptCompiler #788, TSLANG 29) makes it one: the declaration says `entry: (arg: Opaque) => u32` and the C side takes a ThreadEntry. Needs a compiler with @cdecl: an older one ignores the decorator and passes the struct. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Drops the
Opaqueworkaround inThread.spawn. That workaround was needed because a function-typed parameter of a declared function reached C as three pointers (TSLANG 29). The compiler's new@cdecldecorator, added in ASDAlexander77/TypeScriptCompiler#788, makes such a parameter a single C function pointer.lib.native.d.ts:@cdecl @nodrops declare function tslang_thread_spawn(entry: (arg: Opaque) => u32, arg: Opaque): Opaque;lib.generics.ts:tslang_thread_spawn(__thread_entry<R>, <Opaque>this.start), with no cast on the function.thread.cpp: the parameter is typedThreadEntryinstead ofvoid *plus areinterpret_cast.The generated IR is unchanged in substance:
call ptr @tslang_thread_spawn(ptr @"___thread_entry<si32>", ptr %17).Merge order: merge this after ASDAlexander77/TypeScriptCompiler#788. A compiler without
@cdeclignores the decorator and passes the three-pointer struct, soThread.spawnwould crash.Tests
These were run on Windows with the #788 compiler, release build.
check_declarations.ps1matches all 336 declarations; thread_spawn, thread_move, thread_gc_collect and atomics_wait pass under both JIT and compile.// not ownby design, unchanged from Thread.spawn / join and Atomics.wait / notify (workers tier 1) #70.🤖 Generated with Claude Code