From 49682d015951d37adf006af1b819eeca5441721d Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 12 Jan 2019 13:17:59 +0000 Subject: [PATCH] Improve Python 3.7 compatibility. async is now a full (non-contextual) keyword. There are two more instances: - artiq/frontend/artiq_client.py - artiq/devices/thorlabs_tcube/driver.py It is not immediately clear how to fix those, so they are left for later work. --- artiq/compiler/embedding.py | 2 +- artiq/compiler/transforms/llvm_ir_generator.py | 4 ++-- artiq/compiler/types.py | 12 ++++++------ artiq/coredevice/comm_kernel.py | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index 539e4ddad..f7cea0b7f 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -1019,7 +1019,7 @@ class Stitcher: function_type = types.TRPC(ret_type, service=self.embedding_map.store_object(host_function), - async=is_async) + is_async=is_async) self.functions[function] = function_type return function_type diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index fdcbe8ab3..b05467743 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -1342,7 +1342,7 @@ class LLVMIRGenerator: llargptr = self.llbuilder.gep(llargs, [ll.Constant(lli32, index)]) self.llbuilder.store(llargslot, llargptr) - if fun_type.async: + if fun_type.is_async: self.llbuilder.call(self.llbuiltin("rpc_send_async"), [llservice, lltagptr, llargs]) else: @@ -1352,7 +1352,7 @@ class LLVMIRGenerator: # Don't waste stack space on saved arguments. self.llbuilder.call(self.llbuiltin("llvm.stackrestore"), [llstackptr]) - if fun_type.async: + if fun_type.is_async: # If this RPC is called using an `invoke` ARTIQ IR instruction, there will be # no other instructions in this basic block. Since this RPC is async, it cannot # possibly raise an exception, so add an explicit jump to the normal successor. diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index 6e5015f48..a8a2e5703 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -311,14 +311,14 @@ class TRPC(Type): :ivar ret: (:class:`Type`) return type :ivar service: (int) RPC service number - :ivar async: (bool) whether the RPC blocks until return + :ivar is_async: (bool) whether the RPC blocks until return """ attributes = OrderedDict() - def __init__(self, ret, service, async=False): + def __init__(self, ret, service, is_async=False): assert isinstance(ret, Type) - self.ret, self.service, self.async = ret, service, async + self.ret, self.service, self.is_async = ret, service, is_async def find(self): return self @@ -326,7 +326,7 @@ class TRPC(Type): def unify(self, other): if isinstance(other, TRPC) and \ self.service == other.service and \ - self.async == other.async: + self.is_async == other.is_async: self.ret.unify(other.ret) elif isinstance(other, TVar): other.unify(self) @@ -343,7 +343,7 @@ class TRPC(Type): def __eq__(self, other): return isinstance(other, TRPC) and \ self.service == other.service and \ - self.async == other.async + self.is_async == other.is_async def __ne__(self, other): return not (self == other) @@ -742,7 +742,7 @@ class TypePrinter(object): return signature elif isinstance(typ, TRPC): return "[rpc{} #{}](...)->{}".format(typ.service, - " async" if typ.async else "", + " async" if typ.is_async else "", self.name(typ.ret, depth + 1)) elif isinstance(typ, TBuiltinFunction): return "".format(typ.name) diff --git a/artiq/coredevice/comm_kernel.py b/artiq/coredevice/comm_kernel.py index 2cadd0d60..6fa4113e4 100644 --- a/artiq/coredevice/comm_kernel.py +++ b/artiq/coredevice/comm_kernel.py @@ -403,7 +403,7 @@ class CommKernel: return msg def _serve_rpc(self, embedding_map): - async = self._read_bool() + is_async = self._read_bool() service_id = self._read_int32() args, kwargs = self._receive_rpc_args(embedding_map) return_tags = self._read_bytes() @@ -413,9 +413,9 @@ class CommKernel: else: service = embedding_map.retrieve_object(service_id) logger.debug("rpc service: [%d]%r%s %r %r -> %s", service_id, service, - (" (async)" if async else ""), args, kwargs, return_tags) + (" (async)" if is_async else ""), args, kwargs, return_tags) - if async: + if is_async: service(*args, **kwargs) return