-
Notifications
You must be signed in to change notification settings - Fork 7.8k
[RFC] Add support for attributes on compile-time constants #16952
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
base: master
Are you sure you want to change the base?
Conversation
There are going to be some memory issues that CI will report, I couldn't figure those out, asked for help on the mailing list, https://news-web.php.net/php.internals/126065 |
So there are also opcache failures, not just the failures I had locally - I guess a data op isn't the right way to send a pointer to the attributes from the compilation to the runtime - I'll see if I can have it send the raw AST and delay the attribute compilation until runtime |
So for the life of me, I can't figure out why I'm unable to get the cleanup in free_zend_constant() to run properly - I added debugging code diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c
index 8b92650816..ade2efb618 100644
--- a/Zend/zend_constants.c
+++ b/Zend/zend_constants.c
@@ -41,6 +41,8 @@ void free_zend_constant(zval *zv)
{
zend_constant *c = Z_PTR_P(zv);
+ fprintf(stderr, "Freeing constant %s\n", ZSTR_VAL(c->name));
+
if (!(ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT)) {
zval_ptr_dtor_nogc(&c->value);
if (c->name) {
@@ -50,7 +52,7 @@ void free_zend_constant(zval *zv)
zend_string_release_ex(c->filename, 0);
} and none of the compile-time constants in my test script are listed as being freed, though plenty of php-provided ones are. If the cleanup is never reached, then it makes sense that the attributes are not properly freed, but why isn't the cleanup reached? |
From f411ddf4c984ed8d614d003e9eb209387b904f9b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= <[email protected]>
Date: Wed, 27 Nov 2024 17:32:48 +0100
Subject: [PATCH] Fix constant attribute leak
---
Zend/zend_execute_API.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index 9ebc15f3a4..f4adeb855f 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -302,6 +302,9 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown)
if (c->filename) {
zend_string_release_ex(c->filename, 0);
}
+ if (c->attributes) {
+ zend_hash_release(c->attributes);
+ }
efree(c);
zend_string_release_ex(key, 0);
} ZEND_HASH_MAP_FOREACH_END_DEL();
--
2.43.0 This appears to fix the leak for me. I did not verify if it is possible to call |
Thanks - I forgot there was a second place that constants are freed, though I should have remembered it from adding |
So on circleci the deprecation messages don't seem to be properly found, and on windows there are failures with exit code 1073741819, but only for the Reflection tests |
@DanielEScherzer This is not related to CircleCI / ARM, but to JIT. You should be able to reproduce the issue locally with:
see: #11293 (comment) |
I have taken the liberty to push a fix into your PR. |
I can reproduce issues for the 3 tests that fail on Windows by using a non-debug ZTS build and running with Valgrind. Specifically when I configure as follows:
And run the tests as follows:
Running
|
RFC filed: https://wiki.php.net/rfc/attributes-on-constants |
e8f731b
to
50f88e5
Compare
Rebased to update for #17101 fix, then squashed and added UPGRADING |
50f88e5
to
819ed7e
Compare
819ed7e
to
5b65cd9
Compare
Fixed conflict from #17306 |
5b65cd9
to
6f5e5cc
Compare
Rebased to fix conflict from #17056 - @iluuu1994 do you think you might have a chance to review this soon? I see that @TimWolla requested that you take a look |
Yes, I'll review tomorrow. |
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.
You should try running with ASAN, it will reveal some failures in both Zend/tests/attributes/constants
and Zend/tests/attributes/deprecated
related to shutdown/cleanup of attributes.
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.
Thanks for figuring out that the infinite recursion wasn't caused by me, and about how to pass a pointer to the runtime - once the fix for #17711 is merged I'll rebase this patch and address any remaining feedback
Zend/tests/attributes/constants/named_parameter_validation.phpt
Outdated
Show resolved
Hide resolved
This is also missing function JIT support...
|
a7e9a57
to
9a97441
Compare
9a97441
to
59b778a
Compare
I've rebased and squashed this patch. I plan to merge in around a week if there are no further review comments |
@DanielEScherzer Please wait, I haven't gotten around the final review. Sorry for the delay. |
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.
Some comments. Did not have an in-depth look at this.
. Added support for attributes on compile-time non-class constants. | ||
. Added constant Attribute::TARGET_CONSTANT. | ||
. The #[\Deprecated] attribute can now be used on constants. | ||
RFC: https://wiki.php.net/rfc/attributes-on-constants |
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.
. Added support for attributes on compile-time non-class constants. | |
. Added constant Attribute::TARGET_CONSTANT. | |
. The #[\Deprecated] attribute can now be used on constants. | |
RFC: https://wiki.php.net/rfc/attributes-on-constants | |
. Added support for attributes on compile-time non-class constants. | |
RFC: https://wiki.php.net/rfc/attributes-on-constants | |
. The #[\Deprecated] attribute can now be used on constants. | |
RFC: https://wiki.php.net/rfc/attributes-on-constants |
The Attribute::TARGET_CONSTANT
is implied and the RFC should be linked for every change, since it's not always clear what belongs together.
/* Has IS_PTR operands that needs special cleaning | | | */ | ||
#define ZEND_ACC_PTR_OPS (1 << 28) /* | X | | */ | ||
/* | | | */ |
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.
Does this conflict with ZEND_ACC_OVERRIDE
/ is this placed in the correct section?
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.
It is applied to function flags, so it is in the correct section, see usage in zend_compile_const_decl()
It shouldn't conflict because constants are only valid at the top level, where CG(active_op_array)
isn't a real function, and definitely isn't a class method
https://wiki.php.net/rfc/attributes-on-constants