Repository navigation
Call a C math function by the name that is actually emitted (#590 part 1) - #603
Merged
Merged
Conversation
…t 1)
`import "stdlib/math.flow"` then `sin(x)` reached clang as
call to undeclared function 'sin_f32'
Two sites name a function and they disagreed. The definition site uses
_mangled_names, which deliberately keeps `sin` plain and emits no definition
at all, because libm provides it. The call site re-derived the name: when the
overload resolver returns the plain name, the loop matching it against
mangled overload names finds nothing, and the implicit-effect-args fallback
then takes the sole overload's mangled name. So the call said sin_f32 while
nothing declared or defined it.
The registered name is now applied once, after the overload is settled, so
both sites agree by construction rather than by two rules staying in step.
Four documentation examples move to verified. sin(pi/2) prints 1.000000.
Also dedupes the conditional POSIX includes: three externs mapping to
unistd.h emitted `#include <unistd.h>` three times.
Part of #590. The pthread half of that issue is not fixed here and is
genuinely harder: Flow's bindings model pthread_t as i64, which is a pointer
on macOS. Including <pthread.h> turns "pthread_mutex_init undeclared" into
"conflicting types for pthread_create", and not including it breaks
tests/lang/test_pthread.flow, which obtains the header another way. It needs
the binding to model pthread_t honestly, not an include tweak.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
Part of #590.
import "stdlib/math.flow"thensin(x)reached clang as:Two sites named a function and disagreed
The definition site uses
_mangled_names, which deliberately keepssinplain and emits no definition at all, because libm provides it.The call site re-derived the name.
resolve_callcorrectly returns the plainsin, but then the loop matching it against mangled overload names finds nothing, sotarget_overloadis None, and the implicit-effect-args fallback takes the sole overload's mangled name. The call saidsin_f32while nothing declared or defined it.The registered name is now applied once, after the overload is settled, so both sites agree by construction rather than by two rules staying in step.
sin(pi/2)prints1.000000. Four documentation examples move to verified.Also dedupes the conditional POSIX includes: three externs mapping to
unistd.hemitted#include <unistd.h>three times.What this does not fix, and why
The pthread half of #590 is genuinely harder and is left open.
pthread_mutex_initis in the skip-list as "provided by pthread.h", but nothing adds that include, so the doc example reaches clang undeclared. Adding it to the header map is the obvious fix and it does not work: Flow's bindings modelpthread_tas i64, which is a pointer on macOS. Including<pthread.h>converts a missing declaration into a conflicting one:Removing the names from the skip-list instead makes Flow declare them itself, which is self-consistent, but then
tests/lang/test_pthread.flowfails: it obtains<pthread.h>another way and the two declarations collide.So it needs the binding to model
pthread_thonestly, not an include tweak. Bolting either half in would have traded one clang error for another.Verification
pytest tests/./flow test --tier2 --strictcheck_doc_examples.py --check-ledgerruff check srcThree tests in
tests/integration/test_stdlib_c_declarations.py: the emitted name, that the program runs and prints the right value, and that a header maps in once.