Helper function to lower a closure definition to OOMIR This function is called when we encounter a closure call and need to ensure the closure's implementation is available in the OOMIR module.
(
tcx: TyCtxt<'tcx>,
closure_def_id: rustc_hir::def_id::DefId,
oomir_module: &mut oomir::Module,
)
| 60 | use oomir::Type; |
| 61 | use rustc_codegen_ssa::back::archive::{ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder}; |
| 62 | use rustc_codegen_ssa::{ |
| 63 | CompiledModule, CompiledModules, CrateInfo, ModuleKind, traits::CodegenBackend, |
| 64 | }; |
| 65 | use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; |
| 66 | use rustc_hir::def::DefKind; |
| 67 | use std::collections::VecDeque; |
| 68 | |
| 69 | use rustc_data_structures::unord::UnordMap; |
| 70 | use rustc_metadata::EncodedMetadata; |
| 71 | use rustc_middle::{ |
| 72 | dep_graph::{WorkProduct, WorkProductId}, |
| 73 | mono::MonoItem, |
| 74 | ty::{ |
| 75 | EarlyBinder, GenericArgs, Instance, InstanceKind, ShimKind, TyCtxt, TyKind, |
| 76 | TypeVisitableExt, TypingEnv, Unnormalized, VtblEntry, |
| 77 | }, |
| 78 | }; |
| 79 | use rustc_session::{ |
| 80 | IncrCompSession, Session, |
| 81 | config::OutputFilenames, |
| 82 | }; |
| 83 | use rustc_span::def_id::{DefId, LOCAL_CRATE}; |
| 84 | use rustc_structures::CrateType; |
| 85 | use std::{ |
| 86 | any::Any, |
| 87 | io::{BufReader, BufWriter, Read, Write}, |
| 88 | path::{Path, PathBuf}, |
| 89 | sync::{Arc, Mutex, mpsc}, |
| 90 | }; |
| 91 | |
| 92 | mod instrumentation; |
| 93 | mod lower1; |
| 94 | mod lower2; |
| 95 | mod oomir; |
| 96 | mod optimise1; |
| 97 | mod stable_hash; |
| 98 | |
| 99 | /// An instance of our Java bytecode codegen backend. |
| 100 | struct MyBackend; |
| 101 | |
| 102 | /// Rustc's codegen-unit partitioning is tuned for native backends which lower |
| 103 | /// functions into independently owned LLVM modules. Keep each OOMIR shard |
| 104 | /// bounded as a second line of defence for unusually large codegen units. |
| 105 | const MAX_MONO_ITEMS_PER_OOMIR_SHARD: usize = 256; |
| 106 | // Four lower2 workers usefully saturate large crates without retaining an |
| 107 | // unbounded number of prepared OOMIR modules on many-core hosts. |
| 108 | const MAX_CODEGEN_WORKERS: usize = 4; |
| 109 | const OOMIR_SHARD_QUEUE_DEPTH: usize = 1; |
| 110 | const CLASS_BUNDLE_MAGIC: &[u8; 8] = b"RCJVMB1\0"; |
| 111 | |
| 112 | fn combine_class_bundles(path: &Path, bundles: &[(String, PathBuf)]) -> std::io::Result<()> { |
| 113 | let mut output = BufWriter::new(std::fs::File::create(path)?); |
| 114 | output.write_all(CLASS_BUNDLE_MAGIC)?; |
| 115 | for (_, bundle_path) in bundles { |
| 116 | let mut bundle = BufReader::new(std::fs::File::open(bundle_path)?); |
| 117 | let mut magic = [0u8; CLASS_BUNDLE_MAGIC.len()]; |
| 118 | bundle.read_exact(&mut magic)?; |
| 119 | if &magic != CLASS_BUNDLE_MAGIC { |
no test coverage detected