forked from M-Labs/artiq
1
0
Fork 0

compiler: Short-circuit Type.unify() with identical other type

This considerably improves performance; ~15% in terms of total
artiq_run-to-kernel-compiled duration in one test case.
This commit is contained in:
David Nadlinger 2019-12-23 01:27:18 +00:00
parent eebae01503
commit 2c34f0214b
1 changed files with 16 additions and 0 deletions

View File

@ -81,6 +81,8 @@ class TVar(Type):
return root
def unify(self, other):
if other is self:
return
other = other.find()
if self.parent is self:
@ -124,6 +126,8 @@ class TMono(Type):
return self
def unify(self, other):
if other is self:
return
if isinstance(other, TMono) and self.name == other.name:
assert self.params.keys() == other.params.keys()
for param in self.params:
@ -171,6 +175,8 @@ class TTuple(Type):
return self
def unify(self, other):
if other is self:
return
if isinstance(other, TTuple) and len(self.elts) == len(other.elts):
for selfelt, otherelt in zip(self.elts, other.elts):
selfelt.unify(otherelt)
@ -237,6 +243,8 @@ class TFunction(Type):
return self
def unify(self, other):
if other is self:
return
if isinstance(other, TFunction) and \
self.args.keys() == other.args.keys() and \
self.optargs.keys() == other.optargs.keys():
@ -296,6 +304,8 @@ class TCFunction(TFunction):
self.flags = flags
def unify(self, other):
if other is self:
return
if isinstance(other, TCFunction) and \
self.name == other.name:
super().unify(other)
@ -324,6 +334,8 @@ class TRPC(Type):
return self
def unify(self, other):
if other is self:
return
if isinstance(other, TRPC) and \
self.service == other.service and \
self.is_async == other.is_async:
@ -366,6 +378,8 @@ class TBuiltin(Type):
return self
def unify(self, other):
if other is self:
return
if self != other:
raise UnificationError(self, other)
@ -471,6 +485,8 @@ class TValue(Type):
return self
def unify(self, other):
if other is self:
return
if isinstance(other, TVar):
other.unify(self)
elif self != other: