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

Port TypeParser to Hoa\Compiler #900

Merged
merged 1 commit into from
May 1, 2018

Conversation

Majkl578
Copy link
Contributor

@Majkl578 Majkl578 commented Apr 10, 2018

Q A
Bug fix? no
New feature? no
Doc updated -
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets #892

This is a port of TypeParser to Hoa\Compiler. It is entirely independent on legacy and abandoned jms/parser-lib.no
It's currently built on top of current TypeParser to achive & present the prototype and compatibility - this way it can be tested and used even on 1.x. (I won't be rebasing this on top of 2.0 PR.)

Includes/TODO:

  • grammar
  • parser (re)generator
  • legacy visitor used as a compatibility hack for 1.x
  • AST visitor to build AST tree of the type definition
  • AST-based manipulation in consumers
  • replacing occurences of the old TypeParser with the new Parser
  • dropping old TypeParser

Would love to hear some opinions / feedback. 😎

PHP <7.1 tests will be failing because of the PHP 5.x/7.0 madness.

@Majkl578
Copy link
Contributor Author

Rebased onto current master (2.0), dropping old TypeParser completely.

It serves as a drop-in replacement of old TypeParser now.
Further scope is to eliminate those arbitrary array definitions of types used everywhere. :/ Likely in separate PR.

@goetas
Copy link
Collaborator

goetas commented Apr 26, 2018

Just to understand better hoa compiler, has this code present in this PR to be "maintained" of is automatically generated by HOA? (currently to me it seems a lot of "mysterious" code landing in the main repo...)

@goetas
Copy link
Collaborator

goetas commented Apr 26, 2018

What about the phpunit warning/failure?

@goetas goetas added this to the v2.0 milestone Apr 26, 2018
@Majkl578
Copy link
Contributor Author

Majkl578 commented Apr 26, 2018

Updated.

  • Removed AST and only keep current legacy array format for types. (Likely to be rescheduled for 3.0.)
  • Added parser interface (it'd be easy to add some memory or advanced cache layer).

has this code present in this PR to be "maintained" of is automatically generated by HOA?

Regarding parsing itself, the burden is to maintain grammar.pp and TypeVisitor. InnerParser is generated code by Hoa state exporter.

What about the phpunit warning/failure?

The one there is caused by lowest deps of Hoa Compiler itself, likely dependency issue on their side. :/

@Majkl578 Majkl578 changed the title [Prototype] Port TypeParser to Hoa Compiler Port TypeParser to Hoa\Compiler Apr 26, 2018
@Majkl578
Copy link
Contributor Author

Reported here: hoaproject/Compiler#83

@Majkl578 Majkl578 force-pushed the type-parser-hoa branch 2 times, most recently from 81c8cc6 to 8508128 Compare April 28, 2018 21:25
@Majkl578
Copy link
Contributor Author

Majkl578 commented Apr 28, 2018

Right, for now I added conflicts with incompatible lowest deps, that should be good enough.

@goetas
Copy link
Collaborator

goetas commented Apr 29, 2018

can you rebase this please?

@Majkl578
Copy link
Contributor Author

done

@goetas
Copy link
Collaborator

goetas commented Apr 29, 2018

Did some benchmarking...

$typeParser = new \JMS\Serializer\Type\Parser();// HOA
$typeParser = new \JMS\Serializer\TypeParser(); // current parser
///
$typeParser->parse('array<string, User>');
$t = microtime(true);
for ($i = 0; $i < 100000; $i++) {
    $typeParser->parse('array<string, User>');
}

var_dump(microtime(true)-$t);

Results:

float(0.58429503440857)
float(10.030526161194)

Not that fast 😞

@Majkl578
Copy link
Contributor Author

a) you are not going to parse a type 100000x, not even 10000x, 1000x, maybe 100x
b) result is to be cached as part of Metadata anyway so this shouldn't be an issue
c) ParserInterface gives another opportunity for CachedParser (on different level than Metadata)

"doctrine/annotations": "^1.0",
"doctrine/instantiator": "^1.0.3"
"doctrine/instantiator": "^1.0.3",
"hoa/compiler": "^3.17.08.08"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity, which versioning scheme does HOA follows? Is this some kind of 3.x?

Copy link
Contributor Author

@Majkl578 Majkl578 Apr 30, 2018

Choose a reason for hiding this comment

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

If I understand correctly, it's <major>.<releaseyear>.<releasemonth>.<releaseday>. Looks pretty weird, but incidentally works with semver. 😂

@goetas
Copy link
Collaborator

goetas commented May 1, 2018

Even if performance wise there is a drop of 2% on a single iteration, there are advantages with using a AST based parser. Plus having JMS\Serializer\Type\ParserInterface allow us to change in the future the compiler implementation if necessary

@goetas goetas merged commit 9314472 into schmittjoh:master May 1, 2018
@goetas goetas mentioned this pull request May 1, 2018
@Majkl578 Majkl578 deleted the type-parser-hoa branch May 1, 2018 10:07
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.

2 participants