[dart2wasm] Simplify handling null receivers in gets, tear-offs, invocations #50508
Labels
area-dart2wasm
Issues for the dart2wasm compiler.
type-code-health
Internal changes to our tools and workflows to make them cleaner, simpler, or more maintainable
In dart2wasm we don't use the
Null
class fornull
values, instead we use Wasm'snull
value (ref.null
).This means we need special cases in the code generator when generating gets, tear-offs, and invocations (dynamic or instance) to check for
null
Wasm values and based on the member name generate code fornull.toString
tear-off or invocation, ornull.hashCode
instance get etc. Currently these look like this:sdk/pkg/dart2wasm/lib/code_generator.dart
Lines 1848 to 1872 in 50c5e8f
sdk/pkg/dart2wasm/lib/code_generator.dart
Lines 1928 to 1959 in 50c5e8f
sdk/pkg/dart2wasm/lib/code_generator.dart
Lines 1455 to 1476 in 50c5e8f
Since we don't use an actual Dart object for
null
we can't completely avoid these special cases, but we can simplify them a little bit by having a class representing thenull
object (say,WasmNull
), and when a receiver is null in a get, tear-off etc. we replace the receiver with the singleton instance ofWasmNull
. This class can be defined in Dart with the righttoString
,hashCode
etc. implementations.I tried this in a branch but it caused various crashes and it wasn't immediately obvious how can my changes break that much. This won't fix any tests but it may be a worthwhile simplification. We should probably revisit this at some point.
Related CLs:
Null
class.WasmNull
instead of core'sNull
.The text was updated successfully, but these errors were encountered: