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