Branch: refs/heads/main
Revision: 3533112b9f164885cde6e3b281199f48e355c65d
Author: DanilaFe
Link: Dyno: enable Iteration over heterogenous tuples by DanilaFe · Pull Request #26634 · chapel-lang/chapel · GitHub
Log Message:
Dyno: enable Iteration over heterogenous tuples (#26634)
Closes https://github.com/Cray/chapel-private/issues/6740.
proc foo(x) {
compilerWarning(x.type : string);
}
proc helper(xs ...?k) {
for x in xs {
foo(x);
}
}
helper(1, "red", 4.2);
Produces:
─── warning in heterotup.chpl:7 [UserDiagnosticEmitWarning] ───
Int(64)
>
7 | foo(x);
>
─── warning in heterotup.chpl:7 [UserDiagnosticEmitWarning] ───
String
>
7 | foo(x);
>
─── warning in heterotup.chpl:7 [UserDiagnosticEmitWarning] ───
Real(64)
>
7 | foo(x);
>
I implemented this by piggybacking off param
loop iteration. The
fundamental principle is the same (in fact, you can consider iteration
over heterogeneous tuples to be by a for param
over the tuple's
bounds, accessing each individual element), and we already have a
convenient way to note several iterations of the same loop with
different types.
Reviewed by @benharsh -- thanks!
Testing
- dyno tests
- paratest
Diff:
M frontend/include/chpl/resolution/ResolvedVisitor.h
M frontend/lib/resolution/Resolver.cpp
M frontend/test/resolution/testLoopIndexVars.cpp
https://github.com/chapel-lang/chapel/pull/26634.diff