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 crash on local function type variables. #51899

Closed
lrhn opened this issue Mar 30, 2023 · 9 comments
Closed

Dart2js crash on local function type variables. #51899

lrhn opened this issue Mar 30, 2023 · 9 comments
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@lrhn
Copy link
Member

lrhn commented Mar 30, 2023

I received the error

Unexpected compile error.

--- Command "dart2js" (took 01.000144s):
DART_CONFIGURATION=ReleaseX64 out/ReleaseX64/dart-sdk/bin/dart compile js -Dtest_runner.configuration=dart2js-linux-chrome --sound-null-safety --test-mode --packages=.dart_tool/package_config.json tests/corelib/iterable_extension_test.dart --sound-null-safety --out=out/ReleaseX64/generated_compilations/dart2js-linux-chrome/tests_corelib_iterable_extension_test/iterable_extension_test.js

exit code:
253

stdout:
Info: Compiling with sound null safety.
The compiler crashed: Assertion failure: Local function type variables are not supported.
#0      failedAt (package:compiler/src/diagnostics/invariant.dart:39:3)
#1      JsToFrontendMapImpl.toBackendTypeVariable (package:compiler/src/js_model/js_world_builder.dart:586:9)
...

when trying to run a new test.
It's only test code, not the code being tested, so I'll pre-approve the failure for now.

It's coming from js_world_builder.dart:

  TypeVariableEntity? toBackendTypeVariable(TypeVariableEntity typeVariable) {
    if (typeVariable is KLocalTypeVariable) {
      if (_closureData == null) {
        failedAt(
            typeVariable, "Local function type variables are not supported.");
      }

but if it's reachable from user code, then it's a bug.

@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 Mar 30, 2023
@sigmundch
Copy link
Member

Thanks @lrhn - seems like dart2js has never added support for type variables on local functions. While I agree that should be fixed, it would be a shame to not have test coverage in dart2js for your new changes because of this (especially since your feature doesn't relate to this issue). In the meantime, would you consider a small refactor on the test to avoid this feature? I'll comment on your CL as well.

@lrhn
Copy link
Member Author

lrhn commented Mar 31, 2023

Are we sure it doesn't support local generic functions at all. The tests/language/generic/local_functions_test.dart test works, as far as I can see.
I can write simple generic local functions directly too. A little commenting in/out suggests that the problem is in the testIndexed function, which has a recursive generic local function. That might be the trigger, so moving just that one might be sufficient. (Still, make sure we have an issue tracking the fixing of that.)

But I'll rewrite the test and see if it helps.

@sigmundch
Copy link
Member

Sorry, you are right, I just jumped to conclusions too quickly by looking at the error message above.

@sigmundch
Copy link
Member

mmm... I was not able to repro the crash after I patched your CL locally. Do you know if it is still failing on your CL?

@sigmundch
Copy link
Member

Ah, never mind - I saw most closures were still around and I didn't notice that you did hoist testRec. Putting that one back in the method reintroduces the crash.

@sigmundch sigmundch added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Apr 7, 2023
@sigmundch
Copy link
Member

It appears the issue is directly related to records. Here is a minimal repro:

void main() {
  void f<T>(T value, (int, T) record) {
    (0, value) == record;
  }

  f("a", (0, "a"));
}

Which crashes with the following error:

The compiler crashed: Assertion failure: Local function type variables are not supported.
#0      failedAt (package:compiler/src/diagnostics/invariant.dart:39:3)
#1      JsToFrontendMapImpl.toBackendTypeVariable (package:compiler/src/js_model/js_world_builder.dart:586:9)
#2      JsToFrontendMapImpl.toBackendEntity (package:compiler/src/js_model/js_world_builder.dart:556:14)
#3      _TypeConverter.visitTypeVariableType (package:compiler/src/js_model/js_world_builder.dart:679:36)
#4      TypeVariableType.accept (package:compiler/src/elements/types.dart:499:15)
#5      _TypeConverter.visit (package:compiler/src/js_model/js_world_builder.dart:632:17)
#6      _TypeConverter.visitList (package:compiler/src/js_model/js_world_builder.dart:638:16)
#7      _TypeConverter.visitRecordType (package:compiler/src/js_model/js_world_builder.dart:672:46)
#8      RecordType.accept (package:compiler/src/elements/types.dart:440:15)
#9      _TypeConverter.visit (package:compiler/src/js_model/js_world_builder.dart:632:17)
#10     JsToFrontendMapImpl.toBackendType (package:compiler/src/js_model/js_world_builder.dart:550:16)
#11     MappedIterator.moveNext (dart:_internal/iterable.dart:393:20)
#12     JsToFrontendMap.toBackendTypeSet (package:compiler/src/js_model/js_to_frontend_map.dart:35:36)
#13     JClosedWorldBuilder.convertClosedWorld (package:compiler/src/js_model/js_world_builder.dart:150:13)
#14     JsBackendStrategy.createJClosedWorld (package:compiler/src/js_model/js_strategy.dart:188:52)
#15     Compiler.closeResolution (package:compiler/src/compiler.dart:815:25)
#16     Compiler.computeClosedWorld (package:compiler/src/compiler.dart:387:9)
#17     Compiler.produceClosedWorld (package:compiler/src/compiler.dart:629:11)
#18     Compiler.runSequentialPhases (package:compiler/src/compiler.dart:756:15)
<asynchronous suspension>
#19     Compiler.runInternal.<anonymous closure> (package:compiler/src/compiler.dart:319:7)
<asynchronous suspension>
#20     Compiler.runInternal (package:compiler/src/compiler.dart:318:5)
<asynchronous suspension>
#21     Compiler.run.<anonymous closure> (package:compiler/src/compiler.dart:239:11)
<asynchronous suspension>
#22     main (package:compiler/src/dart2js.dart:1474:3)
<asynchronous suspension>

@sigmundch
Copy link
Member

cc @rakudrama

@sigmundch sigmundch added this to the Dart 3 stable milestone Apr 7, 2023
@sigmundch
Copy link
Member

It appears related to the creation of the inner record. Here is an even simpler repro:

void main() {
  Object? f<T>(T value) => (0, value);
  f("a");
}

@sigmundch
Copy link
Member

I marked this as P1 for our team, since it's a crasher, but I don't consider this a blocker for the milestone. Feel free to move it out of the milestone as we approach the deadline.

@vsmenon vsmenon modified the milestones: Dart 3 stable, Dart 3 cleanup Apr 24, 2023
copybara-service bot pushed a commit that referenced this issue May 12, 2023
This cherry-picks a fix for a dart2js crash onto the stable channel.

For more information see #52216

=== original commit message ===
[dart2js] Convert recordTypes after closureData

Bug #51899

Change-Id: Id9108e6cf13aee409b127fe6cd007bef8f0fe609
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298460
Reviewed-by: Sigmund Cherem <[email protected]>
Reviewed-by: Mayank Patke <[email protected]>
Commit-Queue: Stephen Adams <[email protected]>
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302801
Commit-Queue: Sigmund Cherem <[email protected]>
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. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

4 participants