dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.07k stars 1.56k forks source link

dart2js: refine HBoundsCheck #7706

Open rakudrama opened 11 years ago

rakudrama commented 11 years ago

$$.JSArray = {"": "Object;",

  get$last: function(receiver) {     var t1, t2;     t1 = receiver.length;     t2 = t1 - 1;     if (t2 < 0)       throw $.ioore(t2);     return receiver[t2];   },

In this code, t1 is used once. The code is generated like this because the HBoundsCheck has t1 as an input, but the input is not used (so the code generator thinks t1 has two uses). Better code would be generated here if the unused input was unlinked, or if HBoundsCheck was broken into components.

I have put this at low priority since I don't think it is all that common.

kasperl commented 11 years ago

Added this to the M3 milestone.

anders-sandholm commented 11 years ago

Removed this from the M3 milestone. Added this to the M4 milestone.

kasperl commented 11 years ago

Removed this from the M4 milestone. Added this to the M5 milestone.

kasperl commented 11 years ago

Added TriageForM5 label.

kasperl commented 11 years ago

Removed this from the M5 milestone. Added this to the Later milestone. Removed TriageForM5 label.

kasperl commented 10 years ago

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

kasperl commented 10 years ago

Removed Oldschool-Milestone-Later label.

rakudrama commented 2 years ago

get:last has been rewritten to throw a StateError when the list is empty.

HBoundCheck still has the length as an input when there is no upper-range check:

@pragma('dart2js:noInline')
T lastOf<T>(List<T> a) => a[a.length - 1];

t1 is still used once:

    lastOf(a, $T) {
      var t1 = a.length,
        t2 = t1 - 1;
      if (!(t2 >= 0))
        return A.ioore(a, t2);
      return a[t2];
    }