sdk
sdk copied to clipboard
[dart2wasm] Support `opaqueTrue` mechanism from dart2js.
Dart2js has a mechanism that allows keeping dead code alive until late in the optimization pipeline. This allows global analysis & transformations to consider the code alive (and therefore e.g. prevent certain information from being tree shaken by the proto aware tree shaker) but considers it dead later on in the compilation pipeline.
More specifically I'm referring to pkg/dart2js_runtime_metrics/lib/_opaque_bool_dart2js.dart:
/// Always returns `true`. This getter is opaque until SSA and is a counterpart
/// to [opaqueFalse].
@pragma('dart2js:prefer-inline')
bool get opaqueTrue => JS_TRUE();
/// Always returns `false`. This getter is opaque until SSA, so code guarded by
/// [opaqueFalse] will not be optimized away until late in the compilation
/// pipeline.
@pragma('dart2js:prefer-inline')
bool get opaqueFalse => JS_FALSE();
Currently this is used via conditional imports in pkg/dart2js_runtime_metrics/lib/opaque_bool.dart:
export '_opaque_bool_other.dart'
if (dart.library._dart2js_only) '_opaque_bool_dart2js.dart';
In dart2wasm this will just return true which in turn can cause issues as the global analysis & transformations can see that.
(This mechanism is used in internal apps to guard certain proto messages & fields from being tree shaken)