Skip to content

imports: own schemas only through package::, parent:: or self:: - #285

Merged
Kinflou merged 2 commits into
masterfrom
feat/own-schema-relative-paths
Nov 14, 2026
Merged

Kinflou merged 2 commits into
masterfrom
feat/own-schema-relative-paths

Conversation

@Kinflou

@Kinflou Kinflou commented Nov 14, 2026

Copy link
Copy Markdown
Member

Closes #282. Refs #281. Rule: Own schemas only through relative paths (docs#178, docs#181). Cases: ComlineProject/specification#12 (part of specification#11).

The rule

Within a package, its own schemas are reached only as package::..., parent::... or self::.... An absolute first segment of a use means std or a dependency. A bare path that reaches one of the package's own schemas is an error at once, no edition and no warning period.

  • Diagnostic: import::bare-own-schema-path (error), import_resolver::BARE_OWN_SCHEMA_PATH. Message: 'types::{User, Post}' is one of this package's own schemas, reached by a bare path; context: an absolute path starts with `std` or a dependency's name; 'types' is neither; help: write `package::types::{User, Post}`: a package's own schemas are reached as `package::...`, `parent::...` or `self::...` . Raised by check_imports (which the build, check_and_from_declarations and the language server's mirror already use), for each form of a use: a single item, a whole namespace, {...} and *, with or without as.
  • Which paths: the written first segment is not self/parent/package, not std, not a declared dependency's name, and the path reaches one of the package's own schemas. A path that reaches nothing (use typse::User) is still import::unresolved, with its "did you mean".
  • Fix: a Fix with one edit, an insertion of package:: at the start of the path (title Write `package::types::User` ), computed from the schema's text (read from its code map) and the use declaration's span. It is not offered if the declaration isn't use, whitespace, then the path. Fix::apply yields the rewritten file. Qualified references need no rewrite: what an import brings in is the schema's namespace whichever path reached it, so types::User after use types is the same after use package::types (a test builds the fixed text with that reference). There was therefore no multi-edit to make, though Fix supports one.
  • comline fix: not wired. The CLI's comline fix applies Diagnostic::fix from source-only checks (edition::check_config, edition::deprecations); check_imports needs a ProjectContext of the package, and nothing in core builds one for the CLI to ask for fixes. The fix is on the public diagnostic; applying it across the package is cli#162.
  • Unchanged: reserved_dependency_name (std, package, parent, self), reject_shadowing_namespaces (core#256), the word parent. A dependency's and std's own schemas are still not checked in the consumer (check_imports returns early for them), as before.

Specification pin

comline-catalog and core/tests/spec/REV at 6e42967 (head of specification#12; to be re-pinned to the merge commit once it lands), with tests/spec/cases re-vendored by vendor.sh: new group imports (the cases below), and bounded writing package::models::Blob. The Vendored specification files job checks the vendored copy. The cases run in compiler_cases.rs unchanged and pass.

Cases (imports/): bare-own-item|namespace|multi|glob|nested (error import::bare-own-schema-path); package-item|namespace|multi|glob|nested, parent-item, self-item (build); dependency-path, std-path (build); unknown-first-segment (import::unresolved); own-schema-named-like-dependency; dependency-named-std|package|parent|self.

Changed in core

  • core/src/schema/ir/compiler/import_resolver.rs: the code, absolute_first_segment, the error and its fix, the check in check_imports, doc comments; unit-level tests below.
  • core/tests/schema/ir/imports.rs: new tests (each form of a use with the fix's output, the fixed text builds with its qualified reference, the message, a nested directory, relative forms not flagged, dependency and std not flagged, a typo stays import::unresolved); existing cross-file tests write package::.
  • Fixtures to package::: tests/schema/ir/{imports,dataless_arrays,alias_validators}.rs, tests/package/{from_sources,unverified,unverified_inner,unverified_strict,unverified_oracle}.rs, tests/cas/dependency_vendoring_tests.rs (a dependency compiled on its own now writes package:: too), src/doc.rs (doc test sources), examples/imports/src/hole.ids.
  • core/oracle/src/model.rs: the proptest oracle renders use package::s0::T for a schema of the package itself.
  • tests/spec/{REV,cases/*} and core/Cargo.toml (the comline-catalog rev). No Cargo.lock is tracked.
  • std (core_stdlib) has no use of its own schemas; nothing to change there.

No test is weakened, ignored or loosened. cargo test --workspace --features deps passes locally.

Downstream inventory (read-only; nothing edited)

Bare own-schema paths that break or go stale when the repo pins a core with this rule. "Breaks" means a build through core's check_imports (compile_package, PackageSources) rejects it; "stale" means a fixture or doc that doesn't build through it today but should say package::.

Repo Count Where
generation 0 break; 2 stale codegen/src/validation.rs:594 (use limits::BASE) and codegen/src/features.rs:1265 ("use other", a detail string), both IncrementalInterpreter::from_source, which checks no imports. Conformance fixtures are frozen IR, not text. No .ids files
comline-rust 0 break; 1 stale codegen/tests/compiles.rs:1392, use match::Kw (from_source). No .ids files
comline-typescript 0 break; 3 stale codegen/tests/generate.rs:1834-1835 (use names::class, use names::function), :1915-1916 (use shapes::Layout, use shapes::Promise), via from_source. No .ids files
cli 0 fixtures use std:: or a dependency (shared::, greeting::); tests/fixtures/*/src/*.ids have no bare own path
language-server about 115 stale, in 14 source files and the README test inputs and docs for its own import analysis, which mirrors check_imports through resolve_namespace and so still accepts them until language-server#122. First segments: types 80, a 16, b 6, other 6, rules 5, api 5, shapes 2, more 2, chat 2, models 1; in analysis/{diagnostics,import_check,imports,project}.rs, handlers/{code_actions,completion,definition,hovers,rename}. Also behaviour, not just fixtures: the "Add use types::Message" code action (handlers/code_actions.rs:535) and use-path completion offer own schemas as bare paths. (14 shared:: lines are a dependency and fine)
examples 1 break chat/chat.ids:1, use types::Message (the playground compiles every example: app/src/examples.test.ts)
tutorial 0 its one .ids (lessons/chat.ids) has no use
playground 0 break; 1 stale doc comment wasm/src/lib.rs:1281 (use other::Thing); breaks through the comline-examples dependency above
runtime 3 stale the vendored specification's runtime/conformance/spec/compiler/cases/bounded.json (use models::Blob, three cases), which package:: in the next vendoring replaces
runtime-std-extra 0 capacity-management already writes use package::server::Server
docs about 10 guides/idl/use.md (the mypackage:: examples at lines 8-10, use other::User at 45, the error table at 71-72), guides/idl/index.md:61, guides/codegen/generating-code.md:292 (use types::Greeting as G); the proposal pages that show the "before" form on purpose (use-paths-and-groups/relative-use.md:27-28, index.md:20) are as they should be. Tracked in docs#182. .ids files there: 4, none with use
simulator 0 no .ids and no matching text

(The scan: every .ids, .rs, .md, .ts, .json, .py and similar file for use <word> that isn't Rust's own, classified by whether the first word names a dependency or std.)

CI

Draft; tests run in CI, per job below.

Kinflou added 2 commits November 15, 2026 06:31
A bare path to one of the package's own schemas is an error at once,
import::bare-own-schema-path, in each form of a use. It carries a fix
that writes package:: in front of the path. Paths starting with std, a
dependency's name or a relative prefix are as they were, and a path that
matches nothing is still import::unresolved.

Pin the specification at 6e42967 (specification#12, the imports cases)
and vendor its cases. Fixtures, the oracle's rendering, std-free
examples and doc tests write package::.

Refs #281.
@Kinflou
Kinflou marked this pull request as ready for review November 14, 2026 22:49
@Kinflou
Kinflou merged commit 14ce546 into master Nov 14, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Own schemas only through package::, parent:: or self::

1 participant