Skip to content

Commit 870bc6a

Browse files
osiewiczbjorn3
andcommitted
Apply perf suggestions from code review
Co-authored-by: bjorn3 <[email protected]>
1 parent 57eaa9a commit 870bc6a

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
164164
tcx.reachable_non_generics(def_id.krate).contains_key(&def_id)
165165
}
166166

167-
fn exported_symbols_provider_local(
168-
tcx: TyCtxt<'_>,
167+
fn exported_symbols_provider_local<'tcx>(
168+
tcx: TyCtxt<'tcx>,
169169
_: LocalCrate,
170-
) -> &[(ExportedSymbol<'_>, SymbolExportInfo)] {
170+
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
171171
if !tcx.sess.opts.output_types.should_codegen() {
172172
return &[];
173173
}
@@ -341,11 +341,17 @@ fn exported_symbols_provider_local(
341341
is_local
342342
};
343343

344-
let is_instantiable_downstream = |did, type_args| {
345-
std::iter::once(tcx.type_of(did).skip_binder()).chain(type_args).all(|arg| {
346-
arg.walk().all(|ty| ty.as_type().map_or(true, |ty| !is_local_to_current_crate(ty)))
347-
})
348-
};
344+
let is_instantiable_downstream =
345+
|did: Option<DefId>, generic_args: GenericArgsRef<'tcx>| {
346+
generic_args
347+
.types()
348+
.chain(did.into_iter().map(move |did| tcx.type_of(did).skip_binder()))
349+
.all(move |arg| {
350+
arg.walk().all(|ty| {
351+
ty.as_type().map_or(true, |ty| !is_local_to_current_crate(ty))
352+
})
353+
})
354+
};
349355

350356
// The symbols created in this loop are sorted below it
351357
#[allow(rustc::potential_query_instability)]
@@ -378,7 +384,7 @@ fn exported_symbols_provider_local(
378384
let has_generics = args.non_erasable_generics().next().is_some();
379385

380386
let should_export =
381-
has_generics && is_instantiable_downstream(def, args.types());
387+
has_generics && is_instantiable_downstream(Some(def), &args);
382388

383389
if should_export {
384390
let symbol = ExportedSymbol::Generic(def, args);
@@ -396,9 +402,10 @@ fn exported_symbols_provider_local(
396402
// A little sanity-check
397403
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
398404

405+
// Drop glue did is always going to be non-local outside of libcore, thus we don't need to check it's locality (which includes invoking `type_of` query).
399406
let should_export = match ty.kind() {
400-
ty::Adt(def, args) => is_instantiable_downstream(def.did(), args.types()),
401-
ty::Closure(id, args) => is_instantiable_downstream(*id, args.types()),
407+
ty::Adt(_, args) => is_instantiable_downstream(None, args),
408+
ty::Closure(_, args) => is_instantiable_downstream(None, args),
402409
_ => true,
403410
};
404411

0 commit comments

Comments
 (0)