rescript-lang/reanalyze

Awkward record field dead attribute placement with unusual record formatting

Closed this issue · 3 comments

Running reanalyze 389dd68 on Goblint goblint/analyzer@a544002 revealed the following.

Using -write, record field dead attributes are placed quite awkwardly if the record type is formatted as follows:

type ('d,'g,'c,'v) ctx =
  { ask      : 'a. 'a Queries.t -> 'a Queries.result (* Inlined Queries.ask *)
  ; emit     : Events.t -> unit
  ; node     : MyCFG.node
  ; prev_node: MyCFG.node
  ; control_context : Obj.t (** (Control.get_spec ()) context, represented type: unit -> (Control.get_spec ()).C.t *)
  ; [@dead "ctx.control_context"]  context  : unit -> 'c (** current Spec context *)
  ; edge     : MyCFG.edge
  ; local    : 'd
  ; global   : 'v -> 'g
  ; presub   : string -> Obj.t (** raises [Not_found] if such dependency analysis doesn't exist *)
  ; postsub  : string -> Obj.t (** raises [Not_found] if such dependency analysis doesn't exist *)
  ; [@dead "ctx.postsub"]  spawn    : lval option -> varinfo -> exp list -> unit
  ; split    : 'd -> Events.t list -> unit
  ; sideg    : 'v -> 'g -> unit
  }

I guess the attribute gets placed after the ;. It might just be the fault of such weird record formatting we have in a handful of places and not worth fixing in reanalyze, but I thought I'd open an issue about every observation regardless.

Indeed OCaml syntax support is lagging a bit behind ReScript syntax support. Could be revamped.

Looking at this again, reanalyze starts from location info in the typed AST, and has no way of knowing how you format your code.
Would you try to just format this specific code fragment using ocamlformat and see if it works fine.
There's no plan to support every possible formatting, but at least the result of ocamlformat should be supported.

Closing this as that specific formatting is not supported.