2013-05-27 13:59:20 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "typing.h"
|
|
|
|
|
|
|
|
#include "parser.h" // for CompileTimeValue; TODO(rossberg): should move
|
|
|
|
#include "scopes.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
|
|
AstTyper::AstTyper(CompilationInfo* info)
|
|
|
|
: info_(info),
|
|
|
|
oracle_(
|
|
|
|
Handle<Code>(info->closure()->shared()->code()),
|
|
|
|
Handle<Context>(info->closure()->context()->native_context()),
|
|
|
|
info->isolate(),
|
2013-08-06 12:57:23 +00:00
|
|
|
info->zone()),
|
|
|
|
store_(info->zone()) {
|
2013-09-02 09:27:27 +00:00
|
|
|
InitializeAstVisitor(info->isolate());
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-09 11:48:47 +00:00
|
|
|
#define RECURSE(call) \
|
2013-05-27 13:59:20 +00:00
|
|
|
do { \
|
2013-07-09 11:48:47 +00:00
|
|
|
ASSERT(!visitor->HasStackOverflow()); \
|
2013-05-27 13:59:20 +00:00
|
|
|
call; \
|
|
|
|
if (visitor->HasStackOverflow()) return; \
|
|
|
|
} while (false)
|
|
|
|
|
2013-06-12 17:20:37 +00:00
|
|
|
void AstTyper::Run(CompilationInfo* info) {
|
2013-05-27 13:59:20 +00:00
|
|
|
AstTyper* visitor = new(info->zone()) AstTyper(info);
|
|
|
|
Scope* scope = info->scope();
|
|
|
|
|
|
|
|
// Handle implicit declaration of the function name in named function
|
|
|
|
// expressions before other declarations.
|
|
|
|
if (scope->is_function_scope() && scope->function() != NULL) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(visitor->VisitVariableDeclaration(scope->function()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(visitor->VisitDeclarations(scope->declarations()));
|
|
|
|
RECURSE(visitor->VisitStatements(info->function()->body()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 11:48:47 +00:00
|
|
|
#undef RECURSE
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2013-07-09 11:48:47 +00:00
|
|
|
#define RECURSE(call) \
|
2013-05-27 13:59:20 +00:00
|
|
|
do { \
|
2013-07-09 11:48:47 +00:00
|
|
|
ASSERT(!HasStackOverflow()); \
|
2013-05-27 13:59:20 +00:00
|
|
|
call; \
|
|
|
|
if (HasStackOverflow()) return; \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitStatements(ZoneList<Statement*>* stmts) {
|
|
|
|
for (int i = 0; i < stmts->length(); ++i) {
|
|
|
|
Statement* stmt = stmts->at(i);
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt));
|
2013-08-06 12:57:23 +00:00
|
|
|
if (stmt->IsJump()) break;
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitBlock(Block* stmt) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(VisitStatements(stmt->statements()));
|
2013-08-06 12:57:23 +00:00
|
|
|
if (stmt->labels() != NULL) {
|
|
|
|
store_.Forget(); // Control may transfer here via 'break l'.
|
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitExpressionStatement(ExpressionStatement* stmt) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->expression()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitEmptyStatement(EmptyStatement* stmt) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitIfStatement(IfStatement* stmt) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-05-27 13:59:20 +00:00
|
|
|
if (!stmt->condition()->ToBooleanIsTrue() &&
|
|
|
|
!stmt->condition()->ToBooleanIsFalse()) {
|
|
|
|
stmt->condition()->RecordToBooleanTypeFeedback(oracle());
|
|
|
|
}
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
RECURSE(Visit(stmt->condition()));
|
|
|
|
Effects then_effects = EnterEffects();
|
|
|
|
RECURSE(Visit(stmt->then_statement()));
|
|
|
|
ExitEffects();
|
|
|
|
Effects else_effects = EnterEffects();
|
|
|
|
RECURSE(Visit(stmt->else_statement()));
|
|
|
|
ExitEffects();
|
|
|
|
then_effects.Alt(else_effects);
|
|
|
|
store_.Seq(then_effects);
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitContinueStatement(ContinueStatement* stmt) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// TODO(rossberg): is it worth having a non-termination effect?
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitBreakStatement(BreakStatement* stmt) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// TODO(rossberg): is it worth having a non-termination effect?
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitReturnStatement(ReturnStatement* stmt) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-05-27 13:59:20 +00:00
|
|
|
// TODO(rossberg): we only need this for inlining into test contexts...
|
|
|
|
stmt->expression()->RecordToBooleanTypeFeedback(oracle());
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
RECURSE(Visit(stmt->expression()));
|
|
|
|
// TODO(rossberg): is it worth having a non-termination effect?
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitWithStatement(WithStatement* stmt) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(stmt->expression());
|
|
|
|
RECURSE(stmt->statement());
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitSwitchStatement(SwitchStatement* stmt) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->tag()));
|
2013-08-06 12:57:23 +00:00
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
ZoneList<CaseClause*>* clauses = stmt->cases();
|
|
|
|
SwitchStatement::SwitchType switch_type = stmt->switch_type();
|
2013-08-06 12:57:23 +00:00
|
|
|
Effects local_effects(zone());
|
|
|
|
bool complex_effects = false; // True for label effects or fall-through.
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
for (int i = 0; i < clauses->length(); ++i) {
|
|
|
|
CaseClause* clause = clauses->at(i);
|
2013-08-06 12:57:23 +00:00
|
|
|
Effects clause_effects = EnterEffects();
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
if (!clause->is_default()) {
|
|
|
|
Expression* label = clause->label();
|
|
|
|
SwitchStatement::SwitchType label_switch_type =
|
|
|
|
label->IsSmiLiteral() ? SwitchStatement::SMI_SWITCH :
|
|
|
|
label->IsStringLiteral() ? SwitchStatement::STRING_SWITCH :
|
|
|
|
SwitchStatement::GENERIC_SWITCH;
|
|
|
|
if (switch_type == SwitchStatement::UNKNOWN_SWITCH)
|
|
|
|
switch_type = label_switch_type;
|
|
|
|
else if (switch_type != label_switch_type)
|
|
|
|
switch_type = SwitchStatement::GENERIC_SWITCH;
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
RECURSE(Visit(label));
|
|
|
|
if (!clause_effects.IsEmpty()) complex_effects = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZoneList<Statement*>* stmts = clause->statements();
|
|
|
|
RECURSE(VisitStatements(stmts));
|
|
|
|
ExitEffects();
|
|
|
|
if (stmts->is_empty() || stmts->last()->IsJump()) {
|
|
|
|
local_effects.Alt(clause_effects);
|
|
|
|
} else {
|
|
|
|
complex_effects = true;
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
if (complex_effects) {
|
|
|
|
store_.Forget(); // Reached this in unknown state.
|
|
|
|
} else {
|
|
|
|
store_.Seq(local_effects);
|
|
|
|
}
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
if (switch_type == SwitchStatement::UNKNOWN_SWITCH)
|
|
|
|
switch_type = SwitchStatement::GENERIC_SWITCH;
|
|
|
|
stmt->set_switch_type(switch_type);
|
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-05-27 13:59:20 +00:00
|
|
|
// TODO(rossberg): can we eliminate this special case and extra loop?
|
|
|
|
if (switch_type == SwitchStatement::SMI_SWITCH) {
|
|
|
|
for (int i = 0; i < clauses->length(); ++i) {
|
|
|
|
CaseClause* clause = clauses->at(i);
|
|
|
|
if (!clause->is_default())
|
|
|
|
clause->RecordTypeFeedback(oracle());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 11:06:15 +00:00
|
|
|
void AstTyper::VisitCaseClause(CaseClause* clause) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-05-27 13:59:20 +00:00
|
|
|
if (!stmt->cond()->ToBooleanIsTrue()) {
|
|
|
|
stmt->cond()->RecordToBooleanTypeFeedback(oracle());
|
|
|
|
}
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
// TODO(rossberg): refine the unconditional Forget (here and elsewhere) by
|
|
|
|
// computing the set of variables assigned in only some of the origins of the
|
|
|
|
// control transfer (such as the loop body here).
|
|
|
|
store_.Forget(); // Control may transfer here via looping or 'continue'.
|
|
|
|
RECURSE(Visit(stmt->body()));
|
|
|
|
RECURSE(Visit(stmt->cond()));
|
|
|
|
store_.Forget(); // Control may transfer here via 'break'.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitWhileStatement(WhileStatement* stmt) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-05-27 13:59:20 +00:00
|
|
|
if (!stmt->cond()->ToBooleanIsTrue()) {
|
|
|
|
stmt->cond()->RecordToBooleanTypeFeedback(oracle());
|
|
|
|
}
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
store_.Forget(); // Control may transfer here via looping or 'continue'.
|
|
|
|
RECURSE(Visit(stmt->cond()));
|
|
|
|
RECURSE(Visit(stmt->body()));
|
|
|
|
store_.Forget(); // Control may transfer here via termination or 'break'.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitForStatement(ForStatement* stmt) {
|
|
|
|
if (stmt->init() != NULL) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->init()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
2013-08-06 12:57:23 +00:00
|
|
|
store_.Forget(); // Control may transfer here via looping.
|
2013-05-27 13:59:20 +00:00
|
|
|
if (stmt->cond() != NULL) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-07-19 19:55:09 +00:00
|
|
|
stmt->cond()->RecordToBooleanTypeFeedback(oracle());
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
RECURSE(Visit(stmt->cond()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->body()));
|
2013-05-27 13:59:20 +00:00
|
|
|
if (stmt->next() != NULL) {
|
2013-10-14 12:14:42 +00:00
|
|
|
store_.Forget(); // Control may transfer here via 'continue'.
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->next()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
2013-08-06 12:57:23 +00:00
|
|
|
store_.Forget(); // Control may transfer here via termination or 'break'.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitForInStatement(ForInStatement* stmt) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
|
|
|
stmt->RecordTypeFeedback(oracle());
|
|
|
|
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->enumerable()));
|
2013-08-06 12:57:23 +00:00
|
|
|
store_.Forget(); // Control may transfer here via looping or 'continue'.
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->body()));
|
2013-08-06 12:57:23 +00:00
|
|
|
store_.Forget(); // Control may transfer here via 'break'.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
void AstTyper::VisitForOfStatement(ForOfStatement* stmt) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->iterable()));
|
2013-08-06 12:57:23 +00:00
|
|
|
store_.Forget(); // Control may transfer here via looping or 'continue'.
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->body()));
|
2013-08-06 12:57:23 +00:00
|
|
|
store_.Forget(); // Control may transfer here via 'break'.
|
2013-06-06 14:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
void AstTyper::VisitTryCatchStatement(TryCatchStatement* stmt) {
|
2013-08-06 12:57:23 +00:00
|
|
|
Effects try_effects = EnterEffects();
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->try_block()));
|
2013-08-06 12:57:23 +00:00
|
|
|
ExitEffects();
|
|
|
|
Effects catch_effects = EnterEffects();
|
|
|
|
store_.Forget(); // Control may transfer here via 'throw'.
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->catch_block()));
|
2013-08-06 12:57:23 +00:00
|
|
|
ExitEffects();
|
|
|
|
try_effects.Alt(catch_effects);
|
|
|
|
store_.Seq(try_effects);
|
|
|
|
// At this point, only variables that were reassigned in the catch block are
|
|
|
|
// still remembered.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->try_block()));
|
2013-08-06 12:57:23 +00:00
|
|
|
store_.Forget(); // Control may transfer here via 'throw'.
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->finally_block()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitDebuggerStatement(DebuggerStatement* stmt) {
|
2013-08-06 12:57:23 +00:00
|
|
|
store_.Forget(); // May do whatever.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitFunctionLiteral(FunctionLiteral* expr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-01 09:47:37 +00:00
|
|
|
void AstTyper::VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) {
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitConditional(Conditional* expr) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
|
|
|
expr->condition()->RecordToBooleanTypeFeedback(oracle());
|
|
|
|
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(expr->condition()));
|
2013-08-06 12:57:23 +00:00
|
|
|
Effects then_effects = EnterEffects();
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(expr->then_expression()));
|
2013-08-06 12:57:23 +00:00
|
|
|
ExitEffects();
|
|
|
|
Effects else_effects = EnterEffects();
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(expr->else_expression()));
|
2013-08-06 12:57:23 +00:00
|
|
|
ExitEffects();
|
|
|
|
then_effects.Alt(else_effects);
|
|
|
|
store_.Seq(then_effects);
|
2013-07-09 11:48:47 +00:00
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds::Either(
|
|
|
|
expr->then_expression()->bounds(),
|
|
|
|
expr->else_expression()->bounds(), isolate_));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitVariableProxy(VariableProxy* expr) {
|
2013-08-06 12:57:23 +00:00
|
|
|
Variable* var = expr->var();
|
|
|
|
if (var->IsStackAllocated()) {
|
|
|
|
NarrowType(expr, store_.LookupBounds(variable_index(var)));
|
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitLiteral(Literal* expr) {
|
2013-07-09 11:48:47 +00:00
|
|
|
Type* type = Type::Constant(expr->value(), isolate_);
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(type, isolate_));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) {
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::RegExp(), isolate_));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) {
|
|
|
|
ZoneList<ObjectLiteral::Property*>* properties = expr->properties();
|
|
|
|
for (int i = 0; i < properties->length(); ++i) {
|
|
|
|
ObjectLiteral::Property* prop = properties->at(i);
|
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-05-27 13:59:20 +00:00
|
|
|
if ((prop->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL &&
|
|
|
|
!CompileTimeValue::IsCompileTimeValue(prop->value())) ||
|
|
|
|
prop->kind() == ObjectLiteral::Property::COMPUTED) {
|
2013-07-09 11:48:47 +00:00
|
|
|
if (prop->key()->value()->IsInternalizedString() && prop->emit_store()) {
|
2013-05-27 13:59:20 +00:00
|
|
|
prop->RecordTypeFeedback(oracle());
|
2013-07-09 11:48:47 +00:00
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
RECURSE(Visit(prop->value()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
2013-07-09 11:48:47 +00:00
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::Object(), isolate_));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) {
|
|
|
|
ZoneList<Expression*>* values = expr->values();
|
|
|
|
for (int i = 0; i < values->length(); ++i) {
|
|
|
|
Expression* value = values->at(i);
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(value));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
2013-07-09 11:48:47 +00:00
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::Array(), isolate_));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitAssignment(Assignment* expr) {
|
|
|
|
// TODO(rossberg): Can we clean this up?
|
|
|
|
if (expr->is_compound()) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-05-27 13:59:20 +00:00
|
|
|
Expression* target = expr->target();
|
|
|
|
Property* prop = target->AsProperty();
|
|
|
|
if (prop != NULL) {
|
|
|
|
prop->RecordTypeFeedback(oracle(), zone());
|
2013-08-07 18:45:41 +00:00
|
|
|
expr->RecordTypeFeedback(oracle(), zone());
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
2013-07-11 11:47:05 +00:00
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->binary_operation()));
|
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, expr->binary_operation()->bounds());
|
2013-07-09 11:48:47 +00:00
|
|
|
} else {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
|
|
|
if (expr->target()->IsProperty()) {
|
2013-07-19 19:55:09 +00:00
|
|
|
expr->RecordTypeFeedback(oracle(), zone());
|
|
|
|
}
|
2013-07-19 12:54:27 +00:00
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->target()));
|
|
|
|
RECURSE(Visit(expr->value()));
|
|
|
|
|
2013-07-19 19:55:09 +00:00
|
|
|
NarrowType(expr, expr->value()->bounds());
|
2013-07-19 12:54:27 +00:00
|
|
|
}
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
VariableProxy* proxy = expr->target()->AsVariableProxy();
|
|
|
|
if (proxy != NULL && proxy->var()->IsStackAllocated()) {
|
|
|
|
store_.Seq(variable_index(proxy->var()), Effect(expr->bounds()));
|
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitYield(Yield* expr) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(expr->generator_object()));
|
|
|
|
RECURSE(Visit(expr->expression()));
|
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
// We don't know anything about the result type.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitThrow(Throw* expr) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(expr->exception()));
|
2013-08-06 12:57:23 +00:00
|
|
|
// TODO(rossberg): is it worth having a non-termination effect?
|
2013-07-09 11:48:47 +00:00
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::None(), isolate_));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitProperty(Property* expr) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
|
|
|
expr->RecordTypeFeedback(oracle(), zone());
|
|
|
|
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(expr->obj()));
|
|
|
|
RECURSE(Visit(expr->key()));
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
// We don't know anything about the result type.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitCall(Call* expr) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-07-19 19:55:09 +00:00
|
|
|
Expression* callee = expr->expression();
|
|
|
|
Property* prop = callee->AsProperty();
|
|
|
|
if (prop != NULL) {
|
|
|
|
if (prop->key()->IsPropertyName())
|
|
|
|
expr->RecordTypeFeedback(oracle(), CALL_AS_METHOD);
|
|
|
|
} else {
|
|
|
|
expr->RecordTypeFeedback(oracle(), CALL_AS_FUNCTION);
|
2013-07-19 12:54:27 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->expression()));
|
|
|
|
ZoneList<Expression*>* args = expr->arguments();
|
|
|
|
for (int i = 0; i < args->length(); ++i) {
|
|
|
|
Expression* arg = args->at(i);
|
|
|
|
RECURSE(Visit(arg));
|
|
|
|
}
|
|
|
|
|
|
|
|
VariableProxy* proxy = expr->expression()->AsVariableProxy();
|
|
|
|
if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) {
|
|
|
|
store_.Forget(); // Eval could do whatever to local variables.
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't know anything about the result type.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitCallNew(CallNew* expr) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
|
|
|
expr->RecordTypeFeedback(oracle());
|
|
|
|
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(expr->expression()));
|
2013-05-27 13:59:20 +00:00
|
|
|
ZoneList<Expression*>* args = expr->arguments();
|
|
|
|
for (int i = 0; i < args->length(); ++i) {
|
|
|
|
Expression* arg = args->at(i);
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(arg));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
// We don't know anything about the result type.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitCallRuntime(CallRuntime* expr) {
|
|
|
|
ZoneList<Expression*>* args = expr->arguments();
|
|
|
|
for (int i = 0; i < args->length(); ++i) {
|
|
|
|
Expression* arg = args->at(i);
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(arg));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
2013-07-09 11:48:47 +00:00
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
// We don't know anything about the result type.
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitUnaryOperation(UnaryOperation* expr) {
|
2013-06-21 11:10:06 +00:00
|
|
|
// Collect type feedback.
|
2013-05-27 13:59:20 +00:00
|
|
|
if (expr->op() == Token::NOT) {
|
|
|
|
// TODO(rossberg): only do in test or value context.
|
|
|
|
expr->expression()->RecordToBooleanTypeFeedback(oracle());
|
|
|
|
}
|
2013-07-09 11:48:47 +00:00
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->expression()));
|
|
|
|
|
2013-07-09 11:48:47 +00:00
|
|
|
switch (expr->op()) {
|
|
|
|
case Token::NOT:
|
|
|
|
case Token::DELETE:
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::Boolean(), isolate_));
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
|
|
|
case Token::VOID:
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::Undefined(), isolate_));
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
|
|
|
case Token::TYPEOF:
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::InternalizedString(), isolate_));
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitCountOperation(CountOperation* expr) {
|
2013-08-06 12:57:23 +00:00
|
|
|
// Collect type feedback.
|
2013-05-27 13:59:20 +00:00
|
|
|
expr->RecordTypeFeedback(oracle(), zone());
|
|
|
|
Property* prop = expr->expression()->AsProperty();
|
|
|
|
if (prop != NULL) {
|
|
|
|
prop->RecordTypeFeedback(oracle(), zone());
|
|
|
|
}
|
2013-07-09 11:48:47 +00:00
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->expression()));
|
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_));
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
VariableProxy* proxy = expr->expression()->AsVariableProxy();
|
|
|
|
if (proxy != NULL && proxy->var()->IsStackAllocated()) {
|
|
|
|
store_.Seq(variable_index(proxy->var()), Effect(expr->bounds()));
|
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
|
2013-06-21 11:10:06 +00:00
|
|
|
// Collect type feedback.
|
2013-07-05 08:49:37 +00:00
|
|
|
Handle<Type> type, left_type, right_type;
|
2013-06-21 11:10:06 +00:00
|
|
|
Maybe<int> fixed_right_arg;
|
|
|
|
oracle()->BinaryType(expr->BinaryOperationFeedbackId(),
|
2013-10-04 08:17:11 +00:00
|
|
|
&left_type, &right_type, &type, &fixed_right_arg, expr->op());
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowLowerType(expr, type);
|
|
|
|
NarrowLowerType(expr->left(), left_type);
|
|
|
|
NarrowLowerType(expr->right(), right_type);
|
2013-06-21 11:10:06 +00:00
|
|
|
expr->set_fixed_right_arg(fixed_right_arg);
|
2013-05-27 13:59:20 +00:00
|
|
|
if (expr->op() == Token::OR || expr->op() == Token::AND) {
|
|
|
|
expr->left()->RecordToBooleanTypeFeedback(oracle());
|
|
|
|
}
|
2013-07-09 11:48:47 +00:00
|
|
|
|
|
|
|
switch (expr->op()) {
|
|
|
|
case Token::COMMA:
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->left()));
|
|
|
|
RECURSE(Visit(expr->right()));
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, expr->right()->bounds());
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
|
|
|
case Token::OR:
|
2013-08-06 12:57:23 +00:00
|
|
|
case Token::AND: {
|
|
|
|
Effects left_effects = EnterEffects();
|
|
|
|
RECURSE(Visit(expr->left()));
|
|
|
|
ExitEffects();
|
|
|
|
Effects right_effects = EnterEffects();
|
|
|
|
RECURSE(Visit(expr->right()));
|
|
|
|
ExitEffects();
|
|
|
|
left_effects.Alt(right_effects);
|
|
|
|
store_.Seq(left_effects);
|
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds::Either(
|
|
|
|
expr->left()->bounds(), expr->right()->bounds(), isolate_));
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
2013-08-06 12:57:23 +00:00
|
|
|
}
|
2013-07-09 11:48:47 +00:00
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_AND: {
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->left()));
|
|
|
|
RECURSE(Visit(expr->right()));
|
2013-10-14 12:14:42 +00:00
|
|
|
Handle<Type> upper(
|
|
|
|
Type::Union(
|
|
|
|
expr->left()->bounds().upper, expr->right()->bounds().upper),
|
|
|
|
isolate_);
|
|
|
|
if (!upper->Is(Type::Signed32()))
|
|
|
|
upper = handle(Type::Signed32(), isolate_);
|
|
|
|
Handle<Type> lower(Type::Intersect(
|
|
|
|
handle(Type::Smi(), isolate_), upper), isolate_);
|
|
|
|
NarrowType(expr, Bounds(lower, upper));
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SAR:
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->left()));
|
|
|
|
RECURSE(Visit(expr->right()));
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::Smi(), Type::Signed32(), isolate_));
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
|
|
|
case Token::SHR:
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->left()));
|
|
|
|
RECURSE(Visit(expr->right()));
|
2013-10-14 12:14:42 +00:00
|
|
|
// TODO(rossberg): we could use an UnsignedSmi as lower bound here...
|
|
|
|
NarrowType(expr, Bounds(Type::Unsigned32(), isolate_));
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
|
|
|
case Token::ADD: {
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->left()));
|
|
|
|
RECURSE(Visit(expr->right()));
|
2013-07-11 11:47:05 +00:00
|
|
|
Bounds l = expr->left()->bounds();
|
|
|
|
Bounds r = expr->right()->bounds();
|
|
|
|
Type* lower =
|
2013-10-14 12:14:42 +00:00
|
|
|
l.lower->Is(Type::None()) || r.lower->Is(Type::None()) ?
|
|
|
|
Type::None() :
|
2013-10-11 16:41:34 +00:00
|
|
|
l.lower->Is(Type::String()) || r.lower->Is(Type::String()) ?
|
2013-10-14 12:14:42 +00:00
|
|
|
Type::String() :
|
|
|
|
l.lower->Is(Type::Number()) && r.lower->Is(Type::Number()) ?
|
|
|
|
Type::Smi() : Type::None();
|
2013-07-11 11:47:05 +00:00
|
|
|
Type* upper =
|
2013-10-11 16:41:34 +00:00
|
|
|
l.upper->Is(Type::String()) || r.upper->Is(Type::String()) ?
|
2013-10-14 12:14:42 +00:00
|
|
|
Type::String() :
|
|
|
|
l.upper->Is(Type::Number()) && r.upper->Is(Type::Number()) ?
|
|
|
|
Type::Number() : Type::NumberOrString();
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(lower, upper, isolate_));
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
|
|
|
case Token::MOD:
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->left()));
|
|
|
|
RECURSE(Visit(expr->right()));
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_));
|
2013-07-09 11:48:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitCompareOperation(CompareOperation* expr) {
|
2013-06-21 11:10:06 +00:00
|
|
|
// Collect type feedback.
|
|
|
|
Handle<Type> left_type, right_type, combined_type;
|
|
|
|
oracle()->CompareType(expr->CompareOperationFeedbackId(),
|
|
|
|
&left_type, &right_type, &combined_type);
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowLowerType(expr->left(), left_type);
|
|
|
|
NarrowLowerType(expr->right(), right_type);
|
2013-06-21 11:10:06 +00:00
|
|
|
expr->set_combined_type(combined_type);
|
2013-07-09 11:48:47 +00:00
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
RECURSE(Visit(expr->left()));
|
|
|
|
RECURSE(Visit(expr->right()));
|
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
NarrowType(expr, Bounds(Type::Boolean(), isolate_));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitThisFunction(ThisFunction* expr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitDeclarations(ZoneList<Declaration*>* decls) {
|
|
|
|
for (int i = 0; i < decls->length(); ++i) {
|
|
|
|
Declaration* decl = decls->at(i);
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(decl));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitVariableDeclaration(VariableDeclaration* declaration) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitFunctionDeclaration(FunctionDeclaration* declaration) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(declaration->fun()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitModuleDeclaration(ModuleDeclaration* declaration) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(declaration->module()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitImportDeclaration(ImportDeclaration* declaration) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(declaration->module()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitExportDeclaration(ExportDeclaration* declaration) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitModuleLiteral(ModuleLiteral* module) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(module->body()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitModuleVariable(ModuleVariable* module) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitModulePath(ModulePath* module) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(module->module()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitModuleUrl(ModuleUrl* module) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstTyper::VisitModuleStatement(ModuleStatement* stmt) {
|
2013-07-09 11:48:47 +00:00
|
|
|
RECURSE(Visit(stmt->body()));
|
2013-05-27 13:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|