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.22k stars 1.57k forks source link

[dev_compiler] Support enabling asserts for expression evaluation #43986

Closed annagrin closed 1 year ago

annagrin commented 3 years ago

Ddc relies on source information during compilation for creating assert statements. This information is not available if the kernel is loaded from dill, as in expression compilation provided by the expression compilation worker.

Suggestion: store needed source text for asserts in kernel instead. Alternative suggestion: source information (such as file and offsets) and invoke some post-failure step to add source text to the failure message.

See:

https://github.com/dart-lang/sdk/blob/2259593f836cf975f8d9aa86b3134f0c8748acd7/pkg/dev_compiler/lib/src/kernel/compiler.dart#L3617

devoncarew commented 3 years ago

@annagrin - when creating an issue on the sdk repo - if you know the area for it (like area-web for this item) - can you add the area label? It'll reduce the work for the issue triagers; thanks!

annagrin commented 3 years ago

Sure, thanks!

nshahan commented 1 year ago

One reason that compiling an assertion requires the source is that flutter requested when assertions fail the error message includes the source code that failed. The VM does this, but I don't know if the VM does this for assertions written in debugger expressions. We could double check if they do and if so how do they get the source code?

I think another possibility here would be to just not include that information in the error message if there isn't a valid source location available. We could have a separate path when compiling assertions in the expression compiler that is more forgiving and not expect source location to be available. I think it would be understandable if you were to write a failing assertion expression in the debugger and you didn't get back source information when it failed. A message that just says something like "Assertion failed. Error from compiled expression."

annagrin commented 1 year ago

Update: I am changing the DDC compiler code to be resilient to this failure - ie have some reporting with missing information. This allows us to enable asserts in the expression compiler and add tests in the SDK that match the CI bot configurations.

https://dart-review.googlesource.com/c/sdk/+/317448

Evaluating () { assert(false); return 0; } will now result in

Error: Assertion failed: <unknown source>:-1:-1
  BoolLiteral(false)
  is not true

Note that VM does something similar:

Unhandled exception:
'': Failed assertion: line -1: '<optimized out>': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2      Eval.<anonymous closure> ()
#3      Eval ()
annagrin commented 1 year ago

Closed in https://dart-review.googlesource.com/c/sdk/+/317448