From ec6fcf34bb11353882ce18ff032dbd4aede2ca06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Fri, 20 Jan 2023 17:01:41 +0000 Subject: [PATCH] [dart2wasm] Make ClassInfo and ClassInfoCollector members private MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also makes some late field final. Change-Id: I792fb10c151343c3a4a6d8b6a59cc6da8f69489b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279094 Reviewed-by: Joshua Litt Commit-Queue: Ömer Ağacan --- pkg/dart2wasm/lib/class_info.dart | 54 +++++++++++++++---------------- pkg/dart2wasm/lib/translator.dart | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/pkg/dart2wasm/lib/class_info.dart b/pkg/dart2wasm/lib/class_info.dart index 51b2b323f41..6a448aa89d1 100644 --- a/pkg/dart2wasm/lib/class_info.dart +++ b/pkg/dart2wasm/lib/class_info.dart @@ -14,7 +14,7 @@ import 'package:wasm_builder/wasm_builder.dart' as w; /// code, e.g. in intrinsics. /// /// The values are validated by asserts, typically either through -/// [ClassInfo.addField] (for manually added fields) or by a line in +/// [ClassInfo._addField] (for manually added fields) or by a line in /// [FieldIndex.validate] (for fields declared in Dart code). class FieldIndex { static const classId = 0; @@ -104,7 +104,7 @@ class ClassInfo { /// The class whose struct is used as the type for variables of this type. /// This is a type which is a superclass of all subtypes of this type. - late ClassInfo repr; + late final ClassInfo repr; /// All classes which implement this class. This is used to compute `repr`. final List implementedBy = []; @@ -126,7 +126,7 @@ class ClassInfo { implementedBy.add(this); } - void addField(w.FieldType fieldType, [int? expectedIndex]) { + void _addField(w.FieldType fieldType, [int? expectedIndex]) { assert(expectedIndex == null || expectedIndex == struct.fields.length); struct.fields.add(fieldType); } @@ -174,14 +174,14 @@ class ClassInfoCollector { TranslatorOptions get options => translator.options; - void initializeTop() { + void _initializeTop() { final w.StructType struct = m.addStructType("#Top"); topInfo = ClassInfo(null, _nextClassId++, 0, struct, null); translator.classes.add(topInfo); translator.classForHeapType[struct] = topInfo; } - void initialize(Class cls) { + void _initialize(Class cls) { ClassInfo? info = translator.classInfo[cls]; if (info != null) return; @@ -197,9 +197,9 @@ class ClassInfoCollector { info.implementedBy.add(topInfo); } else { // Recursively initialize all supertypes before initializing this class. - initialize(superclass); + _initialize(superclass); for (Supertype interface in cls.implementedTypes) { - initialize(interface.classNode); + _initialize(interface.classNode); } // In the Wasm type hierarchy, Object, bool and num sit directly below @@ -271,19 +271,19 @@ class ClassInfoCollector { info.repr = upperBound(info.implementedBy); } - void generateFields(ClassInfo info) { + void _generateFields(ClassInfo info) { ClassInfo? superInfo = info.superInfo; if (superInfo == null) { // Top - add class id field - info.addField(w.FieldType(w.NumType.i32), FieldIndex.classId); + info._addField(w.FieldType(w.NumType.i32), FieldIndex.classId); } else if (info.struct != superInfo.struct) { // Copy fields from superclass for (w.FieldType fieldType in superInfo.struct.fields) { - info.addField(fieldType); + info._addField(fieldType); } if (info.cls!.superclass == null) { // Object - add identity hash code field - info.addField(w.FieldType(w.NumType.i32), FieldIndex.identityHash); + info._addField(w.FieldType(w.NumType.i32), FieldIndex.identityHash); } // Add fields for type variables for (TypeParameter parameter in info.cls!.typeParameters) { @@ -294,7 +294,7 @@ class ClassInfoCollector { translator.typeParameterIndex[match]!; } else { translator.typeParameterIndex[parameter] = info.struct.fields.length; - info.addField(typeType); + info._addField(typeType); } } // Add fields for Dart instance fields @@ -306,7 +306,7 @@ class ClassInfoCollector { wasmType = wasmType.withNullability(true); } translator.fieldIndex[field] = info.struct.fields.length; - info.addField(w.FieldType(wasmType)); + info._addField(w.FieldType(wasmType)); } } } else { @@ -320,21 +320,21 @@ class ClassInfoCollector { /// Create class info and Wasm struct for all classes. void collect() { - initializeTop(); + _initializeTop(); // Subclasses of the `_Closure` class are generated on the fly as fields // with function types are encountered. Therefore, `_Closure` class must // be early in the initialization order. - initialize(translator.closureClass); + _initialize(translator.closureClass); // Similarly `_Type` is needed for type parameter fields in classes and // needs to be initialized before we encounter a class with type // parameters. - initialize(translator.typeClass); + _initialize(translator.typeClass); for (Library library in translator.component.libraries) { for (Class cls in library.classes) { - initialize(cls); + _initialize(cls); } } @@ -349,7 +349,7 @@ class ClassInfoCollector { // Now that the representation types for all classes have been computed, // fill in the types of the fields in the generated Wasm structs. for (ClassInfo info in translator.classes) { - generateFields(info); + _generateFields(info); } // Add hidden fields of typed_data classes. @@ -362,16 +362,16 @@ class ClassInfoCollector { void _addTypedDataFields() { ClassInfo typedListBaseInfo = translator.classInfo[translator.typedListBaseClass]!; - typedListBaseInfo.addField(w.FieldType(w.NumType.i32, mutable: false), + typedListBaseInfo._addField(w.FieldType(w.NumType.i32, mutable: false), FieldIndex.typedListBaseLength); ClassInfo typedListInfo = translator.classInfo[translator.typedListClass]!; - typedListInfo.addField(w.FieldType(w.NumType.i32, mutable: false), + typedListInfo._addField(w.FieldType(w.NumType.i32, mutable: false), FieldIndex.typedListBaseLength); w.RefType bytesArrayType = w.RefType.def( translator.wasmArrayType(w.PackedType.i8, "i8"), nullable: false); - typedListInfo.addField( + typedListInfo._addField( w.FieldType(bytesArrayType, mutable: false), FieldIndex.typedListArray); w.RefType typedListType = @@ -379,20 +379,20 @@ class ClassInfoCollector { ClassInfo typedListViewInfo = translator.classInfo[translator.typedListViewClass]!; - typedListViewInfo.addField(w.FieldType(w.NumType.i32, mutable: false), + typedListViewInfo._addField(w.FieldType(w.NumType.i32, mutable: false), FieldIndex.typedListBaseLength); - typedListViewInfo.addField(w.FieldType(typedListType, mutable: false), + typedListViewInfo._addField(w.FieldType(typedListType, mutable: false), FieldIndex.typedListViewTypedData); - typedListViewInfo.addField(w.FieldType(w.NumType.i32, mutable: false), + typedListViewInfo._addField(w.FieldType(w.NumType.i32, mutable: false), FieldIndex.typedListViewOffsetInBytes); ClassInfo byteDataViewInfo = translator.classInfo[translator.byteDataViewClass]!; - byteDataViewInfo.addField(w.FieldType(w.NumType.i32, mutable: false), + byteDataViewInfo._addField(w.FieldType(w.NumType.i32, mutable: false), FieldIndex.byteDataViewLength); - byteDataViewInfo.addField(w.FieldType(typedListType, mutable: false), + byteDataViewInfo._addField(w.FieldType(typedListType, mutable: false), FieldIndex.byteDataViewTypedData); - byteDataViewInfo.addField(w.FieldType(w.NumType.i32, mutable: false), + byteDataViewInfo._addField(w.FieldType(w.NumType.i32, mutable: false), FieldIndex.byteDataViewOffsetInBytes); } } diff --git a/pkg/dart2wasm/lib/translator.dart b/pkg/dart2wasm/lib/translator.dart index 5b618ad24b2..03670590346 100644 --- a/pkg/dart2wasm/lib/translator.dart +++ b/pkg/dart2wasm/lib/translator.dart @@ -88,7 +88,7 @@ class Translator with KernelNodes { final Set membersContainingInnerFunctions = {}; final Set membersBeingGenerated = {}; final List<_FunctionGenerator> _pendingFunctions = []; - late Procedure mainFunction; + late final Procedure mainFunction; late final w.Module m; late final w.DefinedFunction initFunction; late final w.ValueType voidMarker;