Skip to content

stage1 and the release compiler resolve a bare Target differently: comptime match Target.os with only use std.sysinfo is ok on stage1 and 'runtime value is not available at comptime' on the release compiler #2248

Closed

Description

@ehartford

Found 2026-10-07 on PR #2247 (f366957). Same sources, two compiler generations, different resolution:

use std.sysinfo
const B: i32 = comptime match Target.os:
    .Windows => 4
    .Macos => 8
    .Linux => 8
    .Wasi => 4
fn main: print(B)
  • out/bootstrap/bin/with-stage1 run: prints 8.
  • out/release/bin/with run: error: runtime value is not available at comptime at Target.os.
  • With use std.os.Target added (as test/behavior/behav_d91_target_constants.w spells it) both accept it.

So without the explicit import, Target resolves to two different declarations in the two generations (the release compiler embeds the bundles and interfaces stage1 does not; something registered there shadows or precedes std.os.Target for a bare name, or stage1 reaches std.os through a path the release does not). Whichever is right, the two must agree: a fixpoint compiler cannot accept a program its own child rejects. Route: WITH_DEBUG_IMPORTS=1 on both, then --dump-resolved for Target on both, and the D70 last-import-wins rule decides which declaration a bare Target names.

Activity

  1. added
    bug
    on Oct 7, 2026
  2. ehartford commented on Oct 7, 2026

    @ehartford
    ContributorAuthor

    Root cause and partial fix on PR (branch next-fixes): stage1 compiles std.re from source, so the corpus's use std.libc loads std.libc and std.os; the release serves the corpus as an interface and loads neither. Modules loaded only through a corpus are now corpus-private (record_engine_corpora fixpoint) and refused by decl_visible_from_current, and both visibility walks respect the corpus boundary (D39 §3.4). Verified: a runtime let t = Target is refused on both generations.

    Still open, pre-existing on both generations whenever the module is loaded: (1) the comptime match Target.os subject resolves the const through the evaluator without the visibility gate; (2) a bare TargetDescription { .. } resolves through lookup_named_type_filtered's path-less-candidate fallback (global_tid), which no gate sees. Both are §18.1 enforcement gaps: a name reaches a module only through its own use.

  3. ehartford commented on Oct 7, 2026

    @ehartford
    ContributorAuthor

    Landed in 60e53a2 (stack #2251): corpus-private std modules (record_engine_corpora → corpus_private_modules; decl_visible_from_current refuses them to user code), the fallback bridge requires an engine twin plus exactly one non-engine non-private std module (the ambience probe is gone), and with analyze f.w 'explain:visible:<name>' / explain:modules print every candidate with its rule and walk edges. Still open, two lookups that do not go through the gate: the comptime-match subject (the evaluator reads a const through the resolver binding) and the path-less type candidate (global_tid fallback in lookup_named_type_filtered).

  4. ehartford commented on Oct 7, 2026

    @ehartford
    ContributorAuthor

    Closed by f1b3eb0 (PR #2254) on top of 60e53a2 (PR #2251). The generation divergence had two halves: (1) std.os loaded only through a corpus on stage1 — now corpus-private and refused (#2251); (2) the evaluator's own lookups bypassed Sema's visibility gate: find_module_let_decl scanned every module's let by name and static_type_expr/eval_field_access read the flat type table, so comptime match HIDDEN through a module never imported printed a value while print(HIDDEN) beside it was refused, on every generation. Both now ask the gate (decl_node_visible_from_current, lookup_named_type_visible), a comptime-if failure reports the evaluator's reason, and a pub type an unimported module declares is named. Fixtures: test/compile_errors/err_2248_comptime_{let,type}_not_transitive.w. On stage1 the original program now refuses exactly as the release does ('Target' requires an explicit import (§18.1); add: use std.os.Target). What remains is not this bug: §18.2 tier 5 is still the interim std-walk stand-in that depends on the loaded set (#752, D29 work item 3).

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions