Skip to content

[Self-Hosting Phase 1] Port Function Overload Resolution by Signature to Flow #677

Closed

Description

@godofecht

Scope

Port function signature matching and overload dispatch from src/flow/overload.py into compiler/src/resolve.flow and compiler/src/typecheck.flow.

Deliverables

  • Multi-signature symbol table support for functions and methods with identical names.
  • Type matching score algorithm considering exact types, subtyping ranks, and array-to-span coercions.
  • Diagnostic reporting for ambiguous overload calls.
  • Validate with tests/lang/test_unsigned_ints.flow.

Activity

  1. added
    self-hosting
    P1-high
    on Aug 21, 2026
  2. godofecht commented on Aug 22, 2026

    @godofecht
    ContributorAuthor

    Implementation note after #709: the next blocker is in Stage-A TcCtx, not the matching predicates. Today the name table stores ns/ne/nk/na, where na is a single arity for function bindings, and flowc_tc_lookup_fn_arity walks backward and returns the first same-name function. The next increment should therefore extend the native function binding metadata to retain one entry per signature (parameter type-node chain + arity), gather all same-name/arity candidates at an AST_CALL, apply the #709 two-phase matcher across argument types, then report 0/1/>1 as missing/unique/ambiguous. That is the path to the actual multi-signature symbol-table and ambiguity deliverables; merely changing lookup order would be wrong.

  3. godofecht commented on Aug 22, 2026

    @godofecht
    ContributorAuthor

    Further integration finding: Stage-A flowc_tc_check_expr currently validates calls by name + a single flowc_tc_lookup_fn_arity; it does not compute a reusable expression type for call arguments. So after the #713 multi-signature table lands, candidate selection needs a small native argument-type inference layer first (at minimum literals, bound identifiers via flowc_tc_lookup_val_type, casts, struct literals, and obvious array/span forms). Then AST_CALL can enumerate same-name/arity decls and apply #709. Trying to wire #709 directly into today's call checker would duplicate or guess type inference.

  4. godofecht commented on Aug 22, 2026

    @godofecht
    ContributorAuthor

    Post-#709 overload work is now split into concrete native layers rather than a monolithic typecheck.flow rewrite:

    Once #713/#715 land, the next integration patch can be surgical: populate the table in flowc_tc_bind_globals; at AST_CALL obtain known identifier type names from TcCtx, classify each argument, enumerate same-name/arity declarations, compare their parameter AST_TYPE spans using #709 compatibility/widening policy, and emit ambiguity/no-match diagnostics. Cross-module overload signatures remain a separate portability problem because foreign AST node ids cannot be stored in the local table.

  5. godofecht commented on Aug 22, 2026

    @godofecht
    ContributorAuthor

    Progress update on native overload resolution: #713 is merged (multi-signature same-name/arity table), #715 is merged (minimal Stage-A expression type classifier + integer-literal widening marker), and #717 is in final qualification for byte-exact AST_TYPE canonical names. #717's self-host/no-Python path is already green; its strict-corpus failure was narrowed to mutation of an immutable helper parameter and fixed at c1a931c. Explicit span mutability loss is tracked separately in #718, and reference-span canonicalization in #720, so neither semantic hole is being silently collapsed. Once #717 lands, the next patch is the direct TcCtx integration: register local overload declarations during global collection, classify/normalize AST_CALL arguments, run the #709 matching policy across #713 candidates, and report ambiguous/no-match calls while preserving the existing unknown-type sole-overload fallback.

  6. godofecht commented on Aug 25, 2026

    @godofecht
    ContributorAuthor

    Progress update (25 Aug 2026): #717 and #722 are merged. Draft #767 now isolates the remaining call-site plumbing into two small native APIs: overload_call.flow owns argument scratch/classification + selector invocation, and overload_registry.flow owns local function-table population/reset. All commits use [skip ci] and are intended for local qualification only.

    After #767, the final typecheck.flow integration is reduced to: own/init/free/reset FlowcOverloadTable; collect local declarations once per module; map AST_IDENT call args through existing flowc_tc_lookup_val_type; invoke flowc_overload_resolve_call; diagnose genuine AMBIGUOUS and known NO_MATCH; preserve UNKNOWN, intrinsics, imports, local callable values and extern fallbacks. Codegen unification remains tracked separately by #725.

  7. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Progress update: native overload binding now consumes declared identifier/cast types in addition to literals, records a selected AST_FN on AST_CALL, and cgen uses that semantic binding. Added typed-identifier regression coverage; the native/MLIR/effects suite is 60/60 and bootstrap/self-host convergence is green. Cross-module signature tables and full resolver parity remain open.

  8. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Validation update: the latest native overload binding passes the full strict language corpus (106/106), including test_unsigned_ints, test_generics, test_effects, test_spans, and test_function_as_value. Bootstrap fixed-point and self_host_full also pass. Cross-module overload signature transport remains the next unresolved scope.

  9. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    Native cross-module overload parity advanced: imported overloads now select by argument type in the bundled C path, with regression coverage for i32/f32 calls (choose_i32, choose_f32). Native duration/unit lowering was also covered alongside the self-host suite. Focused native overload/duration tests pass.

  10. godofecht commented on Sep 24, 2026

    @godofecht
    ContributorAuthor

    Completion audit (24 Sep 2026): the stated Phase-1 overload deliverables are now present on main. Native Stage-A retains multiple same-name signatures, resolves exact/typed and unsuffixed-integer widening calls, reports ambiguity/no-match, records/consumes semantic selections in the strict path, and imported overloads have i32/f32 bundle coverage. The recorded qualification includes the full strict language corpus (106/106), bootstrap fixed-point and self_host_full; test_unsigned_ints is included in that strict corpus. The remaining no-typecheck/codegen compatibility resolver is deliberately separate scope under #725 rather than a blocker for this type-system port. Closing #677 as completed; continue resolver/codegen unification in #725.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-highcompilerself-hosting

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions