Skip to content

Whole-program inference is require-path/layout sensitive — library consumption needs a stable package identity #1367

@OriPekelman

Description

@OriPekelman

Symptom

When a downstream Spinel program requires a library's source via a different relative path than the path the library uses in its own build, whole-program type inference fragments the type table differently. Concretely, an Array<Mat>-shaped declaration compiled clean but generated a C-codegen reference to an undefined sp_Mat type (sp_Mat undeclared) in the consumer, where Mat is a user class defined in the library.

Documented downstream in OriPekelman/toy (docs/consuming-toy.md, toy#19): hand-pathing require_relative "../toy/lib/.../transformer" (where Mat lives) into a consumer fragments inference vs. toy's own build.

Current workaround

Vendor the library's entire source tree in the exact layout the library compiles with (the spinelgems bundler-spinel convention). Same tree shape → inference stays monomorphic the way the library's own build expects. This works but makes library composition fragile off that golden path, and is a large part of why the vendoring convention has to exist.

Ask

A stable package / namespace identity so a user class (e.g. Mat) resolves to the same monomorphic C type regardless of the require path it's reached through — so a downstream program can compose a library's primitives without reproducing the library's exact directory layout.

Related

A minimal self-contained repro (one file required via two paths → divergent inference) is a TODO; filing now to capture the design need since it's the root of the downstream vendoring brittleness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions