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

dart2js: Code does not run with -O0 #41484

Open
rakudrama opened this issue Apr 14, 2020 · 7 comments
Open

dart2js: Code does not run with -O0 #41484

rakudrama opened this issue Apr 14, 2020 · 7 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dart2js-optimization web-dart2js

Comments

@rakudrama
Copy link
Member

I just tried running the code in #41449 with -O0.
The code fails with:

o1.js:1328: TypeError: Cannot read property '$add' of undefined
      return $arguments.length !== 0 ? C.JSString_methods.$add(s, J.$add$ns(C.JSString_methods.$add("<", H._Universe__canonicalRecipeJoin($arguments)), ">")) : s;
                                                          ^
TypeError: Cannot read property '$add' of undefined
    at Object._Universe__canonicalRecipeOfInterface (o1.js:1328:59)
    at Object._Universe__lookupInterfaceRti (o1.js:1332:17)
    at Object._Parser_handleTypeArguments (o1.js:1603:22)
    at Object._Parser_parse (o1.js:1496:17)
    at Object._Universe__parseRecipe (o1.js:1172:19)
    at Object._Universe_eval (o1.js:1133:15)
    at findType (o1.js:661:16)
    at rtii (o1.js:2574:20)
    at dartProgram (o1.js:2589:5)
    at o1.js:2635:3

There is an indirect cycle.
C.JSString is a constant interceptor (methods) in the constant pool.
The types are created (rtii, findType) for the type pool before the constant pool exists.

Possible ways to fix this:

  • Don't use + on Strings. Use a new _Utils.concatN(s1, s2, ..., sN) methods in rti.dart.
  • Use interpolation instead of + (it lowers to HStringConcat and the static S helper)
  • Change codegen for String.+ to be more like numbers - generate a check before the lowered + operation.
  • Adjust constant pool to have two parts, one that has the interceptors (and maybe other constants independent of types) that can go before the type pool initialization, and one that is dependent on types that must go after.

Pulling the interceptor constants earlier might be the best option since the others remedies don't apply if we find the same problem with a different interceptor.

@rakudrama rakudrama added web-dart2js dart2js-optimization area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels Apr 14, 2020
@rakudrama
Copy link
Member Author

Immediate issue above fixed by e025726.
Needs more testing to close.

@edyu
Copy link

edyu commented Jun 1, 2020

Just want to confirm I'm seeing the same thing. Depending on whether using Chrome or Edge, I'm seeing $add or the C.JsString_methods error.

@rakudrama
Copy link
Member Author

@edyu If you could include the stack trace I could tell if it is the same issue or something else.

@edyu
Copy link

edyu commented Jun 1, 2020

from Chrome:

Uncaught TypeError: Cannot read property '$add' of undefined
    at Object._Universe__canonicalRecipeOfInterface (rti.dart:1746)
    at Object._Universe__lookupInterfaceRti (rti.dart:1755)
    at Object._Parser_handleTypeArguments (rti.dart:2258)
    at Object._Parser_parse (rti.dart:2140)
    at Object._Universe__parseRecipe (rti.dart:1509)
    at Object._Universe_eval (rti.dart:1442)
    at findType (rti.dart:405)
    at rtii (main.dart.js:69276)
    at dartProgram (main.dart.js:69741)
    at js_helper.dart:3221
_Universe__canonicalRecipeOfInterface @ rti.dart:1743
_Universe__lookupInterfaceRti @ rti.dart:1753
_Parser_handleTypeArguments @ rti.dart:2256
_Parser_parse @ rti.dart:2137
_Universe__parseRecipe @ rti.dart:1506
_Universe_eval @ rti.dart:1445
findType @ rti.dart:396
rtii @ main.dart.js:69276
dartProgram @ main.dart.js:69741
(anonymous) @ js_helper.dart:3221

@edyu
Copy link

edyu commented Jun 1, 2020

From Firefox:

TypeError: C.JSString_methods is undefined
    _Universe__canonicalRecipeOfInterface rti.dart:1744
    _Universe__lookupInterfaceRti rti.dart:1755
    _Parser_handleTypeArguments rti.dart:2258
    _Parser_parse rti.dart:2140
    _Universe__parseRecipe rti.dart:1509
    _Universe_eval rti.dart:1442
    findType rti.dart:405
    rtii main.dart.js:69276
    dartProgram main.dart.js:69741
     main.dart.js:70694

@edyu
Copy link

edyu commented Jun 1, 2020

@rakudrama
I just posted the stack trace for both Chrome and Firefox.
Here is the corresponding build.yaml:

targets:
  $default:
    builders:
      build_web_compilers|entrypoint:
        options:
          compiler: dart2js
          dart2js_args:
            - -O0

@rakudrama
Copy link
Member Author

Thanks for the investigation. The bug fix e025726 is relatively recent and didn't make the cut for the most recent stable release (2.8.3) but will be in a future release (2.9 preview). In the meantime, use -O1 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dart2js-optimization web-dart2js
Projects
None yet
Development

No branches or pull requests

2 participants