mirror of https://github.com/m-labs/artiq.git
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:
parent
eebae01503
commit
2c34f0214b
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue