Skip to content

std.time Duration is private but appears in pub signatures; its constructors are uncallable #1018

Closed

Description

@eas4ai

Summary

type Duration = i32 (lib/std/time.w:12) is private, yet pub async fn sleep(d: Duration) exposes it, and the documented constructors Duration.millis/from_millis/seconds/from_secs/minutes cannot be called from outside the module.

Repro (seed stage1 at 450733e; probes .audit/probes/std_misc/dur_use.w)

  • use std.time.Duration + let d: Duration = 5 → error: symbol 'Duration' is private.
  • Duration.millis(5) → error: unknown qualified extension method 'Duration.millis' (the D7 top-level placement + private type combine).
  • Control: sleep(5).await WORKS (prints, rc=0) via i32 coercion — so the module functions, but its unit abstraction is unusable: callers pass raw numbers with no way to spell milliseconds-vs-seconds intent.

Root-cause chain

Private alias + public constructors written as top-level fns that require naming the type. Either the type must go pub (and ctors attach) or the ctors must go (sleep takes i32). As-is, 5 public constructor fns are dead surface and the pub signature leaks an unnameable type.

Severity

Low-medium: dead API + unit confusion (millis vs secs spelled identically as i32 literals at call sites).

Audit provenance

Read-only end-to-end audit, std-misc leg (child examination, independently verified by primary: type/code reads + three probes). Related dead-surface kin: #981 (with_concurrency).

Activity

  1. ehartford commented on Sep 16, 2026

    @ehartford
    Contributor

    Review: reproduced

    Verdict. The central claim is established on current main: Duration is module-private, pub async fn sleep(d: Duration) exposes it, and none of the five Duration.* constructors can be called from outside std.time. One correction to the report's framing: the constructors are not "public constructor fns" at all. They are declared without pub (fn Duration.millis(...)), so they are doubly unreachable: the type they hang off is private and the functions themselves are private. The report's proposed diagnosis (private alias plus top-level ctors that require naming the type) is correct; the proposed remedies (make the type pub and the ctors pub, or delete the ctors) are the two real options.

    Additional finding. The shipped example examples/async-auction.w does not type-check for this exact reason (sleep(Duration.millis(500)).await at line 52). It has been broken since Duration was made a private alias; the example is not part of any test corpus, which is why nothing caught it.

    Tested.

    Source main @ 5809ac1 (2026-09-14); lib/std/time.w unchanged since the reported revision 450733e for all lines cited
    Compiler with v0.15.2.1 built from 5809ac1 in a staging worktree
    Platform macOS Darwin 25.6.0 arm64

    Probes (with run <file>), expected vs actual:

    Program Expected (per /// docs) Actual
    use std.time.Duration / let d: Duration = 5 compiles error: symbol 'Duration' is private to module '<embedded-std>/std/time.w'
    use std.time / Duration.millis(5) 5 same privacy error at Duration
    use std.time / sleep(Duration.seconds(1)).await sleeps 1 s same privacy error
    use std.time / sleep(5).await (control) rc 0 slept rc=0, rc 0
    with check examples/async-auction.w ok privacy error at examples/async-auction.w:52:11

    The diagnostic text differs from the one quoted in the report (symbol 'Duration' is private) only by the added module path; the behavior is the same.

    Spec and source pins (5809ac1).

    • Spec §18.3 Visibility: "pub exports names. No pub = module-private. Cross-module access to a non-pub symbol is a compile error; this applies uniformly to functions, types, constants, and globals." The compiler conforms to this rule; the defect is in the stdlib, not Sema.
    • type Duration = i32 (private) and the five non-pub fn Duration.* constructors: lib/std/time.w:11-25. pub async fn sleep(d: Duration): :35-37.
    • Diagnostic site: src/Sema.w:2822.
    • The spec itself uses Duration.seconds(30) in several signatures (e.g. spec lines 1705, 2854), so the intended surface is a nameable Duration with constructors.
    • Example: examples/async-auction.w:52.

    Root cause. A stdlib visibility omission: type Duration = i32 and its constructors were written without pub (the alias dates to b05880a, 2026-03-02) while sleep was made pub and the example was written against Duration.millis. No compiler misbehavior is involved, so no debugger evidence is required; the privacy error is the compiler doing what §18.3 says. The compiler does not currently diagnose "private type in a pub signature" at the declaration site, which is why the inconsistency survived; whether it should is a design question (Rust errors on it), not something the spec rules today.

    Related PRs. None open or merged touch lib/std/time.w since 450733e.

    Recommendation. Fix it; it is a few pub keywords plus a decision. Make Duration and its constructors pub (the with-y option: callers can spell Duration.seconds(1) instead of a bare 1000). Acceptance criteria:

    • use std.time then sleep(Duration.seconds(1)).await compiles and runs.
    • use std.time.Duration compiles.
    • examples/async-auction.w passes with check, and examples are added to a check corpus so a broken example fails CI.
    • Optionally, a declaration-site diagnostic when a pub signature names a private type (would need a spec ruling).

    Not tested. Whether making the alias pub interacts with the D7 top-level fn Type.name placement of associated functions on a type alias (b2 probe: std.time.Duration.millis(5) fails with undefined variable on std, which is the expected absence of path-qualified access, not part of this report).

  2. ehartford commented on Oct 25, 2026

    @ehartford
    Contributor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce; Duration is public now (a0b8b32, #1150, #1284) and its constructors are callable.

    $ cat main.w
    use std.time
    let a = Duration.millis(5)
    let b: Duration = Duration.seconds(2)
    print(a + b)
    $ with run main.w
    2005
    
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