mirror of https://github.com/m-labs/artiq.git
compiler: reduce calls to TypedTreeHasher
We need to check if our inference reached a fixed point. This is checked using hash of the types in the AST, which is very slow. This patch avoids computing the hash if we can make sure that the AST is definitely changed, which is when we parse a new function. For some simple programs with many functions, this can significantly reduce the compile time by up to ~30%.
This commit is contained in:
parent
51d2861e63
commit
4ede58e44b
|
@ -737,6 +737,7 @@ class Stitcher:
|
|||
|
||||
self.embedding_map = EmbeddingMap()
|
||||
self.value_map = defaultdict(lambda: [])
|
||||
self.definitely_changed = False
|
||||
|
||||
def stitch_call(self, function, args, kwargs, callback=None):
|
||||
# We synthesize source code for the initial call so that
|
||||
|
@ -757,14 +758,20 @@ class Stitcher:
|
|||
old_attr_count = None
|
||||
while True:
|
||||
inferencer.visit(self.typedtree)
|
||||
if self.definitely_changed:
|
||||
changed = True
|
||||
self.definitely_changed = False
|
||||
else:
|
||||
typedtree_hash = typedtree_hasher.visit(self.typedtree)
|
||||
attr_count = self.embedding_map.attribute_count()
|
||||
|
||||
if old_typedtree_hash == typedtree_hash and old_attr_count == attr_count:
|
||||
break
|
||||
changed = old_attr_count != attr_count or \
|
||||
old_typedtree_hash != typedtree_hash
|
||||
old_typedtree_hash = typedtree_hash
|
||||
old_attr_count = attr_count
|
||||
|
||||
if not changed:
|
||||
break
|
||||
|
||||
# After we've discovered every referenced attribute, check if any kernel_invariant
|
||||
# specifications refers to ones we didn't encounter.
|
||||
for host_type in self.embedding_map.type_map:
|
||||
|
@ -891,6 +898,9 @@ class Stitcher:
|
|||
return types.TVar()
|
||||
|
||||
def _quote_embedded_function(self, function, flags):
|
||||
# we are now parsing new functions... definitely changed the type
|
||||
self.definitely_changed = True
|
||||
|
||||
if isinstance(function, SpecializedFunction):
|
||||
host_function = function.host_function
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue