Skip to content

Commit ea7057a

Browse files
committed
Don't deduplicate vtables between functions
1 parent 53bfc67 commit ea7057a

File tree

6 files changed

+14
-23
lines changed

6 files changed

+14
-23
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

@@ -156,7 +158,7 @@ pub(crate) fn codegen_fn<'tcx>(cx: &mut crate::CodegenCx<'_, 'tcx>, instance: In
156158
debug_context.define_function(
157159
instance,
158160
func_id,
159-
&name,
161+
symbol_name.name,
160162
isa,
161163
context,
162164
&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-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
9393
let inline_asm_index = fx.inline_asm_index;
9494
fx.inline_asm_index += 1;
9595
let asm_name =
96-
format!("{}__inline_asm_{}", fx.tcx.symbol_name(fx.instance).name, inline_asm_index);
96+
format!("{}__inline_asm_{}", fx.symbol_name, inline_asm_index);
9797

9898
let generated_asm = generate_asm_wrapper(
9999
&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

+4-15
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

@@ -142,24 +142,13 @@ fn build_vtable<'tcx>(
142142
let data_id = fx
143143
.cx
144144
.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,
145+
.declare_anonymous_data(
156146
false,
157147
false,
158148
)
159149
.unwrap();
160150

161-
// FIXME don't duplicate definitions in lazy jit mode
162-
let _ = fx.cx.module.define_data(data_id, &data_ctx);
151+
fx.cx.module.define_data(data_id, &data_ctx).unwrap();
163152

164153
data_id
165154
}

0 commit comments

Comments
 (0)