| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 | 38 |
| 39 AstTyper::AstTyper(CompilationInfo* info) | 39 AstTyper::AstTyper(CompilationInfo* info) |
| 40 : info_(info), | 40 : info_(info), |
| 41 oracle_( | 41 oracle_( |
| 42 Handle<Code>(info->closure()->shared()->code()), | 42 Handle<Code>(info->closure()->shared()->code()), |
| 43 Handle<Context>(info->closure()->context()->native_context()), | 43 Handle<Context>(info->closure()->context()->native_context()), |
| 44 info->isolate(), | |
| 45 info->zone()), | 44 info->zone()), |
| 46 store_(info->zone()) { | 45 store_(info->zone()) { |
| 47 InitializeAstVisitor(info->isolate()); | 46 InitializeAstVisitor(info->zone()); |
| 48 } | 47 } |
| 49 | 48 |
| 50 | 49 |
| 51 #define RECURSE(call) \ | 50 #define RECURSE(call) \ |
| 52 do { \ | 51 do { \ |
| 53 ASSERT(!visitor->HasStackOverflow()); \ | 52 ASSERT(!visitor->HasStackOverflow()); \ |
| 54 call; \ | 53 call; \ |
| 55 if (visitor->HasStackOverflow()) return; \ | 54 if (visitor->HasStackOverflow()) return; \ |
| 56 } while (false) | 55 } while (false) |
| 57 | 56 |
| 58 void AstTyper::Run(CompilationInfo* info) { | 57 void AstTyper::Run(CompilationInfo* info) { |
| 59 AstTyper* visitor = new(info->zone()) AstTyper(info); | 58 AstTyper* visitor = new(info->zone()) AstTyper(info); |
| 60 Scope* scope = info->scope(); | 59 Scope* scope = info->scope(); |
| 61 | 60 |
| 62 // Handle implicit declaration of the function name in named function | 61 // Handle implicit declaration of the function name in named function |
| 63 // expressions before other declarations. | 62 // expressions before other declarations. |
| 64 if (scope->is_function_scope() && scope->function() != NULL) { | 63 if (scope->is_function_scope() && scope->function() != NULL) { |
| 65 RECURSE(visitor->VisitVariableDeclaration(scope->function())); | 64 RECURSE(visitor->VisitVariableDeclaration(scope->function())); |
| 66 } | 65 } |
| 67 RECURSE(visitor->VisitDeclarations(scope->declarations())); | 66 RECURSE(visitor->VisitDeclarations(scope->declarations())); |
| 68 RECURSE(visitor->VisitStatements(info->function()->body())); | 67 RECURSE(visitor->VisitStatements(info->function()->body())); |
| 69 } | 68 } |
| 70 | 69 |
| 71 #undef RECURSE | 70 #undef RECURSE |
| 72 | 71 |
| 73 | 72 |
| 74 #ifdef OBJECT_PRINT | 73 #ifdef OBJECT_PRINT |
| 75 static void PrintObserved(Variable* var, Object* value, Handle<Type> type) { | 74 static void PrintObserved(Variable* var, Object* value, Type* type) { |
| 76 PrintF(" observed %s ", var->IsParameter() ? "param" : "local"); | 75 PrintF(" observed %s ", var->IsParameter() ? "param" : "local"); |
| 77 var->name()->Print(); | 76 var->name()->Print(); |
| 78 PrintF(" : "); | 77 PrintF(" : "); |
| 79 value->ShortPrint(); | 78 value->ShortPrint(); |
| 80 PrintF(" -> "); | 79 PrintF(" -> "); |
| 81 type->TypePrint(); | 80 type->TypePrint(); |
| 82 } | 81 } |
| 83 #endif // OBJECT_PRINT | 82 #endif // OBJECT_PRINT |
| 84 | 83 |
| 85 | 84 |
| 86 Effect AstTyper::ObservedOnStack(Object* value) { | 85 Effect AstTyper::ObservedOnStack(Object* value) { |
| 87 Handle<Type> lower = Type::OfCurrently(handle(value, isolate()), isolate()); | 86 Type* lower = Type::OfCurrently(handle(value, isolate()), zone()); |
| 88 return Effect(Bounds(lower, Type::Any(isolate()))); | 87 return Effect(Bounds(lower, Type::Any(zone()))); |
| 89 } | 88 } |
| 90 | 89 |
| 91 | 90 |
| 92 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) { | 91 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) { |
| 93 if (stmt->OsrEntryId() != info_->osr_ast_id()) return; | 92 if (stmt->OsrEntryId() != info_->osr_ast_id()) return; |
| 94 | 93 |
| 95 DisallowHeapAllocation no_gc; | 94 DisallowHeapAllocation no_gc; |
| 96 JavaScriptFrameIterator it(isolate()); | 95 JavaScriptFrameIterator it(isolate()); |
| 97 JavaScriptFrame* frame = it.frame(); | 96 JavaScriptFrame* frame = it.frame(); |
| 98 Scope* scope = info_->scope(); | 97 Scope* scope = info_->scope(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 bool complex_effects = false; // True for label effects or fall-through. | 225 bool complex_effects = false; // True for label effects or fall-through. |
| 227 | 226 |
| 228 for (int i = 0; i < clauses->length(); ++i) { | 227 for (int i = 0; i < clauses->length(); ++i) { |
| 229 CaseClause* clause = clauses->at(i); | 228 CaseClause* clause = clauses->at(i); |
| 230 | 229 |
| 231 Effects clause_effects = EnterEffects(); | 230 Effects clause_effects = EnterEffects(); |
| 232 | 231 |
| 233 if (!clause->is_default()) { | 232 if (!clause->is_default()) { |
| 234 Expression* label = clause->label(); | 233 Expression* label = clause->label(); |
| 235 // Collect type feedback. | 234 // Collect type feedback. |
| 236 Handle<Type> tag_type, label_type, combined_type; | 235 Type* tag_type; |
| 236 Type* label_type; |
| 237 Type* combined_type; |
| 237 oracle()->CompareType(clause->CompareId(), | 238 oracle()->CompareType(clause->CompareId(), |
| 238 &tag_type, &label_type, &combined_type); | 239 &tag_type, &label_type, &combined_type); |
| 239 NarrowLowerType(stmt->tag(), tag_type); | 240 NarrowLowerType(stmt->tag(), tag_type); |
| 240 NarrowLowerType(label, label_type); | 241 NarrowLowerType(label, label_type); |
| 241 clause->set_compare_type(combined_type); | 242 clause->set_compare_type(combined_type); |
| 242 | 243 |
| 243 RECURSE(Visit(label)); | 244 RECURSE(Visit(label)); |
| 244 if (!clause_effects.IsEmpty()) complex_effects = true; | 245 if (!clause_effects.IsEmpty()) complex_effects = true; |
| 245 } | 246 } |
| 246 | 247 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 store_.Forget(); // Control may transfer here via 'continue'. | 316 store_.Forget(); // Control may transfer here via 'continue'. |
| 316 RECURSE(Visit(stmt->next())); | 317 RECURSE(Visit(stmt->next())); |
| 317 } | 318 } |
| 318 store_.Forget(); // Control may transfer here via termination or 'break'. | 319 store_.Forget(); // Control may transfer here via termination or 'break'. |
| 319 } | 320 } |
| 320 | 321 |
| 321 | 322 |
| 322 void AstTyper::VisitForInStatement(ForInStatement* stmt) { | 323 void AstTyper::VisitForInStatement(ForInStatement* stmt) { |
| 323 // Collect type feedback. | 324 // Collect type feedback. |
| 324 stmt->set_for_in_type(static_cast<ForInStatement::ForInType>( | 325 stmt->set_for_in_type(static_cast<ForInStatement::ForInType>( |
| 325 oracle()->ForInType(stmt->ForInFeedbackId()))); | 326 oracle()->ForInType(stmt->ForInFeedbackSlot()))); |
| 326 | 327 |
| 327 RECURSE(Visit(stmt->enumerable())); | 328 RECURSE(Visit(stmt->enumerable())); |
| 328 store_.Forget(); // Control may transfer here via looping or 'continue'. | 329 store_.Forget(); // Control may transfer here via looping or 'continue'. |
| 329 ObserveTypesAtOsrEntry(stmt); | 330 ObserveTypesAtOsrEntry(stmt); |
| 330 RECURSE(Visit(stmt->body())); | 331 RECURSE(Visit(stmt->body())); |
| 331 store_.Forget(); // Control may transfer here via 'break'. | 332 store_.Forget(); // Control may transfer here via 'break'. |
| 332 } | 333 } |
| 333 | 334 |
| 334 | 335 |
| 335 void AstTyper::VisitForOfStatement(ForOfStatement* stmt) { | 336 void AstTyper::VisitForOfStatement(ForOfStatement* stmt) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 RECURSE(Visit(expr->then_expression())); | 386 RECURSE(Visit(expr->then_expression())); |
| 386 ExitEffects(); | 387 ExitEffects(); |
| 387 Effects else_effects = EnterEffects(); | 388 Effects else_effects = EnterEffects(); |
| 388 RECURSE(Visit(expr->else_expression())); | 389 RECURSE(Visit(expr->else_expression())); |
| 389 ExitEffects(); | 390 ExitEffects(); |
| 390 then_effects.Alt(else_effects); | 391 then_effects.Alt(else_effects); |
| 391 store_.Seq(then_effects); | 392 store_.Seq(then_effects); |
| 392 | 393 |
| 393 NarrowType(expr, Bounds::Either( | 394 NarrowType(expr, Bounds::Either( |
| 394 expr->then_expression()->bounds(), | 395 expr->then_expression()->bounds(), |
| 395 expr->else_expression()->bounds(), isolate_)); | 396 expr->else_expression()->bounds(), zone())); |
| 396 } | 397 } |
| 397 | 398 |
| 398 | 399 |
| 399 void AstTyper::VisitVariableProxy(VariableProxy* expr) { | 400 void AstTyper::VisitVariableProxy(VariableProxy* expr) { |
| 400 Variable* var = expr->var(); | 401 Variable* var = expr->var(); |
| 401 if (var->IsStackAllocated()) { | 402 if (var->IsStackAllocated()) { |
| 402 NarrowType(expr, store_.LookupBounds(variable_index(var))); | 403 NarrowType(expr, store_.LookupBounds(variable_index(var))); |
| 403 } | 404 } |
| 404 } | 405 } |
| 405 | 406 |
| 406 | 407 |
| 407 void AstTyper::VisitLiteral(Literal* expr) { | 408 void AstTyper::VisitLiteral(Literal* expr) { |
| 408 Handle<Type> type = Type::Constant(expr->value(), isolate_); | 409 Type* type = Type::Constant(expr->value(), zone()); |
| 409 NarrowType(expr, Bounds(type)); | 410 NarrowType(expr, Bounds(type)); |
| 410 } | 411 } |
| 411 | 412 |
| 412 | 413 |
| 413 void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) { | 414 void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 414 NarrowType(expr, Bounds(Type::RegExp(isolate_))); | 415 NarrowType(expr, Bounds(Type::RegExp(zone()))); |
| 415 } | 416 } |
| 416 | 417 |
| 417 | 418 |
| 418 void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) { | 419 void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) { |
| 419 ZoneList<ObjectLiteral::Property*>* properties = expr->properties(); | 420 ZoneList<ObjectLiteral::Property*>* properties = expr->properties(); |
| 420 for (int i = 0; i < properties->length(); ++i) { | 421 for (int i = 0; i < properties->length(); ++i) { |
| 421 ObjectLiteral::Property* prop = properties->at(i); | 422 ObjectLiteral::Property* prop = properties->at(i); |
| 422 | 423 |
| 423 // Collect type feedback. | 424 // Collect type feedback. |
| 424 if ((prop->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL && | 425 if ((prop->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL && |
| 425 !CompileTimeValue::IsCompileTimeValue(prop->value())) || | 426 !CompileTimeValue::IsCompileTimeValue(prop->value())) || |
| 426 prop->kind() == ObjectLiteral::Property::COMPUTED) { | 427 prop->kind() == ObjectLiteral::Property::COMPUTED) { |
| 427 if (prop->key()->value()->IsInternalizedString() && prop->emit_store()) { | 428 if (prop->key()->value()->IsInternalizedString() && prop->emit_store()) { |
| 428 prop->RecordTypeFeedback(oracle()); | 429 prop->RecordTypeFeedback(oracle()); |
| 429 } | 430 } |
| 430 } | 431 } |
| 431 | 432 |
| 432 RECURSE(Visit(prop->value())); | 433 RECURSE(Visit(prop->value())); |
| 433 } | 434 } |
| 434 | 435 |
| 435 NarrowType(expr, Bounds(Type::Object(isolate_))); | 436 NarrowType(expr, Bounds(Type::Object(zone()))); |
| 436 } | 437 } |
| 437 | 438 |
| 438 | 439 |
| 439 void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) { | 440 void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) { |
| 440 ZoneList<Expression*>* values = expr->values(); | 441 ZoneList<Expression*>* values = expr->values(); |
| 441 for (int i = 0; i < values->length(); ++i) { | 442 for (int i = 0; i < values->length(); ++i) { |
| 442 Expression* value = values->at(i); | 443 Expression* value = values->at(i); |
| 443 RECURSE(Visit(value)); | 444 RECURSE(Visit(value)); |
| 444 } | 445 } |
| 445 | 446 |
| 446 NarrowType(expr, Bounds(Type::Array(isolate_))); | 447 NarrowType(expr, Bounds(Type::Array(zone()))); |
| 447 } | 448 } |
| 448 | 449 |
| 449 | 450 |
| 450 void AstTyper::VisitAssignment(Assignment* expr) { | 451 void AstTyper::VisitAssignment(Assignment* expr) { |
| 451 // Collect type feedback. | 452 // Collect type feedback. |
| 452 Property* prop = expr->target()->AsProperty(); | 453 Property* prop = expr->target()->AsProperty(); |
| 453 if (prop != NULL) { | 454 if (prop != NULL) { |
| 454 TypeFeedbackId id = expr->AssignmentFeedbackId(); | 455 TypeFeedbackId id = expr->AssignmentFeedbackId(); |
| 455 expr->set_is_uninitialized(oracle()->StoreIsUninitialized(id)); | 456 expr->set_is_uninitialized(oracle()->StoreIsUninitialized(id)); |
| 456 if (!expr->IsUninitialized()) { | 457 if (!expr->IsUninitialized()) { |
| 457 expr->set_is_pre_monomorphic(oracle()->StoreIsPreMonomorphic(id)); | |
| 458 if (prop->key()->IsPropertyName()) { | 458 if (prop->key()->IsPropertyName()) { |
| 459 Literal* lit_key = prop->key()->AsLiteral(); | 459 Literal* lit_key = prop->key()->AsLiteral(); |
| 460 ASSERT(lit_key != NULL && lit_key->value()->IsString()); | 460 ASSERT(lit_key != NULL && lit_key->value()->IsString()); |
| 461 Handle<String> name = Handle<String>::cast(lit_key->value()); | 461 Handle<String> name = Handle<String>::cast(lit_key->value()); |
| 462 oracle()->AssignmentReceiverTypes(id, name, expr->GetReceiverTypes()); | 462 oracle()->AssignmentReceiverTypes(id, name, expr->GetReceiverTypes()); |
| 463 } else { | 463 } else { |
| 464 KeyedAccessStoreMode store_mode; | 464 KeyedAccessStoreMode store_mode; |
| 465 oracle()->KeyedAssignmentReceiverTypes( | 465 oracle()->KeyedAssignmentReceiverTypes( |
| 466 id, expr->GetReceiverTypes(), &store_mode); | 466 id, expr->GetReceiverTypes(), &store_mode); |
| 467 expr->set_store_mode(store_mode); | 467 expr->set_store_mode(store_mode); |
| 468 } | 468 } |
| 469 ASSERT(!expr->IsPreMonomorphic() || !expr->IsMonomorphic()); | |
| 470 } | 469 } |
| 471 } | 470 } |
| 472 | 471 |
| 473 Expression* rhs = | 472 Expression* rhs = |
| 474 expr->is_compound() ? expr->binary_operation() : expr->value(); | 473 expr->is_compound() ? expr->binary_operation() : expr->value(); |
| 475 RECURSE(Visit(expr->target())); | 474 RECURSE(Visit(expr->target())); |
| 476 RECURSE(Visit(rhs)); | 475 RECURSE(Visit(rhs)); |
| 477 NarrowType(expr, rhs->bounds()); | 476 NarrowType(expr, rhs->bounds()); |
| 478 | 477 |
| 479 VariableProxy* proxy = expr->target()->AsVariableProxy(); | 478 VariableProxy* proxy = expr->target()->AsVariableProxy(); |
| 480 if (proxy != NULL && proxy->var()->IsStackAllocated()) { | 479 if (proxy != NULL && proxy->var()->IsStackAllocated()) { |
| 481 store_.Seq(variable_index(proxy->var()), Effect(expr->bounds())); | 480 store_.Seq(variable_index(proxy->var()), Effect(expr->bounds())); |
| 482 } | 481 } |
| 483 } | 482 } |
| 484 | 483 |
| 485 | 484 |
| 486 void AstTyper::VisitYield(Yield* expr) { | 485 void AstTyper::VisitYield(Yield* expr) { |
| 487 RECURSE(Visit(expr->generator_object())); | 486 RECURSE(Visit(expr->generator_object())); |
| 488 RECURSE(Visit(expr->expression())); | 487 RECURSE(Visit(expr->expression())); |
| 489 | 488 |
| 490 // We don't know anything about the result type. | 489 // We don't know anything about the result type. |
| 491 } | 490 } |
| 492 | 491 |
| 493 | 492 |
| 494 void AstTyper::VisitThrow(Throw* expr) { | 493 void AstTyper::VisitThrow(Throw* expr) { |
| 495 RECURSE(Visit(expr->exception())); | 494 RECURSE(Visit(expr->exception())); |
| 496 // TODO(rossberg): is it worth having a non-termination effect? | 495 // TODO(rossberg): is it worth having a non-termination effect? |
| 497 | 496 |
| 498 NarrowType(expr, Bounds(Type::None(isolate_))); | 497 NarrowType(expr, Bounds(Type::None(zone()))); |
| 499 } | 498 } |
| 500 | 499 |
| 501 | 500 |
| 502 void AstTyper::VisitProperty(Property* expr) { | 501 void AstTyper::VisitProperty(Property* expr) { |
| 503 // Collect type feedback. | 502 // Collect type feedback. |
| 504 TypeFeedbackId id = expr->PropertyFeedbackId(); | 503 TypeFeedbackId id = expr->PropertyFeedbackId(); |
| 505 expr->set_is_uninitialized(oracle()->LoadIsUninitialized(id)); | 504 expr->set_is_uninitialized(oracle()->LoadIsUninitialized(id)); |
| 506 if (!expr->IsUninitialized()) { | 505 if (!expr->IsUninitialized()) { |
| 507 expr->set_is_pre_monomorphic(oracle()->LoadIsPreMonomorphic(id)); | |
| 508 if (expr->key()->IsPropertyName()) { | 506 if (expr->key()->IsPropertyName()) { |
| 509 Literal* lit_key = expr->key()->AsLiteral(); | 507 Literal* lit_key = expr->key()->AsLiteral(); |
| 510 ASSERT(lit_key != NULL && lit_key->value()->IsString()); | 508 ASSERT(lit_key != NULL && lit_key->value()->IsString()); |
| 511 Handle<String> name = Handle<String>::cast(lit_key->value()); | 509 Handle<String> name = Handle<String>::cast(lit_key->value()); |
| 512 bool is_prototype; | 510 bool is_prototype; |
| 513 oracle()->PropertyReceiverTypes( | 511 oracle()->PropertyReceiverTypes( |
| 514 id, name, expr->GetReceiverTypes(), &is_prototype); | 512 id, name, expr->GetReceiverTypes(), &is_prototype); |
| 515 expr->set_is_function_prototype(is_prototype); | 513 expr->set_is_function_prototype(is_prototype); |
| 516 } else { | 514 } else { |
| 517 bool is_string; | 515 bool is_string; |
| 518 oracle()->KeyedPropertyReceiverTypes( | 516 oracle()->KeyedPropertyReceiverTypes( |
| 519 id, expr->GetReceiverTypes(), &is_string); | 517 id, expr->GetReceiverTypes(), &is_string); |
| 520 expr->set_is_string_access(is_string); | 518 expr->set_is_string_access(is_string); |
| 521 } | 519 } |
| 522 ASSERT(!expr->IsPreMonomorphic() || !expr->IsMonomorphic()); | |
| 523 } | 520 } |
| 524 | 521 |
| 525 RECURSE(Visit(expr->obj())); | 522 RECURSE(Visit(expr->obj())); |
| 526 RECURSE(Visit(expr->key())); | 523 RECURSE(Visit(expr->key())); |
| 527 | 524 |
| 528 // We don't know anything about the result type. | 525 // We don't know anything about the result type. |
| 529 } | 526 } |
| 530 | 527 |
| 531 | 528 |
| 532 void AstTyper::VisitCall(Call* expr) { | 529 void AstTyper::VisitCall(Call* expr) { |
| 533 // Collect type feedback. | 530 // Collect type feedback. |
| 534 expr->RecordTypeFeedback(oracle()); | 531 RECURSE(Visit(expr->expression())); |
| 532 if (!expr->expression()->IsProperty() && |
| 533 expr->HasCallFeedbackSlot() && |
| 534 oracle()->CallIsMonomorphic(expr->CallFeedbackSlot())) { |
| 535 expr->set_target(oracle()->GetCallTarget(expr->CallFeedbackSlot())); |
| 536 } |
| 535 | 537 |
| 536 RECURSE(Visit(expr->expression())); | |
| 537 ZoneList<Expression*>* args = expr->arguments(); | 538 ZoneList<Expression*>* args = expr->arguments(); |
| 538 for (int i = 0; i < args->length(); ++i) { | 539 for (int i = 0; i < args->length(); ++i) { |
| 539 Expression* arg = args->at(i); | 540 Expression* arg = args->at(i); |
| 540 RECURSE(Visit(arg)); | 541 RECURSE(Visit(arg)); |
| 541 } | 542 } |
| 542 | 543 |
| 543 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 544 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
| 544 if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) { | 545 if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) { |
| 545 store_.Forget(); // Eval could do whatever to local variables. | 546 store_.Forget(); // Eval could do whatever to local variables. |
| 546 } | 547 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 if (expr->op() == Token::NOT) { | 581 if (expr->op() == Token::NOT) { |
| 581 // TODO(rossberg): only do in test or value context. | 582 // TODO(rossberg): only do in test or value context. |
| 582 expr->expression()->RecordToBooleanTypeFeedback(oracle()); | 583 expr->expression()->RecordToBooleanTypeFeedback(oracle()); |
| 583 } | 584 } |
| 584 | 585 |
| 585 RECURSE(Visit(expr->expression())); | 586 RECURSE(Visit(expr->expression())); |
| 586 | 587 |
| 587 switch (expr->op()) { | 588 switch (expr->op()) { |
| 588 case Token::NOT: | 589 case Token::NOT: |
| 589 case Token::DELETE: | 590 case Token::DELETE: |
| 590 NarrowType(expr, Bounds(Type::Boolean(isolate_))); | 591 NarrowType(expr, Bounds(Type::Boolean(zone()))); |
| 591 break; | 592 break; |
| 592 case Token::VOID: | 593 case Token::VOID: |
| 593 NarrowType(expr, Bounds(Type::Undefined(isolate_))); | 594 NarrowType(expr, Bounds(Type::Undefined(zone()))); |
| 594 break; | 595 break; |
| 595 case Token::TYPEOF: | 596 case Token::TYPEOF: |
| 596 NarrowType(expr, Bounds(Type::InternalizedString(isolate_))); | 597 NarrowType(expr, Bounds(Type::InternalizedString(zone()))); |
| 597 break; | 598 break; |
| 598 default: | 599 default: |
| 599 UNREACHABLE(); | 600 UNREACHABLE(); |
| 600 } | 601 } |
| 601 } | 602 } |
| 602 | 603 |
| 603 | 604 |
| 604 void AstTyper::VisitCountOperation(CountOperation* expr) { | 605 void AstTyper::VisitCountOperation(CountOperation* expr) { |
| 605 // Collect type feedback. | 606 // Collect type feedback. |
| 606 TypeFeedbackId store_id = expr->CountStoreFeedbackId(); | 607 TypeFeedbackId store_id = expr->CountStoreFeedbackId(); |
| 607 expr->set_store_mode(oracle()->GetStoreMode(store_id)); | 608 expr->set_store_mode(oracle()->GetStoreMode(store_id)); |
| 608 oracle()->CountReceiverTypes(store_id, expr->GetReceiverTypes()); | 609 oracle()->CountReceiverTypes(store_id, expr->GetReceiverTypes()); |
| 609 expr->set_type(oracle()->CountType(expr->CountBinOpFeedbackId())); | 610 expr->set_type(oracle()->CountType(expr->CountBinOpFeedbackId())); |
| 610 // TODO(rossberg): merge the count type with the generic expression type. | 611 // TODO(rossberg): merge the count type with the generic expression type. |
| 611 | 612 |
| 612 RECURSE(Visit(expr->expression())); | 613 RECURSE(Visit(expr->expression())); |
| 613 | 614 |
| 614 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Number(isolate_))); | 615 NarrowType(expr, Bounds(Type::Smi(zone()), Type::Number(zone()))); |
| 615 | 616 |
| 616 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 617 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
| 617 if (proxy != NULL && proxy->var()->IsStackAllocated()) { | 618 if (proxy != NULL && proxy->var()->IsStackAllocated()) { |
| 618 store_.Seq(variable_index(proxy->var()), Effect(expr->bounds())); | 619 store_.Seq(variable_index(proxy->var()), Effect(expr->bounds())); |
| 619 } | 620 } |
| 620 } | 621 } |
| 621 | 622 |
| 622 | 623 |
| 623 void AstTyper::VisitBinaryOperation(BinaryOperation* expr) { | 624 void AstTyper::VisitBinaryOperation(BinaryOperation* expr) { |
| 624 // Collect type feedback. | 625 // Collect type feedback. |
| 625 Handle<Type> type, left_type, right_type; | 626 Type* type; |
| 627 Type* left_type; |
| 628 Type* right_type; |
| 626 Maybe<int> fixed_right_arg; | 629 Maybe<int> fixed_right_arg; |
| 627 Handle<AllocationSite> allocation_site; | 630 Handle<AllocationSite> allocation_site; |
| 628 oracle()->BinaryType(expr->BinaryOperationFeedbackId(), | 631 oracle()->BinaryType(expr->BinaryOperationFeedbackId(), |
| 629 &left_type, &right_type, &type, &fixed_right_arg, | 632 &left_type, &right_type, &type, &fixed_right_arg, |
| 630 &allocation_site, expr->op()); | 633 &allocation_site, expr->op()); |
| 631 NarrowLowerType(expr, type); | 634 NarrowLowerType(expr, type); |
| 632 NarrowLowerType(expr->left(), left_type); | 635 NarrowLowerType(expr->left(), left_type); |
| 633 NarrowLowerType(expr->right(), right_type); | 636 NarrowLowerType(expr->right(), right_type); |
| 634 expr->set_allocation_site(allocation_site); | 637 expr->set_allocation_site(allocation_site); |
| 635 expr->set_fixed_right_arg(fixed_right_arg); | 638 expr->set_fixed_right_arg(fixed_right_arg); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 648 Effects left_effects = EnterEffects(); | 651 Effects left_effects = EnterEffects(); |
| 649 RECURSE(Visit(expr->left())); | 652 RECURSE(Visit(expr->left())); |
| 650 ExitEffects(); | 653 ExitEffects(); |
| 651 Effects right_effects = EnterEffects(); | 654 Effects right_effects = EnterEffects(); |
| 652 RECURSE(Visit(expr->right())); | 655 RECURSE(Visit(expr->right())); |
| 653 ExitEffects(); | 656 ExitEffects(); |
| 654 left_effects.Alt(right_effects); | 657 left_effects.Alt(right_effects); |
| 655 store_.Seq(left_effects); | 658 store_.Seq(left_effects); |
| 656 | 659 |
| 657 NarrowType(expr, Bounds::Either( | 660 NarrowType(expr, Bounds::Either( |
| 658 expr->left()->bounds(), expr->right()->bounds(), isolate_)); | 661 expr->left()->bounds(), expr->right()->bounds(), zone())); |
| 659 break; | 662 break; |
| 660 } | 663 } |
| 661 case Token::BIT_OR: | 664 case Token::BIT_OR: |
| 662 case Token::BIT_AND: { | 665 case Token::BIT_AND: { |
| 663 RECURSE(Visit(expr->left())); | 666 RECURSE(Visit(expr->left())); |
| 664 RECURSE(Visit(expr->right())); | 667 RECURSE(Visit(expr->right())); |
| 665 Handle<Type> upper = Type::Union( | 668 Type* upper = Type::Union( |
| 666 expr->left()->bounds().upper, expr->right()->bounds().upper, | 669 expr->left()->bounds().upper, expr->right()->bounds().upper, zone()); |
| 667 isolate_); | 670 if (!upper->Is(Type::Signed32())) upper = Type::Signed32(zone()); |
| 668 if (!upper->Is(Type::Signed32())) | 671 Type* lower = Type::Intersect(Type::Smi(zone()), upper, zone()); |
| 669 upper = Type::Signed32(isolate_); | |
| 670 Handle<Type> lower = | |
| 671 Type::Intersect(Type::Smi(isolate_), upper, isolate_); | |
| 672 NarrowType(expr, Bounds(lower, upper)); | 672 NarrowType(expr, Bounds(lower, upper)); |
| 673 break; | 673 break; |
| 674 } | 674 } |
| 675 case Token::BIT_XOR: | 675 case Token::BIT_XOR: |
| 676 case Token::SHL: | 676 case Token::SHL: |
| 677 case Token::SAR: | 677 case Token::SAR: |
| 678 RECURSE(Visit(expr->left())); | 678 RECURSE(Visit(expr->left())); |
| 679 RECURSE(Visit(expr->right())); | 679 RECURSE(Visit(expr->right())); |
| 680 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Signed32(isolate_))); | 680 NarrowType(expr, Bounds(Type::Smi(zone()), Type::Signed32(zone()))); |
| 681 break; | 681 break; |
| 682 case Token::SHR: | 682 case Token::SHR: |
| 683 RECURSE(Visit(expr->left())); | 683 RECURSE(Visit(expr->left())); |
| 684 RECURSE(Visit(expr->right())); | 684 RECURSE(Visit(expr->right())); |
| 685 // TODO(rossberg): The upper bound would be Unsigned32, but since there | 685 // TODO(rossberg): The upper bound would be Unsigned32, but since there |
| 686 // is no 'positive Smi' type for the lower bound, we use the smallest | 686 // is no 'positive Smi' type for the lower bound, we use the smallest |
| 687 // union of Smi and Unsigned32 as upper bound instead. | 687 // union of Smi and Unsigned32 as upper bound instead. |
| 688 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Number(isolate_))); | 688 NarrowType(expr, Bounds(Type::Smi(zone()), Type::Number(zone()))); |
| 689 break; | 689 break; |
| 690 case Token::ADD: { | 690 case Token::ADD: { |
| 691 RECURSE(Visit(expr->left())); | 691 RECURSE(Visit(expr->left())); |
| 692 RECURSE(Visit(expr->right())); | 692 RECURSE(Visit(expr->right())); |
| 693 Bounds l = expr->left()->bounds(); | 693 Bounds l = expr->left()->bounds(); |
| 694 Bounds r = expr->right()->bounds(); | 694 Bounds r = expr->right()->bounds(); |
| 695 Handle<Type> lower = | 695 Type* lower = |
| 696 l.lower->Is(Type::None()) || r.lower->Is(Type::None()) ? | 696 l.lower->Is(Type::None()) || r.lower->Is(Type::None()) ? |
| 697 Type::None(isolate_) : | 697 Type::None(zone()) : |
| 698 l.lower->Is(Type::String()) || r.lower->Is(Type::String()) ? | 698 l.lower->Is(Type::String()) || r.lower->Is(Type::String()) ? |
| 699 Type::String(isolate_) : | 699 Type::String(zone()) : |
| 700 l.lower->Is(Type::Number()) && r.lower->Is(Type::Number()) ? | 700 l.lower->Is(Type::Number()) && r.lower->Is(Type::Number()) ? |
| 701 Type::Smi(isolate_) : Type::None(isolate_); | 701 Type::Smi(zone()) : Type::None(zone()); |
| 702 Handle<Type> upper = | 702 Type* upper = |
| 703 l.upper->Is(Type::String()) || r.upper->Is(Type::String()) ? | 703 l.upper->Is(Type::String()) || r.upper->Is(Type::String()) ? |
| 704 Type::String(isolate_) : | 704 Type::String(zone()) : |
| 705 l.upper->Is(Type::Number()) && r.upper->Is(Type::Number()) ? | 705 l.upper->Is(Type::Number()) && r.upper->Is(Type::Number()) ? |
| 706 Type::Number(isolate_) : Type::NumberOrString(isolate_); | 706 Type::Number(zone()) : Type::NumberOrString(zone()); |
| 707 NarrowType(expr, Bounds(lower, upper)); | 707 NarrowType(expr, Bounds(lower, upper)); |
| 708 break; | 708 break; |
| 709 } | 709 } |
| 710 case Token::SUB: | 710 case Token::SUB: |
| 711 case Token::MUL: | 711 case Token::MUL: |
| 712 case Token::DIV: | 712 case Token::DIV: |
| 713 case Token::MOD: | 713 case Token::MOD: |
| 714 RECURSE(Visit(expr->left())); | 714 RECURSE(Visit(expr->left())); |
| 715 RECURSE(Visit(expr->right())); | 715 RECURSE(Visit(expr->right())); |
| 716 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Number(isolate_))); | 716 NarrowType(expr, Bounds(Type::Smi(zone()), Type::Number(zone()))); |
| 717 break; | 717 break; |
| 718 default: | 718 default: |
| 719 UNREACHABLE(); | 719 UNREACHABLE(); |
| 720 } | 720 } |
| 721 } | 721 } |
| 722 | 722 |
| 723 | 723 |
| 724 void AstTyper::VisitCompareOperation(CompareOperation* expr) { | 724 void AstTyper::VisitCompareOperation(CompareOperation* expr) { |
| 725 // Collect type feedback. | 725 // Collect type feedback. |
| 726 Handle<Type> left_type, right_type, combined_type; | 726 Type* left_type; |
| 727 Type* right_type; |
| 728 Type* combined_type; |
| 727 oracle()->CompareType(expr->CompareOperationFeedbackId(), | 729 oracle()->CompareType(expr->CompareOperationFeedbackId(), |
| 728 &left_type, &right_type, &combined_type); | 730 &left_type, &right_type, &combined_type); |
| 729 NarrowLowerType(expr->left(), left_type); | 731 NarrowLowerType(expr->left(), left_type); |
| 730 NarrowLowerType(expr->right(), right_type); | 732 NarrowLowerType(expr->right(), right_type); |
| 731 expr->set_combined_type(combined_type); | 733 expr->set_combined_type(combined_type); |
| 732 | 734 |
| 733 RECURSE(Visit(expr->left())); | 735 RECURSE(Visit(expr->left())); |
| 734 RECURSE(Visit(expr->right())); | 736 RECURSE(Visit(expr->right())); |
| 735 | 737 |
| 736 NarrowType(expr, Bounds(Type::Boolean(isolate_))); | 738 NarrowType(expr, Bounds(Type::Boolean(zone()))); |
| 737 } | 739 } |
| 738 | 740 |
| 739 | 741 |
| 740 void AstTyper::VisitThisFunction(ThisFunction* expr) { | 742 void AstTyper::VisitThisFunction(ThisFunction* expr) { |
| 741 } | 743 } |
| 742 | 744 |
| 743 | 745 |
| 744 void AstTyper::VisitDeclarations(ZoneList<Declaration*>* decls) { | 746 void AstTyper::VisitDeclarations(ZoneList<Declaration*>* decls) { |
| 745 for (int i = 0; i < decls->length(); ++i) { | 747 for (int i = 0; i < decls->length(); ++i) { |
| 746 Declaration* decl = decls->at(i); | 748 Declaration* decl = decls->at(i); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 void AstTyper::VisitModuleUrl(ModuleUrl* module) { | 791 void AstTyper::VisitModuleUrl(ModuleUrl* module) { |
| 790 } | 792 } |
| 791 | 793 |
| 792 | 794 |
| 793 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { | 795 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { |
| 794 RECURSE(Visit(stmt->body())); | 796 RECURSE(Visit(stmt->body())); |
| 795 } | 797 } |
| 796 | 798 |
| 797 | 799 |
| 798 } } // namespace v8::internal | 800 } } // namespace v8::internal |
| OLD | NEW |