8000 Move Set/UnorderedSet under Data, add Stack and Queue · Issue #233 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Move Set/UnorderedSet under Data, add Stack and Queue #233

Closed

Description

@akoskovacs

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:

  1. 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 as Unknown.
  2. Resolve a bare module segment against an imported path (Set.from(...) after using Data.Set) — TypeChecker::resolveModulePath (and the interpreter's Evaluator::resolveNamespaceAlias) alias a bare name to its qualified module when a using brought it into scope unqualified, with literal-path-beats-alias precedence. Fixes A make block inside an opt-in stdlib module is invisible to the type checker #229 for both the Data.Set case and the real Net.HTTP + Status case 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

https://claude.ai/code/session_01SbX7B795iGL8Tc66wngUxC

Activity

  1. akoskovacs commented on Aug 29, 2026

    @akoskovacs
    CollaboratorAuthor

    Fixed on branch `fix-233-operator-overload-lowering` (based on current `main`, which now has #232 merged).

    What was wrong and the fix

    1. The reported symptom (undefined function '+/Set,[A]'/2 in '+$generic'/2'): a make-block whose method is nested inside a file-header module X (as ours all are) went through a second, duplicated clause-grouping implementation in src/ir/lower.cxx (emitMake's pushMethod, distinct from the top-level pushFn that already had this) that never checked argumentOverloadedMethods — so let +(other: Set<A>) and let +(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.

    2. 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 A make block inside an opt-in stdlib module is invisible to the type checker #229 fix) only existed in the type checker and interpreter, not in src/ir/lower.cxx's own using-handling. Added a registerModuleAliases helper mirroring TypeChecker::resolveModulePath's three tiers (M's own last segment, immediate children, siblings sharing a parent), used by both the scoped and top-level using lowering paths.

    3. Two regressions found while testing (1)+(2) against the full suite, both fixed:

      • A module whose own last segment names a same-named nested constructor block (Net.HTTP.WebSocket's module 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.
      • The alias-consuming call site always substituted path.front()'s alias without checking whether the LITERAL full path was already valid, so Data.Set.from(...) got rewritten to Units.Data.Set.from(...) in a file that also usings Units.Data. Fixed by trying the literal path first (the existing candidate loop already returns on first match), matching the literal-beats-alias precedence A make block inside an opt-in stdlib module is invisible to the type checker #229 established elsewhere.

    Verification

    • ./build/kex -c/-R on data/set.kex standalone: compiles and runs correctly for +/- on both Set and UnorderedSet.
    • 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):

    spec/stdlib/data_set.spec.kex, data_stack.spec.kex, and data_queue.spec.kex still fail under -R because of #234/#235, not because of anything this fix covers. data_shared_module.spec.kex passes fully; data_units_precedence.spec.kex now 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

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0