+
     þÎjê  ã                   ó°   € R t ^ RIt^ RIt^ RIt^ RIHtHt ^ RIHt ^ RI	H
t
Ht R tR tR tR t ! R	 R
]4      t]R8X  d   ]P$                  ! 4        R# R# )aB  
Regression test for issue #5611 / PR #10482.

CFGraph._find_topo_order must be stack-based (not recursive) so that
functions with large control-flow graphs do not exhaust the Python call
stack.

The test is run in a subprocess so that sys.setrecursionlimit manipulation
is completely isolated from the rest of the suite.
N)ÚCFGraphÚControlFlowAnalysis)ÚTestCase)ÚFunctionIdentityÚByteCodec                óÊ   € R.p\        V 4       F0  pVP                  RV R24       VP                  RV RV R24       K2  	  VP                  R4       RP                  V4      # )	z.Source for function with unusually large CFG. zdef _large_cfg_func(x):z    dep_z = 1 if True else 0z    val_z = x if dep_z else 0z    return xÚ
)ÚrangeÚappendÚjoin)ÚcountÚlinesÚis   &  ÚR/opt/data/home/.local/lib/python3.14/site-packages/numba/tests/test_controlflow.pyÚ_generate_large_cfg_sourcer      sf   € à&Ð'€EÜ�5Ž\ˆØ�‰�x ˜sÐ"5Ð6Ô7Ø�‰�x ˜s ,¨q¨c°Ð9Ö:ñ ð 
‡L�L�Ô Ø�9‰9�UÓÐó    c                ó’   € \         P                  ! V 4      p\        V4      p\        V4      pVP	                  4        VP
                  # )z;Create a CFGraph from a Python function for direct testing.)r   Úfrom_functionr   r   ÚrunÚgraph)ÚfuncÚfunc_idÚbcÚcfas   &   r   Ú_create_cfg_from_functionr   #   s9   € ä×,Ò,¨TÓ2€GÜ	�'Ó	€BÜ
˜bÓ
!€CØ‡G�G„IØ�9‰9Ðr   c                óB   € ^pT'       d   T M^ p^pT'       d   T pT # ^ pT # )z6Test function for probing stack depth during compile. © )ÚxÚdep_0Úval_0Údep_1Úval_1s   &    r   Ú_complex_funcr"   ,   s-   € à€Eß‰A˜A€EØ€EßˆA€EØ€Hð €EØ€Hr   c                 óØ   aa€ ^ .o\        \        4      p \        P                  oVV3R lpV\        n         V P                  4        S\        n        S^ ,          #   S\        n        i ; i)z^
Return the Python frame depth at CFGraph._find_topo_order during a trivial
njit compilation.
c                 óž   <€ \         P                  ! 4       p^ pVe   V^,          pVP                  pK  VS^ ,          8”  d   VS^ &   S! V 4      # )é    ©ÚsysÚ	_getframeÚf_back)ÚselfÚfÚdÚdepth_sampleÚoriginals   &  €€r   Ú_probing_topo_orderÚ;_measure_trivial_compile_depth.<locals>._probing_topo_order>   sI   ø€ Ü�MŠM‹OˆØˆØŠmØ��FˆAØ—‘ŠAØˆ|˜A�ÔØˆL˜‰OÙ˜‹~Ðr   )r   r"   r   Ú_find_topo_orderÚprocess)Úcfgr/   r-   r.   s     @@r   Ú_measure_trivial_compile_depthr4   5   s]   ù€ ð
 �3€LÜ
#¤MÓ
2€CÜ×'Ñ'€Höð  3„GÔð#Ø×ÑÔà"ŒŒà˜�?Ðøð #Œ�ús   ¸A ÁA)c                   óD   a € ] tR t^Vt o ]P
                  R 4       tRtV tR# )ÚTestCFGTopoOrderNonRecursivec                ó„  € \        \        4       ^,           4      pR p\        V! 4       4      p\        ^d4      p/ p\	        \        VRR4      V4       \        VR,          4      p\        P                  ! 4       p\        P                  ! W,           4       Rp VP                  4        \        P                  ! V4       Vf   R# RRP                  \        P                  ! VP                  4      4      ,           p
V P!                  V
4       R#   \         d   p	T	p Rp	?	LwRp	?	ii ; i  \        P                  ! T4       i ; i)aŠ  
Regression tests for PR #10482: _find_topo_order must not use recursive
Python calls, so that large CFGs cannot exhaust the stack.

Steps
-----
1.  Measure the frame depth at CFGraph.topo_order() during a trivial
    njit compilation by patching the method to walk the frame
    chain once; call this bsize. Add 2 for headroom.
1a. Determine current frame_depth
2.  Lower sys.setrecursionlimit to bsize + frame_depth
3.  Attempt to compile a function with 100 ternary-expression
    pairs.
4.  Catch any RecursionError.
5.  Restore sys.setrecursionlimit unconditionally.
6.  Fail the test and print the traceback if a RecursionError was
    raised.
c               3   óf   "  € \         P                  ! ^ 4      p V e   V P                  p ^x € K  R# 5i)r%   Nr&   )r+   s    r   ÚframesÚVTestCFGTopoOrderNonRecursive.test_topo_order_no_recursion_in_large_cfg.<locals>.framesp   s+   é € Ü—’˜aÓ ˆAØ’-Ø—H‘H�Ø”ñ  ùs   ‚/1z<generated_large_cfg>ÚexecÚ_large_cfg_funcNzeUnexpected RecursionError.Potential regression related to finding toplogical order.

Full traceback:
Ú )Úintr4   Úsumr   r;   Úcompiler   r'   ÚgetrecursionlimitÚsetrecursionlimitr1   ÚRecursionErrorr   Ú	tracebackÚ	format_tbÚ__traceback__Úfail)r*   Úbsizer9   Úframe_depthÚfunÚenvr3   Úoriginal_limitÚ
caught_excÚexcÚmsgs   &          r   Ú)test_topo_order_no_recursion_in_large_cfgÚFTestCFGTopoOrderNonRecursive.test_topo_order_no_recursion_in_large_cfgX   s   € ô, Ô2Ó4°qÕ8Ó9ˆò	ô ™&›(“mˆä(¨Ó-ˆØˆÜÜØØ'Øóð
 ô	
ô (¨Ð,=Õ(>Ó?ˆô ×.Ò.Ó0ˆÜ×Ò˜eÕ1Ô2ð ˆ
ð	2Ø× Ñ Ô"ô
 ×!Ò! .Ô1ð Òáð$ð —'‘'œ)×-Ò-¨j×.FÑ.FÓGÓHõIð ð
 �I‰I�cŽNøô# ô 	Ø�Jûð	ûô ×!Ò! .Õ1ús*   ÂD ÄD$ÄDÄD' ÄD$Ä$D' Ä'D?r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   Úrun_test_in_subprocessrP   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r6   r6   V   s   ø‡ € à×$Ñ$ñDó %öDr   r6   Ú__main__)Ú__doc__r'   rD   ÚunittestÚnumba.core.controlflowr   r   Únumba.tests.supportr   Únumba.core.bytecoder   r   r   r   r"   r4   r6   rR   Úmainr   r   r   Ú<module>ra      sZ   ðñ	ó Û Û ç ?Ý (ß :òòòòôBG 8ô GðT ˆzÔØ‡M‚M†Oñ r   