Skip to content

Commit 6d4d3c6

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
Remove TrustTypeAnnotations
Change-Id: I7404d10c30642f5282d079e36cb4a20ee2066060 Reviewed-on: https://dart-review.googlesource.com/c/87401 Reviewed-by: Sigmund Cherem <[email protected]> Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent ecccc0d commit 6d4d3c6

File tree

12 files changed

+7
-160
lines changed

12 files changed

+7
-160
lines changed

pkg/compiler/lib/src/common_elements.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,6 @@ abstract class CommonElements {
473473

474474
ClassEntity get expectNoInlineClass;
475475

476-
ClassEntity get expectTrustTypeAnnotationsClass;
477-
478476
ClassEntity get expectAssumeDynamicClass;
479477

480478
/// Returns `true` if [member] is a "foreign helper", that is, a member whose
@@ -1666,7 +1664,6 @@ class CommonElementsImpl
16661664

16671665
bool _expectAnnotationChecked = false;
16681666
ClassEntity _expectNoInlineClass;
1669-
ClassEntity _expectTrustTypeAnnotationsClass;
16701667
ClassEntity _expectAssumeDynamicClass;
16711668

16721669
void _ensureExpectAnnotations() {
@@ -1675,15 +1672,10 @@ class CommonElementsImpl
16751672
LibraryEntity library = _env.lookupLibrary(PACKAGE_EXPECT);
16761673
if (library != null) {
16771674
_expectNoInlineClass = _env.lookupClass(library, 'NoInline');
1678-
_expectTrustTypeAnnotationsClass =
1679-
_env.lookupClass(library, 'TrustTypeAnnotations');
16801675
_expectAssumeDynamicClass = _env.lookupClass(library, 'AssumeDynamic');
1681-
if (_expectNoInlineClass == null ||
1682-
_expectTrustTypeAnnotationsClass == null ||
1683-
_expectAssumeDynamicClass == null) {
1676+
if (_expectNoInlineClass == null || _expectAssumeDynamicClass == null) {
16841677
// This is not the package you're looking for.
16851678
_expectNoInlineClass = null;
1686-
_expectTrustTypeAnnotationsClass = null;
16871679
_expectAssumeDynamicClass = null;
16881680
}
16891681
}
@@ -1695,11 +1687,6 @@ class CommonElementsImpl
16951687
return _expectNoInlineClass;
16961688
}
16971689

1698-
ClassEntity get expectTrustTypeAnnotationsClass {
1699-
_ensureExpectAnnotations();
1700-
return _expectTrustTypeAnnotationsClass;
1701-
}
1702-
17031690
ClassEntity get expectAssumeDynamicClass {
17041691
_ensureExpectAnnotations();
17051692
return _expectAssumeDynamicClass;

pkg/compiler/lib/src/dart2js.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ Future<api.CompilationResult> compile(List<String> argv,
218218

219219
void setTrustTypeAnnotations(String argument) {
220220
trustTypeAnnotations = true;
221-
passThrough(argument);
222221
}
223222

224223
void setCheckedMode(String argument) {

pkg/compiler/lib/src/inferrer/inferrer_engine.dart

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,6 @@ abstract class InferrerEngine {
242242
bool canFunctionParametersBeUsedForGlobalOptimizations(
243243
FunctionEntity function);
244244

245-
/// Returns `true` if parameter and returns types should be trusted for
246-
/// [member].
247-
bool trustTypeAnnotations(MemberEntity member);
248-
249245
/// Returns `true` if inference of parameter types is disabled for [member].
250246
bool assumeDynamic(MemberEntity member);
251247
}
@@ -1246,12 +1242,6 @@ class InferrerEngineImpl extends InferrerEngine {
12461242
return !closedWorld.backendUsage.isFunctionUsedByBackend(function);
12471243
}
12481244

1249-
@override
1250-
bool trustTypeAnnotations(MemberEntity member) {
1251-
return closedWorld.annotationsData.trustTypeAnnotationsMembers
1252-
.contains(member);
1253-
}
1254-
12551245
@override
12561246
bool assumeDynamic(MemberEntity member) {
12571247
return closedWorld.annotationsData.assumeDynamicMembers.contains(member);

pkg/compiler/lib/src/inferrer/type_graph_nodes.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ abstract class MemberTypeInformation extends ElementTypeInformation
478478
AbstractValue potentiallyNarrowType(
479479
AbstractValue mask, InferrerEngine inferrer) {
480480
if (inferrer.options.assignmentCheckPolicy.isTrusted ||
481-
inferrer.options.assignmentCheckPolicy.isEmitted ||
482-
inferrer.trustTypeAnnotations(_member)) {
481+
inferrer.options.assignmentCheckPolicy.isEmitted) {
483482
return _potentiallyNarrowType(mask, inferrer);
484483
}
485484
return mask;
@@ -792,8 +791,7 @@ class ParameterTypeInformation extends ElementTypeInformation {
792791

793792
AbstractValue potentiallyNarrowType(
794793
AbstractValue mask, InferrerEngine inferrer) {
795-
if (inferrer.options.parameterCheckPolicy.isTrusted ||
796-
inferrer.trustTypeAnnotations(_method)) {
794+
if (inferrer.options.parameterCheckPolicy.isTrusted) {
797795
// In checked or strong mode we don't trust the types of the arguments
798796
// passed to a parameter. The means that the checking of a parameter is
799797
// based on the actual arguments.

pkg/compiler/lib/src/js_backend/annotations.dart

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ import '../elements/entities.dart';
1212
import '../kernel/dart2js_target.dart';
1313
import '../serialization/serialization.dart';
1414

15-
/// Returns `true` if parameter and returns types should be trusted for
16-
/// [element].
17-
bool _trustTypeAnnotations(KElementEnvironment elementEnvironment,
18-
KCommonElements commonElements, MemberEntity element) {
19-
return _hasAnnotation(elementEnvironment, element,
20-
commonElements.expectTrustTypeAnnotationsClass);
21-
}
22-
2315
/// Returns `true` if inference of parameter types is disabled for [element].
2416
bool _assumeDynamic(KElementEnvironment elementEnvironment,
2517
KCommonElements commonElements, MemberEntity element) {
@@ -63,11 +55,6 @@ Set<PragmaAnnotation> processMemberAnnotations(
6355
bool hasTryInline = false;
6456
bool disableFinal = false;
6557

66-
if (_trustTypeAnnotations(elementEnvironment, commonElements, element)) {
67-
values.add(PragmaAnnotation.trustTypeAnnotations);
68-
annotationsDataBuilder.registerTrustTypeAnnotations(element);
69-
}
70-
7158
if (_assumeDynamic(elementEnvironment, commonElements, element)) {
7259
values.add(PragmaAnnotation.assumeDynamic);
7360
annotationsDataBuilder.registerAssumeDynamic(element);
@@ -222,9 +209,6 @@ abstract class AnnotationsData {
222209
/// Functions with a `@NoSideEffects()` annotation.
223210
Iterable<FunctionEntity> get sideEffectFreeFunctions;
224211

225-
/// Members with a `@TrustTypeAnnotations()` annotation.
226-
Iterable<MemberEntity> get trustTypeAnnotationsMembers;
227-
228212
/// Members with a `@AssumeDynamic()` annotation.
229213
Iterable<MemberEntity> get assumeDynamicMembers;
230214
}
@@ -239,7 +223,6 @@ class AnnotationsDataImpl implements AnnotationsData {
239223
final Iterable<FunctionEntity> disableFinalFunctions;
240224
final Iterable<FunctionEntity> cannotThrowFunctions;
241225
final Iterable<FunctionEntity> sideEffectFreeFunctions;
242-
final Iterable<MemberEntity> trustTypeAnnotationsMembers;
243226
final Iterable<MemberEntity> assumeDynamicMembers;
244227

245228
AnnotationsDataImpl(
@@ -248,7 +231,6 @@ class AnnotationsDataImpl implements AnnotationsData {
248231
this.disableFinalFunctions,
249232
this.cannotThrowFunctions,
250233
this.sideEffectFreeFunctions,
251-
this.trustTypeAnnotationsMembers,
252234
this.assumeDynamicMembers);
253235

254236
factory AnnotationsDataImpl.readFromDataSource(DataSource source) {
@@ -268,9 +250,6 @@ class AnnotationsDataImpl implements AnnotationsData {
268250
Iterable<FunctionEntity> sideEffectFreeFunctions =
269251
source.readMembers<FunctionEntity>(emptyAsNull: true) ??
270252
const <FunctionEntity>[];
271-
Iterable<MemberEntity> trustTypeAnnotationsMembers =
272-
source.readMembers<MemberEntity>(emptyAsNull: true) ??
273-
const <MemberEntity>[];
274253
Iterable<MemberEntity> assumeDynamicMembers =
275254
source.readMembers<MemberEntity>(emptyAsNull: true) ??
276255
const <MemberEntity>[];
@@ -281,7 +260,6 @@ class AnnotationsDataImpl implements AnnotationsData {
281260
disableFinalFunctions,
282261
cannotThrowFunctions,
283262
sideEffectFreeFunctions,
284-
trustTypeAnnotationsMembers,
285263
assumeDynamicMembers);
286264
}
287265

@@ -292,7 +270,6 @@ class AnnotationsDataImpl implements AnnotationsData {
292270
sink.writeMembers(disableFinalFunctions);
293271
sink.writeMembers(cannotThrowFunctions);
294272
sink.writeMembers(sideEffectFreeFunctions);
295-
sink.writeMembers(trustTypeAnnotationsMembers);
296273
sink.writeMembers(assumeDynamicMembers);
297274
sink.end(tag);
298275
}
@@ -332,11 +309,6 @@ class AnnotationsDataBuilder implements AnnotationsData {
332309
_sideEffectFreeFunctions.add(function);
333310
}
334311

335-
void registerTrustTypeAnnotations(MemberEntity member) {
336-
_trustTypeAnnotationsMembers ??= <MemberEntity>[];
337-
_trustTypeAnnotationsMembers.add(member);
338-
}
339-
340312
void registerAssumeDynamic(MemberEntity member) {
341313
_assumeDynamicMembers ??= <MemberEntity>[];
342314
_assumeDynamicMembers.add(member);

pkg/compiler/lib/src/js_model/js_world_builder.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ class JsClosedWorldBuilder {
203203
closedWorld.annotationsData.cannotThrowFunctions),
204204
map.toBackendFunctionSet(
205205
closedWorld.annotationsData.sideEffectFreeFunctions),
206-
map.toBackendMemberSet(
207-
closedWorld.annotationsData.trustTypeAnnotationsMembers),
208206
map.toBackendMemberSet(
209207
closedWorld.annotationsData.assumeDynamicMembers));
210208

pkg/expect/lib/expect.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -670,20 +670,6 @@ class NoInline {
670670
const NoInline();
671671
}
672672

673-
/// Annotation class for testing of dart2js. Use this as metadata on method
674-
/// declarations to make the type inferrer trust the parameter and return types,
675-
/// effectively asserting the runtime values will (at least) be subtypes of the
676-
/// annotated types.
677-
///
678-
/// While the actually inferred type is guaranteed to be a subtype of the
679-
/// annotation, it often is more precise. In particular, if a method is only
680-
/// called with `null`, the inferrer will still infer null. To ensure that
681-
/// the annotated type is also the inferred type, additionally use
682-
/// [AssumeDynamic].
683-
class TrustTypeAnnotations {
684-
const TrustTypeAnnotations();
685-
}
686-
687673
/// Annotation class for testing of dart2js. Use this as metadata on method
688674
/// declarations to disable closed world assumptions on parameters, effectively
689675
/// assuming that the runtime arguments could be any value. Note that the

tests/compiler/dart2js/codegen/expect_annotations_test.dart

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,13 @@ int method(String arg) => arg.length;
2121
@AssumeDynamic()
2222
int methodAssumeDynamic(String arg) => arg.length;
2323
24-
@TrustTypeAnnotations()
25-
int methodTrustTypeAnnotations(String arg) => arg.length;
26-
2724
@NoInline()
2825
int methodNoInline(String arg) => arg.length;
2926
30-
@NoInline() @TrustTypeAnnotations()
31-
int methodNoInlineTrustTypeAnnotations(String arg) => arg.length;
32-
33-
@AssumeDynamic() @TrustTypeAnnotations()
34-
int methodAssumeDynamicTrustTypeAnnotations(String arg) => arg.length;
35-
36-
3727
void main(List<String> args) {
3828
print(method(args[0]));
3929
print(methodAssumeDynamic('foo'));
40-
print(methodTrustTypeAnnotations(42 as dynamic));
41-
print(methodTrustTypeAnnotations("fourtyTwo"));
4230
print(methodNoInline('bar'));
43-
print(methodNoInlineTrustTypeAnnotations(42 as dynamic));
44-
print(methodNoInlineTrustTypeAnnotations("fourtyTwo"));
45-
print(methodAssumeDynamicTrustTypeAnnotations(null));
4631
}
4732
"""
4833
};
@@ -61,8 +46,6 @@ runTest() async {
6146
Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation');
6247
Expect.isNotNull(closedWorld.commonElements.expectNoInlineClass,
6348
'NoInlineClass is unresolved.');
64-
Expect.isNotNull(closedWorld.commonElements.expectTrustTypeAnnotationsClass,
65-
'TrustTypeAnnotations is unresolved.');
6649
Expect.isNotNull(closedWorld.commonElements.expectAssumeDynamicClass,
6750
'AssumeDynamicClass is unresolved.');
6851

@@ -83,7 +66,6 @@ runTest() async {
8366

8467
void test(String name,
8568
{bool expectNoInline: false,
86-
bool expectTrustTypeAnnotations: false,
8769
TypeMask expectedParameterType: null,
8870
TypeMask expectedReturnType: null,
8971
bool expectAssumeDynamic: false}) {
@@ -95,42 +77,19 @@ runTest() async {
9577
expectNoInline,
9678
closedWorld.annotationsData.nonInlinableFunctions.contains(method),
9779
"Unexpected annotation of @NoInline() on '$method'.");
98-
Expect.equals(
99-
expectTrustTypeAnnotations,
100-
closedWorld.annotationsData.trustTypeAnnotationsMembers
101-
.contains(method),
102-
"Unexpected annotation of @TrustTypeAnnotations() on '$method'.");
10380
Expect.equals(
10481
expectAssumeDynamic,
10582
closedWorld.annotationsData.assumeDynamicMembers.contains(method),
10683
"Unexpected annotation of @AssumeDynamic() on '$method'.");
10784
GlobalTypeInferenceResults results =
10885
compiler.globalInference.resultsForTesting;
109-
if (expectTrustTypeAnnotations && expectedParameterType != null) {
110-
testTypeMatch(method, expectedParameterType, expectedReturnType, results);
111-
} else if (expectAssumeDynamic) {
86+
if (expectAssumeDynamic) {
11287
testTypeMatch(
11388
method, closedWorld.abstractValueDomain.dynamicType, null, results);
11489
}
11590
}
11691

117-
TypeMask jsStringType = closedWorld.abstractValueDomain.stringType;
118-
TypeMask jsIntType = closedWorld.abstractValueDomain.intType;
119-
TypeMask coreStringType =
120-
new TypeMask.subtype(closedWorld.commonElements.stringClass, closedWorld);
121-
12292
test('method');
12393
test('methodAssumeDynamic', expectAssumeDynamic: true);
124-
test('methodTrustTypeAnnotations',
125-
expectTrustTypeAnnotations: true, expectedParameterType: jsStringType);
12694
test('methodNoInline', expectNoInline: true);
127-
test('methodNoInlineTrustTypeAnnotations',
128-
expectNoInline: true,
129-
expectTrustTypeAnnotations: true,
130-
expectedParameterType: jsStringType,
131-
expectedReturnType: jsIntType);
132-
test('methodAssumeDynamicTrustTypeAnnotations',
133-
expectAssumeDynamic: true,
134-
expectTrustTypeAnnotations: true,
135-
expectedParameterType: coreStringType);
13695
}

tests/compiler/dart2js/codegen/trust_type_annotations2_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'package:expect/expect.dart';
66
import "package:async_helper/async_helper.dart";
7-
import 'package:compiler/src/commandline_options.dart';
87
import '../helpers/memory_compiler.dart';
98

109
const MEMORY_SOURCE_FILES = const {
@@ -26,9 +25,7 @@ main (x, y) {
2625

2726
main() {
2827
runTest() async {
29-
var options = [Flags.trustTypeAnnotations];
30-
var result = await runCompiler(
31-
memorySourceFiles: MEMORY_SOURCE_FILES, options: options);
28+
var result = await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES);
3229
var compiler = result.compiler;
3330
var element =
3431
compiler.backendClosedWorldForTesting.elementEnvironment.mainFunction;

tests/compiler/dart2js/equivalence/show_helper.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ ArgParser createArgParser() {
2020
argParser.addFlag('strong', negatable: false, defaultsTo: false);
2121
argParser.addFlag('omit-implicit-checks',
2222
negatable: false, defaultsTo: false);
23-
argParser.addFlag('trust-type-annotations',
24-
negatable: false, defaultsTo: false);
2523
return argParser;
2624
}
2725

@@ -34,7 +32,6 @@ show(ArgResults argResults, DataComputer dataComputer,
3432
}
3533
bool verbose = argResults['verbose'];
3634
bool omitImplicitChecks = argResults['omit-implicit-checks'];
37-
bool trustTypeAnnotations = argResults['trust-type-annotations'];
3835

3936
String file = argResults.rest.first;
4037
Uri entryPoint = Uri.base.resolve(nativeToUriPath(file));
@@ -48,9 +45,6 @@ show(ArgResults argResults, DataComputer dataComputer,
4845
}
4946

5047
options = new List<String>.from(options);
51-
if (trustTypeAnnotations) {
52-
options.add(Flags.trustTypeAnnotations);
53-
}
5448
if (omitImplicitChecks) {
5549
options.add(Flags.omitImplicitChecks);
5650
}

tests/compiler/dart2js/helpers/compiler_helper.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ Future<String> compile(String code,
8989

9090
Future<String> compileAll(String code,
9191
{bool disableInlining: true,
92-
bool trustTypeAnnotations: false,
9392
bool minify: false,
9493
int expectedErrors,
9594
int expectedWarnings}) async {
@@ -99,9 +98,6 @@ Future<String> compileAll(String code,
9998
if (disableInlining) {
10099
options.add(Flags.disableInlining);
101100
}
102-
if (trustTypeAnnotations) {
103-
options.add(Flags.trustTypeAnnotations);
104-
}
105101
if (minify) {
106102
options.add(Flags.minify);
107103
}

0 commit comments

Comments
 (0)