Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f043f9e

Browse files
fishythefishcommit-bot@chromium.org
authored and
commit-bot@chromium.org
committed
Don't legacy-erase type literals.
Change-Id: Ic924a4ddf27801e0d09952cd0da222cfda4f8b73 Bug: dart-lang/sdk#42262 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150821 Commit-Queue: Mayank Patke <fishythefish@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
1 parent 045227e commit f043f9e

16 files changed

+774
-235
lines changed

pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
10651065

10661066
@override
10671067
Constant visitTypeLiteral(TypeLiteral node) {
1068-
final DartType type = evaluateDartType(node, convertType(node.type));
1068+
final DartType type = evaluateDartType(node, node.type);
10691069
return canonicalize(new TypeLiteralConstant(type));
10701070
}
10711071

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'constants_lib.dart' as lib;
6+
7+
typedef F1<T> = T Function(T);
8+
typedef F2 = T Function<T>(T);
9+
10+
const objectTypeLiteral = Object;
11+
const int Function(int) partialInstantiation = lib.id;
12+
const instance = const lib.Class<int>(0);
13+
const functionTypeLiteral = F1;
14+
const genericFunctionTypeLiteral = F2;
15+
const listLiteral = <int>[0];
16+
const setLiteral = <int>{0};
17+
const mapLiteral = <int, String>{0: 'foo'};
18+
const listConcatenation = <int>[...listLiteral];
19+
const setConcatenation = <int>{...setLiteral};
20+
const mapConcatenation = <int, String>{...mapLiteral};
21+
22+
const objectTypeLiteralIdentical =
23+
identical(objectTypeLiteral, lib.objectTypeLiteral);
24+
const partialInstantiationIdentical =
25+
identical(partialInstantiation, lib.partialInstantiation);
26+
const instanceIdentical = identical(instance, lib.instance);
27+
const functionTypeLiteralIdentical =
28+
identical(functionTypeLiteral, lib.functionTypeLiteral);
29+
const genericFunctionTypeLiteralIdentical =
30+
identical(genericFunctionTypeLiteral, lib.genericFunctionTypeLiteral);
31+
const listLiteralIdentical = identical(listLiteral, lib.listLiteral);
32+
const setLiteralIdentical = identical(setLiteral, lib.setLiteral);
33+
const mapLiteralIdentical = identical(mapLiteral, lib.mapLiteral);
34+
const listConcatenationIdentical =
35+
identical(listConcatenation, lib.listConcatenation);
36+
const setConcatenationIdentical =
37+
identical(setConcatenation, lib.setConcatenation);
38+
const mapConcatenationIdentical =
39+
identical(mapConcatenation, lib.mapConcatenation);
40+
41+
main() {
42+
test(objectTypeLiteral, lib.objectTypeLiteral);
43+
test(partialInstantiation, lib.partialInstantiation);
44+
test(instance, lib.instance);
45+
test(functionTypeLiteral, lib.functionTypeLiteral);
46+
test(genericFunctionTypeLiteral, lib.genericFunctionTypeLiteral);
47+
test(listLiteral, lib.listLiteral);
48+
test(setLiteral, lib.setLiteral);
49+
test(mapLiteral, lib.mapLiteral);
50+
test(listConcatenation, lib.listConcatenation);
51+
test(setConcatenation, lib.setConcatenation);
52+
test(mapConcatenation, lib.mapConcatenation);
53+
54+
test(true, objectTypeLiteralIdentical);
55+
test(true, partialInstantiationIdentical);
56+
test(true, instanceIdentical);
57+
test(true, functionTypeLiteralIdentical);
58+
test(true, genericFunctionTypeLiteralIdentical);
59+
test(true, listLiteralIdentical);
60+
test(true, setLiteralIdentical);
61+
test(true, mapLiteralIdentical);
62+
test(true, listConcatenationIdentical);
63+
test(true, setConcatenationIdentical);
64+
test(true, mapConcatenationIdentical);
65+
}
66+
67+
test(expected, actual) {
68+
print('test($expected, $actual)');
69+
if (!identical(expected, actual)) {
70+
throw 'Expected $expected, actual $actual';
71+
}
72+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "constants_lib.dart" as con;
5+
6+
import "org-dartlang-testcase:///constants_lib.dart" as lib;
7+
8+
typedef F1<invariant T extends core::Object? = dynamic> = (T%) → T%;
9+
typedef F2 = <T extends core::Object? = dynamic>(T%) → T%;
10+
static const field core::Type objectTypeLiteral = core::Object;
11+
static const field (core::int) → core::int partialInstantiation = con::id<core::int>;
12+
static const field con::Class<core::int> instance = const con::Class::•<core::int>(0);
13+
static const field core::Type functionTypeLiteral = (dynamic) → dynamic;
14+
static const field core::Type genericFunctionTypeLiteral = <T extends core::Object? = dynamic>(T%) → T%;
15+
static const field core::List<core::int> listLiteral = const <core::int>[0];
16+
static const field core::Set<core::int> setLiteral = const <core::int>{0};
17+
static const field core::Map<core::int, core::String> mapLiteral = const <core::int, core::String>{0: "foo"};
18+
static const field core::List<core::int> listConcatenation = self::listLiteral;
19+
static const field core::Set<core::int> setConcatenation = self::setLiteral;
20+
static const field core::Map<core::int, core::String> mapConcatenation = self::mapLiteral;
21+
static const field core::bool objectTypeLiteralIdentical = core::identical(self::objectTypeLiteral, con::objectTypeLiteral);
22+
static const field core::bool partialInstantiationIdentical = core::identical(self::partialInstantiation, con::partialInstantiation);
23+
static const field core::bool instanceIdentical = core::identical(self::instance, con::instance);
24+
static const field core::bool functionTypeLiteralIdentical = core::identical(self::functionTypeLiteral, con::functionTypeLiteral);
25+
static const field core::bool genericFunctionTypeLiteralIdentical = core::identical(self::genericFunctionTypeLiteral, con::genericFunctionTypeLiteral);
26+
static const field core::bool listLiteralIdentical = core::identical(self::listLiteral, con::listLiteral);
27+
static const field core::bool setLiteralIdentical = core::identical(self::setLiteral, con::setLiteral);
28+
static const field core::bool mapLiteralIdentical = core::identical(self::mapLiteral, con::mapLiteral);
29+
static const field core::bool listConcatenationIdentical = core::identical(self::listConcatenation, con::listConcatenation);
30+
static const field core::bool setConcatenationIdentical = core::identical(self::setConcatenation, con::setConcatenation);
31+
static const field core::bool mapConcatenationIdentical = core::identical(self::mapConcatenation, con::mapConcatenation);
32+
static method main() → dynamic
33+
;
34+
static method test(dynamic expected, dynamic actual) → dynamic
35+
;
36+
37+
library /*isNonNullableByDefault*/;
38+
import self as con;
39+
import "dart:core" as core;
40+
41+
typedef F1<invariant T extends core::Object? = dynamic> = (T%) → T%;
42+
typedef F2 = <T extends core::Object? = dynamic>(T%) → T%;
43+
class Class<T extends core::Object? = dynamic> extends core::Object /*hasConstConstructor*/ {
44+
final field con::Class::T% field;
45+
const constructor •(con::Class::T% field) → con::Class<con::Class::T%>
46+
: con::Class::field = field, super core::Object::•()
47+
;
48+
}
49+
static const field core::Type objectTypeLiteral = core::Object;
50+
static const field (core::Object?, core::Object?) → core::bool c2 = core::identical;
51+
static const field (core::int) → core::int partialInstantiation = con::id<core::int>;
52+
static const field con::Class<core::int> instance = const con::Class::•<core::int>(0);
53+
static const field core::Type functionTypeLiteral = (dynamic) → dynamic;
54+
static const field core::Type genericFunctionTypeLiteral = <T extends core::Object? = dynamic>(T%) → T%;
55+
static const field core::List<core::int> listLiteral = const <core::int>[0];
56+
static const field core::Set<core::int> setLiteral = const <core::int>{0};
57+
static const field core::Map<core::int, core::String> mapLiteral = const <core::int, core::String>{0: "foo"};
58+
static const field core::List<core::int> listConcatenation = con::listLiteral;
59+
static const field core::Set<core::int> setConcatenation = con::setLiteral;
60+
static const field core::Map<core::int, core::String> mapConcatenation = con::mapLiteral;
61+
static method id<T extends core::Object? = dynamic>(con::id::T% t) → con::id::T%
62+
;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "constants_lib.dart" as con;
5+
6+
import "org-dartlang-testcase:///constants_lib.dart" as lib;
7+
8+
typedef F1<invariant T extends core::Object? = dynamic> = (T%) → T%;
9+
typedef F2 = <T extends core::Object? = dynamic>(T%) → T%;
10+
static const field core::Type objectTypeLiteral = #C1;
11+
static const field (core::int) → core::int partialInstantiation = #C3;
12+
static const field con::Class<core::int> instance = #C5;
13+
static const field core::Type functionTypeLiteral = #C6;
14+
static const field core::Type genericFunctionTypeLiteral = #C7;
15+
static const field core::List<core::int> listLiteral = #C8;
16+
static const field core::Set<core::int> setLiteral = #C12;
17+
static const field core::Map<core::int, core::String> mapLiteral = #C15;
18+
static const field core::List<core::int> listConcatenation = #C8;
19+
static const field core::Set<core::int> setConcatenation = #C12;
20+
static const field core::Map<core::int, core::String> mapConcatenation = #C15;
21+
static const field core::bool objectTypeLiteralIdentical = #C16;
22+
static const field core::bool partialInstantiationIdentical = #C16;
23+
static const field core::bool instanceIdentical = #C16;
24+
static const field core::bool functionTypeLiteralIdentical = #C16;
25+
static const field core::bool genericFunctionTypeLiteralIdentical = #C16;
26+
static const field core::bool listLiteralIdentical = #C16;
27+
static const field core::bool setLiteralIdentical = #C16;
28+
static const field core::bool mapLiteralIdentical = #C16;
29+
static const field core::bool listConcatenationIdentical = #C16;
30+
static const field core::bool setConcatenationIdentical = #C16;
31+
static const field core::bool mapConcatenationIdentical = #C16;
32+
static method main() → dynamic {
33+
self::test(#C1, #C1);
34+
self::test(#C3, #C3);
35+
self::test(#C5, #C5);
36+
self::test(#C6, #C6);
37+
self::test(#C7, #C7);
38+
self::test(#C8, #C8);
39+
self::test(#C12, #C12);
40+
self::test(#C15, #C15);
41+
self::test(#C8, #C8);
42+
self::test(#C12, #C12);
43+
self::test(#C15, #C15);
44+
self::test(true, #C16);
45+
self::test(true, #C16);
46+
self::test(true, #C16);
47+
self::test(true, #C16);
48+
self::test(true, #C16);
49+
self::test(true, #C16);
50+
self::test(true, #C16);
51+
self::test(true, #C16);
52+
self::test(true, #C16);
53+
self::test(true, #C16);
54+
self::test(true, #C16);
55+
}
56+
static method test(dynamic expected, dynamic actual) → dynamic {
57+
core::print("test(${expected}, ${actual})");
58+
if(!core::identical(expected, actual)) {
59+
throw "Expected ${expected}, actual ${actual}";
60+
}
61+
}
62+
63+
library /*isNonNullableByDefault*/;
64+
import self as con;
65+
import "dart:core" as core;
66+
67+
typedef F1<invariant T extends core::Object? = dynamic> = (T%) → T%;
68+
typedef F2 = <T extends core::Object? = dynamic>(T%) → T%;
69+
class Class<T extends core::Object? = dynamic> extends core::Object /*hasConstConstructor*/ {
70+
final field con::Class::T% field;
71+
const constructor •(con::Class::T% field) → con::Class<con::Class::T%>
72+
: con::Class::field = field, super core::Object::•()
73+
;
74+
}
75+
static const field core::Type objectTypeLiteral = #C1;
76+
static const field (core::Object?, core::Object?) → core::bool c2 = #C17;
77+
static const field (core::int) → core::int partialInstantiation = #C3;
78+
static const field con::Class<core::int> instance = #C5;
79+
static const field core::Type functionTypeLiteral = #C6;
80+
static const field core::Type genericFunctionTypeLiteral = #C7;
81+
static const field core::List<core::int> listLiteral = #C8;
82+
static const field core::Set<core::int> setLiteral = #C12;
83+
static const field core::Map<core::int, core::String> mapLiteral = #C15;
84+
static const field core::List<core::int> listConcatenation = #C8;
85+
static const field core::Set<core::int> setConcatenation = #C12;
86+
static const field core::Map<core::int, core::String> mapConcatenation = #C15;
87+
static method id<T extends core::Object? = dynamic>(con::id::T% t) → con::id::T%
88+
return t;
89+
90+
constants {
91+
#C1 = TypeLiteralConstant(core::Object)
92+
#C2 = tearoff con::id
93+
#C3 = partial-instantiation con::id <core::int>
94+
#C4 = 0
95+
#C5 = con::Class<core::int> {field:#C4}
96+
#C6 = TypeLiteralConstant((dynamic) → dynamic)
97+
#C7 = TypeLiteralConstant(<T extends core::Object? = dynamic>(T%) → T%)
98+
#C8 = <core::int>[#C4]
99+
#C9 = null
100+
#C10 = <dynamic>[#C4, #C9]
101+
#C11 = core::_ImmutableMap<core::int, core::Null?> {_kvPairs:#C10}
102+
#C12 = col::_UnmodifiableSet<core::int> {_map:#C11}
103+
#C13 = "foo"
104+
#C14 = <dynamic>[#C4, #C13]
105+
#C15 = core::_ImmutableMap<core::int, core::String> {_kvPairs:#C14}
106+
#C16 = true
107+
#C17 = tearoff core::identical
108+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "constants_lib.dart" as con;
5+
6+
import "org-dartlang-testcase:///constants_lib.dart" as lib;
7+
8+
typedef F1<invariant T extends core::Object? = dynamic> = (T%) → T%;
9+
typedef F2 = <T extends core::Object? = dynamic>(T%) → T%;
10+
static const field core::Type objectTypeLiteral = #C1;
11+
static const field (core::int) → core::int partialInstantiation = #C3;
12+
static const field con::Class<core::int> instance = #C5;
13+
static const field core::Type functionTypeLiteral = #C6;
14+
static const field core::Type genericFunctionTypeLiteral = #C7;
15+
static const field core::List<core::int> listLiteral = #C8;
16+
static const field core::Set<core::int> setLiteral = #C12;
17+
static const field core::Map<core::int, core::String> mapLiteral = #C15;
18+
static const field core::List<core::int> listConcatenation = #C8;
19+
static const field core::Set<core::int> setConcatenation = #C12;
20+
static const field core::Map<core::int, core::String> mapConcatenation = #C15;
21+
static const field core::bool objectTypeLiteralIdentical = #C16;
22+
static const field core::bool partialInstantiationIdentical = #C16;
23+
static const field core::bool instanceIdentical = #C16;
24+
static const field core::bool functionTypeLiteralIdentical = #C16;
25+
static const field core::bool genericFunctionTypeLiteralIdentical = #C16;
26+
static const field core::bool listLiteralIdentical = #C16;
27+
static const field core::bool setLiteralIdentical = #C16;
28+
static const field core::bool mapLiteralIdentical = #C16;
29+
static const field core::bool listConcatenationIdentical = #C16;
30+
static const field core::bool setConcatenationIdentical = #C16;
31+
static const field core::bool mapConcatenationIdentical = #C16;
32+
static method main() → dynamic {
33+
self::test(#C1, #C1);
34+
self::test(#C3, #C3);
35+
self::test(#C5, #C5);
36+
self::test(#C6, #C6);
37+
self::test(#C7, #C7);
38+
self::test(#C8, #C8);
39+
self::test(#C12, #C12);
40+
self::test(#C15, #C15);
41+
self::test(#C8, #C8);
42+
self::test(#C12, #C12);
43+
self::test(#C15, #C15);
44+
self::test(true, #C16);
45+
self::test(true, #C16);
46+
self::test(true, #C16);
47+
self::test(true, #C16);
48+
self::test(true, #C16);
49+
self::test(true, #C16);
50+
self::test(true, #C16);
51+
self::test(true, #C16);
52+
self::test(true, #C16);
53+
self::test(true, #C16);
54+
self::test(true, #C16);
55+
}
56+
static method test(dynamic expected, dynamic actual) → dynamic {
57+
core::print("test(${expected}, ${actual})");
58+
if(!core::identical(expected, actual)) {
59+
throw "Expected ${expected}, actual ${actual}";
60+
}
61+
}
62+
63+
library /*isNonNullableByDefault*/;
64+
import self as con;
65+
import "dart:core" as core;
66+
67+
typedef F1<invariant T extends core::Object? = dynamic> = (T%) → T%;
68+
typedef F2 = <T extends core::Object? = dynamic>(T%) → T%;
69+
class Class<T extends core::Object? = dynamic> extends core::Object /*hasConstConstructor*/ {
70+
final field con::Class::T% field;
71+
const constructor •(con::Class::T% field) → con::Class<con::Class::T%>
72+
: con::Class::field = field, super core::Object::•()
73+
;
74+
}
75+
static const field core::Type objectTypeLiteral = #C1;
76+
static const field (core::Object?, core::Object?) → core::bool c2 = #C17;
77+
static const field (core::int) → core::int partialInstantiation = #C3;
78+
static const field con::Class<core::int> instance = #C5;
79+
static const field core::Type functionTypeLiteral = #C6;
80+
static const field core::Type genericFunctionTypeLiteral = #C7;
81+
static const field core::List<core::int> listLiteral = #C8;
82+
static const field core::Set<core::int> setLiteral = #C12;
83+
static const field core::Map<core::int, core::String> mapLiteral = #C15;
84+
static const field core::List<core::int> listConcatenation = #C8;
85+
static const field core::Set<core::int> setConcatenation = #C12;
86+
static const field core::Map<core::int, core::String> mapConcatenation = #C15;
87+
static method id<T extends core::Object? = dynamic>(con::id::T% t) → con::id::T%
88+
return t;
89+
90+
constants {
91+
#C1 = TypeLiteralConstant(core::Object)
92+
#C2 = tearoff con::id
93+
#C3 = partial-instantiation con::id <core::int>
94+
#C4 = 0
95+
#C5 = con::Class<core::int> {field:#C4}
96+
#C6 = TypeLiteralConstant((dynamic) → dynamic)
97+
#C7 = TypeLiteralConstant(<T extends core::Object? = dynamic>(T%) → T%)
98+
#C8 = <core::int>[#C4]
99+
#C9 = null
100+
#C10 = <dynamic>[#C4, #C9]
101+
#C11 = core::_ImmutableMap<core::int, core::Null?> {_kvPairs:#C10}
102+
#C12 = col::_UnmodifiableSet<core::int> {_map:#C11}
103+
#C13 = "foo"
104+
#C14 = <dynamic>[#C4, #C13]
105+
#C15 = core::_ImmutableMap<core::int, core::String> {_kvPairs:#C14}
106+
#C16 = true
107+
#C17 = tearoff core::identical
108+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'constants_lib.dart' as lib;
2+
3+
typedef F1<T> = T Function(T);
4+
typedef F2 = T Function<T>(T);
5+
const objectTypeLiteral = Object;
6+
const int Function(int) partialInstantiation = lib.id;
7+
const instance = const lib.Class<int>(0);
8+
const functionTypeLiteral = F1;
9+
const genericFunctionTypeLiteral = F2;
10+
const listLiteral = <int>[0];
11+
const setLiteral = <int>{0};
12+
const mapLiteral = <int, String>{0: 'foo'};
13+
const listConcatenation = <int>[...listLiteral];
14+
const setConcatenation = <int>{...setLiteral};
15+
const mapConcatenation = <int, String>{...mapLiteral};
16+
const objectTypeLiteralIdentical =
17+
identical(objectTypeLiteral, lib.objectTypeLiteral);
18+
const partialInstantiationIdentical =
19+
identical(partialInstantiation, lib.partialInstantiation);
20+
const instanceIdentical = identical(instance, lib.instance);
21+
const functionTypeLiteralIdentical =
22+
identical(functionTypeLiteral, lib.functionTypeLiteral);
23+
const genericFunctionTypeLiteralIdentical =
24+
identical(genericFunctionTypeLiteral, lib.genericFunctionTypeLiteral);
25+
const listLiteralIdentical = identical(listLiteral, lib.listLiteral);
26+
const setLiteralIdentical = identical(setLiteral, lib.setLiteral);
27+
const mapLiteralIdentical = identical(mapLiteral, lib.mapLiteral);
28+
const listConcatenationIdentical =
29+
identical(listConcatenation, lib.listConcatenation);
30+
const setConcatenationIdentical =
31+
identical(setConcatenation, lib.setConcatenation);
32+
const mapConcatenationIdentical =
33+
identical(mapConcatenation, lib.mapConcatenation);
34+
main() {}
35+
test(expected, actual) {}

0 commit comments

Comments
 (0)