Skip to content

Commit 954d633

Browse files
committed
transpile: make TypedAstContext::macro_{invocations,expansions,expansion_test} into IndexMaps instead of HashMaps
Previously, `macro_invocations` was a `HashMap`, and thus iterating through it was unordered, which populated the `Vec<CExprId>` of `macro_expansions` non-deterministically, which then resulted in non-deterministic output from `--translate-const-macros conservative`. I also changed the other `macro_*` maps to `IndexMap`, as many other maps in `TypedAstContext` are already `IndexMap`s, too, and it's likely that we want these stably ordered and deterministic.
1 parent a962605 commit 954d633

File tree

1 file changed

+6
-6
lines changed
  • c2rust-transpile/src/c_ast

1 file changed

+6
-6
lines changed

c2rust-transpile/src/c_ast/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ pub struct TypedAstContext {
7171
pub label_names: IndexMap<CLabelId, Rc<str>>,
7272

7373
// map expressions to the stack of macros they were expanded from
74-
pub macro_invocations: HashMap<CExprId, Vec<CDeclId>>,
74+
pub macro_invocations: IndexMap<CExprId, Vec<CDeclId>>,
7575

7676
// map macro decls to the expressions they expand to
77-
pub macro_expansions: HashMap<CDeclId, Vec<CExprId>>,
77+
pub macro_expansions: IndexMap<CDeclId, Vec<CExprId>>,
7878

7979
// map expressions to the text of the macro invocation they expanded from,
8080
// if any
81-
pub macro_expansion_text: HashMap<CExprId, String>,
81+
pub macro_expansion_text: IndexMap<CExprId, String>,
8282

8383
pub comments: Vec<Located<String>>,
8484

@@ -178,9 +178,9 @@ impl TypedAstContext {
178178
file_map,
179179
include_map,
180180
parents: HashMap::new(),
181-
macro_invocations: HashMap::new(),
182-
macro_expansions: HashMap::new(),
183-
macro_expansion_text: HashMap::new(),
181+
macro_invocations: Default::default(),
182+
macro_expansions: Default::default(),
183+
macro_expansion_text: Default::default(),
184184
label_names: Default::default(),
185185

186186
comments: Vec::new(),

0 commit comments

Comments
 (0)