Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: src/compiler.cc

Issue 894683003: Introduce LanguageMode, drop StrictMode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: . Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 8
9 #include "src/ast-numbering.h" 9 #include "src/ast-numbering.h"
10 #include "src/ast-this-access-visitor.h" 10 #include "src/ast-this-access-visitor.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // its type feedback. To avoid this, always compile functions in the snapshot 176 // its type feedback. To avoid this, always compile functions in the snapshot
177 // with deoptimization support. 177 // with deoptimization support.
178 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); 178 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport();
179 179
180 if (isolate_->debug()->is_active()) MarkAsDebug(); 180 if (isolate_->debug()->is_active()) MarkAsDebug();
181 if (FLAG_context_specialization) MarkAsContextSpecializing(); 181 if (FLAG_context_specialization) MarkAsContextSpecializing();
182 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); 182 if (FLAG_turbo_inlining) MarkAsInliningEnabled();
183 if (FLAG_turbo_types) MarkAsTypingEnabled(); 183 if (FLAG_turbo_types) MarkAsTypingEnabled();
184 184
185 if (!shared_info_.is_null()) { 185 if (!shared_info_.is_null()) {
186 DCHECK(strict_mode() == SLOPPY); 186 DCHECK(!is_strict(language_mode()));
187 SetStrictMode(shared_info_->strict_mode()); 187 SetLanguageMode(shared_info_->language_mode());
188 } 188 }
189 bailout_reason_ = kNoReason; 189 bailout_reason_ = kNoReason;
190 190
191 if (!shared_info().is_null() && shared_info()->is_compiled()) { 191 if (!shared_info().is_null() && shared_info()->is_compiled()) {
192 // We should initialize the CompilationInfo feedback vector from the 192 // We should initialize the CompilationInfo feedback vector from the
193 // passed in shared info, rather than creating a new one. 193 // passed in shared info, rather than creating a new one.
194 feedback_vector_ = 194 feedback_vector_ =
195 Handle<TypeFeedbackVector>(shared_info()->feedback_vector(), isolate); 195 Handle<TypeFeedbackVector>(shared_info()->feedback_vector(), isolate);
196 } 196 }
197 } 197 }
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 function_info->set_function_token_position(lit->function_token_position()); 617 function_info->set_function_token_position(lit->function_token_position());
618 function_info->set_start_position(lit->start_position()); 618 function_info->set_start_position(lit->start_position());
619 function_info->set_end_position(lit->end_position()); 619 function_info->set_end_position(lit->end_position());
620 function_info->set_is_expression(lit->is_expression()); 620 function_info->set_is_expression(lit->is_expression());
621 function_info->set_is_anonymous(lit->is_anonymous()); 621 function_info->set_is_anonymous(lit->is_anonymous());
622 function_info->set_is_toplevel(is_toplevel); 622 function_info->set_is_toplevel(is_toplevel);
623 function_info->set_inferred_name(*lit->inferred_name()); 623 function_info->set_inferred_name(*lit->inferred_name());
624 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); 624 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
625 function_info->set_allows_lazy_compilation_without_context( 625 function_info->set_allows_lazy_compilation_without_context(
626 lit->AllowsLazyCompilationWithoutContext()); 626 lit->AllowsLazyCompilationWithoutContext());
627 function_info->set_strict_mode(lit->strict_mode()); 627 function_info->set_language_mode(lit->language_mode());
628 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); 628 function_info->set_uses_arguments(lit->scope()->arguments() != NULL);
629 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); 629 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
630 function_info->set_ast_node_count(lit->ast_node_count()); 630 function_info->set_ast_node_count(lit->ast_node_count());
631 function_info->set_is_function(lit->is_function()); 631 function_info->set_is_function(lit->is_function());
632 MaybeDisableOptimization(function_info, lit->dont_optimize_reason()); 632 MaybeDisableOptimization(function_info, lit->dont_optimize_reason());
633 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); 633 function_info->set_dont_cache(lit->flags()->Contains(kDontCache));
634 function_info->set_kind(lit->kind()); 634 function_info->set_kind(lit->kind());
635 function_info->set_uses_super_property(lit->uses_super_property()); 635 function_info->set_uses_super_property(lit->uses_super_property());
636 function_info->set_uses_super_constructor_call( 636 function_info->set_uses_super_constructor_call(
637 lit->uses_super_constructor_call()); 637 lit->uses_super_constructor_call());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 686
687 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( 687 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon(
688 CompilationInfo* info) { 688 CompilationInfo* info) {
689 VMState<COMPILER> state(info->isolate()); 689 VMState<COMPILER> state(info->isolate());
690 PostponeInterruptsScope postpone(info->isolate()); 690 PostponeInterruptsScope postpone(info->isolate());
691 691
692 // Parse and update CompilationInfo with the results. 692 // Parse and update CompilationInfo with the results.
693 if (!Parser::Parse(info)) return MaybeHandle<Code>(); 693 if (!Parser::Parse(info)) return MaybeHandle<Code>();
694 Handle<SharedFunctionInfo> shared = info->shared_info(); 694 Handle<SharedFunctionInfo> shared = info->shared_info();
695 FunctionLiteral* lit = info->function(); 695 FunctionLiteral* lit = info->function();
696 shared->set_strict_mode(lit->strict_mode()); 696 shared->set_language_mode(lit->language_mode());
697 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); 697 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count());
698 MaybeDisableOptimization(shared, lit->dont_optimize_reason()); 698 MaybeDisableOptimization(shared, lit->dont_optimize_reason());
699 699
700 // Compile unoptimized code. 700 // Compile unoptimized code.
701 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); 701 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>();
702 702
703 CHECK_EQ(Code::FUNCTION, info->code()->kind()); 703 CHECK_EQ(Code::FUNCTION, info->code()->kind());
704 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); 704 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
705 705
706 // Update the shared function info with the scope info. Allocating the 706 // Update the shared function info with the scope info. Allocating the
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 } 1209 }
1210 1210
1211 isolate->debug()->OnAfterCompile(script); 1211 isolate->debug()->OnAfterCompile(script);
1212 1212
1213 return result; 1213 return result;
1214 } 1214 }
1215 1215
1216 1216
1217 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( 1217 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
1218 Handle<String> source, Handle<SharedFunctionInfo> outer_info, 1218 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
1219 Handle<Context> context, StrictMode strict_mode, 1219 Handle<Context> context, LanguageMode language_mode,
1220 ParseRestriction restriction, int scope_position) { 1220 ParseRestriction restriction, int scope_position) {
1221 Isolate* isolate = source->GetIsolate(); 1221 Isolate* isolate = source->GetIsolate();
1222 int source_length = source->length(); 1222 int source_length = source->length();
1223 isolate->counters()->total_eval_size()->Increment(source_length); 1223 isolate->counters()->total_eval_size()->Increment(source_length);
1224 isolate->counters()->total_compile_size()->Increment(source_length); 1224 isolate->counters()->total_compile_size()->Increment(source_length);
1225 1225
1226 CompilationCache* compilation_cache = isolate->compilation_cache(); 1226 CompilationCache* compilation_cache = isolate->compilation_cache();
1227 MaybeHandle<SharedFunctionInfo> maybe_shared_info = 1227 MaybeHandle<SharedFunctionInfo> maybe_shared_info =
1228 compilation_cache->LookupEval(source, outer_info, context, strict_mode, 1228 compilation_cache->LookupEval(source, outer_info, context, language_mode,
1229 scope_position); 1229 scope_position);
1230 Handle<SharedFunctionInfo> shared_info; 1230 Handle<SharedFunctionInfo> shared_info;
1231 1231
1232 if (!maybe_shared_info.ToHandle(&shared_info)) { 1232 if (!maybe_shared_info.ToHandle(&shared_info)) {
1233 Handle<Script> script = isolate->factory()->NewScript(source); 1233 Handle<Script> script = isolate->factory()->NewScript(source);
1234 CompilationInfoWithZone info(script); 1234 CompilationInfoWithZone info(script);
1235 info.MarkAsEval(); 1235 info.MarkAsEval();
1236 if (context->IsNativeContext()) info.MarkAsGlobal(); 1236 if (context->IsNativeContext()) info.MarkAsGlobal();
1237 info.SetStrictMode(strict_mode); 1237 info.SetLanguageMode(language_mode);
1238 info.SetParseRestriction(restriction); 1238 info.SetParseRestriction(restriction);
1239 info.SetContext(context); 1239 info.SetContext(context);
1240 1240
1241 Debug::RecordEvalCaller(script); 1241 Debug::RecordEvalCaller(script);
1242 1242
1243 shared_info = CompileToplevel(&info); 1243 shared_info = CompileToplevel(&info);
1244 1244
1245 if (shared_info.is_null()) { 1245 if (shared_info.is_null()) {
1246 return MaybeHandle<JSFunction>(); 1246 return MaybeHandle<JSFunction>();
1247 } else { 1247 } else {
1248 // Explicitly disable optimization for eval code. We're not yet prepared 1248 // Explicitly disable optimization for eval code. We're not yet prepared
1249 // to handle eval-code in the optimizing compiler. 1249 // to handle eval-code in the optimizing compiler.
1250 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) { 1250 if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) {
1251 shared_info->DisableOptimization(kEval); 1251 shared_info->DisableOptimization(kEval);
1252 } 1252 }
1253 1253
1254 // If caller is strict mode, the result must be in strict mode as well. 1254 // If caller is strict mode, the result must be in strict mode as well.
1255 DCHECK(strict_mode == SLOPPY || shared_info->strict_mode() == STRICT); 1255 DCHECK(!is_strict(language_mode) ||
1256 is_strict(shared_info->language_mode()));
1256 if (!shared_info->dont_cache()) { 1257 if (!shared_info->dont_cache()) {
1257 compilation_cache->PutEval(source, outer_info, context, shared_info, 1258 compilation_cache->PutEval(source, outer_info, context, shared_info,
1258 scope_position); 1259 scope_position);
1259 } 1260 }
1260 } 1261 }
1261 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { 1262 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) {
1262 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); 1263 shared_info->ResetForNewContext(isolate->heap()->global_ic_age());
1263 } 1264 }
1264 1265
1265 return isolate->factory()->NewFunctionFromSharedFunctionInfo( 1266 return isolate->factory()->NewFunctionFromSharedFunctionInfo(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 // Compile the function and add it to the cache. 1339 // Compile the function and add it to the cache.
1339 CompilationInfoWithZone info(script); 1340 CompilationInfoWithZone info(script);
1340 info.MarkAsGlobal(); 1341 info.MarkAsGlobal();
1341 info.SetCachedData(cached_data, compile_options); 1342 info.SetCachedData(cached_data, compile_options);
1342 info.SetExtension(extension); 1343 info.SetExtension(extension);
1343 info.SetContext(context); 1344 info.SetContext(context);
1344 if (FLAG_serialize_toplevel && 1345 if (FLAG_serialize_toplevel &&
1345 compile_options == ScriptCompiler::kProduceCodeCache) { 1346 compile_options == ScriptCompiler::kProduceCodeCache) {
1346 info.PrepareForSerializing(); 1347 info.PrepareForSerializing();
1347 } 1348 }
1348 if (FLAG_use_strict) info.SetStrictMode(STRICT); 1349 if (FLAG_use_strict) {
1350 info.SetLanguageMode(
1351 static_cast<LanguageMode>(info.language_mode() | STRICT));
1352 }
1349 1353
1350 result = CompileToplevel(&info); 1354 result = CompileToplevel(&info);
1351 if (extension == NULL && !result.is_null() && !result->dont_cache()) { 1355 if (extension == NULL && !result.is_null() && !result->dont_cache()) {
1352 compilation_cache->PutScript(source, context, result); 1356 compilation_cache->PutScript(source, context, result);
1353 if (FLAG_serialize_toplevel && 1357 if (FLAG_serialize_toplevel &&
1354 compile_options == ScriptCompiler::kProduceCodeCache) { 1358 compile_options == ScriptCompiler::kProduceCodeCache) {
1355 HistogramTimerScope histogram_timer( 1359 HistogramTimerScope histogram_timer(
1356 isolate->counters()->compile_serialize()); 1360 isolate->counters()->compile_serialize());
1357 *cached_data = CodeSerializer::Serialize(isolate, result, source); 1361 *cached_data = CodeSerializer::Serialize(isolate, result, source);
1358 if (FLAG_profile_deserialization) { 1362 if (FLAG_profile_deserialization) {
(...skipping 10 matching lines...) Expand all
1369 return result; 1373 return result;
1370 } 1374 }
1371 1375
1372 1376
1373 Handle<SharedFunctionInfo> Compiler::CompileStreamedScript( 1377 Handle<SharedFunctionInfo> Compiler::CompileStreamedScript(
1374 CompilationInfo* info, int source_length) { 1378 CompilationInfo* info, int source_length) {
1375 Isolate* isolate = info->isolate(); 1379 Isolate* isolate = info->isolate();
1376 isolate->counters()->total_load_size()->Increment(source_length); 1380 isolate->counters()->total_load_size()->Increment(source_length);
1377 isolate->counters()->total_compile_size()->Increment(source_length); 1381 isolate->counters()->total_compile_size()->Increment(source_length);
1378 1382
1379 if (FLAG_use_strict) info->SetStrictMode(STRICT); 1383 if (FLAG_use_strict) {
1384 info->SetLanguageMode(
1385 static_cast<LanguageMode>(info->language_mode() | STRICT));
1386 }
1380 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the 1387 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the
1381 // real code caching lands, streaming needs to be adapted to use it. 1388 // real code caching lands, streaming needs to be adapted to use it.
1382 return CompileToplevel(info); 1389 return CompileToplevel(info);
1383 } 1390 }
1384 1391
1385 1392
1386 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( 1393 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(
1387 FunctionLiteral* literal, Handle<Script> script, 1394 FunctionLiteral* literal, Handle<Script> script,
1388 CompilationInfo* outer_info) { 1395 CompilationInfo* outer_info) {
1389 // Precondition: code has been parsed and scopes have been analyzed. 1396 // Precondition: code has been parsed and scopes have been analyzed.
1390 CompilationInfoWithZone info(script); 1397 CompilationInfoWithZone info(script);
1391 info.SetFunction(literal); 1398 info.SetFunction(literal);
1392 info.PrepareForCompilation(literal->scope()); 1399 info.PrepareForCompilation(literal->scope());
1393 info.SetStrictMode(literal->scope()->strict_mode()); 1400 info.SetLanguageMode(literal->scope()->language_mode());
1394 if (outer_info->will_serialize()) info.PrepareForSerializing(); 1401 if (outer_info->will_serialize()) info.PrepareForSerializing();
1395 1402
1396 Isolate* isolate = info.isolate(); 1403 Isolate* isolate = info.isolate();
1397 Factory* factory = isolate->factory(); 1404 Factory* factory = isolate->factory();
1398 LiveEditFunctionTracker live_edit_tracker(isolate, literal); 1405 LiveEditFunctionTracker live_edit_tracker(isolate, literal);
1399 // Determine if the function can be lazily compiled. This is necessary to 1406 // Determine if the function can be lazily compiled. This is necessary to
1400 // allow some of our builtin JS files to be lazily compiled. These 1407 // allow some of our builtin JS files to be lazily compiled. These
1401 // builtins cannot be handled lazily by the parser, since we have to know 1408 // builtins cannot be handled lazily by the parser, since we have to know
1402 // if a function uses the special natives syntax, which is something the 1409 // if a function uses the special natives syntax, which is something the
1403 // parser records. 1410 // parser records.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 } 1602 }
1596 1603
1597 1604
1598 #if DEBUG 1605 #if DEBUG
1599 void CompilationInfo::PrintAstForTesting() { 1606 void CompilationInfo::PrintAstForTesting() {
1600 PrintF("--- Source from AST ---\n%s\n", 1607 PrintF("--- Source from AST ---\n%s\n",
1601 PrettyPrinter(isolate(), zone()).PrintProgram(function())); 1608 PrettyPrinter(isolate(), zone()).PrintProgram(function()));
1602 } 1609 }
1603 #endif 1610 #endif
1604 } } // namespace v8::internal 1611 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compiler.h ('k') | src/compiler/ast-graph-builder.h » ('j') | src/globals.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698