Skip to content

Commit e780264

Browse files
committed
Auto merge of rust-lang#94107 - tmiasko:fewer-types, r=davidtwco
Reapply cg_llvm: `fewer_names` in `uncached_llvm_type` r? `@davidtwco` `@erikdesjardins`
2 parents 8ebec97 + 4e41a46 commit e780264

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

compiler/rustc_codegen_llvm/src/type_of.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::common::*;
22
use crate::context::TypeLowering;
3+
use crate::llvm_util::get_version;
34
use crate::type_::Type;
45
use rustc_codegen_ssa::traits::*;
56
use rustc_middle::bug;
@@ -42,7 +43,12 @@ fn uncached_llvm_type<'a, 'tcx>(
4243
// FIXME(eddyb) producing readable type names for trait objects can result
4344
// in problematically distinct types due to HRTB and subtyping (see #47638).
4445
// ty::Dynamic(..) |
45-
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str => {
46+
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str
47+
// For performance reasons we use names only when emitting LLVM IR. Unless we are on
48+
// LLVM < 14, where the use of unnamed types resulted in various issues, e.g., #76213,
49+
// #79564, and #79246.
50+
if get_version() < (14, 0, 0) || !cx.sess().fewer_names() =>
51+
{
4652
let mut name = with_no_visible_paths!(with_no_trimmed_paths!(layout.ty.to_string()));
4753
if let (&ty::Adt(def, _), &Variants::Single { index }) =
4854
(layout.ty.kind(), &layout.variants)
@@ -58,6 +64,9 @@ fn uncached_llvm_type<'a, 'tcx>(
5864
}
5965
Some(name)
6066
}
67+
// Use identified structure types for ADT. Due to pointee types in LLVM IR their definition
68+
// might be recursive. Other cases are non-recursive and we can use literal structure types.
69+
ty::Adt(..) => Some(String::new()),
6170
_ => None,
6271
};
6372

0 commit comments

Comments
 (0)