Skip to content

Commit c47eeac

Browse files
committed
Move wasm_import_module_map provider to cg_ssa
1 parent 808090e commit c47eeac

File tree

3 files changed

+31
-38
lines changed

3 files changed

+31
-38
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

-31
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ use std::ffi::CString;
44

55
use cstr::cstr;
66
use rustc_codegen_ssa::traits::*;
7-
use rustc_data_structures::fx::FxHashMap;
87
use rustc_data_structures::small_c_str::SmallCStr;
98
use rustc_hir::def_id::DefId;
109
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1110
use rustc_middle::ty::layout::HasTyCtxt;
12-
use rustc_middle::ty::query::Providers;
1311
use rustc_middle::ty::{self, TyCtxt};
1412
use rustc_session::config::{OptLevel, SanitizerSet};
1513
use rustc_session::Session;
@@ -339,35 +337,6 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
339337
}
340338
}
341339

342-
pub fn provide_both(providers: &mut Providers) {
343-
providers.wasm_import_module_map = |tcx, cnum| {
344-
// Build up a map from DefId to a `NativeLib` structure, where
345-
// `NativeLib` internally contains information about
346-
// `#[link(wasm_import_module = "...")]` for example.
347-
let native_libs = tcx.native_libraries(cnum);
348-
349-
let def_id_to_native_lib = native_libs
350-
.iter()
351-
.filter_map(|lib| lib.foreign_module.map(|id| (id, lib)))
352-
.collect::<FxHashMap<_, _>>();
353-
354-
let mut ret = FxHashMap::default();
355-
for (def_id, lib) in tcx.foreign_modules(cnum).iter() {
356-
let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module);
357-
let module = match module {
358-
Some(s) => s,
359-
None => continue,
360-
};
361-
ret.extend(lib.foreign_items.iter().map(|id| {
362-
assert_eq!(id.krate, cnum);
363-
(*id, module.to_string())
364-
}));
365-
}
366-
367-
ret
368-
};
369-
}
370-
371340
fn wasm_import_module(tcx: TyCtxt<'_>, id: DefId) -> Option<CString> {
372341
tcx.wasm_import_module_map(id.krate).get(&id).map(|s| CString::new(&s[..]).unwrap())
373342
}

compiler/rustc_codegen_llvm/src/lib.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,8 @@ impl CodegenBackend for LlvmCodegenBackend {
253253
Box::new(metadata::LlvmMetadataLoader)
254254
}
255255

256-
fn provide(&self, providers: &mut ty::query::Providers) {
257-
attributes::provide_both(providers);
258-
}
259-
260-
fn provide_extern(&self, providers: &mut ty::query::Providers) {
261-
attributes::provide_both(providers);
262-
}
256+
fn provide(&self, _providers: &mut ty::query::Providers) {}
257+
fn provide_extern(&self, _providers: &mut ty::query::Providers) {}
263258

264259
fn codegen_crate<'tcx>(
265260
&self,

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+29
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,13 @@ pub fn provide(providers: &mut Providers) {
369369
providers.upstream_monomorphizations = upstream_monomorphizations_provider;
370370
providers.is_unreachable_local_definition = is_unreachable_local_definition_provider;
371371
providers.upstream_drop_glue_for = upstream_drop_glue_for_provider;
372+
providers.wasm_import_module_map = wasm_import_module_map;
372373
}
373374

374375
pub fn provide_extern(providers: &mut Providers) {
375376
providers.is_reachable_non_generic = is_reachable_non_generic_provider_extern;
376377
providers.upstream_monomorphizations_for = upstream_monomorphizations_for_provider;
378+
providers.wasm_import_module_map = wasm_import_module_map;
377379
}
378380

379381
fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel {
@@ -441,3 +443,30 @@ pub fn symbol_name_for_instance_in_crate<'tcx>(
441443
ExportedSymbol::NoDefId(symbol_name) => symbol_name.to_string(),
442444
}
443445
}
446+
447+
fn wasm_import_module_map(tcx: TyCtxt<'_>, cnum: CrateNum) -> FxHashMap<DefId, String> {
448+
// Build up a map from DefId to a `NativeLib` structure, where
449+
// `NativeLib` internally contains information about
450+
// `#[link(wasm_import_module = "...")]` for example.
451+
let native_libs = tcx.native_libraries(cnum);
452+
453+
let def_id_to_native_lib = native_libs
454+
.iter()
455+
.filter_map(|lib| lib.foreign_module.map(|id| (id, lib)))
456+
.collect::<FxHashMap<_, _>>();
457+
458+
let mut ret = FxHashMap::default();
459+
for (def_id, lib) in tcx.foreign_modules(cnum).iter() {
460+
let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module);
461+
let module = match module {
462+
Some(s) => s,
463+
None => continue,
464+
};
465+
ret.extend(lib.foreign_items.iter().map(|id| {
466+
assert_eq!(id.krate, cnum);
467+
(*id, module.to_string())
468+
}));
469+
}
470+
471+
ret
472+
}

0 commit comments

Comments
 (0)