Skip to content

Commit

Permalink
[fix] fix #382, compile ignore correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbo Zhang committed May 17, 2016
1 parent 6b179a8 commit b47c2c7
Show file tree
Hide file tree
Showing 19 changed files with 155 additions and 71 deletions.
8 changes: 5 additions & 3 deletions jscomp/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,9 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
| Block [] ->
ipp_comment f L.empty_block; (* debugging*)
cxt
| Exp {expression_desc = Var _;}
-> (* Does it make sense to optimize here? *)
semi f; cxt

| Block b -> (* No braces needed here *)
ipp_comment f L.start_block;
Expand All @@ -1128,8 +1131,6 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
cxt
| Variable l ->
variable_declaration top cxt f l
| Exp {expression_desc = Var _;}-> (* Does it make sense to optimize here? *)
semi f; cxt
| Exp e ->
(* Parentheses are required when the expression
starts syntactically with "{" or "function"
Expand Down Expand Up @@ -1205,7 +1206,8 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
block cxt f s1
in
begin match s2 with
| None | (Some []) |Some [{statement_desc = Block []; }]
| None | (Some [])
| Some [{statement_desc = (Block [] | Exp {expression_desc = Var _;} ); }]
-> P.newline f; cxt
| Some [{statement_desc = If _} as nest]
| Some [{statement_desc = Block [ {statement_desc = If _ ; _} as nest] ; _}]
Expand Down
3 changes: 2 additions & 1 deletion jscomp/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ let rec no_side_effects (lam : Lambda.lambda) : bool =
(* Integer to external pointer *)
| Pint_as_pointer
| Poffsetint _
| Pignore
-> true

| Pignore

| Prevapply _
| Pdirapply _

Expand Down
2 changes: 1 addition & 1 deletion jscomp/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ let translate
| Pignore ->
begin
match args with
| [e] -> e
| [e] -> E.seq e E.unit
| _ -> assert false
end
| Pgetglobal i ->
Expand Down
4 changes: 2 additions & 2 deletions jscomp/runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ caml_format.cmj caml_io.cmj: curry.cmj

$(addsuffix .cmj, $(OTHERS)): caml_builtin_exceptions.cmj block.cmj js.cmj fn.cmj

RUNTIME := $(addsuffix .cmj, $(SOURCE_LIST))
RUNTIME := $(addsuffix .cmj, $(SOURCE_LIST))


COMPFLAGS += $(MODULE_FLAGS) -I ../stdlib -w -40 -js-npm-output-path $(npm_package_name):lib/js -js-no-builtin-ppx-mli
COMPFLAGS += $(MODULE_FLAGS) -I ../stdlib -nostdlib -nopervasives -open Pervasives -w -40 -js-npm-output-path $(npm_package_name):lib/js -js-no-builtin-ppx-mli



Expand Down
4 changes: 4 additions & 0 deletions jscomp/test/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ hashtbl_test.cmx : mt.cmx ../stdlib/moreLabels.cmx ../stdlib/list.cmx \
../stdlib/hashtbl.cmx ../stdlib/array.cmx
http_types.cmj : ../runtime/js.cmj
http_types.cmx : ../runtime/js.cmx
ignore_test.cmj : mt.cmi ../runtime/js.cmj
ignore_test.cmx : mt.cmx ../runtime/js.cmx
inline_edge_cases.cmj : inline_edge_cases.cmi
inline_edge_cases.cmx : inline_edge_cases.cmi
inline_map2_test.cmj : mt.cmi ../stdlib/list.cmi
Expand Down Expand Up @@ -868,6 +870,8 @@ hashtbl_test.cmj : mt.cmj ../stdlib/moreLabels.cmj ../stdlib/list.cmj \
../stdlib/hashtbl.cmj ../stdlib/array.cmj
http_types.cmo : ../runtime/js.cmo
http_types.cmj : ../runtime/js.cmj
ignore_test.cmo : mt.cmi ../runtime/js.cmo
ignore_test.cmj : mt.cmj ../runtime/js.cmj
inline_edge_cases.cmo : inline_edge_cases.cmi
inline_edge_cases.cmj : inline_edge_cases.cmi
inline_map2_test.cmo : mt.cmi ../stdlib/list.cmi
Expand Down
19 changes: 19 additions & 0 deletions jscomp/test/ignore_test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let suites : Mt.pair_suites ref = ref []
let test_id = ref 0
let eq loc x y =
incr test_id ;
suites :=
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites

let f x =
ignore (x)

let ff x =
ignore (Js.log x)


let () =
eq __LOC__ (f 3 ) ()


let () = Mt.from_pair_suites __FILE__ !suites
4 changes: 3 additions & 1 deletion jscomp/test/test.mllib
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,6 @@ test_unsafe_obj_ffi_ppx

ppx_apply_test
test_http_server
http_types
http_types

ignore_test
3 changes: 2 additions & 1 deletion lib/js/camlinternalFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5826,7 +5826,8 @@ function fmt_ebb_of_string(legacy_behavior, str) {
else if (fmt.tag === 11) {
if (typeof fmt[1] === "number") {
try {
return open_box_of_string(fmt[0]);
open_box_of_string(fmt[0]);
return /* () */0;
}
catch (exn){
if (exn[0] === Caml_builtin_exceptions.failure) {
Expand Down
21 changes: 14 additions & 7 deletions lib/js/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,11 +1025,13 @@ function default_pp_mark_close_tag(s) {
}

function default_pp_print_open_tag(prim) {
return prim;
;
return /* () */0;
}

function default_pp_print_close_tag(prim) {
return prim;
;
return /* () */0;
}

function pp_make_formatter(f, g, h, i) {
Expand Down Expand Up @@ -1087,9 +1089,11 @@ function pp_make_formatter(f, g, h, i) {

function make_formatter(output, flush) {
var ppf = pp_make_formatter(output, flush, function (prim) {
return prim;
;
return /* () */0;
}, function (prim) {
return prim;
;
return /* () */0;
});
ppf[/* pp_out_newline */18] = function (param) {
return display_newline(ppf, param);
Expand All @@ -1112,7 +1116,8 @@ function formatter_of_buffer(b) {
return make_formatter(function (param, param$1, param$2) {
return Buffer.add_substring(b, param, param$1, param$2);
}, function (prim) {
return prim;
;
return /* () */0;
});
}

Expand Down Expand Up @@ -1764,13 +1769,15 @@ function ikfprintf(k, x, param) {

function fprintf(ppf, fmt) {
return kfprintf(function (prim) {
return prim;
;
return /* () */0;
}, ppf, fmt);
}

function ifprintf(ppf, fmt) {
return ikfprintf(function (prim) {
return prim;
;
return /* () */0;
}, ppf, fmt);
}

Expand Down
9 changes: 6 additions & 3 deletions lib/js/printf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ function ikfprintf(k, oc, param) {

function fprintf(oc, fmt) {
return kfprintf(function (prim) {
return prim;
;
return /* () */0;
}, oc, fmt);
}

function bprintf(b, fmt) {
return kbprintf(function (prim) {
return prim;
;
return /* () */0;
}, b, fmt);
}

function ifprintf(oc, fmt) {
return ikfprintf(function (prim) {
return prim;
;
return /* () */0;
}, oc, fmt);
}

Expand Down
13 changes: 7 additions & 6 deletions lib/js/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ var interactive = [/* false */0];

function set_signal(sig_num, sig_beh) {
;
return sig_beh;
;
return /* () */0;
}

var Break = Caml_exceptions.create("Sys.Break");

function catch_break(on) {
if (on) {
-6;
return /* Signal_handle */[function () {
throw Break;
}];
/* Signal_handle */[function () {
throw Break;
}];
return /* () */0;
}
else {
-6;
return /* Signal_default */0;
return /* () */0;
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/js/test/caml_format_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ var suites = Pervasives.$at(from_of_string(of_string), Pervasives.$at(/* :: */[
"throw",
function () {
return /* ThrowAny */Block.__(3, [function () {
return Caml_format.caml_float_of_string("");
Caml_format.caml_float_of_string("");
return /* () */0;
}]);
}
],
Expand Down
47 changes: 47 additions & 0 deletions lib/js/test/ignore_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
'use strict';

var Mt = require("./mt");
var Block = require("../block");

var suites = [/* [] */0];

var test_id = [0];

function eq(loc, x, y) {
test_id[0] = test_id[0] + 1 | 0;
suites[0] = /* :: */[
/* tuple */[
loc + (" id " + test_id[0]),
function () {
return /* Eq */Block.__(0, [
x,
y
]);
}
],
suites[0]
];
return /* () */0;
}

function f(x) {
;
return /* () */0;
}

function ff(x) {
console.log(x);
return /* () */0;
}

eq('File "ignore_test.ml", line 16, characters 5-12', (3, /* () */0), /* () */0);

Mt.from_pair_suites("ignore_test.ml", suites[0]);

exports.suites = suites;
exports.test_id = test_id;
exports.eq = eq;
exports.f = f;
exports.ff = ff;
/* Not a pure module */
16 changes: 4 additions & 12 deletions lib/js/test/lazy_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ function lazy_test() {
if (tag === 246) {
CamlinternalLazy.force_lazy_block(v);
}
else {
;
}

}
var g = u[0];
return /* tuple */[
Expand All @@ -39,9 +37,7 @@ function f(param) {
if (tag === 246) {
CamlinternalLazy.force_lazy_block(match);
}
else {
;
}

}
var match$1 = param[2][/* contents */0];
if (match$1) {
Expand All @@ -51,9 +47,7 @@ function f(param) {
if (tag$1 === 246) {
CamlinternalLazy.force_lazy_block(match$2);
}
else {
;
}

}
var match$3 = param[2][/* contents */0];
if (match$3) {
Expand Down Expand Up @@ -118,9 +112,7 @@ if (tag !== 250) {
if (tag === 246) {
CamlinternalLazy.force_lazy_block(u$1);
}
else {
;
}

}

function exotic(param) {
Expand Down
42 changes: 22 additions & 20 deletions lib/js/test/ocaml_proto_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4359,6 +4359,26 @@ function not_found(f) {
}
}

function list_assoc2(x, _param) {
while(true) {
var param = _param;
if (param) {
var match = param[0];
if (Caml_obj.caml_compare(match[1], x)) {
_param = param[1];
continue ;

}
else {
return match[0];
}
}
else {
throw Caml_builtin_exceptions.not_found;
}
};
}

function type_of_spec(file_name, file_options, id, scope, spec) {
return /* record */[
/* scope */scope,
Expand Down Expand Up @@ -4462,27 +4482,9 @@ function compile_message_p1(file_name, file_options, message_scope, param) {
var number = field_number(field);
var name = field_name(field);
if (not_found(function () {
return List.assoc(number, number_index);
return List.assoc(number, number_index), /* () */0;
}) && not_found(function () {
var x = name;
var _param = number_index;
while(true) {
var param = _param;
if (param) {
var match = param[0];
if (Caml_obj.caml_compare(match[1], x)) {
_param = param[1];
continue ;

}
else {
return match[0];
}
}
else {
throw Caml_builtin_exceptions.not_found;
}
};
return list_assoc2(name, number_index), /* () */0;
})) {
return /* :: */[
/* tuple */[
Expand Down
Loading

0 comments on commit b47c2c7

Please sign in to comment.