forked from M-Labs/artiq
1
0
Fork 0

transforms.inferencer: only instantiate RPC function types, not regular.

This commit is contained in:
whitequark 2015-12-02 21:48:14 +08:00
parent ffd065961f
commit 8cb2215edb
4 changed files with 13 additions and 7 deletions

View File

@ -104,7 +104,7 @@ class Inferencer(algorithm.Visitor):
] ]
attr_type = object_type.attributes[node.attr] attr_type = object_type.attributes[node.attr]
if types.is_function(attr_type): if types.is_rpc_function(attr_type):
attr_type = types.instantiate(attr_type) attr_type = types.instantiate(attr_type)
self._unify(node.type, attr_type, node.loc, None, self._unify(node.type, attr_type, node.loc, None,
@ -112,6 +112,9 @@ class Inferencer(algorithm.Visitor):
elif types.is_instance(object_type) and \ elif types.is_instance(object_type) and \
node.attr in object_type.constructor.attributes: node.attr in object_type.constructor.attributes:
attr_type = object_type.constructor.attributes[node.attr].find() attr_type = object_type.constructor.attributes[node.attr].find()
if types.is_rpc_function(attr_type):
attr_type = types.instantiate(attr_type)
if types.is_function(attr_type): if types.is_function(attr_type):
# Convert to a method. # Convert to a method.
if len(attr_type.args) < 1: if len(attr_type.args) < 1:
@ -140,7 +143,7 @@ class Inferencer(algorithm.Visitor):
makenotes=makenotes, makenotes=makenotes,
when=" while inferring the type for self argument") when=" while inferring the type for self argument")
attr_type = types.TMethod(object_type, types.instantiate(attr_type)) attr_type = types.TMethod(object_type, attr_type)
if not types.is_var(attr_type): if not types.is_var(attr_type):
self._unify(node.type, attr_type, self._unify(node.type, attr_type,
@ -793,7 +796,10 @@ class Inferencer(algorithm.Visitor):
typ_optargs = typ.optargs typ_optargs = typ.optargs
typ_ret = typ.ret typ_ret = typ.ret
else: else:
typ = types.get_method_function(typ) typ = types.get_method_function(typ)
if types.is_var(typ):
return # not enough info yet
typ_arity = typ.arity() - 1 typ_arity = typ.arity() - 1
typ_args = OrderedDict(list(typ.args.items())[1:]) typ_args = OrderedDict(list(typ.args.items())[1:])
typ_optargs = typ.optargs typ_optargs = typ.optargs

View File

@ -641,11 +641,11 @@ def is_method(typ):
def get_method_self(typ): def get_method_self(typ):
if is_method(typ): if is_method(typ):
return typ.find().params["self"] return typ.find().params["self"].find()
def get_method_function(typ): def get_method_function(typ):
if is_method(typ): if is_method(typ):
return typ.find().params["fn"] return typ.find().params["fn"].find()
def is_value(typ): def is_value(typ):
return isinstance(typ.find(), TValue) return isinstance(typ.find(), TValue)

View File

@ -4,7 +4,7 @@
from artiq.language.core import * from artiq.language.core import *
from artiq.language.types import * from artiq.language.types import *
# CHECK-L: call ()->NoneType delay('b) %local.testbench.entrypoint ; calls testbench.entrypoint # CHECK-L: call ()->NoneType %local.testbench.entrypoint ; calls testbench.entrypoint
@kernel @kernel
def baz(): def baz():

View File

@ -15,5 +15,5 @@ c.a
# CHECK-L: .f:()->NoneType delay('b) # CHECK-L: .f:()->NoneType delay('b)
c.f c.f
# CHECK-L: .m:method(fn=(self:<instance c>)->NoneType delay('d), self=<instance c>) # CHECK-L: .m:method(fn=(self:<instance c>)->NoneType delay('c), self=<instance c>)
c().m() c().m()