dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.24k stars 1.57k forks source link

[dart2js] Crash in modular compile #49681

Open rakudrama opened 2 years ago

rakudrama commented 2 years ago

This hand-written modular script causes dart2js to crash when run from the sdk enlistment.

Many targets, including some really large ones, work properly.

#!/bin/bash

OUT=om1x
MAIN=benchmarks/OmnibusDeferred/dart
PACKAGES=.dart_tool/package_config.json
ENTRY=$MAIN/OmnibusDeferred.dart

OPTIONS="-O4 --no-minify "

DART2JS="out/ReleaseX64/dart-sdk/bin/dart pkg/compiler/lib/src/dart2js.dart --invoker=x --packages=$PACKAGES $OPTIONS"

set -x

$DART2JS --cfe-only --out=$OUT/cfe.dill $ENTRY

$DART2JS --input-dill=$OUT/cfe.dill --entry-uri=$ENTRY \
  --write-closed-world=$OUT/world.data --out=$OUT/modified.dill

$DART2JS --input-dill=$OUT/modified.dill --entry-uri=$ENTRY \
    --read-closed-world=$OUT/world.data --write-data=$OUT/global.data \
    --no-closed-world-in-data

$DART2JS --input-dill=$OUT/modified.dill --entry-uri=$ENTRY \
    --read-closed-world=$OUT/world.data --read-data=$OUT/global.data \
    --codegen-shards=1 --codegen-shard=0 --write-codegen=$OUT/codegen

$DART2JS --input-dill=$OUT/modified.dill --entry-uri=$ENTRY \
    --read-closed-world=$OUT/world.data --read-data=$OUT/global.data \
    --codegen-shards=1 --read-codegen=$OUT/codegen --out=$OUT/out.js
$ bash modular.sh
+ out/ReleaseX64/dart-sdk/bin/dart pkg/compiler/lib/src/dart2js.dart --invoker=x --packages=.dart_tool/package_config.json -O4 --no-minify --cfe-only --out=om1x/cfe.dill benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart
Compiled 10,142,869 characters Dart to 10,826,976 kernel bytes in 3.43 seconds using 194.617 MB of memory
Dart file benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart compiled to dill: om1x/cfe.dill.
+ out/ReleaseX64/dart-sdk/bin/dart pkg/compiler/lib/src/dart2js.dart --invoker=x --packages=.dart_tool/package_config.json -O4 --no-minify --input-dill=om1x/cfe.dill --entry-uri=benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart --write-closed-world=om1x/world.data --out=om1x/modified.dill
Serialized 20,334,792 kernel bytes to 11,568,166 bytes data in 3.02 seconds using 221.234 MB of memory
Dart file om1x/cfe.dill serialized to dill and data: om1x/modified.dill and om1x/world.data.
+ out/ReleaseX64/dart-sdk/bin/dart pkg/compiler/lib/src/dart2js.dart --invoker=x --packages=.dart_tool/package_config.json -O4 --no-minify --input-dill=om1x/modified.dill --entry-uri=benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart --read-closed-world=om1x/world.data --write-data=om1x/global.data --no-closed-world-in-data
Serialized 11,568,166 bytes data to 11,043,168 bytes data in 2.55 seconds using 182.355 MB of memory
Data files om1x/modified.dill and om1x/world.data serialized to dill and data: out.dill and om1x/global.data.
+ out/ReleaseX64/dart-sdk/bin/dart pkg/compiler/lib/src/dart2js.dart --invoker=x --packages=.dart_tool/package_config.json -O4 --no-minify --input-dill=om1x/modified.dill --entry-uri=benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart --read-closed-world=om1x/world.data --read-data=om1x/global.data --codegen-shards=1 --codegen-shard=0 --write-codegen=om1x/codegen
Serialized 11,752,990 bytes data to 1,181,035 bytes data in 3.95 seconds using 181.586 MB of memory
Data files om1x/modified.dill, om1x/world.data, and om1x/global.data serialized to codegen data: om1x/codegen0.
+ out/ReleaseX64/dart-sdk/bin/dart pkg/compiler/lib/src/dart2js.dart --invoker=x --packages=.dart_tool/package_config.json -O4 --no-minify --input-dill=om1x/modified.dill --entry-uri=benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart --read-closed-world=om1x/world.data --read-data=om1x/global.data --codegen-shards=1 --read-codegen=om1x/codegen --out=om1x/out.js
benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart@2729+1:
Internal Error: The compiler crashed when compiling this element.
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 (build number could not be determined), and

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

