Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Blocked on removing debug mode #1396

@leonsenft

Description

@leonsenft

See #952 for context.

Today we conditionally generate debug code based on the compilation mode: debug or release. For example, a simple check for changes in release mode

if (!identical(_expr_0, currVal_0) {

is instead generated as

if (checkBinding(_expr_0, currVal_0)) {

in debug mode. This is not an exhaustive list of differences, it's merely one example.

The intent is to remove the debug mode altogether, and instead generate code that relies on dart2js optimizations. For example, we make use of

https://github.com/dart-lang/angular/blob/1ba3746c60597b92aebfb6edbadcba9754f04ddb/angular/lib/src/runtime/optimizations.dart#L23

to guard debug code. The Angular compiler will emit this code unconditionally, and rely on constant-propagation and dead-code elimination in dart2js to optimize away statements guarded by isDevMode (which to dart2js with assertions disabled, is false throughout the lifetime of the program).

The goal is to avoid regressing the code generated for release mode. With the new single compilation mode using isDevMode, we've managed to retain identical dart2js output in all but one place: the original example above. We now always emit

if (checkBinding(_expr_0, currVal_0)) {

in place of

if (!identical(_expr_0, currVal_0) {

and rely on isDevMode internally to call !identical() for release mode. Initially we noticed checkBinding() is too long to inline, which we fixed with @dart2js.tryInline. We confirmed this is due to dart2js performing inlining before dead-code elimination.

This led to the issue that is unresolved today. The optimized checkBinding() call yields slightly more JavaScript than !identical().

<         if (this._feed_component_template$_expr_0 !== currVal_0) {
---
>         t1 = this._feed_component_template$_expr_0;
>         if (t1 !== currVal_0) {

This is again likely due to the order in which dart2js performs optimizations; at an earlier phase before code was eliminated it probably made sense to perform the assignment to t1, but in the final result it seems pointless (t1 is immediately reassigned to something else inside the if-block).

Until we resolve this regression (or accept it), we won't be able to remove the distinct compilation modes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions