-
Notifications
You must be signed in to change notification settings - Fork 231
Blocked on removing debug mode #1396
Description
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
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.