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

Runtime: Annotate all fall through switch case #1691

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"suspicious": {
"noAssignInExpressions": "off",
"noDoubleEquals": "off",
"noFallthroughSwitchClause": "off",
"noRedeclare": "off"
}
}
Expand Down
16 changes: 12 additions & 4 deletions runtime/bigarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,13 @@ function caml_ba_hash(ba) {
w = 0;
switch (num_elts & 3) {
case 3:
w = ba.data[i + 2] << 16; /* fallthrough */
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
w = ba.data[i + 2] << 16;
// fallthrough
case 2:
w |= ba.data[i + 1] << 8; /* fallthrough */
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
w |= ba.data[i + 1] << 8;
// fallthrough
case 1:
w |= ba.data[i + 0];
h = caml_hash_mix_int(h, w);
Expand Down Expand Up @@ -874,13 +878,17 @@ function caml_ba_hash(ba) {
}
break;
case 10: // Float32Array (complex32)
num_elts *= 2; /* fallthrough */
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
num_elts *= 2;
// fallthrough
case 0: // Float32Array
if (num_elts > 64) num_elts = 64;
for (var i = 0; i < num_elts; i++) h = caml_hash_mix_float(h, ba.data[i]);
break;
case 11: // Float64Array (complex64)
num_elts *= 2; /* fallthrough */
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
num_elts *= 2;
// fallthrough
case 1: // Float64Array
if (num_elts > 32) num_elts = 32;
for (var i = 0; i < num_elts; i++) h = caml_hash_mix_float(h, ba.data[i]);
Expand Down
5 changes: 4 additions & 1 deletion runtime/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ function caml_parse_format(fmt) {
i++;
}
i--;
break;
hhugo marked this conversation as resolved.
Show resolved Hide resolved
case "d":
case "i":
f.signedconv = true; /* fallthrough */
f.signedconv = true;
f.base = 10;
break;
case "u":
f.base = 10;
break;
Expand Down
10 changes: 8 additions & 2 deletions runtime/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ function caml_hash_mix_jsbytes(h, s) {
w = 0;
switch (len & 3) {
case 3:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
w = s.charCodeAt(i + 2) << 16;
// fallthrough
case 2:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
w |= s.charCodeAt(i + 1) << 8;
// fallthrough
case 1:
w |= s.charCodeAt(i);
h = caml_hash_mix_int(h, w);
default:
}
h ^= len;
return h;
Expand All @@ -165,13 +168,16 @@ function caml_hash_mix_bytes_arr(h, s) {
w = 0;
switch (len & 3) {
case 3:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
w = s[i + 2] << 16;
// fallthrough
case 2:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
w |= s[i + 1] << 8;
// fallthrough
case 1:
w |= s[i];
h = caml_hash_mix_int(h, w);
default:
}
h ^= len;
return h;
Expand Down
1 change: 1 addition & 0 deletions runtime/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ function caml_nativeint_unmarshal(reader, size) {
return reader.read32s();
case 2:
caml_failwith("input_value: native integer value too large");
break;
default:
caml_failwith("input_value: ill-formed native integer");
}
Expand Down
5 changes: 3 additions & 2 deletions runtime/mlBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,9 @@ MlBytes.prototype.toString = function () {
return this.c;
case 4: /* ARRAY */
case 2 /* PARTIAL */:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
caml_convert_string_to_bytes(this);
//fallthrough
// fallthrough
case 0 /*BYTES | UNKOWN*/:
if (jsoo_is_ascii(this.c)) this.t = 9; /*BYTES | ASCII*/
else this.t = 8; /*BYTES | NOT_ASCII*/
Expand Down Expand Up @@ -899,7 +900,7 @@ function caml_ml_bytes_content(s) {
switch (s.t & 6) {
case 2 /* PARTIAL */:
caml_convert_string_to_bytes(s);
// fallthrough
return s.c;
default: /* BYTES or ARRAY */
return s.c;
}
Expand Down
34 changes: 20 additions & 14 deletions runtime/parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,27 @@ function caml_parse_engine(tables, env, cmd, arg) {
the_loop: for (;;) {
switch (cmd) {
case 0: //START:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
state = 0;
errflag = 0;
// Fall through
// fallthrough

case 6: //loop:
n = tables.defred[state];
if (n != 0) {
cmd = reduce;
break;
continue the_loop;
}
if (env[env_curr_char] >= 0) {
cmd = testshift;
break;
continue the_loop;
}
res = READ_TOKEN;
break the_loop;
/* The ML code calls the lexer and updates */
/* symb_start and symb_end */
case 1: //TOKEN_READ:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
if (Array.isArray(arg)) {
env[env_curr_char] = tables[tbl_transl_block][arg[0] + 1];
env[env_lval] = arg[1];
Expand All @@ -159,9 +161,10 @@ function caml_parse_engine(tables, env, cmd, arg) {
env[env_lval] = 0;
}
if (caml_parser_trace) print_token(state, arg);
// Fall through
// fallthrough

case 7: //testshift:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
n1 = tables.sindex[state];
n2 = n1 + env[env_curr_char];
if (
Expand All @@ -171,7 +174,7 @@ function caml_parse_engine(tables, env, cmd, arg) {
tables.check[n2] == env[env_curr_char]
) {
cmd = shift;
break;
continue the_loop;
}
n1 = tables.rindex[state];
n2 = n1 + env[env_curr_char];
Expand All @@ -183,13 +186,13 @@ function caml_parse_engine(tables, env, cmd, arg) {
) {
n = tables.table[n2];
cmd = reduce;
break;
continue the_loop;
}
if (errflag <= 0) {
res = CALL_ERROR_FUNCTION;
break the_loop;
}
// Fall through
// fallthrough
/* The ML code calls the error function */
case 5: //ERROR_DETECTED:
if (errflag < 3) {
Expand Down Expand Up @@ -223,14 +226,16 @@ function caml_parse_engine(tables, env, cmd, arg) {
if (caml_parser_trace) log("Discarding last token read");
env[env_curr_char] = -1;
cmd = loop;
break;
continue the_loop;
}
// Fall through
// Unreachable
hhugo marked this conversation as resolved.
Show resolved Hide resolved
case 8: //shift:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
env[env_curr_char] = -1;
if (errflag > 0) errflag--;
// Fall through
// fallthrough
case 9: //shift_recover:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
if (caml_parser_trace)
log("State " + state + ": shift to state " + tables.table[n2]);
state = tables.table[n2];
Expand All @@ -239,17 +244,18 @@ function caml_parse_engine(tables, env, cmd, arg) {
res = GROW_STACKS_1;
break the_loop;
}
// Fall through
// fallthrough
/* The ML code resizes the stacks */
case 2: //STACKS_GROWN_1:
env[env_s_stack][sp + 1] = state;
env[env_v_stack][sp + 1] = env[env_lval];
env[env_symb_start_stack][sp + 1] = env[env_symb_start];
env[env_symb_end_stack][sp + 1] = env[env_symb_end];
cmd = loop;
break;
continue the_loop;

case 10: //reduce:
// biome-ignore lint/suspicious/noFallthroughSwitchClause:
if (caml_parser_trace) log("State " + state + ": reduce by rule " + n);
var m = tables.len[n];
env[env_asp] = sp;
Expand All @@ -272,7 +278,7 @@ function caml_parse_engine(tables, env, cmd, arg) {
res = GROW_STACKS_2;
break the_loop;
}
// Fall through
// fallthrough
/* The ML code resizes the stacks */
case 3: //STACKS_GROWN_2:
res = COMPUTE_SEMANTIC_ACTION;
Expand All @@ -288,7 +294,7 @@ function caml_parse_engine(tables, env, cmd, arg) {
env[env_symb_start_stack][sp + 1] = env[env_symb_end_stack][asp + 1];
}
cmd = loop;
break;
continue the_loop;
/* Should not happen */
default:
return RAISE_PARSE_ERROR;
Expand Down