Skip to content

fasta: Don't emit invalid-statement for redirecting factories #28424

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

Closed
mkustermann opened this issue Jan 17, 2017 · 10 comments
Closed

fasta: Don't emit invalid-statement for redirecting factories #28424

mkustermann opened this issue Jan 17, 2017 · 10 comments
Assignees
Labels
front-end-fasta front-end-kernel legacy-area-front-end Legacy: Use area-dart-model instead. P2 A bug or feature request we're likely to work on status-blocked Blocked from making progress by another (referenced) issue

Comments

@mkustermann
Copy link
Member

Dartk translates

class Foo {
  factory Foo() = Bar;
}
class Bar implements Foo {
  Bar() {}
}
main() {}

to

  class Foo extends core::Object {
    constructor •() → dynamic
      invalid-statement;
  }
  class Bar extends core::Object implements test::Foo {
    constructor •() → void
      : super core::Object::•() {}
  }
  static method main() → dynamic {}

It should not emit invalid-statement.

/cc @kmillikin & #28263

@asgerf
Copy link
Contributor

asgerf commented Jan 18, 2017

Redirecting factories are eliminated in the front-end.

Originally they were converted to a procedure that called the target, but the analyzer's element model does not expose default parameter values, and thus we cannot generate a forwarding procedure without loading the full source code of the target.

The constructor in Foo is inserted by the sanitize_for_vm pass to ensure all classes have at least one procedure or constructor, because otherwise the VM crashes.

@mkustermann
Copy link
Member Author

Some tests pass --compile-all to the VM. Which will make the VM generate code for all classes/methods. It then crashes on InvalidStatement.

I think if the input to dartk is perfectly valid and sound code, the IR should not contain any invalud-* nodes.

@asgerf
Copy link
Contributor

asgerf commented Jan 18, 2017

@kmillikin
Copy link

The fix, to not use invalid statement, seems good. I'll just note here that the VM doesn't crash, it hits an assertion failure in debug builds, and that assertion seems to be just a sanity-check precondition and not a correctness precondition.

Running in a release build or without the assertion in a debug build does not seem to fail.

@mkustermann
Copy link
Member Author

Maybe a better way to formulate this is: The VM does not expect to ever encounter an InvalidStatement because it doesn't know how to handle it. Could we get rid of this AST node?

@asgerf
Copy link
Contributor

asgerf commented Jan 18, 2017

I completely agree - we should get rid of all invalid nodes.

@mraleph mraleph changed the title dartk: Support for factory Name() = OtherClass fasta: Don't emit invalid-statement for redirecting factories Mar 27, 2017
@mraleph
Copy link
Member

mraleph commented Mar 27, 2017

This test still crashes with fasta and --compile-all. We need executive/design decision here how Kernel should look like for redirecting factories that were erased by the front-end (especially in the context of the modular compilation).

Also see #28421

@peter-ahe-google peter-ahe-google added the status-blocked Blocked from making progress by another (referenced) issue label Mar 27, 2017
@peter-ahe-google
Copy link
Contributor

peter-ahe-google commented Mar 27, 2017

Blocked on #29841

@mkustermann
Copy link
Member Author

mkustermann commented Apr 3, 2017

There is btw also a test, which invokes a redirecting factory via dart:mirrors:

class A {
  factory A(
    String //  //# 01: static type warning
      x) = B;
  A._();
}

class B extends A {
  var x;
  B(int x)
      : super._(),
        this.x = x;
}

main() {
  var cm = reflectClass(A);
  // The type-annotation in A's constructor must be ignored.
  var b = cm.newInstance(const Symbol(''), [499]).reflectee;
  Expect.equals(499, b.x);
  Expect.throws(
      () => cm.newInstance(const Symbol(''), ["str"]), (e) => e is TypeError);
}

from tests/lib/mirrors/redirecting_factory_different_type_test.dart

@alexmarkov
Copy link
Contributor

Fixed in 300a2ea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
front-end-fasta front-end-kernel legacy-area-front-end Legacy: Use area-dart-model instead. P2 A bug or feature request we're likely to work on status-blocked Blocked from making progress by another (referenced) issue
Projects
None yet
Development

No branches or pull requests

10 participants