Skip to content

Use attribute validator for assigning flags #19465

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

iluuu1994
Copy link
Member

No description provided.

@iluuu1994
Copy link
Member Author

Oh, I just noticed this has significant overlap with #18817 (which I only went to review right after this PR).

@DanielEScherzer
Copy link
Member

I'd prefer to do #18817 first since that is for an RFC

@@ -70,7 +70,8 @@ typedef struct _zend_attribute {
typedef struct _zend_internal_attribute {
zend_class_entry *ce;
uint32_t flags;
void (*validator)(zend_attribute *attr, uint32_t target, zend_class_entry *scope);
/* Parameter offsets start at 1, everything else uses 0. */
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't need both scope and target

if (target_type & (ZEND_ATTRIBUTE_TARGET_FUNCTION|ZEND_ATTRIBUTE_TARGET_METHOD)) {
zend_op_array *op_array = target;
op_array->fn_flags |= ZEND_ACC_DEPRECATED;
} else if (target_type & (ZEND_ATTRIBUTE_TARGET_CLASS_CONST)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} else if (target_type & (ZEND_ATTRIBUTE_TARGET_CLASS_CONST)) {
} else if (target_type & ZEND_ATTRIBUTE_TARGET_CLASS_CONST) {

ZEND_CLASS_CONST_FLAGS(c) |= ZEND_ACC_DEPRECATED;
/* For deprecated constants, we need to flag the zval for recursion
* detection. Make sure the zval is separated out of shm. */
scope->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;
Copy link
Member

Choose a reason for hiding this comment

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

after removing the separate scope, can use

Suggested change
scope->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;
c->ce->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;

and similar for the removal of ZEND_ACC_CONSTANTS_UPDATED

@iluuu1994
Copy link
Member Author

iluuu1994 commented Aug 15, 2025

We should also move the ZEND_ACC_NODISCARD stuff from zend_compile.c into the validator, which I missed.

https://github.com/iluuu1994/php-src/blob/49b4e45d7fa0864707e00c51b771a8ecc2b6ae0c/Zend/zend_compile.c#L8479-L8498

@iluuu1994
Copy link
Member Author

I'd prefer to do #18817 first since that is for an RFC

That's ok with me. Though it makes your patch a bit more complicated, parts of it we might want to revert again.

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