compiler: Other types microoptimisations

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.
This commit is contained in:
David Nadlinger 2019-12-23 01:29:13 +00:00
parent 2c34f0214b
commit d8c81d6d05
1 changed files with 7 additions and 5 deletions

View File

@ -73,7 +73,7 @@ class TVar(Type):
# path compression # path compression
iter = self iter = self
while iter.__class__ == TVar: while iter.__class__ == TVar:
if iter is iter.parent: if iter is root:
break break
else: else:
iter, iter.parent = iter.parent, root iter, iter.parent = iter.parent, root
@ -577,13 +577,15 @@ def is_mono(typ, name=None, **params):
if not isinstance(typ, TMono): if not isinstance(typ, TMono):
return False return False
params_match = True if name is not None and typ.name != name:
return False
for param in params: for param in params:
if param not in typ.params: if param not in typ.params:
return False return False
params_match = params_match and \ if typ.params[param].find() != params[param].find():
typ.params[param].find() == params[param].find() return False
return name is None or (typ.name == name and params_match) return True
def is_polymorphic(typ): def is_polymorphic(typ):
return typ.fold(False, lambda accum, typ: accum or is_var(typ)) return typ.fold(False, lambda accum, typ: accum or is_var(typ))