Skip to content

compat, sizer: resolve a type name as the validator does (#289) - #294

Merged
Kinflou merged 2 commits into
masterfrom
fix/shared-type-resolver
Nov 16, 2026
Merged

Kinflou merged 2 commits into
masterfrom
fix/shared-type-resolver

Conversation

@Kinflou

@Kinflou Kinflou commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Closes #289. Refs #281, #290.

Problem

Three places decided what a name written in a type names, each by its own rule. The validator accepts a name that is the schema's own declaration, a name one of its uses brings in (the alias, else the last segment), or a qualified path equal to a use's path. compat (shape hashes, so compatibility verdicts) and the sizer resolved it looser:

  • compat::Index::find took a qualified name as written against every schema's namespace::Name (so a dependency's s0::A found the consumer's own s0), then any namespace that ends with the written prefix (no :: boundary: api matches rapi), then the first schema that declares the bare name. It did not read the schema's uses at all, so an imported User took whichever User was indexed first and an alias found nothing.
  • FrozenLookup::find matched a qualified path to a namespace that equals it, ends with ::path, or is a suffix of it (api for v1::api), took the first, and fell back to any schema's declaration of the name.
  • compat also read the fields and alias targets of a declaration from another schema in the namespace of the protocol, not of the schema that declares it.

What changed

  • schema::ir::resolve (new, in the IR-only build too): the one rule, over the frozen IR.
    • Import (a use as frozen): bare() is the name it brings in, brings(name) is that name or its path written out. The validator's symbol table now holds these (SymbolTable::add_import, is_imported), so the validator's check and the resolvers' are one function.
    • Resolver::new(schemas, packages) and resolve(from, name) -> Result<Found, Unresolved>: the schema's own declaration (it shadows an import of the name), then the first use that brings the name in and leads to a declaration. A use's path namespace::Name is looked up by exact namespace. No suffix match, no first declaration of the name.
    • Found carries the schema the declaration is in, so what is written in it is resolved there.
    • A schema of a dependency or std (its namespace begins with a name in packages) is frozen by its own package, which writes the package's other schemas without the package's name (s0::A, in p0::s1). Its paths are looked up under its package first, then as written where they begin with std or another package. A path to a package the version doesn't hold (a dependency's own dependency, which it doesn't publish) is Unresolved::NotLoaded, not a guess.
    • Unresolved says why: NotInScope, NotLoaded, NotAType, NotDeclared.
  • compat: Index is a Resolver and the errors by ordinal. A name that doesn't resolve is an internal error (a panic that names the schema, the name and why), as the validator has accepted it. The one that stays Ty::Unresolved is NotLoaded in a dependency's schema, which is what such a name hashed as before.
  • sizer: FrozenLookup is a Resolver. FrozenLookup::with_packages names the other packages' schemas (doc passes the dependencies and std); new is the one-package case. A name that doesn't resolve is still None (the Lookup contract: an editor's lookup can't know it was validated).
  • validator: SymbolTable keeps the Imports; validate_type asks is_imported where it asked is_imported_bare. Nothing it accepts or refuses changes.

Tests

core/tests/schema/ir/type_resolution.rs, written first (commit 1, failing on master in the runs of this PR):

  • two schemas that declare User and a protocol in a third that imports one of them, bare, aliased and qualified, with the pairs v1::api/v2::api, rapi/api and v1::api/api, in both orders: the protocol's shape hash and User's packed range are those of the same struct declared in the protocol's schema. Of the 36 combinations, 18 fail in compat on master (every aliased one, and the bare one whenever the imported schema isn't the first indexed) and 6 in the sizer (all in the v1::api/api pair: a qualified api::User or v2::api::User takes the first namespace that is a suffix of it, or that it is a suffix of).
  • a dependency's bare and qualified reference to a sibling schema, against a consumer schema of the same name: the consumer's shape hash and range don't move when the consumer adds its own A. On master: both compat cases fail.

Resolver's own rules are unit-tested in resolve.rs (shadowing, no suffix, not a type, a dependency's package, what an import brings in).

Not moved

No existing test, spec compiler case, frozen IR, golden hash (tests/migrations/expected) or bench changed; the format gate and the bench gate pass. Shape hashes of the existing fixtures are unchanged (the only moves are the new cases' own, which were wrong).

Not here

  • Qualified references follow the Rust model #290's rule (a qualified reference starts with a name a use brought into scope; whole-namespace use brings only its name; a full path in a type position). It plugs into Schema::reach in resolve.rs, the one place a written name is read in its schema; Import::brings is what a use is a name for.
  • The language server's mirror, doc's own Scope::resolve (documentation links), and the validator's looser could_be_imported (asks whether to put a name to an ImportLookup, not what it names) still have their own rules. ProjectImports::declaring_schema (alias targets, constants, validators) goes through find_schema_bringing_into_scope over parsed declarations.

Kinflou added 2 commits November 16, 2026 09:28
compat and the sizer resolve a name by suffix and first match. These cases hold the shape hash and the byte range of a protocol's type to those of the same declaration written in the protocol's own schema: two schemas declaring one name, namespaces that are a string suffix of another, bare, aliased and qualified, and a dependency's names against a consumer's schema of the same name.
… sizer (#289)

Resolve a name as the validator accepts it: the schema's own declarations, then its uses (aliases included), then a qualified path equal to a use's. No suffix match and no first declaration of the name. compat and the sizer read a declaration's own names in the schema that declares it, and a dependency's in its own package.
@Kinflou
Kinflou marked this pull request as ready for review November 16, 2026 02:11
@Kinflou
Kinflou merged commit 7c6f4a2 into master Nov 16, 2026
33 checks passed
@Kinflou
Kinflou deleted the fix/shared-type-resolver branch November 16, 2026 02:11
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.

compat and the sizer resolve names by suffix and first match, not as the validator does

1 participant