Skip to content

[BUG] Regression in generated code: 'There is no containing label named "x"' #1547

Closed
@jchavarri

Description

@jchavarri

Describe the bug
As part of the Melange playground, we create a version of ocamlformat that we can run on the browser.

When updating to the most recent version of jsoo, we noticed an error when creating this JS version of ocamlformat: https://github.com/melange-re/melange-re.github.io/actions/runs/7139925249/job/19444213740#step:15:44

The error comes from esbuild, I paste below some details.

Part of the error (click to open)
There is no containing label named "b"
17821|  11:var
17822|  h=a[1],c=h[1];if(typeof
17823|  c!=="number"&&14===c[0]){if(c[2])break b;if(h[4])break b;var
   |                                         ^
17824|  i=a[2],f=i[1];if(typeof
17825|  f!=="number"&&9===f[0]){if(i[4])break b;return [0,[14,c[1],[0,f[1]]],b[2],b[3],b[4]]}break b}break b;case

There is no containing label named "b"
17821|  11:var
17822|  h=a[1],c=h[1];if(typeof
17823|  c!=="number"&&14===c[0]){if(c[2])break b;if(h[4])break b;var
   |                                                         ^
17824|  i=a[2],f=i[1];if(typeof
17825|  f!=="number"&&9===f[0]){if(i[4])break b;return [0,[14,c[1],[0,f[1]]],b[2],b[3],b[4]]}break b}break b;case

There is no containing label named "b"
17823|  c!=="number"&&14===c[0]){if(c[2])break b;if(h[4])break b;var
17824|  i=a[2],f=i[1];if(typeof
17825|  f!=="number"&&9===f[0]){if(i[4])break b;return [0,[14,c[1],[0,f[1]]],b[2],b[3],b[4]]}break b}break b;case
   |                                        ^
17826|  18:var
17827|  d=a[1];if(!d)break b;var

Debugging notes

  • The error only happens with using profile=release but it does not occur with profile=dev.
  • It only happens when trying to process large programs, like ocamlformat or the melange compiler. I have not been able to reproduce or isolate using small programs.
  • After dissecting back in time through the past commits of jsoo, we found the regression starts happening after commit 29c693b (Compiler: refactor control flow compilation #1496), with 3ddba6b being the last commit that works fine.
  • One thing I noticed in the generated code is that there are two nested b labels, see the extracted section of the generated code below:
Section of generated minified JS that causes the failure (click to open)
function q(g, b) {
  var a = b[1];
  b: if (typeof a !== "number")
    switch (a[0]) {
      case 7:
        var q = a[2],
          r = a[1],
          t = bS(r, function (a) {
            var c = a[3],
              d = a[2],
              b = a[1];
            b: if (c) {
              var h = c[1],
                e = h[1];
              if (typeof e !== "number")
                switch (e[0]) {
                  case 0:
                    if (h[4]) break b;
                    if (tp(b[1], [0, e[1][1]])) return [0, b, d, 0];
                    break b;
                  case 11:
                    if (d) break b;
                    var i = c[1],
                      k = i[1],
                      l = k[1],
                      f = l[1];
                    if (typeof f !== "number" && 0 === f[0]) {
                      if (l[4]) break b;
                      if (i[4]) break b;
                      var m = k[2],
                        n = f[1][1];
                      if (j && tp(b[1], [0, n]))
                        return [0, b, [0, m], 0];
                      break b;
                    }
                    break b;
                }
            }
            return [0, b, d, o(eR, c, p(g[33], g))];
          });
        return [0, [7, t, q], b[2], b[3], b[4]];
      case 11:
        var h = a[1],
          c = h[1];
        if (typeof c !== "number" && 14 === c[0]) {
          if (c[2]) break b; /* <--- error triggered here */
          if (h[4]) break b;
          var i = a[2],
            f = i[1];
          if (typeof f !== "number" && 9 === f[0]) {
            if (i[4]) break b;
            return [0, [14, c[1], [0, f[1]]], b[2], b[3], b[4]];
          }
          break b;
        }
        break b;
      case 18:
        var d = a[1];
        if (!d) break b;
        var k = d[2];
        if (!k) break b;
        if (!k[2]) break b;
        var l = dm(d),
          e = l[1];
        d: {
          e: if (typeof e !== "number" && 5 === e[0]) {
            var n = e[1][1];
            if (0 !== n[0]) break e;
            if (s(n[1], d1)) break e;
            if (e[2]) break e;
            if (l[4]) break e;
            var m = 1;
            break d;
          }
          var m = 0;
        }
        if (!m) break b;
        var u = b6(o8(b6(d)));
        return [0, [9, u], b[2], b[3], b[4]];
    }
  return Cs(g, b);
}

Expected behavior
Js_of_ocaml should generate code that is usable by other JavaScript tooling.

Versions
See section "Debugging notes" above about commits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions