From 2928af2b1235b954965116a25a6ab35fcb8ed189 Mon Sep 17 00:00:00 2001 From: Jens Johansen Date: Tue, 27 Oct 2020 12:59:33 +0000 Subject: [PATCH] [kernel] Remove unused Class.level, ClassLevel enum and shift Library.flags down ClassLevel and Class.level have been unused for (at least) years. This CL removes them. Library.flags furthermore had the first bit unused after the 'external' flag was removed (last year I think). This CL shifts it down so the actual flags doesn't start at bit 1. Change-Id: Ie0afd150cad331ea694bc5fe2a20aafed22916cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169202 Reviewed-by: Johnni Winther Commit-Queue: Jens Johansen --- pkg/kernel/binary.md | 20 ++---- pkg/kernel/lib/ast.dart | 71 +++---------------- pkg/kernel/lib/binary/ast_from_binary.dart | 11 +-- pkg/kernel/lib/binary/ast_to_binary.dart | 10 +-- pkg/kernel/lib/binary/tag.dart | 2 +- .../mixin_full_resolution.dart | 9 +-- .../frontend/kernel_translation_helper.h | 22 +++--- runtime/vm/kernel_binary.h | 4 +- runtime/vm/kernel_loader.cc | 2 - 9 files changed, 31 insertions(+), 120 deletions(-) diff --git a/pkg/kernel/binary.md b/pkg/kernel/binary.md index a1429ad7512..6470e3a87c7 100644 --- a/pkg/kernel/binary.md +++ b/pkg/kernel/binary.md @@ -143,7 +143,7 @@ type CanonicalName { type ComponentFile { UInt32 magic = 0x90ABCDEF; - UInt32 formatVersion = 48; + UInt32 formatVersion = 49; Byte[10] shortSdkHash; List problemsAsJson; // Described in problems.md. Library[] libraries; @@ -230,8 +230,7 @@ type Name { } type Library { - Byte flags (_unused_, isSynthetic, isNonNullableByDefault, - nnbdModeBit1, nnbdModeBit2); + Byte flags (isSynthetic, isNonNullableByDefault, nnbdModeBit1, nnbdModeBit2); UInt languageVersionMajor; UInt languageVersionMinor; CanonicalNameReference canonicalName; @@ -301,16 +300,6 @@ abstract type Node { Byte tag; } -enum ClassLevel { Type = 0, Hierarchy = 1, Mixin = 2, Body = 3, } - -// A class can be represented at one of three levels: type, hierarchy, or body. -// -// If the enclosing library is external, a class is either at type or -// hierarchy level, depending on its isTypeLevel flag. -// If the enclosing library is not external, a class is always at body level. -// -// See ClassLevel in ast.dart for the details of each loading level. - type Class extends Node { Byte tag = 2; CanonicalNameReference canonicalName; @@ -319,9 +308,8 @@ type Class extends Node { FileOffset startFileOffset; // Offset of the start of the class including any annotations. FileOffset fileOffset; // Offset of the name of the class. FileOffset fileEndOffset; - Byte flags (levelBit0, levelBit1, isAbstract, isEnum, isAnonymousMixin, - isEliminatedMixin, isMixinDeclaration, - hasConstConstructor); // Where level is index into ClassLevel + Byte flags (isAbstract, isEnum, isAnonymousMixin, isEliminatedMixin, + isMixinDeclaration, hasConstConstructor); StringReference name; List annotations; List typeParameters; diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart index de5beb8a499..fadd9a2d007 100644 --- a/pkg/kernel/lib/ast.dart +++ b/pkg/kernel/lib/ast.dart @@ -366,10 +366,10 @@ class Library extends NamedNode _languageVersion = languageVersion; } - static const int SyntheticFlag = 1 << 1; - static const int NonNullableByDefaultFlag = 1 << 2; - static const int NonNullableByDefaultModeBit1 = 1 << 3; - static const int NonNullableByDefaultModeBit2 = 1 << 4; + static const int SyntheticFlag = 1 << 0; + static const int NonNullableByDefaultFlag = 1 << 1; + static const int NonNullableByDefaultModeBit1 = 1 << 2; + static const int NonNullableByDefaultModeBit2 = 1 << 3; int flags = 0; @@ -872,53 +872,6 @@ class Typedef extends NamedNode implements FileUriNode { } } -/// The degree to which the contents of a class have been loaded into memory. -/// -/// Each level imply the requirements of the previous ones. -enum ClassLevel { - /// Temporary loading level for internal use by IR producers. Consumers of - /// kernel code should not expect to see classes at this level. - Temporary, - - /// The class may be used as a type, and it may contain members that are - /// referenced from this build unit. - /// - /// The type parameters and their bounds are present. - /// - /// There is no guarantee that all members are present. - /// - /// All supertypes of this class are at [Type] level or higher. - Type, - - /// All instance members of the class are present. - /// - /// All supertypes of this class are at [Hierarchy] level or higher. - /// - /// This level exists so supertypes of a fully loaded class contain all the - /// members needed to detect override constraints. - Hierarchy, - - /// All instance members of the class have their body loaded, and their - /// annotations are present. - /// - /// All supertypes of this class are at [Hierarchy] level or higher. - /// - /// If this class is a mixin application, then its mixin is loaded at [Mixin] - /// level or higher. - /// - /// This level exists so the contents of a mixin can be cloned into a - /// mixin application. - Mixin, - - /// All members of the class are fully loaded and are in the correct order. - /// - /// Annotations are present on classes and members. - /// - /// All supertypes of this class are at [Hierarchy] level or higher, - /// not necessarily at [Body] level. - Body, -} - /// List-wrapper that marks the parent-class as dirty if the list is modified. /// /// The idea being, that for non-dirty classes (classes just loaded from dill) @@ -975,9 +928,6 @@ class Class extends NamedNode implements Annotatable, FileUriNode { /// (this is the default if none is specifically set). int fileEndOffset = TreeNode.noOffset; - /// The degree to which the contents of the class have been loaded. - ClassLevel level = ClassLevel.Body; - /// List of metadata annotations on the class. /// /// This defaults to an immutable empty list. Use [addAnnotation] to add @@ -994,13 +944,12 @@ class Class extends NamedNode implements Annotatable, FileUriNode { String name; // Must match serialized bit positions. - static const int LevelMask = 0x3; // Bits 0 and 1. - static const int FlagAbstract = 1 << 2; - static const int FlagEnum = 1 << 3; - static const int FlagAnonymousMixin = 1 << 4; - static const int FlagEliminatedMixin = 1 << 5; - static const int FlagMixinDeclaration = 1 << 6; - static const int FlagHasConstConstructor = 1 << 7; + static const int FlagAbstract = 1 << 0; + static const int FlagEnum = 1 << 1; + static const int FlagAnonymousMixin = 1 << 2; + static const int FlagEliminatedMixin = 1 << 3; + static const int FlagMixinDeclaration = 1 << 4; + static const int FlagHasConstConstructor = 1 << 5; int flags = 0; diff --git a/pkg/kernel/lib/binary/ast_from_binary.dart b/pkg/kernel/lib/binary/ast_from_binary.dart index ab556d1c658..7292d922df2 100644 --- a/pkg/kernel/lib/binary/ast_from_binary.dart +++ b/pkg/kernel/lib/binary/ast_from_binary.dart @@ -1149,9 +1149,7 @@ class BinaryBuilder { node = null; } if (node == null) { - node = new Class(reference: reference) - ..level = ClassLevel.Temporary - ..dirty = false; + node = new Class(reference: reference)..dirty = false; } var fileUri = readUriReference(); @@ -1159,12 +1157,7 @@ class BinaryBuilder { node.fileOffset = readOffset(); node.fileEndOffset = readOffset(); int flags = readByte(); - node.flags = flags & ~Class.LevelMask; - int levelIndex = flags & Class.LevelMask; - var level = ClassLevel.values[levelIndex + 1]; - if (level.index >= node.level.index) { - node.level = level; - } + node.flags = flags; var name = readStringOrNullIfEmpty(); var annotations = readAnnotationList(node); assert(() { diff --git a/pkg/kernel/lib/binary/ast_to_binary.dart b/pkg/kernel/lib/binary/ast_to_binary.dart index 872398eb364..a5a426f573c 100644 --- a/pkg/kernel/lib/binary/ast_to_binary.dart +++ b/pkg/kernel/lib/binary/ast_to_binary.dart @@ -1113,20 +1113,12 @@ class BinaryPrinter implements Visitor, BinarySink { } } - int _encodeClassFlags(int flags, ClassLevel level) { - assert((flags & Class.LevelMask) == 0); - final levelIndex = level.index - 1; - assert((levelIndex & Class.LevelMask) == levelIndex); - return flags | levelIndex; - } - @override void visitClass(Class node) { classOffsets.add(getBufferOffset()); if (node.isAnonymousMixin) _currentlyInNonimplementation = true; - int flags = _encodeClassFlags(node.flags, node.level); if (node.canonicalName == null) { throw new ArgumentError('Missing canonical name for $node'); } @@ -1137,7 +1129,7 @@ class BinaryPrinter implements Visitor, BinarySink { writeOffset(node.fileOffset); writeOffset(node.fileEndOffset); - writeByte(flags); + writeByte(node.flags); writeStringReference(node.name ?? ''); enterScope(memberScope: true); diff --git a/pkg/kernel/lib/binary/tag.dart b/pkg/kernel/lib/binary/tag.dart index 2e7a77968db..ebdf993b42c 100644 --- a/pkg/kernel/lib/binary/tag.dart +++ b/pkg/kernel/lib/binary/tag.dart @@ -146,7 +146,7 @@ class Tag { /// Internal version of kernel binary format. /// Bump it when making incompatible changes in kernel binaries. /// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md. - static const int BinaryFormatVersion = 48; + static const int BinaryFormatVersion = 49; } abstract class ConstantTag { diff --git a/pkg/kernel/lib/transformations/mixin_full_resolution.dart b/pkg/kernel/lib/transformations/mixin_full_resolution.dart index f260c10c2c3..345d45259ff 100644 --- a/pkg/kernel/lib/transformations/mixin_full_resolution.dart +++ b/pkg/kernel/lib/transformations/mixin_full_resolution.dart @@ -83,8 +83,7 @@ class MixinFullResolution { } // Ensure super classes have been transformed before this class. - if (class_.superclass != null && - class_.superclass.level.index >= ClassLevel.Mixin.index) { + if (class_.superclass != null) { transformClass(librariesToBeTransformed, processedClasses, transformedClasses, class_.superclass, referenceFromIndex); } @@ -94,12 +93,6 @@ class MixinFullResolution { if (!class_.isMixinApplication) return; assert(librariesToBeTransformed.contains(enclosingLibrary)); - if (class_.mixedInClass.level.index < ClassLevel.Mixin.index) { - throw new Exception( - 'Class "${class_.name}" mixes in "${class_.mixedInClass.name}" from' - ' an external library. Did you forget --link?'); - } - transformedClasses.add(class_); // Clone fields and methods from the mixin class. diff --git a/runtime/vm/compiler/frontend/kernel_translation_helper.h b/runtime/vm/compiler/frontend/kernel_translation_helper.h index 8febf296543..e3f6c542317 100644 --- a/runtime/vm/compiler/frontend/kernel_translation_helper.h +++ b/runtime/vm/compiler/frontend/kernel_translation_helper.h @@ -689,12 +689,12 @@ class ClassHelper { }; enum Flag { - kIsAbstract = 1 << 2, - kIsEnumClass = 1 << 3, - kIsAnonymousMixin = 1 << 4, - kIsEliminatedMixin = 1 << 5, - kFlagMixinDeclaration = 1 << 6, - kHasConstConstructor = 1 << 7, + kIsAbstract = 1 << 0, + kIsEnumClass = 1 << 1, + kIsAnonymousMixin = 1 << 2, + kIsEliminatedMixin = 1 << 3, + kFlagMixinDeclaration = 1 << 4, + kHasConstConstructor = 1 << 5, }; explicit ClassHelper(KernelReaderHelper* helper) @@ -770,11 +770,10 @@ class LibraryHelper { }; enum Flag { - kExternal = 1 << 0, - kSynthetic = 1 << 1, - kIsNonNullableByDefault = 1 << 2, - kNonNullableByDefaultCompiledModeBit1 = 1 << 3, - kNonNullableByDefaultCompiledModeBit2 = 1 << 4, + kSynthetic = 1 << 0, + kIsNonNullableByDefault = 1 << 1, + kNonNullableByDefaultCompiledModeBit1 = 1 << 2, + kNonNullableByDefaultCompiledModeBit2 = 1 << 3, }; explicit LibraryHelper(KernelReaderHelper* helper, uint32_t binary_version) @@ -789,7 +788,6 @@ class LibraryHelper { void SetNext(Field field) { next_read_ = field; } void SetJustRead(Field field) { next_read_ = field + 1; } - bool IsExternal() const { return (flags_ & kExternal) != 0; } bool IsSynthetic() const { return (flags_ & kSynthetic) != 0; } bool IsNonNullableByDefault() const { return (flags_ & kIsNonNullableByDefault) != 0; diff --git a/runtime/vm/kernel_binary.h b/runtime/vm/kernel_binary.h index 1a643959572..1625ce1048e 100644 --- a/runtime/vm/kernel_binary.h +++ b/runtime/vm/kernel_binary.h @@ -20,8 +20,8 @@ namespace kernel { static const uint32_t kMagicProgramFile = 0x90ABCDEFu; // Both version numbers are inclusive. -static const uint32_t kMinSupportedKernelFormatVersion = 48; -static const uint32_t kMaxSupportedKernelFormatVersion = 48; +static const uint32_t kMinSupportedKernelFormatVersion = 49; +static const uint32_t kMaxSupportedKernelFormatVersion = 49; // Keep in sync with package:kernel/lib/binary/tag.dart #define KERNEL_TAG_LIST(V) \ diff --git a/runtime/vm/kernel_loader.cc b/runtime/vm/kernel_loader.cc index 44b07a485a3..5b5ea0d44cf 100644 --- a/runtime/vm/kernel_loader.cc +++ b/runtime/vm/kernel_loader.cc @@ -1040,8 +1040,6 @@ LibraryPtr KernelLoader::LoadLibrary(intptr_t index) { Library& library = Library::Handle(Z, LookupLibrary(library_helper.canonical_name_)); - // The Kernel library is external implies that it is already loaded. - ASSERT(!library_helper.IsExternal() || library.Loaded()); if (library.Loaded()) return library.raw(); library.set_is_nnbd(library_helper.IsNonNullableByDefault());