@@ -38,7 +38,9 @@ interpreter.
38
38
Some instructions are accompanied by one or more inline cache entries,
39
39
which take the form of :opcode: `CACHE ` instructions. These instructions
40
40
are hidden by default, but can be shown by passing ``show_caches=True `` to
41
- any :mod: `dis ` utility.
41
+ any :mod: `dis ` utility. Furthermore, the interpreter now adapts the
42
+ bytecode to specialize it for different runtime conditions. The
43
+ adaptive bytecode can be shown by passing ``adaptive=True ``.
42
44
43
45
44
46
Example: Given the function :func: `myfunc `::
@@ -70,8 +72,8 @@ The bytecode analysis API allows pieces of Python code to be wrapped in a
70
72
:class: `Bytecode ` object that provides easy access to details of the compiled
71
73
code.
72
74
73
- .. class :: Bytecode(x, *, first_line=None, current_offset=None, show_caches=False)
74
-
75
+ .. class :: Bytecode(x, *, first_line=None, current_offset=None,\
76
+ show_caches=False, adaptive=False)
75
77
76
78
Analyse the bytecode corresponding to a function, generator, asynchronous
77
79
generator, coroutine, method, string of source code, or a code object (as
90
92
disassembled code. Setting this means :meth: `.dis ` will display a "current
91
93
instruction" marker against the specified opcode.
92
94
95
+ If *show_caches * is ``True ``, :meth: `.dis ` will display inline cache
96
+ entries used by the interpreter to specialize the bytecode.
97
+
98
+ If *adaptive * is ``True ``, :meth: `.dis ` will display specialized bytecode
99
+ that may be different from the original bytecode.
100
+
93
101
.. classmethod :: from_traceback(tb, *, show_caches=False)
94
102
95
103
Construct a :class: `Bytecode ` instance from the given traceback, setting
@@ -117,7 +125,7 @@ code.
117
125
This can now handle coroutine and asynchronous generator objects.
118
126
119
127
.. versionchanged :: 3.11
120
- Added the `` show_caches `` parameter .
128
+ Added the * show_caches * and * adaptive * parameters .
121
129
122
130
Example:
123
131
@@ -172,7 +180,7 @@ operation is being performed, so the intermediate analysis object isn't useful:
172
180
Added *file * parameter.
173
181
174
182
175
- .. function :: dis(x=None, *, file=None, depth=None, show_caches=False)
183
+ .. function :: dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False )
176
184
177
185
Disassemble the *x * object. *x * can denote either a module, a class, a
178
186
method, a function, a generator, an asynchronous generator, a coroutine,
@@ -193,6 +201,12 @@ operation is being performed, so the intermediate analysis object isn't useful:
193
201
The maximal depth of recursion is limited by *depth * unless it is ``None ``.
194
202
``depth=0 `` means no recursion.
195
203
204
+ If *show_caches * is ``True ``, this function will display inline cache
205
+ entries used by the interpreter to specialize the bytecode.
206
+
207
+ If *adaptive * is ``True ``, this function will display specialized bytecode
208
+ that may be different from the original bytecode.
209
+
196
210
.. versionchanged :: 3.4
197
211
Added *file * parameter.
198
212
@@ -203,10 +217,10 @@ operation is being performed, so the intermediate analysis object isn't useful:
203
217
This can now handle coroutine and asynchronous generator objects.
204
218
205
219
.. versionchanged :: 3.11
206
- Added the `` show_caches `` parameter .
220
+ Added the * show_caches * and * adaptive * parameters .
207
221
208
222
209
- .. function :: distb(tb=None, *, file=None, show_caches=False)
223
+ .. function :: distb(tb=None, *, file=None, show_caches=False, adaptive=False )
210
224
211
225
Disassemble the top-of-stack function of a traceback, using the last
212
226
traceback if none was passed. The instruction causing the exception is
@@ -219,11 +233,11 @@ operation is being performed, so the intermediate analysis object isn't useful:
219
233
Added *file * parameter.
220
234
221
235
.. versionchanged :: 3.11
222
- Added the `` show_caches `` parameter .
236
+ Added the * show_caches * and * adaptive * parameters .
223
237
224
238
225
- .. function :: disassemble(code, lasti=-1, *, file=None, show_caches=False)
226
- disco(code, lasti=-1, *, file=None, show_caches=False)
239
+ .. function :: disassemble(code, lasti=-1, *, file=None, show_caches=False, adaptive=False )
240
+ disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False )
227
241
228
242
Disassemble a code object, indicating the last instruction if *lasti * was
229
243
provided. The output is divided in the following columns:
@@ -246,10 +260,10 @@ operation is being performed, so the intermediate analysis object isn't useful:
246
260
Added *file * parameter.
247
261
248
262
.. versionchanged :: 3.11
249
- Added the `` show_caches `` parameter .
263
+ Added the * show_caches * and * adaptive * parameters .
250
264
251
265
252
- .. function :: get_instructions(x, *, first_line=None, show_caches=False)
266
+ .. function :: get_instructions(x, *, first_line=None, show_caches=False, adaptive=False )
253
267
254
268
Return an iterator over the instructions in the supplied function, method,
255
269
source code string or code object.
@@ -262,10 +276,12 @@ operation is being performed, so the intermediate analysis object isn't useful:
262
276
source line information (if any) is taken directly from the disassembled code
263
277
object.
264
278
279
+ The *show_caches * and *adaptive * parameters work as they do in :func: `dis `.
280
+
265
281
.. versionadded :: 3.4
266
282
267
283
.. versionchanged :: 3.11
268
- Added the `` show_caches `` parameter .
284
+ Added the * show_caches * and * adaptive * parameters .
269
285
270
286
271
287
.. function :: findlinestarts(code)
0 commit comments