Skip to content

How to implement this efficiently in dart2js? #4

@rakudrama

Description

@rakudrama

I'd like to understand how to implement this efficiently when compiled to JavaScript.
If possible I'd like to find a solution where

  • No methods are compiled twice to 'place' them into different mixin applications.
  • A dynamically dispatched (i.e. mixed-in) super call can be implemented as a simple JavaScript method call. I'd like to avoid the use of JavaScript's Function.prototype.call and Function.prototype.apply methods as these are seldom adequately optimized.

Our experience to date has been that super calls are sufficiently alluring that it is important to make them both compact in the generated code and efficient in dispatch. Ditto mixins.

How should the following program work?
Given the usual JavaScript context of

  • I am in M.foo, and
  • my receiver is an instance of C

we do not have enough information to determine which mixin application, i.e. which S_dynamic, to use:

class M {
  foo(_) => super.foo(print('M.foo'));
}

class A {
  foo(_) => print('A.foo');
}

class B extends A with M {
  foo(_) => super.foo(print('B.foo'));
}

class C extends B with M {
  foo(_) => super.foo(print('C.foo'));
}

main() {
  new C().foo();
}

If we can somehow avoid the above problem (e.g. making it an error to mix in the same class twice), then M.foo's call to super.foo could be implemented as this.from$M$foo$1(...) with each S_dynamic defining from$M$foo$1 as an alias to the appropriate method (i.e. a separate property in a prototype chain object that has the same value as the main property).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions