While looking at #476, I noticed that Optimizer only folds certain nodes. For example, Concat nodes are not optimized, but should be. Since all it's doing is trying to call node.as_const, and all Expr nodes define as_const and raise Impossible appropriately, can we safely make fold apply to all nodes that define as_const? Something like:
def generic_visit(self, node):
if hasattr(node, 'as_const'):
try:
return self.fold(node)
except Impossible:
pass
return super().generic_visit(node)
@mitsuhiko
While looking at #476, I noticed that
Optimizeronly folds certain nodes. For example,Concatnodes are not optimized, but should be. Since all it's doing is trying to callnode.as_const, and allExprnodes defineas_constand raiseImpossibleappropriately, can we safely makefoldapply to all nodes that defineas_const? Something like:@mitsuhiko