Skip to content

Optimizer seems too restricted #733

@davidism

Description

@davidism

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions