File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -986,6 +986,21 @@ impl TypedAstContext {
986986 }
987987 }
988988
989+ /// Sort the top-level declarations with macros coming last.
990+ /// This is needed during conversion so that when recreating macros,
991+ /// we can look up the [`Translation::expr_override_tys`],
992+ /// which are set when the macro expansion expressions are converted.
993+ pub fn sort_top_decls_for_converting ( & mut self ) {
994+ self . c_decls_top . sort_unstable_by_key ( |decl_id| {
995+ let reverse_order = match self . c_decls . get ( decl_id) . unwrap ( ) . kind {
996+ CDeclKind :: MacroFunction { .. } => 0 ,
997+ CDeclKind :: MacroObject { .. } => 1 ,
998+ _ => 2 ,
999+ } ;
1000+ -reverse_order
1001+ } ) ;
1002+ }
1003+
9891004 /// Sort the top-level declarations by file and source location
9901005 /// so that we preserve the ordering of all declarations in each file.
9911006 /// This preserves the order when we emit the converted declarations.
Original file line number Diff line number Diff line change @@ -684,6 +684,8 @@ pub fn translate(
684684 }
685685 }
686686
687+ t. ast_context . sort_top_decls_for_converting ( ) ;
688+
687689 // Export top-level value declarations.
688690 // We do this in a conversion pass and then an insertion pass
689691 // so that the conversion order can differ from the order they're emitted in.
You can’t perform that action at this time.
0 commit comments