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 DNF types #159

Merged
merged 24 commits into from
Dec 8, 2022
Merged

Add support for DNF types #159

merged 24 commits into from
Dec 8, 2022

Conversation

IonBazan
Copy link
Contributor

@IonBazan IonBazan commented Nov 21, 2022

Q A
Documentation no
Bugfix no
BC Break no (not yet)
New Feature yes
RFC no
QA no

Description

Basic support for DNF types (as per #142)

Code review welcome, I'd like to know if this is the right direction. Collaboration is welcome too 🙏🏻 .

@Ocramius Ocramius added this to the 4.8.0 milestone Nov 22, 2022
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

Let's get psalm happy, before continuing this :D

src/Generator/TypeGenerator/AtomicType.php Outdated Show resolved Hide resolved
src/Generator/TypeGenerator/BaseComplexType.php Outdated Show resolved Hide resolved
src/Generator/TypeGenerator/BaseComplexType.php Outdated Show resolved Hide resolved
test/Generator/TypeGenerator/UnionTypeTest.php Outdated Show resolved Hide resolved
@IonBazan IonBazan force-pushed the feature/dnf branch 6 times, most recently from a6fdf0c to 6f0e7ee Compare November 23, 2022 09:18
@IonBazan IonBazan marked this pull request as ready for review November 23, 2022 09:20
@IonBazan IonBazan changed the title Add basic DNF type objects Add support for DNF types Nov 23, 2022
@IonBazan
Copy link
Contributor Author

IonBazan commented Nov 23, 2022

The tests are passing on both PHP 8.1 and 8.2. I added some more test cases too.

Not sure if you want to keep CompositeTypeTest as it overlaps with what TypeGeneratorTest checks but it's definitely much easier to debug things having a separate test.

There is a lot of mess and code duplication in toString() and __toString() methods - not quite sure how to handle that nicely but I'm open to suggestions. Technically I could move everything back to the TypeGenerator and allow storing TypeGenerator[] in types but I feel it would give it too many responsibilities. Besides, it doesn't have a common interface with AtomicType (and shouldn't).

Idk why is psalm crashing 🤷🏻‍♂️

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

Overall looking good from the tests: implementation will need a lot of careful reading / focus :)

Otherwise nice work!

I'll check it out locally when I can, and get it shipped.

src/Generator/TypeGenerator/TypeInterface.php Outdated Show resolved Hide resolved
@Ocramius
Copy link
Member

The crash in psalm is... novel :O

I wonder if we should just try going vimeo/psalm:^5.0.0-rc1?

@IonBazan
Copy link
Contributor Author

Psalm v5 crashes there too so no solution for that so far 😝

@IonBazan
Copy link
Contributor Author

IonBazan commented Nov 28, 2022

Well, Psalm is kinda fixed now - produces many more errors but at least the analysis completes. You may want to add them to baseline later.
image

Locked at dev-master as v5.0.0-rc1 does not allow PHP 8.2.

IonBazan and others added 4 commits December 7, 2022 16:50
Signed-off-by: Ion Bazan <ion.bazan@gmail.com>
Signed-off-by: Ion Bazan <ion.bazan@gmail.com>
Signed-off-by: Ion Bazan <ion.bazan@gmail.com>
…ting DNF types

Disjunctive Normal Form types are hard, yo!

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
@Ocramius
Copy link
Member

Ocramius commented Dec 7, 2022

@IonBazan I'm picking this up: vimeo/psalm:^5.1.0 fixed the issue with scanning DNF types, apparently :)

@IonBazan
Copy link
Contributor Author

IonBazan commented Dec 7, 2022

Great, thanks! Let me know if any help is needed.

This stuff is a bunch of junk: on purpose.

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
…empty-string`

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
… effects

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
Signed-off-by: Marco Pivetta <ocramius@gmail.com>
…always guaranteed to be generated

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
Since `vimeo/psalm:^5`, inheriting from a class that declares
generic types also does require generic types to be declared
while extending.

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
…g and type improvements

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

Still working on it - got stuck on paid work :P

src/Generator/TypeGenerator/AtomicType.php Outdated Show resolved Hide resolved
src/Generator/TypeGenerator/CompositeType.php Outdated Show resolved Hide resolved
src/Generator/TypeGenerator/CompositeType.php Outdated Show resolved Hide resolved
src/Generator/TypeGenerator/CompositeType.php Outdated Show resolved Hide resolved
…nternals

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
…pe` instances

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
… `IntersectionType` instances

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
Signed-off-by: Marco Pivetta <ocramius@gmail.com>
Signed-off-by: Marco Pivetta <ocramius@gmail.com>
…ted internally

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
…/intersection type abstractions

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
This massively reduces the internal complexity
of the `TypeGenerator`, since we convert
`ReflectionType` symbols **directly** to our `@internal`
data structures, ready to be rendered.

Before this, we would cast the whole `ReflectionType` to a `string` that
fits our need, and then we would go back to parsing that string, with
a substantial overhead (especially considering the newly introduced
validation rules around DNF types).

Note that this introduces new Psalm violations that were added to `psalm-baseline.xml`,
but which are solved by my work @ vimeo/psalm#8722

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
Signed-off-by: Marco Pivetta <ocramius@gmail.com>
@Ocramius
Copy link
Member

Ocramius commented Dec 8, 2022

@IonBazan as you can see, I ended up using a radically different representation of internal types, mostly so that it can be understood at runtime.

Shipping this now :)

…not useful in this codebase

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
@Ocramius Ocramius merged commit 27f73dd into laminas:4.8.x Dec 8, 2022
@IonBazan IonBazan deleted the feature/dnf branch December 8, 2022 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants