-
Notifications
You must be signed in to change notification settings - Fork 516
Fix memory error when trying to represent big literal string types #1088
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
Fix memory error when trying to represent big literal string types #1088
Conversation
017bbc9
to
94261e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please write a separate test in AnalyserIntegrationTest (see the other test cases there). Those are mostly for memory crashes and performance hogs like you are trying to fix.
- Please add another case that's exactly under the precision limit.
Otherwise this fix is great and exactly how I'd do it 😊
94261e2
to
8c3226b
Compare
@@ -0,0 +1,8 @@ | |||
<?php | |||
|
|||
namespace Bug6740; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespace has a different bug number then the filename.
And another bug number in the
Method name
@@ -569,6 +570,16 @@ public function testBug6740(): void | |||
$this->assertNoErrors($errors); | |||
} | |||
|
|||
public function testBug1088(): void | |||
{ | |||
$str = str_repeat('a', 99); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 lines should be moved into the data/*bug added file.
assertType
is meant for use in these data/* files
8c3226b
to
79acc55
Compare
|
||
use function PHPStan\Testing\assertType; | ||
|
||
$str = str_repeat('a', 99); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code in data/* files should be within functions or class-methods, so it won't be executed while running tests, but just been analyzed by phpstan.
Method/Class/Function-names are not relevant
Otherwise looks great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ah this is real-time feedback :)
thank you for your help!
6c6ce29
to
c8353db
Compare
function f(): void | ||
{ | ||
$str = str_repeat('a', 99); | ||
assertType('"' . $str . '"', $str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I mixed it up. The analyserIntegaration data/* files do not require the assertType calls.
You put the code in there which should work as is - see other data/ files beeing analysed by the this TestCase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok. So, should I move the assertType(...)
part of the test back to data/literal-string.php and leave only the standalone str_repeat() in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so
7cb0b4c
to
8520200
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the underscores in the number, they don't work in all PHP versions that are tested here. Otherwise looks fine 😊
8520200
to
1994c81
Compare
@@ -27,6 +27,9 @@ public function doFoo($literalString, string $string) | |||
assertType('literal-string', str_repeat($literalString, 10)); | |||
assertType("''", str_repeat('', 10)); | |||
assertType("'foofoofoofoofoofoofoofoofoofoo'", str_repeat('foo', 10)); | |||
$str = str_repeat('a', 99); | |||
assertType("'$str'", $str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, one more thing, sorry. This isn't a useful test, it's a tautology and we don't know what's getting tested here. Just repeat 'a' 99 times in the string, thanks.
1994c81
to
1179066
Compare
return a non-empty-string type instead when length is > 100
1179066
to
8888d43
Compare
ok, so everything is green except one "Compile PHAR" check, but I can't see what's going on, GitHub return a 500 "unicorn" page when trying to see the details 🤷 let me know if I can do anything about this |
Thank you! |
Well done @mathroc |
Hey, sorry, I don't want to be annoying, but shouldn't this have been merged/cherry-picked to 1.4.x (too)? |
Yeah, I've kept 1.4.x around to issue hotfixes if something really bad happens in 1.4.9 :) But I don't plan to release anything in 1.4.x anymore. BTW thanks to some changes I made, I'll be able to release 1.5.x more easily after 1.6.x is the default branch :) |
return a non-empty-string type instead when length is > 100
fix phpstan/phpstan#6866