From 6459ec4ff4383acfbeda94da450f5fc75f5187f2 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Tue, 29 Nov 2016 16:31:55 -0800 Subject: [PATCH] ppx_compare Annot Reviewed By: cristianoc Differential Revision: D4232367 fbshipit-source-id: d44bd52 --- infer/src/IR/Annot.re | 37 +++++++------------------------------ infer/src/IR/Annot.rei | 17 ++++------------- 2 files changed, 11 insertions(+), 43 deletions(-) diff --git a/infer/src/IR/Annot.re b/infer/src/IR/Annot.re index 92918530d..32711ba8c 100644 --- a/infer/src/IR/Annot.re +++ b/infer/src/IR/Annot.re @@ -23,18 +23,8 @@ let module F = Format; type t = { class_name: string, /** name of the annotation */ parameters: list string /** currently only one string parameter */ -}; - - -/** Compare function for annotations. */ -let compare a1 a2 => { - let n = string_compare a1.class_name a2.class_name; - if (n != 0) { - n - } else { - IList.compare string_compare a1.parameters a2.parameters - } -}; +} +[@@deriving compare]; /** Pretty print an annotation. */ @@ -49,20 +39,10 @@ let module Map = PrettyPrintable.MakePPMap { let module Item = { /** Annotation for one item: a list of annotations with visibility. */ - type nonrec t = list (t, bool); - - /** Compare function for annotation items. */ - let compare ia1 ia2 => { - let cmp (a1, b1) (a2, b2) => { - let n = compare a1 a2; - if (n != 0) { - n - } else { - bool_compare b1 b2 - } - }; - IList.compare cmp ia1 ia2 - }; + /* Don't use nonrec due to https://github.com/janestreet/ppx_compare/issues/2 */ + /* type nonrec t = list (t, bool) [@@deriving compare]; */ + type _t = list (t, bool) [@@deriving compare]; + type t = _t [@@deriving compare]; /** Pretty print an item annotation. */ let pp fmt ann => { @@ -92,10 +72,7 @@ let module Class = { let module Method = { /** Annotation for a method: return value and list of parameters. */ - type t = (Item.t, list Item.t); - - /** Compare function for Method annotations. */ - let compare (ia1, ial1) (ia2, ial2) => IList.compare Item.compare [ia1, ...ial1] [ia2, ...ial2]; + type t = (Item.t, list Item.t) [@@deriving compare]; /** Pretty print a method annotation. */ let pp s fmt (ia, ial) => F.fprintf fmt "%a %s(%a)" Item.pp ia s (pp_seq Item.pp) ial; diff --git a/infer/src/IR/Annot.rei b/infer/src/IR/Annot.rei index 34c3b352e..4b00c4688 100644 --- a/infer/src/IR/Annot.rei +++ b/infer/src/IR/Annot.rei @@ -21,11 +21,8 @@ let module F = Format; type t = { class_name: string, /** name of the annotation */ parameters: list string /** currently only one string parameter */ -}; - - -/** Compare function for annotations. */ -let compare: t => t => int; +} +[@@deriving compare]; /** Pretty print an annotation. */ @@ -36,10 +33,7 @@ let module Map: PrettyPrintable.PPMap with type key = t; let module Item: { /** Annotation for one item: a list of annotations with visibility. */ - type nonrec t = list (t, bool); - - /** Compare function for annotation items. */ - let compare: t => t => int; + type nonrec t = list (t, bool) [@@deriving compare]; /** Pretty print an item annotation. */ let pp: F.formatter => t => unit; @@ -57,10 +51,7 @@ let module Class: {let objc: Item.t; let cpp: Item.t;}; let module Method: { /** Annotation for a method: return value and list of parameters. */ - type t = (Item.t, list Item.t); - - /** Compare function for Method annotations. */ - let compare: t => t => int; + type t = (Item.t, list Item.t) [@@deriving compare]; /** Empty method annotation. */ let empty: t;