message: Split create_ecx out of eval_main
diff: @@ -132,16 +132,13 @@ impl ScalarExt for Scalar {
  }
  }
  -pub fn eval_main<'a, 'tcx: 'a>(
  +fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
  tcx: TyCtxt<'a, 'tcx, 'tcx>,
  main_id: DefId,
  start_wrapper: Option<DefId>,
  -) {
  - fn run_main<'a, 'mir: 'a, 'tcx: 'mir>(
  - ecx: &mut rustc_mir::interpret::EvalContext<'a, 'mir, 'tcx, Evaluator<'tcx>>,
  - main_id: DefId,
  - start_wrapper: Option<DefId>,
  - ) -> EvalResult<'tcx> {
  +) -> EvalResult<'tcx, (EvalContext<'a, 'mir, 'tcx, Evaluator<'tcx>>, Option<Pointer>)> {
  + let mut ecx = EvalContext::new(tcx.at(syntax::codemap::DUMMY_SP), ty::ParamEnv::reveal_all(), Default::default(), Default::default());
  +
  let main_instance = ty::Instance::mono(ecx.tcx.tcx, main_id);
  let main_mir = ecx.load_mir(main_instance.def)?;
  let mut cleanup_ptr = None; // Scalar to be deallocated when we are done
  @@ -161,7 +158,8 @@ pub fn eval_main<'a, 'tcx: 'a>(
  ty::ParamEnv::reveal_all(),
  start_id,
  ecx.tcx.mk_substs(
  - ::std::iter::once(ty::subst::Kind::from(main_ret_ty)))).unwrap();
  + ::std::iter::once(ty::subst::Kind::from(main_ret_ty)))
  + ).unwrap();
  let start_mir = ecx.load_mir(start_instance.def)?;
  if start_mir.arg_count != 3 {
  @@ -233,6 +231,17 @@ pub fn eval_main<'a, 'tcx: 'a>(
  assert!(args.next().is_none(), "main function must not have arguments");
  }
  + Ok((ecx, cleanup_ptr))
  +}
  +
  +pub fn eval_main<'a, 'tcx: 'a>(
  + tcx: TyCtxt<'a, 'tcx, 'tcx>,
  + main_id: DefId,
  + start_wrapper: Option<DefId>,
  +) {
  + let (mut ecx, cleanup_ptr) = create_ecx(tcx, main_id, start_wrapper).expect("Couldn't create ecx");
  +
  + let res: EvalResult = do catch {
  while ecx.step()? {}
  ecx.run_tls_dtors()?;
  if let Some(cleanup_ptr) = cleanup_ptr {
  @@ -242,11 +251,9 @@ pub fn eval_main<'a, 'tcx: 'a>(
  MemoryKind::Stack,
  )?;
  }
  - Ok(())
  - }
  + };
  - let mut ecx = EvalContext::new(tcx.at(syntax::codemap::DUMMY_SP), ty::ParamEnv::reveal_all(), Default::default(), Default::default());
  - match run_main(&mut ecx, main_id, start_wrapper) {
  + match res {
  Ok(()) => {
  let leaks = ecx.memory().leak_report();
  if leaks != 0 {
  