forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#120303 - fmease:rollup-to11ql5, r=fmease
Rollup of 10 pull requests Successful merges: - rust-lang#114764 ([style edition 2024] Combine all delimited exprs as last argument) - rust-lang#118326 (Add `NonZero*::count_ones`) - rust-lang#118636 (Add the unstable option to reduce the binary size of dynamic library…) - rust-lang#119460 (coverage: Never emit improperly-ordered coverage regions) - rust-lang#119616 (Add a new `wasm32-wasi-preview2` target) - rust-lang#120185 (coverage: Don't instrument `#[automatically_derived]` functions) - rust-lang#120265 (Remove no-system-llvm) - rust-lang#120284 (privacy: Refactor top-level visiting in `TypePrivacyVisitor`) - rust-lang#120285 (Remove extra # from url in suggestion) - rust-lang#120299 (Add mw to review rotation and add some owner assignments) Failed merges: - rust-lang#120124 (Split assembly tests for ELF and MachO) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
79 changed files
with
824 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::v0; | ||
use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher}; | ||
use rustc_hir::def_id::CrateNum; | ||
use rustc_middle::ty::{Instance, TyCtxt}; | ||
|
||
use std::fmt::Write; | ||
|
||
pub(super) fn mangle<'tcx>( | ||
tcx: TyCtxt<'tcx>, | ||
instance: Instance<'tcx>, | ||
instantiating_crate: Option<CrateNum>, | ||
full_mangling_name: impl FnOnce() -> String, | ||
) -> String { | ||
// The symbol of a generic function may be scattered in multiple downstream dylibs. | ||
// If the symbol of a generic function still contains `crate name`, hash conflicts between the | ||
// generic funcion and other symbols of the same `crate` cannot be detected in time during | ||
// construction. This symbol conflict is left over until it occurs during run time. | ||
// In this case, `instantiating-crate name` is used to replace `crate name` can completely | ||
// eliminate the risk of the preceding potential hash conflict. | ||
let crate_num = | ||
if let Some(krate) = instantiating_crate { krate } else { instance.def_id().krate }; | ||
|
||
let mut symbol = "_RNxC".to_string(); | ||
v0::push_ident(tcx.crate_name(crate_num).as_str(), &mut symbol); | ||
|
||
let hash = tcx.with_stable_hashing_context(|mut hcx| { | ||
let mut hasher = StableHasher::new(); | ||
full_mangling_name().hash_stable(&mut hcx, &mut hasher); | ||
hasher.finish::<Hash64>().as_u64() | ||
}); | ||
|
||
push_hash64(hash, &mut symbol); | ||
|
||
symbol | ||
} | ||
|
||
// The hash is encoded based on `base-62` and the final terminator `_` is removed because it does | ||
// not help prevent hash collisions | ||
fn push_hash64(hash: u64, output: &mut String) { | ||
let hash = v0::encode_integer_62(hash); | ||
let hash_len = hash.len(); | ||
let _ = write!(output, "{hash_len}H{}", &hash[..hash_len - 1]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.