-
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: Failed null check at ClosureRepresentation.fieldIndexForSignature on a statically typed constructor tearoff expression #56372
Comments
Summary: The |
/cc @osa1 Could you have a look? |
I'm unable to reproduce the issue from the snippets. Is it possible to share the whole project with commands to run to get the error? |
It's a private repo, maybe I can add you as a collaborator temporarily so you can access it? |
@plammens unfortunately we are only allowed to look at appropriately licensed open source code. (Not sure which licenses are those exactly, but common ones like BSD, MIT etc. work) For now I will try a few more things to try to reproduce this. |
@plammens Could you try to verify that this problem still happens when you're on flutter master channel?
This is an indication that the issue is due to a partial instantiation of a tear-off constant, i.e.
The issue has to do with closure representations. Dart2wasm will try to make a good calling convention for closures. To do that it will look at a) all function definitions b) all function call sites. It then partitions them together into groups that have to be together (all possible definitions for a given callsite, all callsites for a definition) and based on those groups makes optimized vtables for fast closure calls. If this issue still persists on flutter master channel, then we'll need a minimal reproduction we can look at (I've spent the entire morning looking through the relevant code and trying to construct cases that could trigger this, but failed to come up with an example where this would trigger). What we need for a minimal reproduction is the code that creates those closures (class hierarchy, constructors and how the constructor tear-offs are used) and the code that invokes those closures. @plammens Could you try to make a minimal flutter app that reproduces this? |
I can confirm that the issue is still there on master, flutter/flutter@e66ce15 .
```text
Flutter 3.24.0-1.0.pre.517 • channel master • https://github.com/flutter/flutter.git
Framework • revision e66ce1591f (16 minutes ago) • 2024-08-08 14:25:19 -0400
Engine • revision 387f6f3c5f
Tools • Dart 3.6.0 (build 3.6.0-129.0.dev) • DevTools 2.38.0
```
I'll try again making a reproducible example, this time I'll try to work my way down from my actual code to a more minimal version instead of trying to build my way up. |
I've used a script to put all my code in a single file to try to whittle it down to a minimal example, but it seems this is going to take forever because many times I delete some code that seems completely unrelated and the error goes away. Plus I have to wait 60 seconds between each iteration due to having to run the command. At least it does seem to be deterministic with respect to the code. Currently gone from 10k lines of code to 7.5k. Is there any chance I can just send you the file privately and slap an open-source license on it? It's a personal project anyway. |
We really appreciate the effort, @plammens !
If it's under an open source license we can take a look - irrespective of how it's shared. You're welcome to share via email. |
Okay, I've added a GPL license to the file. What email address should I send it to? I'll also send the pubspec in case you need it. By the way, don't try to make too much sense of the code as it is now in a heavily mutilated state :) |
You can send it to |
Done, thanks! |
@plammens Thank you very much for the reproduction! The following test case reproduces the issue void main() {
final funs = <String Function({Object? shared})>[
foo,
bar,
];
final one = int.parse('1');
final barS = funs[one] as String Function({Object? barSpecific});
if (barS(barSpecific: 1) != 'bar(null, 1)') {
throw 'failed: ${barS(barSpecific: 1)}';
}
}
String foo<T>({Object? shared, Object? fooSpecific}) =>
'foo<$T>($shared, $fooSpecific)';
String bar({Object? shared, Object? barSpecific}) =>
'bar($shared, $barSpecific)'; => Sent out cl/380100 |
Partial instantiation constants are closures. Those closures have vtables with all entries needed for the closure representation corresponding to the instantiated closure. The entries of those vtables have to either call the corresponding method of the generic closure, or are unreachable dummy entries. Dummy entries can be required due to clustering callees/callers together where a particular target doesn't support the name combination. The case that was incorrect is if the particular name combination did not get clustered with anything for the generic closure representation. Issue #56372 TEST=web/wasm/regress_56372_test Change-Id: Ifbf624e10dd1162f4d5660b43914e5b34ba82294 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380100 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Ömer Ağacan <[email protected]>
Fixed with f7fc4d0. |
@plammens The fix should have rolled up all the way to flutter/flutter now, so it's available on main/master channel |
Partial instantiation constants are closures. Those closures have vtables with all entries needed for the closure representation corresponding to the instantiated closure. The entries of those vtables have to either call the corresponding method of the generic closure, or are unreachable dummy entries. Dummy entries can be required due to clustering callees/callers together where a particular target doesn't support the name combination. The case that was incorrect is if the particular name combination did not get clustered with anything for the generic closure representation. Issue #56372 TEST=web/wasm/regress_56372_test Bug: #56372 Change-Id: I7a219237519c39d982b89ce272f33fb4d90cd173 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/380100 Cherry-pick-request: #56440 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380120 Reviewed-by: Ömer Ağacan <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
I get a compilation error when compiling to wasm with
flutter build web --wasm --release
(that I don't get with other compilation targets.) (I use a flutter command but the error happens in thedart2wasm
library, so I'm posting the issue here.)The error is:
Stack trace:
I've tried to write a minimal reproducible example from scratch, but I haven't succeeded, so I'll show my actual code.
The culprit of this exception, as pointed out by the error, seems to be this tearoff expression:
I have the following typedefs:
The problem disappears when I set:
Related code (definition of
EditHabit.blank
):Surprisingly, I have other elements in the map above for which this error does not occur, in particular for
EditTask.blank
:I thought the difference might be in the
const
, but I haven't managed to make a minimal reproducible example. Maybe someone experienced withdart2wasm
will be able to do so.dart info
)Whether you are using Windows, macOS, or Linux (if applicable)
Windows
Whether you are using Chrome, Safari, Firefox, Edge (if applicable)
Chrome
The text was updated successfully, but these errors were encountered: