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

dart2js: useless argument / parameter on generative constructor bodies with initializing formals #17868

Open
rakudrama opened this issue Mar 27, 2014 · 2 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dart2js-optimization type-enhancement A request for a change that isn't a bug web-dart2js

Comments

@rakudrama
Copy link
Member

This probably won't make a huge difference, but it is an example of where we can remove unused parameters without much analysis. I think there are 20-30 useless expressions that can be eliminated in swarm.

An initializing formal is not a parameter of a generative constructor body.

-------- example
class A {
  var a,b,c,d;

 A(this.a, b, c, d) : b = b {
    // There are only three parameters: b, c, d. 'a' resolves to this.a
    if (false) throw 123; // inhibit inlining
    this.c = c;
    a++;b++;c++;
    this.d = [a, b, c, d];
  }

  toString() => 'A($a, $b, $c, $d)';
}

make() => new A(10, 20, 30, 40);

main() {
  print((make)());
}

-------- output
A(11, 20, 30, [11, 21, 31, 40])

-------- generated code
  make: [function() {
    var t1 = new E.A(10, 20, null, null);
    t1.A$4(10, 20, 30, 40);
    return t1;
  }, "call$0", "make$closure", 0, 0, 0],
  main: ...,
  A: {
    ...,
    A$4: function(a, b, c, d) {
      var t1;
      this.c = c;
      t1 = this.a + 1;
      this.a = t1;
      this.d = [t1, b + 1, c + 1, d];
    }
  }


Notice that A$4 has a useless 'a' parameter, and the call is passed a useless argument.

@rakudrama
Copy link
Member Author

GenerativeConstructorBodies also often have unused type parameters.

@rakudrama
Copy link
Member Author

This still appears to be unexploited.
Current code:

  B = {
    A$: function(a, b, c, d) {
      var t1 = new B.A(a, b);
      t1.A$4(a, b, c, d);
      return t1;
    },
    make: function() {
      return B.A$(10, 20, 30, 40);
    },
    ...
    A: function A(t0, t1) {
      var _ = this;
      _.a = t0;
      _.b = t1;
      _.d = _.c = null;
    }
  };
  B.A.prototype = {
    A$4: function(a, b, c, d) {
      this.c = c;
      this.d = [++this.a, b + 1, c + 1, d];
    },
    toString$0: function(_) {
      var _this = this;
      return "A(" + _this.a + ", " + _this.b + ", " + H.S(_this.c) + ", " + H.S(_this.d) + ")";
    }
  };

@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dart2js-optimization type-enhancement A request for a change that isn't a bug web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants