Skip to content

Call a C math function by the name that is actually emitted (#590 part 1) - #603

Merged
godofecht merged 1 commit into
mainfrom
fix-math-call-name
Aug 19, 2026
Merged

godofecht merged 1 commit into
mainfrom
fix-math-call-name

Conversation

@godofecht

@godofecht godofecht commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Part of #590. import "stdlib/math.flow" then sin(x) reached clang as:

call to undeclared function 'sin_f32'

Two sites named a function and 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. resolve_call correctly returns the plain sin, but then the loop matching it against mangled overload names finds nothing, so target_overload is None, and the implicit-effect-args fallback takes the sole overload's mangled name. 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.

before:  float x = sin_f32((3.14159 / 2.0));
after:   float x = sin((3.14159 / 2.0));

sin(pi/2) prints 1.000000. Four documentation examples move to verified.

Also dedupes the conditional POSIX includes: three externs mapping to unistd.h emitted #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_init is 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 model pthread_t as i64, which is a pointer on macOS. Including <pthread.h> converts a missing declaration into a conflicting one:

error: conflicting types for 'pthread_create'
error: incompatible pointer to integer conversion assigning to 'int64_t' from 'pthread_t'

Removing the names from the skip-list instead makes Flow declare them itself, which is self-consistent, but then tests/lang/test_pthread.flow fails: it obtains <pthread.h> another way and the two declarations collide.

So it needs the binding to model pthread_t honestly, not an include tweak. Bolting either half in would have traded one clang error for another.

Verification

Check Result
pytest tests/ 1701 passed, 6 skipped
./flow test --tier2 --strict 691/691
check_doc_examples.py --check-ledger no new unverified, 219
ruff check src clean

Three 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.

…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]>
@godofecht
godofecht merged commit 822e0af into main Aug 19, 2026
22 checks passed
@godofecht
godofecht deleted the fix-math-call-name branch August 19, 2026 22:55
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.

1 participant