mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
Remove getProperty js_util optimization
Removing usage of the foreign JS function from the js_util CFE optimizations. Keeps foreign JS calls only injected by the compilers. There will be no change in generated JavaScript for dart2js, it was already inlining getProperty calls. There will be a small change for generated JavaScript for ddc, but we will work on adding a simple ddc inliner to account for it. Change-Id: Iadcc81a6798a8af397205bf6bb89d0bfbd095432 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214306 Commit-Queue: Riley Porter <rileyporter@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Srujan Gaddam <srujzs@google.com>
This commit is contained in:
parent
dc4d16fc1b
commit
e559b80f52
|
@ -12,7 +12,6 @@ import '../js_interop.dart' show getJSName;
|
|||
/// Replaces js_util methods with inline calls to foreign_helper JS which
|
||||
/// emits the code as a JavaScript code fragment.
|
||||
class JsUtilOptimizer extends Transformer {
|
||||
final Procedure _jsTarget;
|
||||
final Procedure _callMethodTarget;
|
||||
final List<Procedure> _callMethodUncheckedTargets;
|
||||
final Procedure _callConstructorTarget;
|
||||
|
@ -31,6 +30,7 @@ class JsUtilOptimizer extends Transformer {
|
|||
'setProperty'
|
||||
];
|
||||
final Iterable<Procedure> _allowedInteropJsUtilTargets;
|
||||
final Procedure _jsTarget;
|
||||
final Procedure _allowInteropTarget;
|
||||
final Procedure _listEmptyFactory;
|
||||
|
||||
|
@ -39,9 +39,7 @@ class JsUtilOptimizer extends Transformer {
|
|||
Map<Reference, ExtensionMemberDescriptor>? _extensionMemberIndex;
|
||||
|
||||
JsUtilOptimizer(this._coreTypes, ClassHierarchy hierarchy)
|
||||
: _jsTarget =
|
||||
_coreTypes.index.getTopLevelProcedure('dart:_foreign_helper', 'JS'),
|
||||
_callMethodTarget =
|
||||
: _callMethodTarget =
|
||||
_coreTypes.index.getTopLevelProcedure('dart:js_util', 'callMethod'),
|
||||
_callMethodUncheckedTargets = List<Procedure>.generate(
|
||||
5,
|
||||
|
@ -59,6 +57,8 @@ class JsUtilOptimizer extends Transformer {
|
|||
.getTopLevelProcedure('dart:js_util', 'setProperty'),
|
||||
_setPropertyUncheckedTarget = _coreTypes.index
|
||||
.getTopLevelProcedure('dart:js_util', '_setPropertyUnchecked'),
|
||||
_jsTarget =
|
||||
_coreTypes.index.getTopLevelProcedure('dart:_foreign_helper', 'JS'),
|
||||
_allowInteropTarget =
|
||||
_coreTypes.index.getTopLevelProcedure('dart:js', 'allowInterop'),
|
||||
_allowedInteropJsUtilTargets = _allowedInteropJsUtilMembers.map(
|
||||
|
@ -140,8 +140,8 @@ class JsUtilOptimizer extends Transformer {
|
|||
StringLiteral(_getExtensionMemberName(node))
|
||||
]))
|
||||
..fileOffset = node.fileOffset;
|
||||
return ReturnStatement(AsExpression(
|
||||
_lowerGetProperty(getPropertyInvocation), function.returnType));
|
||||
return ReturnStatement(
|
||||
AsExpression(getPropertyInvocation, function.returnType));
|
||||
}
|
||||
|
||||
/// Returns a new function body for the given [node] external setter.
|
||||
|
@ -199,16 +199,15 @@ class JsUtilOptimizer extends Transformer {
|
|||
|
||||
/// Replaces js_util method calls with optimization when possible.
|
||||
///
|
||||
/// Lowers `getProperty` for any argument type straight to JS fragment call.
|
||||
/// Lowers `setProperty` to `_setPropertyUnchecked` for values that are
|
||||
/// Lowers `setProperty` to `_setPropertyUnchecked` for values that are
|
||||
/// not Function type and guaranteed to be interop allowed.
|
||||
/// Lowers `callMethod` to `_callMethodUncheckedN` when the number of given
|
||||
/// arguments is 0-4 and all arguments are guaranteed to be interop allowed.
|
||||
/// Lowers `callConstructor` to `_callConstructorUncheckedN` when there are
|
||||
/// 0-4 arguments and all arguments are guaranteed to be interop allowed.
|
||||
@override
|
||||
visitStaticInvocation(StaticInvocation node) {
|
||||
if (node.target == _getPropertyTarget) {
|
||||
node = _lowerGetProperty(node);
|
||||
} else if (node.target == _setPropertyTarget) {
|
||||
if (node.target == _setPropertyTarget) {
|
||||
node = _lowerSetProperty(node);
|
||||
} else if (node.target == _callMethodTarget) {
|
||||
node = _lowerCallMethod(node);
|
||||
|
@ -219,28 +218,6 @@ class JsUtilOptimizer extends Transformer {
|
|||
return node;
|
||||
}
|
||||
|
||||
/// Lowers the given js_util `getProperty` call to the foreign_helper JS call
|
||||
/// for any argument type. Lowers `getProperty(o, name)` to
|
||||
/// `JS('Object|Null', '#.#', o, name)`.
|
||||
StaticInvocation _lowerGetProperty(StaticInvocation node) {
|
||||
Arguments arguments = node.arguments;
|
||||
assert(arguments.types.isEmpty);
|
||||
assert(arguments.positional.length == 2);
|
||||
assert(arguments.named.isEmpty);
|
||||
return StaticInvocation(
|
||||
_jsTarget,
|
||||
Arguments(
|
||||
[
|
||||
StringLiteral("Object|Null"),
|
||||
StringLiteral("#.#"),
|
||||
...arguments.positional
|
||||
],
|
||||
// TODO(rileyporter): Copy type from getProperty when it's generic.
|
||||
types: [DynamicType()],
|
||||
)..fileOffset = arguments.fileOffset)
|
||||
..fileOffset = node.fileOffset;
|
||||
}
|
||||
|
||||
/// Lowers the given js_util `setProperty` call to `_setPropertyUnchecked`
|
||||
/// when the additional validation checks in `setProperty` can be elided.
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue