Skip to content
Permalink
Browse files

Pull out common util logic, Improve diffs for signature mismatches (#44)

Summary:
1. Pulls out a bunch of logic from `rely` into a `common` package.
2. Improves signature mismatch error outputs:
Before:
![image](https://user-images.githubusercontent.com/4126319/49839937-1aa03a80-fd66-11e8-84ba-37d08b9a4448.png)
After:
![image](https://user-images.githubusercontent.com/4126319/49839940-20961b80-fd66-11e8-98c7-6c49edd805b9.png)
Pull Request resolved: #44

Reviewed By: bandersongit

Differential Revision: D13525723

Pulled By: bandersongit

fbshipit-source-id: 0d37336d06af7410cb48c3139241d3f584db4a37
  • Loading branch information...
kpsuperplane authored and facebook-github-bot committed Dec 20, 2018
1 parent 4522970 commit c6da481278aa8a6ea6067dcf08c74f07a46bcbae
Showing with 667 additions and 390 deletions.
  1. +29 −0 .hgignore
  2. +10 −0 common/Common.re
  3. +6 −3 src/rely/Collections.re → common/CommonCollections.re
  4. +1 −2 src/rely/Collections.rei → common/CommonCollections.rei
  5. +1 −0 src/rely/CollectionTypes.re → common/CommonCollectionsTypes.re
  6. 0 src/rely/Errors.re → common/CommonErrors.re
  7. +1 −1 src/rely/Option.re → common/CommonOption.re
  8. +8 −0 common/CommonStrs.re
  9. +7 −0 common/CommonStrsCrypto.re
  10. +9 −10 src/rely/Strings.re → common/CommonStrsDiffs.re
  11. +1 −2 console.json
  12. +1 −0 esy.json
  13. +248 −183 esy.lock.json
  14. +114 −50 esy.lock/index.json
  15. +28 −0 esy.lock/opam-override/ocaml-migrate-parsetree.1.1.0/files/ocaml-migrate-parsetree.1.1.0.patch
  16. +11 −0 esy.lock/opam-override/ocaml-migrate-parsetree.1.1.0/package.json
  17. +36 −0 esy.lock/opam/ppx_deriving_yojson.3.3/opam
  18. +26 −0 esy.lock/opam/ppxfind.1.2/opam
  19. +1 −2 pastel.json
  20. +1 −1 refmterr.json
  21. +8 −8 scripts/esy-prepublish.js
  22. +16 −8 src/refmterr/lib/reportError.re
  23. +1 −1 src/refmterr/tests/test.re
  24. +1 −6 src/refmterr/tests/type_SignatureItemMismatch/type_SignatureItemMismatch_10_expected.txt
  25. +1 −6 src/refmterr/tests/type_SignatureItemMismatch/type_SignatureItemMismatch_11_expected.txt
  26. +25 −0 src/refmterr/tests/type_SignatureItemMismatch/type_SignatureItemMismatch_13.ml
  27. +65 −0 src/refmterr/tests/type_SignatureItemMismatch/type_SignatureItemMismatch_13_expected.txt
  28. +1 −6 src/refmterr/tests/type_SignatureItemMismatch/type_SignatureItemMismatch_8_expected.txt
  29. +1 −6 src/refmterr/tests/type_SignatureItemMismatch/type_SignatureItemMismatch_9_expected.txt
  30. +4 −3 src/rely/Rely.re
  31. +1 −1 src/rely/Snapshot.re
  32. +0 −88 src/rely/Strings.rei
  33. +1 −1 src/rely/dune
  34. +3 −2 src/rely/matchers/MatcherUtils.re
@@ -0,0 +1,29 @@
syntax: glob
.DS_Store

*.cmo
*.out
*.cmi

_build
_release
_esy
node_modules
*.native
*.byte
*.docdir

setup.data
setup.log

/tests/**/*actual.txt

.jenga
*.install
src/refmterr/tests/test.ml

yarn-error.log
**/.merlin

npm-debug.log
yarn-error.log
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/;
module Strs = CommonStrs;
module Option = CommonOption;
module Errors = CommonErrors;
module Collections = CommonCollections;
@@ -77,7 +77,8 @@ module MutableSet = {
/* Non-standard creation */
let empty: unit => t = () => ref(Set_Impl.empty);
let fromList: list(value) => t = list => ref(Set_Impl.fromList(list));
let fromArray: array(value) => t = arr => ref(Set_Impl.fromArray(arr));
let fromArray: array(value) => t =
arr => ref(Set_Impl.fromArray(arr));
/* Non-standard conversion */
let toList: t => list(value) = set => Set_Impl.toList(set^);
let toArray: t => array(value) = set => Set_Impl.toArray(set^);
@@ -98,13 +99,15 @@ module MutableSet = {
set := Set_Impl.delete(value, set^);
();
};
let entries: t => list((value, value)) = set => Set_Impl.entries(set^);
let entries: t => list((value, value)) =
set => Set_Impl.entries(set^);
let forEach: (value => unit, t) => unit =
(fn, set) => {
let _ = Set_Impl.forEach(fn, set^);
();
};
let has: (value, t) => bool = (value, set) => Set_Impl.has(value, set^);
let has: (value, t) => bool =
(value, set) => Set_Impl.has(value, set^);
let values: t => list(value) = toList;
/* Non-standard JavaScript methods - Similar to JavaScript array */
let every: (value => bool, t) => bool =
@@ -16,8 +16,7 @@
* light-weight wrapper around a `ref` of the immutable versions. The
* collections are not truly optimized to be mutable.
*/
open CollectionTypes;

open CommonCollectionsTypes;
module Set: {
module type OrderedType = Core_Set.OrderedType;
module Make: (Ord: OrderedType) => SetMakeResult with type value = Ord.t;
@@ -4,6 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/;

module Core_Set = Set;

module Core_Map = Map;
File renamed without changes.
@@ -17,7 +17,7 @@ let isNone = (o: option('a)): bool =>
let valuex = (o: option('a)): 'a =>
switch (o) {
| Some(value) => value
| None => Errors.fatal("Expected option to have value but got None")
| None => CommonErrors.fatal("Expected option to have value but got None")
};
let valueOr = (default: 'a, o: option('a)): 'a =>
switch (o) {
@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/;
module Diffs = CommonStrsDiffs;
module Crypto = CommonStrsCrypto;
@@ -0,0 +1,7 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/;
let md5 = string => string |> Digest.string |> Digest.to_hex;
@@ -4,12 +4,8 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/;
open Collections;

type difference =
| Old(string)
| New(string)
| Both(string);
module StringMap = CommonCollections.StringMap;
module IntSet = CommonCollections.IntSet;

type operation =
| Delete
@@ -39,6 +35,11 @@ let incrememntCounter = (counter: counter): counter =>
| Many => Many
};

type difference =
| Old(string)
| New(string)
| Both(string);

let split = (splitRe: Str.regexp, s: string): array(string) =>
s
|> Str.full_split(splitRe)
@@ -83,7 +84,7 @@ let diff =
table^,
);
};
let entry = StringMap.getOpt(token, table^) |> Option.valuex;
let entry = StringMap.getOpt(token, table^) |> CommonOption.valuex;
entry.nCounter = incrememntCounter(entry.nCounter);
TableRef(entry);
},
@@ -118,7 +119,7 @@ let diff =
table^,
);
};
let entry = StringMap.getOpt(token, table^) |> Option.valuex;
let entry = StringMap.getOpt(token, table^) |> CommonOption.valuex;
entry.oCounter = incrememntCounter(entry.oCounter);
entry.oTokenNumber = Some(index);
TableRef(entry);
@@ -434,5 +435,3 @@ let printDiffBg =
~newFormatter=s => Pastel.(bg.green(black(s))),
~bothFormatter=s => s,
);

let md5 = string => string |> Digest.string |> Digest.to_hex;
@@ -4,7 +4,7 @@
"description": "No effort, universal logger",
"license": "MIT",
"esy": {
"build": "refmterr dune build -p console",
"build": "dune build -p console",
"install": "esy-installer console.install"
},
"scripts": {
@@ -16,7 +16,6 @@
"dependencies": {
"@opam/dune": "*",
"@esy-ocaml/reason": "^3.3.0",
"refmterr": "*",
"ocaml": ">= 4.2.0 <= 4.7.0"
},
"devDependencies": {
@@ -18,6 +18,7 @@
]
},
"scripts": {
"bootstrap": "esy x bash -cx ./bootstrap.cmd",
"all": "./scripts/run-all.sh",
"test": "./scripts/test.sh"
},

0 comments on commit c6da481

Please sign in to comment.
You can’t perform that action at this time.