-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
dart2wasm
compiler generates Wasm code with an invalid cast when calling a function with generics.
#59901
Comments
FYI: @kevmoo @askeksa @mkustermann |
Reproduced with Thanks for the detailed report and repro! 🙏 |
Thanks for the fast response. I hope to have this fixed on Dart 3.6.2, or I won't be able to finish the "dart:html" to "web" migration before Dart 3.7. Best regards. |
Thanks for the small repro. This is related to TFA. Relevant parts of post-TFA kernel:
Here type of
It looks like when TFA propagates the string value based on the conditional I think we should make TFA not assume that a string will always be represented as @mkustermann @alexmarkov any thoughts on this? |
If concrete class of literal is actually known and the problem is that inference of variable value after sdk/pkg/vm/lib/transformations/type_flow/summary_collector.dart Lines 1584 to 1586 in e1ba3ea
to add a target-specific predicate, something along the lines (rhs is StringLiteral &&
_isSubtype(lhs.variable.type,
_environment.coreTypes.stringNullableRawType) &&
target.canInferStringValueAfterEqualityComparison()) || By default, we can declare |
Two strings in dart2wasm can be equal but don't have to be identical nor have to have same concrete class. In VM's terminology: Imagine comparing a |
I'm trying both approaches.
|
IMHO, |
Both of the solutions are specific to dart2wasm, they don't impact other platforms. Returning (I found it somewhat surprising that it didn't make a larger impact, as benchmark code tend to be simpler than real world and more amenable to static analysis and so they can exaggerate results.) I still sent the CL with the new |
In dart2wasm, when a comparison like `x == "hello"` is true, we can't assume that the class of `x` is the same as the class of `"hello"`: - If `x` is received from JS, it will be `JSStringImpl`. - If it's a substring of a `TwoByteString`, it will be `TwoByteString`. - Otherwise it will be `OneByteString`. Update `Target` with the new method ``` bool get canInferStringClassAfterEqualityComparison => true; ``` to allow TFA to *not* infer classes of string values after comparisons. Override the method to return `false` in dart2wasm's `Target` implementation. Bug: #59901 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/404562 Cherry-pick-request: #59924 Change-Id: I1a6c8deaf27c54240dd4e821dbd8160914502ad7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404842 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Ömer Ağacan <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
I created a project to isolate and reproduce the error:
https://github.com/gmpassos/web_attr_issue
Isolating the compilation error was challenging due to tree-shaking and compiler optimizations.
When running the code in the project, the test freezes due to a "crash" in the WebAssembly VM in Chrome:
dart test --platform chrome --compiler dart2wasm
Output:
dart2js
, the test runs and completes successfully.Dart:
Dart SDK version: 3.6.1 (stable) (Tue Jan 7 09:50:00 2025 -0800) on "macos_x64"
The error also happens with
Dart 3.6.0
.The text was updated successfully, but these errors were encountered: