Skip to content

Commit

Permalink
Add support for strict arrays, fix type alias intersection, fix array…
Browse files Browse the repository at this point in the history
…_is_list assertion on non-lists (#8395)

* Immutable CodeLocation

* Remove excess clones

* Remove external clones

* Remove leftover clones

* Fix final clone issue

* Immutable storages

* Refactoring

* Fixes

* Fixes

* Fix

* Fix

* Fixes

* Simplify

* Fixes

* Fix

* Fixes

* Update

* Fix

* Cache global types

* Fix

* Update

* Update

* Fixes

* Fixes

* Refactor

* Fixes

* Fix

* Fix

* More caching

* Fix

* Fix

* Update

* Update

* Fix

* Fixes

* Update

* Refactor

* Update

* Fixes

* Break one more test

* Fix

* FIx

* Fix

* Fix

* Fix

* Fix

* Improve performance and readability

* Equivalent logic

* Fixes

* Revert

* Revert "Revert"

This reverts commit f917510.

* Fix

* Fix reference bug

* Make default TypeVisitor immutable

* Bugfix

* Remove clones

* Partial refactoring

* Refactoring

* Fixes

* Fix

* Fixes

* Fixes

* cs-fix

* Fix final bugs

* Add test

* Misc fixes

* Update

* Fixes

* Experiment with removing different property

* revert "Experiment with removing different property"

This reverts commit ac1156e.

* Uniform naming

* Uniform naming

* Hack hotfix

* Clean up $_FILES ref #8621

* Undo hack, try fixing properly

* Helper method

* Remove redundant call

* Partially fix bugs

* Cleanup

* Change defaults

* Fix bug

* Fix (?, hope this doesn't break anything else)

* cs-fix

* Review fixes

* Bugfix

* Bugfix

* Improve logic

* Add support for list{} and callable-list{} types, properly implement array_is_list assertions (fixes #8389)

* Default to sealed arrays

* Fix array_merge bug

* Fixes

* Fix

* Sealed type checks

* Properly infer properties-of and get_object_vars on final classes

* Fix array_map zipping

* Fix tests

* Fixes

* Fixes

* Fix more stuff

* Recursively resolve type aliases

* Fix typo

* Fixes

* Fix array_is_list assertion on keyed array

* Add BC docs

* Fixes

* fix

* Update

* Update

* Update

* Update

* Seal arrays with count assertions

* Fix #8528

* Fix

* Update

* Improve sealed array foreach logic

* get_object_vars on template properties

* Fix sealed array assertion reconciler logic

* Improved reconciler

* Add tests

* Single source of truth for test types

* Fix tests

* Fixup tests

* Fixup tests

* Fixup tests

* Update

* Fix tests

* Fix tests

* Final fixes

* Fixes

* Use list syntax only when needed

* Fix tests

* Cs-fix

* Update docs

* Update docs

* Update docs

* Update docs

* Update docs

* Document missing types

* Update docs

* Improve class-string-map docs

* Update

* Update

* I love working on psalm :)

* Keep arrays unsealed by default

* Fixup tests

* Fix syntax mistake

* cs-fix

* Fix typo

* Re-import missing types

* Keep strict types only in return types

* argc/argv fixes

* argc/argv fixes

* Fix test

* Comment-out valinor code, pinging @romm pls merge CuyZ/Valinor#246 so we can add valinor to the psalm docs :)
  • Loading branch information
danog committed Nov 5, 2022
1 parent 205e8cc commit 1986c8b
Show file tree
Hide file tree
Showing 251 changed files with 2,703 additions and 1,676 deletions.
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)).

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

0 comments on commit 1986c8b

Please sign in to comment.