Skip to content

Compiler crashes when compiling to WASM #54958

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

Closed
Schwusch opened this issue Feb 19, 2024 · 3 comments
Closed

Compiler crashes when compiling to WASM #54958

Schwusch opened this issue Feb 19, 2024 · 3 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop web-dart2js web-js-interop Issues that impact all js interop

Comments

@Schwusch
Copy link

When compiling to WASM on MacOS Sonoma 14.3, the Dart compiler crashes.
Complete log:

flutter build web --wasm

┌─ Experimental feature ───────────────────────────────┐
│   WebAssembly compilation is experimental.           │
│   See https://flutter.dev/wasm for more information. │
└──────────────────────────────────────────────────────┘

Target dart2js failed: ProcessException: Process exited abnormally with exit code 253:
lib/file_system_access/platform_file.dart:34:20:
Internal Error: Unknown external method j:method(FilePickerOptions|constructor#)
  external factory FilePickerOptions({
                   ^
The compiler is broken.

When compiling the above element, the compiler crashed. It is not
possible to tell if this is caused by a problem in your program or
not. Regardless, the compiler should not crash.

The Dart team would greatly appreciate if you would take a moment to
report this problem at http://dartbug.com/new.

Please include the following information:

* the name and version of your operating system,

* the Dart SDK build number (3.4.0-148.0.dev), and

* the entire message you see here (including the full stack trace
  below as well as the source location above).

The compiler crashed: Assertion failure: Unknown external method j:method(FilePickerOptions|constructor#)
#0      failedAt (package:compiler/src/diagnostics/invariant.dart:39:3)
#1      KernelSsaGraphBuilder._buildExternalFunctionNode (package:compiler/src/ssa/builder.dart:1820:5)
#2      KernelSsaGraphBuilder.build.<anonymous closure> (package:compiler/src/ssa/builder.dart:440:15)
#3      DiagnosticReporter.withCurrentElement (package:compiler/src/diagnostics/diagnostic_listener.dart:154:15)
#4      KernelSsaGraphBuilder.build (package:compiler/src/ssa/builder.dart:428:21)
#5      KernelSsaBuilder.build.<anonymous closure> (package:compiler/src/js_model/js_strategy.dart:525:22)
#6      CompilerTask.measure (package:compiler/src/common/tasks.dart:66:51)
#7      KernelSsaBuilder.build (package:compiler/src/js_model/js_strategy.dart:507:18)
#8      SsaBuilderTask.build (package:compiler/src/ssa/ssa.dart:365:21)
#9      SsaFunctionCompiler.compile (package:compiler/src/ssa/ssa.dart:99:28)
#10     OnDemandCodegenResults.getCodegenResults (package:compiler/src/common/codegen.dart:409:30)
#11     JsBackendStrategy.generateCode (package:compiler/src/js_model/js_strategy.dart:331:43)
#12     KernelCodegenWorkItem.run (package:compiler/src/js_model/js_strategy.dart:466:29)
#13     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:756:70)
#14     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#15     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:756:32)
#16     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#17     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:754:28)
#18     DiagnosticReporter.withCurrentElement (package:compiler/src/diagnostics/diagnostic_listener.dart:154:15)
#19     Compiler.emptyQueue.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:752:18)
#20     CodegenEnqueuer._forEach (package:compiler/src/js_backend/enqueuer.dart:267:12)
#21     CodegenEnqueuer.forEach (package:compiler/src/js_backend/enqueuer.dart:283:5)
#22     Compiler.emptyQueue.<anonymous closure> (package:compiler/src/compiler.dart:748:16)
#23     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#24     Compiler.emptyQueue (package:compiler/src/compiler.dart:747:14)
#25     Compiler.processQueue.<anonymous closure> (package:compiler/src/compiler.dart:771:7)
#26     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#27     Compiler.processQueue (package:compiler/src/compiler.dart:765:14)
#28     Compiler.runCodegenEnqueuer (package:compiler/src/compiler.dart:472:5)
#29     Compiler.runSequentialPhases (package:compiler/src/compiler.dart:684:27)
<asynchronous suspension>
#30     Compiler.runInternal.<anonymous closure> (package:compiler/src/compiler.dart:315:7)
<asynchronous suspension>
#31     Compiler.runInternal (package:compiler/src/compiler.dart:314:5)
<asynchronous suspension>
#32     Compiler.run.<anonymous closure> (package:compiler/src/compiler.dart:235:11)
<asynchronous suspension>
#33     compile.<anonymous closure> (package:compiler/compiler_api.dart:256:30)
<asynchronous suspension>
#34     compile.compilationDone (package:compiler/src/dart2js.dart:730:3)
<asynchronous suspension>
#35     main (package:compiler/src/dart2js.dart:1240:3)
<asynchronous suspension>
  Command: /Users/jonathanbocker/fvm/versions/master/bin/cache/dart-sdk/bin/dart --disable-dart-dev /Users/jonathanbocker/fvm/versions/master/bin/cache/dart-sdk/bin/snapshots/dart2js.dart.snapshot
  --platform-binaries=/Users/jonathanbocker/fvm/versions/master/bin/cache/flutter_web_sdk/kernel --invoker=flutter_tool -Ddart.vm.product=true
  -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/dd530f1556dfe22c6fc3549a1e8342fadde7302c/ -DFLUTTER_WEB_AUTO_DETECT=false -DFLUTTER_WEB_USE_SKIA=true --native-null-assertions
  --no-source-maps -O4 -o /Users/jonathanbocker/development/vdu/app/.dart_tool/flutter_build/886e40a1726ba7845dc07d95e6513162/main.dart.js
  /Users/jonathanbocker/development/vdu/app/.dart_tool/flutter_build/886e40a1726ba7845dc07d95e6513162/app.dill
#0      RunResult.throwException (package:flutter_tools/src/base/process.dart:127:5)
#1      _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart:326:19)
<asynchronous suspension>
#2      Dart2JSTarget.build (package:flutter_tools/src/build_system/targets/web.dart:195:5)
<asynchronous suspension>
#3      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:875:9)
<asynchronous suspension>
#4      Future.wait.<anonymous closure> (dart:async/future.dart:524:21)
<asynchronous suspension>
#5      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:813:32)
<asynchronous suspension>
#6      Future.wait.<anonymous closure> (dart:async/future.dart:524:21)
<asynchronous suspension>
#7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:813:32)
<asynchronous suspension>
#8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:642:16)
<asynchronous suspension>
#9      WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:91:34)
<asynchronous suspension>
#10     BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:237:5)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1394:27)
<asynchronous suspension>
#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:360:9)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:300:5)
<asynchronous suspension>
#17     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:119:9)
<asynchronous suspension>
#18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#19     main (package:flutter_tools/executable.dart:94:3)
<asynchronous suspension>

Compiling lib/main.dart for the Web...                             60.7s
Error: Failed to compile application for the Web.
@Schwusch
Copy link
Author

Schwusch commented Feb 19, 2024

The code in question is:

import 'dart:js_interop';
import 'package:web/web.dart';

extension WindowExtensions on Window {
  external JSPromise<JSArray<FileSystemFileHandle>?> showOpenFilePicker(
      FilePickerOptions options);
}

@JS()
extension type FilePickerOptions._(JSObject _) implements JSAny {
  external factory FilePickerOptions({
    String? id,
    JSArray<FileType>? types,
  });
}

@JS()
extension type FileType._(JSObject _) implements JSAny {
  external factory FileType({
    String? description,
    required JSAny accept,
  });
}

@lrhn lrhn added the area-dart2wasm Issues for the dart2wasm compiler. label Feb 19, 2024
@Schwusch
Copy link
Author

Found workaround here: #54801

Adding this on top makes the error go away:

@JS()
library;

@srujzs srujzs added web-dart2js web-js-interop Issues that impact all js interop area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop and removed area-dart2wasm Issues for the dart2wasm compiler. labels Feb 19, 2024
@srujzs
Copy link
Contributor

srujzs commented Feb 19, 2024

Duplicate of #54801 .

Looks like you found the workaround before I could respond. :) Also documented here under object literal constructors: https://dart.dev/interop/js-interop/usage#interop-type-members and should be fixed in 3.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop web-dart2js web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

3 participants