From 75b30281deefdf6e0060e447ae081407e5d26169 Mon Sep 17 00:00:00 2001 From: Tobias Tebbi Date: Tue, 12 May 2020 13:43:50 +0200 Subject: [PATCH] [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 Reviewed-by: Jakob Gruber Cr-Commit-Position: refs/heads/master@{#67750} --- src/builtins/ic-callable.tq | 33 ++++++++++++++++----------------- src/builtins/ic.tq | 4 ++-- src/builtins/torque-internal.tq | 12 +++++++----- src/torque/torque-parser.cc | 12 ++++-------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/builtins/ic-callable.tq b/src/builtins/ic-callable.tq index c93679d2cc..40dbc188e6 100644 --- a/src/builtins/ic-callable.tq +++ b/src/builtins/ic-callable.tq @@ -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 diff --git a/src/builtins/ic.tq b/src/builtins/ic.tq index 4b4e31ee6f..91b2db478f 100644 --- a/src/builtins/ic.tq +++ b/src/builtins/ic.tq @@ -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); } diff --git a/src/builtins/torque-internal.tq b/src/builtins/torque-internal.tq index ad804d4c1c..d2b107f932 100644 --- a/src/builtins/torque-internal.tq +++ b/src/builtins/torque-internal.tq @@ -20,15 +20,17 @@ struct Reference { type ConstReference extends Reference; type MutableReference extends ConstReference; -macro UnsafeNewReference(object: HeapObject, offset: intptr):&T { +namespace unsafe { +macro NewReference(object: HeapObject, offset: intptr):&T { return %RawDownCast<&T>( Reference{object: object, offset: offset, unsafeMarker: Unsafe {}}); } +} // namespace unsafe struct Slice { macro TryAtIndex(index: intptr):&T labels OutOfBounds { if (Convert(index) < Convert(this.length)) { - return UnsafeNewReference( + return unsafe::NewReference( this.object, this.offset + index * %SizeOf()); } else { goto OutOfBounds; @@ -105,7 +107,7 @@ struct SliceIterator { if (this.Empty()) { goto NoMore; } else { - const result = UnsafeNewReference(this.object, this.start); + const result = unsafe::NewReference(this.object, this.start); this.start += %SizeOf(); 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(r.object, r.offset) + value: * unsafe::NewReference(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(r.object, r.offset) = value.value; + * unsafe::NewReference(r.object, r.offset) = value.value; } } } // namespace torque_internal diff --git a/src/torque/torque-parser.cc b/src/torque/torque-parser.cc index b13c605629..fa496ae6a0 100644 --- a/src/torque/torque-parser.cc +++ b/src/torque/torque-parser.cc @@ -2436,21 +2436,17 @@ struct TorqueGrammar : Grammar { Sequence({Token("constexpr"), &externalString})), Token("{"), NonemptyList(&name, Token(",")), CheckIf(Sequence({Token(","), Token("...")})), Token("}")}, - MakeEnumDeclaration)}; + MakeEnumDeclaration), + Rule({Token("namespace"), &identifier, Token("{"), &declarationList, + Token("}")}, + AsSingletonVector())}; // Result: std::vector Symbol declarationList = { Rule({List>(&declaration)}, ConcatList)}; - // Result: std::vector - Symbol namespaceDeclaration = { - Rule({Token("namespace"), &identifier, Token("{"), &declarationList, - Token("}")}, - AsSingletonVector())}; - Symbol file = {Rule({&file, Token("import"), &externalString}, ProcessTorqueImportDeclaration), - Rule({&file, &namespaceDeclaration}, AddGlobalDeclarations), Rule({&file, &declaration}, AddGlobalDeclarations), Rule({})}; };