Repository navigation
fix(ifc): enforce labels on fields of imported declared types - #2626
Merged
Merged
Conversation
A label declared on a field of a record, alias or ADT was a source label
only when the type was declared in the same module: for an imported
`Doc = {body: string<pii>, ...}`, `piisink(d.body)` passed `ailang check`.
The IFC pass indexed only the module's own type declarations, and the
interface could not supply an imported one's labels: closeInterfaceTypes
replaces each alias body with the elaborator's, which is label-free because
it feeds type checking.
A module whose types reach a label now publishes its declarations,
labelled and unexpanded, in a new IFC-only iface field (IFCTypes; absent
otherwise, so stdlib interfaces are unchanged). The importer resolves an
imported type name through its own TypeScope (new side-effect-free Peek)
into those declarations, and every IFC lookup goes through one
decl()/ctor() pair, so local and imported labels are read by the same code.
Wired for the CLI gate and export summaries (cache key v17; dep digest
covers the labels) and for the REPL/WASM loader.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e for CLI and REPL Review follow-ups to the imported-type label fix: - IFCTypesCarryLabels now counts a label written anywhere in a type, function-type parameters included (it used deepLabel, which counts only a function's return). `type Handler = (string<sqlsafe>) -> string` alone was not published, so Check C on an imported handler was silently lost. - iface.PublishedIFCTypes is the single decision of what a module publishes; the interface builder and the REPL/WASM loader both call it, and the REPL importer reads a registered module in the CLI's interface shape (published declarations plus label-free aliases and constructors). - Regression test: adding a label to a cache-warm dependency's type re-checks the unchanged importer (pins the +ifc: part of cacheDepDigest). - Changelog names the verdict changes precisely (imported generic records are not field-precise; unlabelled arms of an imported ADT with a labelled constructor), both mirroring same-module behaviour. - TestCompileCacheClear_Artifacts reads the manifest version from the new pipeline.CacheFormatVersion() instead of a hard-coded "v16". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
An IFC label declared on a field of a record, alias or ADT was a source label only when the type was declared in the same module. If the type was imported, labelled data reached a
{not ℓ}sink andailang checkaccepted it. This was reported by docparse on v0.60.4 and reproduced atdevHEAD (a66b854).Repro: before and after
DocDocdeclared in main (control)✓ No errors found!(rc 0)information-flow violation: value labelled <pii> reaches parameter "s" which forbids it(rc 1)ifct/main.ail:7:45: information-flow violation: value labelled <pii> reaches parameter "s" which forbids it (string{not pii})(rc 1)Root cause
The IFC pass reads declared labels from
ast.TypeDecls, butifcTypesindexed only the module's own declarations, so an imported type's deep label was ⊥. The interface could not supply the missing labels either. The builder does convert type bodies with their labels.closeInterfaceTypesthen replaces every alias body with the elaborator's, and the elaborator strips labels on purpose, because those bodies feed type checking. So the "labels survive in iface" path was dead for records and aliases.Fix: one reader for local and imported labels
Iface.IFCTypes. "Reach" means a label written anywhere in the type, function-type parameters included, or one carried by a type it names, including imported ones. One function,iface.PublishedIFCTypes, makes this decision for both the CLI builder and the REPL/WASM loader. Typing still reads the label-freeTypeAliases, so noTLabelledreaches the HM core or the backend. Modules with no labelled types publish nothing, so their interfaces are byte-for-byte unchanged (see the stdlib section below).IFCTypeEnvrebuilds imported declarations asast.TypeDecl, keyed by nominal identity.ifcTypes.decl()/ctor()resolve a name locally first, then through the module's ownTypeScope, the resolver the elaborator used, via a new side-effect-freeTypeScope.Peek. Every existing lookup (deepLabel,recordTypeOf/fieldType,paramBound,dataOnly,funcTypeOf, constructor typing) now goes through those two methods, so imported and local labels are read by the same code.AnalyzeModuleIFCWithImports). The cached iface JSON carriesifc_types, the dependency cache key includes its digest, andcacheKeyVersiongoes from v16 to v17.iface.PublishedIFCTypesdecides. Importers read it, plus label-free alias bodies and constructors, through the sameiface.AddIFCTypesthe CLI uses. The type scope is now built before the IFC gate.TestCompileCacheClear_Artifactsseeded a manifest pinned to"v16". It now reads the version from a newpipeline.CacheFormatVersion()accessor, so the next bump cannot strand it. No other test pins the cache version; the observatory'sv16is its DB schema, which is unrelated.Audit
Each case was checked with a HEAD build and with this PR's build. They are all regression rows in
TestIFCImportedTypeLabels.match)export import)type D2 = Doc)Box[int])L.Doc)type Secret = string<pii>)Handler = (string<sqlsafe>) -> string)mkDoc().body)d.title)Still open (not the same root cause): a
{not ℓ}refinement written inside an imported type, on a field or on a function type's parameter (Logger = (string{not pii}) -> unit ! {IO}), does not bind a parameter that the importer declares with that type. Refinements are not stored on types at all (astTypeToInternalTypedrops them), so fixing it needs a refinement representation in the interface. An imported function with such a parameter is still enforced through its export summary (verified). The IFC guide's limitation line now describes this gap instead of the fixed one.Soundness: newly rejected programs
Yes, intentionally. The programs that are now rejected are exactly those that would be rejected if the imported type were declared in the importer:
b: Box[string],Box[a] = {v: a, tag: string<pii>}:piisink(b.v)is rejected, because generic records are not field-precise);match w { W(s) => …, Plain(s) => piisink(s) }: match destructuring gives each binding the scrutinee's full label).The last two are the existing same-module imprecision, now applied to imported types. Each is a row in
TestIFCImportedTypeLabels, paired with its same-module control.ailang checkover all 591examples/**/*.ailwith the HEAD binary and this PR's binary gave 512 accepted and 79 rejected for both, with 0 verdict differences (rerun after the follow-up).make verify-examplesis green.Stdlib / freeze
No stdlib type declares a label (the only
<label>instd/is a function return type instd/secret), so no std module publishesIFCTypes.make verify-stdlibreports: ✓ All 49 stdlib interfaces stable. No re-freeze.Tests
internal/pipeline/ifc_imported_type_labels_test.goTestIFCImportedTypeLabels: the repro, a same-module control, the 9 other rejected audit cases, and 3 clean controls (unlabelled field, unlabelled sibling through mid, local declaration shadowing an imported name).It also has the Handler repro (a label only on a function type's parameter) with its same-module control, and the generic-record and ADT-arm verdict changes, each with its same-module control.
TestIFCImportedTypeLabelsWarmDependency: lib and mid are served from the compile cache and the importer is still rejected.TestIFCImportedTypeLabelAddedToWarmDependency: the importer is cache-warm and unchanged; a label is added to a field of the dependency's type; the importer must now be rejected.internal/repl/ifc_imported_type_labels_test.goTestLoadModule_IFCImportedTypeLabels: record field, ADT field, through an unlabelled module, the Handler repro, and a clean control.cmd/ailang/serve_api_mcp_surface_test.go:TestCompileCacheClear_Artifactsreads the manifest version frompipeline.CacheFormatVersion().Mutation testing
Each file was copied to a scratch backup, mutated in place, tested, then restored from the backup.
ifcTypes.declignores imported declarationsIFCTypesIFCTypesIFCImports.TypesunsetIFCTypesIFCTypesCarryLabels(file, nil))TypeScope, which already ranks local declarations firstTestIFCImportedTypeLabelsand the REPL test+ifc:part ofcacheDepDigestremovedTestIFCImportedTypeLabelAddedToWarmDependencyfails: the importer is served a stale accept (err = <nil>)CacheFormatVersion()returns"v16"TestCompileCacheClear_Artifacts/successfails with "Cleared 0", the CI symptomKnown, not fixed here:
IFCTypesis excluded from the interfaceDigestand the hash projection, so a label change on a type field does not change a published package's identity (function summaries do). This predates the PR: the compile cache key carries theIFCTypesdigest separately.Gates
make test-changed✓ ·make test-core✓ ·make lint✓ (0 issues) ·make check-file-sizes✓ ·make verify-stdlib✓ ·make verify-examples✓ ·make check-changelog✓ ·make check-boundaries✓ ·GOOS=js GOARCH=wasm go build ./cmd/wasm✓🤖 Generated with Claude Code