Repository navigation
feat: typed function declarations and verified direct and indirect calls - #237
Merged
Merged
Conversation
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.
Problem and result
AST programs could not express calls, and IR calls only carried a string symbol plus unchecked argument IDs. Call sites now resolve a typed function identity or a function-pointer SSA value and must match the complete signature, calling convention and result contract.
Closes #90
Closes #110
Closes #159
Implementation
FunctionId, a module declaration table, completeFunctionSignature,Whale/SysV64calling conventions, and internal/external linkage. External functions require an explicit nonemptylink_name; conflicting declarations, duplicate definitions, missing internal bodies and external-name collisions are rejected. Definitions refer to declaration IDs rather than their position in the table.begin_functionconvenience still creates an internal Whale definition.Direct(FunctionId)andIndirect(ValueId). IntroduceFnPtr(signature),FunctionAddrand typedNullFunction. Function-pointer types survive storage, parameter/return passing, phi, select and tuple extraction; invalid extraction cannot manufacture a callable type. Casts involving function-pointer types are rejected.--no-verify. Update the README, existing fixtures and empty-PATH smoke inputs.Format migration
AST format and printed typed IR format each advance from 1 to 2; semantics remain 1. Format 1 input is rejected rather than interpreted under the changed schema.
AST producers must add
program.declarations(an empty array when unused) and explicitconvention/linkageon function definitions. Internal definitions normally use"Whale"/"Internal"and no link name. External declarations/definitions need an explicitlink_name. Numeric string encodings are unchanged. The complete strict schema isir/schema/ast-v2.schema.json.Rust users must register callees and replace
Callee::Symboland caller-supplied return types with typed direct/indirect calls returningResult<Option<ValueId>, CallError>. Raw module producers must populate declaration IDs and keep definition types consistent with declarations. Printed IR exposes declarations, convention, linkage, link names and definition IDs.Boundaries
A well-typed null or invalid indirect target has a required runtime trap before entering the callee. This PR represents and verifies the IR contract; it does not add an interpreter, machine ABI lowering, native call emission, foreign callback lifetime management or runtime shadow metadata. Those execution checks remain with #67 and the execution work.
Function identity/link names are preserved at the IR boundary only. #215 remains open for typed identity through object emission and final linking. Aggregate Whale signatures are representable IR, not a claim of native aggregate ABI support. Existing uninitialized-value work (#65), strong/weak policy and complete static linking are unchanged.
Validation
The final additional regression covers
function_addrrejecting malformed signatures produced through the legacy infallible convenience API.Windows checkout correction
Both Windows all-feature jobs failed the exact printed-IR fixture assertion because Git converted
calls-v2.wirto CRLF while the printer consistently emits LF. Add*.wir text eol=lfto preserve the canonical fixture bytes on every host; keep the exact assertion and printer output unchanged.Reproduced the pre-fix conversion in an isolated checkout with
core.autocrlf=true. With the attribute applied, fresh checkout of the fixture preserves identical LF bytes forcore.autocrlf=true,false, andinput, includingcore.eol=crlf. All five call-lowering tests and diff checks passed locally. On commit4f14536c5fa419d8cd107f770888145d16d180ee, all 23 GitHub CI checks passed, including native Windows x64 and ARM64 with default and all features.