Skip to content

Commit 0cabc6a

Browse files
backesCommit Bot
authored andcommitted
Reland "[utils] Make BitField final"
This is a reland of 658ff20 Original change's description: > [utils] Make BitField final > > We have hundreds of classes that derive from {BitField} without adding > any functionality. This CL switches all such occurrences to 'using' > declarations instead. > > Before: > class MyBitField : public BitField<int, 6, 4, MyEnum> {}; > After: > using MyBitField = BitField<int, 6, 4, MyEnum>; > > This might reduce compilation time by reducing the number of existing > classes. > > The old pattern is forbidden now by making {BitField} final. > > R=yangguo@chromium.org > > Bug: v8:9396, v8:7629 > Change-Id: I8a8364707e8eae0bb522af2459c160e3293eecbb > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1722565 > Reviewed-by: Yang Guo <yangguo@chromium.org> > Commit-Queue: Clemens Hammacher <clemensh@chromium.org> > Cr-Commit-Position: refs/heads/master@{#62956} Bug: v8:9396, v8:7629 Change-Id: Ic68541af9d1e8d0340691970922f282b24a9767f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1724379 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#62959}
1 parent 753a07d commit 0cabc6a

36 files changed

Lines changed: 274 additions & 318 deletions

src/ast/ast.h

