Commit 076ec0dd authored by whitequark's avatar whitequark
Browse files

fhdl.visit: fix nondeterminism in visit_Case.

str(value) serializes to e.g. <Constant object at 0x7f3f94f346d8>,
which is randomized due to ASLR even with e.g. PYTHONHASHSEED set.
parent 1e114c76
...@@ -83,7 +83,7 @@ class NodeVisitor: ...@@ -83,7 +83,7 @@ class NodeVisitor:
def visit_Case(self, node): def visit_Case(self, node):
self.visit(node.test) self.visit(node.test)
for v, statements in sorted(node.cases.items(), for v, statements in sorted(node.cases.items(),
key=lambda x: str(x[0])): key=lambda x: -1 if x[0] is "default" else x[0].duid):
self.visit(statements) self.visit(statements)
def visit_Fragment(self, node): def visit_Fragment(self, node):
...@@ -188,7 +188,7 @@ class NodeTransformer: ...@@ -188,7 +188,7 @@ class NodeTransformer:
def visit_Case(self, node): def visit_Case(self, node):
cases = {v: self.visit(statements) cases = {v: self.visit(statements)
for v, statements in sorted(node.cases.items(), for v, statements in sorted(node.cases.items(),
key=lambda x: str(x[0]))} key=lambda x: -1 if x[0] is "default" else x[0].duid)}
r = Case(self.visit(node.test), cases) r = Case(self.visit(node.test), cases)
return r return r
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment