From 673151f457021c91267cb80db0fa2239ec674102 Mon Sep 17 00:00:00 2001 From: Stephan Seitz <stephan.seitz@fau.de> Date: Tue, 17 Sep 2019 17:25:42 +0200 Subject: [PATCH] Sort headers/global definitions to enable reproducible code generation headers and global_declarations are generated by methods that return sets. So even with the same inputs it is not guaranteed that the same source code is generated since sets do not guarantee a specific order when iterating over them. --- pystencils/backends/cbackend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py index 239f060e..197e21d8 100644 --- a/pystencils/backends/cbackend.py +++ b/pystencils/backends/cbackend.py @@ -87,7 +87,7 @@ def get_global_declarations(ast): visit_node(ast) - return set(global_declarations) + return sorted(set(global_declarations), key=lambda x: str(x)) def get_headers(ast_node: Node) -> Set[str]: @@ -103,7 +103,7 @@ def get_headers(ast_node: Node) -> Set[str]: if isinstance(a, Node): headers.update(get_headers(a)) - return headers + return sorted(headers) # --------------------------------------- Backend Specific Nodes ------------------------------------------------------- -- GitLab