Reorder Rust file declarations to match OCaml source order. Use when porting OCaml to Rust and declarations are out of order, or when asked to fix ordering to match OCaml.
Reorder declarations in a Rust port file to exactly match the OCaml source file order.
The entire workflow MUST be run in a subagent. You MUST follow this sequence of steps sequentially and exactly. Don't come up with your own smart way. Trust me, you will always screw up when you do that. NO CREATIVITY ALLOWED.
Read the Rust .rs file and manually list every declaration (struct, enum, type, mod, fn) with their names. fn within a toplevel should be considered as toplevel as well. You must include every single toplevel item, regardless of their visibility. You must not list non-toplevel items, such as members of an enum. Don't filter anything. Write to rust_decls.md in the . At this stage, rust_decls.md must be a markdown file of list . .
implRead the OCaml .ml file. For each Rust declaration in rust_decls.md, find which OCaml declaration it corresponds to by matching names (considering naming conventions). You must inspect the result carefully. Having exact match doesn't mean that you found the declaration in the ocaml code, due to naming convention differences. Write down the mapping with the OCaml line number inside in rust_decls.md. You are only allowed to add the ocaml line number to the left of the name. e.g.
- * struct Foo
+ * (1337) struct Foo
- * enum Bar
+ * (42) enum Bar
DO NOT SKIP ITEMS. DO NOT STOP. Work through every single item until every single item has a line number. When you are unsure, ask me. At this stage, rust_decls.md must be a markdown file of list ONLY. ONLY LIST. ONE GIANT LIST ONLY.
Sort your Rust declarations in rust_decls.md based on the line number you found in the last step. Create a sorted list showing the desired final order. Overwrite rust_decls.md with the sorted list. At this stage, rust_decls.md must be a markdown file of list ONLY. ONLY LIST. ONE GIANT LIST ONLY.
Based on the sorted order, create a TODO list where each item is: "- [ ] <Rust declaration name>"
The line number should be removed in this step.
Use TodoWrite to create this checklist. The checklist must be put into the current project directory as order.md. At this stage, order.md must be a markdown file of list ONLY. ONLY list. No title. No comments. No judgement.
For each TODO item in order.md:
DO NOT SKIP ITEMS. DO NOT STOP. Work through every single item.
After all moves complete:
buck2 build <target>