File tree 3 files changed +31
-1
lines changed 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,7 @@ Known values:
276
276
Python 3.14a7 3621 (Optimize LOAD_FAST opcodes into LOAD_FAST_BORROW)
277
277
Python 3.14a7 3622 (Store annotations in different class dict keys)
278
278
Python 3.14a7 3623 (Add BUILD_INTERPOLATION & BUILD_TEMPLATE opcodes)
279
+ Python 3.14b1 3624 (Don't optimize LOAD_FAST when local is killed by DELETE_FAST)
279
280
280
281
Python 3.15 will start with 3650
281
282
@@ -288,7 +289,7 @@ PC/launcher.c must also be updated.
288
289
289
290
*/
290
291
291
- #define PYC_MAGIC_NUMBER 3623
292
+ #define PYC_MAGIC_NUMBER 3624
292
293
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
293
294
(little-endian) and then appending b'\r\n'. */
294
295
#define PYC_MAGIC_NUMBER_TOKEN \
Original file line number Diff line number Diff line change 1
1
import dis
2
+ import gc
2
3
from itertools import combinations , product
3
4
import opcode
4
5
import sys
@@ -2472,6 +2473,13 @@ def test_unoptimized_if_support_killed(self):
2472
2473
]
2473
2474
self .check (insts , insts )
2474
2475
2476
+ insts = [
2477
+ ("LOAD_FAST" , 0 , 1 ),
2478
+ ("DELETE_FAST" , 0 , 2 ),
2479
+ ("POP_TOP" , None , 3 ),
2480
+ ]
2481
+ self .check (insts , insts )
2482
+
2475
2483
def test_unoptimized_if_aliased (self ):
2476
2484
insts = [
2477
2485
("LOAD_FAST" , 0 , 1 ),
@@ -2606,6 +2614,22 @@ def test_send(self):
2606
2614
]
2607
2615
self .cfg_optimization_test (insts , expected , consts = [None ])
2608
2616
2617
+ def test_del_in_finally (self ):
2618
+ # This loads `obj` onto the stack, executes `del obj`, then returns the
2619
+ # `obj` from the stack. See gh-133371 for more details.
2620
+ def create_obj ():
2621
+ obj = [42 ]
2622
+ try :
2623
+ return obj
2624
+ finally :
2625
+ del obj
2626
+
2627
+ obj = create_obj ()
2628
+ # The crash in the linked issue happens while running GC during
2629
+ # interpreter finalization, so run it here manually.
2630
+ gc .collect ()
2631
+ self .assertEqual (obj , [42 ])
2632
+
2609
2633
2610
2634
2611
2635
if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -2795,6 +2795,11 @@ optimize_load_fast(cfg_builder *g)
2795
2795
assert (opcode != EXTENDED_ARG );
2796
2796
switch (opcode ) {
2797
2797
// Opcodes that load and store locals
2798
+ case DELETE_FAST : {
2799
+ kill_local (instr_flags , & refs , oparg );
2800
+ break ;
2801
+ }
2802
+
2798
2803
case LOAD_FAST : {
2799
2804
PUSH_REF (i , oparg );
2800
2805
break ;
You can’t perform that action at this time.
0 commit comments