Skip to content

Commit 38120d0

Browse files
committed
Don't deduplicate vtables between functions
1 parent 29a4a55 commit 38120d0

File tree

6 files changed

+15
-32
lines changed

6 files changed

+15
-32
lines changed

src/base.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ pub(crate) fn codegen_fn<'tcx>(cx: &mut crate::CodegenCx<'_, 'tcx>, instance: In
1818
let mir = tcx.instance_mir(instance.def);
1919

2020
// Declare function
21-
let name = tcx.symbol_name(instance).name.to_string();
21+
let symbol_name = tcx.symbol_name(instance);
2222
let sig = get_function_sig(tcx, cx.module.isa().triple(), instance);
23-
let func_id = cx.module.declare_function(&name, Linkage::Local, &sig).unwrap();
23+
let func_id = cx.module.declare_function(symbol_name.name, Linkage::Local, &sig).unwrap();
2424

2525
cx.cached_context.clear();
2626

@@ -46,8 +46,10 @@ pub(crate) fn codegen_fn<'tcx>(cx: &mut crate::CodegenCx<'_, 'tcx>, instance: In
4646
cx,
4747
tcx,
4848
pointer_type,
49+
vtables: FxHashMap::default(),
4950

5051
instance,
52+
symbol_name,
5153
mir,
5254
fn_abi: Some(FnAbi::of_instance(&RevealAllLayoutCx(tcx), instance, &[])),
5355

@@ -151,7 +153,7 @@ pub(crate) fn codegen_fn<'tcx>(cx: &mut crate::CodegenCx<'_, 'tcx>, instance: In
151153
debug_context.define_function(
152154
instance,
153155
func_id,
154-
&name,
156+
symbol_name.name,
155157
isa,
156158
context,
157159
&source_info_set,

src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_index::vec::IndexVec;
2+
use rustc_middle::ty::SymbolName;
23
use rustc_target::abi::call::FnAbi;
34
use rustc_target::abi::{Integer, Primitive};
45
use rustc_target::spec::{HasTargetSpec, Target};
@@ -230,8 +231,10 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx> {
230231
pub(crate) cx: &'clif mut crate::CodegenCx<'m, 'tcx>,
231232
pub(crate) tcx: TyCtxt<'tcx>,
232233
pub(crate) pointer_type: Type, // Cached from module
234+
pub(crate) vtables: FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
233235

234236
pub(crate) instance: Instance<'tcx>,
237+
pub(crate) symbol_name: SymbolName<'tcx>,
235238
pub(crate) mir: &'tcx Body<'tcx>,
236239
pub(crate) fn_abi: Option<FnAbi<'tcx, Ty<'tcx>>>,
237240

src/inline_asm.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
9292

9393
let inline_asm_index = fx.inline_asm_index;
9494
fx.inline_asm_index += 1;
95-
let asm_name =
96-
format!("{}__inline_asm_{}", fx.tcx.symbol_name(fx.instance).name, inline_asm_index);
95+
let asm_name = format!("{}__inline_asm_{}", fx.symbol_name, inline_asm_index);
9796

9897
let generated_asm = generate_asm_wrapper(
9998
&asm_name,

src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ struct CodegenCx<'m, 'tcx: 'm> {
125125
global_asm: String,
126126
constants_cx: ConstantCx,
127127
cached_context: Context,
128-
vtables: FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
129128
debug_context: Option<DebugContext<'tcx>>,
130129
unwind_context: UnwindContext<'tcx>,
131130
}
@@ -150,7 +149,6 @@ impl<'m, 'tcx> CodegenCx<'m, 'tcx> {
150149
global_asm: String::new(),
151150
constants_cx: ConstantCx::default(),
152151
cached_context: Context::new(),
153-
vtables: FxHashMap::default(),
154152
debug_context,
155153
unwind_context,
156154
}

src/trap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) {
2121
fx.add_comment(puts, "puts");
2222
}
2323

24-
let symbol_name = fx.tcx.symbol_name(fx.instance);
25-
let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, symbol_name, msg);
24+
let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, fx.symbol_name, msg);
2625
let msg_ptr = fx.anonymous_str("trap", &real_msg);
2726
fx.bcx.ins().call(puts, &[msg_ptr]);
2827
}

src/vtable.rs

+5-23
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ pub(crate) fn get_vtable<'tcx>(
7272
layout: TyAndLayout<'tcx>,
7373
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
7474
) -> Value {
75-
let data_id = if let Some(data_id) = fx.cx.vtables.get(&(layout.ty, trait_ref)) {
75+
let data_id = if let Some(data_id) = fx.vtables.get(&(layout.ty, trait_ref)) {
7676
*data_id
7777
} else {
7878
let data_id = build_vtable(fx, layout, trait_ref);
79-
fx.cx.vtables.insert((layout.ty, trait_ref), data_id);
79+
fx.vtables.insert((layout.ty, trait_ref), data_id);
8080
data_id
8181
};
8282

@@ -139,27 +139,9 @@ fn build_vtable<'tcx>(
139139

140140
data_ctx.set_align(fx.tcx.data_layout.pointer_align.pref.bytes());
141141

142-
let data_id = fx
143-
.cx
144-
.module
145-
.declare_data(
146-
&format!(
147-
"__vtable.{}.for.{:?}.{}",
148-
trait_ref
149-
.as_ref()
150-
.map(|trait_ref| format!("{:?}", trait_ref.skip_binder()).into())
151-
.unwrap_or(std::borrow::Cow::Borrowed("???")),
152-
layout.ty,
153-
fx.cx.vtables.len(),
154-
),
155-
Linkage::Local,
156-
false,
157-
false,
158-
)
159-
.unwrap();
160-
161-
// FIXME don't duplicate definitions in lazy jit mode
162-
let _ = fx.cx.module.define_data(data_id, &data_ctx);
142+
let data_id = fx.cx.module.declare_anonymous_data(false, false).unwrap();
143+
144+
fx.cx.module.define_data(data_id, &data_ctx).unwrap();
163145

164146
data_id
165147
}

0 commit comments

Comments
 (0)