mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:21:07 +00:00
[dart2js] Remove unused 'classesOnlyNeededForRti' field.
Change-Id: I424fd9fcf6c7f8a9d0f724b5599fc96242bb9042 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192943 Commit-Queue: Joshua Litt <joshualitt@google.com> Reviewed-by: Mayank Patke <fishythefish@google.com>
This commit is contained in:
parent
3c2dfd7975
commit
5ca3b45541
|
@ -261,6 +261,9 @@ class Class implements FieldContainer {
|
|||
/// Uses indicate missing information in the model.
|
||||
final ClassEntity element;
|
||||
|
||||
// TODO(joshualitt): Now that we collect all rti needed classes and handle
|
||||
// them separately, we should investigate whether or not we still need to
|
||||
// store the type data on the class.
|
||||
final ClassTypeData typeData;
|
||||
|
||||
final js.Name name;
|
||||
|
|
|
@ -24,7 +24,6 @@ class Collector {
|
|||
|
||||
final Set<ClassEntity> neededClasses = {};
|
||||
final Set<ClassEntity> neededClassTypes = {};
|
||||
final Set<ClassEntity> classesOnlyNeededForRti = {};
|
||||
final Set<ClassEntity> classesOnlyNeededForConstructor = {};
|
||||
final Map<OutputUnit, List<ClassEntity>> outputClassLists = {};
|
||||
final Map<OutputUnit, List<ClassEntity>> outputClassTypeLists = {};
|
||||
|
@ -140,17 +139,6 @@ class Collector {
|
|||
Set<ClassEntity> backendTypeHelpers =
|
||||
getBackendTypeHelpers(_commonElements).toSet();
|
||||
|
||||
/// A class type is 'shadowed' if the class is needed for direct
|
||||
/// instantiation in one OutputUnit while its type is needed in another
|
||||
/// OutputUnit.
|
||||
bool isClassTypeShadowed(ClassEntity cls) {
|
||||
return !backendTypeHelpers.contains(cls) &&
|
||||
_rtiNeededClasses.contains(cls) &&
|
||||
!classesOnlyNeededForRti.contains(cls) &&
|
||||
_outputUnitData.outputUnitForClass(cls) !=
|
||||
_outputUnitData.outputUnitForClassType(cls);
|
||||
}
|
||||
|
||||
// Compute needed classes.
|
||||
Set<ClassEntity> instantiatedClasses =
|
||||
// TODO(johnniwinther): This should be accessed from a codegen closed
|
||||
|
@ -184,20 +172,10 @@ class Collector {
|
|||
}
|
||||
}
|
||||
|
||||
// 4. Find all classes needed for rti.
|
||||
// It is important that this is the penultimate step, at this point,
|
||||
// neededClasses must only contain classes that have been resolved and
|
||||
// codegen'd. The rtiNeededClasses may contain additional classes, but
|
||||
// these are thought to not have been instantiated, so we need to be able
|
||||
// to identify them later and make sure we only emit "empty shells" without
|
||||
// fields, etc.
|
||||
// 4. Find all class types needed for rti.
|
||||
for (ClassEntity cls in _rtiNeededClasses) {
|
||||
if (backendTypeHelpers.contains(cls)) continue;
|
||||
while (cls != null && !neededClasses.contains(cls)) {
|
||||
if (!classesOnlyNeededForRti.add(cls)) break;
|
||||
// TODO(joshualitt) delete classesOnlyNeededForRti when the
|
||||
// no-defer-class_types flag is removed.
|
||||
neededClassTypes.add(cls);
|
||||
while (cls != null && neededClassTypes.add(cls)) {
|
||||
cls = _elementEnvironment.getSuperClass(cls);
|
||||
}
|
||||
}
|
||||
|
@ -219,14 +197,7 @@ class Collector {
|
|||
}
|
||||
}
|
||||
|
||||
// 6. Collect any class types 'shadowed' by direct instantiation.
|
||||
for (ClassEntity cls in _rtiNeededClasses) {
|
||||
if (isClassTypeShadowed(cls)) {
|
||||
neededClassTypes.add(cls);
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Sort classes needed for type checking and then add them to their
|
||||
// 6. Sort classes needed for type checking and then add them to their
|
||||
// respective OutputUnits.
|
||||
for (ClassEntity cls in _sorter.sortClasses(neededClassTypes)) {
|
||||
outputClassTypeLists
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) 2021, 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.
|
||||
|
||||
/*class: A:
|
||||
class_unit=1{libb},
|
||||
type_unit=2{libb, liba}
|
||||
*/
|
||||
/*member: A.:member_unit=1{libb}*/
|
||||
class A {}
|
||||
|
||||
/*class: B:
|
||||
class_unit=main{},
|
||||
type_unit=main{}
|
||||
*/
|
||||
/*member: B.:member_unit=main{}*/
|
||||
class B {}
|
||||
|
||||
/*class: C_Parent:
|
||||
class_unit=1{libb},
|
||||
type_unit=main{}
|
||||
*/
|
||||
/*member: C_Parent.:member_unit=1{libb}*/
|
||||
class C_Parent {}
|
||||
|
||||
/*class: D:
|
||||
class_unit=1{libb},
|
||||
type_unit=2{libb, liba}
|
||||
*/
|
||||
/*member: D.:member_unit=1{libb}*/
|
||||
class D {}
|
||||
|
||||
/*class: E:
|
||||
class_unit=1{libb},
|
||||
type_unit=1{libb}
|
||||
*/
|
||||
/*member: E.:member_unit=1{libb}*/
|
||||
class E extends D {}
|
||||
|
||||
/*class: F:
|
||||
class_unit=1{libb},
|
||||
type_unit=1{libb}
|
||||
*/
|
||||
/*member: F.:member_unit=1{libb}*/
|
||||
class F {}
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2021, 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 'lib_shared.dart';
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
/*member: isA:member_unit=3{liba}*/
|
||||
isA(foo) {
|
||||
return foo is A;
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
/*member: isD:member_unit=3{liba}*/
|
||||
isD(foo) {
|
||||
return foo is D;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (c) 2021, 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 'lib_shared.dart';
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
/*member: createA:member_unit=1{libb}*/
|
||||
createA() {
|
||||
return A();
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
/*member: isB:member_unit=1{libb}*/
|
||||
isB(foo) {
|
||||
return foo is B;
|
||||
}
|
||||
|
||||
/*class: C:
|
||||
class_unit=1{libb},
|
||||
type_unit=main{}
|
||||
*/
|
||||
/*member: C.:member_unit=1{libb}*/
|
||||
class C extends C_Parent {}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
/*member: createC:member_unit=1{libb}*/
|
||||
createC() {
|
||||
return C();
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
/*member: createE:member_unit=1{libb}*/
|
||||
createE() {
|
||||
return E();
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
/*member: isFWithUnused:member_unit=1{libb}*/
|
||||
isFWithUnused(foo) {
|
||||
var unused = F();
|
||||
return foo is F;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (c) 2021, 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.
|
||||
|
||||
/*library:
|
||||
output_units=[
|
||||
f1: {units: [3{liba}], usedBy: [], needs: []},
|
||||
f2: {units: [1{libb}], usedBy: [], needs: []}],
|
||||
steps=[
|
||||
liba=(f1),
|
||||
libb=(f2)]
|
||||
*/
|
||||
|
||||
import 'liba.dart' deferred as liba;
|
||||
import 'libb.dart' deferred as libb;
|
||||
import 'lib_shared.dart';
|
||||
|
||||
/*member: main:member_unit=main{}*/
|
||||
main() async {
|
||||
var f = /*closure_unit=main{}*/ () => libb.C();
|
||||
print(f is C_Parent Function());
|
||||
await liba.loadLibrary();
|
||||
await libb.loadLibrary();
|
||||
|
||||
print(liba.isA(libb.createA()));
|
||||
print(libb.createA());
|
||||
print(libb.createC());
|
||||
print(libb.isB(B()));
|
||||
print(liba.isD(libb.createE()));
|
||||
print(libb.isFWithUnused(null as dynamic));
|
||||
}
|
22
tests/web/deferred/shadowed_types/lib_shared.dart
Normal file
22
tests/web/deferred/shadowed_types/lib_shared.dart
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright (c) 2021, 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.
|
||||
|
||||
// Class A has a type used in libb, but a class used in liba.
|
||||
class A {}
|
||||
|
||||
// Class B has a class used in the main output unit, and a type used in libb.
|
||||
class B {}
|
||||
|
||||
// Class C_Parent is extended is libb, and closed around in the main output
|
||||
// unit.
|
||||
class C_Parent {}
|
||||
|
||||
// Classes D through F represent a simple heirarchy.
|
||||
// D's type is used in liba.
|
||||
// F is instantiated, but unused in libb.
|
||||
class D {}
|
||||
|
||||
class E extends D {}
|
||||
|
||||
class F {}
|
15
tests/web/deferred/shadowed_types/liba.dart
Normal file
15
tests/web/deferred/shadowed_types/liba.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) 2021, 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 'lib_shared.dart';
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
isA(foo) {
|
||||
return foo is A;
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
isD(foo) {
|
||||
return foo is D;
|
||||
}
|
33
tests/web/deferred/shadowed_types/libb.dart
Normal file
33
tests/web/deferred/shadowed_types/libb.dart
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2021, 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 'lib_shared.dart';
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
createA() {
|
||||
return A();
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
isB(foo) {
|
||||
return foo is B;
|
||||
}
|
||||
|
||||
class C extends C_Parent {}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
createC() {
|
||||
return C();
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
createE() {
|
||||
return E();
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
isFWithUnused(foo) {
|
||||
var unused = F();
|
||||
return foo is F;
|
||||
}
|
22
tests/web/deferred/shadowed_types/shadowed_types_test.dart
Normal file
22
tests/web/deferred/shadowed_types/shadowed_types_test.dart
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright (c) 2021, 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';
|
||||
import 'liba.dart' deferred as liba;
|
||||
import 'libb.dart' deferred as libb;
|
||||
import 'lib_shared.dart';
|
||||
|
||||
main() async {
|
||||
var f = () => libb.C();
|
||||
Expect.isTrue(f is C_Parent Function());
|
||||
await liba.loadLibrary();
|
||||
await libb.loadLibrary();
|
||||
|
||||
Expect.isTrue(liba.isA(libb.createA()));
|
||||
print(libb.createA());
|
||||
print(libb.createC());
|
||||
Expect.isTrue(libb.isB(B()));
|
||||
Expect.isTrue(liba.isD(libb.createE()));
|
||||
Expect.isFalse(libb.isFWithUnused(null as dynamic));
|
||||
}
|
Loading…
Reference in a new issue