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

Uri.parse result with dart2js throws runtime error on -O0, while other levels are OK #55058

Open
daniel-v opened this issue Feb 29, 2024 · 2 comments
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@daniel-v
Copy link

daniel-v commented Feb 29, 2024

dart info


If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

#### General info

- Dart 3.2.6 (stable) (Wed Jan 24 13:41:58 2024 +0000) on "linux_x64"
- on linux / Linux 6.7.5-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Feb 17 17:20:08 UTC 2024
- locale is en_US.UTF-8

#### Project info

- sdk constraint: '>=2.17.0 <4.0.0'
- dependencies: sentry, web
- dev_dependencies: build_runner, build_web_compilers, lints

#### Process info

| Memory |  CPU | Elapsed time | Command line                                                                    |
| -----: | ---: | -----------: | ------------------------------------------------------------------------------- |
| 481 MB | 0.4% |     01:12:25 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.82.0 |
| 711 MB | 1.5% |        42:00 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.82.0 |

The following code throws with -O0 when compiled with dart2js (release mode), while it works properly with other optimization levels:

void main() {
  var uri = Uri.parse('https://aaaa@bbbb.dart.dev/pathsegment');
  print('${uri.pathSegments.isEmpty}');
}

Uri.parse internally calls _computePathSegments which returns either a const <String>[] or List<String>.unmodifiable(pathToSplit.split("/").map(Uri.decodeComponent)).

I went ahead and tested if any of these might be the source of the problem and NO. In -O0, _computePathSegments is never actually called. In the compiled code, the execution stops here:

  A._Uri.prototype = {
    // ...
    get$pathSegments() {
      var result,
        value = this.___Uri_pathSegments_FI;
      if (A.boolConversionCheck(A.isSentinel(value))) { // HERE
        result = A._Uri__computePathSegments(this.path);
        value !== $ && A.throwLateFieldADI("pathSegments");
        this.set$___Uri_pathSegments_FI(result);
        value = result;
      }
      return value;
    },

The expression A.isSentinel(value) ALWAYS returns false - seem to be hard-coded:

    isSentinel(value) {
      return false;
    },

❗ NOTE: replacing @ with eg. _ in the URL seem to fix the problem in -O0 😕

Update: found out why _ works while @ doesn't. Uri.parse with _ instantiates _SimpleUri while @ causes to instantiate _Uri that in fact calls _computePathSegments.

Is there anything else I can show/give you to help track this down?

@lrhn lrhn added web-dart2js type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels Feb 29, 2024
@fishythefish
Copy link
Member

Likely the same root cause as #49599. That bug hasn't been high priority, but I can take another look now that we have a report of someone using -O0 and running into this in the wild.

@fishythefish fishythefish self-assigned this Feb 29, 2024
@daniel-v
Copy link
Author

daniel-v commented Mar 1, 2024

Likely the same root cause as #49599. That bug hasn't been high priority, but I can take another look now that we have a report of someone using -O0 and running into this in the wild.

To be fair, @fishythefish , I don't think it is that common.

What I do use -O0 for is debugging as it has the most info when compiling with dart2js. There are those bugs that just don't show up with DDC and dart2js is used for prod push.

Thanks if you look at it but even for me, I don't think it is high prio.

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. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants