Commit 4b7dc57f authored by verwaest's avatar verwaest Committed by Commit bot

There are only 2 language modes, not 3

Use bool is_strict_ to encode language_mode in scopes using a single bit.

BUG=

Review-Url: https://codereview.chromium.org/2261463002
Cr-Commit-Position: refs/heads/master@{#38724}
parent 07884202
......@@ -88,7 +88,7 @@ Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type)
DCHECK_EQ(SCRIPT_SCOPE, scope_type);
} else {
asm_function_ = outer_scope_->asm_module_;
language_mode_ = outer_scope->language_mode_;
set_language_mode(outer_scope->language_mode());
force_context_allocation_ =
!is_function_scope() && outer_scope->has_forced_context_allocation();
outer_scope_->AddInnerScope(this);
......@@ -137,7 +137,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
DCHECK(scope_info.is_null());
} else {
scope_calls_eval_ = scope_info->CallsEval();
language_mode_ = scope_info->language_mode();
set_language_mode(scope_info->language_mode());
num_heap_slots_ = scope_info->ContextLength();
}
DCHECK_LE(Context::MIN_CONTEXT_SLOTS, num_heap_slots_);
......@@ -204,7 +204,7 @@ void Scope::SetDefaults() {
num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
num_global_slots_ = 0;
language_mode_ = SLOPPY;
set_language_mode(SLOPPY);
scope_inside_with_ = false;
scope_calls_eval_ = false;
......@@ -1005,7 +1005,7 @@ void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to,
DCHECK(!force_eager_compilation_);
migrate_to->set_start_position(start_position_);
migrate_to->set_end_position(end_position_);
migrate_to->language_mode_ = language_mode_;
migrate_to->set_language_mode(language_mode());
migrate_to->arity_ = arity_;
migrate_to->force_context_allocation_ = force_context_allocation_;
outer_scope_->RemoveInnerScope(this);
......
......@@ -230,7 +230,7 @@ class Scope: public ZoneObject {
// Set the language mode flag (unless disabled by a global flag).
void SetLanguageMode(LanguageMode language_mode) {
DCHECK(!is_module_scope() || is_strict(language_mode));
language_mode_ = language_mode;
set_language_mode(language_mode);
}
// Set the ASM module flag.
......@@ -311,7 +311,7 @@ class Scope: public ZoneObject {
// Information about which scopes calls eval.
bool calls_eval() const { return scope_calls_eval_; }
bool calls_sloppy_eval() const {
return scope_calls_eval_ && is_sloppy(language_mode_);
return scope_calls_eval_ && is_sloppy(language_mode());
}
bool outer_scope_calls_sloppy_eval() const {
return outer_scope_calls_sloppy_eval_;
......@@ -338,7 +338,7 @@ class Scope: public ZoneObject {
ScopeType scope_type() const { return scope_type_; }
// The language mode of this scope.
LanguageMode language_mode() const { return language_mode_; }
LanguageMode language_mode() const { return is_strict_ ? STRICT : SLOPPY; }
// inner_scope() and sibling() together implement the inner scope list of a
// scope. Inner scope points to the an inner scope of the function, and
......@@ -452,7 +452,7 @@ class Scope: public ZoneObject {
protected:
void set_language_mode(LanguageMode language_mode) {
language_mode_ = language_mode;
is_strict_ = is_strict(language_mode);
}
private:
......@@ -503,8 +503,8 @@ class Scope: public ZoneObject {
// Scope-specific information computed during parsing.
//
// The language mode of this scope.
STATIC_ASSERT(LANGUAGE_END == 3);
LanguageMode language_mode_ : 2;
STATIC_ASSERT(LANGUAGE_END == 2);
bool is_strict_ : 1;
// This scope is inside a 'with' of some outer scope.
bool scope_inside_with_ : 1;
// This scope or a nested catch scope or with scope contain an 'eval' call. At
......
......@@ -1845,8 +1845,8 @@ class StoreGlobalViaContextStub final : public PlatformCodeStub {
private:
class DepthBits : public BitField<int, 0, 4> {};
STATIC_ASSERT(DepthBits::kMax == kMaximumDepth);
class LanguageModeBits : public BitField<LanguageMode, 4, 2> {};
STATIC_ASSERT(LANGUAGE_END == 3);
class LanguageModeBits : public BitField<LanguageMode, 4, 1> {};
STATIC_ASSERT(LANGUAGE_END == 2);
DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreGlobalViaContext);
DEFINE_PLATFORM_CODE_STUB(StoreGlobalViaContext, PlatformCodeStub);
......
......@@ -272,8 +272,7 @@ template <typename T, class P = FreeStoreAllocationPolicy> class List;
// The Strict Mode (ECMA-262 5th edition, 4.2.2).
enum LanguageMode { SLOPPY, STRICT, LANGUAGE_END = 3 };
enum LanguageMode : uint32_t { SLOPPY, STRICT, LANGUAGE_END };
inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) {
switch (mode) {
......
......@@ -257,8 +257,8 @@ class StoreICState final BASE_EMBEDDED {
return StoreICState(state).language_mode();
}
class LanguageModeState : public BitField<LanguageMode, 1, 2> {};
STATIC_ASSERT(i::LANGUAGE_END == 3);
class LanguageModeState : public BitField<LanguageMode, 1, 1> {};
STATIC_ASSERT(i::LANGUAGE_END == 2);
// For convenience, a statically declared encoding of strict mode extra
// IC state.
......
......@@ -6015,14 +6015,14 @@ void SharedFunctionInfo::set_optimization_disabled(bool disable) {
LanguageMode SharedFunctionInfo::language_mode() {
STATIC_ASSERT(LANGUAGE_END == 3);
STATIC_ASSERT(LANGUAGE_END == 2);
return construct_language_mode(
BooleanBit::get(compiler_hints(), kStrictModeFunction));
}
void SharedFunctionInfo::set_language_mode(LanguageMode language_mode) {
STATIC_ASSERT(LANGUAGE_END == 3);
STATIC_ASSERT(LANGUAGE_END == 2);
// We only allow language mode transitions that set the same language mode
// again or go up in the chain:
DCHECK(is_sloppy(this->language_mode()) || is_strict(language_mode));
......
......@@ -9163,22 +9163,15 @@ Handle<Map> Map::AsLanguageMode(Handle<Map> initial_map,
// using |strict_function_transition_symbol| as a key.
if (language_mode == SLOPPY) return initial_map;
Isolate* isolate = initial_map->GetIsolate();
Factory* factory = isolate->factory();
Handle<Symbol> transition_symbol;
int map_index = Context::FunctionMapIndex(language_mode, kind);
Handle<Map> function_map(
Map::cast(isolate->native_context()->get(map_index)));
STATIC_ASSERT(LANGUAGE_END == 3);
switch (language_mode) {
case STRICT:
transition_symbol = factory->strict_function_transition_symbol();
break;
default:
UNREACHABLE();
break;
}
STATIC_ASSERT(LANGUAGE_END == 2);
DCHECK_EQ(STRICT, language_mode);
Handle<Symbol> transition_symbol =
isolate->factory()->strict_function_transition_symbol();
Map* maybe_transition =
TransitionArray::SearchSpecial(*initial_map, *transition_symbol);
if (maybe_transition != NULL) {
......@@ -16020,7 +16013,7 @@ class StringSharedKey : public HashTableKey {
// collection.
Script* script(Script::cast(shared->script()));
hash ^= String::cast(script->source())->Hash();
STATIC_ASSERT(LANGUAGE_END == 3);
STATIC_ASSERT(LANGUAGE_END == 2);
if (is_strict(language_mode)) hash ^= 0x8000;
hash += scope_position;
}
......
......@@ -4404,9 +4404,9 @@ class ScopeInfo : public FixedArray {
// Properties of scopes.
class ScopeTypeField : public BitField<ScopeType, 0, 4> {};
class CallsEvalField : public BitField<bool, ScopeTypeField::kNext, 1> {};
STATIC_ASSERT(LANGUAGE_END == 3);
STATIC_ASSERT(LANGUAGE_END == 2);
class LanguageModeField
: public BitField<LanguageMode, CallsEvalField::kNext, 2> {};
: public BitField<LanguageMode, CallsEvalField::kNext, 1> {};
class DeclarationScopeField
: public BitField<bool, LanguageModeField::kNext, 1> {};
class ReceiverVariableField
......@@ -7506,8 +7506,6 @@ class SharedFunctionInfo: public HeapObject {
kIsAsmWasmBroken,
kCompilerHintsCount, // Pseudo entry
};
// Add hints for other modes when they're added.
STATIC_ASSERT(LANGUAGE_END == 3);
// kFunctionKind has to be byte-aligned
STATIC_ASSERT((kFunctionKind % kBitsPerByte) == 0);
// Make sure that FunctionKind and byte 2 are in sync:
......
......@@ -175,7 +175,7 @@ class ParseInfo {
return construct_language_mode(is_strict_mode());
}
void set_language_mode(LanguageMode language_mode) {
STATIC_ASSERT(LANGUAGE_END == 3);
STATIC_ASSERT(LANGUAGE_END == 2);
set_strict_mode(is_strict(language_mode));
}
......
......@@ -1137,8 +1137,8 @@ class AllocateTargetSpace : public BitField<AllocationSpace, 1, 3> {};
class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
class DeclareGlobalsNativeFlag : public BitField<bool, 1, 1> {};
STATIC_ASSERT(LANGUAGE_END == 3);
class DeclareGlobalsLanguageMode : public BitField<LanguageMode, 2, 2> {};
STATIC_ASSERT(LANGUAGE_END == 2);
class DeclareGlobalsLanguageMode : public BitField<LanguageMode, 2, 1> {};
} // namespace internal
} // namespace v8
......
......@@ -65,8 +65,7 @@ const double kIntegerValues[] = {-V8_INFINITY, INT_MIN, -1000.0, -42.0,
Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(),
Type::Number(), Type::String(), Type::Object()};
STATIC_ASSERT(LANGUAGE_END == 3);
STATIC_ASSERT(LANGUAGE_END == 2);
const LanguageMode kLanguageModes[] = {SLOPPY, STRICT};
} // namespace
......
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