Skip to content

Add numeric builtins#9600

Open
lukewilliamboswell wants to merge 42 commits into
mainfrom
numeric-builtins
Open

Add numeric builtins#9600
lukewilliamboswell wants to merge 42 commits into
mainfrom
numeric-builtins

Conversation

@lukewilliamboswell

Copy link
Copy Markdown
Collaborator

Summary

  • Adds public numeric builtin families implemented so far: integer compare/predicates/bit counts/saturating arithmetic/ceil division/pow, float bit conversions/constants/classification/sqrt/pow/trig, and fractional rounding conversions.
  • Wires new explicit low-level operations through canonicalization, LIR consumers, interpreter, dev, wasm, LLVM, static exports, and wrapper tests where needed.
  • Leaves exact Dec transcendental APIs unexposed because current Dec helpers route through F64 and do not satisfy the exact-Dec requirement.

Validation

  • Focused family checks passed while developing, including builtin format/rebuild, eval filters, docs checks, wrapper tests, and backend symbol tests.
  • Full minici progressed through lint/snapshots after fixes, then failed in run-test-cli.
  • Current blocker: focused repro still fails: zig build run-test-cli -- --suite subcommands --filter "roc build wasm32 no-link succeeds for list builtins". Direct roc build --target=wasm32 --no-link --no-cache test/wasm/list_builtin_static_lib_app.roc exits 1 with no output.

lukewilliamboswell and others added 24 commits June 10, 2026 15:13
The Windows parallel CLI runner gave each test an isolated ROC_CACHE_DIR /
XDG_CACHE_HOME / ZIG_LOCAL_CACHE_DIR but left TEMP/TMP shared, so every
concurrent `roc` child used one shared `%TEMP%/roc/<version>` tree. That
shared tree plus roc's background temp-cleanup thread produced a
non-deterministic interpreter-backend access violation (exit 139) on a
random test each suite run; isolating the temp dir makes the runs
hermetic and removes the flake (verified 20+ consecutive clean runs).

This is a test-hermeticity fix. It does not change roc itself, and the
underlying roc behavior under concurrent shared-temp use is being
investigated separately.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Three Windows-specific fixes surfaced by `zig build minici`:

- dev backend: float-to-int/f32 try conversions hand-placed the float
  `val` arg in XMM0 and passed the integer args through the CallBuilder
  starting at slot 0. That matches System V (separate int/float register
  files) but not Windows x64, where float and integer args share
  positional slots, so `target_bits` landed in the wrong register and
  arrived as garbage (overflowing `target_bits - 1` in the wrapper and
  corrupting the conversion's success flag -> spurious "number is out of
  range" crash). Route the float through the CallBuilder in argument
  order on x86-64; keep the manual V0 placement on aarch64 (AAPCS).

- eval tests: add focused single-conversion regression tests for F32/F64
  floor/ceiling/round-to-int so a regression in one conversion isn't
  masked by `and` short-circuiting in the compound tests.

- dylib platform: a Windows DLL only exposes dllexport symbols, and a
  static host .lib linked into a DLL exports nothing unless its `export
  fn` API is marked dllexport. Build the dylib host with
  `-fdll-export-fns` so roc_run_app is exported (without leaking
  bundled compiler_rt), matching ELF/Mach-O export-all behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts:
#	src/backend/dev/LirCodeGen.zig
#	src/builtins/dec.zig
#	test/snapshots/arrow_qualified_functions.md
#	test/snapshots/eval/file_import_both.md
#	test/snapshots/eval/list_join_with_custom.md
#	test/snapshots/eval/nominal_record_field_access.md
#	test/snapshots/match_expr/guards_1.md
#	test/snapshots/plume_package/Color.md
#	test/snapshots/type_app_multiple_args.md
@lukewilliamboswell lukewilliamboswell marked this pull request as ready for review June 14, 2026 02:14
# Conflicts:
#	test/snapshots/annotations.md
#	test/snapshots/arrow_qualified_functions.md
#	test/snapshots/eval/file_import_both.md
#	test/snapshots/eval/issue8773_polymorphic_opaque.md
#	test/snapshots/eval/issue8783_fold_recursive_opaque.md
#	test/snapshots/eval/issue8783_simple_for_match.md
#	test/snapshots/eval/nominal_record_field_access.md
#	test/snapshots/issue/inspect_open_union.md
#	test/snapshots/match_expr/guards_1.md
#	test/snapshots/multiline_string_complex.md
#	test/snapshots/nominal_type_origin_mismatch.md
#	test/snapshots/plume_package/Color.md
#	test/snapshots/question_in_expect_err_type_unbound.md
#	test/snapshots/question_in_expect_mixed_err_types.md
#	test/snapshots/static_dispatch/Adv.md
#	test/snapshots/static_dispatch/Basic.md
#	test/snapshots/static_dispatch/BasicNoAnno.md
#	test/snapshots/static_dispatch/MethodDispatch.md
#	test/snapshots/test_nested_instantiation_crash.md
#	test/snapshots/type_alias_simple.md
#	test/snapshots/type_app_multiple_args.md
#	test/snapshots/type_app_nested.md
#	test/snapshots/type_multiple_aliases.md
# Conflicts:
#	src/backend/dev/LirCodeGen.zig
#	src/build/roc/Builtin.roc
#	src/cli/main.zig
#	src/cli/targets/arm64musl/roc_default_platform.o
#	test/snapshots/match_expr/guards_1.md
#	test/snapshots/type_app_multiple_args.md
@lukewilliamboswell lukewilliamboswell marked this pull request as draft June 15, 2026 07:35
@lukewilliamboswell

Copy link
Copy Markdown
Collaborator Author

I've discovered a number of low level things that still need to be implemented properly for LLVM specifically.

# Conflicts:
#	src/backend/dev/LirCodeGen.zig
#	src/builtins/dev_wrappers.zig
#	test/snapshots/eval/issue8783_fold_recursive_opaque.md
#	test/snapshots/match_expr/guards_1.md
#	test/snapshots/multiline_string_complex.md
#	test/snapshots/nested_try_interpolation_recursive_dispatch.md
#	test/snapshots/plume_package/Color.md
#	test/snapshots/static_dispatch/MethodDispatch.md
@lukewilliamboswell lukewilliamboswell marked this pull request as ready for review June 16, 2026 06:36
@Anton-4 Anton-4 self-assigned this Jun 16, 2026
Comment thread src/builtins/dec.zig
@Anton-4

Anton-4 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

I'm looking at the snapshot change now, it's not a typical update, something is gone that should be there.

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.

2 participants