Skip to content

fix!: bound retained compile memory and give cross-module facts one owner - #237

Merged
jacoelho merged 1 commit into
mainfrom
fix/architecture-remediation
Nov 26, 2026
Merged

jacoelho merged 1 commit into
mainfrom
fix/architecture-remediation

Conversation

@jacoelho

Copy link
Copy Markdown
Owner

Breaking: three limits now measure what is retained or compared rather than a proxy, so a schema or document near a limit can be accepted or rejected differently. Some diagnostics change position, text or precedence, as the paragraphs below describe. The exported Go API is unchanged. Only option doc comments change.

value.Builder charges the inherited facet entries a derived type retains against its storage budget. Before, it charged only the type's own facets while copying every inherited bound and enumeration into each derived type. A schema of a few hundred KB within every public limit could then retain gigabytes and run out of memory instead of failing. Such a schema now fails with schema.limit. Merged facet lists are allocated at their exact length, and a side the derived type does not change shares the base's storage. docs/RESOURCE_LIMITS.md states the per-type retention.

MaxSchemaPatternRetainedBytes charges a compiled pattern's tables by capacity instead of length, because the machine retains the whole backing arrays. The retained estimate rises by the arrays' append slack, so a pattern set close to the limit can now exceed it. Each compiled pattern records an explicit runner mode, and the general NFA branch that no pattern could reach is deleted.

MaxIdentityTupleBytes caps the canonical text bytes of every identity entry: the sum of each field's canonical length plus one byte between fields. Key, unique and keyref tuples were measured by an internal encoding of the key, and ID and IDREF values by their canonical text. The one public limit meant two things.

A schemaLocation or xml:base that the project's URI grammar admits but the built-in fallback cannot represent is now an unavailable optional reference, as ARCHITECTURE.md already stated. The fallback re-parsed such references with net/url and reported its errors. A value such as http://h:abc/x.xsd, valid as xs:anyURI, failed compilation, and the outcome depended on whether a resolver was configured.

The include and import reference rules (src-include 2.1, src-import) are decided once, when the compile is planned. They were decided at load time when the referencing document declared targetNamespace, and at plan time when it was a chameleon document. The same reference violation then won or lost against a later parse violation depending on that attribute. It now loses to a later parse violation in every case.

One identity operation owns the sequence that records an assessed value, checks its fixed value, captures it into matched fields and commits it. Seven call sites ran these steps by hand in two orders. When a fixed-value violation and an identity violation hit the same node, a declared attribute reported only the identity violation and a wildcard attribute only the fixed-value violation. Both now report the fixed-value violation.

internal/schema constructs and renders runtime names. An attribute diagnostic names a known qualified attribute as "{urn:a}x", as it already named an unknown one, where it printed the local name alone. Tests build runtime names through Schema.ResolveName, the constructor production uses, and Schema.NameOf is deleted.

The XML reader owns the class and position of its errors. internal/format reports a document with no root element at the reader's position, as validation does, rather than at 1:1. Misuse of the reader's lifecycle is reported as internal.invariant by every consumer. A DOCTYPE declaration is rejected at its <. The KindDirective token kind, which no consumer could receive, is deleted, so the token switches no longer opt out of the exhaustive lint.

After a simple type is completed, internal/value alone holds its structure (base, list item, union members, variety and whitespace), and internal/schema reads it through Builder.TypeView. Schema's stored declaration no longer carries a copy of that structure, and the duplicate union-facets flag is deleted.

docs/RESOURCE_LIMITS.md owns what each public option means. The option doc comments in compile.go and session.go keep a one-line summary, the zero-value rule and a link, and a test checks that form.

The oracle run cache key covers every file under the directory the providers mount, not only the files a case declares. A changed file that a provider reads now invalidates the cached verdict.

Exported identifiers of internal packages that only tests used are deleted. Their tests go through each module's real surface instead, such as compiling a schema or parsing XML. The deleted identifiers include schema.Compile, value.BuiltinTypeID, xmlstream.NewAttr, format.XML and the identity-program read accessors. Production methods that only tests called are deleted too. tests/test_only_exports_test.go fails when an exported identifier of an internal package has no production use in the host or js/wasm build. A new make lint-test-only-code pass, part of make lint, runs unused with tests excluded so it reports unexported production code that only tests reach.

…wner

