Skip to content

HashSet intrinsic lowering assumes HashMap shapes and breaks contains/remove #81

Closed

Description

@ehartford

Summary

HashSet intrinsic lowering is incomplete and currently reuses HashMap paths that assume map-style generic arity and argument counts. Direct HashSet operations already fail; borrowing only exposes the same underlying bug.

This was split out of #78 after investigation showed it is not the same bug as projected receiver lowering.

Spec references:

  • docs/with-specification.md §7.7 method call syntax for self: &T / self: &mut T

Minimal repros

Repro 1: direct contains fails

fn main:
    let set: HashSet[i32] = HashSet.new()
    set.insert(4)
    assert(set.contains(4))

Repro 2: direct remove/len fails

fn main:
    var set: HashSet[i32] = HashSet.new()
    set.insert(5)
    assert(set.remove(5))
    assert(set.len() == 0)

Expected

HashSet.new, insert, contains, remove, and len should work consistently for both direct and borrowed receivers.

Actual

Direct HashSet programs already fail at runtime, including contains and remove. The borrowed form in issue64_borrowed_map_set_methods.w is not a distinct receiver bug; it is another manifestation of the same intrinsic lowering problem.

Root cause

MIR classifies HashSet methods onto map intrinsics, but codegen remains HashMap-specific:

  • src/MirLower.w maps HashSet.new/insert/contains/remove/len/clear onto MIR_INTRINSIC_MAP_*
  • src/CodegenDispatch.w has no HashSet branch in classify_generic_call_intrinsic
  • MIR_INTRINSIC_MAP_NEW only handles the 2-argument HashMap[K, V] shape
  • MIR_INTRINSIC_MAP_INSERT assumes a map-style (recv, key, value) call and reads a value operand that HashSet.insert does not have
  • key/value type recovery helpers only recognize HashMap, not HashSet

Affected tests

  • test/behavior/issue64_borrowed_map_set_methods.w

Activity

  1. added a commit that references this issue on Jun 8, 2026
    abfa717
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