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

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

Closed
jchavarri opened this issue Dec 8, 2023 · 7 comments
Closed
Labels

Comments

@jchavarri
Copy link
Contributor

jchavarri commented Dec 8, 2023

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.

@jchavarri jchavarri added the bug label Dec 8, 2023
@hhugo
Copy link
Member

hhugo commented Dec 8, 2023

The duplicated labels are not really duplicated because there are not inside the same function. They belong to two different (yet nested) functions.

@jchavarri
Copy link
Contributor Author

jchavarri commented Dec 8, 2023 via email

@hhugo
Copy link
Member

hhugo commented Dec 8, 2023

What version of esbuild do you use ?
Can you provide a file cause this error ?

@jchavarri
Copy link
Contributor Author

I tried with both esbuild 0.14.54 and 0.19.8 and saw the same error. I am noticing now that somewhere in the process with vite (which is the tool driving esbuild), the top level b label is being removed. I'm going to close this as it seems an issue with some JS tooling rather than jsoo. Sorry for the distraction.

@hhugo
Copy link
Member

hhugo commented Dec 9, 2023

Could you point to issues you end up opening if/once you figure out who's responsible for the deletion ?

@jchavarri
Copy link
Contributor Author

It seems the problem is in rollup (another module bundler, i am not sure why vite uses two module bundlers 😞 )

Repro:

  • Go to rollup playground, loading the snippet with a failing function
  • Change treeshake option on the right from false to true
  • See how the top level b label disappears

@jchavarri
Copy link
Contributor Author

rollup/rollup#5292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants