Skip to content

Avoid inherited method clone when no generic slot changes#4

Merged
azjezz merged 1 commit into
carthage-software:rfc/bound-erased-generic-types-historyfrom
prateekbhujel:prateekbhujel/generics-fix-inherited-method-return-lifetime
May 12, 2026
Merged

Avoid inherited method clone when no generic slot changes#4
azjezz merged 1 commit into
carthage-software:rfc/bound-erased-generic-types-historyfrom
prateekbhujel:prateekbhujel/generics-fix-inherited-method-return-lifetime

Conversation

@prateekbhujel
Copy link
Copy Markdown

The failing CI job was Zend/tests/generics/inheritance/method/inherited_method_with_named_with_args_return.phpt.

That case has a method-level generic return Box<O>. The method still has generic side-table data, but inheriting it into StringBox extends Box<string> does not actually substitute any class-scope slot.

zend_substitute_trait_method_arg_info() was still cloning the arg_info block eagerly, even when no parameter or return type changed. This keeps the original arg_info unless a substitution actually writes into the cloned block.

Tests run:

make -j$(sysctl -n hw.ncpu)
sapi/cli/php run-tests.php -q -d opcache.enable_cli=1 -d opcache.jit=function -d opcache.protect_memory=1 -d opcache.jit_buffer_size=64M Zend/tests/generics/inheritance/method/inherited_method_with_named_with_args_return.phpt
sapi/cli/php run-tests.php -q -d opcache.enable_cli=1 -d opcache.jit=tracing -d opcache.protect_memory=1 -d opcache.jit_buffer_size=64M Zend/tests/generics/inheritance/method/inherited_method_with_named_with_args_return.phpt
sapi/cli/php run-tests.php -q Zend/tests/generics/inheritance/method Zend/tests/generics/traits ext/reflection/tests/generics
sapi/cli/php run-tests.php -q Zend/tests/generics ext/reflection/tests/generics

Only clone arg_info for inherited generic methods once a class-scope substitution actually changes a parameter or return type.

A method-level generic return such as Box<O> still has generic side-table data, but it does not require a class-scope substitution when inherited by Box<string>. Leaving the original arg_info in place avoids creating an unnecessary substituted clone.
@azjezz azjezz merged commit 33e6090 into carthage-software:rfc/bound-erased-generic-types-history May 12, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants