Skip to content

t27c: const inlining drops the declared u64 type, shift lowers as u32 #13369

Open

Description

@gHashTag

Observed 2026-11-08 on branch lane/t27l-core (commit 2457ab7), for specs/t27os/t27t.t27 fn tt_range_mask before that commit. Refs #6092 (open epic: t27c silent misreads to zero). The self-host epic #5980 is closed.

Const inlining loses the declared type. const one : u64 = 1; m = m | (one << k); lowered to (@as(u32, 1) << @intCast(k)) in generated Zig: the width was re-invented from the literal magnitude (1 fits u32) instead of taken from the const's declared u64. So k >= 32 panics in a debug test run, and would wrap or truncate in release. Silent misread. Workaround in the spec: (@as(u64, 1) << @as(u6, @intCast(k))). Related: the declared-type path for let initializers already exists (zig_declared_int_type); the const-inlined use site does not consult it.

Repro (not run: gen is not run on the bench Mac; the observed instance is named above):

module m
const one : u64 = 1;
pub fn mask(k: u32) -> u64 {
    var m : u64 = 0;
    m = m | (one << k);
    return m;
}
test mask_high { assert mask(40) == 1099511627776; }
endmodule

Boundary

  • bootstrap/src/compiler.rs :: fn zig_int_literal_default_type
  • bootstrap/src/compiler.rs :: fn zig_declared_int_type

User Scenarios

  • Given a module const declared u64, when it is used as the left side of a runtime shift, then the generated Zig pins the left side to u64.
  • Given a const with no declared integer type, when it is shifted, then the magnitude default is unchanged.

Requirements

  • FR-001: a const-inlined use MUST carry the const's declared integer type into the shift lowering.
  • FR-002: the shift amount MUST be cast to the log2 width of the left side type so k >= 32 does not trap.

Success Criteria

  • The repro test mask_high passes in a debug test run with 0 panics.
  • The generated Zig contains 0 occurrences of @as(u32, 1) << for that fn.
  • t27c test-report specs/t27os/t27t.t27 reports FAIL 0 and vacuous passes 0 with the spec's explicit @as(u64, 1) workaround reverted to const one : u64 = 1;, and t27b test specs/t27os/t27t.t27 --check --quiet ends in exit 0.

Activity

  1. added
    shape-refusedClosed by the issue-shape gate (specs/policy/issue_shape.t27); a passing edit reopens it
    on Nov 8, 2026
  2. github-actions commented on Nov 8, 2026

    @github-actions
    Contributor

    Closed by the issue-shape gate (specs/policy/issue_shape.t27, #7498): an issue must have the template's sections. Edit the body; an edit that passes reopens it.

    • missing: ## Success Criteria -- an outcome a machine can settle: a number with a unit, a backticked file, exit 0, or a backticked command
  3. removed
    shape-refusedClosed by the issue-shape gate (specs/policy/issue_shape.t27); a passing edit reopens it
    on Nov 8, 2026
  4. github-actions commented on Nov 8, 2026

    @github-actions
    Contributor

    The shape check passes now (specs/policy/issue_shape.t27); reopened.

  5. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Covered by specs/tri/compiler_issues.t27 (typecheck OK, 1 test pass).

  6. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Reopened: closed as spec-only. A specification/test scaffold exists, but the required production implementation, integration test, and CI verification are absent. This issue remains open until the target component implements the specified behavior and evidence is provided.

  7. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Spec exists and passes typecheck + tests. M2 milestone complete.

  8. gHashTag commented on Nov 18, 2026

    @gHashTag
    CollaboratorAuthor

    Reopened: closed as spec-only. A .t27 spec was created but no production implementation, integration test, or CI verification exists. This issue remains open until the target component implements the specified behavior and evidence is provided.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions