Skip to content

fix: provide builtin ABS monomorphs for unsigned types - #1850

Open
ghaith wants to merge 1 commit into
release/1.0.xfrom
fix/abs_unsigned_1.0.x
Open

fix: provide builtin ABS monomorphs for unsigned types#1850
ghaith wants to merge 1 commit into
release/1.0.xfrom
fix/abs_unsigned_1.0.x

Conversation

@ghaith

@ghaith ghaith commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Calling ABS with an unsigned argument (USINT/UINT/UDINT/ULINT) resolved to a monomorph the standard library does not provide. The resolver synthesized an external declaration, the shared object carried an undefined symbol, and the call crashed at runtime.

ABS__USINT/ABS__UINT/ABS__UDINT/ABS__ULINT are now builtins:

  • the generic resolver binds e.g. ABS(UINT#1) to ABS__UINT through its normal find_pou lookup — no resolver changes needed
  • their codegen returns the argument unchanged (|x| = x for unsigned values)
  • each call reports the new warning E150 ("ABS on a value of unsigned type 'UINT' has no effect") — an unsigned ABS call is almost always a mistake, e.g. an argument expression that already underflowed

Signed and float arguments are untouched and still call the library implementations.

Notes for review

  • Builtin validation is now dispatched under the resolved call name in addition to the flat AST name (guarded against double dispatch when they match), so the warning and the argument-count check fire for generic calls that bind to a builtin.
  • generate_implementation_stubs skips builtin implementations so no dead declare @ABS__UINT lands in the IR.
  • E150 matches the code used on master; the registry documents the E142..E149 gap reserved for later branches.
  • One pre-existing snapshot shifted (builtin_functions_named_arguments_invalid_parameter_names): its E037 message embeds a source slice from a type declared in the concatenated <builtin> unit, sliced against the wrong file — garbage before, differently-shifted garbage now that the builtin unit contains four more declarations. Might be worth a separate issue.

Master counterpart (full builtin ABS with intrinsics): #1849

Test plan

  • cargo test --workspace
  • ./scripts/build.sh --lit (default + -Onone)
  • new codegen inline snapshot, five validator unit tests, and two lit tests (abs_unsigned.st, abs_unsigned_warning.st)

🤖 Generated with Claude Code

Calling ABS with an unsigned argument bound to ABS__USINT/UINT/UDINT/ULINT,
which the standard library does not provide; the shared object carried an
undefined symbol and the call crashed at runtime. These monomorphs are now
builtins that return the argument unchanged and report the new warning E150
because the call has no effect.

Builtin validation is also dispatched under the resolved call name so the
warning and argument-count checks fire for generic calls, and stub
generation skips builtin implementations. Signed and float arguments still
call the library implementations.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Build Artifacts

🪟 Windows

Artifact Link Size
stdlib.lib Download 4.0 MB
stdlib.dll Download 0.1 MB
plc.exe Download 38.3 MB

From workflow run

🐧 Linux

Artifact Link Size
deb-x86_64 Download 10.9 MB
schema Download 0.0 MB
stdlib Download 33.5 MB
plc-x86_64 Download 43.5 MB
deb-aarch64 Download 5.4 MB
plc-aarch64 Download 43.3 MB

From workflow run

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