Skip to content

Commit 4838a48

Browse files
committed
fix(driver): do cleanup after analysis if no codegen is to be performed
Without this sqlite connection is never closed and the transaction is basically aborted, leaving an empty database around.
1 parent 9b2763f commit 4838a48

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/driver.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,19 @@ impl<C: CallbacksExt> Callbacks for CallbackWrapper<C> {
101101
}
102102

103103
fn after_analysis<'tcx>(&mut self, compiler: &Compiler, tcx: TyCtxt<'tcx>) -> Compilation {
104-
self.callback.lock().unwrap().after_analysis(compiler, tcx)
104+
let ret = self.callback.lock().unwrap().after_analysis(compiler, tcx);
105+
106+
if tcx.sess.opts.unstable_opts.no_codegen || !tcx.sess.opts.output_types.should_codegen() {
107+
// Normally we destory `cx` in `codegen_crate`. However when codegen is not happening,
108+
// that will not be invoked, and this is our last change to do cleanups.
109+
let tcx_addr = *tcx as *const _ as usize;
110+
let cx = TCX_EXT_MAP.lock().unwrap().remove(&tcx_addr).unwrap();
111+
assert!(cx.is::<C::ExtCtxt<'static>>());
112+
// SAFETY: we just check the (type-erased) type matches.
113+
drop(unsafe { Box::from_raw(Box::into_raw(cx) as *mut C::ExtCtxt<'tcx>) });
114+
}
115+
116+
ret
105117
}
106118
}
107119

0 commit comments

Comments
 (0)