Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for strict arrays, fix type alias intersection, fix array_is_list assertion on non-lists #8395

Merged
merged 159 commits into from Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from 153 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
28d4b03
Immutable CodeLocation
danog Oct 11, 2022
48d4e65
Remove excess clones
danog Oct 12, 2022
32d58cd
Remove external clones
danog Oct 12, 2022
7263cbd
Remove leftover clones
danog Oct 12, 2022
15f7dbd
Fix final clone issue
danog Oct 12, 2022
e75f390
Immutable storages
danog Oct 12, 2022
477a0c4
Refactoring
danog Oct 13, 2022
9015dbe
Fixes
danog Oct 13, 2022
9e10e00
Fixes
danog Oct 13, 2022
ef8b613
Fix
danog Oct 17, 2022
c2ab160
Fix
danog Oct 18, 2022
955b69f
Fixes
danog Oct 18, 2022
75a8ef7
Simplify
danog Oct 18, 2022
a53f6cc
Fixes
danog Oct 18, 2022
64d3b9b
Fix
danog Oct 18, 2022
5bffe8c
Fixes
danog Oct 18, 2022
7b4c9ee
Update
danog Oct 18, 2022
c169f94
Fix
danog Oct 18, 2022
5eba409
Cache global types
danog Oct 18, 2022
94d214b
Fix
danog Oct 18, 2022
00ea583
Update
danog Oct 18, 2022
fc0fe2e
Update
danog Oct 18, 2022
f7341d6
Fixes
danog Oct 18, 2022
d131ada
Fixes
danog Oct 18, 2022
1284ef9
Refactor
danog Oct 18, 2022
4fc8318
Fixes
danog Oct 19, 2022
9aec377
Fix
danog Oct 19, 2022
aeb9d38
Fix
danog Oct 19, 2022
0c8d83f
More caching
danog Oct 19, 2022
d398883
Fix
danog Oct 19, 2022
a2bcba3
Fix
danog Oct 19, 2022
ee70da6
Update
danog Oct 19, 2022
f8d86c2
Update
danog Oct 19, 2022
5c91b47
Fix
danog Oct 19, 2022
68d76d5
Fixes
danog Oct 19, 2022
b45bcd9
Update
danog Oct 19, 2022
1d5b4e3
Refactor
danog Oct 19, 2022
ca86d28
Update
danog Oct 19, 2022
d4f2e9b
Fixes
danog Oct 19, 2022
c4450be
Break one more test
danog Oct 19, 2022
10ab6c8
Fix
danog Oct 19, 2022
94b3af4
FIx
danog Oct 20, 2022
4bc47af
Fix
danog Oct 20, 2022
47ad0ff
Fix
danog Oct 20, 2022
c022617
Fix
danog Oct 20, 2022
00c8d5e
Fix
danog Oct 20, 2022
db401b4
Improve performance and readability
danog Oct 20, 2022
9f1f205
Equivalent logic
danog Oct 20, 2022
7650781
Fixes
danog Oct 20, 2022
f917510
Revert
danog Oct 20, 2022
0a2596c
Revert "Revert"
danog Oct 20, 2022
84a1bab
Fix
danog Oct 20, 2022
3d4b64e
Fix reference bug
danog Oct 22, 2022
6dc4dcc
Make default TypeVisitor immutable
danog Oct 22, 2022
5ad7ce5
Bugfix
danog Oct 22, 2022
1e5c3e6
Remove clones
danog Oct 22, 2022
b9dc64e
Partial refactoring
danog Oct 22, 2022
9eb031e
Refactoring
danog Oct 22, 2022
5305934
Merge branch 'uwu' into immutable_readonly_4
danog Oct 22, 2022
7090d03
Fixes
danog Oct 22, 2022
2a1bc83
Fix
danog Oct 22, 2022
81c345f
Fixes
danog Oct 22, 2022
76eb09c
Fixes
danog Oct 22, 2022
d66593a
cs-fix
danog Oct 22, 2022
ea8634f
Fix final bugs
danog Oct 24, 2022
01eb5ed
Add test
danog Oct 24, 2022
4ffc25c
Misc fixes
danog Oct 24, 2022
3ad0f95
Update
danog Oct 25, 2022
bbd5db8
Fixes
danog Oct 25, 2022
ac1156e
Experiment with removing different property
danog Oct 25, 2022
3a6b975
revert "Experiment with removing different property"
danog Oct 25, 2022
ec0c6a3
Uniform naming
danog Oct 25, 2022
d6ccae2
Uniform naming
danog Oct 25, 2022
a4c2565
Hack hotfix
danog Oct 26, 2022
64e683f
Clean up $_FILES ref #8621
danog Oct 26, 2022
1f90e18
Undo hack, try fixing properly
danog Oct 27, 2022
ecf6fff
Helper method
danog Oct 27, 2022
b12f013
Merge remote-tracking branch 'origin/master' into immutable_readonly_4
danog Oct 27, 2022
afa748f
Remove redundant call
danog Oct 28, 2022
d89d26e
Partially fix bugs
danog Oct 28, 2022
4f5f1f9
Cleanup
danog Oct 28, 2022
05ad20c
Change defaults
danog Oct 31, 2022
b22f754
Fix bug
danog Oct 31, 2022
e782141
Fix (?, hope this doesn't break anything else)
danog Oct 31, 2022
5aa9967
cs-fix
danog Oct 31, 2022
fc2acce
Review fixes
danog Oct 31, 2022
c72980d
Bugfix
danog Nov 1, 2022
b0bc942
Bugfix
danog Nov 1, 2022
50924b2
Improve logic
danog Nov 1, 2022
55176a9
Add support for list{} and callable-list{} types, properly implement …
danog Nov 1, 2022
fb8d612
Default to sealed arrays
danog Nov 1, 2022
bc46d93
Fix array_merge bug
danog Nov 1, 2022
ac8ec2d
Fixes
danog Nov 1, 2022
2495c71
Fix
danog Nov 1, 2022
2fbad9a
Sealed type checks
danog Nov 1, 2022
03b00d6
Properly infer properties-of and get_object_vars on final classes
danog Nov 1, 2022
405bf1f
Fix array_map zipping
danog Nov 1, 2022
cf4cdec
Fix tests
danog Nov 1, 2022
fa065c5
Fixes
danog Nov 1, 2022
136baa4
Fixes
danog Nov 1, 2022
0610b74
Fix more stuff
danog Nov 1, 2022
4fb2a07
Recursively resolve type aliases
danog Nov 1, 2022
0543145
Fix typo
danog Nov 1, 2022
4463168
Fixes
danog Nov 1, 2022
9345f46
Fix array_is_list assertion on keyed array
danog Nov 1, 2022
cf2f9ce
Add BC docs
danog Nov 1, 2022
92a1162
Fixes
danog Nov 1, 2022
efdd5e6
fix
danog Nov 1, 2022
bf3c493
Update
danog Nov 1, 2022
68db669
Update
danog Nov 1, 2022
3da9148
Update
danog Nov 1, 2022
4096d4f
Update
danog Nov 1, 2022
b26e46c
Seal arrays with count assertions
danog Nov 2, 2022
8dc031d
Fix #8528
danog Nov 2, 2022
6928a17
Fix
danog Nov 2, 2022
8694475
Update
danog Nov 2, 2022
cc7e656
Merge remote-tracking branch 'nicelocal/immutable_readonly_4' into li…
danog Nov 2, 2022
94a29e6
Improve sealed array foreach logic
danog Nov 2, 2022
71f39e1
get_object_vars on template properties
danog Nov 3, 2022
d427f19
Fix sealed array assertion reconciler logic
danog Nov 3, 2022
cf4fecc
Improved reconciler
danog Nov 3, 2022
08e7f40
Add tests
danog Nov 3, 2022
767ef6b
Single source of truth for test types
danog Nov 3, 2022
6cf4325
Fix tests
danog Nov 3, 2022
b8eeedf
Fixup tests
danog Nov 3, 2022
6b9ce13
Fixup tests
danog Nov 3, 2022
108e12a
Fixup tests
danog Nov 3, 2022
8a908ee
Update
danog Nov 3, 2022
a69d81d
Fix tests
danog Nov 3, 2022
2cf8e09
Fix tests
danog Nov 3, 2022
e42e1ac
Final fixes
danog Nov 3, 2022
14cb4d9
Fixes
danog Nov 3, 2022
b740fb6
Use list syntax only when needed
danog Nov 3, 2022
09d7674
Fix tests
danog Nov 3, 2022
e2b3f8e
Cs-fix
danog Nov 3, 2022
01c77ee
Update docs
danog Nov 3, 2022
369eacb
Update docs
danog Nov 3, 2022
dcdce4c
Update docs
danog Nov 3, 2022
2fce076
Update docs
danog Nov 3, 2022
434889c
Update docs
danog Nov 3, 2022
c5f09f7
Document missing types
danog Nov 4, 2022
04d61cc
Update docs
danog Nov 4, 2022
9e9d033
Improve class-string-map docs
danog Nov 4, 2022
ebc3e48
Update
danog Nov 4, 2022
8fa28a5
Update
danog Nov 4, 2022
131b1cb
I love working on psalm :)
danog Nov 4, 2022
3aafa57
Merge remote-tracking branch 'origin/master' into list_types
danog Nov 4, 2022
45075e8
Keep arrays unsealed by default
danog Nov 5, 2022
a168021
Fixup tests
danog Nov 5, 2022
ca0379d
Fix syntax mistake
danog Nov 5, 2022
4c83c93
cs-fix
danog Nov 5, 2022
12188ca
Fix typo
danog Nov 5, 2022
059f6bf
Re-import missing types
danog Nov 5, 2022
d2c3c28
Keep strict types only in return types
danog Nov 5, 2022
257eb93
argc/argv fixes
danog Nov 5, 2022
b440bf0
argc/argv fixes
danog Nov 5, 2022
b5996a5
Fix test
danog Nov 5, 2022
50023a2
Comment-out valinor code, pinging @romm pls merge https://github.com/…
danog Nov 5, 2022
3179ccc
Merge remote-tracking branch 'origin/master' into list_types
danog Nov 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -27,6 +27,6 @@ Have a look at [CONTRIBUTING.md](CONTRIBUTING.md).

