-
Couldn't load subscription status.
- Fork 400
[WIP] Use the dummy codegen backend #4648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,16 +39,12 @@ use miri::{ | |
| use rustc_abi::ExternAbi; | ||
| use rustc_data_structures::sync; | ||
| use rustc_driver::Compilation; | ||
| use rustc_hir as hir; | ||
| use rustc_hir::def_id::LOCAL_CRATE; | ||
| use rustc_hir::{self as hir, Node}; | ||
| use rustc_hir_analysis::check::check_function_signature; | ||
| use rustc_interface::interface::Config; | ||
| use rustc_log::tracing::debug; | ||
| use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; | ||
| use rustc_middle::middle::exported_symbols::{ | ||
| ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel, | ||
| }; | ||
| use rustc_middle::query::LocalCrate; | ||
| use rustc_middle::middle::exported_symbols::ExportedSymbol; | ||
| use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; | ||
| use rustc_middle::ty::{self, Ty, TyCtxt}; | ||
| use rustc_middle::util::Providers; | ||
|
|
@@ -250,71 +246,6 @@ struct MiriBeRustCompilerCalls { | |
| } | ||
|
|
||
| impl rustc_driver::Callbacks for MiriBeRustCompilerCalls { | ||
| #[allow(rustc::potential_query_instability)] // rustc_codegen_ssa (where this code is copied from) also allows this lint | ||
| fn config(&mut self, config: &mut Config) { | ||
| if config.opts.prints.is_empty() && self.target_crate { | ||
| // Queries overridden here affect the data stored in `rmeta` files of dependencies, | ||
| // which will be used later in non-`MIRI_BE_RUSTC` mode. | ||
| config.override_queries = Some(|_, local_providers| { | ||
| // `exported_non_generic_symbols` and `reachable_non_generics` provided by rustc always returns | ||
| // an empty result if `tcx.sess.opts.output_types.should_codegen()` is false. | ||
| // In addition we need to add #[used] symbols to exported_symbols for `lookup_link_section`. | ||
| local_providers.exported_non_generic_symbols = |tcx, LocalCrate| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought we may still need this for |
||
| let reachable_set = tcx.with_stable_hashing_context(|hcx| { | ||
| tcx.reachable_set(()).to_sorted(&hcx, true) | ||
| }); | ||
| tcx.arena.alloc_from_iter( | ||
| // This is based on: | ||
| // https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L62-L63 | ||
| // https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L174 | ||
| reachable_set.into_iter().filter_map(|&local_def_id| { | ||
| // Do the same filtering that rustc does: | ||
| // https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L84-L102 | ||
| // Otherwise it may cause unexpected behaviours and ICEs | ||
| // (https://github.com/rust-lang/rust/issues/86261). | ||
| let is_reachable_non_generic = matches!( | ||
| tcx.hir_node_by_def_id(local_def_id), | ||
| Node::Item(&hir::Item { | ||
| kind: hir::ItemKind::Static(..) | hir::ItemKind::Fn{ .. }, | ||
| .. | ||
| }) | Node::ImplItem(&hir::ImplItem { | ||
| kind: hir::ImplItemKind::Fn(..), | ||
| .. | ||
| }) | ||
| if !tcx.generics_of(local_def_id).requires_monomorphization(tcx) | ||
| ); | ||
| if !is_reachable_non_generic { | ||
| return None; | ||
| } | ||
| let codegen_fn_attrs = tcx.codegen_fn_attrs(local_def_id); | ||
| if codegen_fn_attrs.contains_extern_indicator() | ||
| || codegen_fn_attrs | ||
| .flags | ||
| .contains(CodegenFnAttrFlags::USED_COMPILER) | ||
| || codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) | ||
| { | ||
| Some(( | ||
| ExportedSymbol::NonGeneric(local_def_id.to_def_id()), | ||
| // Some dummy `SymbolExportInfo` here. We only use | ||
| // `exported_symbols` in shims/foreign_items.rs and the export info | ||
| // is ignored. | ||
| SymbolExportInfo { | ||
| level: SymbolExportLevel::C, | ||
| kind: SymbolExportKind::Text, | ||
| used: false, | ||
| rustc_std_internal_symbol: false, | ||
| }, | ||
| )) | ||
| } else { | ||
| None | ||
| } | ||
| }), | ||
| ) | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| fn after_analysis<'tcx>( | ||
| &mut self, | ||
| _: &rustc_interface::interface::Compiler, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,7 @@ pub use crate::shims::unwind::{CatchUnwindData, EvalContextExt as _}; | |
| /// Also disable the MIR pass that inserts an alignment check on every pointer dereference. Miri | ||
| /// does that too, and with a better error message. | ||
| pub const MIRI_DEFAULT_ARGS: &[&str] = &[ | ||
| "-Zcodegen-backend=dummy", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dummy codegen backend is a builtin codegen backend that is only capable of emitting rlibs containing the crate metadata. For every other crate type it emits an error after codegen. This is fine for miri as for |
||
| "--cfg=miri", | ||
| "-Zalways-encode-mir", | ||
| "-Zextra-const-ub-checks", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
forward_patched_extern_argfunction can likely be removed as the fake lib file hack has been removed.