Commit 61833f5b authored by littledan's avatar littledan Committed by Commit bot

Remove class fields desugaring

This patch removes parser code implementing desugaring for ESnext
public and private fields on classes. The desugaring should probably
be implemented in the interpreter instead, and more work needs to go
into optimization and debugger support. The actual parsing of class
fields is left in, as the syntax is relatively stable, and there are
strong cctests for the grammar.

R=marja
BUG=v8:5367

Review-Url: https://codereview.chromium.org/2578893005
Cr-Commit-Position: refs/heads/master@{#41776}
parent b1c148b9
......@@ -291,7 +291,6 @@ class AstValue : public ZoneObject {
F(default, "default") \
F(done, "done") \
F(dot, ".") \
F(dot_class_field_init, ".class-field-init") \
F(dot_for, ".for") \
F(dot_generator_object, ".generator_object") \
F(dot_iterator, ".iterator") \
......
......@@ -2672,21 +2672,6 @@ class FunctionLiteral final : public Expression {
int yield_count() { return yield_count_; }
void set_yield_count(int yield_count) { yield_count_ = yield_count; }
bool requires_class_field_init() {
return RequiresClassFieldInit::decode(bit_field_);
}
void set_requires_class_field_init(bool requires_class_field_init) {
bit_field_ =
RequiresClassFieldInit::update(bit_field_, requires_class_field_init);
}
bool is_class_field_initializer() {
return IsClassFieldInitializer::decode(bit_field_);
}
void set_is_class_field_initializer(bool is_class_field_initializer) {
bit_field_ =
IsClassFieldInitializer::update(bit_field_, is_class_field_initializer);
}
int return_position() {
return std::max(start_position(), end_position() - (has_braces_ ? 1 : 0));
}
......@@ -2721,15 +2706,13 @@ class FunctionLiteral final : public Expression {
raw_inferred_name_(ast_value_factory->empty_string()),
ast_properties_(zone),
function_literal_id_(function_literal_id) {
bit_field_ |=
FunctionTypeBits::encode(function_type) | Pretenure::encode(false) |
HasDuplicateParameters::encode(has_duplicate_parameters ==
kHasDuplicateParameters) |
IsFunction::encode(is_function) |
RequiresClassFieldInit::encode(false) |
ShouldNotBeUsedOnceHintField::encode(false) |
DontOptimizeReasonField::encode(kNoReason) |
IsClassFieldInitializer::encode(false);
bit_field_ |= FunctionTypeBits::encode(function_type) |
Pretenure::encode(false) |
HasDuplicateParameters::encode(has_duplicate_parameters ==
kHasDuplicateParameters) |
IsFunction::encode(is_function) |
ShouldNotBeUsedOnceHintField::encode(false) |
DontOptimizeReasonField::encode(kNoReason);
if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile();
}
......@@ -2740,12 +2723,9 @@ class FunctionLiteral final : public Expression {
class IsFunction : public BitField<bool, HasDuplicateParameters::kNext, 1> {};
class ShouldNotBeUsedOnceHintField
: public BitField<bool, IsFunction::kNext, 1> {};
class RequiresClassFieldInit
: public BitField<bool, ShouldNotBeUsedOnceHintField::kNext, 1> {};
class IsClassFieldInitializer
: public BitField<bool, RequiresClassFieldInit::kNext, 1> {};
class DontOptimizeReasonField
: public BitField<BailoutReason, IsClassFieldInitializer::kNext, 8> {};
: public BitField<BailoutReason, ShouldNotBeUsedOnceHintField::kNext, 8> {
};
int materialized_literal_count_;
int expected_property_count_;
......@@ -2803,13 +2783,6 @@ class ClassLiteral final : public Expression {
return HasStaticComputedNames::decode(bit_field_);
}
VariableProxy* static_initializer_proxy() const {
return static_initializer_proxy_;
}
void set_static_initializer_proxy(VariableProxy* proxy) {
static_initializer_proxy_ = proxy;
}
// Object literals need one feedback slot for each non-trivial value, as well
// as some slots for home objects.
void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
......@@ -2835,8 +2808,7 @@ class ClassLiteral final : public Expression {
class_variable_proxy_(class_variable_proxy),
extends_(extends),
constructor_(constructor),
properties_(properties),
static_initializer_proxy_(nullptr) {
properties_(properties) {
bit_field_ |= HasNameStaticProperty::encode(has_name_static_property) |
HasStaticComputedNames::encode(has_static_computed_names);
}
......@@ -2848,7 +2820,6 @@ class ClassLiteral final : public Expression {
Expression* extends_;
FunctionLiteral* constructor_;
ZoneList<Property*>* properties_;
VariableProxy* static_initializer_proxy_;
class HasNameStaticProperty
: public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
......
......@@ -14039,9 +14039,6 @@ void SharedFunctionInfo::InitFromFunctionLiteral(
}
shared_info->set_needs_home_object(lit->scope()->NeedsHomeObject());
shared_info->set_asm_function(lit->scope()->asm_function());
shared_info->set_requires_class_field_init(lit->requires_class_field_init());
shared_info->set_is_class_field_initializer(
lit->is_class_field_initializer());
shared_info->set_function_literal_id(lit->function_literal_id());
SetExpectedNofPropertiesFromEstimate(shared_info, lit);
}
......
......@@ -673,19 +673,15 @@ class ParserBase {
: proxy(nullptr),
extends(parser->impl()->EmptyExpression()),
properties(parser->impl()->NewClassPropertyList(4)),
instance_field_initializers(parser->impl()->NewExpressionList(0)),
constructor(parser->impl()->EmptyFunctionLiteral()),
has_seen_constructor(false),
static_initializer_var(nullptr),
has_name_static_property(false),
has_static_computed_names(false) {}
VariableProxy* proxy;
ExpressionT extends;
typename Types::ClassPropertyList properties;
ExpressionListT instance_field_initializers;
FunctionLiteralT constructor;
bool has_seen_constructor;
Variable* static_initializer_var;
bool has_name_static_property;
bool has_static_computed_names;
};
......@@ -2309,7 +2305,6 @@ ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_,
initializer_scope->start_position(), true, GetNextFunctionLiteralId());
function_literal->set_is_class_field_initializer(true);
return function_literal;
}
......@@ -3162,7 +3157,6 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) {
// Explicit calls to the super constructor using super() perform an
// implicit binding assignment to the 'this' variable.
if (is_super_call) {
result = impl()->RewriteSuperCall(result);
ExpressionT this_expr = impl()->ThisExpression(pos);
result =
factory()->NewAssignment(Token::INIT, this_expr, result, pos);
......
This diff is collapsed.
......@@ -476,11 +476,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
int function_token_position, FunctionLiteral::FunctionType type,
LanguageMode language_mode, bool* ok);
Expression* InstallHomeObject(Expression* function_literal,
Expression* home_object);
FunctionLiteral* SynthesizeClassFieldInitializer(int count);
FunctionLiteral* InsertClassFieldInitializer(FunctionLiteral* constructor);
// Get odd-ball literals.
Literal* GetLiteralUndefined(int position);
......@@ -523,8 +518,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// Factory methods.
FunctionLiteral* DefaultConstructor(const AstRawString* name, bool call_super,
bool requires_class_field_init, int pos,
int end_pos, LanguageMode language_mode);
int pos, int end_pos,
LanguageMode language_mode);
// Skip over a lazy function, either using cached data if we have it, or
// by parsing the function with PreParser. Consumes the ending }.
......
......@@ -322,8 +322,6 @@ class PreParserExpression {
int position() const { return kNoSourcePosition; }
void set_function_token_position(int position) {}
void set_is_class_field_initializer(bool is_class_field_initializer) {}
private:
enum Type {
kEmpty,
......@@ -974,11 +972,6 @@ class PreParser : public ParserBase<PreParser> {
PreParserExpressionList args,
int pos);
V8_INLINE PreParserExpression
RewriteSuperCall(PreParserExpression call_expression) {
return call_expression;
}
V8_INLINE void RewriteDestructuringAssignments() {}
V8_INLINE PreParserExpression RewriteExponentiation(PreParserExpression left,
......@@ -1083,23 +1076,13 @@ class PreParser : public ParserBase<PreParser> {
ClassLiteralProperty::Kind kind,
bool is_static, bool is_constructor,
ClassInfo* class_info, bool* ok) {
if (kind == ClassLiteralProperty::FIELD && !is_static && !is_constructor) {
class_info->instance_field_initializers->Add(
PreParserExpression::Default(), zone());
}
}
V8_INLINE PreParserExpression RewriteClassLiteral(PreParserIdentifier name,
ClassInfo* class_info,
int pos, bool* ok) {
bool has_default_constructor = !class_info->has_seen_constructor;
bool has_instance_fields =
class_info->instance_field_initializers->length() > 0;
// Account for the default constructor.
if (has_default_constructor) GetNextFunctionLiteralId();
if (allow_harmony_class_fields() && has_instance_fields) {
// Account for initializer function.
GetNextFunctionLiteralId();
}
return PreParserExpression::Default();
}
......
......@@ -671,38 +671,6 @@ RUNTIME_FUNCTION(Runtime_DefineDataPropertyInLiteral) {
return *object;
}
RUNTIME_FUNCTION(Runtime_DefineDataProperty) {
HandleScope scope(isolate);
DCHECK(args.length() == 5);
CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
CONVERT_SMI_ARG_CHECKED(set_function_name, 4);
if (set_function_name) {
DCHECK(value->IsJSFunction());
JSFunction::SetName(Handle<JSFunction>::cast(value), name,
isolate->factory()->empty_string());
}
PropertyDescriptor desc;
desc.set_writable(!(attrs & ReadOnly));
desc.set_enumerable(!(attrs & DontEnum));
desc.set_configurable(!(attrs & DontDelete));
desc.set_value(value);
Maybe<bool> result = JSReceiver::DefineOwnProperty(isolate, receiver, name,
&desc, Object::DONT_THROW);
RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
if (result.IsNothing()) {
DCHECK(isolate->has_pending_exception());
return isolate->heap()->exception();
}
return *receiver;
}
// Return property without being observable by accessors or interceptors.
RUNTIME_FUNCTION(Runtime_GetDataProperty) {
HandleScope scope(isolate);
......
......@@ -412,7 +412,6 @@ namespace internal {
F(IsJSGlobalProxy, 1, 1) \
F(DefineAccessorPropertyUnchecked, 5, 1) \
F(DefineDataPropertyInLiteral, 5, 1) \
F(DefineDataProperty, 5, 1) \
F(GetDataProperty, 2, 1) \
F(GetConstructorName, 1, 1) \
F(HasFastPackedElements, 1, 1) \
......
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