Branch: refs/heads/main
Revision: a8726212b59b258309972e54c8bdc4aeb6cb3392
Author: DanilaFe
Link: Fix promotion with named arguments by DanilaFe · Pull Request #28109 · chapel-lang/chapel · GitHub
Log Message:
Fix promotion with named arguments (#28109)
Closes Compilation failure for promotion and named-expression · Issue #11225 · chapel-lang/chapel · GitHub.
There were a few issues in resolving promoted calls that had to do with
the order of arguments. Specifically, the code expected that actual
indices in the final call line up with the formal indices of the called
function. This assumption occurred twice:
- Once when finding the leader/follower arguments for generating the
promoted calls. They used the actual index to look into the formal
array. - Once when generating a call to the promotion wrapper, in which the
actuals were copied verbatim from the call removing their names.
Thus, calls like foo(x = 1) were turned into calls like
foo_promo(1), which did not preserve the actual order.
In general, since we already have a formal-actual mapping, it seemed
most robust to always insert pass named arguments. This way, we remove
any ordering ambiguities. I made this change (which required some tweaks
to other logic that only expected SymExprs and not NamedExprs).
Furthermore, I re-wrote leadingArg and haveLeaderAndFollowers to use
the formal-actual map instead of assuming actuals map to formals in the
same order. This resolved the original issue (see tests).
Reviewed by @jabraham17 -- thanks!
Testing
- paratest
Diff:
M compiler/resolution/wrappers.cpp
A test/functions/promotion/issue-11225.chpl
A test/functions/promotion/issue-11225.good
https://github.com/chapel-lang/chapel/pull/28109.diff