Skip to content

Commit 8fb9578

Browse files
nshahanCommit Queue
authored andcommitted
[ddc] Refactor function invocation visitors
`visitFunctionInvocation()` and `visitLocalFunctionInvocation()` now emit code directly. Towards reducing the variety of code that flows through `_emitMethodCall()` so hot reload soundness checks can be added when they are appropriate. Change-Id: I11e7fef6a454509a18f570bc2a316e81b9e09f2a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422365 Reviewed-by: Nate Biggs <[email protected]> Reviewed-by: Mark Zhou <[email protected]> Commit-Queue: Nicholas Shahan <[email protected]>
1 parent 4ddb83e commit 8fb9578

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5268,7 +5268,17 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
52685268

52695269
@override
52705270
js_ast.Expression visitFunctionInvocation(FunctionInvocation node) {
5271-
return _emitMethodCall(node.receiver, null, node.arguments, node);
5271+
assert(node.name.text == 'call');
5272+
var function = _visitExpression(node.receiver);
5273+
var arguments = _emitArgumentList(node.arguments);
5274+
if (node.functionType == null) {
5275+
// A `null` here implies the receiver is typed as `Function`. There isn't
5276+
// any more type information available at compile time to know this
5277+
// invocation is sound so a dynamic call will handle the checks at
5278+
// runtime.
5279+
return _emitDynamicInvoke(function, null, arguments, node.arguments);
5280+
}
5281+
return js_ast.Call(function, arguments);
52725282
}
52735283

52745284
@override
@@ -5292,11 +5302,10 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
52925302

52935303
@override
52945304
js_ast.Expression visitLocalFunctionInvocation(LocalFunctionInvocation node) {
5295-
return _emitMethodCall(
5296-
VariableGet(node.variable)..fileOffset = node.fileOffset,
5297-
null,
5298-
node.arguments,
5299-
node);
5305+
assert(node.name.text == 'call');
5306+
final localName = VariableGet(node.variable)..fileOffset = node.fileOffset;
5307+
return js_ast.Call(
5308+
_visitExpression(localName), _emitArgumentList(node.arguments));
53005309
}
53015310

53025311
@override

pkg/dev_compiler/lib/src/kernel/compiler_new.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5717,7 +5717,17 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
57175717

57185718
@override
57195719
js_ast.Expression visitFunctionInvocation(FunctionInvocation node) {
5720-
return _emitMethodCall(node.receiver, null, node.arguments, node);
5720+
assert(node.name.text == 'call');
5721+
var function = _visitExpression(node.receiver);
5722+
var arguments = _emitArgumentList(node.arguments);
5723+
if (node.functionType == null) {
5724+
// A `null` here implies the receiver is typed as `Function`. There isn't
5725+
// any more type information available at compile time to know this
5726+
// invocation is sound so a dynamic call will handle the checks at
5727+
// runtime.
5728+
return _emitDynamicInvoke(function, null, arguments, node.arguments);
5729+
}
5730+
return js_ast.Call(function, arguments);
57215731
}
57225732

57235733
@override
@@ -5741,11 +5751,10 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
57415751

57425752
@override
57435753
js_ast.Expression visitLocalFunctionInvocation(LocalFunctionInvocation node) {
5744-
return _emitMethodCall(
5745-
VariableGet(node.variable)..fileOffset = node.fileOffset,
5746-
null,
5747-
node.arguments,
5748-
node);
5754+
assert(node.name.text == 'call');
5755+
final localName = VariableGet(node.variable)..fileOffset = node.fileOffset;
5756+
return js_ast.Call(
5757+
_visitExpression(localName), _emitArgumentList(node.arguments));
57495758
}
57505759

57515760
@override

0 commit comments

Comments
 (0)