Skip to content

Package bundles: a program that imports a large module for one function checks all of it (the user-program half of #3351) #3401

Open

Description

@ehartford

Split from #3351, whose own repro is fixed: a 31-line test that imports a compiler module built in 106 s and now links the compiler's bundle (internals-tests 260 s -> 16 s, #3393).

What is left is the same cost for a user's program: a program that imports a large package for one function has every body of that package checked, lowered and (until #3359) generated each time. The mechanism that fixed the compiler's tests is a tree bundle (wo_bundles.md, "Tree bundles"): a package's modules compiled once, an interface the importer reads on demand, an initializer the importer runs. For a user's packages that needs decisions that are not mine:

  • what the unit is (a with.toml package, a dependency fetched by with get, a workspace member);
  • where the bundle lives and what invalidates it (a tree bundle is keyed on nothing and rebuilt by the build; a user's needs a key the user never sees);
  • visibility across the boundary (a tree bundle prints every declaration because its importers are the package's own tests; another package sees pub only, and generics and comptime then need a rule: today a generic is left to the bundle with a note);
  • the write contract (§21.1 rule 1) for a package's globals, which a tree bundle scopes to its own.

Why the label: this is a design with user-visible consequences (what a package boundary means), and "how" is not "go". It needs Eric's direction before any code.

Activity

  1. ehartford commented on Nov 19, 2026

    @ehartford
    ContributorAuthor

    Ruled, 2026-11-18: bring the design document first. Start from the existing bundle interface (D39, the .wo form), not a third format; and from the boundary rule already ruled: facts inferred inside a package do not cross it, only declared ones, so the interface is pub signatures plus their declared contracts and generics travel as source.

  2. ehartford commented on Nov 20, 2026

    @ehartford
    ContributorAuthor

    The design document Eric asked for is drafted (2026-11-20; a local working file, package-bundles.md under proposals, to be shown to him before it is pushed). In short: the unit is a package (D100); one bundle per (package inputs, compiler generation, target), cached per user and never named by the user; the interface is pub plus declared contracts, so nothing inferred from a body crosses (D178's rule, extended to return types, origins and effects); generics and comptime travel as source; a package's globals live in its bundle and its initializer runs before the program's. Three questions are Eric's: (a) whether a generic's private callees are compiled into the bundle or carried as source; (b) whether std is bundled after user packages or first; (c) whether a pub function with an inferred return type is refused at the package boundary or its inferred type is printed into the interface. Labelled human attn needed for those.

  3. ehartford commented on Nov 21, 2026

    @ehartford
    ContributorAuthor

    Step 1, first part, merged (#3501). A tree bundle's interface now prints what was inferred: a result's origins as a from clause, a stored or returned callable parameter as an @[effect] pin, a callable invoked at most once as once. The lane package-interface-check checks eight programs against the fixture package's source and against its interface alone.

    Left in step 1: generics carried as source (today "not exported at Level 0"), pub-only output (a tree bundle prints private functions too), the effect-disagreement warnings (noise for a package), the bundle's wording when a callable is invoked twice (it says the package has no body and suggests once), suspension (not probed), and the module-path mapping for a real package (the fixture uses a lib/ ancestor).

  4. ehartford commented on Nov 21, 2026

    @ehartford
    ContributorAuthor

    Generic functions cross the boundary as source (#3503). A tree bundle's interface now carries a free generic function's declaration; the importer instantiates it and links the package's private functions it calls from the bundle's object. Left in step 1: generic methods and generic types, comptime functions, the effect-disagreement warnings, the bundle's wording for a twice-invoked callable, suspension, and the module-path mapping for a real package.

  5. ehartford commented on Nov 21, 2026

    @ehartford
    ContributorAuthor

    Correction to what #3501 and #3503 claim. The lane package-interface-check says each program is checked "against the package's interface alone". That is too strong. Measured today:

    • With the package's source directory hidden, an importer given --link-bundle fails at use shapes: "import module not found". Module resolution still needs the source file to exist.
    • A generic type and a generic method, both written into the interface only as "not exported" notes, still work against the bundle while the source is present, so the importer reads them from the source.
    • Editing the source after the bundle is built (adding a field to a non-generic pub type) changes what the importer sees, so at least in that state the importer is reading the source, not the interface.

    So the interface changes of #3501 and #3503 are real (they changed which programs the bundle path accepts and refuses, and the fingerprint proves the interface reproduces the declarations), but the rule "an importer reads the interface, never the body" is not yet enforced. The next step of this issue is exactly that:

    1. A module of a bundled package resolves from its interface section; the source need not exist.
    2. No fallback to the source for a declaration the interface omits: what is not in the interface is not visible, and the three remaining omissions (generic types, generic methods, comptime functions) are carried as source text in the interface, as free generic functions now are.
    3. The lane hides the fixture's source before it checks the programs against the bundle, so the claim is tested.
  6. ehartford commented on Nov 21, 2026

    @ehartford
    ContributorAuthor

    The correction above was itself too broad; here is what the measurements actually show.

    So the remaining work is: resolve a bundled module without its source, and carry generic types, generic methods and comptime functions as source text.

  7. ehartford commented on Nov 24, 2026

    @ehartford
    ContributorAuthor

    Labelled human attn needed: the body already says why, and the label was missing. Four decisions are Eric's before any code: what the unit of a user's bundle is, where it lives and what invalidates it, what crosses the boundary (pub only, and the rule for generics and comptime), and the write contract for a package's globals.

  8. ehartford commented on Nov 25, 2026

    @ehartford
    ContributorAuthor

    Ruled by Eric, 2026-11-25 (answers to briefs.md).

    A: a build file's dependencies are read from source. Two invariants to write into the design: a package is always distributed with its source, and the source a build file reads is checked against the bundle (a hash), so the two cannot be different versions. The other questions were ruled 2026-11-20 (package-bundles.md). Label removed; step 1 continues.

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