@@ -18,7 +18,7 @@ use rustc_errors::PResult;
1818use rustc_errors:: { DiagnosticBuilder , ErrorGuaranteed } ;
1919use rustc_index:: vec:: IndexVec ;
2020use rustc_interface:: interface;
21- use rustc_interface:: util:: { get_codegen_backend , run_in_thread_pool_with_globals} ;
21+ use rustc_interface:: util:: run_in_thread_pool_with_globals;
2222use rustc_interface:: { util, Config } ;
2323use rustc_lint:: LintStore ;
2424use rustc_middle:: hir:: map as hir_map;
@@ -31,15 +31,13 @@ use rustc_session::{self, DiagnosticOutput, Session};
3131use rustc_span:: def_id:: LocalDefId ;
3232use rustc_span:: edition:: Edition ;
3333use rustc_span:: hygiene:: SyntaxContext ;
34+ use rustc_span:: source_map:: FileLoader ;
3435use rustc_span:: source_map:: SourceMap ;
35- use rustc_span:: source_map:: { FileLoader , RealFileLoader } ;
3636use rustc_span:: symbol:: { kw, Symbol } ;
37- use rustc_span:: SourceFileHashAlgorithm ;
3837use rustc_span:: { FileName , Span , DUMMY_SP } ;
3938use std:: collections:: HashSet ;
4039use std:: mem;
4140use std:: path:: { Path , PathBuf } ;
42- use std:: rc:: Rc ;
4341use std:: sync:: Arc ;
4442
4543use crate :: ast_manip:: { remove_paren, AstSpanMaps } ;
@@ -92,115 +90,6 @@ impl<'a, 'tcx: 'a> RefactorCtxt<'a, 'tcx> {
9290 }
9391}
9492
95- // /// Various driver bits that we have lying around at the end of `phase_1_parse_input`. This is
96- // /// everything we need to (re-)run the compiler from phase 1 onward.
97- // pub struct Phase1Bits {
98- // session: Session,
99- // cstore: CStore,
100- // codegen_backend: Box<CodegenBackend>,
101- // input: Input,
102- // output: Option<PathBuf>,
103- // out_dir: Option<PathBuf>,
104- // control: CompileController<'static>,
105- // krate: Crate,
106- // }
107-
108- // impl Phase1Bits {
109- // /// Set up the compiler again, using a previously-constructed `Session`.
110- // ///
111- // /// A `Crate` is mostly self-contained, but its `Span`s are really indexes into external
112- // /// tables. So if you actually plan to run the compiler after calling `reset()`, the new
113- // /// `krate` passed here should satisfy a few properties:
114- // ///
115- // /// 1. The crate must have been parsed under the same `SourceMap` used by `session`. Spans'
116- // /// `hi` and `lo` byte positions are indices into the `SourceMap` used for parsing, so
117- // /// transferring those spans to a different `SourceMap` produces nonsensical results.
118- // ///
119- // /// 2. The crate must not contain any paths starting with `$crate` from a non-empty
120- // /// `SyntaxCtxt`. These types of paths appear during macro expansion, and can only be
121- // /// resolved using tables populated by the macro expander.
122- // ///
123- // /// 3. All `NodeId`s in the crate must be DUMMY_NODE_ID.
124- // ///
125- // /// 4. The crate must not contain automatically-injected `extern crate` declarations. The
126- // /// compilation process will inject new copies of these, and then fail due to the name
127- // /// collision.
128- // ///
129- // /// A crate that has only been compiled to `Phase1` already satisfies points 2-4. If you want
130- // /// to re-compile a crate from `Phase2` or later, use `recheck::prepare_recheck` to fix things
131- // /// up first.
132- // pub fn from_session_and_crate(old_session: &Session, krate: Crate) -> Phase1Bits {
133- // let (session, cstore, codegen_backend) = rebuild_session(old_session);
134-
135- // let in_path = old_session.local_crate_source_file.clone();
136- // let input = Input::File(in_path.unwrap());
137-
138- // let mut control = CompileController::basic();
139- // control.provide = Box::new(move |providers| {
140- // use rustc_hir::def_id::CrateNum;
141- // use rustc_middle::privacy::AccessLevels;
142- // use rustc_data_structures::sync::Lrc;
143- // use rustc_privacy;
144-
145- // fn privacy_access_levels<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>,
146- // krate: CrateNum) -> Lrc<AccessLevels> {
147- // // Get and call the original implementation, resetting the error count before
148- // // returning so that `abort_if_errors` won't abort.
149- // // NOTE: It's possible in theory for the codegen_backend to override the
150- // // implementation, since `codegen_backend.provide` runs after `default_provide`.
151- // // We wouldn't handle that since we call only `rustc_privacy::provide` here.
152- // // Privacy checking would be a weird thing for a backend to override, though.
153- // let mut p = Providers::default();
154- // rustc_privacy::provide(&mut p);
155- // let r = (p.privacy_access_levels)(tcx, krate);
156- // tcx.sess.diagnostic().reset_err_count();
157- // r
158- // }
159- // providers.privacy_access_levels = privacy_access_levels;
160-
161- // // TODO: provide error-resetting versions of other "query + `abort_if_errors`" passes
162- // // in `phase_3_run_analysis_passes`.
163- // });
164-
165- // Phase1Bits {
166- // session, cstore, codegen_backend,
167-
168- // input,
169- // output: None,
170- // out_dir: None,
171-
172- // control, krate,
173- // }
174- // }
175-
176- // /// Set up the compiler using a previously-created session, repeating phase 1 (input parsing).
177- // pub fn from_session_reparse(old_session: &Session) -> Phase1Bits {
178- // let (session, cstore, codegen_backend) = rebuild_session(old_session);
179-
180- // let in_path = old_session.local_crate_source_file.clone();
181- // let input = Input::File(in_path.unwrap());
182-
183- // let control = CompileController::basic();
184-
185- // // Start of `compile_input` code
186- // let krate = driver::phase_1_parse_input(&control, &session, &input).unwrap();
187-
188- // Phase1Bits {
189- // session, cstore, codegen_backend,
190-
191- // input,
192- // output: None,
193- // out_dir: None,
194-
195- // control, krate,
196- // }
197- // }
198-
199- // pub fn into_crate(self) -> Crate {
200- // self.krate
201- // }
202- // }
203-
20493/// Sysroot adjustment: if the sysroot is unset, and args[0] is an absolute path, use args[0] to
20594/// infer a sysroot. Rustc's own sysroot detection (filesearch::get_or_default_sysroot) uses
20695/// env::current_exe, which will point to c2rust-refactor, not rustc.
@@ -382,121 +271,6 @@ pub fn make_compiler(
382271 compiler
383272}
384273
385- // pub fn run_compiler_to_phase1(args: &[String],
386- // file_loader: Option<Box<FileLoader+Sync+Send>>) -> Phase1Bits {
387- // let matches = rustc_driver::handle_options(args)
388- // .expect("rustc arg parsing failed");
389- // let (sopts, _cfg) = session::config::build_session_options_and_crate_config(&matches);
390- // let sopts = maybe_set_sysroot(sopts, args);
391- // let out_dir = matches.opt_str("out-dir").map(|o| PathBuf::from(&o));
392- // let output = matches.opt_str("o").map(|o| PathBuf::from(&o));
393-
394- // assert!(matches.free.len() == 1,
395- // "expected exactly one input file");
396- // let in_path = Some(Path::new(&matches.free[0]).to_owned());
397- // let input = Input::File(in_path.as_ref().unwrap().clone());
398-
399- // let (session, cstore, codegen_backend) = build_session(sopts, in_path, file_loader);
400-
401- // // It might seem tempting to set up a custom CompileController and invoke `compile_input` here,
402- // // in order to avoid duplicating a bunch of `compile_input`'s logic. Unfortunately, that
403- // // doesn't work well with the current API. The `CompileState`s provided to the PhaseController
404- // // callbacks only contain the data relevant to th ecurrent phase - for example, in the
405- // // after_analysis callback, `tcx` is available but `krate`, `arena`, and `hir_map` are not.
406- // // Furthermore, the callback type is such that the `CompileState`s for separate callbacks have
407- // // unrelated lifetimes, so we can't (safely) collect up the relevant pieces ourselves from
408- // // multiple callback invocations.
409-
410- // let control = CompileController::basic();
411-
412- // // Start of `compile_input` code
413- // let krate = driver::phase_1_parse_input(&control, &session, &input).unwrap();
414-
415- // Phase1Bits {
416- // session, cstore, codegen_backend,
417- // input, output, out_dir,
418- // control, krate,
419- // }
420- // }
421-
422- /// Run the compiler with some command line `args`. Stops compiling and invokes the callback
423- /// `func` after the indicated `phase`.
424- ///
425- /// `file_loader` can be `None` to read source code from the file system. Otherwise, the provided
426- /// loader will be used within the compiler. For example, editor integration uses a custom file
427- /// loader to provide the compiler with buffer contents for currently open files.
428- // pub fn run_compiler<F, R>(args: &[String],
429- // file_loader: Option<Box<FileLoader+Sync+Send>>,
430- // phase: Phase,
431- // func: F) -> R
432- // where F: FnOnce(Crate, RefactorCtxt) -> R {
433- // let bits = run_compiler_to_phase1(args, file_loader);
434- // run_compiler_from_phase1(bits, phase, func)
435- // }
436-
437- pub fn build_session_from_args (
438- args : & [ String ] ,
439- file_loader : Option < Box < dyn FileLoader + Sync + Send > > ,
440- ) -> Session {
441- let matches = rustc_driver:: handle_options ( args) . expect ( "rustc arg parsing failed" ) ;
442-
443- let sopts = rustc_session:: config:: build_session_options ( & matches) ;
444- let sopts = maybe_set_sysroot ( sopts, args) ;
445-
446- assert ! ( matches. free. len( ) == 1 , "expected exactly one input file" ) ;
447- let in_path = Some ( Path :: new ( & matches. free [ 0 ] ) . to_owned ( ) ) ;
448-
449- let ( session, _codegen_backend) = build_session ( sopts, in_path, file_loader) ;
450- session
451- }
452-
453- fn build_session (
454- sopts : SessionOptions ,
455- in_path : Option < PathBuf > ,
456- file_loader : Option < Box < dyn FileLoader + Sync + Send > > ,
457- ) -> ( Session , Box < dyn CodegenBackend > ) {
458- // Corresponds roughly to `run_compiler`.
459- let descriptions = rustc_driver:: diagnostics_registry ( ) ;
460- let file_loader = file_loader. unwrap_or_else ( || Box :: new ( RealFileLoader ) ) ;
461- let hash_kind = sopts
462- . unstable_opts
463- . src_hash_algorithm
464- . unwrap_or ( SourceFileHashAlgorithm :: Md5 ) ;
465- // Note: `source_map` is expected to be an `Lrc<SourceMap>`, which is an alias for `Rc<SourceMap>`.
466- // If this ever changes, we'll need a new trick to obtain the `SourceMap` in `rebuild_session`.
467- let source_map = Rc :: new ( SourceMap :: with_file_loader_and_hash_kind (
468- file_loader,
469- sopts. file_path_mapping ( ) ,
470- hash_kind,
471- ) ) ;
472- // Put a dummy file at the beginning of the source_map, so that no real `Span` will accidentally
473- // collide with `DUMMY_SP` (which is `0 .. 0`).
474- source_map. new_source_file ( FileName :: Custom ( "<dummy>" . to_string ( ) ) , " " . to_string ( ) ) ;
475-
476- let codegen_backend = get_codegen_backend (
477- & sopts. maybe_sysroot ,
478- sopts
479- . unstable_opts
480- . codegen_backend
481- . as_ref ( )
482- . map ( |name| & name[ ..] ) ,
483- ) ;
484- let target_override = codegen_backend. target_override ( & sopts) ;
485- let sess = rustc_session:: build_session (
486- sopts,
487- in_path,
488- None ,
489- descriptions,
490- DiagnosticOutput :: Default ,
491- Default :: default ( ) ,
492- None ,
493- target_override,
494- ) ;
495- codegen_backend. init ( & sess) ;
496-
497- ( sess, codegen_backend)
498- }
499-
500274fn make_parser < ' a > ( sess : & ' a Session , src : & str ) -> Parser < ' a > {
501275 rustc_parse:: new_parser_from_source_str (
502276 & sess. parse_sess ,
0 commit comments