cgen, coroutines: fix go expr handle referencing undeclared thread__tN#27379
Open
medvednikov wants to merge 1 commit into
Open
cgen, coroutines: fix go expr handle referencing undeclared thread__tN#27379medvednikov wants to merge 1 commit into
go expr handle referencing undeclared thread__tN#27379medvednikov wants to merge 1 commit into
Conversation
…__tN`
With `-use-coroutines`, a `go expr` whose handle is stored/used (e.g.
`a.worker = go a.loop()`) made cgen reference a C variable `thread__tN`
that it never declared, so the generated C failed to compile:
error: use of undeclared identifier 'thread__t2'
The coroutine branch in `spawn_and_go_expr` only emitted the
`photon_thread_create*` call, which returns void and yields no joinable
handle, yet the handle `thread_<tmp>` was still written back as the
expression's value. The Photon wrapper exposes no waitable handle, so a
`go` whose handle is actually used is now lowered to the regular `spawn`
(pthread) path, which declares and assigns `thread_<tmp>`. Plain
statement-form `go f()` keeps using the Photon work-pool path.
markused: a `go` handle that is used must mark the same thread-handle
type and pthread error helpers (`panic_error_number`,
`c_error_number_str`, ...) that `spawn` needs, otherwise `-skip-unused`
prunes them and the rerouted spawn path fails to link.
Fixes #27338
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Description
Fixes #27338.
With
-use-coroutines, ago exprwhose handle is stored/used (e.g.a.worker = go a.loop()) made cgen reference a C variablethread__tNthat it never declared:The coroutine branch in
spawn_and_go_expronly emitted thephoton_thread_create*call (which returnsvoidand yields no joinable handle), yet the handlethread_<tmp>was still written back as the expression's value.Fix
The Photon wrapper exposes no waitable handle, so a
gowhose handle is actually used (node.is_expr) is now lowered to the regularspawn(pthread) path, which declares and assignsthread_<tmp>. The generated C now contains:so it compiles and the handle is joinable via
.wait(), matching the non-coroutinespawnpath. Plain statement-formgo f()(no handle used) is unchanged and keeps using the Photon work-pool path.A companion change in
markusedis required: agohandle that is used must mark the same thread-handle type and pthread error helpers (panic_error_number,c_error_number_str, …) thatspawnneeds — otherwise-skip-unused(the default) prunes them and the rerouted spawn path fails to link withundefined symbol 'builtin__panic_error_number'.Verification
pthread_thandle (was: undeclared identifier).panic_error_number/c_error_number_strare emitted (no longer pruned).array_of_threads_wait_test.v,spawn_with_cond_fncall_test.v,generic_spawn_test.v).examples/coroutines/go_handle.vdocumenting the now-working pattern.