Skip to content

Commit

Permalink
Revert "[hole-check-elimination] Simplest possible hole check elimina…
Browse files Browse the repository at this point in the history
…tion"

This reverts commit 10883f5.

Bug: v8:7427, chromium:1021457
Change-Id: Ib7f54158a2030a0c427c24b108a4eb76658d3ee0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1901909
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Joshua Litt <joshualitt@chromium.org>
Cr-Commit-Position: refs/branch-heads/7.9@{v8#39}
Cr-Branched-From: be181e2-refs/heads/7.9.317@{#1}
Cr-Branched-From: 0d7889d-refs/heads/master@{#64307}
  • Loading branch information
joshualitt committed Nov 7, 2019
1 parent d7968ad commit 5d914ab
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 283 deletions.
4 changes: 0 additions & 4 deletions src/ast/scopes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type,
DCHECK(!is_eval_scope());
sloppy_eval_can_extend_vars_ = true;
}
if (scope_info->CanElideThisHoleChecks()) {
can_elide_this_hole_checks_ = true;
}
}

Scope::Scope(Zone* zone, const AstRawString* catch_variable_name,
Expand Down Expand Up @@ -252,7 +249,6 @@ void DeclarationScope::SetDefaults() {
scope_uses_super_property_ = false;
has_checked_syntax_ = false;
has_this_reference_ = false;
can_elide_this_hole_checks_ = false;
has_this_declaration_ =
(is_function_scope() && !is_arrow_scope()) || is_module_scope();
needs_private_name_context_chain_recalc_ = false;
Expand Down
9 changes: 3 additions & 6 deletions src/ast/scopes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1088,13 +1088,11 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {

void set_has_this_reference() { has_this_reference_ = true; }
bool has_this_reference() const { return has_this_reference_; }

bool can_elide_this_hole_checks() const {
return can_elide_this_hole_checks_;
void UsesThis() {
set_has_this_reference();
GetReceiverScope()->receiver()->ForceContextAllocation();
}

void set_can_elide_this_hole_checks() { can_elide_this_hole_checks_ = true; }

bool needs_private_name_context_chain_recalc() const {
return needs_private_name_context_chain_recalc_;
}
Expand Down Expand Up @@ -1144,7 +1142,6 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
bool has_checked_syntax_ : 1;
bool has_this_reference_ : 1;
bool has_this_declaration_ : 1;
bool can_elide_this_hole_checks_ : 1;
bool needs_private_name_context_chain_recalc_ : 1;

// If the scope is a function scope, this is the function kind.
Expand Down
3 changes: 0 additions & 3 deletions src/diagnostics/objects-printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2304,9 +2304,6 @@ void ScopeInfo::ScopeInfoPrint(std::ostream& os) { // NOLINT
if (HasInferredFunctionName()) {
os << "\n - inferred function name: " << Brief(InferredFunctionName());
}
if (CanElideThisHoleChecks()) {
os << "\n - can elide this hole checks";
}

if (HasPositionInfo()) {
os << "\n - start position: " << StartPosition();
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/bytecode-generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5626,9 +5626,9 @@ void BytecodeGenerator::VisitTemplateLiteral(TemplateLiteral* expr) {
void BytecodeGenerator::BuildThisVariableLoad() {
DeclarationScope* receiver_scope = closure_scope()->GetReceiverScope();
Variable* var = receiver_scope->receiver();
// TODO(littledan): implement 'this' hole check elimination.
HoleCheckMode hole_check_mode =
(IsDerivedConstructor(receiver_scope->function_kind()) &&
!receiver_scope->can_elide_this_hole_checks())
IsDerivedConstructor(receiver_scope->function_kind())
? HoleCheckMode::kRequired
: HoleCheckMode::kElided;
BuildVariableLoad(var, hole_check_mode);
Expand Down
17 changes: 3 additions & 14 deletions src/objects/scope-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
bool has_simple_parameters = false;
bool is_asm_module = false;
bool sloppy_eval_can_extend_vars = false;
bool can_elide_this_hole_checks = false;
if (scope->is_function_scope()) {
DeclarationScope* function_scope = scope->AsDeclarationScope();
has_simple_parameters = function_scope->has_simple_parameters();
Expand All @@ -184,8 +183,6 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
function_kind = scope->AsDeclarationScope()->function_kind();
sloppy_eval_can_extend_vars =
scope->AsDeclarationScope()->sloppy_eval_can_extend_vars();
can_elide_this_hole_checks =
scope->AsDeclarationScope()->can_elide_this_hole_checks();
}

// Encode the flags.
Expand All @@ -209,8 +206,7 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
ForceContextAllocationField::encode(
scope->ForceContextForLanguageMode()) |
PrivateNameLookupSkipsOuterClassField::encode(
scope->private_name_lookup_skips_outer_class()) |
CanElideThisHoleChecksField::encode(can_elide_this_hole_checks);
scope->private_name_lookup_skips_outer_class());
scope_info.SetFlags(flags);

scope_info.SetParameterCount(parameter_count);
Expand Down Expand Up @@ -396,8 +392,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForWithScope(
HasOuterScopeInfoField::encode(has_outer_scope_info) |
IsDebugEvaluateScopeField::encode(false) |
ForceContextAllocationField::encode(false) |
PrivateNameLookupSkipsOuterClassField::encode(false) |
CanElideThisHoleChecksField::encode(false);
PrivateNameLookupSkipsOuterClassField::encode(false);
scope_info->SetFlags(flags);

scope_info->SetParameterCount(0);
Expand Down Expand Up @@ -466,8 +461,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
HasOuterScopeInfoField::encode(false) |
IsDebugEvaluateScopeField::encode(false) |
ForceContextAllocationField::encode(false) |
PrivateNameLookupSkipsOuterClassField::encode(false) |
CanElideThisHoleChecksField::encode(false);
PrivateNameLookupSkipsOuterClassField::encode(false);
scope_info->SetFlags(flags);
scope_info->SetParameterCount(parameter_count);
scope_info->SetContextLocalCount(context_local_count);
Expand Down Expand Up @@ -654,11 +648,6 @@ bool ScopeInfo::PrivateNameLookupSkipsOuterClass() const {
return PrivateNameLookupSkipsOuterClassField::decode(Flags());
}

bool ScopeInfo::CanElideThisHoleChecks() const {
if (length() == 0) return false;
return CanElideThisHoleChecksField::decode(Flags());
}

bool ScopeInfo::HasContext() const { return ContextLength() > 0; }

Object ScopeInfo::FunctionName() const {
Expand Down
5 changes: 0 additions & 5 deletions src/objects/scope-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class ScopeInfo : public FixedArray {
// Does this scope make a sloppy eval call?
bool SloppyEvalCanExtendVars() const;

// True if we can elide 'this' hole checks in this scope.
bool CanElideThisHoleChecks() const;

// Return the number of context slots for code if a context is allocated. This
// number consists of three parts:
// 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS
Expand Down Expand Up @@ -264,8 +261,6 @@ class ScopeInfo : public FixedArray {
using ForceContextAllocationField = IsDebugEvaluateScopeField::Next<bool, 1>;
using PrivateNameLookupSkipsOuterClassField =
ForceContextAllocationField::Next<bool, 1>;
using CanElideThisHoleChecksField =
PrivateNameLookupSkipsOuterClassField::Next<bool, 1>;

STATIC_ASSERT(kLastFunctionKind <= FunctionKindField::kMax);

Expand Down
19 changes: 1 addition & 18 deletions src/parsing/expression-scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,6 @@ class ExpressionScope {
} while (scope != nullptr);
}

void RecordCallsSuper() {
ExpressionScope* scope = this;
do {
if (scope->IsArrowHeadParsingScope()) {
scope->AsArrowHeadParsingScope()->RecordCallsSuper();
}
scope = scope->parent();
} while (scope != nullptr);
}

void RecordPatternError(const Scanner::Location& loc,
MessageTemplate message) {
// TODO(verwaest): Non-assigning expression?
Expand Down Expand Up @@ -764,12 +754,7 @@ class ArrowHeadParsingScope : public ExpressionParsingScope<Types> {
}
#endif // DEBUG

if (uses_this_) {
result->set_has_this_reference();
}
if (uses_this_ || calls_super_) {
result->GetReceiverScope()->receiver()->ForceContextAllocation();
}
if (uses_this_) result->UsesThis();
return result;
}

Expand All @@ -782,7 +767,6 @@ class ArrowHeadParsingScope : public ExpressionParsingScope<Types> {

void RecordNonSimpleParameter() { has_simple_parameter_list_ = false; }
void RecordThisUse() { uses_this_ = true; }
void RecordCallsSuper() { calls_super_ = true; }

private:
FunctionKind kind() const {
Expand All @@ -795,7 +779,6 @@ class ArrowHeadParsingScope : public ExpressionParsingScope<Types> {
MessageTemplate declaration_error_message = MessageTemplate::kNone;
bool has_simple_parameter_list_ = true;
bool uses_this_ = false;
bool calls_super_ = false;

DISALLOW_COPY_AND_ASSIGN(ArrowHeadParsingScope);
};
Expand Down
68 changes: 8 additions & 60 deletions src/parsing/parser-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1005,21 +1005,6 @@ class ParserBase {
return var;
}

// Similar to UseThis, but does not disable hole check elision.
V8_INLINE void CallsSuper() {
DeclarationScope* closure_scope = scope()->GetClosureScope();
DeclarationScope* receiver_scope = closure_scope->GetReceiverScope();
if (closure_scope == receiver_scope) {
// It's possible that we're parsing the head of an arrow function, in
// which case we haven't realized yet that closure_scope !=
// receiver_scope. Mark through the ExpressionScope for now.
expression_scope()->RecordCallsSuper();
} else {
Variable* var = receiver_scope->receiver();
var->ForceContextAllocation();
}
}

V8_INLINE IdentifierT ParseAndClassifyIdentifier(Token::Value token);
// Parses an identifier or a strict mode future reserved word. Allows passing
// in function_kind for the case of parsing the identifier in a function
Expand Down Expand Up @@ -1113,8 +1098,6 @@ class ParserBase {

ExpressionT ParseArrowFunctionLiteral(const FormalParametersT& parameters);
void ParseAsyncFunctionBody(Scope* scope, StatementListT* body);
void ParseDerivedConstructorBody(StatementListT* body,
Token::Value end_token);
ExpressionT ParseAsyncFunctionLiteral();
ExpressionT ParseClassLiteral(IdentifierT name,
Scanner::Location class_name_location,
Expand Down Expand Up @@ -3498,7 +3481,8 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression(
if (!is_new && peek() == Token::LPAREN && IsDerivedConstructor(kind)) {
// TODO(rossberg): This might not be the correct FunctionState for the
// method here.
CallsSuper();
expression_scope()->RecordThisUse();
UseThis();
return impl()->NewSuperCallReference(pos);
}
}
Expand Down Expand Up @@ -4081,18 +4065,16 @@ void ParserBase<Impl>::ParseFunctionBody(
impl()->ParseAndRewriteGeneratorFunctionBody(pos, kind, &inner_body);
} else if (IsAsyncFunction(kind)) {
ParseAsyncFunctionBody(inner_scope, &inner_body);
} else if (IsDerivedConstructor(kind)) {
ParseDerivedConstructorBody(&inner_body, closing_token);
{
ExpressionParsingScope expression_scope(impl());
inner_body.Add(factory()->NewReturnStatement(impl()->ThisExpression(),
kNoSourcePosition));
expression_scope.ValidateExpression();
}
} else {
ParseStatementList(&inner_body, closing_token);
}

if (IsDerivedConstructor(kind)) {
ExpressionParsingScope expression_scope(impl());
inner_body.Add(factory()->NewReturnStatement(impl()->ThisExpression(),
kNoSourcePosition));
expression_scope.ValidateExpression();
}
Expect(closing_token);
}
}
Expand Down Expand Up @@ -4762,40 +4744,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseV8Intrinsic() {

return impl()->NewV8Intrinsic(name, args, pos);
}
template <typename Impl>
void ParserBase<Impl>::ParseDerivedConstructorBody(StatementListT* body,
Token::Value end_token) {
// Allocate a target stack to use for this set of source elements. This way,
// all scripts and functions get their own target stack thus avoiding illegal
// breaks and continues across functions.
TargetScopeT target_scope(this);
while (peek() != end_token) {
StatementT stat = impl()->NullStatement();
// We can elide some hole checks in a derived constructor with a top level
// 'super,' but only if 'this' has not been used before the super. For
// safety we also require hole checks if 'eval' was called before 'super.'
if (V8_UNLIKELY(peek() == Token::SUPER && PeekAhead() == Token::LPAREN) &&
!GetReceiverScope()->receiver()->is_used() &&
!GetReceiverScope()->inner_scope_calls_eval()) {
int pos = peek_position();
ExpressionT expr = ParseExpression();

// Check again to confirm the 'super' expression did not reference
// 'this' or use 'eval.'
DeclarationScope* receiver_scope = GetReceiverScope();
if (!receiver_scope->receiver()->is_used() &&
!receiver_scope->inner_scope_calls_eval()) {
receiver_scope->set_can_elide_this_hole_checks();
}
stat = factory()->NewExpressionStatement(expr, pos);
} else {
stat = ParseStatementListItem();
}
if (impl()->IsNull(stat)) return;
if (stat->IsEmptyStatement()) continue;
body->Add(stat);
}
}

template <typename Impl>
void ParserBase<Impl>::ParseStatementList(StatementListT* body,
Expand Down
13 changes: 3 additions & 10 deletions src/parsing/preparse-data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ using InnerScopeCallsEvalField =
ScopeSloppyEvalCanExtendVarsField::Next<bool, 1>;
using NeedsPrivateNameContextChainRecalcField =
InnerScopeCallsEvalField::Next<bool, 1>;
using CanElideThisHoleChecks =
using ShouldSaveClassVariableIndexField =
NeedsPrivateNameContextChainRecalcField::Next<bool, 1>;
using ShouldSaveClassVariableIndexField = CanElideThisHoleChecks::Next<bool, 1>;

using VariableMaybeAssignedField = BitField8<bool, 0, 1>;
using VariableContextAllocatedField = VariableMaybeAssignedField::Next<bool, 1>;
Expand Down Expand Up @@ -357,7 +356,7 @@ void PreparseDataBuilder::SaveDataForScope(Scope* scope) {
byte_data_.WriteUint8(scope->scope_type());
#endif

uint8_t scope_data_flags =
uint8_t eval_and_private_recalc =
ScopeSloppyEvalCanExtendVarsField::encode(
scope->is_declaration_scope() &&
scope->AsDeclarationScope()->sloppy_eval_can_extend_vars()) |
Expand All @@ -366,14 +365,11 @@ void PreparseDataBuilder::SaveDataForScope(Scope* scope) {
scope->is_function_scope() &&
scope->AsDeclarationScope()
->needs_private_name_context_chain_recalc()) |
CanElideThisHoleChecks::encode(
scope->is_declaration_scope() &&
scope->AsDeclarationScope()->can_elide_this_hole_checks()) |
ShouldSaveClassVariableIndexField::encode(
scope->is_class_scope() &&
scope->AsClassScope()->should_save_class_variable_index());
byte_data_.Reserve(kUint8Size);
byte_data_.WriteUint8(scope_data_flags);
byte_data_.WriteUint8(eval_and_private_recalc);

if (scope->is_function_scope()) {
Variable* function = scope->AsDeclarationScope()->function_var();
Expand Down Expand Up @@ -625,9 +621,6 @@ void BaseConsumedPreparseData<Data>::RestoreDataForScope(
if (NeedsPrivateNameContextChainRecalcField::decode(scope_data_flags)) {
scope->AsDeclarationScope()->RecordNeedsPrivateNameContextChainRecalc();
}
if (CanElideThisHoleChecks::decode(scope_data_flags)) {
scope->AsDeclarationScope()->set_can_elide_this_hole_checks();
}
if (ShouldSaveClassVariableIndexField::decode(scope_data_flags)) {
Variable* var;
// An anonymous class whose class variable needs to be saved do not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ snippet: "
"
frame size: 6
parameter count: 1
bytecode array length: 36
bytecode array length: 40
bytecodes: [
B(Mov), R(closure), R(1),
/* 113 E> */ B(StackCheck),
Expand All @@ -120,9 +120,12 @@ bytecodes: [
B(Ldar), R(this),
B(ThrowSuperAlreadyCalledIfNotHole),
B(Mov), R(5), R(this),
/* 128 S> */ B(LdaSmi), I8(2),
/* 128 S> */ B(Ldar), R(this),
B(ThrowSuperNotCalledIfHole),
B(LdaSmi), I8(2),
/* 136 E> */ B(StaNamedProperty), R(this), U8(0), U8(2),
B(Ldar), R(this),
B(ThrowSuperNotCalledIfHole),
/* 141 S> */ B(Return),
]
constant pool: [
Expand All @@ -146,7 +149,7 @@ snippet: "
"
frame size: 5
parameter count: 1
bytecode array length: 32
bytecode array length: 36
bytecodes: [
B(Mov), R(closure), R(1),
/* 112 E> */ B(StackCheck),
Expand All @@ -158,9 +161,12 @@ bytecodes: [
B(Ldar), R(this),
B(ThrowSuperAlreadyCalledIfNotHole),
B(Mov), R(4), R(this),
/* 126 S> */ B(LdaSmi), I8(2),
/* 126 S> */ B(Ldar), R(this),
B(ThrowSuperNotCalledIfHole),
B(LdaSmi), I8(2),
/* 134 E> */ B(StaNamedProperty), R(this), U8(0), U8(2),
B(Ldar), R(this),
B(ThrowSuperNotCalledIfHole),
/* 139 S> */ B(Return),
]
constant pool: [
Expand Down
Loading

0 comments on commit 5d914ab

Please sign in to comment.