Commit da632baa authored by bradnelson's avatar bradnelson Committed by Commit bot

Switch to using Function(Any) for foreign functions, label declarations.

As it turns out checking for bare Type::Function is problematic,
switching to use Type::Function(Type::Any())).

Also labeling the type on foreign function declarations.

BUG= https://code.google.com/p/v8/issues/detail?id=4203
TEST=test-asm-validator
R=aseemgarg@chromium.org
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#33691}
parent 3c56400e
......@@ -908,13 +908,16 @@ void AsmTyper::VisitProperty(Property* expr) {
return;
}
// stdlib.x or foreign.x
VariableProxy* proxy = expr->obj()->AsVariableProxy();
if (proxy != NULL) {
Variable* var = proxy->var();
if (var->location() == VariableLocation::PARAMETER && var->index() == 1) {
// foreign.x is ok.
// foreign.x - Function represent as () -> Any
if (Type::Any()->Is(expected_type_)) {
SetResult(expr, Type::Function(Type::Any(), zone()));
} else {
SetResult(expr, expected_type_);
}
return;
}
}
......@@ -942,6 +945,27 @@ void AsmTyper::VisitCall(Call* expr) {
FunctionType* fun_type = computed_type_->AsFunction();
Type* result_type = fun_type->Result();
ZoneList<Expression*>* args = expr->arguments();
if (Type::Any()->Is(result_type)) {
// For foreign calls.
ZoneList<Expression*>* args = expr->arguments();
for (int i = 0; i < args->length(); ++i) {
Expression* arg = args->at(i);
RECURSE(VisitWithExpectation(
arg, Type::Any(), "foreign call argument expected to be any"));
// Checking for asm extern types explicitly, as the type system
// doesn't correctly check their inheritance relationship.
if (!computed_type_->Is(cache_.kAsmSigned) &&
!computed_type_->Is(cache_.kAsmFixnum) &&
!computed_type_->Is(cache_.kAsmDouble)) {
FAIL(arg,
"foreign call argument expected to be int, double, or fixnum");
}
}
intish_ = 0;
expr->expression()->set_bounds(
Bounds(Type::Function(Type::Any(), zone())));
IntersectResult(expr, expected_type);
} else {
if (fun_type->Arity() != args->length()) {
FAIL(expr, "call with wrong arity");
}
......@@ -980,25 +1004,7 @@ void AsmTyper::VisitCall(Call* expr) {
}
intish_ = 0;
IntersectResult(expr, result_type);
} else if (computed_type_->Is(Type::Any())) {
// For foreign calls.
ZoneList<Expression*>* args = expr->arguments();
for (int i = 0; i < args->length(); ++i) {
Expression* arg = args->at(i);
RECURSE(VisitWithExpectation(arg, Type::Any(),
"foreign call argument expected to be any"));
// Checking for asm extern types explicitly, as the type system
// doesn't correctly check their inheritance relationship.
if (!computed_type_->Is(cache_.kAsmSigned) &&
!computed_type_->Is(cache_.kAsmFixnum) &&
!computed_type_->Is(cache_.kAsmDouble)) {
FAIL(arg,
"foreign call argument expected to be int, double, or fixnum");
}
}
intish_ = kMaxUncombinedAdditiveSteps;
expr->expression()->set_bounds(Bounds(Type::Function()));
IntersectResult(expr, expected_type);
} else {
FAIL(expr, "invalid callee");
}
......
......@@ -16,7 +16,7 @@
#include "test/cctest/expression-type-collector-macros.h"
// Macros for function types.
#define FUNC_BARE_TYPE Bounds(Type::Function())
#define FUNC_FOREIGN_TYPE Bounds(Type::Function(Type::Any(), zone))
#define FUNC_V_TYPE Bounds(Type::Function(Type::Undefined(), zone))
#define FUNC_I_TYPE Bounds(Type::Function(cache.kAsmSigned, zone))
#define FUNC_F_TYPE Bounds(Type::Function(cache.kAsmFloat, zone))
......@@ -1726,7 +1726,7 @@ TEST(ForeignFunction) {
CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) {
CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) {
CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) {
CHECK_VAR(baz, FUNC_BARE_TYPE);
CHECK_VAR(baz, FUNC_FOREIGN_TYPE);
CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum));
CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum));
}
......@@ -1740,9 +1740,9 @@ TEST(ForeignFunction) {
}
}
CHECK_FUNC_TYPES_END_1()
CHECK_EXPR(Assignment, Bounds(Type::Any())) {
CHECK_VAR(baz, Bounds(Type::Any()));
CHECK_EXPR(Property, Bounds(Type::Any())) {
CHECK_EXPR(Assignment, Bounds(FUNC_FOREIGN_TYPE)) {
CHECK_VAR(baz, Bounds(FUNC_FOREIGN_TYPE));
CHECK_EXPR(Property, Bounds(FUNC_FOREIGN_TYPE)) {
CHECK_VAR(foreign, Bounds::Unbounded());
CHECK_EXPR(Literal, Bounds::Unbounded());
}
......@@ -2127,7 +2127,7 @@ TEST(Imports) {
CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) {
CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) {
CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) {
CHECK_VAR(ffunc, FUNC_BARE_TYPE);
CHECK_VAR(ffunc, FUNC_FOREIGN_TYPE);
CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) {
CHECK_VAR(fint, Bounds(cache.kAsmInt));
CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum));
......@@ -2141,7 +2141,7 @@ TEST(Imports) {
CHECK_EXPR(FunctionLiteral, FUNC_D_TYPE) {
CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmDouble)) {
CHECK_EXPR(Call, Bounds(cache.kAsmDouble)) {
CHECK_VAR(ffunc, FUNC_BARE_TYPE);
CHECK_VAR(ffunc, FUNC_FOREIGN_TYPE);
CHECK_VAR(fdouble, Bounds(cache.kAsmDouble));
CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) {
CHECK_VAR(fint, Bounds(cache.kAsmInt));
......@@ -2154,9 +2154,9 @@ TEST(Imports) {
// "use asm";
CHECK_EXPR(Literal, Bounds(Type::String()));
// var func = foreign.foo;
CHECK_EXPR(Assignment, Bounds(Type::Any())) {
CHECK_VAR(ffunc, Bounds(Type::Any()));
CHECK_EXPR(Property, Bounds(Type::Any())) {
CHECK_EXPR(Assignment, Bounds(FUNC_FOREIGN_TYPE)) {
CHECK_VAR(ffunc, Bounds(FUNC_FOREIGN_TYPE));
CHECK_EXPR(Property, Bounds(FUNC_FOREIGN_TYPE)) {
CHECK_VAR(foreign, Bounds::Unbounded());
CHECK_EXPR(Literal, Bounds::Unbounded());
}
......
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