From 6718277501d284d229e3b99cb6090b3f0bee737a Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 1 Mar 2014 16:30:37 +0100 Subject: [PATCH] moved futures into threads/ and updated oasis; added benchmark for Conv --- META | 4 +- _oasis | 12 +- _tags | 49 ++-- containers_thread.mldylib | 4 - myocamlbuild.ml | 95 +++---- setup.ml | 245 ++++++++++-------- tests/bench_conv.ml | 19 ++ .../containers_thread.mllib | 0 future.ml => threads/future.ml | 0 future.mli => threads/future.mli | 0 10 files changed, 223 insertions(+), 205 deletions(-) delete mode 100644 containers_thread.mldylib create mode 100644 tests/bench_conv.ml rename containers_thread.mllib => threads/containers_thread.mllib (100%) rename future.ml => threads/future.ml (100%) rename future.mli => threads/future.mli (100%) diff --git a/META b/META index 79591c55..bdfc3a8d 100644 --- a/META +++ b/META @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 6c4b4efc4408717882c37d4e5ee32d91) +# DO NOT EDIT (digest: 9f5c18246e625c62ccb7bf59b1670289) version = "0.1" description = "A bunch of modules, including polymorphic containers." requires = "unix" @@ -11,7 +11,7 @@ exists_if = "containers.cma" package "thread" ( version = "0.1" description = "A bunch of modules, including polymorphic containers." - requires = "containers lwt" + requires = "containers threads lwt" archive(byte) = "containers_thread.cma" archive(byte, plugin) = "containers_thread.cma" archive(native) = "containers_thread.cmxa" diff --git a/_oasis b/_oasis index 3ff99541..7a6e972b 100644 --- a/_oasis +++ b/_oasis @@ -44,14 +44,14 @@ Library "containers" BuildDepends: unix Library "containers_thread" - Path: . + Path: threads/ Modules: Future FindlibName: thread FindlibParent: containers Build$: flag(thread) Install$: flag(thread) BuildDepends: containers,threads - XMETARequires: containers,lwt + XMETARequires: containers,threads,lwt Library "containers_lwt" Path: . @@ -90,6 +90,14 @@ Executable benchs MainIs: benchs.ml BuildDepends: containers,bench +Executable bench_conv + Path: tests/ + Install: false + CompiledObject: native + Build$: flag(bench) + MainIs: bench_conv.ml + BuildDepends: containers,benchmark + Test all Command: $run_tests TestTools: run_tests diff --git a/_tags b/_tags index c1f16037..ad18471f 100644 --- a/_tags +++ b/_tags @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 546f589c3cee93fdadf97d55440d02f8) +# DO NOT EDIT (digest: dcba3d944e29e7f7be0fecd41665b91e) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -55,48 +55,57 @@ "automaton.cmx": for-pack(Containers) "conv.cmx": for-pack(Containers) # Library containers_thread -"containers_thread.cmxs": use_containers_thread -<*.ml{,i}>: package(threads) +"threads/containers_thread.cmxs": use_containers_thread +: use_containers +: package(threads) +: package(unix) # Library containers_lwt "containers_lwt.cmxs": use_containers_lwt "behavior.cmx": for-pack(Containers_lwt) "lwt_automaton.cmx": for-pack(Containers_lwt) +<*.ml{,i}>: use_containers <*.ml{,i}>: package(lwt) <*.ml{,i}>: package(lwt.unix) <*.ml{,i}>: package(unix) -<*.ml{,i}>: use_containers # Library containers_cgi "cgi/containers_cgi.cmxs": use_containers_cgi +: use_containers : package(CamlGI) : package(unix) -: use_containers # Executable benchs +"tests/benchs.native": use_containers "tests/benchs.native": package(bench) "tests/benchs.native": package(unix) -"tests/benchs.native": use_containers : package(bench) +# Executable bench_conv +"tests/bench_conv.native": use_containers +"tests/bench_conv.native": package(benchmark) +"tests/bench_conv.native": package(unix) +: package(benchmark) # Executable run_tests +"tests/run_tests.native": use_containers +"tests/run_tests.native": package(threads) +"tests/run_tests.native": package(oUnit) "tests/run_tests.native": package(lwt) "tests/run_tests.native": package(lwt.unix) -"tests/run_tests.native": package(oUnit) -"tests/run_tests.native": package(threads) "tests/run_tests.native": package(unix) -"tests/run_tests.native": use_containers +: use_containers +: package(threads) +: package(oUnit) : package(lwt) : package(lwt.unix) -: package(oUnit) -: package(threads) : package(unix) -: use_containers # Executable web_pwd -"examples/cgi/web_pwd.byte": package(CamlGI) -"examples/cgi/web_pwd.byte": package(threads) -"examples/cgi/web_pwd.byte": package(unix) -"examples/cgi/web_pwd.byte": use_containers "examples/cgi/web_pwd.byte": use_containers_cgi -: package(CamlGI) -: package(threads) -: package(unix) -: use_containers +"examples/cgi/web_pwd.byte": use_containers +"examples/cgi/web_pwd.byte": package(threads) +"examples/cgi/web_pwd.byte": package(CamlGI) +"examples/cgi/web_pwd.byte": package(unix) : use_containers_cgi +: use_containers +: package(threads) +: package(CamlGI) +: package(unix) # OASIS_STOP +: thread +: thread diff --git a/containers_thread.mldylib b/containers_thread.mldylib deleted file mode 100644 index b10f0345..00000000 --- a/containers_thread.mldylib +++ /dev/null @@ -1,4 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: adff855173c9b92b5478129af7d39e03) -Future -# OASIS_STOP diff --git a/myocamlbuild.ml b/myocamlbuild.ml index 6b1600df..500eb530 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -1,5 +1,5 @@ (* OASIS_START *) -(* DO NOT EDIT (digest: c8b764a938cf7287206f86816566b0b5) *) +(* DO NOT EDIT (digest: e5b7778fcec1af4e8956e90e19fccd18) *) module OASISGettext = struct (* # 22 "src/oasis/OASISGettext.ml" *) @@ -204,27 +204,26 @@ module BaseEnvLight = struct end - let rec var_expand str env = - let buff = - Buffer.create ((String.length str) * 2) - in - Buffer.add_substitute - buff - (fun var -> - try - var_expand (MapString.find var env) env - with Not_found -> - failwith - (Printf.sprintf - "No variable %s defined when trying to expand %S." - var - str)) - str; - Buffer.contents buff - - let var_get name env = - var_expand (MapString.find name env) env + let rec var_expand str = + let buff = + Buffer.create ((String.length str) * 2) + in + Buffer.add_substitute + buff + (fun var -> + try + var_expand (MapString.find var env) + with Not_found -> + failwith + (Printf.sprintf + "No variable %s defined when trying to expand %S." + var + str)) + str; + Buffer.contents buff + in + var_expand (MapString.find name env) let var_choose lst env = @@ -234,7 +233,7 @@ module BaseEnvLight = struct end -# 237 "myocamlbuild.ml" +# 236 "myocamlbuild.ml" module MyOCamlbuildFindlib = struct (* # 22 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *) @@ -307,22 +306,6 @@ module MyOCamlbuildFindlib = struct let find_syntaxes () = ["camlp4o"; "camlp4r"] - let well_known_syntax = [ - "camlp4.quotations.o"; - "camlp4.quotations.r"; - "camlp4.exceptiontracer"; - "camlp4.extend"; - "camlp4.foldgenerator"; - "camlp4.listcomprehension"; - "camlp4.locationstripper"; - "camlp4.macro"; - "camlp4.mapgenerator"; - "camlp4.metagenerator"; - "camlp4.profiler"; - "camlp4.tracer" - ] - - let dispatch = function | Before_options -> @@ -348,17 +331,13 @@ module MyOCamlbuildFindlib = struct List.iter begin fun pkg -> let base_args = [A"-package"; A pkg] in - (* TODO: consider how to really choose camlp4o or camlp4r. *) let syn_args = [A"-syntax"; A "camlp4o"] in let args = - (* Heuristic to identify syntax extensions: whether they end in - ".syntax"; some might not. - *) - if Filename.check_suffix pkg "syntax" || - List.mem pkg well_known_syntax then - syn_args @ base_args - else - base_args + (* Heuristic to identify syntax extensions: whether they end in + * ".syntax"; some might not *) + if Filename.check_suffix pkg "syntax" + then syn_args @ base_args + else base_args in flag ["ocaml"; "compile"; "pkg_"^pkg] & S args; flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args; @@ -389,11 +368,7 @@ module MyOCamlbuildFindlib = struct flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]); flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]); flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]); - flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"]); - flag ["ocaml"; "package(threads)"; "compile"] (S[A "-thread"]); - flag ["ocaml"; "package(threads)"; "doc"] (S[A "-I"; A "+threads"]); - flag ["ocaml"; "package(threads)"; "link"] (S[A "-thread"]); - flag ["ocaml"; "package(threads)"; "infer_interface"] (S[A "-thread"]); + flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"]) | _ -> () @@ -552,14 +527,10 @@ module MyOCamlbuildBase = struct (* Add flags *) List.iter (fun (tags, cond_specs) -> - let spec = BaseEnvLight.var_choose cond_specs env in - let rec eval_specs = - function - | S lst -> S (List.map eval_specs lst) - | A str -> A (BaseEnvLight.var_expand str env) - | spec -> spec + let spec = + BaseEnvLight.var_choose cond_specs env in - flag tags & (eval_specs spec)) + flag tags & spec) t.flags | _ -> () @@ -576,14 +547,14 @@ module MyOCamlbuildBase = struct end -# 579 "myocamlbuild.ml" +# 550 "myocamlbuild.ml" open Ocamlbuild_plugin;; let package_default = { MyOCamlbuildBase.lib_ocaml = [ ("containers", [], []); - ("containers_thread", [], []); + ("containers_thread", ["threads"], []); ("containers_lwt", [], []); ("containers_cgi", ["cgi"], []) ]; @@ -595,6 +566,6 @@ let package_default = let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;; -# 599 "myocamlbuild.ml" +# 570 "myocamlbuild.ml" (* OASIS_STOP *) Ocamlbuild_plugin.dispatch dispatch_default;; diff --git a/setup.ml b/setup.ml index 40508ff9..215d68dd 100644 --- a/setup.ml +++ b/setup.ml @@ -1,9 +1,9 @@ (* setup.ml generated for the first time by OASIS v0.3.0 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 269dc97805609b876f6d0e0b85780bd1) *) +(* DO NOT EDIT (digest: 70d10cce7646b7db6e9097bd53a36898) *) (* - Regenerated by OASIS v0.4.2 + Regenerated by OASIS v0.4.0 Visit http://oasis.forge.ocamlcore.org for more information and documentation about functions used in this file. *) @@ -52,7 +52,6 @@ module OASISContext = struct type t = { - (* TODO: replace this by a proplist. *) quiet: bool; info: bool; debug: bool; @@ -89,31 +88,19 @@ module OASISContext = struct {!default with quiet = true} - let fspecs () = - (* TODO: don't act on default. *) - let ignore_plugins = ref false in + let args () = ["-quiet", Arg.Unit (fun () -> default := {!default with quiet = true}), - s_ " Run quietly"; + (s_ " Run quietly"); "-info", Arg.Unit (fun () -> default := {!default with info = true}), - s_ " Display information message"; + (s_ " Display information message"); "-debug", Arg.Unit (fun () -> default := {!default with debug = true}), - s_ " Output debug message"; - - "-ignore-plugins", - Arg.Set ignore_plugins, - s_ " Ignore plugin's field."; - - "-C", - (* TODO: remove this chdir. *) - Arg.String (fun str -> Sys.chdir str), - s_ "dir Change directory before running."], - fun () -> {!default with ignore_plugins = !ignore_plugins} + (s_ " Output debug message")] end module OASISString = struct @@ -299,13 +286,6 @@ module OASISUtils = struct Hashtbl.hash (String.lowercase s) end) - module SetStringCsl = - Set.Make - (struct - type t = string - let compare = compare_csl - end) - let varname_of_string ?(hyphen='_') s = if String.length s = 0 then @@ -940,6 +920,7 @@ module OASISLicense = struct | DEP5And of license_dep_5 list + type t = | DEP5License of license_dep_5 | OtherLicense of string (* URL *) @@ -1633,12 +1614,6 @@ module OASISFeatures = struct create "section_object" beta (fun () -> s_ "Implement an object section.") - - - let dynrun_for_release = - create "dynrun_for_release" alpha - (fun () -> - s_ "Make '-setup-update dynamic' suitable for releasing project.") end module OASISUnixPath = struct @@ -2782,7 +2757,7 @@ module OASISFileUtil = struct end -# 2785 "setup.ml" +# 2760 "setup.ml" module BaseEnvLight = struct (* # 22 "src/base/BaseEnvLight.ml" *) @@ -2857,27 +2832,26 @@ module BaseEnvLight = struct end - let rec var_expand str env = - let buff = - Buffer.create ((String.length str) * 2) - in - Buffer.add_substitute - buff - (fun var -> - try - var_expand (MapString.find var env) env - with Not_found -> - failwith - (Printf.sprintf - "No variable %s defined when trying to expand %S." - var - str)) - str; - Buffer.contents buff - - let var_get name env = - var_expand (MapString.find name env) env + let rec var_expand str = + let buff = + Buffer.create ((String.length str) * 2) + in + Buffer.add_substitute + buff + (fun var -> + try + var_expand (MapString.find var env) + with Not_found -> + failwith + (Printf.sprintf + "No variable %s defined when trying to expand %S." + var + str)) + str; + Buffer.contents buff + in + var_expand (MapString.find name env) let var_choose lst env = @@ -2887,15 +2861,15 @@ module BaseEnvLight = struct end -# 2890 "setup.ml" +# 2864 "setup.ml" module BaseContext = struct (* # 22 "src/base/BaseContext.ml" *) - (* TODO: get rid of this module. *) + open OASISContext - let args () = fst (fspecs ()) + let args = args let default = default @@ -5026,14 +5000,11 @@ module BaseSetup = struct s_ " Don't try to update setup.ml, even if _oasis has changed.") - let default_oasis_fn = "_oasis" - - let update_setup_ml t = let oasis_fn = match t.oasis_fn with | Some fn -> fn - | None -> default_oasis_fn + | None -> "_oasis" in let oasis_exec = match t.oasis_exec with @@ -5131,8 +5102,7 @@ module BaseSetup = struct try match t.oasis_digest with | Some dgst -> - if Sys.file_exists oasis_fn && - dgst <> Digest.file default_oasis_fn then + if Sys.file_exists oasis_fn && dgst <> Digest.file "_oasis" then begin do_update (); true @@ -5298,7 +5268,7 @@ module BaseSetup = struct end -# 5301 "setup.ml" +# 5271 "setup.ml" module InternalConfigurePlugin = struct (* # 22 "src/plugins/internal/InternalConfigurePlugin.ml" *) @@ -6147,7 +6117,7 @@ module InternalInstallPlugin = struct end -# 6150 "setup.ml" +# 6120 "setup.ml" module OCamlbuildCommon = struct (* # 22 "src/plugins/ocamlbuild/OCamlbuildCommon.ml" *) @@ -6159,15 +6129,10 @@ module OCamlbuildCommon = struct open OASISGettext open BaseEnv open BaseStandardVar - open OASISTypes - - - type extra_args = string list - - - let ocamlbuild_clean_ev = "ocamlbuild-clean" + let ocamlbuild_clean_ev = + "ocamlbuild-clean" let ocamlbuildflags = @@ -6290,7 +6255,27 @@ module OCamlbuildPlugin = struct ref (fun lst -> lst) - let build extra_args pkg argv = + type ocamlbuild_plugin = + { + plugin_tags: string option; + extra_args: string list; + } + + + let check_ocaml_version version pkg = + match pkg.ocaml_version with + | Some ocaml_version -> + let min_ocaml_version = OASISVersion.version_of_string version in + OASISVersion.comparator_ge min_ocaml_version ocaml_version + | None -> + false + + + let ocamlbuild_supports_ocamlfind = check_ocaml_version "3.12.1" + let ocamlbuild_supports_plugin_tags = check_ocaml_version "4.01" + + + let build t pkg argv = (* Return the filename in build directory *) let in_build_dir fn = Filename.concat @@ -6434,13 +6419,33 @@ module OCamlbuildPlugin = struct (BaseBuilt.register bt bnm lst) in - (* Run the hook *) - let cond_targets = !cond_targets_hook cond_targets in + let cond_targets = + (* Run the hook *) + !cond_targets_hook cond_targets + in - (* Run a list of target... *) - run_ocamlbuild (List.flatten (List.map snd cond_targets) @ extra_args) argv; - (* ... and register events *) - List.iter check_and_register (List.flatten (List.map fst cond_targets)) + let extra_args = + match t.plugin_tags with + | Some tags -> "-plugin-tags" :: ("'" ^ tags ^ "'") :: t.extra_args + | None -> t.extra_args + in + let extra_args = + if ocamlbuild_supports_ocamlfind pkg then + "-use-ocamlfind" :: extra_args + else + extra_args + in + + (* Run a list of target... *) + run_ocamlbuild + (List.flatten + (List.map snd cond_targets) + @ extra_args) + argv; + (* ... and register events *) + List.iter + check_and_register + (List.flatten (List.map fst cond_targets)) let clean pkg extra_args = @@ -6477,18 +6482,12 @@ module OCamlbuildDocPlugin = struct - type run_t = - { - extra_args: string list; - run_path: unix_filename; - } - - let doc_build run pkg (cs, doc) argv = + let doc_build path pkg (cs, doc) argv = let index_html = OASISUnixPath.make [ - run.run_path; + path; cs.cs_name^".docdir"; "index.html"; ] @@ -6497,11 +6496,11 @@ module OCamlbuildDocPlugin = struct OASISHostPath.make [ build_dir argv; - OASISHostPath.of_unix run.run_path; + OASISHostPath.of_unix path; cs.cs_name^".docdir"; ] in - run_ocamlbuild (index_html :: run.extra_args) argv; + run_ocamlbuild [index_html] argv; List.iter (fun glb -> BaseBuilt.register @@ -6512,7 +6511,7 @@ module OCamlbuildDocPlugin = struct ["*.html"; "*.css"] - let doc_clean run pkg (cs, doc) argv = + let doc_clean t pkg (cs, doc) argv = run_clean argv; BaseBuilt.unregister BaseBuilt.BDoc cs.cs_name @@ -6520,7 +6519,7 @@ module OCamlbuildDocPlugin = struct end -# 6523 "setup.ml" +# 6522 "setup.ml" module CustomPlugin = struct (* # 22 "src/plugins/custom/CustomPlugin.ml" *) @@ -6668,13 +6667,15 @@ module CustomPlugin = struct end -# 6671 "setup.ml" +# 6670 "setup.ml" open OASISTypes;; let setup_t = { BaseSetup.configure = InternalConfigurePlugin.configure; - build = OCamlbuildPlugin.build ["-use-ocamlfind"]; + build = + OCamlbuildPlugin.build + {OCamlbuildPlugin.plugin_tags = None; extra_args = []}; test = [ ("all", @@ -6686,15 +6687,7 @@ let setup_t = cmd_distclean = [(OASISExpr.EBool true, None)] }) ]; - doc = - [ - ("containers", - OCamlbuildDocPlugin.doc_build - { - OCamlbuildDocPlugin.extra_args = ["-use-ocamlfind"]; - run_path = "." - }) - ]; + doc = [("containers", OCamlbuildDocPlugin.doc_build ".")]; install = InternalInstallPlugin.install; uninstall = InternalInstallPlugin.uninstall; clean = [OCamlbuildPlugin.clean]; @@ -6709,15 +6702,7 @@ let setup_t = cmd_distclean = [(OASISExpr.EBool true, None)] }) ]; - clean_doc = - [ - ("containers", - OCamlbuildDocPlugin.doc_clean - { - OCamlbuildDocPlugin.extra_args = ["-use-ocamlfind"]; - run_path = "." - }) - ]; + clean_doc = [("containers", OCamlbuildDocPlugin.doc_clean ".")]; distclean = []; distclean_test = [ @@ -6926,7 +6911,7 @@ let setup_t = (OASISExpr.EBool true, false); (OASISExpr.EFlag "thread", true) ]; - bs_path = "."; + bs_path = "threads/"; bs_compiled_object = Best; bs_build_depends = [ @@ -7095,6 +7080,37 @@ let setup_t = bs_nativeopt = [(OASISExpr.EBool true, [])] }, {exec_custom = false; exec_main_is = "benchs.ml"}); + Executable + ({ + cs_name = "bench_conv"; + cs_data = PropList.Data.create (); + cs_plugin_data = [] + }, + { + bs_build = + [ + (OASISExpr.EBool true, false); + (OASISExpr.EFlag "bench", true) + ]; + bs_install = [(OASISExpr.EBool true, false)]; + bs_path = "tests/"; + bs_compiled_object = Native; + bs_build_depends = + [ + InternalLibrary "containers"; + FindlibPackage ("benchmark", None) + ]; + bs_build_tools = [ExternalTool "ocamlbuild"]; + bs_c_sources = []; + bs_data_files = []; + bs_ccopt = [(OASISExpr.EBool true, [])]; + bs_cclib = [(OASISExpr.EBool true, [])]; + bs_dlllib = [(OASISExpr.EBool true, [])]; + bs_dllpath = [(OASISExpr.EBool true, [])]; + bs_byteopt = [(OASISExpr.EBool true, [])]; + bs_nativeopt = [(OASISExpr.EBool true, [])] + }, + {exec_custom = false; exec_main_is = "bench_conv.ml"}); Executable ({ cs_name = "run_tests"; @@ -7223,9 +7239,8 @@ let setup_t = plugin_data = [] }; oasis_fn = Some "_oasis"; - oasis_version = "0.4.2"; - oasis_digest = - Some "\145G\\+\192\166\200\007\233\210\000\157\216\241\017 "; + oasis_version = "0.4.0"; + oasis_digest = Some "r\230rE\018\166\247N\216N\001k\0214\177\204"; oasis_exec = None; oasis_setup_args = []; setup_update = false @@ -7233,6 +7248,6 @@ let setup_t = let setup () = BaseSetup.setup setup_t;; -# 7237 "setup.ml" +# 7252 "setup.ml" (* OASIS_STOP *) let () = setup ();; diff --git a/tests/bench_conv.ml b/tests/bench_conv.ml new file mode 100644 index 00000000..0209a59c --- /dev/null +++ b/tests/bench_conv.ml @@ -0,0 +1,19 @@ + +let conv_json = + let src = Conv.Source.(list_ (pair int_ int_)) in + fun x -> Conv.into src Conv.Json.sink x + +let manual_json = + fun l -> + `List (List.map (fun (a,b) -> `List [`Int a; `Int b]) l) + +let bench_list x = + let res = Benchmark.throughputN 5 + [ "conv", conv_json, x + ; "manual", manual_json, x + ] in + Benchmark.tabulate res + +let () = + Printf.printf "list of 5 elements...\n"; + bench_list [1,2; 3,4; 5,6; 7,8; 9,10] diff --git a/containers_thread.mllib b/threads/containers_thread.mllib similarity index 100% rename from containers_thread.mllib rename to threads/containers_thread.mllib diff --git a/future.ml b/threads/future.ml similarity index 100% rename from future.ml rename to threads/future.ml diff --git a/future.mli b/threads/future.mli similarity index 100% rename from future.mli rename to threads/future.mli