Breaking: three limits now measure what is retained or compared rather than a proxy, so a schema or document near a limit can be accepted or rejected differently. Some diagnostics change position, text or precedence, as the paragraphs below describe. The exported Go API is unchanged. Only option doc comments change.

`value.Builder` charges the inherited facet entries a derived type retains against its storage budget. Before, it charged only the type's own facets while copying every inherited bound and enumeration into each derived type. A schema of a few hundred KB within every public limit could then retain gigabytes and run out of memory instead of failing. Such a schema now fails with `schema.limit`. Merged facet lists are allocated at their exact length, and a side the derived type does not change shares the base's storage. docs/RESOURCE_LIMITS.md states the per-type retention.

`MaxSchemaPatternRetainedBytes` charges a compiled pattern's tables by capacity instead of length, because the machine retains the whole backing arrays. The retained estimate rises by the arrays' append slack, so a pattern set close to the limit can now exceed it. Each compiled pattern records an explicit runner mode, and the general NFA branch that no pattern could reach is deleted.

`MaxIdentityTupleBytes` caps the canonical text bytes of every identity entry: the sum of each field's canonical length plus one byte between fields. Key, unique and keyref tuples were measured by an internal encoding of the key, and ID and IDREF values by their canonical text. The one public limit meant two things.

A `schemaLocation` or `xml:base` that the project's URI grammar admits but the built-in fallback cannot represent is now an unavailable optional reference, as ARCHITECTURE.md already stated. The fallback re-parsed such references with `net/url` and reported its errors. A value such as `http://h:abc/x.xsd`, valid as `xs:anyURI`, failed compilation, and the outcome depended on whether a resolver was configured.

The include and import reference rules (src-include 2.1, src-import) are decided once, when the compile is planned. They were decided at load time when the referencing document declared `targetNamespace`, and at plan time when it was a chameleon document. The same reference violation then won or lost against a later parse violation depending on that attribute. It now loses to a later parse violation in every case.

One identity operation owns the sequence that records an assessed value, checks its fixed value, captures it into matched fields and commits it. Seven call sites ran these steps by hand in two orders. When a fixed-value violation and an identity violation hit the same node, a declared attribute reported only the identity violation and a wildcard attribute only the fixed-value violation. Both now report the fixed-value violation.

`internal/schema` constructs and renders runtime names. An attribute diagnostic names a known qualified attribute as `"{urn:a}x"`, as it already named an unknown one, where it printed the local name alone. Tests build runtime names through `Schema.ResolveName`, the constructor production uses, and `Schema.NameOf` is deleted.

The XML reader owns the class and position of its errors. `internal/format` reports a document with no root element at the reader's position, as validation does, rather than at 1:1. Misuse of the reader's lifecycle is reported as `internal.invariant` by every consumer. A DOCTYPE declaration is rejected at its `<`. The `KindDirective` token kind, which no consumer could receive, is deleted, so the token switches no longer opt out of the exhaustive lint.

After a simple type is completed, `internal/value` alone holds its structure (base, list item, union members, variety and whitespace), and `internal/schema` reads it through `Builder.TypeView`. Schema's stored declaration no longer carries a copy of that structure, and the duplicate union-facets flag is deleted.

docs/RESOURCE_LIMITS.md owns what each public option means. The option doc comments in compile.go and session.go keep a one-line summary, the zero-value rule and a link, and a test checks that form.

The oracle run cache key covers every file under the directory the providers mount, not only the files a case declares. A changed file that a provider reads now invalidates the cached verdict.

Exported identifiers of internal packages that only tests used are deleted. Their tests go through each module's real surface instead, such as compiling a schema or parsing XML. The deleted identifiers include `schema.Compile`, `value.BuiltinTypeID`, `xmlstream.NewAttr`, `format.XML` and the identity-program read accessors. Production methods that only tests called are deleted too. `tests/test_only_exports_test.go` fails when an exported identifier of an internal package has no production use in the host or js/wasm build. A new `make lint-test-only-code` pass, part of `make lint`, runs `unused` with tests excluded so it reports unexported production code that only tests reach.
@jacoelho
jacoelho merged commit 8a0e65b into main Nov 26, 2026
2 checks passed
@jacoelho
jacoelho deleted the fix/architecture-remediation branch November 26, 2026 12:40
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.

1 participant