Fix: return module items in file order

This affects their UIDs, and the order in which they later get traversed.

In particular, it was affecting the struct names renaming.
This commit is contained in:
Louis Gesbert 2024-08-06 12:41:57 +02:00
parent dbfd05155b
commit acc13867bf
2 changed files with 6 additions and 1 deletions

View File

@ -122,6 +122,10 @@ let rename_ids
let module PathMap = Map.Make (Uid.Path) in
let pctxmap = PathMap.singleton [] ctx in
let pctxmap, structs_map, fields_map, ctx_structs =
(* Warning: the folding order matters here, if a module contains e.g. two
fields with the same name. This fold relies on UIDs, and is thus
dependent on the definition order. Another possibility would be to fold
lexicographically, but the result would be "less intuitive" *)
StructName.Map.fold
(fun name fields (pctxmap, structs_map, fields_map, ctx_structs) ->
let path = StructName.path name in

View File

@ -476,7 +476,8 @@ let get_interface program =
(* Non-metadata blocks are ignored *)
req, acc
in
List.fold_left filter ([], []) program.Ast.program_items
let req, acc = List.fold_left filter ([], []) program.Ast.program_items in
List.rev req, List.rev acc
(** {1 API} *)