@@ -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 `::
@@ -71,8 +73,8 @@ The bytecode analysis API allows pieces of Python code to be wrapped in a
71
73
:class: `Bytecode ` object that provides easy access to details of the compiled
72
74
code.
73
75
74
- .. class :: Bytecode(x, *, first_line=None, current_offset=None, show_caches=False)
75
-
76
+ .. class :: Bytecode(x, *, first_line=None, current_offset=None,\
77
+ show_caches=False, adaptive=False)
76
78
77
79
Analyse the bytecode corresponding to a function, generator, asynchronous
78
80
generator, coroutine, method, string of source code, or a code object (as
91
93
disassembled code. Setting this means :meth: `.dis ` will display a "current
92
94
instruction" marker against the specified opcode.
93
95
96
+ If *show_caches * is ``True ``, :meth: `.dis ` will display inline cache
97
+ entries used by the interpreter to specialize the bytecode.
98
+
99
+ If *adaptive * is ``True ``, :meth: `.dis ` will display specialized bytecode
100
+ that may be different from the original bytecode.
101
+
94
102
.. classmethod :: from_traceback(tb, *, show_caches=False)
95
103
96
104
Construct a :class: `Bytecode ` instance from the given traceback, setting
@@ -118,7 +126,7 @@ code.
118
126
This can now handle coroutine and asynchronous generator objects.
119
127
120
128
.. versionchanged :: 3.11
121
- Added the `` show_caches `` parameter .
129
+ Added the * show_caches * and * adaptive * parameters .
122
130
123
131
Example:
124
132
@@ -174,7 +182,7 @@ operation is being performed, so the intermediate analysis object isn't useful:
174
182
Added *file * parameter.
175
183
176
184
177
- .. function :: dis(x=None, *, file=None, depth=None, show_caches=False)
185
+ .. function :: dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False )
178
186
179
187
Disassemble the *x * object. *x * can denote either a module, a class, a
180
188
method, a function, a generator, an asynchronous generator, a coroutine,
@@ -195,6 +203,12 @@ operation is being performed, so the intermediate analysis object isn't useful:
195
203
The maximal depth of recursion is limited by *depth * unless it is ``None ``.
196
204
``depth=0 `` means no recursion.
197
205
206
+ If *show_caches * is ``True ``, this function will display inline cache
207
+ entries used by the interpreter to specialize the bytecode.
208
+
209
+ If *adaptive * is ``True ``, this function will display specialized bytecode
210
+ that may be different from the original bytecode.
211
+
198
212
.. versionchanged :: 3.4
199
213
Added *file * parameter.
200
214
@@ -205,10 +219,10 @@ operation is being performed, so the intermediate analysis object isn't useful:
205
219
This can now handle coroutine and asynchronous generator objects.
206
220
207
221
.. versionchanged :: 3.11
208
- Added the `` show_caches `` parameter .
222
+ Added the * show_caches * and * adaptive * parameters .
209
223
210
224
211
- .. function :: distb(tb=None, *, file=None, show_caches=False)
225
+ .. function :: distb(tb=None, *, file=None, show_caches=False, adaptive=False )
212
226
213
227
Disassemble the top-of-stack function of a traceback, using the last
214
228
traceback if none was passed. The instruction causing the exception is
@@ -221,11 +235,11 @@ operation is being performed, so the intermediate analysis object isn't useful:
221
235
Added *file * parameter.
222
236
223
237
.. versionchanged :: 3.11
224
- Added the `` show_caches `` parameter .
238
+ Added the * show_caches * and * adaptive * parameters .
225
239
226
240
227
- .. function :: disassemble(code, lasti=-1, *, file=None, show_caches=False)
228
- disco(code, lasti=-1, *, file=None, show_caches=False)
241
+ .. function :: disassemble(code, lasti=-1, *, file=None, show_caches=False, adaptive=False )
242
+ disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False )
229
243
230
244
Disassemble a code object, indicating the last instruction if *lasti * was
231
245
provided. The output is divided in the following columns:
@@ -248,10 +262,10 @@ operation is being performed, so the intermediate analysis object isn't useful:
248
262
Added *file * parameter.
249
263
250
264
.. versionchanged :: 3.11
251
- Added the `` show_caches `` parameter .
265
+ Added the * show_caches * and * adaptive * parameters .
252
266
253
267
254
- .. function :: get_instructions(x, *, first_line=None, show_caches=False)
268
+ .. function :: get_instructions(x, *, first_line=None, show_caches=False, adaptive=False )
255
269
256
270
Return an iterator over the instructions in the supplied function, method,
257
271
source code string or code object.
@@ -264,10 +278,12 @@ operation is being performed, so the intermediate analysis object isn't useful:
264
278
source line information (if any) is taken directly from the disassembled code
265
279
object.
266
280
281
+ The *show_caches * and *adaptive * parameters work as they do in :func: `dis `.
282
+
267
283
.. versionadded :: 3.4
268
284
269
285
.. versionchanged :: 3.11
270
- Added the `` show_caches `` parameter .
286
+ Added the * show_caches * and * adaptive * parameters .
271
287
272
288
273
289
.. function :: findlinestarts(code)
0 commit comments