Skip to content

Commit 69fce63

Browse files
mralephcommit-bot@chromium.org
authored andcommitted
[vm/compiler] Omit implicit result type check for recognized natives.
We will still type check returns from native methods but everything that is explicitly handled by graph builder would be trusted. Bug: #31798 Change-Id: Ia2f5dfba63349bef7578ca4774686f47b5e484b1 Reviewed-on: https://dart-review.googlesource.com/70644 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Vyacheslav Egorov <[email protected]>
1 parent 8629563 commit 69fce63

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

runtime/vm/compiler/frontend/kernel_to_il.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,15 @@ Fragment FlowGraphBuilder::NativeCall(const String* name,
449449
return Fragment(call);
450450
}
451451

452-
Fragment FlowGraphBuilder::Return(TokenPosition position) {
452+
Fragment FlowGraphBuilder::Return(TokenPosition position,
453+
bool omit_result_type_check /* = false */) {
453454
Fragment instructions;
454455
const Function& function = parsed_function_->function();
455456

456457
// Emit a type check of the return type in checked mode for all functions
457458
// and in strong mode for native functions.
458-
if (I->type_checks() || (function.is_native() && I->strong())) {
459+
if (!omit_result_type_check &&
460+
(I->type_checks() || (function.is_native() && I->strong()))) {
459461
const AbstractType& return_type =
460462
AbstractType::Handle(Z, function.result_type());
461463
instructions += CheckAssignable(return_type, Symbols::FunctionResult());
@@ -741,7 +743,8 @@ Fragment FlowGraphBuilder::NativeFunctionBody(const Function& function,
741743
// to build these graphs so that this code is not duplicated.
742744

743745
Fragment body;
744-
MethodRecognizer::Kind kind = MethodRecognizer::RecognizeKind(function);
746+
const MethodRecognizer::Kind kind = MethodRecognizer::RecognizeKind(function);
747+
bool omit_result_type_check = true;
745748
switch (kind) {
746749
case MethodRecognizer::kObjectEquals:
747750
body += LoadLocal(scopes_->this_variable);
@@ -919,10 +922,12 @@ Fragment FlowGraphBuilder::NativeFunctionBody(const Function& function,
919922
body += PushArgument();
920923
}
921924
body += NativeCall(&name, &function);
925+
// We typecheck results of native calls for type safety.
926+
omit_result_type_check = false;
922927
break;
923928
}
924929
}
925-
return body + Return(TokenPosition::kNoSource);
930+
return body + Return(TokenPosition::kNoSource, omit_result_type_check);
926931
}
927932

928933
Fragment FlowGraphBuilder::BuildImplicitClosureCreation(

runtime/vm/compiler/frontend/kernel_to_il.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class FlowGraphBuilder : public BaseFlowGraphBuilder {
111111
Fragment LoadLocal(LocalVariable* variable);
112112
Fragment InitStaticField(const Field& field);
113113
Fragment NativeCall(const String* name, const Function* function);
114-
Fragment Return(TokenPosition position);
114+
Fragment Return(TokenPosition position, bool omit_result_type_check = false);
115115
Fragment CheckNull(TokenPosition position,
116116
LocalVariable* receiver,
117117
const String& function_name);

0 commit comments

Comments
 (0)