Skip to content

Commit f46670e

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm,dyn_modules] Support instantiated tear-offs of generic instance methods in the interpreter
TEST=ci (co19/Language/Expressions/Property_Extraction/Generic_Method_Instantiation/generic_method_A02_t03) Change-Id: I9b4862cdbaf6977230e1cce9f5f82c729464425f Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443638 Reviewed-by: Tess Strickland <[email protected]> Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 6100970 commit f46670e

File tree

4 files changed

+68
-9
lines changed

4 files changed

+68
-9
lines changed

runtime/vm/constants_kbc.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ static const KBCInstr
4848
KernelBytecode::kTrap,
4949
};
5050

51+
static const KBCInstr kVMInternal_ImplicitInstanceClosureInstructions[] = {
52+
KernelBytecode::kVMInternal_ImplicitInstanceClosure,
53+
0,
54+
0,
55+
KernelBytecode::kReturnTOS,
56+
};
57+
58+
static const KBCInstr kVMInternal_ImplicitInstanceClosure_WideInstructions[] = {
59+
KernelBytecode::kTrap,
60+
};
61+
5162
#define DECLARE_INSTRUCTIONS(name, fmt, kind, fmta, fmtb, fmtc) \
5263
static const KBCInstr k##name##Instructions[] = { \
5364
KernelBytecode::k##name, \

runtime/vm/constants_kbc.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,14 @@ namespace dart {
205205
// These bytecodes are only generated within the VM. Reassigning their
206206
// opcodes is not a breaking change.
207207
#define INTERNAL_KERNEL_BYTECODES_WITH_CUSTOM_CODE(V) \
208-
/* VMInternal_ImplicitConstructorClosure uses D_F encoding as it calls */ \
209-
/* constructor and should be compatible with other ***Call instructions */ \
208+
/* ImplicitConstructorClosure and ImplicitInstanceClosure instructions */ \
209+
/* use D_F encoding as they may call target constructor or method and */ \
210+
/* should be compatible with other ***Call instructions */ \
210211
/* in order to support DecodeArgc when returning from a call. */ \
211212
V(VMInternal_ImplicitConstructorClosure, D_F, ORDN, num, num, ___) \
212213
V(VMInternal_ImplicitConstructorClosure_Wide, D_F, ORDN, num, num, ___) \
214+
V(VMInternal_ImplicitInstanceClosure, D_F, ORDN, num, num, ___) \
215+
V(VMInternal_ImplicitInstanceClosure_Wide, D_F, ORDN, num, num, ___) \
213216

214217
#define INTERNAL_KERNEL_BYTECODES_WITH_DEFAULT_CODE(V) \
215218
V(VMInternal_ImplicitGetter, 0, ORDN, ___, ___, ___) \
@@ -221,7 +224,6 @@ namespace dart {
221224
V(VMInternal_InvokeField, 0, ORDN, ___, ___, ___) \
222225
V(VMInternal_ForwardDynamicInvocation, 0, ORDN, ___, ___, ___) \
223226
V(VMInternal_ImplicitStaticClosure, 0, ORDN, ___, ___, ___) \
224-
V(VMInternal_ImplicitInstanceClosure, 0, ORDN, ___, ___, ___) \
225227
V(VMInternal_NoSuchMethodDispatcher, 0, ORDN, ___, ___, ___) \
226228

227229
#define INTERNAL_KERNEL_BYTECODES_LIST(V) \

runtime/vm/interpreter.cc

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,7 +3757,7 @@ ObjectPtr Interpreter::Run(Thread* thread,
37573757
}
37583758

37593759
{
3760-
BYTECODE(VMInternal_ImplicitInstanceClosure, 0);
3760+
BYTECODE(VMInternal_ImplicitInstanceClosure, D_F);
37613761
FunctionPtr function = FrameFunction(FP);
37623762
ASSERT(Function::KindOf(function) ==
37633763
UntaggedFunction::kImplicitClosureFunction);
@@ -3770,10 +3770,60 @@ ObjectPtr Interpreter::Run(Thread* thread,
37703770
const intptr_t argc =
37713771
InterpreterHelpers::ArgDescArgCount(argdesc_) + receiver_idx;
37723772
ObjectPtr* argv = FrameArguments(FP, argc);
3773+
ClosurePtr closure = Closure::RawCast(argv[receiver_idx]);
3774+
3775+
TypeParametersPtr type_params =
3776+
FunctionType::RawCast(function->untag()->signature())
3777+
->untag()
3778+
->type_parameters();
3779+
if (type_params == null_value) {
3780+
if (type_args_len > 0) {
3781+
SP[1] = function;
3782+
goto NoSuchMethodFromPrologue;
3783+
}
3784+
} else {
3785+
TypeArgumentsPtr delayed_type_arguments =
3786+
closure->untag()->delayed_type_arguments();
3787+
if (delayed_type_arguments != Object::empty_type_arguments().ptr()) {
3788+
if (type_args_len > 0) {
3789+
SP[1] = function;
3790+
goto NoSuchMethodFromPrologue;
3791+
}
3792+
3793+
// Type arguments.
3794+
*++SP = delayed_type_arguments;
3795+
ObjectPtr* call_base = SP;
3796+
// Captured receiver.
3797+
*++SP = closure->untag()->context();
3798+
// Copy the rest of the arguments.
3799+
for (intptr_t i = receiver_idx + 1; i < argc; i++) {
3800+
*++SP = argv[i];
3801+
}
3802+
3803+
const intptr_t new_type_args_len =
3804+
Smi::Value(type_params->untag()->names()->untag()->length());
3805+
3806+
SP[1] = target;
3807+
SP[2] = 0; // Space for result.
3808+
SP[3] = argdesc_;
3809+
SP[4] = target;
3810+
SP[5] = Smi::New(new_type_args_len);
3811+
Exit(thread, FP, SP + 6, pc);
3812+
INVOKE_RUNTIME(DRT_AdjustArgumentsDesciptorForImplicitClosure,
3813+
NativeArguments(thread, 3, SP + 3, SP + 2));
3814+
argdesc_ = Array::RawCast(SP[2]);
3815+
3816+
ObjectPtr* call_top = SP + 1;
3817+
if (!Invoke(thread, call_base, call_top, &pc, &FP, &SP)) {
3818+
HANDLE_EXCEPTION;
3819+
}
3820+
3821+
DISPATCH();
3822+
}
3823+
}
37733824

37743825
// Replace closure receiver with captured receiver
37753826
// and call target function.
3776-
ClosurePtr closure = Closure::RawCast(argv[receiver_idx]);
37773827
argv[receiver_idx] = closure->untag()->context();
37783828
SP[1] = target;
37793829

runtime/vm/runtime_entry.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,6 @@ DEFINE_RUNTIME_ENTRY(AdjustArgumentsDesciptorForImplicitClosure, 3) {
10601060
if (target.IsGenerativeConstructor()) {
10611061
// Type arguments are not passed to a generative constructor.
10621062
type_args_len = 0;
1063-
} else {
1064-
// No need to adjust arguments descriptor.
1065-
arguments.SetReturn(descriptor);
1066-
return;
10671063
}
10681064
}
10691065

0 commit comments

Comments
 (0)