Repository navigation
compat, sizer: resolve a type name as the validator does (#289) - #294
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ause's path.compat(shape hashes, so compatibility verdicts) and the sizer resolved it looser:compat::Index::findtook a qualified name as written against every schema'snamespace::Name(so a dependency'ss0::Afound the consumer's owns0), then any namespace that ends with the written prefix (no::boundary:apimatchesrapi), then the first schema that declares the bare name. It did not read the schema'suses at all, so an importedUsertook whicheverUserwas indexed first and an alias found nothing.FrozenLookup::findmatched a qualified path to a namespace that equals it, ends with::path, or is a suffix of it (apiforv1::api), took the first, and fell back to any schema's declaration of the name.What changed
schema::ir::resolve(new, in the IR-only build too): the one rule, over the frozen IR.Import(auseas 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)andresolve(from, name) -> Result<Found, Unresolved>: the schema's own declaration (it shadows an import of the name), then the firstusethat brings the name in and leads to a declaration. Ause's pathnamespace::Nameis looked up by exact namespace. No suffix match, no first declaration of the name.Foundcarries the schema the declaration is in, so what is written in it is resolved there.std(its namespace begins with a name inpackages) is frozen by its own package, which writes the package's other schemas without the package's name (s0::A, inp0::s1). Its paths are looked up under its package first, then as written where they begin withstdor another package. A path to a package the version doesn't hold (a dependency's own dependency, which it doesn't publish) isUnresolved::NotLoaded, not a guess.Unresolvedsays why:NotInScope,NotLoaded,NotAType,NotDeclared.Indexis aResolverand 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 staysTy::UnresolvedisNotLoadedin a dependency's schema, which is what such a name hashed as before.FrozenLookupis aResolver.FrozenLookup::with_packagesnames the other packages' schemas (docpasses the dependencies andstd);newis the one-package case. A name that doesn't resolve is stillNone(theLookupcontract: an editor's lookup can't know it was validated).SymbolTablekeeps theImports;validate_typeasksis_importedwhere it askedis_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):Userand a protocol in a third that imports one of them, bare, aliased and qualified, with the pairsv1::api/v2::api,rapi/apiandv1::api/api, in both orders: the protocol's shape hash andUser'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 thev1::api/apipair: a qualifiedapi::Userorv2::api::Usertakes the first namespace that is a suffix of it, or that it is a suffix of).A. On master: both compat cases fail.Resolver's own rules are unit-tested inresolve.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
usebrought into scope; whole-namespaceusebrings only its name; a full path in a type position). It plugs intoSchema::reachinresolve.rs, the one place a written name is read in its schema;Import::bringsis what auseis a name for.doc's ownScope::resolve(documentation links), and the validator's loosercould_be_imported(asks whether to put a name to anImportLookup, not what it names) still have their own rules.ProjectImports::declaring_schema(alias targets, constants, validators) goes throughfind_schema_bringing_into_scopeover parsed declarations.