[torque] allow nested namespaces

- Change the Torque parser to support nested namespaces. All the rest
  of Torque has already supported them for a long time.
- Use nested namespaces in ic-callable.tq and torque-internal.tq.

Bug: v8:7793
Change-Id: I869ce21e4a6aeb5951815815cbd4feedfcb312b3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2196127
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67750}
This commit is contained in:
Tobias Tebbi 2020-05-12 13:43:50 +02:00 committed by Commit Bot
parent d746a0347c
commit 75b30281de
4 changed files with 29 additions and 32 deletions

View File

@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
namespace ic_callable {
namespace ic {
namespace callable {
extern macro IncrementCallCount(FeedbackVector, uintptr): void;
@ -39,16 +40,14 @@ macro TryInitializeAsMonomorphic(implicit context: Context)(
goto TransitionToMegamorphic;
}
ic::StoreWeakReferenceInFeedbackVector(
feedbackVector, slotId, targetHeapObject);
ic::ReportFeedbackUpdate(feedbackVector, slotId, 'Call:Initialize');
StoreWeakReferenceInFeedbackVector(feedbackVector, slotId, targetHeapObject);
ReportFeedbackUpdate(feedbackVector, slotId, 'Call:Initialize');
}
macro TransitionToMegamorphic(implicit context: Context)(
feedbackVector: FeedbackVector, slotId: uintptr): void {
ic::StoreFeedbackVectorSlot(feedbackVector, slotId, ic::kMegamorphicSymbol);
ic::ReportFeedbackUpdate(
feedbackVector, slotId, 'Call:TransitionMegamorphic');
StoreFeedbackVectorSlot(feedbackVector, slotId, kMegamorphicSymbol);
ReportFeedbackUpdate(feedbackVector, slotId, 'Call:TransitionMegamorphic');
}
macro CollectCallFeedback(
@ -60,10 +59,10 @@ macro CollectCallFeedback(
try {
const feedback: MaybeObject =
ic::LoadFeedbackVectorSlot(feedbackVector, slotId);
LoadFeedbackVectorSlot(feedbackVector, slotId);
if (IsMonomorphic(feedback, maybeTarget)) return;
if (ic::IsMegamorphic(feedback)) return;
if (ic::IsUninitialized(feedback)) goto TryInitializeAsMonomorphic;
if (IsMegamorphic(feedback)) return;
if (IsUninitialized(feedback)) goto TryInitializeAsMonomorphic;
// If cleared, we have a new chance to become monomorphic.
const feedbackValue: HeapObject =
@ -85,9 +84,8 @@ macro CollectCallFeedback(
if (!TaggedEqual(feedbackCell, targetFeedbackCell))
goto TransitionToMegamorphic;
ic::StoreWeakReferenceInFeedbackVector(
feedbackVector, slotId, feedbackCell);
ic::ReportFeedbackUpdate(feedbackVector, slotId, 'Call:FeedbackVectorCell');
StoreWeakReferenceInFeedbackVector(feedbackVector, slotId, feedbackCell);
ReportFeedbackUpdate(feedbackVector, slotId, 'Call:FeedbackVectorCell');
} label TryInitializeAsMonomorphic {
TryInitializeAsMonomorphic(maybeTarget, feedbackVector, slotId)
otherwise TransitionToMegamorphic;
@ -105,10 +103,10 @@ macro CollectInstanceOfFeedback(
try {
const feedback: MaybeObject =
ic::LoadFeedbackVectorSlot(feedbackVector, slotId);
LoadFeedbackVectorSlot(feedbackVector, slotId);
if (IsMonomorphic(feedback, maybeTarget)) return;
if (ic::IsMegamorphic(feedback)) return;
if (ic::IsUninitialized(feedback)) goto TryInitializeAsMonomorphic;
if (IsMegamorphic(feedback)) return;
if (IsUninitialized(feedback)) goto TryInitializeAsMonomorphic;
// If cleared, we have a new chance to become monomorphic.
const _feedbackValue: HeapObject =
@ -123,4 +121,5 @@ macro CollectInstanceOfFeedback(
}
}
} // namespace ic_callable
} // namespace callable
} // namespace ic

View File

@ -10,7 +10,7 @@ namespace ic {
macro CollectCallFeedback(
maybeTarget: JSAny, context: Context,
maybeFeedbackVector: Undefined|FeedbackVector, slotId: uintptr): void {
ic_callable::CollectCallFeedback(
callable::CollectCallFeedback(
maybeTarget, context, maybeFeedbackVector, slotId);
}
@ -18,7 +18,7 @@ macro CollectCallFeedback(
macro CollectInstanceOfFeedback(
maybeTarget: JSAny, context: Context,
maybeFeedbackVector: Undefined|FeedbackVector, slotId: uintptr): void {
ic_callable::CollectInstanceOfFeedback(
callable::CollectInstanceOfFeedback(
maybeTarget, context, maybeFeedbackVector, slotId);
}

View File

@ -20,15 +20,17 @@ struct Reference<T: type> {
type ConstReference<T: type> extends Reference<T>;
type MutableReference<T: type> extends ConstReference<T>;
macro UnsafeNewReference<T: type>(object: HeapObject, offset: intptr):&T {
namespace unsafe {
macro NewReference<T: type>(object: HeapObject, offset: intptr):&T {
return %RawDownCast<&T>(
Reference<T>{object: object, offset: offset, unsafeMarker: Unsafe {}});
}
} // namespace unsafe
struct Slice<T: type> {
macro TryAtIndex(index: intptr):&T labels OutOfBounds {
if (Convert<uintptr>(index) < Convert<uintptr>(this.length)) {
return UnsafeNewReference<T>(
return unsafe::NewReference<T>(
this.object, this.offset + index * %SizeOf<T>());
} else {
goto OutOfBounds;
@ -105,7 +107,7 @@ struct SliceIterator<T: type> {
if (this.Empty()) {
goto NoMore;
} else {
const result = UnsafeNewReference<T>(this.object, this.start);
const result = unsafe::NewReference<T>(this.object, this.start);
this.start += %SizeOf<T>();
return result;
}
@ -174,14 +176,14 @@ extern macro StoreDoubleHole(HeapObject, intptr);
macro LoadFloat64OrHole(r:&float64_or_hole): float64_or_hole {
return float64_or_hole{
is_hole: IsDoubleHole(r.object, r.offset - kHeapObjectTag),
value: * UnsafeNewReference<float64>(r.object, r.offset)
value: * unsafe::NewReference<float64>(r.object, r.offset)
};
}
macro StoreFloat64OrHole(r:&float64_or_hole, value: float64_or_hole) {
if (value.is_hole) {
StoreDoubleHole(r.object, r.offset - kHeapObjectTag);
} else {
* UnsafeNewReference<float64>(r.object, r.offset) = value.value;
* unsafe::NewReference<float64>(r.object, r.offset) = value.value;
}
}
} // namespace torque_internal

View File

@ -2436,21 +2436,17 @@ struct TorqueGrammar : Grammar {
Sequence({Token("constexpr"), &externalString})),
Token("{"), NonemptyList<Identifier*>(&name, Token(",")),
CheckIf(Sequence({Token(","), Token("...")})), Token("}")},
MakeEnumDeclaration)};
MakeEnumDeclaration),
Rule({Token("namespace"), &identifier, Token("{"), &declarationList,
Token("}")},
AsSingletonVector<Declaration*, MakeNamespaceDeclaration>())};
// Result: std::vector<Declaration*>
Symbol declarationList = {
Rule({List<std::vector<Declaration*>>(&declaration)}, ConcatList)};
// Result: std::vector<Declaration*>
Symbol namespaceDeclaration = {
Rule({Token("namespace"), &identifier, Token("{"), &declarationList,
Token("}")},
AsSingletonVector<Declaration*, MakeNamespaceDeclaration>())};
Symbol file = {Rule({&file, Token("import"), &externalString},
ProcessTorqueImportDeclaration),
Rule({&file, &namespaceDeclaration}, AddGlobalDeclarations),
Rule({&file, &declaration}, AddGlobalDeclarations), Rule({})};
};