Remove getters that duplicate FunctionKind in SharedFunctionInfo and ParseInfo

R=neis@chromium.org

Review-Url: https://codereview.chromium.org/2372373002
Cr-Commit-Position: refs/heads/master@{#39842}
This commit is contained in:
adamk 2016-09-28 14:23:53 -07:00 committed by Commit bot
parent ddbc4dcce6
commit 622bb78d9b
16 changed files with 50 additions and 107 deletions

View File

@ -3294,14 +3294,14 @@ bool Value::IsAsyncFunction() const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);
if (!obj->IsJSFunction()) return false;
i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(obj);
return func->shared()->is_async();
return i::IsAsyncFunction(func->shared()->kind());
}
bool Value::IsGeneratorFunction() const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);
if (!obj->IsJSFunction()) return false;
i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(obj);
return func->shared()->is_generator();
return i::IsGeneratorFunction(func->shared()->kind());
}

View File

@ -916,7 +916,7 @@ MaybeHandle<Code> GetBaselineCode(Handle<JSFunction> function) {
// baseline code because there might be suspended activations stored in
// generator objects on the heap. We could eventually go directly to
// TurboFan in this case.
if (function->shared()->is_resumable()) {
if (IsResumableFunction(function->shared()->kind())) {
return MaybeHandle<Code>();
}
@ -1385,7 +1385,7 @@ bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
// baseline code because there might be suspended activations stored in
// generator objects on the heap. We could eventually go directly to
// TurboFan in this case.
if (shared->is_resumable()) return false;
if (IsResumableFunction(shared->kind())) return false;
// TODO(4280): For now we disable switching to baseline code in the presence
// of interpreter activations of the given function. The reasons is that the

View File

@ -1294,7 +1294,8 @@ bool Debug::PrepareFunctionForBreakPoints(Handle<SharedFunctionInfo> shared) {
HeapIterator iterator(isolate_->heap());
HeapObject* obj;
// Continuation from old-style generators need to be recomputed.
bool find_resumables = baseline_exists && shared->is_resumable();
bool find_resumables =
baseline_exists && IsResumableFunction(shared->kind());
while ((obj = iterator.next())) {
if (obj->IsJSFunction()) {
@ -1353,7 +1354,7 @@ bool Debug::PrepareFunctionForBreakPoints(Handle<SharedFunctionInfo> shared) {
void Debug::RecordAsyncFunction(Handle<JSGeneratorObject> generator_object) {
if (last_step_action() <= StepOut) return;
if (!generator_object->function()->shared()->is_async()) return;
if (!IsAsyncFunction(generator_object->function()->shared()->kind())) return;
DCHECK(!has_suspended_generator());
thread_local_.suspended_generator_ = *generator_object;
ClearStepping();

View File

@ -1557,7 +1557,7 @@ static const char* DropActivationsInActiveThreadImpl(Isolate* isolate,
if (frame->is_java_script()) {
SharedFunctionInfo* shared =
JavaScriptFrame::cast(frame)->function()->shared();
if (shared->is_resumable()) {
if (IsResumableFunction(shared->kind())) {
non_droppable_frame_found = true;
non_droppable_reason = LiveEdit::FUNCTION_BLOCKED_UNDER_GENERATOR;
break;

View File

@ -1358,7 +1358,7 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code,
// TODO(littledan): Why do we have this is_generator test when
// NewFunctionPrototype already handles finding an appropriately
// shared prototype?
if (!function->shared()->is_resumable()) {
if (!IsResumableFunction(function->shared()->kind())) {
if (prototype->IsTheHole(isolate())) {
prototype = NewFunctionPrototype(function);
}
@ -1384,12 +1384,11 @@ Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
// can be from a different context.
Handle<Context> native_context(function->context()->native_context());
Handle<Map> new_map;
if (function->shared()->is_resumable()) {
if (IsResumableFunction(function->shared()->kind())) {
// Generator and async function prototypes can share maps since they
// don't have "constructor" properties.
new_map = handle(native_context->generator_object_prototype_map());
} else {
CHECK(!function->shared()->is_async());
// Each function prototype gets a fresh map to avoid unwanted sharing of
// maps between prototypes of different constructors.
Handle<JSFunction> object_function(native_context->object_function());
@ -1400,7 +1399,7 @@ Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
DCHECK(!new_map->is_prototype_map());
Handle<JSObject> prototype = NewJSObjectFromMap(new_map);
if (!function->shared()->is_resumable()) {
if (!IsResumableFunction(function->shared()->kind())) {
JSObject::AddProperty(prototype, constructor_string(), function, DONT_ENUM);
}
@ -1739,7 +1738,7 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array,
Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
Handle<JSFunction> function) {
DCHECK(function->shared()->is_resumable());
DCHECK(IsResumableFunction(function->shared()->kind()));
JSFunction::EnsureHasInitialMap(function);
Handle<Map> map(function->initial_map());
DCHECK_EQ(JS_GENERATOR_OBJECT_TYPE, map->instance_type());

View File

@ -623,7 +623,7 @@ bool StaticMarkingVisitor<StaticVisitor>::IsFlushable(
// We do not (yet?) flush code for generator functions, or async functions,
// because we don't know if there are still live activations
// (generator objects) on the heap.
if (shared_info->is_resumable()) {
if (IsResumableFunction(shared_info->kind())) {
return false;
}

View File

@ -6096,8 +6096,7 @@ void SharedFunctionInfo::set_language_mode(LanguageMode language_mode) {
set_compiler_hints(hints);
}
FunctionKind SharedFunctionInfo::kind() {
FunctionKind SharedFunctionInfo::kind() const {
return FunctionKindBits::decode(compiler_hints());
}
@ -6122,17 +6121,6 @@ BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_function, kIsFunction)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, dont_crankshaft,
kDontCrankshaft)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, dont_flush, kDontFlush)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_arrow, kIsArrow)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_generator, kIsGenerator)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_async, kIsAsyncFunction)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_concise_method,
kIsConciseMethod)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_getter_function,
kIsGetterFunction)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_setter_function,
kIsSetterFunction)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_default_constructor,
kIsDefaultConstructor)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_asm_wasm_broken,
kIsAsmWasmBroken)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, requires_class_field_init,
@ -6140,10 +6128,6 @@ BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, requires_class_field_init,
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_class_field_initializer,
kIsClassFieldInitializer)
inline bool SharedFunctionInfo::is_resumable() const {
return is_generator() || is_async();
}
bool Script::HasValidSource() {
Object* src = this->source();
if (!src->IsString()) return true;

View File

@ -974,9 +974,9 @@ void JSFunction::JSFunctionPrint(std::ostream& os) { // NOLINT
os << "\n - name = " << Brief(shared()->name());
os << "\n - formal_parameter_count = "
<< shared()->internal_formal_parameter_count();
if (shared()->is_generator()) {
if (IsGeneratorFunction(shared()->kind())) {
os << "\n - generator";
} else if (shared()->is_async()) {
} else if (IsAsyncFunction(shared()->kind())) {
os << "\n - async";
}
os << "\n - context = " << Brief(context());

View File

@ -12902,7 +12902,8 @@ bool CanSubclassHaveInobjectProperties(InstanceType instance_type) {
void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) {
DCHECK(function->IsConstructor() || function->shared()->is_resumable());
DCHECK(function->IsConstructor() ||
IsResumableFunction(function->shared()->kind()));
if (function->has_initial_map()) return;
Isolate* isolate = function->GetIsolate();
@ -12913,7 +12914,7 @@ void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) {
// First create a new map with the size and number of in-object properties
// suggested by the function.
InstanceType instance_type;
if (function->shared()->is_resumable()) {
if (IsResumableFunction(function->shared()->kind())) {
instance_type = JS_GENERATOR_OBJECT_TYPE;
} else {
instance_type = JS_OBJECT_TYPE;
@ -13144,17 +13145,18 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
}
IncrementalStringBuilder builder(isolate);
if (!shared_info->is_arrow()) {
if (shared_info->is_concise_method()) {
if (shared_info->is_generator()) {
FunctionKind kind = shared_info->kind();
if (!IsArrowFunction(kind)) {
if (IsConciseMethod(kind)) {
if (IsGeneratorFunction(kind)) {
builder.AppendCharacter('*');
} else if (shared_info->is_async()) {
} else if (IsAsyncFunction(kind)) {
builder.AppendCString("async ");
}
} else {
if (shared_info->is_generator()) {
if (IsGeneratorFunction(kind)) {
builder.AppendCString("function* ");
} else if (shared_info->is_async()) {
} else if (IsAsyncFunction(kind)) {
builder.AppendCString("async function ");
} else {
builder.AppendCString("function ");

View File

@ -7415,31 +7415,6 @@ class SharedFunctionInfo: public HeapObject {
// Indicates that code for this function cannot be flushed.
DECL_BOOLEAN_ACCESSORS(dont_flush)
// Indicates that this function is a generator.
DECL_BOOLEAN_ACCESSORS(is_generator)
// Indicates that this function is an async function.
DECL_BOOLEAN_ACCESSORS(is_async)
// Indicates that this function can be suspended, either via YieldExpressions
// or AwaitExpressions.
inline bool is_resumable() const;
// Indicates that this function is an arrow function.
DECL_BOOLEAN_ACCESSORS(is_arrow)
// Indicates that this function is a concise method.
DECL_BOOLEAN_ACCESSORS(is_concise_method)
// Indicates that this function is a getter.
DECL_BOOLEAN_ACCESSORS(is_getter_function)
// Indicates that this function is a setter.
DECL_BOOLEAN_ACCESSORS(is_setter_function)
// Indicates that this function is a default constructor.
DECL_BOOLEAN_ACCESSORS(is_default_constructor)
// Indicates that this is a constructor for a base class with instance fields.
DECL_BOOLEAN_ACCESSORS(requires_class_field_init)
// Indicates that this is a synthesized function to set up class instance
@ -7461,7 +7436,7 @@ class SharedFunctionInfo: public HeapObject {
// Indicates that asm->wasm conversion failed and should not be re-attempted.
DECL_BOOLEAN_ACCESSORS(is_asm_wasm_broken)
inline FunctionKind kind();
inline FunctionKind kind() const;
inline void set_kind(FunctionKind kind);
// Indicates whether or not the code in the shared function support

View File

@ -88,19 +88,6 @@ bool ParseInfo::is_declaration() const {
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDeclaration)) != 0;
}
bool ParseInfo::is_arrow() const {
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsArrow)) != 0;
}
bool ParseInfo::is_async() const {
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsAsyncFunction)) != 0;
}
bool ParseInfo::is_default_constructor() const {
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDefaultConstructor)) !=
0;
}
bool ParseInfo::requires_class_field_init() const {
return (compiler_hints_ &
(1 << SharedFunctionInfo::kRequiresClassFieldInit)) != 0;

View File

@ -148,9 +148,6 @@ class ParseInfo {
// Getters for individual compiler hints.
bool is_declaration() const;
bool is_arrow() const;
bool is_async() const;
bool is_default_constructor() const;
bool requires_class_field_init() const;
bool is_class_field_initializer() const;
FunctionKind function_kind() const;

View File

@ -398,16 +398,12 @@ class ParserBase {
void AddProperty() { expected_property_count_++; }
int expected_property_count() { return expected_property_count_; }
bool is_generator() const { return IsGeneratorFunction(kind()); }
bool is_async_function() const { return IsAsyncFunction(kind()); }
bool is_resumable() const { return is_generator() || is_async_function(); }
FunctionKind kind() const { return scope()->function_kind(); }
FunctionState* outer() const { return outer_function_state_; }
void set_generator_object_variable(typename Types::Variable* variable) {
DCHECK(variable != NULL);
DCHECK(is_resumable());
DCHECK(IsResumableFunction(kind()));
generator_object_variable_ = variable;
}
typename Types::Variable* generator_object_variable() const {
@ -416,7 +412,7 @@ class ParserBase {
void set_promise_variable(typename Types::Variable* variable) {
DCHECK(variable != NULL);
DCHECK(is_async_function());
DCHECK(IsAsyncFunction(kind()));
promise_variable_ = variable;
}
typename Types::Variable* promise_variable() const {
@ -942,11 +938,15 @@ class ParserBase {
LanguageMode old = scope()->language_mode();
impl()->SetLanguageMode(scope(), old > mode ? old : mode);
}
bool is_generator() const { return function_state_->is_generator(); }
bool is_async_function() const {
return function_state_->is_async_function();
bool is_generator() const {
return IsGeneratorFunction(function_state_->kind());
}
bool is_async_function() const {
return IsAsyncFunction(function_state_->kind());
}
bool is_resumable() const {
return IsResumableFunction(function_state_->kind());
}
bool is_resumable() const { return function_state_->is_resumable(); }
// Report syntax errors.
void ReportMessage(MessageTemplate::Template message) {

View File

@ -942,11 +942,11 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
DCHECK(is_sloppy(outer->language_mode()) ||
is_strict(info->language_mode()));
FunctionLiteral::FunctionType function_type = ComputeFunctionType(info);
FunctionKind kind = info->function_kind();
bool ok = true;
if (info->is_arrow()) {
bool is_async = allow_harmony_async_await() && info->is_async();
if (is_async) {
if (IsArrowFunction(kind)) {
if (allow_harmony_async_await() && IsAsyncFunction(kind)) {
DCHECK(!scanner()->HasAnyLineTerminatorAfterNext());
if (!Check(Token::ASYNC)) {
CHECK(stack_overflow());
@ -959,8 +959,7 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
}
// TODO(adamk): We should construct this scope from the ScopeInfo.
FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
DeclarationScope* scope = NewFunctionScope(arrow_kind);
DeclarationScope* scope = NewFunctionScope(kind);
// These two bits only need to be explicitly set because we're
// not passing the ScopeInfo to the Scope constructor.
@ -1013,10 +1012,9 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
}
}
}
} else if (info->is_default_constructor()) {
} else if (IsDefaultConstructor(kind)) {
DCHECK_EQ(scope(), outer);
bool is_subclass_constructor =
IsSubclassConstructor(info->function_kind());
bool is_subclass_constructor = IsSubclassConstructor(kind);
result = DefaultConstructor(
raw_name, is_subclass_constructor, info->requires_class_field_init(),
info->start_position(), info->end_position(), info->language_mode());
@ -1033,10 +1031,9 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
result = SynthesizeClassFieldInitializer(shared_info->length());
}
} else {
result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(),
kSkipFunctionNameCheck,
info->function_kind(), kNoSourcePosition,
function_type, info->language_mode(), &ok);
result = ParseFunctionLiteral(
raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind,
kNoSourcePosition, function_type, info->language_mode(), &ok);
if (info->requires_class_field_init()) {
result = InsertClassFieldInitializer(result);
}

View File

@ -95,7 +95,8 @@ static MaybeHandle<Object> DefineClass(Isolate* isolate,
prototype_parent = isolate->factory()->null_value();
} else if (super_class->IsConstructor()) {
DCHECK(!super_class->IsJSFunction() ||
!Handle<JSFunction>::cast(super_class)->shared()->is_resumable());
!IsResumableFunction(
Handle<JSFunction>::cast(super_class)->shared()->kind()));
ASSIGN_RETURN_ON_EXCEPTION(
isolate, prototype_parent,
Runtime::GetObjectProperty(isolate, super_class,

View File

@ -18,7 +18,7 @@ RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) {
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
CHECK(function->shared()->is_resumable());
CHECK(IsResumableFunction(function->shared()->kind()));
Handle<FixedArray> operand_stack;
if (function->shared()->HasBytecodeArray()) {
@ -49,7 +49,7 @@ RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) {
JavaScriptFrameIterator stack_iterator(isolate);
JavaScriptFrame* frame = stack_iterator.frame();
CHECK(frame->function()->shared()->is_resumable());
CHECK(IsResumableFunction(frame->function()->shared()->kind()));
DCHECK_EQ(frame->function(), generator_object->function());
DCHECK(frame->function()->shared()->is_compiled());
DCHECK(!frame->function()->IsOptimized());