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.06k stars 1.56k forks source link

feat: `dart` will try to run a compiled .exe as a .dill and crash #54654

Open eseidel opened 7 months ago

eseidel commented 7 months ago
eseidel@erics-mbp sdk % cat empty.dart
void main() {}
eseidel@erics-mbp sdk % dart compile exe empty.dart
Generated: /Users/eseidel/Documents/GitHub/dart-sdk/sdk/empty.exe
eseidel@erics-mbp sdk % dart empty.exe

It will eventually crash as:

(This crash isn't exactly from the command above, but rather copied from a report we got with a different executable, but I believe it will fail this way. I just didn't wait the many minutes to let it crash on my machine.)

Exhausted heap space, trying to allocate 35232 bytes.
Crash when compiling file:///Users/eseidel/Documents/GitHub/dart-sdk/sdk/empty.exe:
Out of Memory

#0      _StringBase._concatRangeNative (dart:core-patch/string_patch.dart:962:78)
#1      _JsonStringStringifier.stringify (dart:convert/json.dart:968:19)
#2      SourceLibraryBuilder.addProblem (package:front_end/src/fasta/source/source_library_builder.dart:1868:52)
#3      SourceLoader.tokenize (package:front_end/src/fasta/source/source_loader.dart:949:24)
#4      _rootRunUnary (dart:async/zone.dart:1407:47)
#5      _CustomZone.runUnary (dart:async/zone.dart:1308:19)
#6      _FutureListener.handleValue (dart:async/future_impl.dart:162:18)
#7      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:846:45)
#8      Future._propagateToListeners (dart:async/future_impl.dart:875:13)
#9      Future._completeWithValue (dart:async/future_impl.dart:647:5)
#10     Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:721:7)
#11     _rootRun (dart:async/zone.dart:1399:13)
#12     _CustomZone.run (dart:async/zone.dart:1301:19)
#13     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1233:23)
#14     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#15     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#16     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#17     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:405:11)
#18     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#19     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

 (2250.4s)
eseidel commented 7 months ago

I suspect the real bug is just that the .dill frontend doesn't error out fast enough. When stuff goes off the rails, it would be OK for it to error sooner. 🤷

In any case, there is obvious user/developer error here and it's fine if this just gets closed.

parlough commented 7 months ago

Since an input file and its compiled output can easily end up in the same directory (with similar names) and be supplied to the dart command accidentally, I think a better (and earlier) error message here would be quite useful. Thanks for raising this :)

I'm going to tentatively label this area-vm as I'm not sure if that handling should be in the VM or the frontend. Please retriage if necessary, thanks!