encore icon indicating copy to clipboard operation
encore copied to clipboard

Error generating c-code when mutually calling stream functions in the same active class

Open PhucVH888 opened this issue 8 years ago • 7 comments

In the same class, the c-code is generated incorrect when calling one stream function inside another stream function. One argument is missing/ when generating c-code.

For instance:

class Foo {
  stream foo1() : int
    yield 1
  stream foo2() : int 
    let foo3 = this.foo1()
    in yield 2
}
class Main
  def main() : void
    ()

The error:

test_src/Foo.encore.c:67:66: error: too few arguments to function call, expected 3, have 2
  int64_t _sync_method_call_0 = _enc__method_Foo_foo1(_ctx, _this);
                                ~~~~~~~~~~~~~~~~~~~~~            ^
test_src/Foo.encore.c:52:1: note: '_enc__method_Foo_foo1' declared here
void _enc__method_Foo_foo1(pony_ctx_t* _ctx, _enc__active_Foo_t* _this, stream_t* _stream)
^
1 error generated.
 *** Compilation failed with exit code 1 ***

PhucVH888 avatar May 11 '16 09:05 PhucVH888

Calling a streaming method on yourself is semantically interesting (i.e. "what does it mean?"). If foo2 was to call get foo3, the actor would deadlock, so you can't read from your own stream. I would guess that the only thing you can do with foo3 is return it (after which the actor itself can start populating the stream) or pass it to another actor. What's the intended use case?

In any case, the error stems from the fact that all calls on this are considered synchronous. Look at the MethodCall cases in Expr.hs and Typechecker.hs. A temporary workaround might be to bind this to another variable and call the streaming method on that:

stream foo2() : int {
  let that = this;
  let foo3 = that.foo1();
  yield 2;
}

EliasC avatar May 11 '16 09:05 EliasC

Not the get this.foo3 case. My intention is to pass this.foo3(), the expected result of stream foo2() : Stream int is Stream (Stream int).

We probably can fix it by placing foo2() and foo1() in 2 different active classes, but I don't think that's a good way.

PhucVH888 avatar May 12 '16 11:05 PhucVH888

Ideally, one could continue the stream produced in foo2 with the one produced by foo1. This needs language level support, though.

supercooldave avatar May 12 '16 11:05 supercooldave

@PhucVH888 @EliasC @kikofernandez
This is blocking me ticking off the October 16 sprint (!). Can this be removed or moved elsewhere so I can tick it off?

TobiasWrigstad avatar Jan 27 '17 16:01 TobiasWrigstad

I think that things that have not been achieved in the milestone should be moved to an "Incomplete milestone" or similar, where we can start piling up things that we did not manage to finish on time and should be moved / reconsider for next milestone

kikofernandez avatar Jan 27 '17 16:01 kikofernandez

Thanks Kiko. Doing that now!

TobiasWrigstad avatar Jan 27 '17 16:01 TobiasWrigstad

If we agree with my approach, we can have the monthly review on what has been and what has NOT been achieved. We could discuss the reasons for not finishing on time. It could be that we underestimated the issue, that the assigned person doesn't have time at the moment or that the assignee (person in charge) needs a bit of help :)

kikofernandez avatar Jan 27 '17 16:01 kikofernandez