Skip to content

Commit d34be93

Browse files
Prevent creating the same Instance::mono multiple times
1 parent ad18fe0 commit d34be93

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ impl<'ll> CodegenCx<'ll, '_> {
246246

247247
#[instrument(level = "debug", skip(self, llty))]
248248
pub(crate) fn get_static_inner(&self, def_id: DefId, llty: &'ll Type) -> &'ll Value {
249-
if let Some(&g) = self.instances.borrow().get(&Instance::mono(self.tcx, def_id)) {
249+
let instance = Instance::mono(self.tcx, def_id);
250+
if let Some(&g) = self.instances.borrow().get(&instance) {
250251
trace!("used cached value");
251252
return g;
252253
}
@@ -259,7 +260,7 @@ impl<'ll> CodegenCx<'ll, '_> {
259260
statics defined in the same CGU, but did not for `{def_id:?}`"
260261
);
261262

262-
let sym = self.tcx.symbol_name(Instance::mono(self.tcx, def_id)).name;
263+
let sym = self.tcx.symbol_name(instance).name;
263264
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
264265

265266
debug!(?sym, ?fn_attrs);
@@ -349,7 +350,7 @@ impl<'ll> CodegenCx<'ll, '_> {
349350
}
350351
}
351352

352-
self.instances.borrow_mut().insert(Instance::mono(self.tcx, def_id), g);
353+
self.instances.borrow_mut().insert(instance, g);
353354
g
354355
}
355356

0 commit comments

Comments
 (0)