Skip to content

Commit 380fa39

Browse files
authored
Bytecode instrumented placeholder (#6741)
* Add all other bytecodes * Mark passing/failing tests
1 parent 4cb3b9d commit 380fa39

File tree

3 files changed

+296
-11
lines changed

3 files changed

+296
-11
lines changed

Lib/_opcode_metadata.py

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,102 @@
136136
'JUMP_IF_FALSE_OR_POP': 129,
137137
'JUMP_IF_TRUE_OR_POP': 130,
138138
'JUMP_IF_NOT_EXC_MATCH': 131,
139-
'SET_EXC_INFO': 134,
140-
'SUBSCRIPT': 135,
139+
'SET_EXC_INFO': 132,
140+
'SUBSCRIPT': 133,
141141
'RESUME': 149,
142-
'LOAD_CLOSURE': 253,
142+
'BINARY_OP_ADD_FLOAT': 150,
143+
'BINARY_OP_ADD_INT': 151,
144+
'BINARY_OP_ADD_UNICODE': 152,
145+
'BINARY_OP_MULTIPLY_FLOAT': 153,
146+
'BINARY_OP_MULTIPLY_INT': 154,
147+
'BINARY_OP_SUBTRACT_FLOAT': 155,
148+
'BINARY_OP_SUBTRACT_INT': 156,
149+
'BINARY_SUBSCR_DICT': 157,
150+
'BINARY_SUBSCR_GETITEM': 158,
151+
'BINARY_SUBSCR_LIST_INT': 159,
152+
'BINARY_SUBSCR_STR_INT': 160,
153+
'BINARY_SUBSCR_TUPLE_INT': 161,
154+
'CALL_ALLOC_AND_ENTER_INIT': 162,
155+
'CALL_BOUND_METHOD_EXACT_ARGS': 163,
156+
'CALL_BOUND_METHOD_GENERAL': 164,
157+
'CALL_BUILTIN_CLASS': 165,
158+
'CALL_BUILTIN_FAST': 166,
159+
'CALL_BUILTIN_FAST_WITH_KEYWORDS': 167,
160+
'CALL_BUILTIN_O': 168,
161+
'CALL_ISINSTANCE': 169,
162+
'CALL_LEN': 170,
163+
'CALL_LIST_APPEND': 171,
164+
'CALL_METHOD_DESCRIPTOR_FAST': 172,
165+
'CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS': 173,
166+
'CALL_METHOD_DESCRIPTOR_NOARGS': 174,
167+
'CALL_METHOD_DESCRIPTOR_O': 175,
168+
'CALL_NON_PY_GENERAL': 176,
169+
'CALL_PY_EXACT_ARGS': 177,
170+
'CALL_PY_GENERAL': 178,
171+
'CALL_STR_1': 179,
172+
'CALL_TUPLE_1': 180,
173+
'CALL_TYPE_1': 181,
174+
'COMPARE_OP_FLOAT': 182,
175+
'COMPARE_OP_INT': 183,
176+
'COMPARE_OP_STR': 184,
177+
'CONTAINS_OP_DICT': 185,
178+
'CONTAINS_OP_SET': 186,
179+
'FOR_ITER_GEN': 187,
180+
'FOR_ITER_LIST': 188,
181+
'FOR_ITER_RANGE': 189,
182+
'FOR_ITER_TUPLE': 190,
183+
'LOAD_ATTR_CLASS': 191,
184+
'LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN': 192,
185+
'LOAD_ATTR_INSTANCE_VALUE': 193,
186+
'LOAD_ATTR_METHOD_LAZY_DICT': 194,
187+
'LOAD_ATTR_METHOD_NO_DICT': 195,
188+
'LOAD_ATTR_METHOD_WITH_VALUES': 196,
189+
'LOAD_ATTR_MODULE': 197,
190+
'LOAD_ATTR_NONDESCRIPTOR_NO_DICT': 198,
191+
'LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES': 199,
192+
'LOAD_ATTR_PROPERTY': 200,
193+
'LOAD_ATTR_SLOT': 201,
194+
'LOAD_ATTR_WITH_HINT': 202,
195+
'LOAD_GLOBAL_BUILTIN': 203,
196+
'LOAD_GLOBAL_MODULE': 204,
197+
'LOAD_SUPER_ATTR_ATTR': 205,
198+
'LOAD_SUPER_ATTR_METHOD': 206,
199+
'RESUME_CHECK': 207,
200+
'SEND_GEN': 208,
201+
'STORE_ATTR_INSTANCE_VALUE': 209,
202+
'STORE_ATTR_SLOT': 210,
203+
'STORE_ATTR_WITH_HINT': 211,
204+
'STORE_SUBSCR_DICT': 212,
205+
'STORE_SUBSCR_LIST_INT': 213,
206+
'TO_BOOL_ALWAYS_TRUE': 214,
207+
'TO_BOOL_BOOL': 215,
208+
'TO_BOOL_INT': 216,
209+
'TO_BOOL_LIST': 217,
210+
'TO_BOOL_NONE': 218,
211+
'TO_BOOL_STR': 219,
212+
'UNPACK_SEQUENCE_LIST': 220,
213+
'UNPACK_SEQUENCE_TUPLE': 221,
214+
'UNPACK_SEQUENCE_TWO_TUPLE': 222,
215+
'INSTRUMENTED_RESUME': 236,
216+
'INSTRUMENTED_END_FOR': 237,
217+
'INSTRUMENTED_END_SEND': 238,
218+
'INSTRUMENTED_RETURN_VALUE': 239,
219+
'INSTRUMENTED_RETURN_CONST': 240,
220+
'INSTRUMENTED_YIELD_VALUE': 241,
221+
'INSTRUMENTED_LOAD_SUPER_ATTR': 242,
222+
'INSTRUMENTED_FOR_ITER': 243,
223+
'INSTRUMENTED_CALL': 244,
224+
'INSTRUMENTED_CALL_KW': 245,
225+
'INSTRUMENTED_CALL_FUNCTION_EX': 246,
226+
'INSTRUMENTED_INSTRUCTION': 247,
227+
'INSTRUMENTED_JUMP_FORWARD': 248,
228+
'INSTRUMENTED_JUMP_BACKWARD': 249,
229+
'INSTRUMENTED_POP_JUMP_IF_TRUE': 250,
230+
'INSTRUMENTED_POP_JUMP_IF_FALSE': 251,
231+
'INSTRUMENTED_POP_JUMP_IF_NONE': 252,
232+
'INSTRUMENTED_POP_JUMP_IF_NOT_NONE': 253,
233+
'INSTRUMENTED_LINE': 254,
234+
'LOAD_CLOSURE': 255,
143235
'JUMP': 256,
144236
'JUMP_NO_INTERRUPT': 257,
145237
'RESERVED_258': 258,

Lib/test/test__opcode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def check_bool_function_result(self, func, ops, expected):
1616
self.assertIsInstance(func(op), bool)
1717
self.assertEqual(func(op), expected)
1818

19+
@unittest.expectedFailure # TODO: RUSTPYTHON; Move LoadClosure to psudoes
1920
def test_invalid_opcodes(self):
2021
invalid = [-100, -1, 255, 512, 513, 1000]
2122
self.check_bool_function_result(_opcode.is_valid, invalid, False)
@@ -27,7 +28,6 @@ def test_invalid_opcodes(self):
2728
self.check_bool_function_result(_opcode.has_local, invalid, False)
2829
self.check_bool_function_result(_opcode.has_exc, invalid, False)
2930

30-
@unittest.expectedFailure # TODO: RUSTPYTHON - no instrumented opcodes
3131
def test_is_valid(self):
3232
names = [
3333
'CACHE',

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 200 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,7 @@ pub enum Instruction {
245245
YieldValue {
246246
arg: Arg<u32>,
247247
} = 118,
248-
Resume {
249-
arg: Arg<u32>,
250-
} = 149,
251-
// ==================== RustPython-only instructions (119-135) ====================
248+
// ==================== RustPython-only instructions (119-133) ====================
252249
// Ideally, we want to be fully aligned with CPython opcodes, but we still have some leftovers.
253250
// So we assign random IDs to these opcodes.
254251
Break {
@@ -277,10 +274,106 @@ pub enum Instruction {
277274
target: Arg<Label>,
278275
} = 130,
279276
JumpIfNotExcMatch(Arg<Label>) = 131,
280-
SetExcInfo = 134,
281-
Subscript = 135,
277+
SetExcInfo = 132,
278+
Subscript = 133,
279+
// End of custom instructions
280+
Resume {
281+
arg: Arg<u32>,
282+
} = 149,
283+
BinaryOpAddFloat = 150, // Placeholder
284+
BinaryOpAddInt = 151, // Placeholder
285+
BinaryOpAddUnicode = 152, // Placeholder
286+
BinaryOpMultiplyFloat = 153, // Placeholder
287+
BinaryOpMultiplyInt = 154, // Placeholder
288+
BinaryOpSubtractFloat = 155, // Placeholder
289+
BinaryOpSubtractInt = 156, // Placeholder
290+
BinarySubscrDict = 157, // Placeholder
291+
BinarySubscrGetitem = 158, // Placeholder
292+
BinarySubscrListInt = 159, // Placeholder
293+
BinarySubscrStrInt = 160, // Placeholder
294+
BinarySubscrTupleInt = 161, // Placeholder
295+
CallAllocAndEnterInit = 162, // Placeholder
296+
CallBoundMethodExactArgs = 163, // Placeholder
297+
CallBoundMethodGeneral = 164, // Placeholder
298+
CallBuiltinClass = 165, // Placeholder
299+
CallBuiltinFast = 166, // Placeholder
300+
CallBuiltinFastWithKeywords = 167, // Placeholder
301+
CallBuiltinO = 168, // Placeholder
302+
CallIsinstance = 169, // Placeholder
303+
CallLen = 170, // Placeholder
304+
CallListAppend = 171, // Placeholder
305+
CallMethodDescriptorFast = 172, // Placeholder
306+
CallMethodDescriptorFastWithKeywords = 173, // Placeholder
307+
CallMethodDescriptorNoargs = 174, // Placeholder
308+
CallMethodDescriptorO = 175, // Placeholder
309+
CallNonPyGeneral = 176, // Placeholder
310+
CallPyExactArgs = 177, // Placeholder
311+
CallPyGeneral = 178, // Placeholder
312+
CallStr1 = 179, // Placeholder
313+
CallTuple1 = 180, // Placeholder
314+
CallType1 = 181, // Placeholder
315+
CompareOpFloat = 182, // Placeholder
316+
CompareOpInt = 183, // Placeholder
317+
CompareOpStr = 184, // Placeholder
318+
ContainsOpDict = 185, // Placeholder
319+
ContainsOpSet = 186, // Placeholder
320+
ForIterGen = 187, // Placeholder
321+
ForIterList = 188, // Placeholder
322+
ForIterRange = 189, // Placeholder
323+
ForIterTuple = 190, // Placeholder
324+
LoadAttrClass = 191, // Placeholder
325+
LoadAttrGetattributeOverridden = 192, // Placeholder
326+
LoadAttrInstanceValue = 193, // Placeholder
327+
LoadAttrMethodLazyDict = 194, // Placeholder
328+
LoadAttrMethodNoDict = 195, // Placeholder
329+
LoadAttrMethodWithValues = 196, // Placeholder
330+
LoadAttrModule = 197, // Placeholder
331+
LoadAttrNondescriptorNoDict = 198, // Placeholder
332+
LoadAttrNondescriptorWithValues = 199, // Placeholder
333+
LoadAttrProperty = 200, // Placeholder
334+
LoadAttrSlot = 201, // Placeholder
335+
LoadAttrWithHint = 202, // Placeholder
336+
LoadGlobalBuiltin = 203, // Placeholder
337+
LoadGlobalModule = 204, // Placeholder
338+
LoadSuperAttrAttr = 205, // Placeholder
339+
LoadSuperAttrMethod = 206, // Placeholder
340+
ResumeCheck = 207, // Placeholder
341+
SendGen = 208, // Placeholder
342+
StoreAttrInstanceValue = 209, // Placeholder
343+
StoreAttrSlot = 210, // Placeholder
344+
StoreAttrWithHint = 211, // Placeholder
345+
StoreSubscrDict = 212, // Placeholder
346+
StoreSubscrListInt = 213, // Placeholder
347+
ToBoolAlwaysTrue = 214, // Placeholder
348+
ToBoolBool = 215, // Placeholder
349+
ToBoolInt = 216, // Placeholder
350+
ToBoolList = 217, // Placeholder
351+
ToBoolNone = 218, // Placeholder
352+
ToBoolStr = 219, // Placeholder
353+
UnpackSequenceList = 220, // Placeholder
354+
UnpackSequenceTuple = 221, // Placeholder
355+
UnpackSequenceTwoTuple = 222, // Placeholder
356+
InstrumentedResume = 236, // Placeholder
357+
InstrumentedEndFor = 237, // Placeholder
358+
InstrumentedEndSend = 238, // Placeholder
359+
InstrumentedReturnValue = 239, // Placeholder
360+
InstrumentedReturnConst = 240, // Placeholder
361+
InstrumentedYieldValue = 241, // Placeholder
362+
InstrumentedLoadSuperAttr = 242, // Placeholder
363+
InstrumentedForIter = 243, // Placeholder
364+
InstrumentedCall = 244, // Placeholder
365+
InstrumentedCallKw = 245, // Placeholder
366+
InstrumentedCallFunctionEx = 246, // Placeholder
367+
InstrumentedInstruction = 247, // Placeholder
368+
InstrumentedJumpForward = 248, // Placeholder
369+
InstrumentedJumpBackward = 249, // Placeholder
370+
InstrumentedPopJumpIfTrue = 250, // Placeholder
371+
InstrumentedPopJumpIfFalse = 251, // Placeholder
372+
InstrumentedPopJumpIfNone = 252, // Placeholder
373+
InstrumentedPopJumpIfNotNone = 253, // Placeholder
374+
InstrumentedLine = 254, // Placeholder
282375
// Pseudos (needs to be moved to `PseudoInstruction` enum.
283-
LoadClosure(Arg<NameIdx>) = 253, // TODO: Move to pseudos
376+
LoadClosure(Arg<NameIdx>) = 255, // TODO: Move to pseudos
284377
}
285378

286379
const _: () = assert!(mem::size_of::<Instruction>() == 1);
@@ -305,6 +398,12 @@ impl TryFrom<u8> for Instruction {
305398
// Resume has a non-contiguous opcode (149)
306399
let resume_id = u8::from(Self::Resume { arg: Arg::marker() });
307400

401+
let specialized_start = u8::from(Self::BinaryOpAddFloat);
402+
let specialized_end = u8::from(Self::UnpackSequenceTwoTuple);
403+
404+
let instrumented_start = u8::from(Self::InstrumentedResume);
405+
let instrumented_end = u8::from(Self::InstrumentedLine);
406+
308407
// TODO: Remove this; This instruction needs to be pseudo
309408
let load_closure = u8::from(Self::LoadClosure(Arg::marker()));
310409

@@ -345,6 +444,8 @@ impl TryFrom<u8> for Instruction {
345444
|| value == resume_id
346445
|| value == load_closure
347446
|| custom_ops.contains(&value)
447+
|| (specialized_start..=specialized_end).contains(&value)
448+
|| (instrumented_start..=instrumented_end).contains(&value)
348449
{
349450
Ok(unsafe { mem::transmute::<u8, Self>(value) })
350451
} else {
@@ -589,6 +690,98 @@ impl InstructionMetadata for Instruction {
589690
Self::PopJumpIfNone { .. } => 0,
590691
Self::PopJumpIfNotNone { .. } => 0,
591692
Self::LoadClosure(_) => 1,
693+
Self::BinaryOpAddFloat => 0,
694+
Self::BinaryOpAddInt => 0,
695+
Self::BinaryOpAddUnicode => 0,
696+
Self::BinaryOpMultiplyFloat => 0,
697+
Self::BinaryOpMultiplyInt => 0,
698+
Self::BinaryOpSubtractFloat => 0,
699+
Self::BinaryOpSubtractInt => 0,
700+
Self::BinarySubscrDict => 0,
701+
Self::BinarySubscrGetitem => 0,
702+
Self::BinarySubscrListInt => 0,
703+
Self::BinarySubscrStrInt => 0,
704+
Self::BinarySubscrTupleInt => 0,
705+
Self::CallAllocAndEnterInit => 0,
706+
Self::CallBoundMethodExactArgs => 0,
707+
Self::CallBoundMethodGeneral => 0,
708+
Self::CallBuiltinClass => 0,
709+
Self::CallBuiltinFast => 0,
710+
Self::CallBuiltinFastWithKeywords => 0,
711+
Self::CallBuiltinO => 0,
712+
Self::CallIsinstance => 0,
713+
Self::CallLen => 0,
714+
Self::CallListAppend => 0,
715+
Self::CallMethodDescriptorFast => 0,
716+
Self::CallMethodDescriptorFastWithKeywords => 0,
717+
Self::CallMethodDescriptorNoargs => 0,
718+
Self::CallMethodDescriptorO => 0,
719+
Self::CallNonPyGeneral => 0,
720+
Self::CallPyExactArgs => 0,
721+
Self::CallPyGeneral => 0,
722+
Self::CallStr1 => 0,
723+
Self::CallTuple1 => 0,
724+
Self::CallType1 => 0,
725+
Self::CompareOpFloat => 0,
726+
Self::CompareOpInt => 0,
727+
Self::CompareOpStr => 0,
728+
Self::ContainsOpDict => 0,
729+
Self::ContainsOpSet => 0,
730+
Self::ForIterGen => 0,
731+
Self::ForIterList => 0,
732+
Self::ForIterRange => 0,
733+
Self::ForIterTuple => 0,
734+
Self::LoadAttrClass => 0,
735+
Self::LoadAttrGetattributeOverridden => 0,
736+
Self::LoadAttrInstanceValue => 0,
737+
Self::LoadAttrMethodLazyDict => 0,
738+
Self::LoadAttrMethodNoDict => 0,
739+
Self::LoadAttrMethodWithValues => 0,
740+
Self::LoadAttrModule => 0,
741+
Self::LoadAttrNondescriptorNoDict => 0,
742+
Self::LoadAttrNondescriptorWithValues => 0,
743+
Self::LoadAttrProperty => 0,
744+
Self::LoadAttrSlot => 0,
745+
Self::LoadAttrWithHint => 0,
746+
Self::LoadGlobalBuiltin => 0,
747+
Self::LoadGlobalModule => 0,
748+
Self::LoadSuperAttrAttr => 0,
749+
Self::LoadSuperAttrMethod => 0,
750+
Self::ResumeCheck => 0,
751+
Self::SendGen => 0,
752+
Self::StoreAttrInstanceValue => 0,
753+
Self::StoreAttrSlot => 0,
754+
Self::StoreAttrWithHint => 0,
755+
Self::StoreSubscrDict => 0,
756+
Self::StoreSubscrListInt => 0,
757+
Self::ToBoolAlwaysTrue => 0,
758+
Self::ToBoolBool => 0,
759+
Self::ToBoolInt => 0,
760+
Self::ToBoolList => 0,
761+
Self::ToBoolNone => 0,
762+
Self::ToBoolStr => 0,
763+
Self::UnpackSequenceList => 0,
764+
Self::UnpackSequenceTuple => 0,
765+
Self::UnpackSequenceTwoTuple => 0,
766+
Self::InstrumentedResume => 0,
767+
Self::InstrumentedEndFor => 0,
768+
Self::InstrumentedEndSend => 0,
769+
Self::InstrumentedReturnValue => 0,
770+
Self::InstrumentedReturnConst => 0,
771+
Self::InstrumentedYieldValue => 0,
772+
Self::InstrumentedLoadSuperAttr => 0,
773+
Self::InstrumentedForIter => 0,
774+
Self::InstrumentedCall => 0,
775+
Self::InstrumentedCallKw => 0,
776+
Self::InstrumentedCallFunctionEx => 0,
777+
Self::InstrumentedInstruction => 0,
778+
Self::InstrumentedJumpForward => 0,
779+
Self::InstrumentedJumpBackward => 0,
780+
Self::InstrumentedPopJumpIfTrue => 0,
781+
Self::InstrumentedPopJumpIfFalse => 0,
782+
Self::InstrumentedPopJumpIfNone => 0,
783+
Self::InstrumentedPopJumpIfNotNone => 0,
784+
Self::InstrumentedLine => 0,
592785
}
593786
}
594787

0 commit comments

Comments
 (0)