mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
![Sigmund Cherem](/assets/img/avatar_default.png)
Change-Id: I46be49b2effec3e38a3dc44cd45cfe736f77fa78 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182680 Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Joshua Litt <joshualitt@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Stephen Adams <sra@google.com>
81 lines
2.4 KiB
Dart
81 lines
2.4 KiB
Dart
// Copyright (c) 2014, 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.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class A {
|
|
const A();
|
|
indexOf(item) => 42;
|
|
|
|
// This call get:indexOf has a known receiver type, so is is potentially
|
|
// eligible for a dummy receiver optimization.
|
|
getIndexOf() => this.indexOf;
|
|
}
|
|
|
|
var getIndexOfA = (a) => a.getIndexOf();
|
|
|
|
var getter1 = (a) => a.indexOf;
|
|
|
|
var getter2 = (a) {
|
|
// Known interceptor.
|
|
if (a is String) return a.indexOf;
|
|
|
|
// Call needs to be indirect to avoid inlining.
|
|
if (a is A) return getIndexOfA(a);
|
|
|
|
return a.indexOf;
|
|
};
|
|
|
|
var inscrutable;
|
|
|
|
main() {
|
|
inscrutable = (x) => x;
|
|
|
|
var array = ['foo', 'bar', [], [], new A(), new A(), const [], const A()];
|
|
|
|
array = inscrutable(array);
|
|
getter1 = inscrutable(getter1);
|
|
getter2 = inscrutable(getter2);
|
|
getIndexOfA = inscrutable(getIndexOfA);
|
|
|
|
var set = new Set.from(array.map(getter1));
|
|
|
|
// Closures should be distinct since they are closures bound to distinct
|
|
// objects.
|
|
Expect.equals(array.length, set.length);
|
|
|
|
// And repeats should be equal to existing closures and add no new elements.
|
|
set.addAll(array.map(getter1));
|
|
Expect.equals(array.length, set.length);
|
|
|
|
// And closures created in different optimization contexts should be equal.
|
|
set.addAll(array.map(getter2));
|
|
Expect.equals(array.length, set.length);
|
|
|
|
for (int i = 0; i < array.length; i++) {
|
|
Expect.equals(array[i], array[i]);
|
|
|
|
Expect.isTrue(set.contains(getter1(array[i])));
|
|
|
|
Expect.equals(getter1(array[i]), getter1(array[i]));
|
|
Expect.equals(getter1(array[i]), getter2(array[i]));
|
|
Expect.equals(getter2(array[i]), getter1(array[i]));
|
|
Expect.equals(getter2(array[i]), getter2(array[i]));
|
|
|
|
Expect.equals(getter1(array[i]).hashCode, getter1(array[i]).hashCode);
|
|
Expect.equals(getter1(array[i]).hashCode, getter2(array[i]).hashCode);
|
|
Expect.equals(getter2(array[i]).hashCode, getter1(array[i]).hashCode);
|
|
Expect.equals(getter2(array[i]).hashCode, getter2(array[i]).hashCode);
|
|
|
|
for (int j = 0; j < array.length; j++) {
|
|
if (i == j) continue;
|
|
|
|
Expect.notEquals(getter1(array[i]), getter1(array[j]));
|
|
Expect.notEquals(getter1(array[i]), getter2(array[j]));
|
|
Expect.notEquals(getter2(array[i]), getter1(array[j]));
|
|
Expect.notEquals(getter2(array[i]), getter2(array[j]));
|
|
}
|
|
}
|
|
}
|