Repository navigation
Accept merged shapes in unions and bound accepts reasons - #7210
Merged
Merged
Conversation
Every member of a union that rejects a type adds its own reasons, and ConstantArrayType::checkOurKeys() prefixes each one with the full value types, so the reasons of nested unions of shapes multiply with every level. A recursive mapping type produced 829 reasons and a 2.7 MB tip on a single return.type error. The constructor now keeps only the first ten. Amp-Thread-ID: https://ampcode.com/threads/T-01a21c50-6b52-77f7-9d04-dff937be67fa
Symfony's OutputFormatter reads every <...> in a type description such as array<int, string> as a possible style tag and measures the text up to it from the start of the message, which is quadratic in the message length: a 2.7 MB tip took about 11 minutes to format. ConsoleTagEscaper escapes what is not a style tag before the table and JSON formatters format it, so the escaped tags are skipped. The output stays the same. Amp-Thread-ID: https://ampcode.com/threads/T-01a21c50-6b52-77f7-9d04-dff937be67fa
union() merges shapes that differ at one key into one shape, such as
array{type: 'boolean'|'keyword'}, which no member of
array{type: 'boolean'}|array{type: 'keyword', fields?: ...} accepts alone.
UnionType::accepts() now splits such a shape at a key holding a union of
constant scalars and accepts it when it accepts every piece.
Amp-Thread-ID: https://ampcode.com/threads/T-01a21c50-6b52-77f7-9d04-dff937be67fa
ondrejmirtes
force-pushed
the
accepts-merged-shapes
branch
from
November 27, 2026 10:51
1fc4ef1 to
f293069
Compare
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.
Since 0e9fdb5,
union()merges shapes that differ at one key into one shape:$b ? ['type' => 'boolean'] : ['type' => 'keyword']becomesarray{type: 'boolean'|'keyword'}. No member ofarray{type: 'boolean'}|array{type: 'keyword', fields?: …}accepts that shape alone, so it is reported asreturn.type. In a downstream project, one such error on a recursive mapping type carried a 2.7 MB tip, and formatting that tip took the job from about 1.5 to 13 minutes.UnionType::accepts()splits the shape at a key holding a union of constant scalars, usingArrayAlgebra::splitConstantArrayAtFiniteValue()with a cap of 64 pieces.AcceptsResult::REASONS_LIMIT(10) reasons. The reasons of nested unions multiplied at every level, reaching 829 on that error.OutputFormatteris quadratic on every<…>in a type description. With them escaped, the 2.7 MB tip formats in 0.17 s instead of about 15 minutes, and the output is the same.The turbo mirrors are ported in
AcceptsResult.cppandUnionType.cpp. The smoke test, signature parity and side-by-side checks pass, and the suites pass with the extension loaded.Amp thread: https://ampcode.com/threads/T-01a21c50-6b52-77f7-9d04-dff937be67fa