diff --git a/jscomp/test/build.ninja b/jscomp/test/build.ninja index 16e995d5393..4f8dfd9edb0 100644 --- a/jscomp/test/build.ninja +++ b/jscomp/test/build.ninja @@ -324,6 +324,7 @@ o test/gpr_4900_test.cmi test/gpr_4900_test.cmj : cc test/gpr_4900_test.ml | tes o test/gpr_4924_test.cmi test/gpr_4924_test.cmj : cc test/gpr_4924_test.ml | test/mt.cmj $stdlib o test/gpr_4931.cmi test/gpr_4931.cmj : cc test/gpr_4931.ml | $stdlib o test/gpr_5071_test.cmi test/gpr_5071_test.cmj : cc test/gpr_5071_test.res | test/react.cmj $stdlib +o test/gpr_5169_test.cmi test/gpr_5169_test.cmj : cc test/gpr_5169_test.ml | $stdlib o test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib o test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.ml | $stdlib o test/gpr_858_test.cmi test/gpr_858_test.cmj : cc test/gpr_858_test.ml | $stdlib @@ -471,6 +472,7 @@ o test/ocaml_re_test.cmi test/ocaml_re_test.cmj : cc test/ocaml_re_test.ml | tes o test/of_string_test.cmi test/of_string_test.cmj : cc test/of_string_test.ml | test/mt.cmj $stdlib o test/offset.cmi test/offset.cmj : cc test/offset.ml | $stdlib o test/oo_js_test_date.cmi test/oo_js_test_date.cmj : cc test/oo_js_test_date.ml | test/mt.cmj $stdlib +o test/option_encoding_test.cmi test/option_encoding_test.cmj : cc test/option_encoding_test.ml | $stdlib o test/option_repr_test.cmi test/option_repr_test.cmj : cc test/option_repr_test.ml | test/mt.cmj $stdlib o test/optional_ffi_test.cmi test/optional_ffi_test.cmj : cc test/optional_ffi_test.ml | test/mt.cmj $stdlib o test/optional_regression_test.cmi test/optional_regression_test.cmj : cc test/optional_regression_test.ml | test/mt.cmj $stdlib diff --git a/jscomp/test/gpr_5169_test.js b/jscomp/test/gpr_5169_test.js new file mode 100644 index 00000000000..697db483c7c --- /dev/null +++ b/jscomp/test/gpr_5169_test.js @@ -0,0 +1,53 @@ +'use strict'; + + +var NotOption = {}; + +var TotallyNotOption = {}; + +var NotOption2 = {}; + +var a; + +var b = 1; + +var c; + +var d = 1; + +var e; + +var f = 1; + +var g; + +var h = 1; + +var i = /* None */0; + +var j = /* Some */{ + _0: 1 +}; + +var k = /* None */0; + +var l = /* Some */{ + _0: 1 +}; + +exports.NotOption = NotOption; +exports.a = a; +exports.b = b; +exports.c = c; +exports.d = d; +exports.TotallyNotOption = TotallyNotOption; +exports.e = e; +exports.f = f; +exports.g = g; +exports.h = h; +exports.NotOption2 = NotOption2; +exports.i = i; +exports.j = j; +exports.k = k; +exports.l = l; +/* No side effect */ diff --git a/jscomp/test/gpr_5169_test.ml b/jscomp/test/gpr_5169_test.ml new file mode 100644 index 00000000000..12a929fa6a6 --- /dev/null +++ b/jscomp/test/gpr_5169_test.ml @@ -0,0 +1,29 @@ +module NotOption = struct + + type 'a t = None | Some of 'a +end + +let a = NotOption.None (* undefined *) +let b = NotOption.Some(1) (* 1 *) +let c = let open NotOption in None +let d = let open NotOption in Some(1) + + +module TotallyNotOption = struct + type 'a t = Some of ('a) | None +end + +let e = TotallyNotOption.None (* undefined *) +let f = TotallyNotOption.Some(1) (* 1 *) +let g = let open TotallyNotOption in None +let h = let open TotallyNotOption in Some(1) + + +module NotOption2 = struct + type 'a t = None | Some of 'a | Bogus +end + +let i = NotOption2.None +let j = NotOption2.Some(1) +let k = let open NotOption2 in None +let l = let open NotOption2 in Some(1) \ No newline at end of file diff --git a/jscomp/test/option_encoding_test.js b/jscomp/test/option_encoding_test.js new file mode 100644 index 00000000000..199bbcd1998 --- /dev/null +++ b/jscomp/test/option_encoding_test.js @@ -0,0 +1,16 @@ +'use strict'; + + +var N = {}; + +var u = [ + undefined, + 3 +]; + +var h; + +exports.N = N; +exports.u = u; +exports.h = h; +/* No side effect */ diff --git a/jscomp/test/option_encoding_test.ml b/jscomp/test/option_encoding_test.ml new file mode 100644 index 00000000000..138bc30fe9a --- /dev/null +++ b/jscomp/test/option_encoding_test.ml @@ -0,0 +1,24 @@ +[@@@config { + flags = [| + "-w"; + "@A"; + "-drawlambda"; + "-dtypedtree"; + "-bs-diagnose"; + "-dparsetree"; + (* "-dsource"; *) + |] +}] + + +module N = struct + type 'a t = 'a option = + | None + | Some of 'a +end + + +let u = N.(None, Some 3) + + +let h = N.None \ No newline at end of file diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index ddf512d05d0..85224e68d50 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -71820,7 +71820,9 @@ and transl_exp0 e = | Longident.Lident "None" when Datarepr.constructor_has_optional_shape cstr -> Pt_shape_none - | _ -> Pt_constructor {name = cstr.cstr_name; const = cstr.cstr_consts; non_const = cstr.cstr_nonconsts} + | _ -> + if Datarepr.constructor_has_optional_shape cstr then Pt_shape_none + else Pt_constructor {name = cstr.cstr_name; const = cstr.cstr_consts; non_const = cstr.cstr_nonconsts} )) | Cstr_unboxed -> (match ll with [v] -> v | _ -> assert false) diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 9c99f691df9..e139c9e94c1 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -355863,7 +355863,9 @@ and transl_exp0 e = | Longident.Lident "None" when Datarepr.constructor_has_optional_shape cstr -> Pt_shape_none - | _ -> Pt_constructor {name = cstr.cstr_name; const = cstr.cstr_consts; non_const = cstr.cstr_nonconsts} + | _ -> + if Datarepr.constructor_has_optional_shape cstr then Pt_shape_none + else Pt_constructor {name = cstr.cstr_name; const = cstr.cstr_consts; non_const = cstr.cstr_nonconsts} )) | Cstr_unboxed -> (match ll with [v] -> v | _ -> assert false) diff --git a/scripts/ninja.js b/scripts/ninja.js index 92ad771a86f..3ae1f5bff09 100755 --- a/scripts/ninja.js +++ b/scripts/ninja.js @@ -1420,8 +1420,10 @@ function test(dir) { return ( (x.endsWith(".ml") || x.endsWith(".mli")) && !(x.endsWith(".cppo.ml") || x.endsWith(".cppo.mli")) && - !x.includes('bytelibrarian') && !x.includes('bytelink') && - !x.includes('bytepackager') && !x.includes('emitcode') + !x.includes("bytelibrarian") && + !x.includes("bytelink") && + !x.includes("bytepackager") && + !x.includes("emitcode") ); }) .map((x) => path.join(dir, x)); @@ -1522,7 +1524,7 @@ ${buildNapkinFiles} `; var cppoNinjaFile = getPreprocessorFileName(); writeFileSync(path.join(jscompDir, cppoNinjaFile), cppoNative); - cp.execFileSync(vendorNinjaPath, ["-f", cppoNinjaFile, "--verbose",'-v'], { + cp.execFileSync(vendorNinjaPath, ["-f", cppoNinjaFile, "--verbose", "-v"], { cwd: jscompDir, stdio: [0, 1, 2], encoding: "utf8", @@ -1557,8 +1559,9 @@ var sourceDirs = [ function makeLibs(dirs) { return dirs.map((x) => `${x}/${x}.cmxa`).join(" "); } -var compiler_libs = ['utils','parsing', 'typing','bytecomp'] -var bsc_libs = compiler_libs.concat([ +var compiler_libs = ["utils", "parsing", "typing", "bytecomp"]; +var bsc_libs = [ + ...compiler_libs, "js_parser", "stubs", "ext", @@ -1569,20 +1572,43 @@ var bsc_libs = compiler_libs.concat([ "super_errors", "outcome_printer", "core", -]); - +]; -var bspack_libs = compiler_libs.concat(["stubs", "ext", "common", "frontend", "depends"]); +var bspack_libs = [ + ...compiler_libs, + "stubs", + "ext", + "common", + "frontend", + "depends", +]; var bsb_helper_libs = ["stubs", "ext", "common", "bsb_helper"]; var rescript_libs = ["stubs", "ext", "common", "bsb"]; -var cmjdumps_libs = compiler_libs.concat(["stubs", "ext", "common", "frontend", "depends", "core"]); +var cmjdumps_libs = [ + ...compiler_libs, + "stubs", + "ext", + "common", + "frontend", + "depends", + "core", +]; -var cmij_libs = compiler_libs.concat(["stubs", "ext", "common", "frontend", "depends", "core"]); +var cmij_libs = [ + ...compiler_libs, + "stubs", + "ext", + "common", + "frontend", + "depends", + "core", +]; -var tests_libs = compiler_libs.concat([ +var tests_libs = [ + ...compiler_libs, "ounit", "stubs", "ext", @@ -1593,7 +1619,7 @@ var tests_libs = compiler_libs.concat([ "bsb_helper", "core", "ounit_tests", -]); +]; /** * Note don't run `ninja -t clean -g` * Since it will remove generated ml file which has