Ast_invariants(3)

✨ Ast_invariants ✨

okay so bestie, this is a page from the OCaml library manual, and honestly? it's a little niche but it's giving compiler internals realness πŸ’… so let's get into it.


πŸ¦‹ NAME πŸ¦‹

Ast_invariants β€” literally just: Check AST invariants. that's the whole vibe check, no cap.

πŸŽ€ Module πŸŽ€

the module is called Ast_invariants, bestie. say it with me. 🌸

πŸ’– Documentation πŸ’–

so the module itself is Module Ast_invariants and its signature is : sig end β€” yeah, it's an anonymous-ish sig situation, that's just how OCamldoc prints it, don't come for me πŸ™ˆ

and what does it do? Check AST invariants. icon behaviour, truly. πŸ‘‘

⚠️ Warning: this module is unstable and it's part of Compiler_libs. so like, use it but know it might shift under you, ngl. unstable means unstable, fr fr.

🌈 the values 🌈

  • val structure : Parsetree.structure -> unit β€” takes a Parsetree.structure and gives you back unit. that's it. that's the whole function. slay. ✨
  • val signature : Parsetree.signature -> unit β€” same energy, but for a Parsetree.signature β†’ unit. 🫢
  • val check_loc_ghost : (Ast_iterator.iterator -> Ast_iterator.iterator -> 'a -> unit) -> 'a -> source_contents:string -> unit β€” okay this one's the main character πŸ‘‘. it checks the invariant of Location.t's loc_ghost field β€” the ones that are stated in location.mli. (yes, location.mli is the source of truth here, go read it, iykyk πŸ’€)

you can run this with -dparsetree-loc-ghost-invariants, which is used slightly in the testsuite β€” but honestly it should be used more, so we can find more of the places where the invariant is broken. like, more coverage bestie, we're begging πŸ₯Ί


lowkey a reminder that check_loc_ghost takes a function of two Ast_iterator.iterator args, then 'a, and a labelled source_contents:string β€” keep those exactly as written, they're load-bearing πŸ’€

and that's the page!! πŸŒΈπŸ¦‹πŸ’œ

sign-off szn: this lil doc was made with OCamldoc, dated 2026-06-22, and it's page Ast_invariants(3) of the OCaml library manual. mwah, go check those invariants πŸ’‹βœ¨

πŸ“¦ where this page comes from