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

Commit 52562bb

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2js] Prep js_emitter/program_builder.dart for migration to null safety.
Change-Id: I95b3255706d2d6b4015555361416e3636e0965da Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/268406 Reviewed-by: Mayank Patke <fishythefish@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
1 parent 4c1391e commit 52562bb

File tree

9 files changed

+30
-50
lines changed

9 files changed

+30
-50
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import '../common/codegen_interfaces.dart' show CodegenImpact;
99
import '../constants/values.dart';
1010
import '../elements/entities.dart';
1111
import '../elements/types.dart';
12-
import '../js_emitter/interfaces.dart' show NativeEmitter;
12+
import '../js_emitter/native_emitter.dart';
1313
import '../js_model/js_world.dart';
1414
import '../native/enqueue.dart';
1515
import '../native/behavior.dart';

pkg/compiler/lib/src/js_emitter/class_stub_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class ClassStubGenerator {
212212
jsAst.Expression code;
213213
if (field.isElided) {
214214
code = js("function() { return #; }",
215-
_emitter.constantReference(field.constantValue));
215+
_emitter.constantReference(field.constantValue!));
216216
} else {
217217
String template;
218218
if (field.needsInterceptedGetterOnReceiver) {

pkg/compiler/lib/src/js_emitter/code_emitter_task.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ abstract class Emitter implements ModularEmitter, interfaces.Emitter {
247247

248248
@override
249249
int compareConstants(ConstantValue a, ConstantValue b);
250+
@override
250251
bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant);
251252

252253
/// Returns the size of the code generated for a given output [unit].

pkg/compiler/lib/src/js_emitter/interfaces.dart

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import '../elements/entities.dart';
1212
import '../js/js.dart' as jsAst;
1313

1414
import 'metadata_collector.dart' show MetadataCollector;
15+
import 'native_emitter.dart';
1516
import 'startup_emitter/fragment_merger.dart';
1617

1718
abstract class CodeEmitterTask {
@@ -22,19 +23,6 @@ abstract class CodeEmitterTask {
2223
MetadataCollector get metadataCollector;
2324
}
2425

25-
abstract class NativeEmitter {
26-
Map<ClassEntity, List<ClassEntity>> get subtypes;
27-
Map<ClassEntity, List<ClassEntity>> get directSubtypes;
28-
Set<FunctionEntity> get nativeMethods;
29-
List<jsAst.Statement> generateParameterStubStatements(
30-
FunctionEntity member,
31-
bool isInterceptedMethod,
32-
jsAst.Name invocationName,
33-
List<jsAst.Parameter> stubParameters,
34-
List<jsAst.Expression> argumentsBuffer,
35-
int indexOfLastOptionalArgumentInParameters);
36-
}
37-
3826
abstract class ModularEmitter {
3927
jsAst.Expression constructorAccess(ClassEntity e);
4028
jsAst.Expression constantReference(ConstantValue constant);
@@ -55,4 +43,5 @@ abstract class Emitter extends ModularEmitter {
5543
jsAst.Expression generateEmbeddedGlobalAccess(String global);
5644
int compareConstants(ConstantValue a, ConstantValue b);
5745
jsAst.Expression interceptorClassAccess(ClassEntity e);
46+
bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant);
5847
}

pkg/compiler/lib/src/js_emitter/metadata_collector.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class MetadataCollector implements jsAst.TokenFinalizer {
139139
}
140140
}
141141

142-
jsAst.Expression? reifyType(DartType type, OutputUnit outputUnit) {
142+
jsAst.Expression reifyType(DartType type, OutputUnit outputUnit) {
143143
return _addTypeInOutputUnit(type, outputUnit);
144144
}
145145

pkg/compiler/lib/src/js_emitter/model.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Program {
2121

2222
// If this field is not `null` then its value must be emitted in the embedded
2323
// global `TYPE_TO_INTERCEPTOR_MAP`. The map references constants and classes.
24-
final js.Expression typeToInterceptorMap;
24+
final js.Expression? typeToInterceptorMap;
2525

2626
// TODO(floitsch): we should store the metadata directly instead of storing
2727
// the collector. However, the old emitter still updates the data.
@@ -173,7 +173,8 @@ class StaticField {
173173
final FieldEntity element;
174174

175175
final js.Name name;
176-
final js.Name getterName;
176+
// Null for static non-final fields.
177+
final js.Name? getterName;
177178
// TODO(floitsch): the holder for static fields is the isolate object. We
178179
// could remove this field and use the isolate object directly.
179180
final js.Expression code;
@@ -252,7 +253,7 @@ class Class {
252253

253254
// If the class implements a function type, and the type is encoded in the
254255
// metatada table, then this field contains the index into that field.
255-
final js.Expression functionTypeIndex;
256+
final js.Expression? functionTypeIndex;
256257

257258
/// Whether the class must be evaluated eagerly.
258259
bool isEager = false;
@@ -305,11 +306,11 @@ class MixinApplication extends Class {
305306
List<StubMethod> checkedSetters,
306307
List<StubMethod> gettersSetters,
307308
List<StubMethod> isChecks,
308-
js.Expression functionTypeIndex,
309-
{required bool hasRtiField,
310-
required bool onlyForRti,
311-
required bool onlyForConstructor,
312-
required bool isDirectlyInstantiated})
309+
js.Expression? functionTypeIndex,
310+
{required super.hasRtiField,
311+
required super.onlyForRti,
312+
required super.onlyForConstructor,
313+
required super.isDirectlyInstantiated})
313314
: super(
314315
element,
315316
typeData,
@@ -322,10 +323,6 @@ class MixinApplication extends Class {
322323
gettersSetters,
323324
isChecks,
324325
functionTypeIndex,
325-
hasRtiField: hasRtiField,
326-
onlyForRti: onlyForRti,
327-
onlyForConstructor: onlyForConstructor,
328-
isDirectlyInstantiated: isDirectlyInstantiated,
329326
isNative: false,
330327
isClosureBaseClass: false,
331328
isMixinApplicationWithMembers: false);
@@ -363,9 +360,9 @@ class Field {
363360

364361
final bool needsCheckedSetter;
365362

366-
final ConstantValue initializerInAllocator;
363+
final ConstantValue? initializerInAllocator;
367364

368-
final ConstantValue constantValue;
365+
final ConstantValue? constantValue;
369366

370367
final bool isElided;
371368

@@ -488,7 +485,7 @@ class InstanceMethod extends DartMethod {
488485
super.name,
489486
super.code,
490487
super.parameterStubs,
491-
js.Name super.callName, {
488+
super.callName, {
492489
required super.needsTearOff,
493490
super.tearOffName,
494491
this.aliasName,
@@ -559,7 +556,7 @@ abstract class StaticMethod implements Method {}
559556

560557
class StaticDartMethod extends DartMethod implements StaticMethod {
561558
StaticDartMethod(super.element, super.name, super.code, super.parameterStubs,
562-
js.Name super.callName,
559+
super.callName,
563560
{required super.needsTearOff,
564561
super.tearOffName,
565562
required super.canBeApplied,

pkg/compiler/lib/src/js_emitter/native_emitter.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ import '../native/enqueue.dart' show NativeCodegenEnqueuer;
1717

1818
import 'interfaces.dart' show CodeEmitterTask;
1919
import 'model.dart';
20-
import 'interfaces.dart' as interfaces;
2120

22-
class NativeEmitter implements interfaces.NativeEmitter {
21+
class NativeEmitter {
2322
final CodeEmitterTask _emitterTask;
2423
final JClosedWorld _closedWorld;
2524
final NativeCodegenEnqueuer _nativeCodegenEnqueuer;
@@ -28,15 +27,12 @@ class NativeEmitter implements interfaces.NativeEmitter {
2827
bool hasNativeClasses = false;
2928

3029
// Caches the native subtypes of a native class.
31-
@override
3230
Map<ClassEntity, List<ClassEntity>> subtypes = {};
3331

34-
@override
3532
// Caches the direct native subtypes of a native class.
3633
Map<ClassEntity, List<ClassEntity>> directSubtypes = {};
3734

3835
// Caches the methods that have a native body.
39-
@override
4036
Set<FunctionEntity> nativeMethods = {};
4137

4238
// Type metadata redirections, where the key is the class type data being
@@ -314,7 +310,6 @@ class NativeEmitter implements interfaces.NativeEmitter {
314310
});
315311
}
316312

317-
@override
318313
List<jsAst.Statement> generateParameterStubStatements(
319314
FunctionEntity member,
320315
bool isInterceptedMethod,

pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,14 @@ import '../../universe/class_hierarchy.dart';
4141
import '../../universe/codegen_world_builder.dart';
4242
import '../../universe/selector.dart' show Selector;
4343
import '../../universe/world_builder.dart' show SelectorConstraints;
44-
import '../js_emitter.dart'
45-
show
46-
ClassStubGenerator,
47-
CodeEmitterTask,
48-
Emitter,
49-
InstantiationStubGenerator,
50-
InterceptorStubGenerator,
51-
MainCallStubGenerator,
52-
ParameterStubGenerator,
53-
RuntimeTypeGenerator,
54-
TypeTestProperties;
44+
import '../class_stub_generator.dart' show ClassStubGenerator;
45+
import '../instantiation_stub_generator.dart' show InstantiationStubGenerator;
46+
import '../interceptor_stub_generator.dart' show InterceptorStubGenerator;
47+
import '../main_call_stub_generator.dart' show MainCallStubGenerator;
48+
import '../parameter_stub_generator.dart' show ParameterStubGenerator;
49+
import '../runtime_type_generator.dart'
50+
show RuntimeTypeGenerator, TypeTestProperties;
51+
import '../interfaces.dart' show CodeEmitterTask, Emitter;
5552
import '../model.dart';
5653
import '../sorter.dart';
5754

pkg/compiler/lib/src/native/enqueue.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import '../common/elements.dart' show CommonElements, ElementEnvironment;
66
import '../elements/entities.dart';
77
import '../elements/types.dart';
88
import '../js_backend/native_data.dart' show NativeData;
9-
import '../js_emitter/interfaces.dart' show CodeEmitterTask, NativeEmitter;
9+
import '../js_emitter/interfaces.dart' show CodeEmitterTask;
10+
import '../js_emitter/native_emitter.dart';
1011
import '../options.dart';
1112
import '../universe/use.dart' show TypeUse;
1213
import '../universe/world_impact.dart'

0 commit comments

Comments
 (0)