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

dartk: Await/Yield points during expression evaluation of assert statements #28498

Closed
mkustermann opened this issue Jan 24, 2017 · 7 comments
Closed
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-kernel P1 A high priority bug; for example, a single project is unusable or has many test failures
Milestone

Comments

@mkustermann
Copy link
Member

mkustermann commented Jan 24, 2017

Currently the following code

main() async {
  assert(await false);
}

is compiled (with async/await transformer) to

  static method main() → dynamic /* not debuggable */ {
    final asy::Completer<dynamic> :completer = asy::Completer::sync<dynamic>();
    dynamic :return_value;
    dynamic :async_op_then;
    dynamic :async_op_error;
    dynamic :await_jump_var = 0;
    dynamic :await_ctx_var;
    function :async_op([dynamic :result, dynamic :exception, dynamic :stack_trace]) → dynamic yielding 
      try {
        #L1:
        {}
        :completer.complete(:return_value);
        return;
      }
      on dynamic catch(dynamic :exception, dynamic :stack_trace) {
        :completer.completeError(:exception, :stack_trace);
      }
    :async_op_then = asy::_asyncThenWrapperHelper(:async_op);
    :async_op_error = asy::_asyncErrorWrapperHelper(:async_op);
    asy::Future::microtask<dynamic>(:async_op);
    return :completer.future;
  }

Due to the following TODO in the pkg/kernel/lib/transformers/continuation.dart:

  TreeNode visitAssertStatement(AssertStatement stmt) {
    // TODO!
    return null;
  }

With our old block expressions this might have been easier to handle.

/cc @kmillikin & #28263

@mkustermann mkustermann changed the title Await/Yield points during expression evaluation of assert statements dartk: Await/Yield points during expression evaluation of assert statements Jan 24, 2017
@mraleph
Copy link
Member

mraleph commented Mar 27, 2017

@kmillikin & @asgerf: We need a way to express this in Kernel

@jensjoha jensjoha added the P2 A bug or feature request we're likely to work on label Jan 9, 2018
@mraleph mraleph added P0 A serious issue requiring immediate resolution and removed P2 A bug or feature request we're likely to work on labels Mar 2, 2018
@mraleph
Copy link
Member

mraleph commented Mar 2, 2018

I am escalating this, I just wasted a lot of time debugging a Flutter plugin test because of assert statement was silently eaten away by the transformer.

@mraleph
Copy link
Member

mraleph commented Mar 2, 2018

Please triage /cc @kmillikin

@mraleph mraleph added this to the I/O Beta 2 milestone Mar 2, 2018
@kmillikin kmillikin added P1 A high priority bug; for example, a single project is unusable or has many test failures and removed P0 A serious issue requiring immediate resolution labels Mar 2, 2018
@kmillikin
Copy link

The issue is that the async-elimination transformer translates an expression containing await into a sequence of statements with calls to runtime support functions and a fresh expression. We need to guard this sequence of statements so it is evaluated only when assert is enabled.

We will solve this in Kernel by eliminating assert entirely and adding a simpler form which is a nullary expression AssertsEnabled. The encoding of assert(e, m) is then:

if (AssertsEnabled) if (!e) throw AssertionError(m)

We can optionally provide a mechanism for a back end to control the specific constructor that is used for the error.

@mkustermann
Copy link
Member Author

To avoid the increase in binary size due to desugaring (and taking a bit of control away from backends) you could also consider something similar, namely adding a class AssertBlock extends Statement (similar to the existing Block, or adding a flag on Block).

Then the await/async transformer can work as usual.

Just a suggestion!

@dgrove
Copy link
Contributor

dgrove commented Mar 9, 2018

@kmillikin Any updates on this?

@kmillikin
Copy link

I have a fix in flight, but it will have to wait until tomorrow (Tuesday) at this point.

@kmillikin kmillikin added area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-kernel labels Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-kernel P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

5 participants