Repository navigation
Solve accumulator templates that cycle through several closures together - #7213
Merged
Merged
Conversation
A template a closure argument returns and another one takes, as the T and U of callable(T): U and callable(U): T passed together, is now solved by the same fixed point as a single closure's accumulator. Each round types the closures in the order their data flows, and only a closure's return grows the templates it returns. Amp-Thread-ID: https://ampcode.com/threads/T-01a21c3c-cedc-7330-a083-cc986590888f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #7212.
#7212 solves an accumulator that one closure feeds back to itself, as the
TCarryofcallable(TCarry, T): TCarry. A template can also cycle through several closures: one closure returns it, and another one takes it. Before this PR, every closure was typed on its own, so the cycle never ran more than once:ArgumentsHandler::solveClosureAccumulatorTypes()now solves the call's closures together:GenericParametersAcceptorResolver::getCallableTemplateFlow()reports both sides for each parameter. A single-closure accumulator is the case where both sides are in one parameter.LOOP_SCOPE_ITERATIONS/GENERALIZE_AFTER_ITERATIONwidening as Resolve accumulator templates of a closure to a fixed point #7212. Without a fixed point, every closure falls back togatherClosureArgType()alone, as before.pongPingtypedgbeforeUwas known and leakedfloat|intintoT.array $u) is an upper bound onU, not a value for it. Joining it in widenedUtoarray.falready sees whatgreturns.The C++ port in
turbo-ext/src/ArgumentsHandler.cppmirrors the solver.getCallableTemplateFlow()andresolveAccumulatorTemplateTypes()stay PHP static methods that it calls.resolveAccumulatorTemplateTypes()now takes the accumulator names instead of one parameter, and skips an accumulator the arguments don't determine instead of returning null. Neither method is@api.Tests:
nsrt/template-accumulator-fixed-point.php. Without the source change, four of their assertions fail.pingPong(0, fn ($t) => [$t], fn ($u) => count($u) + 1)stays0|2, which is the exact fixed point, so it is not over-widened.bug-7280andbug-15388, are unchanged.Checks:
side-by-side.php,signature-parity.phpandsmoke.phppass.The first commit adds the
// lint >= 8.0comment thatbug-7280.phpfrom #7212 was missing. It usesinitial:, soRequiredPhpVersionCommentTestfails on2.3.xwithout it.