dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.09k stars 1.56k forks source link

dart2js: Code does not run with `-O0` #41484

Open rakudrama opened 4 years ago

rakudrama commented 4 years ago

I just tried running the code in https://github.com/dart-lang/sdk/issues/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:

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 commented 4 years ago

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

edyu commented 4 years ago

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 commented 4 years ago

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

edyu commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

Thanks for the investigation. The bug fix e0257265d34efffc845ea88643e183dc3cc5bb0e 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.