Repository navigation
Description
Summary
Moves Set/UnorderedSet from src/stdlib/set.kex to src/stdlib/data/set.kex under a shared module Data header, and adds Data.Stack and Data.Queue alongside them. Implements the "checker half" needed to make this safe:
- Publish annotated make-block methods for source-loaded opt-in modules so a bare receiver type (e.g.
Set) resolves correctly across file boundaries instead of typing asUnknown. - Resolve a bare module segment against an imported path (
Set.from(...)afterusing Data.Set) —TypeChecker::resolveModulePath(and the interpreter'sEvaluator::resolveNamespaceAlias) alias a bare name to its qualified module when ausingbrought it into scope unqualified, with literal-path-beats-alias precedence. Fixes Amakeblock inside an opt-in stdlib module is invisible to the type checker #229 for both theData.Setcase and the realNet.HTTP+Statuscase introduced by the network rewrite (Network rewrite #228).
Related: #229 (receiver typing as Unknown after a module move), #209 (route Set/UnorderedSet to ordsets/sets v2 BIFs — depends on the record layouts staying as they are).
Known limitation — BEAM lowering bug (needs follow-up)
Compiling Data.Set/Data.Stack/Data.Queue/Data.UnorderedSet to BEAM (-c/-R) fails for their own +/- operator overloads:
undefined function '+/Set,[A]'/2 in '+$generic'/2
Root cause: when the SAME receiver type overloads an operator by a non-receiver parameter's type (e.g. let +(other: Set<A>) and let +(other: [A]) both on Set), src/ir/lower.cxx merges both clauses into ONE beam function named after only the FIRST clause's signature (e.g. +/Set,Set<A>), but the separate operator dispatcher built from argumentOverloadSignatures still expects a SECOND, distinctly-named function (+/Set,[A]) that is never emitted — and even if it were, the merged function's own clause guards only test the receiver's type, not the second argument's, so the merged clauses would collide anyway. This is a genuine, narrow gap: no existing stdlib type overloads an operator this way (same receiver, differing only by the other operand's type) until this change, so it was never exercised.
Affects: ./build/kex -c/-R on spec/stdlib/data_set.spec.kex, data_stack.spec.kex, data_queue.spec.kex, data_shared_module.spec.kex, data_units_precedence.spec.kex. The tree-walk interpreter path is unaffected — make spec-stdlib passes cleanly (290 passed, 0 failed); make spec-stdlib-beam currently fails on exactly these 5 new files.
Needs its own investigation into src/ir/lower.cxx's per-clause vs. merged-function emission for argumentOverloadedMethods before +/- can be trusted on BEAM for these types.
🤖 Generated with Claude Code
Activity
akoskovacs commentedon Aug 29, 2026
Fixed on branch `fix-233-operator-overload-lowering` (based on current `main`, which now has #232 merged).
What was wrong and the fix
The reported symptom (
undefined function '+/Set,[A]'/2 in '+$generic'/2'): a make-block whose method is nested inside a file-headermodule X(as ours all are) went through a second, duplicated clause-grouping implementation insrc/ir/lower.cxx(emitMake'spushMethod, distinct from the top-levelpushFnthat already had this) that never checkedargumentOverloadedMethods— solet +(other: Set<A>)andlet +(other: [A])got merged into one BEAM function under one mangled name, silently dropping the second signature that the operator dispatcher still expected. Fixed by mirroring the top-level splitting logic there.A necessary prerequisite, uncovered getting to (1):
Set.from(...)/UnorderedSet.from(...)never resolved on BEAM at all (Undefined function: Set.from) — bare-module-alias resolution (the Amakeblock inside an opt-in stdlib module is invisible to the type checker #229 fix) only existed in the type checker and interpreter, not insrc/ir/lower.cxx's ownusing-handling. Added aregisterModuleAliaseshelper mirroringTypeChecker::resolveModulePath's three tiers (M's own last segment, immediate children, siblings sharing a parent), used by both the scoped and top-levelusinglowering paths.Two regressions found while testing (1)+(2) against the full suite, both fixed:
Net.HTTP.WebSocket'smodule WebSocket do ... end) has no direct members of its own — tier 1 was claiming the bare name before the correct child alias could. Fixed by preferring a same-named child when one exists.path.front()'s alias without checking whether the LITERAL full path was already valid, soData.Set.from(...)got rewritten toUnits.Data.Set.from(...)in a file that alsousingsUnits.Data. Fixed by trying the literal path first (the existing candidate loop already returns on first match), matching the literal-beats-alias precedence Amakeblock inside an opt-in stdlib module is invisible to the type checker #229 established elsewhere.Verification
./build/kex -c/-Rondata/set.kexstandalone: compiles and runs correctly for+/-on bothSetandUnorderedSet.make spec— 334 passing, 0 failing (no regression, including the two caught above).make spec-beam— 300 matching, 0 differing (no regression).make spec-stdlib— 290 passed, 0 failed (interpreter, unaffected).Still open, tracked separately
Getting
Set.from(...)etc. to actually resolve on BEAM exposed two further, unrelated lowering bugs that were never reachable before (the calls always failed earlier):Data.Set'sitemsfield vs.Data.UnorderedSet'sitemsmethod) misreads the field on BEAM.any?,all?,==) don't dispatch for these opt-in types on BEAM.spec/stdlib/data_set.spec.kex,data_stack.spec.kex, anddata_queue.spec.kexstill fail under-Rbecause of #234/#235, not because of anything this fix covers.data_shared_module.spec.kexpasses fully;data_units_precedence.spec.kexnow correctly resolves the precedent-path/alias distinction this issue was about, but two of its assertions still fail due to #234.🤖 Generated with Claude Code
https://claude.ai/code/session_01SbX7B795iGL8Tc66wngUxC