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

InvalidArgumentException + out of memory #8182

Open
michabbb opened this issue Jun 27, 2022 · 4 comments
Open

InvalidArgumentException + out of memory #8182

michabbb opened this issue Jun 27, 2022 · 4 comments

Comments

@michabbb
Copy link

michabbb commented Jun 27, 2022

hi,
same code, different psalm versions.
with psalm v4.15.0 --> all fine, no errors
with psalm v4.23.0:

with --debug --debug-by-line it get:

Getting /app/vendor/mailgun/mailgun-php/src/HttpClient/Plugin/HistoryTrait.php
Analyzing /app/vendor/mailgun/mailgun-php/src/HttpClient/Plugin/HistoryTrait.php
/app/vendor/mailgun/mailgun-php/src/HttpClient/Plugin/HistoryTrait.php:21
/app/vendor/mailgun/mailgun-php/src/HttpClient/Plugin/HistoryTrait.php:25
Uncaught InvalidArgumentException: Could not get class storage for historytrait in /app/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php:46
Stack trace:
#0 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/TraitAnalyzer.php(66): Psalm\Internal\Provider\ClassLikeStorageProvider->get('HistoryTrait')
#1 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(597): Psalm\Internal\Analyzer\TraitAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Trait_), Object(Psalm\Context))
#2 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(206): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Trait_), Object(Psalm\Context), NULL)
#3 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php(68): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context))
#4 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php(365): Psalm\Internal\Analyzer\Statements\Block\IfElse\IfAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Internal\Scope\IfScope), Object(Psalm\Internal\Scope\IfConditionalScope), Object(Psalm\Context), Object(Psalm\Context), Object(Psalm\Context), Array)
#5 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(517): Psalm\Internal\Analyzer\Statements\Block\IfElseAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context))
#6 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(206): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context), NULL)
#7 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php(92): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), NULL, true)
#8 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(316): Psalm\Internal\Analyzer\NamespaceAnalyzer->collectAnalyzableInformation()
#9 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(193): Psalm\Internal\Analyzer\FileAnalyzer->populateCheckers(Array)
#10 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(362): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#11 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(619): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}(16646, '/app/vendor/mai...')
#12 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(291): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1)
#13 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(1203): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1, false, false)
#14 /app/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(375): Psalm\Internal\Analyzer\ProjectAnalyzer->checkPaths(Array)
#15 /app/vendor/vimeo/psalm/psalm(7): Psalm\Internal\Cli\Psalm::run(Array)
#16 {main}
(Psalm 4.23.0@f1fe6ff483bf325c803df9f510d09a03fd796f88 crashed due to an uncaught Throwable)

without --debug --debug-by-line and using only one thread, I get:

mmap() failed: [12] Out of memory
mmap() failed: [12] Out of memory
Fatal error: Out of memory (allocated 1191182336) (tried to allocate 20480 bytes) in /app/vendor/nikic/php-parser/lib/PhpParser/Lexer.php on line 88

in case it has something to do with it, here´s the HistoryTrait.php

is there anything I can do except going back to 4.15 ?

thanks for any help!

@michabbb
Copy link
Author

important notice, the error appears from version 4.22 on. 4.21 and below is okay.

@orklah
Copy link
Collaborator

orklah commented Jul 18, 2022

It was most likely caused by this change: https://github.com/vimeo/psalm/pull/7727/files#diff-41dfd662b2225a26b01170877d516fe5ef1df0ef8d7703cf8527b50bbcf4bac6R66

My guess is that the compatibility layer where the trait is declared twice is badly handled in Psalm (this is not a surprise, having two symbols with the same name but different behaviour is pretty much impossible to handle) and that cause Psalm to not have this symbol registered here at all

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jul 18, 2022

I'll try to get around to fixing that soon.

@orklah I'm thinking it might work well to store some sort of identifier (filename + offset?) in the class storage, then when analyzing if that identifier from the class storage doesn't match the class declaration, we can re-scan the class to get the storage for the current declaration. I'm hoping having the identifier will prevent performance regressions since generally there will only be one class declaration for the majority of classes. I suppose if there are multiple declarations the identifier should probably either be set to null or combined somehow so it doesn't match any of the declarations, forcing a rescan when each declaration is analyzed.

If this works it should also improve analysis overall whenever there are multiple class declarations, so you don't have false negatives like this. It still leaves the problem of correctly merging conditional declarations, but I'll just leave that for later.

I haven't actually tried implementing any of this yet though, so we'll see how it ends up going.

@weirdan
Copy link
Collaborator

weirdan commented Dec 3, 2022

InvalidArgumentException should have been fixed by #8817

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants