Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Defaults module with JSON schema #499

Merged
merged 57 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ad9a900
Add ocplib-json-typed dependency
sim642 Dec 10, 2021
1105641
Add JSON validation attempt
sim642 Dec 10, 2021
bcc82b4
Add recursive validation of JSON schema objects
sim642 Dec 10, 2021
6db73d6
Try JSON schema generation from defaults
sim642 Dec 10, 2021
5141f32
Rewrite defaults JSON schema generation properly
sim642 Dec 10, 2021
4a282a1
Switch from ocplib-json-typed to json-data-encoding
sim642 Dec 13, 2021
67bf73e
Add default values to generated schema
sim642 Dec 13, 2021
efa5ee0
Add schema for array elements
sim642 Dec 13, 2021
1764488
Add element schema to phases
sim642 Dec 13, 2021
0fd4ddb
Remove broken old-style phases
sim642 Dec 13, 2021
233360d
Remove special case for old-style ana.activated from JSON schema
sim642 Dec 13, 2021
bc6b2ee
Add category descriptions to generated JSON schema
sim642 Dec 13, 2021
c74b4bc
Add defaults object generation from JSON schema
sim642 Dec 13, 2021
0db5c60
Change GobConfig.set_value to preserve order
sim642 Dec 13, 2021
75f886b
Remove unused GobConfig json path copy from JsonSchema2
sim642 Dec 13, 2021
02fba60
Fix integer JSON schema generation
sim642 Dec 13, 2021
def40ab
Add schema conversion to all required fields
sim642 Dec 13, 2021
3ee612a
Remove category description from JSON schema root
sim642 Dec 13, 2021
bdb317d
Add missing cases to encoding_of_schema_element
sim642 Dec 14, 2021
282751e
Add new JSON schema validation to options, including --conf
sim642 Dec 14, 2021
79f39d5
Reverse Defaults and GobConfig dependency
sim642 Dec 14, 2021
60c368e
Create Options module
sim642 Dec 14, 2021
22bc7f5
Move defaults to schema conversion to Options
sim642 Dec 14, 2021
077ce0c
Remove unused schema string from JsonSchema2
sim642 Dec 14, 2021
8067e0a
Refactor element_category_of_defaults_json
sim642 Dec 14, 2021
ea5fded
Refactor schema_of_defaults_json
sim642 Dec 14, 2021
51e0ca7
Refactor schema_require_all
sim642 Dec 14, 2021
836bb7e
Reverse defaults to fix schema order
sim642 Dec 14, 2021
a4ed797
Refactor schema_defaults
sim642 Dec 14, 2021
8d142d2
Refactor schema generation
sim642 Dec 14, 2021
2f86672
Register json-data-encoding exception printers
sim642 Dec 15, 2021
0ccfe38
Extract JSON schema Validator functor
sim642 Dec 15, 2021
f949d13
Add --options and --all-options
sim642 Dec 15, 2021
45e92f8
Add schema_to_yojson and schema_of_yojson
sim642 Dec 15, 2021
cb3b00c
Fix exception names in json-data-encoding printer
sim642 Dec 15, 2021
2bf48b3
Add parsing of options JSON schema
sim642 Dec 15, 2021
de313c4
Merge branch 'master' into json-schema
sim642 Dec 15, 2021
89a56a1
Use new JSON schema validation
sim642 Dec 15, 2021
80acec9
Remove new global schema
sim642 Dec 15, 2021
eac376f
Disable require-all schema and defaults generation
sim642 Dec 15, 2021
834de35
Use default options from schema
sim642 Dec 15, 2021
e78e144
Use ppx_blob to embed JSON schema
sim642 Dec 15, 2021
bcd9762
Document options JSON schema usage in VSCode
sim642 Dec 15, 2021
7e0cb95
Add ppx_blob >= 0.6.0 lower bound
sim642 Dec 16, 2021
4ac625f
Erasae Json_Schema of_json argument implicitly to improve json-data-e…
sim642 Dec 16, 2021
d85718f
Merge branch 'master' into json-schema
sim642 Dec 22, 2021
74509ff
Regenerate options JSON schema from master changes
sim642 Dec 22, 2021
2d562c0
Remove old JsonSchema module (PR #499)
sim642 Dec 22, 2021
df56976
Rename new JsonSchema2 to JsonSchema (PR #499)
sim642 Dec 22, 2021
f2c2279
Remove commented out JsonSchema validation
sim642 Dec 22, 2021
4918cca
Reimplement options shorthand using Options
sim642 Dec 22, 2021
042c323
Remove old Defaults module (PR #499)
sim642 Dec 22, 2021
b843a0e
Remove Defaults to schema conversion (PR #499)
sim642 Dec 22, 2021
e8bbece
Remove now unused GobConfig.build_config
sim642 Dec 22, 2021
249360b
Implement string enum validation in JSON
sim642 Dec 22, 2021
cdd9719
Add string enums to options schema (PR #499)
sim642 Dec 22, 2021
1f1deeb
Fix JSON schema indentation
sim642 Dec 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/user-guide/configuring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Configuring

## JSON conf files

### JSON schema

#### VSCode
In `.vscode/settings.json` add the following:
```json
{
"json.schemas": [
{
"fileMatch": [
"/conf/*.json"
],
"url": "/src/util/options.schema.json"
}
]
}
```
2 changes: 2 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
(ppx_distr_guards (>= 0.2))
ppx_deriving
ppx_deriving_yojson
(ppx_blob (>= 0.6.0))
(ocaml-monadic (>= 0.5))
(ounit2 :with-test)
(odoc :with-doc)
dune-site
json-data-encoding
(sha (>= 1.12))
(conf-gmp (>= 3)) ; only needed transitively, but they don't have lower bound, which is needed on MacOS
(conf-ruby :with-test)
Expand Down
2 changes: 2 additions & 0 deletions goblint.opam
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ depends: [
"ppx_distr_guards" {>= "0.2"}
"ppx_deriving"
"ppx_deriving_yojson"
"ppx_blob" {>= "0.6.0"}
"ocaml-monadic" {>= "0.5"}
"ounit2" {with-test}
"odoc" {with-doc}
"dune-site"
"json-data-encoding"
"sha" {>= "1.12"}
"conf-gmp" {>= "3"}
"conf-ruby" {with-test}
Expand Down
9 changes: 9 additions & 0 deletions goblint.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ homepage: "https://goblint.in.tum.de"
doc: "https://goblint.readthedocs.io/en/latest/"
bug-reports: "https://github.com/goblint/analyzer/issues"
depends: [
"angstrom" {= "0.15.0"}
"apron" {= "v0.9.13"}
"astring" {= "0.8.5" & with-doc}
"base-bigarray" {= "base"}
Expand All @@ -26,12 +27,15 @@ depends: [
"base-unix" {= "base"}
"batteries" {= "3.4.0"}
"benchmark" {= "1.6" & with-test}
"bigarray-compat" {= "1.0.0"}
"bigstringaf" {= "0.7.0"}
"biniou" {= "1.2.1"}
"camlidl" {= "1.09"}
"cmdliner" {= "1.0.4" & with-doc}
"conf-gmp" {= "3"}
"conf-mpfr" {= "2"}
"conf-perl" {= "1"}
"conf-pkg-config" {= "2"}
"conf-ruby" {= "1.0.0" & with-test}
"cppo" {= "1.6.7"}
"dune" {= "2.9.1"}
Expand All @@ -41,6 +45,7 @@ depends: [
"fmt" {= "0.9.0" & with-doc}
"fpath" {= "0.7.3" & with-doc}
"goblint-cil" {= "1.8.2"}
"json-data-encoding" {= "0.10"}
"logs" {= "0.7.0" & with-doc}
"mlgmpidl" {= "1.2.13"}
"num" {= "1.4"}
Expand All @@ -51,11 +56,13 @@ depends: [
"ocaml-migrate-parsetree" {= "2.2.0" & with-doc}
"ocaml-monadic" {= "0.5"}
"ocaml-options-vanilla" {= "1"}
"ocaml-syntax-shims" {= "1.0.0"}
"ocamlbuild" {= "0.14.0"}
"ocamlfind" {= "1.9.1"}
"odoc" {= "2.0.2" & with-doc}
"odoc-parser" {= "0.9.0" & with-doc}
"ounit2" {= "2.2.4" & with-test}
"ppx_blob" {= "0.7.2"}
"ppx_derivers" {= "1.2.1"}
"ppx_deriving" {= "5.2.1"}
"ppx_deriving_yojson" {= "3.6.1"}
Expand All @@ -68,9 +75,11 @@ depends: [
"sexplib0" {= "v0.14.0"}
"sha" {= "1.15.1"}
"stdlib-shims" {= "0.3.0"}
"stringext" {= "1.6.0"}
"topkg" {= "1.0.3" & with-doc}
"tyxml" {= "4.4.0" & with-doc}
"uchar" {= "0.0.2" & with-doc}
"uri" {= "4.2.0"}
"uutf" {= "1.0.2" & with-doc}
"yojson" {= "1.7.0"}
"zarith" {= "1.12"}
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ nav:
- Home: index.md
- 'User guide':
- user-guide/running.md
- user-guide/configuring.md
- user-guide/inspecting.md
- user-guide/annotating.md
- 'Developer guide':
Expand Down
5 changes: 3 additions & 2 deletions src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(public_name goblint.lib)
(wrapped false)
(modules :standard \ goblint mainarinc maindomaintest mainspec privPrecCompare apronPrecCompare)
(libraries goblint.sites goblint-cil.all-features batteries.unthreaded qcheck-core.runner sha
(libraries goblint.sites goblint-cil.all-features batteries.unthreaded qcheck-core.runner sha json-data-encoding
; Conditionally compile based on whether apron optional dependency is installed or not.
; Alternative dependencies seem like the only way to optionally depend on optional dependencies.
; See: https://dune.readthedocs.io/en/stable/concepts.html#alternative-dependencies.
Expand All @@ -35,7 +35,8 @@
)
(preprocess
(staged_pps ppx_deriving.std ppx_deriving_yojson
ppx_distr_guards ocaml-monadic))
ppx_distr_guards ocaml-monadic ppx_blob))
(preprocessor_deps (file util/options.schema.json))
)

; Workaround for alternative dependencies with unqualified subdirs.
Expand Down
2 changes: 1 addition & 1 deletion src/maindomaintest.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open! Defaults (* Enums / ... need initialized conf *)
(* open! Defaults (* Enums / ... need initialized conf *) *)

module type FiniteSetElems =
sig
Expand Down
18 changes: 8 additions & 10 deletions src/maingoblint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

open Prelude
open GobConfig
open Defaults
open Printf
open Goblintutil

Expand Down Expand Up @@ -83,10 +82,10 @@ let option_spec_list =
set_bool "dbg.print_dead_code" true;
set_string "result" "sarif"
in
let defaults_spec_list = List.map (fun (_, (name, (_, _))) ->
let defaults_spec_list = List.map (fun path ->
(* allow "--option value" as shorthand for "--set option value" *)
("--" ^ name, Arg.String (set_auto name), "")
) !Defaults.registrar
("--" ^ path, Arg.String (set_auto path), "")
) Options.paths
in
let tmp_arg = ref "" in
[ "-o" , Arg.String (set_string "outfile"), ""
Expand All @@ -100,8 +99,8 @@ let option_spec_list =
; "--conf" , Arg.String merge_file, ""
; "--writeconf" , Arg.String (fun fn -> writeconffile := fn), ""
; "--version" , Arg.Unit print_version, ""
; "--print_options" , Arg.Unit (fun _ -> printCategory stdout Std; exit 0), ""
; "--print_all_options" , Arg.Unit (fun _ -> printAllCategories stdout; exit 0), ""
; "--print_options" , Arg.Unit (fun () -> Options.print_options (); exit 0), ""
; "--print_all_options" , Arg.Unit (fun () -> Options.print_all_options (); exit 0), ""
; "--trace" , Arg.String set_trace, ""
; "--tracevars" , add_string Tracing.tracevars, ""
; "--tracelocs" , add_int Tracing.tracelocs, ""
Expand Down Expand Up @@ -362,13 +361,12 @@ let do_analyze change_info merged_AST =
Printexc.raise_with_backtrace e backtrace (* re-raise with captured inner backtrace *)
(* Cilfacade.current_file := ast'; *)
in
(* old style is ana.activated = [phase_1, ...] with phase_i = [ana_1, ...]
new style (Goblintutil.phase_config = true) is phases[i].ana.activated = [ana_1, ...]
(* new style is phases[i].ana.activated = [ana_1, ...]
phases[i].ana.x overwrites setting ana.x *)
let num_phases =
let np,na,nt = Tuple3.mapn (List.length % get_list) ("phases", "ana.activated", "trans.activated") in
phase_config := np > 0; (* TODO what about wrong usage like { phases = [...], ana.activated = [...] }? should child-lists add to parent-lists? *)
if get_bool "dbg.verbose" then print_endline @@ "Using " ^ if !phase_config then "new" else "old" ^ " format for phases!";
(* TODO what about wrong usage like { phases = [...], ana.activated = [...] }? should child-lists add to parent-lists? *)
if get_bool "dbg.verbose" then print_endline @@ "Using new format for phases!";
if np = 0 && na = 0 && nt = 0 then failwith "No phases and no activated analyses or transformations!";
max np 1
in
Expand Down
Loading