Built by Matt Brown ([@muglug](https://github.com/muglug)).

Maintained by Orklah ([@orklah](https://github.com/orklah)) and Bruce Weirdan ([@weirdan](https://github.com/weirdan)).
Maintained by Orklah ([@orklah](https://github.com/orklah)), Daniil Gentili ([@danog](https://github.com/danog)), and Bruce Weirdan ([@weirdan](https://github.com/weirdan)).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

Copy link
Collaborator Author

@danog danog Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3 :)


The engineering team at [Vimeo](https://github.com/vimeo) have provided a lot encouragement, especially [@nbeliard](https://github.com/nbeliard), [@erunion](https://github.com/erunion) and [@nickyr](https://github.com/nickyr).
26 changes: 21 additions & 5 deletions UPGRADING.md
@@ -1,25 +1,41 @@
# Upgrading from Psalm 4 to Psalm 5
## Changed
- [BC] `Psalm\Type\Union`s are now partially immutable, mutator methods were removed and moved into `Psalm\Type\MutableUnion`.
To modify a union type, use the new `Psalm\Type\Union::getBuilder` method to turn a `Psalm\Type\Union` into a `Psalm\Type\MutableUnion`: once you're done, use `Psalm\Type\MutableUnion::freeze` to get a new `Psalm\Type\Union`.

- [BC] Shaped arrays can now be sealed: this brings many assertion improvements and bugfixes, see [the docs for more info](https://psalm.dev/docs/annotating_code/type_syntax/array_types/#sealed-object-like-arrays).

- [BC] All atomic types, `Psalm\Type\Union`, `Psalm\CodeLocation` and storages are fully immutable, use the new setter methods or the new constructors to change properties: these setter methods will return new instances without altering the original instance.
Full immutability fixes a whole class of bugs that occurred in multithreaded mode, you can now feel free to use `--threads=$(nproc)` ;)
Full immutability also makes Psalm run faster, even in single-threaded mode, by removing all superfluous `clone`s!
For this purpose, `__clone` was also made private, forbidding the cloning of atomics, unions and storages (an old and brittle pattern used to avoid side-effects caused by mutability).

- [BC] `Psalm\Type\Union`s are now fully immutable, pre-existing in-place mutator methods were removed and moved into `Psalm\Type\MutableUnion`.
To modify a union type, usage of the new setter methods in `Psalm\Type\Union` is strongly recommended.
When many consecutive property sets are required, use `Psalm\Type\Union::setProperties` method to avoid creating a new instance for each set.
All setter methods will return a new instance of the type without altering the original instance.
If many property sets are required throughout multiple methods on a single Union instance, use `Psalm\Type\Union::getBuilder` to turn a `Psalm\Type\Union` into a `Psalm\Type\MutableUnion`: once you're done, use `Psalm\Type\MutableUnion::freeze` to get a new `Psalm\Type\Union`.
Methods removed from `Psalm\Type\Union` and moved into `Psalm\Type\MutableUnion`:

- `replaceTypes`
- `addType`
- `removeType`
- `substitute`
- `replaceClassLike`

- [BC] `Psalm\Type\TypeNode::getChildNodes()` was removed, use `Psalm\Type\Union::getAtomicTypes()` to get the types of a union, and use `Psalm\Type\TypeVisitor` with the new `Psalm\Type\MutableTypeVisitor` class to iterate over a type tree.

- [BC] `Psalm\Type\TypeVisitor` is now fully immutable, implementors MUST NOT alter type nodes during iteration: use `Psalm\Type\MutableTypeVisitor` if type node mutation is desired.

- [BC] TPositiveInt has been removed and replaced by TIntRange

- [BC] The parameter `$php_version` of `Psalm\Type\Atomic::create()` renamed
to `$analysis_php_version_id` and changed from `array|null` to `int|null`.
Previously it accepted PHP version as `array{major_version, minor_version}`
Previously it accepted PHP version as `strict-array{major_version, minor_version}`
while now it accepts version ID, similar to how [`PHP_VERSION_ID` is
calculated](https://www.php.net/manual/en/reserved.constants.php#constant.php-version-id).

- [BC] The parameter `$php_version` of `Psalm\Type::parseString()` renamed to
`$analysis_php_version_id` and changed from `array|null` to `int|null`.
Previously it accepted PHP version as `array{major_version, minor_version}`
Previously it accepted PHP version as `strict-array{major_version, minor_version}`
while now it accepts version ID.

- [BC] Parameter 0 of `canBeFullyExpressedInPhp()` of the classes listed below
Expand Down Expand Up @@ -789,7 +805,7 @@
- [BC] Class `Psalm\Type\TaintKind` became final
- [BC] Class `Psalm\Type\Union` became final
- [BC] Property `Psalm\Config::$universal_object_crates` changed default value
from `array{'stdClass','SimpleXMLElement','SimpleXMLIterator'}` to `null`
from `strict-array{'stdClass','SimpleXMLElement','SimpleXMLIterator'}` to `null`

## Removed
- [BC] Property `Psalm\Codebase::$php_major_version` was removed, use
Expand Down