File tree Expand file tree Collapse file tree 1 file changed +31
-8
lines changed
Expand file tree Collapse file tree 1 file changed +31
-8
lines changed Original file line number Diff line number Diff line change 1+ import _opcode
12import contextlib
3+ import gc
24import itertools
5+ import os
36import sys
47import textwrap
5- import unittest
6- import gc
7- import os
88import types
9+ import unittest
910
10- import _opcode
11-
12- from test .support import (script_helper , requires_specialization ,
13- import_helper , Py_GIL_DISABLED , requires_jit_enabled ,
14- reset_code )
11+ from test .support import (
12+ Py_GIL_DISABLED ,
13+ import_helper ,
14+ requires_jit_enabled ,
15+ requires_specialization ,
16+ reset_code ,
17+ script_helper ,
18+ )
1519
1620_testinternalcapi = import_helper .import_module ("_testinternalcapi" )
1721
@@ -3574,6 +3578,25 @@ def return_false():
35743578 # v + 1 should be constant folded
35753579 self .assertNotIn ("_BINARY_OP" , uops )
35763580
3581+ def test_is_number_narrows_to_constant (self ):
3582+ def f (n ):
3583+ def return_1 ():
3584+ return 1
3585+
3586+ hits = 0
3587+ v = return_1 ()
3588+ for i in range (n ):
3589+ if v is 1 :
3590+ hits += v + 1
3591+ return hits
3592+
3593+ res , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
3594+ self .assertEqual (res , TIER2_THRESHOLD * 2 )
3595+ self .assertIsNotNone (ex )
3596+
3597+ # v + 1 should be constant folded
3598+ self .assertLessEqual (count_ops (ex , "_BINARY_OP_ADD_INT" ), 1 )
3599+
35773600 def test_for_iter_gen_frame (self ):
35783601 def f (n ):
35793602 for i in range (n ):
You can’t perform that action at this time.
0 commit comments