chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.79k stars 421 forks source link

Implicit borrow upon these() #12325

Open vasslitvinov opened 5 years ago

vasslitvinov commented 5 years ago

When a class is iterated over via one of its these() methods, the user has to explicitly borrow() in several cases to make the compiler accept the code.

It would be nice to avoid that and do the borrowing implicitly. For example:

// assume c1 and c2 point to suitable class instance; myFun() is promoted
forall zip(c1,c2) do ....;
myFun(c1);
myFun(c1,c2);

This assumes that #5114 has been implemented. As of this writing, the desired property is present if the class has proc chpl__promotionType() type and we are not concerned with standalone iterators.

Tests:

test/parallel/forall/may-vs-must-par/classes-implicit-borrow-promo-1arg.chpl
test/parallel/forall/may-vs-must-par/classes-implicit-borrow-promo-2arg.chpl
test/parallel/forall/may-vs-must-par/classes-implicit-borrow-stmt-zippered.chpl
e-kayrakli commented 3 years ago

https://github.com/chapel-lang/chapel/pull/17212 resolved this to an extent by removing the chpl__iterLF tuple from the equation. But that PR didn't go all the way removing tuples for zip clauses, so there are still some cases that this issue persists. https://github.com/Cray/chapel-private/issues/1784 has list of cases where we still have tuples for zip clauses, and I believe fixing those will resolve this issue completely.