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: missed CSE opportinities in checked mode #10769

Closed
rakudrama opened this issue May 21, 2013 · 6 comments
Closed

dart2js: missed CSE opportinities in checked mode #10769

rakudrama opened this issue May 21, 2013 · 6 comments
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@rakudrama
Copy link
Member

The code for LinkedHashMap.operator[]= contains type checks for type parameters K, V.

Ignoring for now that the code could be heavily specialized (this.$asLinkedHashMap -> undefined aka null since there are no classes extending or implementing LinkedHashMap),
there is a lot of repeated code.

this.$asLinkedHashMap is idempotent.
$.getRuntimeTypeInfo(this) is idempotent.

$$.LinkedHashMap = {"": "Object;_length,_strings,_nums,_rest,_first,_last,modifications",
  ...
  $indexSet: function(
, key, value) {
    var $arguments, arguments0, strings, table, nums, rest, hash, bucket, t1, index;

    $arguments = this.$asLinkedHashMap;
    arguments0 = $.getRuntimeTypeInfo(this);
    if ($arguments != null && $arguments.constructor === Array)
      ;
    else
      $arguments = typeof $arguments == "function" ? $arguments.apply(null, arguments0) : arguments0;
    $.assertSubtypeOfRuntimeType(key, $arguments == null ? null : $arguments[0]);

    $arguments = this.$asLinkedHashMap;
    arguments0 = $.getRuntimeTypeInfo(this);
    if ($arguments != null && $arguments.constructor === Array)
      ;
    else
      $arguments = typeof $arguments == "function" ? $arguments.apply(null, arguments0) : arguments0;
    $.assertSubtypeOfRuntimeType(value, $arguments == null ? null : $arguments[1]);

Ideally this should optimize to something like:

    arguments0 = $.getRuntimeTypeInfo(this);
    $arguments = arguments0;
    $.assertSubtypeOfRuntimeType(key, $arguments == null ? null : $arguments[0]);
    $.assertSubtypeOfRuntimeType(value, $arguments == null ? null : $arguments[1]);

@kasperl
Copy link

kasperl commented May 23, 2013

Added this to the Later milestone.

@kasperl
Copy link

kasperl commented May 23, 2013

Added TriageForM5 label.

@kasperl
Copy link

kasperl commented May 28, 2013

Removed TriageForM5 label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Feb 29, 2016
@rakudrama
Copy link
Member Author

The code looks better because we no longer inline getTypeArgumentByIndex

      $indexSet: function(_, key, value) {
        var strings, nums, rest, hash, bucket, index;
        H.assertSubtypeOfRuntimeType(key, H.getTypeArgumentByIndex(this, 0));
        H.assertSubtypeOfRuntimeType(value, H.getTypeArgumentByIndex(this, 1));

I'm closing this because we need to revisit the representation of reified types to make type checks more efficient and reduce the number of allocations for type representations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants