@@ -31,7 +31,7 @@ use monty_types::{
3131 AssertMessageAnnotations , CHECKER_MODULE_NAMES , CompileOptions , ExcType , ExtFunctionResult , IMPORT_STUBS_CALL_ID ,
3232 ModuleStub , MontyException , MontyObject , NamedValues , OsFunctionCall , OsPolicy , PrintStream , PrintWriter ,
3333 PrintWriterCallback , ResourceLimits , ResourceTracker , SANDBOX_MODULE_NAMES , SOURCE_SCAN_THRESHOLD , SourceRange ,
34- TypeCheckState , TypeCheckingConfig , allocate_into_baseline ,
34+ TypeCheckState , TypeCheckingConfig ,
3535} ;
3636
3737use super :: {
@@ -219,9 +219,7 @@ pub struct Child {
219219 /// Script name of the current session (used for error and type-check
220220 /// diagnostics).
221221 script_name : String ,
222- /// Built by the first type-checked feed and kept for the worker's life; what
223- /// building it allocates joins the baseline rather than that session's budget.
224- /// What its first run caches is charged to the session, as it always was.
222+ /// Built by the first type-checked feed and dropped when the session resets.
225223 type_checker : Option < TypeChecker > ,
226224 /// `Some` when the session was created with `type_check: true`.
227225 type_check : Option < TypeCheckState > ,
@@ -289,18 +287,10 @@ impl Child {
289287 pb:: parent_request:: Kind :: AbortFeed ( abort) => self . handle_abort_feed ( abort, sink) ,
290288 pb:: parent_request:: Kind :: Dump ( _) => self . handle_dump ( ) ,
291289 pb:: parent_request:: Kind :: Load ( load) => self . handle_load ( & load) ,
292- pb:: parent_request:: Kind :: Reset ( _) => match self . reset ( ) {
293- Ok ( ( ) ) => ok_event ( ) ,
294- // A failed scrub leaves the finished session's files in the
295- // type checker, so this worker must never serve another one:
296- // the next session could resolve the previous session's
297- // modules. Die with an explanation the parent can log rather
298- // than carry on — or panic, which it would only see as a crash.
299- Err ( err) => {
300- sink. send ( & self . fatal_event ( & format ! ( "type-check cleanup failed: {err}" ) ) ) ?;
301- return Ok ( HandleOutcome :: Fatal ) ;
302- }
303- } ,
290+ pb:: parent_request:: Kind :: Reset ( _) => {
291+ self . reset ( ) ;
292+ ok_event ( )
293+ }
304294 pb:: parent_request:: Kind :: Shutdown ( _) => {
305295 sink. send ( & ok_event ( ) ) ?;
306296 return Ok ( HandleOutcome :: Shutdown ) ;
@@ -1088,9 +1078,7 @@ impl Child {
10881078 module_stubs : & self . module_stubs ,
10891079 prelude : & state. committed_imports ,
10901080 } ;
1091- let type_checker = self
1092- . type_checker
1093- . get_or_insert_with ( || allocate_into_baseline ( TypeChecker :: default) ) ;
1081+ let type_checker = self . type_checker . get_or_insert_with ( TypeChecker :: default) ;
10941082 match type_checker. run_with ( & SourceFile :: new ( code, & self . script_name ) , & context, state. config ) {
10951083 Ok ( None ) => None ,
10961084 Ok ( Some ( diagnostics) ) => Some ( event ( pb:: child_event:: Kind :: TypingError ( pb:: TypingError {
@@ -1102,17 +1090,15 @@ impl Child {
11021090
11031091 /// Drops all session state, returning to the unconfigured state ready for
11041092 /// the next `Configure` (or `Load`).
1105- ///
1106- /// `Err` means the type checker still holds this session's files, which is
1107- /// terminal for the worker — see the `Reset` arm in [`Self::handle`].
1108- fn reset ( & mut self ) -> Result < ( ) , String > {
1093+ fn reset ( & mut self ) {
11091094 self . state = SessionState :: Configured ( None ) ;
1095+ // Invalidating source files leaves Salsa caches and interned data allocated.
1096+ self . type_checker = None ;
11101097 self . type_check = None ;
11111098 self . script_name = String :: new ( ) ;
11121099 self . print_flush_interval = DEFAULT_PRINT_FLUSH_INTERVAL ;
11131100 self . os_policy = OsPolicy :: default ( ) ;
11141101 self . module_stubs = Vec :: new ( ) ;
1115- self . type_checker . as_mut ( ) . map_or ( Ok ( ( ) ) , TypeChecker :: reset)
11161102 }
11171103}
11181104
0 commit comments