dart-lang/language

update spec on evaluation order of deferred checks

Opened this issue · 5 comments

I couldn't find in the spec a lot of details explaining deferred checks. The program below:

import 'a.dart' deferred as a;

main() {
  var x = 1;
  try {
    a.foo(x = 2);
  } finally {
    print(x);
}

We will be injecting a check that "a" is loaded before we allow the call to "foo". This check can be injected before or after arguments are evaluated to a value. This is implemented differently in dart2js and the VM: the example above prints 1 in dart2js and 2 in the vm.

In Dart 1 I'd have said we should implement the VM semantics. However, In Dart2 I believe we want the dart2js semantics instead: this matches the left-to-right consistency rule that we are adopting for Dart 2. I'm about to implement that in the FE at this moment.

@leafpetersen @lrhn @floitschG - can you clarify? would it be possible to explicitly call this out in the spec?

Related issue dart-lang/sdk#27577

Makes sense to me. I believe we've discussed making deferred loading an web only feature: whether we do so or not, I think it is largely driven by the needs of the web.

Yes, I think it makes sense to specify the evaluation order more precisely also in this case, and I agree that it should follow the left-to-right rule you mention consistently. @lrhn?

lrhn commented

The a.foo should fail at the time where foo is looked up in a (and a isn't loaded).
So, yes, it should follow the evaluation order of the expression. In this case, it means before evaluating arguments.

OK, decided: The language specification should specify the left-to-right evaluation order (in the example: the arguments should not be evaluated before failing). This issue serves to get that done. It would also serve as a justification for implementing it that way now.

Fantastic! Thanks for the quick turn around on this!