Skip to content

Commit

Permalink
transforms.inferencer: only instantiate RPC function types, not regular.
Browse files Browse the repository at this point in the history
whitequark committed Dec 2, 2015
1 parent ffd0659 commit 8cb2215
Showing 4 changed files with 13 additions and 7 deletions.
12 changes: 9 additions & 3 deletions artiq/compiler/transforms/inferencer.py
Original file line number Diff line number Diff line change
@@ -104,14 +104,17 @@ def makenotes(printer, typea, typeb, loca, locb):
]

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)

self._unify(node.type, attr_type, node.loc, None,
makenotes=makenotes, when=" for attribute '{}'".format(node.attr))
elif types.is_instance(object_type) and \
node.attr in object_type.constructor.attributes:
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):
# Convert to a method.
if len(attr_type.args) < 1:
@@ -140,7 +143,7 @@ def makenotes(printer, typea, typeb, loca, locb):
makenotes=makenotes,
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):
self._unify(node.type, attr_type,
@@ -793,7 +796,10 @@ def visit_CallT(self, node):
typ_optargs = typ.optargs
typ_ret = typ.ret
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_args = OrderedDict(list(typ.args.items())[1:])
typ_optargs = typ.optargs
4 changes: 2 additions & 2 deletions artiq/compiler/types.py
Original file line number Diff line number Diff line change
@@ -641,11 +641,11 @@ def is_method(typ):

def get_method_self(typ):
if is_method(typ):
return typ.find().params["self"]
return typ.find().params["self"].find()

def get_method_function(typ):
if is_method(typ):
return typ.find().params["fn"]
return typ.find().params["fn"].find()

def is_value(typ):
return isinstance(typ.find(), TValue)
2 changes: 1 addition & 1 deletion lit-test/test/devirtualization/function.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from artiq.language.core 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
def baz():
2 changes: 1 addition & 1 deletion lit-test/test/inferencer/class.py
Original file line number Diff line number Diff line change
@@ -15,5 +15,5 @@ def m(self):
# CHECK-L: .f:()->NoneType delay('b)
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()

0 comments on commit 8cb2215

Please sign in to comment.