rescript-association / reanalyze

Experimental analyses for ReScript and OCaml: globally dead values/types, exception analysis, and termination analysis.
MIT License
277 stars 20 forks source link

Awkward record field dead attribute placement with unusual record formatting #152

Closed sim642 closed 2 years ago

sim642 commented 2 years ago

Running reanalyze https://github.com/rescript-association/reanalyze/commit/389dd682223201b42c33e5c444e5c79e0805adad on Goblint https://github.com/goblint/analyzer/commit/a544002114324a207df72f9e79eb656c3ebe7b5b 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.

cristianoc commented 2 years ago

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

cristianoc commented 2 years ago

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.

cristianoc commented 2 years ago

Closing this as that specific formatting is not supported.