Classes: Cleanup default constructor flag
authorErik Arvidsson <arv@chromium.org>
Thu, 13 Nov 2014 16:50:03 +0000 (11:50 -0500)
committerErik Arvidsson <arv@chromium.org>
Thu, 13 Nov 2014 16:50:21 +0000 (16:50 +0000)
Now that we keep track of whether a function contains super we do not
need kDefaultConstructorCallSuper

BUG=None
LOG=Y
R=dslomov@chromium.org

Review URL: https://codereview.chromium.org/718833002

Cr-Commit-Position: refs/heads/master@{#25337}

src/ast.cc
src/ast.h
src/code-stubs.h
src/compiler.cc
src/globals.h
src/hydrogen-instructions.h
src/objects-inl.h
src/objects.h
src/parser.cc

index 79654c3..220dc04 100644 (file)
@@ -151,7 +151,7 @@ StrictMode FunctionLiteral::strict_mode() const {
 }
 
 
-bool FunctionLiteral::needs_super_binding() const {
+bool FunctionLiteral::uses_super() const {
   DCHECK_NOT_NULL(scope());
   return scope()->uses_super() || scope()->inner_uses_super();
 }
index 360fc93..deead81 100644 (file)
--- a/src/ast.h
+++ b/src/ast.h
@@ -2469,11 +2469,11 @@ class FunctionLiteral FINAL : public Expression {
   bool is_expression() const { return IsExpression::decode(bitfield_); }
   bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
   StrictMode strict_mode() const;
-  bool needs_super_binding() const;
+  bool uses_super() const;
 
   static bool NeedsHomeObject(Expression* literal) {
     return literal != NULL && literal->IsFunctionLiteral() &&
-           literal->AsFunctionLiteral()->needs_super_binding();
+           literal->AsFunctionLiteral()->uses_super();
   }
 
   int materialized_literal_count() { return materialized_literal_count_; }
@@ -2557,9 +2557,6 @@ class FunctionLiteral FINAL : public Expression {
   bool is_default_constructor() {
     return IsDefaultConstructor(FunctionKindBits::decode(bitfield_));
   }
-  bool is_default_constructor_call_super() {
-    return IsDefaultConstructorCallSuper(FunctionKindBits::decode(bitfield_));
-  }
 
   int ast_node_count() { return ast_properties_.node_count(); }
   AstProperties::Flags* flags() { return ast_properties_.flags(); }
@@ -2631,7 +2628,7 @@ class FunctionLiteral FINAL : public Expression {
   class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
   class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
   class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {};
-  class FunctionKindBits : public BitField<FunctionKind, 6, 5> {};
+  class FunctionKindBits : public BitField<FunctionKind, 6, 4> {};
 };
 
 
index 915de4f..7a6ad6a 100644 (file)
@@ -576,13 +576,10 @@ class FastNewClosureStub : public HydrogenCodeStub {
   bool is_generator() const { return IsGeneratorFunction(kind()); }
   bool is_concise_method() const { return IsConciseMethod(kind()); }
   bool is_default_constructor() const { return IsDefaultConstructor(kind()); }
-  bool is_default_constructor_call_super() const {
-    return IsDefaultConstructorCallSuper(kind());
-  }
 
  private:
   class StrictModeBits : public BitField<StrictMode, 0, 1> {};
-  class FunctionKindBits : public BitField<FunctionKind, 1, 5> {};
+  class FunctionKindBits : public BitField<FunctionKind, 1, 4> {};
 
   DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewClosure);
   DEFINE_HYDROGEN_CODE_STUB(FastNewClosure, HydrogenCodeStub);
index f52d6fc..4472afa 100644 (file)
@@ -615,6 +615,7 @@ static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
   MaybeDisableOptimization(function_info, lit->dont_optimize_reason());
   function_info->set_dont_cache(lit->flags()->Contains(kDontCache));
   function_info->set_kind(lit->kind());
+  function_info->set_uses_super(lit->uses_super());
   function_info->set_asm_function(lit->scope()->asm_function());
 }
 
@@ -1341,6 +1342,7 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(
   RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
   result->set_allows_lazy_compilation(allow_lazy);
   result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
+  result->set_uses_super(literal->uses_super());
 
   // Set the expected number of properties for instances and return
   // the resulting function.
index 1de3f0f..d896374 100644 (file)
@@ -783,8 +783,7 @@ enum FunctionKind {
   kGeneratorFunction = 2,
   kConciseMethod = 4,
   kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod,
-  kDefaultConstructor = 8,
-  kDefaultConstructorCallSuper = 16
+  kDefaultConstructor = 8
 };
 
 
@@ -794,8 +793,7 @@ inline bool IsValidFunctionKind(FunctionKind kind) {
          kind == FunctionKind::kGeneratorFunction ||
          kind == FunctionKind::kConciseMethod ||
          kind == FunctionKind::kConciseGeneratorMethod ||
-         kind == FunctionKind::kDefaultConstructor ||
-         kind == FunctionKind::kDefaultConstructorCallSuper;
+         kind == FunctionKind::kDefaultConstructor;
 }
 
 
@@ -823,10 +821,6 @@ inline bool IsDefaultConstructor(FunctionKind kind) {
 }
 
 
-inline bool IsDefaultConstructorCallSuper(FunctionKind kind) {
-  DCHECK(IsValidFunctionKind(kind));
-  return kind & FunctionKind::kDefaultConstructorCallSuper;
-}
 } }  // namespace v8::internal
 
 namespace i = v8::internal;
index ed44901..1752c44 100644 (file)
@@ -7567,9 +7567,6 @@ class HFunctionLiteral FINAL : public HTemplateInstruction<1> {
   bool is_generator() const { return IsGeneratorFunction(kind()); }
   bool is_concise_method() const { return IsConciseMethod(kind()); }
   bool is_default_constructor() const { return IsDefaultConstructor(kind()); }
-  bool is_default_constructor_call_super() const {
-    return IsDefaultConstructorCallSuper(kind());
-  }
   FunctionKind kind() const { return FunctionKindField::decode(bit_field_); }
   StrictMode strict_mode() const { return StrictModeField::decode(bit_field_); }
 
@@ -7589,7 +7586,7 @@ class HFunctionLiteral FINAL : public HTemplateInstruction<1> {
 
   virtual bool IsDeletable() const OVERRIDE { return true; }
 
-  class FunctionKindField : public BitField<FunctionKind, 0, 5> {};
+  class FunctionKindField : public BitField<FunctionKind, 0, 4> {};
   class PretenureField : public BitField<bool, 5, 1> {};
   class HasNoLiteralsField : public BitField<bool, 6, 1> {};
   class StrictModeField : public BitField<StrictMode, 7, 1> {};
index c741ce3..6bc1ab2 100644 (file)
@@ -5746,6 +5746,7 @@ void SharedFunctionInfo::set_kind(FunctionKind kind) {
 }
 
 
+BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, uses_super, kUsesSuper)
 BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, native, kNative)
 BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, inline_builtin,
                kInlineBuiltin)
@@ -5763,9 +5764,6 @@ BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_concise_method,
                kIsConciseMethod)
 BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_default_constructor,
                kIsDefaultConstructor)
-BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints,
-               is_default_constructor_call_super,
-               kIsDefaultConstructorCallSuper)
 
 ACCESSORS(CodeCache, default_cache, FixedArray, kDefaultCacheOffset)
 ACCESSORS(CodeCache, normal_type_cache, Object, kNormalTypeCacheOffset)
index 8dd3fc3..3d331a0 100644 (file)
@@ -6815,6 +6815,10 @@ class SharedFunctionInfo: public HeapObject {
   // False if the function definitely does not allocate an arguments object.
   DECL_BOOLEAN_ACCESSORS(uses_arguments)
 
+  // Indicates that this function uses super. This is needed to set up the
+  // [[HomeObject]] on the function instance.
+  DECL_BOOLEAN_ACCESSORS(uses_super)
+
   // True if the function has any duplicated parameter names.
   DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
 
@@ -6862,10 +6866,6 @@ class SharedFunctionInfo: public HeapObject {
   // Indicates that this function is a default constructor.
   DECL_BOOLEAN_ACCESSORS(is_default_constructor)
 
-  // Indicates that this function is a default constructor that needs to call
-  // super.
-  DECL_BOOLEAN_ACCESSORS(is_default_constructor_call_super)
-
   // Indicates that this function is an asm function.
   DECL_BOOLEAN_ACCESSORS(asm_function)
 
@@ -7096,6 +7096,7 @@ class SharedFunctionInfo: public HeapObject {
     kOptimizationDisabled,
     kStrictModeFunction,
     kUsesArguments,
+    kUsesSuper,
     kHasDuplicateParameters,
     kNative,
     kInlineBuiltin,
@@ -7109,13 +7110,12 @@ class SharedFunctionInfo: public HeapObject {
     kIsGenerator,
     kIsConciseMethod,
     kIsDefaultConstructor,
-    kIsDefaultConstructorCallSuper,
     kIsAsmFunction,
     kDeserialized,
     kCompilerHintsCount  // Pseudo entry
   };
 
-  class FunctionKindBits : public BitField<FunctionKind, kIsArrow, 5> {};
+  class FunctionKindBits : public BitField<FunctionKind, kIsArrow, 4> {};
 
   class DeoptCountBits : public BitField<int, 0, 4> {};
   class OptReenableTriesBits : public BitField<int, 4, 18> {};
index 0301e40..e202afe 100644 (file)
@@ -279,8 +279,6 @@ FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
   int parameter_count = 0;
   AstProperties ast_properties;
   const AstRawString* name = ast_value_factory()->empty_string();
-  FunctionKind kind = call_super ? FunctionKind::kDefaultConstructorCallSuper
-                                 : FunctionKind::kDefaultConstructor;
 
   Scope* function_scope = NewScope(scope, FUNCTION_SCOPE);
   function_scope->SetStrictMode(STRICT);
@@ -304,6 +302,7 @@ FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
           Runtime::FunctionForId(Runtime::kDefaultConstructorSuperCall), args,
           pos);
       body->Add(factory()->NewExpressionStatement(call, pos), zone());
+      function_scope->RecordSuperUsage();
     }
 
     materialized_literal_count = function_state.materialized_literal_count();
@@ -318,7 +317,8 @@ FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
       materialized_literal_count, expected_property_count, handler_count,
       parameter_count, FunctionLiteral::kNoDuplicateParameters,
       FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
-      FunctionLiteral::kNotParenthesized, kind, pos);
+      FunctionLiteral::kNotParenthesized, FunctionKind::kDefaultConstructor,
+      pos);
 
   function_literal->set_ast_properties(&ast_properties);
 
@@ -1060,11 +1060,10 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
       Expression* expression = ParseExpression(false, &ok);
       DCHECK(expression->IsFunctionLiteral());
       result = expression->AsFunctionLiteral();
-    } else if (shared_info->is_default_constructor() ||
-               shared_info->is_default_constructor_call_super()) {
-      result = DefaultConstructor(
-          shared_info->is_default_constructor_call_super(), scope,
-          shared_info->start_position(), shared_info->end_position());
+    } else if (shared_info->is_default_constructor()) {
+      result = DefaultConstructor(shared_info->uses_super(), scope,
+                                  shared_info->start_position(),
+                                  shared_info->end_position());
     } else {
       result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(),
                                     false,  // Strict mode name already checked.