Commit 1d6d89d0 authored by Daniel Clifford's avatar Daniel Clifford Committed by Commit Bot

[torque]: Fix sharing of re-opened namespaces

In the process, create a shared array utility GetLengthProperty that fast-paths
accessing the length properties of JSArray.

Bug: v8:7793
Change-Id: I6d7f0007c162794773dc0fc3e8bf12b3adf12fa0
Reviewed-on: https://chromium-review.googlesource.com/1116221
Commit-Queue: Daniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54133}
parent d683fd7d
......@@ -137,8 +137,7 @@ module array {
let o: Object = ToObject(context, receiver);
// 2. Let len be ? ToLength(? Get(O, "length")).
let len: Number =
ToLength_Inline(context, GetProperty(context, o, 'length'));
let len: Number = GetLengthProperty(context, o);
// 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (arguments.length == 0) {
......
......@@ -568,8 +568,7 @@ module array {
}
label slow {
// 3. Let len be ? ToLength(? Get(obj, "length")).
let len: Number =
ToLength_Inline(context, GetProperty(context, obj, 'length'));
let len: Number = GetLengthProperty(context, obj);
if (len < 2) return receiver;
let nofNonUndefined: Smi = PrepareElementsForSort(context, obj, len);
......
......@@ -3,6 +3,16 @@
// found in the LICENSE file.
module array {
macro GetLengthProperty(context: Context, o: Object): Number {
if (BranchIfFastJSArray(o, context)) {
let a: JSArray = unsafe_cast<JSArray>(o);
return a.length_fast;
} else
deferred {
return ToLength_Inline(context, GetProperty(context, o, 'length'));
}
}
macro FastArraySplice(
context: Context, args: constexpr Arguments, o: Object,
originalLengthNumber: Number, actualStartNumber: Number, insertCount: Smi,
......@@ -103,8 +113,7 @@ module array {
let o: Object = ToObject(context, receiver);
// 2. Let len be ? ToLength(? Get(O, "length")).
let len: Number =
ToLength_Inline(context, GetProperty(context, o, 'length'));
let len: Number = GetLengthProperty(context, o);
// 3. Let relativeStart be ? ToInteger(start).
let start: Object = arguments[0];
......
......@@ -26,7 +26,7 @@ type Code extends AbstractCode generates 'TNode<Code>';
type JSReceiver extends HeapObject generates 'TNode<JSReceiver>';
type Context extends HeapObject generates 'TNode<Context>';
type String extends HeapObject generates
'TNode<String>' constexpr 'const char*';
'TNode<String>' constexpr 'const char*';
type Oddball extends HeapObject generates 'TNode<Oddball>';
type HeapNumber extends HeapObject generates 'TNode<HeapNumber>';
type Number = Smi|HeapNumber;
......@@ -69,16 +69,16 @@ type HasPropertyLookupMode constexpr 'HasPropertyLookupMode';
const NO_ELEMENTS: constexpr ElementsKind generates 'NO_ELEMENTS';
const PACKED_SMI_ELEMENTS: constexpr ElementsKind generates
'PACKED_SMI_ELEMENTS';
'PACKED_SMI_ELEMENTS';
const HOLEY_SMI_ELEMENTS: constexpr ElementsKind generates 'HOLEY_SMI_ELEMENTS';
const PACKED_ELEMENTS: constexpr ElementsKind generates 'PACKED_ELEMENTS';
const HOLEY_ELEMENTS: constexpr ElementsKind generates 'HOLEY_ELEMENTS';
const PACKED_DOUBLE_ELEMENTS: constexpr ElementsKind generates
'PACKED_DOUBLE_ELEMENTS';
'PACKED_DOUBLE_ELEMENTS';
const HOLEY_DOUBLE_ELEMENTS: constexpr ElementsKind generates
'HOLEY_DOUBLE_ELEMENTS';
'HOLEY_DOUBLE_ELEMENTS';
const DICTIONARY_ELEMENTS: constexpr ElementsKind generates
'DICTIONARY_ELEMENTS';
'DICTIONARY_ELEMENTS';
const UINT8_ELEMENTS: constexpr ElementsKind generates 'UINT8_ELEMENTS';
const INT8_ELEMENTS: constexpr ElementsKind generates 'INT8_ELEMENTS';
......@@ -89,7 +89,7 @@ const INT32_ELEMENTS: constexpr ElementsKind generates 'INT32_ELEMENTS';
const FLOAT32_ELEMENTS: constexpr ElementsKind generates 'FLOAT32_ELEMENTS';
const FLOAT64_ELEMENTS: constexpr ElementsKind generates 'FLOAT64_ELEMENTS';
const UINT8_CLAMPED_ELEMENTS: constexpr ElementsKind generates
'UINT8_CLAMPED_ELEMENTS';
'UINT8_CLAMPED_ELEMENTS';
const BIGUINT64_ELEMENTS: constexpr ElementsKind generates 'BIGUINT64_ELEMENTS';
const BIGINT64_ELEMENTS: constexpr ElementsKind generates 'BIGINT64_ELEMENTS';
......@@ -344,7 +344,7 @@ extern macro SmiToInt32(Smi): int32;
extern macro LoadHeapNumberValue(HeapNumber): float64;
extern macro ChangeFloat32ToFloat64(float32): float64;
extern macro ChangeNumberToFloat64(Number): float64;
extern macro ChangeInt32ToIntPtr(int32): intptr; // Sign-extends.
extern macro ChangeInt32ToIntPtr(int32): intptr; // Sign-extends.
extern macro ChangeUint32ToWord(uint32): uintptr; // Doesn't sign-extend.
extern macro NumberConstant(constexpr float64): Number;
......@@ -683,13 +683,9 @@ macro NumberIsNaN(number: Number): bool {
extern macro BranchIfToBooleanIsTrue(Object): never labels Taken, NotTaken;
macro ToBoolean(obj: Object): bool {
try {
BranchIfToBooleanIsTrue(obj) otherwise Taken, NotTaken;
}
label Taken {
if (BranchIfToBooleanIsTrue(obj)) {
return true;
}
label NotTaken {
} else {
return false;
}
}
......@@ -296,6 +296,14 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
return UncheckedCast<JSArray>(heap_object);
}
TNode<JSArray> TaggedToFastJSArray(TNode<Context> context,
TNode<Object> value, Label* fail) {
GotoIf(TaggedIsSmi(value), fail);
TNode<HeapObject> heap_object = CAST(value);
GotoIfNot(IsFastJSArray(heap_object, context), fail);
return UncheckedCast<JSArray>(heap_object);
}
TNode<JSDataView> TaggedToJSDataView(TNode<Object> value, Label* fail) {
GotoIf(TaggedIsSmi(value), fail);
TNode<HeapObject> heap_object = CAST(value);
......
......@@ -24,8 +24,7 @@ class DeclarationVisitor : public FileVisitor {
public:
explicit DeclarationVisitor(GlobalContext& global_context)
: FileVisitor(global_context),
scope_(declarations(), global_context.ast()->default_module()) {
}
scope_(declarations(), global_context.GetDefaultModule()) {}
void Visit(Ast* ast) {
Visit(ast->default_module());
......@@ -38,7 +37,7 @@ class DeclarationVisitor : public FileVisitor {
void Visit(ModuleDeclaration* decl) {
ScopedModuleActivator activator(this, decl->GetModule());
Declarations::NodeScopeActivator scope(declarations(), decl);
Declarations::ModuleScopeActivator scope(declarations(), decl->GetModule());
for (Declaration* child : decl->declarations) Visit(child);
}
void Visit(DefaultModuleDeclaration* decl) {
......@@ -170,7 +169,7 @@ class DeclarationVisitor : public FileVisitor {
const CallableNodeSignature* signature,
Statement* body) override;
Declarations::NodeScopeActivator scope_;
Declarations::ModuleScopeActivator scope_;
std::vector<Builtin*> torque_builtins_;
std::vector<LiveAndChanged> live_and_changed_variables_;
};
......
......@@ -9,6 +9,14 @@ namespace v8 {
namespace internal {
namespace torque {
Scope* Declarations::GetModuleScope(const Module* module) {
auto i = module_scopes_.find(module);
if (i != module_scopes_.end()) return i->second;
Scope* result = chain_.NewScope();
module_scopes_[module] = result;
return result;
}
Scope* Declarations::GetNodeScope(const AstNode* node, bool reset_scope) {
std::pair<const AstNode*, TypeVector> key(
node, current_generic_specialization_ == nullptr
......
......@@ -116,6 +116,7 @@ class Declarations {
void PrintScopeChain() { chain_.Print(); }
class ModuleScopeActivator;
class NodeScopeActivator;
class CleanNodeScopeActivator;
class GenericScopeActivator;
......@@ -123,6 +124,7 @@ class Declarations {
class ScopedGenericScopeChainSnapshot;
private:
Scope* GetModuleScope(const Module* module);
Scope* GetNodeScope(const AstNode* node, bool reset_scope = false);
Scope* GetGenericScope(Generic* generic, const TypeVector& types);
......@@ -152,6 +154,7 @@ class Declarations {
Deduplicator<FunctionPointerType> function_pointer_types_;
Deduplicator<UnionType> union_types_;
std::vector<std::unique_ptr<Type>> nominal_types_;
std::map<const Module*, Scope*> module_scopes_;
std::map<std::pair<const AstNode*, TypeVector>, Scope*> scopes_;
std::map<Generic*, ScopeChain::Snapshot> generic_declaration_scopes_;
};
......@@ -165,6 +168,15 @@ class Declarations::NodeScopeActivator {
Scope::Activator activator_;
};
class Declarations::ModuleScopeActivator {
public:
ModuleScopeActivator(Declarations* declarations, const Module* module)
: activator_(declarations->GetModuleScope(module)) {}
private:
Scope::Activator activator_;
};
class Declarations::CleanNodeScopeActivator {
public:
CleanNodeScopeActivator(Declarations* declarations, AstNode* node)
......
......@@ -157,7 +157,7 @@ void ImplementationVisitor::Visit(ModuleDeclaration* decl) {
Module* module = decl->GetModule();
Module* saved_module = module_;
module_ = module;
Declarations::NodeScopeActivator scope(declarations(), decl);
Declarations::ModuleScopeActivator scope(declarations(), decl->GetModule());
for (auto& child : decl->declarations) Visit(child);
module_ = saved_module;
}
......
......@@ -162,7 +162,7 @@ void PrintSignature(std::ostream& os, const Signature& sig, bool with_names) {
os << " labels ";
for (size_t i = 0; i < sig.labels.size(); ++i) {
if (i > 0) os << ", ";
os << sig.labels[i].name;
if (with_names) os << sig.labels[i].name;
if (sig.labels[i].types.size() > 0) os << "(" << sig.labels[i].types << ")";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment