Skip to content

Bug: no_std gating leaks (builtin Vec/HashMap/async/std.io compile under --no-std) (§18.7) #458

Closed

Description

@ehartford

Summary

Close the remaining no_std tier leaks so heap, OS, async, and std-only modules cannot be used when §18.7 says they are unavailable. The compiler has a partial core/alloc/std tier model, but it relies mostly on symbol checks and misses constructed builtins, explicit std module imports, and async syntax when --no-std still leaves the runtime flag enabled.

Spec

§18.7 says --no-std / std = false keeps core primitives, ownership, Option/Result, slices, fixed arrays, tuples, ranges, pointers, comptime, c_import, panic handler support, Never, and unsafe. It excludes str/String, Vec, HashMap, Box, printing, std.io, std.fs, std.net, async fn/.await, and std.sync unless an explicit alloc/core exception is specified.

Current state

The infrastructure exists but is partial. Prelude mode switches to core or alloc when no_std is set (src/compiler/Compilation/Config.w:36). Sema has symbol-tier helpers for alloc and std (src/Sema.w:705, src/Sema.w:712, src/Sema.w:720) and validates panic handler/entry/global allocator requirements (src/SemaCheck.w:511). String literals and regex are gated (src/SemaCheck.w:2822, src/SemaCheck.w:2839, src/SemaCheck.w:2868).

The leak is that tier checks are not centralized on every surface. symbol_requires_std_tier only knows regex and print-like names (src/Sema.w:720), not modules like std.io, std.net, or std.sync. require_async_runtime only checks runtime_available (src/SemaCheck.w:30), so --no-std without --no-runtime can still allow async syntax even though §18.7 marks async as std/runtime-only. Generic/builtin collection construction can bypass simple imported-symbol checks.

Implementation plan

  1. Introduce a single tier classifier for modules, types, functions, syntax forms, and compiler intrinsics: core, alloc, or std. Do not scatter more one-off string checks.
  2. Extend module import resolution/frontend checks so explicit use std.io, use std.net, use std.fs, use std.sync, and other std-only modules fail under --no-std unless an allowed alloc/core subset is chosen.
  3. Gate syntax and builtins directly: async fn, async: blocks, .await, select await, channels, task APIs, and sync primitives should require std/runtime under §18.7, not only runtime_available.
  4. Gate generic builtins by constructed base type, not by name lookup only: Vec[T], HashMap[K,V], HashSet[T], Box[T], and owned str require alloc, and OS-backed modules require std.
  5. Preserve allowed core behavior: fixed arrays, slices, tuples, ranges, raw pointers, Option/Result, c_import, and borrowed &str literals must continue to work.
  6. Make diagnostics explicit: Vec requires alloc; use --alloc or set alloc = true with std = false, async requires std/fiber runtime, std.io requires std.
  7. Add regression coverage before broad refactors so every leak named in the original issue fails red first.

Test plan

Add compile-error tests:

  • err_no_std_vec_builtin_leak.w;
  • err_no_std_hashmap_builtin_leak.w;
  • err_no_std_async_fn_leak.w;
  • err_no_std_await_leak.w;
  • err_no_std_use_std_io_leak.w;
  • err_no_std_use_std_net_leak.w;
  • err_no_std_use_std_sync_leak.w.

Keep/extend existing no_std positives: test/behavior/behav_no_std_core_prelude.w and test/behavior/behav_no_std_alloc_prelude.w.

Add one alloc-mode positive where std = false, alloc = true permits Vec but still rejects std.io and async.

Acceptance criteria

  • Every §18.7 std-only category is rejected under core no_std.
  • Alloc no_std permits allocation-backed types only when alloc = true and allocator requirements are met.
  • OS/fiber-backed modules and syntax remain rejected under no_std.
  • Diagnostics tell users which tier is required.
  • with build && with build :fixpoint && with build :test pass.

Dependencies

None.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 18.7.1.24, 18.7.1.25, 18.7.1.28, 18.7.1.29, 18.7.1.30, 18.7.1.31.

Activity

  1. ehartford commented on Jun 13, 2026

    @ehartford
    ContributorAuthor

    Implemented in afdcb48. no_std now rejects std-only module imports from the resolved module graph, gates async syntax/declarations with a std/fiber-runtime diagnostic, and gates constructed alloc-backed builtins before unknown-type fallback. Added negative coverage for Vec, HashMap, async fn, await, std.io, std.fs, std.net, std.sync, plus alloc-mode async rejection, while preserving core/alloc no_std positives. Verification passed: build, fixpoint, full test suite, and test-green.

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