diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-04-19 23:09:57 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-04-19 23:13:58 +0200 |
| commit | d34be935ecdcd24d9623ceb32e3cb3e40996524c (patch) | |
| tree | 67a19beff5fbbc08fcdcaab0ad68acf3b803a184 | |
| parent | ad18fe08de03fbb459c05475bddee22707b4f0ec (diff) | |
| download | rust-d34be935ecdcd24d9623ceb32e3cb3e40996524c.tar.gz rust-d34be935ecdcd24d9623ceb32e3cb3e40996524c.zip | |
Prevent creating the same `Instance::mono` multiple times
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/consts.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 4afa230e598..3e0597b1a76 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -246,7 +246,8 @@ impl<'ll> CodegenCx<'ll, '_> { #[instrument(level = "debug", skip(self, llty))] pub(crate) fn get_static_inner(&self, def_id: DefId, llty: &'ll Type) -> &'ll Value { - if let Some(&g) = self.instances.borrow().get(&Instance::mono(self.tcx, def_id)) { + let instance = Instance::mono(self.tcx, def_id); + if let Some(&g) = self.instances.borrow().get(&instance) { trace!("used cached value"); return g; } @@ -259,7 +260,7 @@ impl<'ll> CodegenCx<'ll, '_> { statics defined in the same CGU, but did not for `{def_id:?}`" ); - let sym = self.tcx.symbol_name(Instance::mono(self.tcx, def_id)).name; + let sym = self.tcx.symbol_name(instance).name; let fn_attrs = self.tcx.codegen_fn_attrs(def_id); debug!(?sym, ?fn_attrs); @@ -349,7 +350,7 @@ impl<'ll> CodegenCx<'ll, '_> { } } - self.instances.borrow_mut().insert(Instance::mono(self.tcx, def_id), g); + self.instances.borrow_mut().insert(instance, g); g } |
