From 8cb2215edbdd9ee9faaf89223129f754348082db Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 2 Dec 2015 21:48:14 +0800 Subject: [PATCH] transforms.inferencer: only instantiate RPC function types, not regular. --- artiq/compiler/transforms/inferencer.py | 12 +++++++++--- artiq/compiler/types.py | 4 ++-- lit-test/test/devirtualization/function.py | 2 +- lit-test/test/inferencer/class.py | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 24f3d94b2..8ebe4f5b7 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -104,7 +104,7 @@ class Inferencer(algorithm.Visitor): ] 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, @@ -112,6 +112,9 @@ class Inferencer(algorithm.Visitor): 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 @@ class Inferencer(algorithm.Visitor): 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 @@ class Inferencer(algorithm.Visitor): 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 diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index a20743142..36667b238 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -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) diff --git a/lit-test/test/devirtualization/function.py b/lit-test/test/devirtualization/function.py index 4c1f48544..5c24b492b 100644 --- a/lit-test/test/devirtualization/function.py +++ b/lit-test/test/devirtualization/function.py @@ -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(): diff --git a/lit-test/test/inferencer/class.py b/lit-test/test/inferencer/class.py index a46b2cad6..1249474a0 100644 --- a/lit-test/test/inferencer/class.py +++ b/lit-test/test/inferencer/class.py @@ -15,5 +15,5 @@ c.a # CHECK-L: .f:()->NoneType delay('b) c.f -# CHECK-L: .m:method(fn=(self:)->NoneType delay('d), self=) +# CHECK-L: .m:method(fn=(self:)->NoneType delay('c), self=) c().m()