Files
sdk/pkg/compiler/test/optimization/data/remove_last.dart
T
Stephen Adams 9200e866f2 [dart2js] Remove SsaCheckInserter
Index bounds checks are now added as part of lowering `[]`, `[]=` and
`removeLast()` rather that being added later in a separate pass.

To know when to add checks, new trust/check annotations have been
added:

    @pragma('dart2js:index-bounds:trust')
    @pragma('dart2js:index-bounds:check')

These default according to the `--trust-primitives` command-line
option.

In order to consult the annotations, the enclosing context of the
method call is tracked. This allows annotations to be applied correctly
when several methods with different annotations are inlined.

Change-Id: I22e1acf90b85ad0d100766b85a50095ced9815e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171632
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2020-11-12 19:42:50 +00:00

60 lines
1.5 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.7
import 'dart:collection';
import 'dart:typed_data';
/*member: dynamicIndex:Specializer=[!RemoveLast]*/
@pragma('dart2js:noInline')
dynamicIndex(var list) {
return list.removeLast(); // This is not known to be an indexable primitive.
}
/*member: unknownList:Specializer=[!RemoveLast]*/
@pragma('dart2js:noInline')
unknownList(List list) {
return list.removeLast(); // This is not known to be an indexable primitive.
}
/*member: possiblyNullMutableList:Specializer=[RemoveLast]*/
@pragma('dart2js:noInline')
possiblyNullMutableList(bool b) {
var list = b ? [0] : null;
return list.removeLast();
}
/*member: mutableList:Specializer=[RemoveLast]*/
@pragma('dart2js:noInline')
mutableList() {
var list = [0];
return list.removeLast();
}
/*member: typedList:Specializer=[!RemoveLast]*/
@pragma('dart2js:noInline')
typedList() {
var list = Uint8List(10);
return list.removeLast();
}
main() {
dynamicIndex([]);
dynamicIndex({});
unknownList([]);
unknownList(new MyList());
possiblyNullMutableList(true);
possiblyNullMutableList(false);
mutableList();
typedList();
}
class MyList<E> extends ListBase<E> {
E operator [](int index) => null;
void operator []=(int index, E value) {}
int get length => 0;
void set length(int value) {}
}