Repository navigation
Union string accessories and arrays independently of member order - #7176
Closed
ondrejmirtes wants to merge 2 commits into
Closed
ondrejmirtes wants to merge 2 commits into
ondrejmirtes wants to merge 2 commits into
Conversation
TypeCombinator::union() decided two cases from describe(VerbosityLevel::value()) strings: - '' absorbed a non-empty string only when the other member described as exactly non-empty-string or non-falsy-string, and then rebuilt the result from its case accessories alone. '' | non-empty-literal-string stayed ''|(literal-string&non-empty-string). Now the non-empty/non-falsy accessory is removed from the intersection and the rest is kept whenever it accepts '' (literal-string, lowercase-string, ...); ''|numeric-string stays as is. - A union stayed benevolent when every member described like a member of a benevolent union, so (int|lowercase-string) | uppercase-string stayed benevolent because uppercase-string also describes as "string". Membership is now identity, or absorbing a benevolent member as before. turbo-ext: the same in TypeCombinator.cpp. Amp-Thread-ID: https://ampcode.com/threads/T-01a17eac-1199-74a6-b3f7-dfbd8a084465
…d by another member first
TypeCombinator::union() gave different results for the same members in a
different order or grouping (32 of 97,336 triples of 46 types differed
semantically, now 12):
- non-empty-X | Y is X when Y is within X and holds the strings
non-empty-X lacks: '' and, for non-falsy-X, '0'. non-empty-string |
lowercase-string is string, non-empty-literal-string |
(literal-string&lowercase-string) is literal-string. Before, only
'' | non-empty-X did this.
- non-falsy-X | Y is non-empty-X when '0' ∈ Y ⊆ non-empty-X:
non-falsy-string | numeric-string is non-empty-string. Before, only
'0' | non-falsy-X did this.
- A member new to the union, like string from non-empty-string |
lowercase-string, is compared again with the members it was not
compared with: callable-string|non-empty-string|lowercase-string is
string, no longer callable-string|string.
- Arrays another member holds, like array<int> next to iterable<int>, are
dropped before processArrayTypes() merges the arrays into a type that
member no longer holds: array{a: string}|array<int>|iterable<int> is
array{a: string}|iterable<int>, no longer
iterable<(int|string), int|string>|iterable<int>.
The remaining 12 triples merge two arrays before a third member holds
one of them, which processArrayTypes() does on purpose.
- TypeCombinatorTest, bug-12312: the unions above are now string,
lowercase-string&non-empty-string, ...
- union-string-accessories-structural: (int|lowercase-string) |
non-empty-string is (int|string), as string absorbs the benevolent
lowercase-string; numeric-string is the strict control now.
- turbo-ext: the same in TypeCombinator.cpp.
Amp-Thread-ID: https://ampcode.com/threads/T-01a17eac-1199-74a6-b3f7-dfbd8a084465
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.
TypeCombinator::union()decided two cases by comparingdescribe(VerbosityLevel::value())strings. Both now look at the types themselves.''absorbed by a non-empty string. The empty string merged into the other member only when that member described as exactlynon-empty-stringornon-falsy-string, and the result was then rebuilt from its case accessories alone. Now thenon-empty-string/non-falsy-stringaccessory is removed from the intersection, and the rest is used whenever it accepts'':'' | non-empty-literal-string''|(literal-string&non-empty-string)literal-string'' | (literal-string&lowercase-string&non-falsy-string)''|(literal-string&lowercase-string&non-falsy-string)literal-string&lowercase-string'' | (non-empty-string&numeric-string)''|numeric-stringBenevolent membership. A union stayed benevolent when every member had the same description as a member of a benevolent union.
uppercase-stringdescribes asstring, likelowercase-string, so(int|lowercase-string) | uppercase-stringstayed benevolent while(int|lowercase-string) | non-empty-stringdid not. Membership is now identity, or absorbing a benevolent member (unchanged).The C++ mirror in
turbo-ext/src/TypeCombinator.cppgets the same change. Test:nsrt/union-string-accessories-structural.php, which fails without the change.Second commit: union no longer depends on member order or grouping. On a pool of 46 types, 32 of 97,336 triples gave semantically different results depending on bracketing; now 12 do (
(a ∪ b) ∪ cvsa ∪ (b ∪ c)).non-empty-X | YisXwhenY ⊆ Xholds the stringsnon-empty-Xlacks ('', and'0'for non-falsy). For example,non-empty-string | lowercase-stringisstring. Before, only'' | non-empty-Xdid this.non-falsy-X | Yisnon-empty-Xwhen'0' ∈ Y ⊆ non-empty-X. For example,non-falsy-string | numeric-stringisnon-empty-string.callable-string|non-empty-string|lowercase-stringis nowstring, where it wascallable-string|string.processArrayTypes()merges the arrays.array{a: string}|array<int>|iterable<int>is nowarray{a: string}|iterable<int>, where it wasiterable<(int|string), int|string>|iterable<int>.The 12 triples that still differ merge two arrays before a third member holds one of them, which
processArrayTypes()does on purpose. Expectations inTypeCombinatorTestandbug-12312got more precise: afterif ($s != '0'),$sis back to its declaredlowercase-string&non-empty-string. The new testnsrt/union-string-accessories-complete.phpfails without the change, including the rescan case. A parity dump of 25,230 unions is identical with turbo active.