The compiler crashed: type 'JField' is not a subtype of type 'IndexedConstructor'
#0      ClosedEntityReader._readLateMemberFromDataSource (package:compiler/src/js_model/element_map_impl.dart:2660:28)
#1      ClosedEntityReader.readMemberFromDataSource (package:compiler/src/js_model/element_map_impl.dart:2649:14)
#2      DataSourceReader.readMember (package:compiler/src/serialization/source.dart:1053:26)
#3      DataSourceReader.readMemberOrNull (package:compiler/src/serialization/source.dart:1061:14)
#4      new DictionaryTypeMask.readFromDataSource (package:compiler/src/inferrer/typemasks/dictionary_type_mask.dart:37:45)
#5      new TypeMask.readFromDataSource (package:compiler/src/inferrer/typemasks/type_mask.dart:262:35)
#6      CommonMasks.readAbstractValueFromDataSource.<anonymous closure> (package:compiler/src/inferrer/typemasks/masks.dart:982:46)
#7      UnorderedIndexedSource._readAtOffset.<anonymous closure> (package:compiler/src/serialization/indexed_sink_source.dart:128:23)
#8      BinaryDataSource.readAtOffset (package:compiler/src/serialization/binary_source.dart:86:25)
#9      DataSourceReader.readWithOffset (package:compiler/src/serialization/source.dart:227:26)
#10     UnorderedIndexedSource._readAtOffset.<anonymous closure> (package:compiler/src/serialization/indexed_sink_source.dart:134:33)
#11     DataSourceReader.readWithSource (package:compiler/src/serialization/source.dart:221:20)
#12     UnorderedIndexedSource._readAtOffset (package:compiler/src/serialization/indexed_sink_source.dart:133:25)
#13     UnorderedIndexedSource.read (package:compiler/src/serialization/indexed_sink_source.dart:114:12)
#14     DataSourceReader.readCachedOrNull (package:compiler/src/serialization/source.dart:273:19)
#15     DataSourceReader.readCached (package:compiler/src/serialization/source.dart:262:16)
#16     CommonMasks.readAbstractValueFromDataSource (package:compiler/src/inferrer/typemasks/masks.dart:982:10)
#17     CodegenReaderImpl.readAbstractValue (package:compiler/src/common/codegen.dart:2224:10)
#18     DataSourceReader.readAbstractValue (package:compiler/src/serialization/source.dart:1423:28)
#19     new DynamicUse.readFromDataSource (package:compiler/src/universe/use.dart:68:35)
#20     new _CodegenImpact.readFromDataSource.<anonymous closure> (package:compiler/src/common/codegen.dart:113:42)
#21     DataSourceReader.readListOrNull (package:compiler/src/serialization/source.dart:308:18)
#22     new _CodegenImpact.readFromDataSource (package:compiler/src/common/codegen.dart:113:10)
#23     new CodegenResult.readFromDataSource (package:compiler/src/common/codegen.dart:499:42)
#24     SerializationTask._deserializeCodegenInput.<anonymous closure>.<anonymous closure> (package:compiler/src/serialization/task.dart:398:46)
#25     BinaryDataSource.readAtOffset (package:compiler/src/serialization/binary_source.dart:86:25)
#26     DataSourceReader.readWithOffset (package:compiler/src/serialization/source.dart:227:26)
#27     _DeferredCache._loadData (package:compiler/src/serialization/deferrable.dart:100:19)
#28     _DeferredCache._data (package:compiler/src/serialization/deferrable.dart:90:24)
#29     _DeferredCache._data (package:compiler/src/serialization/deferrable.dart)
#30     _DeferredCache.loaded (package:compiler/src/serialization/deferrable.dart:93:17)
#31     DeferrableValueMap.[] (package:compiler/src/serialization/deferrable.dart:120:23)
#32     DeserializedCodegenResults.getCodegenResults (package:compiler/src/common/codegen.dart:462:32)
#33     JsBackendStrategy.generateCode (package:compiler/src/js_model/js_strategy.dart:328:43)
#34     KernelCodegenWorkItem.run (package:compiler/src/js_model/js_strategy.dart:472:29)
#35     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:751:70)
#36     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#37     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:751:32)
#38     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#39     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:749:28)
#40     DiagnosticReporter.withCurrentElement (package:compiler/src/diagnostics/diagnostic_listener.dart:142:15)
#41     Compiler.emptyQueue.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:747:18)
#42     CodegenEnqueuer._forEach (package:compiler/src/js_backend/enqueuer.dart:249:12)
#43     CodegenEnqueuer.forEach (package:compiler/src/js_backend/enqueuer.dart:265:5)
#44     Compiler.emptyQueue.<anonymous closure> (package:compiler/src/compiler.dart:743:16)
#45     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#46     Compiler.emptyQueue (package:compiler/src/compiler.dart:742:14)
#47     Compiler.processQueue.<anonymous closure> (package:compiler/src/compiler.dart:766:7)
#48     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#49     Compiler.processQueue (package:compiler/src/compiler.dart:760:14)
#50     Compiler.runCodegenEnqueuer (package:compiler/src/compiler.dart:506:5)
#51     Compiler.runSequentialPhases (package:compiler/src/compiler.dart:690:23)
<asynchronous suspension>
#52     Compiler.runInternal.<anonymous closure> (package:compiler/src/compiler.dart:315:7)
<asynchronous suspension>
#53     Compiler.runInternal (package:compiler/src/compiler.dart:314:5)
<asynchronous suspension>
#54     Compiler.run.<anonymous closure> (package:compiler/src/compiler.dart:235:11)
<asynchronous suspension>
#55     main (package:compiler/src/dart2js.dart:1423:3)
<asynchronous suspension>
sigmundch commented 2 years ago

does the failure reproduce if we copy this benchmark into the modular test suite directory? (thinking whether there is an easy way to add a regression test in the future?)

rakudrama commented 2 years ago

This benchmark pulls in 12 other benchmarks, so it would be a bit of a bear to move. Perhaps we can compile it in place from there by importing it.

rakudrama commented 2 years ago

I didn't manage to import it - the benchmarks directory is not part of any package:, and a ../.. file import goes above the root.