<s> from parakeet import Int64 , make_tuple_type , make_array_type <EOL> from parakeet . analysis . escape_analysis import EscapeAnalysis <EOL> from parakeet . syntax import Tuple , Var , TypedFn , Assign , Return , Array , TupleProj , zero_i64 , one_i64 <EOL> from parakeet . testing_helpers import run_local_tests <EOL> array_t = make_array_type ( Int64 , <NUM_LIT:1> ) <EOL> tuple_t = make_tuple_type ( ( Int64 , array_t ) ) <EOL> nested_tuple_t = make_tuple_type ( ( tuple_t , tuple_t ) ) <EOL> array_const = Array ( [ one_i64 ] , type = array_t ) <EOL> a_int = Var ( "<STR_LIT>" , type = Int64 ) <EOL> b_array = Var ( "<STR_LIT>" , type = array_t ) <EOL> c_tuple = Var ( "<STR_LIT>" , type = tuple_t ) <EOL> d_tuple = Var ( "<STR_LIT>" , type = tuple_t ) <EOL> e_nested_tuple = Var ( "<STR_LIT>" , type = nested_tuple_t ) <EOL> f_nested_tuple = Var ( "<STR_LIT>" , type = nested_tuple_t ) <EOL> body = [ <EOL> Assign ( a_int , one_i64 ) , <EOL> Assign ( b_array , array_const ) , <EOL> Assign ( c_tuple , Tuple ( elts = ( a_int , b_array ) , type = tuple_t ) ) , <EOL> Assign ( d_tuple , Tuple ( elts = ( a_int , array_const ) , type = tuple_t ) ) , <EOL> Assign ( e_nested_tuple , Tuple ( elts = ( c_tuple , c_tuple ) , type = nested_tuple_t ) ) , <EOL> Assign ( f_nested_tuple , Tuple ( elts = ( d_tuple , d_tuple ) , type = nested_tuple_t ) ) , <EOL> Return ( b_array ) <EOL> ] <EOL> tenv = { "<STR_LIT>" : Int64 , <EOL> "<STR_LIT>" : array_t , <EOL> "<STR_LIT>" : tuple_t , <EOL> "<STR_LIT>" : nested_tuple_t , <EOL> "<STR_LIT>" : nested_tuple_t , <EOL> "<STR_LIT>" : nested_tuple_t , <EOL> } <EOL> fn = TypedFn ( name = "<STR_LIT>" , <EOL> type_env = tenv , <EOL> input_types = ( ) , <EOL> arg_names = ( ) , <EOL> body = body , <EOL> return_type = nested_tuple_t <EOL> ) <EOL> def test_escape_analysis ( ) : <EOL> escape_analysis = EscapeAnalysis ( ) <EOL> escape_analysis . visit_fn ( fn ) <EOL> may_escape = escape_analysis . may_escape <EOL> assert "<STR_LIT>" not in may_escape , "<STR_LIT>" <EOL> assert "<STR_LIT>" in may_escape <EOL> assert "<STR_LIT>" in may_escape <EOL> assert "<STR_LIT>" not in may_escape <EOL> assert "<STR_LIT>" in may_escape <EOL> assert "<STR_LIT>" not in may_escape <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> run_local_tests ( ) </s>
