Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instrumentation to enhanced for when iterating suspendable Iterables #285

Open
FroMage opened this issue Aug 8, 2017 · 2 comments
Open

Comments

@FroMage
Copy link

FroMage commented Aug 8, 2017

Hi,

I'm trying a suspendable Iterable and I can't get it to work in enhanced for loops, probably due to the instrumentation not detecting that the Iterator has @Suspendable in its next() method definition.

Would it be possible to add support in instrumenting for loops, where the iterated element has a suspendable iterator as determined statically?

In my case, I'm doing:

class SuspendableIterable<T> implements Iterable<T> {
 @Override
 public SuspendableIterator<T> iterator() {
  return new SuspendableIterator<>(...);
 }
}
class SuspendableIterator<T> implements Iterator<T> {
 @Override
 @Suspendable
 public T next() {
  ...
 }
 @Override
 @Suspendable
 public boolean hasNext() {
  ...
 }
 ...
}

SuspendableIterable<Integer> it = ...;
for(int i : it){
}

And this breaks because the instrumentation does not detect that the for loop will call hasNext/next which are suspendable. I think this can be determined statically, no?

@FroMage
Copy link
Author

FroMage commented Aug 8, 2017

Especially since the following works, and should be equivalent in the bytecode, no?

for(SuspendableIterator<Integer> it2 = it.iterator(); it2.hasNext() ; ){
 int i = it2.next();
 System.err.println("Got item: "+i);
}

FroMage added a commit to FroMage/quasi that referenced this issue Nov 24, 2017
FroMage added a commit to FroMage/quasi that referenced this issue Nov 24, 2017
@FroMage
Copy link
Author

FroMage commented Nov 24, 2017

I've added a PR for this in #297

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

No branches or pull requests

1 participant