From d8c81d6d05ad0606dac69193c6db6cfa2f7094af Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Mon, 23 Dec 2019 01:29:13 +0000 Subject: [PATCH] compiler: Other types microoptimisations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Interestingly enough, these actually seem to give a measurable speedup (if small – about 1% improvement out of 6s whole-program compile-time in one particular test case). The previous implementation of is_mono() had also interesting behaviour if `name` wasn't given; it would test only for the presence of any keys specified via keyword arguments, disregarding their values. Looking at uses across the current ARTIQ codebase, I could neither find a case where this would have actually been triggered, nor any rationale for it. With the short-circuited implementation from this commit, is_mono() now checks name/all of params against any specified conditions. --- artiq/compiler/types.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index 1f2a62a05..5299822c3 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -73,7 +73,7 @@ class TVar(Type): # path compression iter = self while iter.__class__ == TVar: - if iter is iter.parent: + if iter is root: break else: iter, iter.parent = iter.parent, root @@ -577,13 +577,15 @@ def is_mono(typ, name=None, **params): if not isinstance(typ, TMono): return False - params_match = True + if name is not None and typ.name != name: + return False + for param in params: if param not in typ.params: return False - params_match = params_match and \ - typ.params[param].find() == params[param].find() - return name is None or (typ.name == name and params_match) + if typ.params[param].find() != params[param].find(): + return False + return True def is_polymorphic(typ): return typ.fold(False, lambda accum, typ: accum or is_var(typ))