[regexp] Clean up js-regexp.h

Update outdated comments and address TODO about kDataIndex.

Change-Id: Ibf6e91857c0430cb9a598c98933db63ac42a1d1f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3189197
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Patrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77123}
This commit is contained in:
Jakob Gruber 2021-09-28 16:44:19 +02:00 committed by V8 LUCI CQ
parent 4b53234311
commit c872728c5d
2 changed files with 57 additions and 63 deletions

View File

@ -86,8 +86,8 @@ Object JSRegExp::DataAt(int index) const {
void JSRegExp::SetDataAt(int index, Object value) {
DCHECK(TypeTag() != NOT_COMPILED);
DCHECK_GE(index,
kDataIndex); // Only implementation data can be set this way.
// Only implementation data can be set this way.
DCHECK_GE(index, kFirstTypeSpecificIndex);
FixedArray::cast(data()).set(index, value);
}

View File

@ -104,7 +104,7 @@ class JSRegExp : public TorqueGeneratedJSRegExp<JSRegExp, JSObject> {
void MarkTierUpForNextExec();
inline Type TypeTag() const;
static bool TypeSupportsCaptures(Type t) {
static constexpr bool TypeSupportsCaptures(Type t) {
return t == IRREGEXP || t == EXPERIMENTAL;
}
@ -114,7 +114,9 @@ class JSRegExp : public TorqueGeneratedJSRegExp<JSRegExp, JSObject> {
// Number of captures (without the match itself).
inline int CaptureCount() const;
// Each capture (including the match itself) needs two registers.
static int RegistersForCaptureCount(int count) { return (count + 1) * 2; }
static constexpr int RegistersForCaptureCount(int count) {
return (count + 1) * 2;
}
inline int MaxRegisterCount() const;
inline Flags GetFlags() const;
@ -158,59 +160,49 @@ class JSRegExp : public TorqueGeneratedJSRegExp<JSRegExp, JSObject> {
static constexpr int kInitialLastIndexValue = 0;
// Indices in the data array.
static const int kTagIndex = 0;
static const int kSourceIndex = kTagIndex + 1;
static const int kFlagsIndex = kSourceIndex + 1;
static const int kDataIndex = kFlagsIndex + 1;
// TODO(jgruber): Rename kDataIndex to something more appropriate.
// There is no 'data' field, kDataIndex is just a marker for the
// first non-generic index.
static constexpr int kMinDataArrayLength = kDataIndex;
static constexpr int kTagIndex = 0;
static constexpr int kSourceIndex = kTagIndex + 1;
static constexpr int kFlagsIndex = kSourceIndex + 1;
static constexpr int kFirstTypeSpecificIndex = kFlagsIndex + 1;
static constexpr int kMinDataArrayLength = kFirstTypeSpecificIndex;
// The data fields are used in different ways depending on the
// value of the tag.
// Atom regexps (literal strings).
static const int kAtomPatternIndex = kDataIndex;
static constexpr int kAtomPatternIndex = kFirstTypeSpecificIndex;
static constexpr int kAtomDataSize = kAtomPatternIndex + 1;
static const int kAtomDataSize = kAtomPatternIndex + 1;
// Irregexp compiled code or trampoline to interpreter for Latin1. If
// compilation fails, this fields hold an exception object that should be
// thrown if the regexp is used again.
static const int kIrregexpLatin1CodeIndex = kDataIndex;
// Irregexp compiled code or trampoline to interpreter for UC16. If
// compilation fails, this fields hold an exception object that should be
// thrown if the regexp is used again.
static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
// Bytecode to interpret the regexp for Latin1. Contains kUninitializedValue
// if we haven't compiled the regexp yet, regexp are always compiled or if
// tier-up has happened (i.e. when kIrregexpLatin1CodeIndex contains native
// irregexp code).
static const int kIrregexpLatin1BytecodeIndex = kDataIndex + 2;
// Bytecode to interpret the regexp for UC16. Contains kUninitializedValue if
// we haven't compiled the regxp yet, regexp are always compiled or if tier-up
// has happened (i.e. when kIrregexpUC16CodeIndex contains native irregexp
// code).
static const int kIrregexpUC16BytecodeIndex = kDataIndex + 3;
// A Code object or a Smi marker value equal to kUninitializedValue.
static constexpr int kIrregexpLatin1CodeIndex = kFirstTypeSpecificIndex;
static constexpr int kIrregexpUC16CodeIndex = kIrregexpLatin1CodeIndex + 1;
// A ByteArray object or a Smi marker value equal to kUninitializedValue.
static constexpr int kIrregexpLatin1BytecodeIndex =
kIrregexpUC16CodeIndex + 1;
static constexpr int kIrregexpUC16BytecodeIndex =
kIrregexpLatin1BytecodeIndex + 1;
// Maximal number of registers used by either Latin1 or UC16.
// Only used to check that there is enough stack space
static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4;
static constexpr int kIrregexpMaxRegisterCountIndex =
kIrregexpUC16BytecodeIndex + 1;
// Number of captures in the compiled regexp.
static const int kIrregexpCaptureCountIndex = kDataIndex + 5;
static constexpr int kIrregexpCaptureCountIndex =
kIrregexpMaxRegisterCountIndex + 1;
// Maps names of named capture groups (at indices 2i) to their corresponding
// (1-based) capture group indices (at indices 2i + 1).
static const int kIrregexpCaptureNameMapIndex = kDataIndex + 6;
static constexpr int kIrregexpCaptureNameMapIndex =
kIrregexpCaptureCountIndex + 1;
// Tier-up ticks are set to the value of the tier-up ticks flag. The value is
// decremented on each execution of the bytecode, so that the tier-up
// happens once the ticks reach zero.
// This value is ignored if the regexp-tier-up flag isn't turned on.
static const int kIrregexpTicksUntilTierUpIndex = kDataIndex + 7;
static constexpr int kIrregexpTicksUntilTierUpIndex =
kIrregexpCaptureNameMapIndex + 1;
// A smi containing either the backtracking limit or kNoBacktrackLimit.
// TODO(jgruber): If needed, this limit could be packed into other fields
// above to save space.
static const int kIrregexpBacktrackLimit = kDataIndex + 8;
static const int kIrregexpDataSize = kDataIndex + 9;
static constexpr int kIrregexpBacktrackLimit =
kIrregexpTicksUntilTierUpIndex + 1;
static constexpr int kIrregexpDataSize = kIrregexpBacktrackLimit + 1;
// TODO(mbid,v8:10765): At the moment the EXPERIMENTAL data array conforms
// to the format of an IRREGEXP data array, with most fields set to some
@ -222,22 +214,24 @@ class JSRegExp : public TorqueGeneratedJSRegExp<JSRegExp, JSObject> {
static constexpr int kExperimentalDataSize = kIrregexpDataSize;
// In-object fields.
static const int kLastIndexFieldIndex = 0;
static const int kInObjectFieldCount = 1;
static constexpr int kLastIndexFieldIndex = 0;
static constexpr int kInObjectFieldCount = 1;
// The actual object size including in-object fields.
static int Size() { return kHeaderSize + kInObjectFieldCount * kTaggedSize; }
static constexpr int Size() {
return kHeaderSize + kInObjectFieldCount * kTaggedSize;
}
// Descriptor array index to important methods in the prototype.
static const int kExecFunctionDescriptorIndex = 1;
static const int kSymbolMatchFunctionDescriptorIndex = 14;
static const int kSymbolMatchAllFunctionDescriptorIndex = 15;
static const int kSymbolReplaceFunctionDescriptorIndex = 16;
static const int kSymbolSearchFunctionDescriptorIndex = 17;
static const int kSymbolSplitFunctionDescriptorIndex = 18;
static constexpr int kExecFunctionDescriptorIndex = 1;
static constexpr int kSymbolMatchFunctionDescriptorIndex = 14;
static constexpr int kSymbolMatchAllFunctionDescriptorIndex = 15;
static constexpr int kSymbolReplaceFunctionDescriptorIndex = 16;
static constexpr int kSymbolSearchFunctionDescriptorIndex = 17;
static constexpr int kSymbolSplitFunctionDescriptorIndex = 18;
// The uninitialized value for a regexp code object.
static const int kUninitializedValue = -1;
static constexpr int kUninitializedValue = -1;
// The heuristic value for the length of the subject string for which we
// tier-up to the compiler immediately, instead of using the interpreter.
@ -262,17 +256,17 @@ class JSRegExpResult
// instance type as JSArray.
// Indices of in-object properties.
static const int kIndexIndex = 0;
static const int kInputIndex = 1;
static const int kGroupsIndex = 2;
static constexpr int kIndexIndex = 0;
static constexpr int kInputIndex = 1;
static constexpr int kGroupsIndex = 2;
// Private internal only fields.
static const int kNamesIndex = 3;
static const int kRegExpInputIndex = 4;
static const int kRegExpLastIndex = 5;
static const int kInObjectPropertyCount = 6;
static constexpr int kNamesIndex = 3;
static constexpr int kRegExpInputIndex = 4;
static constexpr int kRegExpLastIndex = 5;
static constexpr int kInObjectPropertyCount = 6;
static const int kMapIndexInContext = Context::REGEXP_RESULT_MAP_INDEX;
static constexpr int kMapIndexInContext = Context::REGEXP_RESULT_MAP_INDEX;
TQ_OBJECT_CONSTRUCTORS(JSRegExpResult)
};
@ -284,8 +278,8 @@ class JSRegExpResultWithIndices
static_assert(
JSRegExpResult::kInObjectPropertyCount == 6,
"JSRegExpResultWithIndices must be a subclass of JSRegExpResult");
static const int kIndicesIndex = 6;
static const int kInObjectPropertyCount = 7;
static constexpr int kIndicesIndex = 6;
static constexpr int kInObjectPropertyCount = 7;
TQ_OBJECT_CONSTRUCTORS(JSRegExpResultWithIndices)
};
@ -305,11 +299,11 @@ class JSRegExpResultIndices
Handle<Object> maybe_names);
// Indices of in-object properties.
static const int kGroupsIndex = 0;
static const int kInObjectPropertyCount = 1;
static constexpr int kGroupsIndex = 0;
static constexpr int kInObjectPropertyCount = 1;
// Descriptor index of groups.
static const int kGroupsDescriptorIndex = 1;
static constexpr int kGroupsDescriptorIndex = 1;
TQ_OBJECT_CONSTRUCTORS(JSRegExpResultIndices)
};