Skip to content

enhancement: self-host compositional set helpers in stdlib #59

Description

@vycdev2

Summary

Move the compositional set helpers set.is_empty, set.union, set.intersection, and set.difference from hardcoded checker/interpreter cases into an exported compiler-shipped .jett set module while preserving their current generic signatures, membership results, and iteration-derived result order. Keep equality, storage, and cardinality operations as Rust-backed kernels.

Source documentation

Current state

The four helpers are implemented and behaviorally covered, but there is no stdlib/set.jett. Their public generic signatures remain hardcoded in jett_typecheck, and their bodies remain Rust match arms in jett_comptime.

The language can express this bounded slice compositionally:

  • is_empty[T] can compare the retained set.length[T] kernel with zero.
  • union[T] can start with the left set and add each right-side item through the retained set.add[T] kernel.
  • intersection[T] and difference[T] can iterate the left set and select items through the retained set.contains[T] kernel.

The existing interpreter stores sets in insertion order. Source implementations should preserve the current observable order when results are later passed to set.to_list: union keeps left-side order before novel right-side items, while intersection and difference retain left-side order.

Scope

Includes:

  • Add an exported namespace set stdlib source surface for is_empty, union, intersection, and difference.
  • Remove only those four redundant checker signatures and interpreter bodies.
  • Preserve generic inference, explicit type arguments, membership behavior, deduplication, and the current iteration-derived result order.
  • Add regression coverage proving normal builds and symbol/signature queries resolve the migrated helpers from compiler-shipped set source.
  • Keep standard-library progress, design, and architecture documentation aligned with the resulting boundary.

Explicitly excludes:

  • Reimplementing the foundational set.new, set.add, set.remove, set.contains, or set.length equality/storage kernels.
  • Migrating set.to_list or defining a new language-level set ordering guarantee.
  • Changing set ownership, equality/hashability rules, generic inference, namespace/import rules, or the trusted stdlib-origin design tracked by design: define module imports and trusted stdlib origins #3.
  • HIR, MIR, native runtime, or code-generation work.

Acceptance criteria

  • Compiler-shipped stdlib source exports generic set.is_empty, set.union, set.intersection, and set.difference with their existing signatures.
  • Empty, disjoint, overlapping, duplicate-add, and result-order cases pass for inferred and explicit generic calls.
  • The four helpers no longer have hardcoded public signatures in jett_typecheck or Rust execution bodies in jett_comptime.
  • set.new, set.add, set.remove, set.contains, set.length, and set.to_list remain explicit Rust-backed kernels.
  • Project and dependency code still cannot reopen the builtin set namespace.
  • A focused query or loader regression identifies the compiler-shipped set source as the definition location for at least one migrated helper.
  • docs/design.md, docs/architecture.md, and docs/progress.md distinguish source-hosted set helpers from retained kernels.
  • cargo fmt --check, cargo build, and cargo test -q pass.

Dependencies / open questions

Coordinate builtin-type namespace handling with PR #56 and issue #57 so string, list, and set use one narrow compiler-shipped rule rather than parallel special cases. This work must not broaden or resolve the module/import/trusted-origin policy in #3.

This was generated by an AI agent (vycdev2). Please verify any changes before merging or applying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions