Skip to content

Commit

Permalink
Reapply cg_llvm: fewer_names in uncached_llvm_type
Browse files Browse the repository at this point in the history
Co-authored-by: Erik Desjardins <erikdesjardins@users.noreply.github.com>
Co-authored-by: Tomasz Miąsko <tomasz.miasko@gmail.com>
  • Loading branch information
3 people committed Feb 22, 2022
1 parent b8967b0 commit 4e41a46
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion compiler/rustc_codegen_llvm/src/type_of.rs
@@ -1,5 +1,6 @@
use crate::common::*;
use crate::context::TypeLowering;
use crate::llvm_util::get_version;
use crate::type_::Type;
use rustc_codegen_ssa::traits::*;
use rustc_middle::bug;
Expand Down Expand Up @@ -42,7 +43,12 @@ fn uncached_llvm_type<'a, 'tcx>(
// FIXME(eddyb) producing readable type names for trait objects can result
// in problematically distinct types due to HRTB and subtyping (see #47638).
// ty::Dynamic(..) |
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str => {
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str
// For performance reasons we use names only when emitting LLVM IR. Unless we are on
// LLVM < 14, where the use of unnamed types resulted in various issues, e.g., #76213,
// #79564, and #79246.
if get_version() < (14, 0, 0) || !cx.sess().fewer_names() =>
{
let mut name = with_no_visible_paths!(with_no_trimmed_paths!(layout.ty.to_string()));
if let (&ty::Adt(def, _), &Variants::Single { index }) =
(layout.ty.kind(), &layout.variants)
Expand All @@ -58,6 +64,9 @@ fn uncached_llvm_type<'a, 'tcx>(
}
Some(name)
}
// Use identified structure types for ADT. Due to pointee types in LLVM IR their definition
// might be recursive. Other cases are non-recursive and we can use literal structure types.
ty::Adt(..) => Some(String::new()),
_ => None,
};

Expand Down

0 comments on commit 4e41a46

Please sign in to comment.