@@ -19,7 +19,7 @@ use crate::{
1919 compiler:: { CompileError , ParseError } ,
2020 convert:: ToPyObject ,
2121} ;
22- use node:: { AstFromObjectContext , AstToObjectContext , Node } ;
22+ use node:: Node ;
2323use ruff_python_ast as ast;
2424use ruff_text_size:: { Ranged , TextRange , TextSize } ;
2525use rustpython_compiler_core:: {
@@ -98,7 +98,7 @@ fn get_node_field_required(
9898}
9999
100100fn get_required_identifier_field < T : Node > (
101- ctx : & AstFromObjectContext < ' _ > ,
101+ ctx : & VirtualMachine ,
102102 source_file : & SourceFile ,
103103 obj : & PyObject ,
104104 field : & ' static str ,
@@ -112,7 +112,7 @@ fn get_required_identifier_field<T: Node>(
112112}
113113
114114fn get_required_node_field < T : Node > (
115- ctx : & AstFromObjectContext < ' _ > ,
115+ ctx : & VirtualMachine ,
116116 source_file : & SourceFile ,
117117 obj : & PyObject ,
118118 field : & ' static str ,
@@ -139,7 +139,7 @@ fn get_node_field_opt(
139139}
140140
141141fn get_node_list_field < T : Node > (
142- ctx : & AstFromObjectContext < ' _ > ,
142+ ctx : & VirtualMachine ,
143143 source_file : & SourceFile ,
144144 obj : & PyObject ,
145145 field : & ' static str ,
@@ -169,7 +169,7 @@ fn get_node_list_field_object(
169169}
170170
171171fn convert_node_list_field < T : Node > (
172- ctx : & AstFromObjectContext < ' _ > ,
172+ ctx : & VirtualMachine ,
173173 source_file : & SourceFile ,
174174 list : & PyList ,
175175 field : & ' static str ,
@@ -201,7 +201,7 @@ fn convert_node_list_field<T: Node>(
201201}
202202
203203fn get_node_boxed_slice_field < T : Node > (
204- ctx : & AstFromObjectContext < ' _ > ,
204+ ctx : & VirtualMachine ,
205205 source_file : & SourceFile ,
206206 obj : & PyObject ,
207207 field : & ' static str ,
@@ -1906,8 +1906,7 @@ pub(crate) fn parse(
19061906 } ) ,
19071907 ast:: Mod :: Expression ( e) => Mod :: Expression ( e) ,
19081908 } ;
1909- let ctx = AstToObjectContext :: new ( vm, & source_file) ;
1910- let obj = top. ast_to_object ( & ctx) ;
1909+ let obj = top. ast_to_object ( vm, & source_file) ;
19111910 if let Some ( lines) = & type_comment_source
19121911 && obj. class ( ) . is ( pyast:: NodeModModule :: static_type ( ) )
19131912 {
@@ -2073,8 +2072,7 @@ pub(crate) fn parse_func_type(
20732072 runtime_argtypes : None ,
20742073 } ;
20752074 let source_file = SourceFileBuilder :: new ( "" . to_owned ( ) , source. to_owned ( ) ) . finish ( ) ;
2076- let ctx = AstToObjectContext :: new ( vm, & source_file) ;
2077- Ok ( func_type. ast_to_object ( & ctx) )
2075+ Ok ( func_type. ast_to_object ( vm, & source_file) )
20782076}
20792077
20802078fn type_ignores_from_source (
@@ -2346,9 +2344,7 @@ pub(crate) fn preprocess_ast_object(
23462344 let original_object = object. clone ( ) ;
23472345 let text = synthetic_source_from_ast_object ( vm, & object) ?;
23482346 let source_file = SourceFileBuilder :: new ( filename. to_owned ( ) , text) . finish ( ) ;
2349- let ast = constant:: with_ast_from_object_context ( vm, |from_ctx| {
2350- Node :: ast_from_object ( from_ctx, & source_file, object)
2351- } ) ?;
2347+ let ast = Node :: ast_from_object ( vm, & source_file, object) ?;
23522348 validate:: validate_mod ( vm, & ast) ?;
23532349 let syntax_check_only = !optimized_ast;
23542350
@@ -2405,8 +2401,7 @@ pub(crate) fn preprocess_ast_object(
24052401 }
24062402 Mod :: FunctionType ( function_type) => Mod :: FunctionType ( function_type) ,
24072403 } ;
2408- let ctx = AstToObjectContext :: new ( vm, & source_file) ;
2409- let result = ast. ast_to_object ( & ctx) ;
2404+ let result = ast. ast_to_object ( vm, & source_file) ;
24102405 copy_ast_passthrough_fields ( vm, & original_object, & result) ?;
24112406 Ok ( result)
24122407}
@@ -2421,9 +2416,7 @@ pub(crate) fn compile(
24212416) -> PyResult {
24222417 let text = synthetic_source_from_ast_object ( vm, & object) ?;
24232418 let source_file = SourceFileBuilder :: new ( filename. to_owned ( ) , text. clone ( ) ) . finish ( ) ;
2424- let ast = constant:: with_ast_from_object_context ( vm, |from_ctx| {
2425- Node :: ast_from_object ( from_ctx, & source_file, object)
2426- } ) ?;
2419+ let ast = Node :: ast_from_object ( vm, & source_file, object) ?;
24272420 validate:: validate_mod ( vm, & ast) ?;
24282421 let ast = match ast {
24292422 Mod :: Module ( m) => ast:: Mod :: Module ( m. module ) ,
@@ -2486,9 +2479,7 @@ pub(crate) fn compile(
24862479#[ cfg( not( feature = "rustpython-codegen" ) ) ]
24872480pub ( crate ) fn validate_ast_object ( vm : & VirtualMachine , object : PyObjectRef ) -> PyResult < ( ) > {
24882481 let source_file = SourceFileBuilder :: new ( "<ast>" . to_owned ( ) , "" . to_owned ( ) ) . finish ( ) ;
2489- let ast = constant:: with_ast_from_object_context ( vm, |from_ctx| {
2490- Node :: ast_from_object ( from_ctx, & source_file, object)
2491- } ) ?;
2482+ let ast = Node :: ast_from_object ( vm, & source_file, object) ?;
24922483 validate:: validate_mod ( vm, & ast) ?;
24932484 Ok ( ( ) )
24942485}
0 commit comments