Skip to content

Conversation

@iluuu1994
Copy link
Member

Fixes php/php-tasks#35

ce->flags will follow in a separate PR.

zend_function *mptr;
uint32_t keep_flags = ZEND_ACC_PPP_MASK
/* Keep in mind that all userland-exposed flags should fit in the low 32-bits
* for 32-bit architectures. Shuffle ZEND_ACC_* flags around accordingly. */
Copy link
Member

Choose a reason for hiding this comment

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

we should add some kind of test or assertion for this. Maybe

ZEND_ASSERT(keep_flags < (1 << 31));

so that if we ever change the values of the flags things would instantly break?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ofc, makes sense.

#define ZEND_ACC_NOT_SERIALIZABLE (1 << 29) /* X | | | */
/* | | | */
/* Function Flags (unused: 30) | | | */
/* Function Flags (unused: 30,32-63) | | | */
Copy link
Member

Choose a reason for hiding this comment

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

can just say

Suggested change
/* Function Flags (unused: 30,32-63) | | | */
/* Function Flags (unused: 30,32...) | | | */

like property flags above

/* }}} */

const char *zend_visibility_string(uint32_t fn_flags) /* {{{ */
const char *zend_visibility_string(uint32_t flags) /* {{{ */
Copy link
Member

Choose a reason for hiding this comment

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

why is this not updated to use zend_fn_flags? Given that visibility is used for methods, we no longer guarantee that the flags fit into 32 bits. Maybe add an assertion at the top?

ZEND_ASSERT((ZEND_ACC_PUBLIC|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED) < (1 << 31));

Copy link
Member Author

Choose a reason for hiding this comment

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

This is used for non-functions (e.g. class constants). For functions, we'll simply drop the high-bits when calling the function. The assertion makes sense, though it can probably be a static assert.

ZEND_ASSERT(rx != IR_UNUSED);
ir_ref if_trampoline_or_generator = ir_IF(ir_AND_U32(
ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_function, common.fn_flags))),
ir_TRUNC_U32(ir_LOAD_U64(ir_ADD_OFFSET(func_ref, offsetof(zend_function, common.fn_flags)))),
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the JIT enough to be confident in this comment, but it seems that this makes it so that only 32 of the bits are usable here? Or that at least ZEND_ACC_CALL_VIA_TRAMPOLINE and ZEND_ACC_GENERATOR need to be in the bottom 32 bits?

Same with some of the other flags down below

Copy link
Member Author

Choose a reason for hiding this comment

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

They need to be in the bottom bits, yes. I haven't tested it, but IR should be able to optimize this back to a ir_LOAD_U32() on little-endian platforms. The aim was to change as few things as possible.

Or that at least ZEND_ACC_CALL_VIA_TRAMPOLINE and ZEND_ACC_GENERATOR need to be in the bottom 32 bits?

They are (nothing uses the high bits yet), but we can also add an assert.

const struct _zend_internal_arg_info *arg_info;
uint32_t num_args;
uint32_t flags;
zend_fn_flags flags;
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be easier to introduce yet another filed (e.g. flags2).

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be easier indeed, but also a bit more confusing (i.e. having to remember which field is stored in which flag). This can be partially mitigated by naming the flags accordingly (e.g. ZEND_ACC2_*). But ok, Niels has suggested the same thing, so let me implement that instead.

iluuu1994 added a commit to iluuu1994/php-src that referenced this pull request Sep 29, 2025
iluuu1994 added a commit to iluuu1994/php-src that referenced this pull request Sep 29, 2025
@iluuu1994 iluuu1994 closed this Sep 29, 2025
iluuu1994 added a commit to iluuu1994/php-src that referenced this pull request Sep 29, 2025
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.

Running out of ce_flags and fn_flags options

3 participants