Lines changed: 61 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class AstNode: public ZoneObject {
168168
void* operator new(size_t size);
169169

170170
int position_;
171-
class NodeTypeField : public BitField<NodeType, 0, 6> {};
171+
using NodeTypeField = BitField<NodeType, 0, 6>;
172172

173173
protected:
174174
uint32_t bit_field_;
@@ -265,8 +265,7 @@ class Expression : public AstNode {
265265
}
266266

267267
private:
268-
class IsParenthesizedField
269-
: public BitField<bool, AstNode::kNextBitFieldIndex, 1> {};
268+
using IsParenthesizedField = BitField<bool, AstNode::kNextBitFieldIndex, 1>;
270269

271270
protected:
272271
Expression(int pos, NodeType type) : AstNode(pos, type) {
@@ -321,8 +320,8 @@ class BreakableStatement : public Statement {
321320
}
322321

323322
private:
324-
class BreakableTypeField
325-
: public BitField<BreakableType, Statement::kNextBitFieldIndex, 1> {};
323+
using BreakableTypeField =
324+
BitField<BreakableType, Statement::kNextBitFieldIndex, 1>;
326325

327326
protected:
328327
BreakableStatement(BreakableType breakable_type, int position, NodeType type)
@@ -357,10 +356,9 @@ class Block : public BreakableStatement {
357356
ZonePtrList<Statement> statements_;
358357
Scope* scope_;
359358

360-
class IgnoreCompletionField
361-
: public BitField<bool, BreakableStatement::kNextBitFieldIndex, 1> {};
362-
class IsLabeledField
363-
: public BitField<bool, IgnoreCompletionField::kNext, 1> {};
359+
using IgnoreCompletionField =
360+
BitField<bool, BreakableStatement::kNextBitFieldIndex, 1>;
361+
using IsLabeledField = BitField<bool, IgnoreCompletionField::kNext, 1>;
364362

365363
protected:
366364
Block(Zone* zone, ZonePtrList<const AstRawString>* labels, int capacity,
@@ -448,8 +446,7 @@ class VariableDeclaration : public Declaration {
448446
private:
449447
friend class AstNodeFactory;
450448

451-
class IsNestedField
452-
: public BitField<bool, Declaration::kNextBitFieldIndex, 1> {};
449+
using IsNestedField = BitField<bool, Declaration::kNextBitFieldIndex, 1>;
453450

454451
protected:
455452
explicit VariableDeclaration(int pos, bool is_nested = false)
@@ -740,8 +737,7 @@ class ReturnStatement final : public JumpStatement {
740737
Expression* expression_;
741738
int end_position_;
742739

743-
class TypeField
744-
: public BitField<Type, JumpStatement::kNextBitFieldIndex, 1> {};
740+
using TypeField = BitField<Type, JumpStatement::kNextBitFieldIndex, 1>;
745741
};
746742

747743

@@ -977,8 +973,7 @@ class SloppyBlockFunctionStatement final : public Statement {
977973
private:
978974
friend class AstNodeFactory;
979975

980-
class TokenField
981-
: public BitField<Token::Value, Statement::kNextBitFieldIndex, 8> {};
976+
using TokenField = BitField<Token::Value, Statement::kNextBitFieldIndex, 8>;
982977

983978
SloppyBlockFunctionStatement(int pos, Variable* var, Token::Value init,
984979
Statement* statement)
@@ -1079,7 +1074,7 @@ class Literal final : public Expression {
10791074
private:
10801075
friend class AstNodeFactory;
10811076

1082-
class TypeField : public BitField<Type, Expression::kNextBitFieldIndex, 4> {};
1077+
using TypeField = BitField<Type, Expression::kNextBitFieldIndex, 4>;
10831078

10841079
Literal(int smi, int position) : Expression(position, kLiteral), smi_(smi) {
10851080
bit_field_ = TypeField::update(bit_field_, kSmi);
@@ -1210,10 +1205,10 @@ class AggregateLiteral : public MaterializedLiteral {
12101205

12111206
private:
12121207
int depth_ : 31;
1213-
class NeedsInitialAllocationSiteField
1214-
: public BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1> {};
1215-
class IsSimpleField
1216-
: public BitField<bool, NeedsInitialAllocationSiteField::kNext, 1> {};
1208+
using NeedsInitialAllocationSiteField =
1209+
BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1>;
1210+
using IsSimpleField =
1211+
BitField<bool, NeedsInitialAllocationSiteField::kNext, 1>;
12171212

12181213
protected:
12191214
friend class AstNodeFactory;
@@ -1413,14 +1408,11 @@ class ObjectLiteral final : public AggregateLiteral {
14131408
Handle<ObjectBoilerplateDescription> boilerplate_description_;
14141409
ZoneList<Property*> properties_;
14151410

1416-
class HasElementsField
1417-
: public BitField<bool, AggregateLiteral::kNextBitFieldIndex, 1> {};
1418-
class HasRestPropertyField
1419-
: public BitField<bool, HasElementsField::kNext, 1> {};
1420-
class FastElementsField
1421-
: public BitField<bool, HasRestPropertyField::kNext, 1> {};
1422-
class HasNullPrototypeField
1423-
: public BitField<bool, FastElementsField::kNext, 1> {};
1411+
using HasElementsField =
1412+
BitField<bool, AggregateLiteral::kNextBitFieldIndex, 1>;
1413+
using HasRestPropertyField = BitField<bool, HasElementsField::kNext, 1>;
1414+
using FastElementsField = BitField<bool, HasRestPropertyField::kNext, 1>;
1415+
using HasNullPrototypeField = BitField<bool, FastElementsField::kNext, 1>;
14241416
};
14251417

14261418
// An array literal has a literals object that is used
@@ -1586,15 +1578,14 @@ class VariableProxy final : public Expression {
15861578

15871579
explicit VariableProxy(const VariableProxy* copy_from);
15881580

1589-
class IsAssignedField
1590-
: public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
1591-
class IsResolvedField : public BitField<bool, IsAssignedField::kNext, 1> {};
1592-
class IsRemovedFromUnresolvedField
1593-
: public BitField<bool, IsResolvedField::kNext, 1> {};
1594-
class IsNewTargetField
1595-
: public BitField<bool, IsRemovedFromUnresolvedField::kNext, 1> {};
1596-
class HoleCheckModeField
1597-
: public BitField<HoleCheckMode, IsNewTargetField::kNext, 1> {};
1581+
using IsAssignedField = BitField<bool, Expression::kNextBitFieldIndex, 1>;
1582+
using IsResolvedField = BitField<bool, IsAssignedField::kNext, 1>;
1583+
using IsRemovedFromUnresolvedField =
1584+
BitField<bool, IsResolvedField::kNext, 1>;
1585+
using IsNewTargetField =
1586+
BitField<bool, IsRemovedFromUnresolvedField::kNext, 1>;
1587+
using HoleCheckModeField =
1588+
BitField<HoleCheckMode, IsNewTargetField::kNext, 1>;
15981589

15991590
union {
16001591
const AstRawString* raw_name_; // if !is_resolved_
@@ -1743,10 +1734,8 @@ class Call final : public Expression {
17431734
arguments.CopyTo(&arguments_, zone);
17441735
}
17451736

1746-
class IsPossiblyEvalField
1747-
: public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
1748-
class IsTaggedTemplateField
1749-
: public BitField<bool, IsPossiblyEvalField::kNext, 1> {};
1737+
using IsPossiblyEvalField = BitField<bool, Expression::kNextBitFieldIndex, 1>;
1738+
using IsTaggedTemplateField = BitField<bool, IsPossiblyEvalField::kNext, 1>;
17501739

17511740
Expression* expression_;
17521741
ZonePtrList<Expression> arguments_;
@@ -1838,8 +1827,8 @@ class UnaryOperation final : public Expression {
18381827

18391828
Expression* expression_;
18401829

1841-
class OperatorField
1842-
: public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
1830+
using OperatorField =
1831+
BitField<Token::Value, Expression::kNextBitFieldIndex, 7>;
18431832
};
18441833

18451834

@@ -1865,8 +1854,8 @@ class BinaryOperation final : public Expression {
18651854
Expression* left_;
18661855
Expression* right_;
18671856

1868-
class OperatorField
1869-
: public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
1857+
using OperatorField =
1858+
BitField<Token::Value, Expression::kNextBitFieldIndex, 7>;
18701859
};
18711860

18721861
class NaryOperation final : public Expression {
@@ -1925,8 +1914,8 @@ class NaryOperation final : public Expression {
19251914
};
19261915
ZoneVector<NaryOperationEntry> subsequent_;
19271916

1928-
class OperatorField
1929-
: public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
1917+
using OperatorField =
1918+
BitField<Token::Value, Expression::kNextBitFieldIndex, 7>;
19301919
};
19311920

19321921
class CountOperation final : public Expression {
@@ -1946,9 +1935,8 @@ class CountOperation final : public Expression {
19461935
bit_field_ |= IsPrefixField::encode(is_prefix) | TokenField::encode(op);
19471936
}
19481937

1949-
class IsPrefixField
1950-
: public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
1951-
class TokenField : public BitField<Token::Value, IsPrefixField::kNext, 7> {};
1938+
using IsPrefixField = BitField<bool, Expression::kNextBitFieldIndex, 1>;
1939+
using TokenField = BitField<Token::Value, IsPrefixField::kNext, 7>;
19521940

19531941
Expression* expression_;
19541942
};
@@ -1978,8 +1966,8 @@ class CompareOperation final : public Expression {
19781966
Expression* left_;
19791967
Expression* right_;
19801968

1981-
class OperatorField
1982-
: public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
1969+
using OperatorField =
1970+
BitField<Token::Value, Expression::kNextBitFieldIndex, 7>;
19831971
};
19841972

19851973

@@ -2071,10 +2059,8 @@ class Assignment : public Expression {
20712059
private:
20722060
friend class AstNodeFactory;
20732061

2074-
class TokenField
2075-
: public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
2076-
class LookupHoistingModeField : public BitField<bool, TokenField::kNext, 1> {
2077-
};
2062+
using TokenField = BitField<Token::Value, Expression::kNextBitFieldIndex, 7>;
2063+
using LookupHoistingModeField = BitField<bool, TokenField::kNext, 1>;
20782064

20792065
Expression* target_;
20802066
Expression* value_;
@@ -2132,8 +2118,8 @@ class Suspend : public Expression {
21322118

21332119
Expression* expression_;
21342120

2135-
class OnAbruptResumeField
2136-
: public BitField<OnAbruptResume, Expression::kNextBitFieldIndex, 1> {};
2121+
using OnAbruptResumeField =
2122+
BitField<OnAbruptResume, Expression::kNextBitFieldIndex, 1>;
21372123
};
21382124

21392125
class Yield final : public Suspend {
@@ -2370,17 +2356,17 @@ class FunctionLiteral final : public Expression {
23702356
body.CopyTo(&body_, zone);
23712357
}
23722358

2373-
class FunctionTypeBits
2374-
: public BitField<FunctionType, Expression::kNextBitFieldIndex, 3> {};
2375-
class Pretenure : public BitField<bool, FunctionTypeBits::kNext, 1> {};
2376-
class HasDuplicateParameters : public BitField<bool, Pretenure::kNext, 1> {};
2377-
class DontOptimizeReasonField
2378-
: public BitField<BailoutReason, HasDuplicateParameters::kNext, 8> {};
2379-
class RequiresInstanceMembersInitializer
2380-
: public BitField<bool, DontOptimizeReasonField::kNext, 1> {};
2381-
class HasBracesField
2382-
: public BitField<bool, RequiresInstanceMembersInitializer::kNext, 1> {};
2383-
class OneshotIIFEBit : public BitField<bool, HasBracesField::kNext, 1> {};
2359+
using FunctionTypeBits =
2360+
BitField<FunctionType, Expression::kNextBitFieldIndex, 3>;
2361+
using Pretenure = BitField<bool, FunctionTypeBits::kNext, 1>;
2362+
using HasDuplicateParameters = BitField<bool, Pretenure::kNext, 1>;
2363+
using DontOptimizeReasonField =
2364+
BitField<BailoutReason, HasDuplicateParameters::kNext, 8>;
2365+
using RequiresInstanceMembersInitializer =
2366+
BitField<bool, DontOptimizeReasonField::kNext, 1>;
2367+
using HasBracesField =
2368+
BitField<bool, RequiresInstanceMembersInitializer::kNext, 1>;
2369+
using OneshotIIFEBit = BitField<bool, HasBracesField::kNext, 1>;
23842370

23852371
// expected_property_count_ is the sum of instance fields and properties.
23862372
// It can vary depending on whether a function is lazily or eagerly parsed.
@@ -2525,12 +2511,12 @@ class ClassLiteral final : public Expression {
25252511
ZonePtrList<Property>* properties_;
25262512
FunctionLiteral* static_fields_initializer_;
25272513
FunctionLiteral* instance_members_initializer_function_;
2528-
class HasNameStaticProperty
2529-
: public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
2530-
class HasStaticComputedNames
2531-
: public BitField<bool, HasNameStaticProperty::kNext, 1> {};
2532-
class IsAnonymousExpression
2533-
: public BitField<bool, HasStaticComputedNames::kNext, 1> {};
2514+
using HasNameStaticProperty =
2515+
BitField<bool, Expression::kNextBitFieldIndex, 1>;
2516+
using HasStaticComputedNames =
2517+
BitField<bool, HasNameStaticProperty::kNext, 1>;
2518+
using IsAnonymousExpression =
2519+
BitField<bool, HasStaticComputedNames::kNext, 1>;
25342520
};
25352521

25362522

src/ast/variables.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -243,25 +243,21 @@ class Variable final : public ZoneObject {
243243
bit_field_ = MaybeAssignedFlagField::update(bit_field_, kMaybeAssigned);
244244
}
245245

246-
class VariableModeField : public BitField16<VariableMode, 0, 3> {};
247-
class VariableKindField
248-
: public BitField16<VariableKind, VariableModeField::kNext, 3> {};
249-
class LocationField
250-
: public BitField16<VariableLocation, VariableKindField::kNext, 3> {};
251-
class ForceContextAllocationField
252-
: public BitField16<bool, LocationField::kNext, 1> {};
253-
class IsUsedField
254-
: public BitField16<bool, ForceContextAllocationField::kNext, 1> {};
255-
class InitializationFlagField
256-
: public BitField16<InitializationFlag, IsUsedField::kNext, 1> {};
257-
class ForceHoleInitializationField
258-
: public BitField16<bool, InitializationFlagField::kNext, 1> {};
259-
class MaybeAssignedFlagField
260-
: public BitField16<MaybeAssignedFlag,
261-
ForceHoleInitializationField::kNext, 1> {};
262-
class RequiresBrandCheckField
263-
: public BitField16<RequiresBrandCheckFlag, MaybeAssignedFlagField::kNext,
264-
1> {};
246+
using VariableModeField = BitField16<VariableMode, 0, 3>;
247+
using VariableKindField =
248+
BitField16<VariableKind, VariableModeField::kNext, 3>;
249+
using LocationField =
250+
BitField16<VariableLocation, VariableKindField::kNext, 3>;
251+
using ForceContextAllocationField = BitField16<bool, LocationField::kNext, 1>;
252+
using IsUsedField = BitField16<bool, ForceContextAllocationField::kNext, 1>;
253+
using InitializationFlagField =
254+
BitField16<InitializationFlag, IsUsedField::kNext, 1>;
255+
using ForceHoleInitializationField =
256+
BitField16<bool, InitializationFlagField::kNext, 1>;
257+
using MaybeAssignedFlagField =
258+
BitField16<MaybeAssignedFlag, ForceHoleInitializationField::kNext, 1>;
259+
using RequiresBrandCheckField =
260+
BitField16<RequiresBrandCheckFlag, MaybeAssignedFlagField::kNext, 1>;
265261
Variable** next() { return &next_; }
266262
friend List;
267263
friend base::ThreadedListTraits<Variable>;

src/builtins/builtins-array.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,10 @@ class ArrayConcatVisitor {
782782
storage_ = isolate_->global_handles()->Create(storage);
783783
}
784784

785-
class FastElementsField : public BitField<bool, 0, 1> {};
786-
class ExceedsLimitField : public BitField<bool, 1, 1> {};
787-
class IsFixedArrayField : public BitField<bool, 2, 1> {};
788-
class HasSimpleElementsField : public BitField<bool, 3, 1> {};
785+
using FastElementsField = BitField<bool, 0, 1>;
786+
using ExceedsLimitField = BitField<bool, 1, 1>;
787+
using IsFixedArrayField = BitField<bool, 2, 1>;
788+
using HasSimpleElementsField = BitField<bool, 3, 1>;
789789

790790
bool fast_elements() const { return FastElementsField::decode(bit_field_); }
791791
void set_fast_elements(bool fast) {

src/codegen/handler-table.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ class V8_EXPORT_PRIVATE HandlerTable {
129129
static const int kReturnEntrySize = 2;
130130

131131
// Encoding of the {handler} field.
132-
class HandlerPredictionField : public BitField<CatchPrediction, 0, 3> {};
133-
class HandlerOffsetField : public BitField<int, 3, 29> {};
132+
using HandlerPredictionField = BitField<CatchPrediction, 0, 3>;
133+
using HandlerOffsetField = BitField<int, 3, 29>;
134134
};
135135

136136
} // namespace internal

src/codegen/ia32/assembler-ia32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ class Displacement {
342342
private:
343343
int data_;
344344

345-
class TypeField : public BitField<Type, 0, 2> {};
346-
class NextField : public BitField<int, 2, 32 - 2> {};
345+
using TypeField = BitField<Type, 0, 2>;
346+
using NextField = BitField<int, 2, 32 - 2>;
347347

348348
void init(Label* L, Type type);
349349
};

src/codegen/source-position-table.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ namespace internal {
2727
namespace {
2828

2929
// Each byte is encoded as MoreBit | ValueBits.
30-
class MoreBit : public BitField8<bool, 7, 1> {};
31-
class ValueBits : public BitField8<unsigned, 0, 7> {};
30+
using MoreBit = BitField8<bool, 7, 1>;
31+
using ValueBits = BitField8<unsigned, 0, 7>;
3232

3333
// Helper: Add the offsets from 'other' to 'value'. Also set is_statement.
3434
void AddAndSetEntry(PositionTableEntry& value, // NOLINT(runtime/references)

0 commit comments

Comments
 (0)