forked from M-Labs/artiq
1
0
Fork 0

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
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))