Skip to content

Documented str.is_empty() has no intrinsic: compiler aborts with internal BUG (core dump) #1010

Closed

Description

@eas4ai

Summary

lib/std/string.w:5 documents s.is_empty() -> bool as a built-in str method, but the method-intrinsic table has no is_empty arm. Calling it aborts the compiler with an internal-contract BUG and a core dump instead of any diagnostic.

Repro (seed stage1 at 450733e; probe .audit/probes/std_str/is_empty_ice.w)

fn main:
    let s = "x"
    print(if s.is_empty(): "empty" else: "nonempty")

check → BUG: user generic call lacks a concrete contract: body=659(main) call=0 node=6594 sig=-1 mono=0 [src/MirLower.w:14570 MirModule.validate_generic_call_contracts] then Aborted (core dumped). Re-run by primary.

Root-cause chain (verified by reading + execution)

  1. src/CodegenDispatch.w:7236-7251: the TY_STR method table maps len/byte_at/slice/contains/starts_with/ends_with/find/split/trim/to_upper/to_lower/replace/index_of/repeat — is_empty absent → returns MirIntrinsic.NONE.
  2. The unresolved method call proceeds into generic-call lowering, where MirModule.validate_generic_call_contracts (MirLower.w:14570) hits the fatal-assertion path for a missing contract — an unreachable-class abort intended for compiler bugs, here reached from ordinary user code calling a documented API.
  3. Sibling methods from the same doc block (len, contains, starts_with, find, to_upper) all resolve — only is_empty is missing, so this is a one-arm omission, not a design gap.

Severity

High: a documented one-line call core-dumps the compiler. Users cannot distinguish "unimplemented" from "broken" — and an abort loses all session diagnostics.

Suggested fix (owner's call)

Add the is_empty arm (desugar to len == 0) or remove it from the doc block; audit the remaining doc-listed methods against the table for siblings (contains/starts_with/ends_with/find/to_upper present — is_empty looks like the only gap, but verify mechanically).

Audit provenance

Read-only end-to-end audit, string-surface leg (child complete examination, independently verified by primary: doc-vs-table comparison + abort re-run). Related: #1007 (Vec intrinsic check gap — same method-table family, distinct defect).

Activity

  1. ehartford commented on Sep 16, 2026

    @ehartford
    Contributor

    Review: reproduced

    Verdict. Established on current main. lib/std/string.w documents s.is_empty() -> bool as a built-in str method, no is_empty arm exists in the str method-intrinsic table, and calling it aborts with check (and with run) with the internal-contract assertion BUG: user generic call lacks a concrete contract and rc 134. Every sibling in the same doc block that I tried resolves normally, so this is a one-arm omission, as the report says.

    Tested revision and compiler

    item value
    source main @ 5809ac1 (2026-09-14); no commit since 450733e adds an is_empty arm for str
    compiler with build of 5809ac1 in a detached worktree, self-reports with v0.15.2.1
    platform macOS Darwin 25.6.0, arm64

    Repro

    fn main:
        let s = "x"
        print(if s.is_empty(): "empty" else: "nonempty")
    
    command result
    with check ie.w BUG: user generic call lacks a concrete contract: body=744(main) call=0 node=7429 sig=-1 mono=0 [src/MirLower.w:14793 MirModule.validate_generic_call_contracts], rc 134
    with run ie.w same abort
    control: s.len() == 0, s.contains("x"), s.starts_with("x"), s.to_upper(), s.trim() false true true X x, rc 0

    Expected: either nonempty printed, or a normal unknown method 'is_empty' for type 'str' diagnostic.

    Source

    • Doc claim: lib/std/string.w:5 s.is_empty() -> bool — true if length is 0. The only is_empty definition in that file is StringBuilder.is_empty (:75), not a str method.
    • Intrinsic table: src/CodegenDispatch.w:7218-7234 maps len, byte_at, slice, contains, starts_with, ends_with, find, split, trim, to_upper/upper, to_lower/lower, replace, index_of, repeat; no is_empty. The is_empty arms that do exist (:7259, :7285, and MirLower.w:9830/:9856) are for Vec and fixed strings.
    • Abort: src/MirLower.w:14793 sema_phase_bug(...) in validate_generic_call_contracts, the compiler-bug assertion path, reached because Sema let the call through as an unresolved "generic" method and MIR lowering found no contract.

    Two defects, as the report frames them

    1. The documented method does not exist (a one-line intrinsic arm, or a str method in the stdlib, would provide it; the spec itself shows the shape at line 3764: fn is_empty() -> bool: self.len() == 0).
    2. A user program can reach a sema_phase_bug abort: an unresolved method on a builtin type should be an ordinary unknown method diagnostic before MIR lowering, the way a.n() on a struct is (Impl method arity is not checked against the trait (types are, D140): an extra parameter fails late #988's control). That is the more important half, since any other missing table arm produces the same core dump.

    Spec

    §15.1 lists str operations without is_empty; the spec uses is_empty on Vec (lines 814, 3947). So the doc block in string.w over-promises relative to both the spec and the table. Either adding the method or removing the doc line is spec-consistent; the abort is not.

    Related PRs

    None merged or open touch the str intrinsic table for this. #1007 (closed) was a different Vec table defect.

    Would I champion a fix? Yes, both halves are small.

    Acceptance criteria:

    1. s.is_empty() on str compiles and returns len() == 0 (intrinsic arm or stdlib method), with a behaviour test.
    2. Sema rejects an unresolvable method call on a builtin type with unknown method '<m>' for type '<T>' before MIR lowering; a test/compile_errors fixture calls a made-up str method and asserts the diagnostic and rc 1, never a BUG: line.
    3. A mechanical audit (a test that parses the doc block at the top of string.w and asserts each listed method resolves) so the doc and the table cannot drift again.

    Untested

    Whether other doc-listed methods beyond the five I tried also lack arms was not exhaustively checked; criterion 3 covers it. Linux and Windows not executed (pure frontend).

  2. joshhickson commented on Oct 3, 2026

    @joshhickson
    Contributor

    PR #1947 closed this automatically because its description said "Fixes #1010". That was my mistake: it fixes only the abort. The other acceptance criteria are still open (a Sema diagnostic before any phase bug, and the doc-vs-table audit), and Eric's review on #1947 says this issue stays open for them. Could it be reopened?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions