Can someone explain what the patch keyword does? For example, in
math_patch.dart
I see
patch num pow(num x, num exponent) => MathNatives.pow(x, exponent);
patch double atan2(num a, num b) => MathNatives.atan2(a, b);
patch double sin(num x) => MathNatives.sin(x);
patch double cos(num x) => MathNatives.cos(x);
What does this mean? What are _patch.dart
files for?
The patch mechanism is used internally (and is only available internally, not to end users) to provide different implementations of core library functionality.
For the math library that you have below, the platform independent
library source in lib/math
declares these methods as external
.
external
methods get their implementation from a patch file. There
is a patch file in the VM in runtime/lib/math_patch.dart
, which
supplies the implementation for the VM and there is a patch file in
the dart2js
compiler in
lib/compiler/implementation/lib/math_patch.dart
, which supplies the
dart2js
implementation.
The external
keyword is understood by the analyzer and doing it this
way allows only the shared part to be in the SDK and be understood by
the tools. That means that the SDK can have lib/math
instead of having
lib/math/runtime
and lib/math/dart2js
, which makes the SDK cleaner and
easier to understand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With