Skip to content

Commit cc9353a

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[ddc] Tag classes with names of static members
Temporarily add names of static members so they can be accessed by the debugger. Eventually, these will be accessible through the symbol data and should be removed from the compiled Javascript. This increases the size of the compiled output by ~1% in a large google3 application. Names and types of static members were originally removed from the compiled output in https://dart-review.googlesource.com/c/sdk/+/48455 because they are not needed for runtime correctness. Change-Id: Idfd827ececec80d903586917676ec027e2a5a9e8 Issue: #40273 Issue: dart-lang/webdev#1430 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217501 Reviewed-by: Anna Gringauze <[email protected]> Commit-Queue: Nicholas Shahan <[email protected]>
1 parent 76dadee commit cc9353a

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

pkg/dev_compiler/lib/src/kernel/compiler.dart

+37-12
Original file line numberDiff line numberDiff line change
@@ -1395,16 +1395,26 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
13951395
void emitSignature(String name, List<js_ast.Property> elements) {
13961396
if (elements.isEmpty) return;
13971397

1398+
js_ast.Statement setSignature;
13981399
if (!name.startsWith('Static')) {
13991400
var proto = c == _coreTypes.objectClass
14001401
? js.call('Object.create(null)')
14011402
: runtimeCall('get${name}s(#.__proto__)', [className]);
14021403
elements.insert(0, js_ast.Property(propertyName('__proto__'), proto));
1404+
setSignature = runtimeStatement('set${name}Signature(#, () => #)', [
1405+
className,
1406+
js_ast.ObjectInitializer(elements, multiline: elements.length > 1)
1407+
]);
1408+
} else {
1409+
// TODO(40273) Only tagging with the names of static members until the
1410+
// debugger consumes signature information from symbol files.
1411+
setSignature = runtimeStatement('set${name}Signature(#, () => #)', [
1412+
className,
1413+
js_ast.ArrayInitializer(elements.map((e) => e.name).toList())
1414+
]);
14031415
}
1404-
body.add(runtimeStatement('set${name}Signature(#, () => #)', [
1405-
className,
1406-
js_ast.ObjectInitializer(elements, multiline: elements.length > 1)
1407-
]));
1416+
1417+
body.add(setSignature);
14081418
}
14091419

14101420
var extMethods = _classProperties.extensionMethods;
@@ -1416,6 +1426,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
14161426
var staticSetters = <js_ast.Property>[];
14171427
var instanceSetters = <js_ast.Property>[];
14181428
List<js_ast.Property> getSignatureList(Procedure p) {
1429+
// TODO(40273) Skip for all statics when the debugger consumes signature
1430+
// information from symbol files.
14191431
if (p.isStatic) {
14201432
if (p.isGetter) {
14211433
return staticGetters;
@@ -1437,9 +1449,14 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
14371449

14381450
var classProcedures = c.procedures.where((p) => !p.isAbstract).toList();
14391451
for (var member in classProcedures) {
1440-
// Static getters/setters/methods cannot be called with dynamic dispatch,
1441-
// nor can they be torn off.
1442-
if (member.isStatic) continue;
1452+
// Static getters/setters cannot be called with dynamic dispatch or torn
1453+
// off. Static methods can't be called with dynamic dispatch and are
1454+
// tagged with a type when torn off. Most are implicitly const and
1455+
// canonicalized. Static signatures are only used by the debugger and are
1456+
// not needed for runtime correctness.
1457+
// TODO(40273) Skip for all statics when the debugger consumes signature
1458+
// information from symbol files.
1459+
if (isTearOffLowering(member)) continue;
14431460

14441461
var name = member.name.text;
14451462
var reifiedType = _memberRuntimeType(member, c) as FunctionType;
@@ -1478,6 +1495,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
14781495
}
14791496

14801497
emitSignature('Method', instanceMethods);
1498+
// TODO(40273) Skip for all statics when the debugger consumes signature
1499+
// information from symbol files.
14811500
emitSignature('StaticMethod', staticMethods);
14821501
emitSignature('Getter', instanceGetters);
14831502
emitSignature('Setter', instanceSetters);
@@ -1491,16 +1510,19 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
14911510

14921511
var classFields = c.fields.toList();
14931512
for (var field in classFields) {
1494-
// Only instance fields need to be saved for dynamic dispatch.
1495-
var isStatic = field.isStatic;
1496-
if (isStatic) continue;
1497-
1513+
// Static fields cannot be called with dynamic dispatch or torn off. The
1514+
// signatures are only used by the debugger and are not needed for runtime
1515+
// correctness.
14981516
var memberName = _declareMemberName(field);
14991517
var fieldSig = _emitFieldSignature(field, c);
1500-
(isStatic ? staticFields : instanceFields)
1518+
// TODO(40273) Skip static fields when the debugger consumes signature
1519+
// information from symbol files.
1520+
(field.isStatic ? staticFields : instanceFields)
15011521
.add(js_ast.Property(memberName, fieldSig));
15021522
}
15031523
emitSignature('Field', instanceFields);
1524+
// TODO(40273) Skip for all statics when the debugger consumes signature
1525+
// information from symbol files.
15041526
emitSignature('StaticField', staticFields);
15051527

15061528
// Add static property dart._runtimeType to Object.
@@ -2525,6 +2547,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
25252547
var exportName = _jsExportName(member);
25262548
if (exportName != null) return propertyName(exportName);
25272549
}
2550+
if (member is Procedure && member.isFactory) {
2551+
return _constructorName(member.name.text);
2552+
}
25282553
switch (name) {
25292554
// Reserved for the compiler to do `x as T`.
25302555
case 'as':

sdk/lib/_internal/js_dev_runtime/private/debugger.dart

+3-17
Original file line numberDiff line numberDiff line change
@@ -924,23 +924,9 @@ class ClassFormatter implements Formatter {
924924
// implemented interfaces, and methods.
925925
var ret = LinkedHashSet<NameValuePair>();
926926

927-
var staticProperties = Set<NameValuePair>();
928-
var staticMethods = Set<NameValuePair>();
929-
// Static fields and properties.
930-
addPropertiesFromSignature(
931-
dart.getStaticFields(type), staticProperties, type, false);
932-
addPropertiesFromSignature(
933-
dart.getStaticGetters(type), staticProperties, type, false);
934-
// static methods.
935-
addPropertiesFromSignature(
936-
dart.getStaticMethods(type), staticMethods, type, false);
937-
938-
if (staticProperties.isNotEmpty || staticMethods.isNotEmpty) {
939-
ret
940-
..add(NameValuePair(value: '[[Static members]]', hideName: true))
941-
..addAll(sortProperties(staticProperties))
942-
..addAll(sortProperties(staticMethods));
943-
}
927+
// Static fields, getters, setters, and methods signatures were removed
928+
// from the runtime representation because they are not needed. At this
929+
// time there is no intention to support them in this custom formatter.
944930

945931
// instance methods.
946932
var instanceMethods = Set<NameValuePair>();

0 commit comments

Comments
 (0)