MCPcopy Create free account
hub / github.com/Rust-API/Rust-API-Bypass-Checker / summary_key_str

Function summary_key_str

src/analysis/memory/utils.rs:222–263  ·  view source on GitHub ↗

Constructs a string that uniquely identifies a definition to serve as a key to the summary cache, which is a key value store. The string will always be the same as long as the definition does not change its name or location, so it can be used to transfer information from one compilation to the next, making incremental analysis possible.

(tcx: TyCtxt<'_>, def_id: DefId)

Source from the content-addressed store, hash-verified

220/// long as the definition does not change its name or location, so it can be used to
221/// transfer information from one compilation to the next, making incremental analysis possible.
222pub fn summary_key_str(tcx: TyCtxt<'_>, def_id: DefId) -> Rc<String> {
223 let mut name = crate_name(tcx, def_id);
224 let mut type_ns: Option<String> = None;
225 for component in &tcx.def_path(def_id).data {
226 if name.ends_with("foreign_contracts") {
227 // By stripping off this special prefix, we allow this crate (or module) to define
228 // functions that appear to be from other crates.
229 // We use this to provide contracts for functions defined in crates we do not
230 // wish to modify in place.
231 name.clear();
232 } else if !name.ends_with('.') {
233 name.push('.');
234 }
235 push_component_name(component.data, &mut name);
236 if let DefPathData::TypeNs(sym) = component.data {
237 type_ns = Some(sym.as_str().to_string());
238 }
239 if component.disambiguator != 0 {
240 name.push('_');
241 if component.data == DefPathData::Impl {
242 #[allow(irrefutable_let_patterns)]
243 if let parent_def_id = tcx.parent(def_id) {
244 if let Some(type_ns) = &type_ns {
245 if type_ns == "num"
246 && tcx.crate_name(parent_def_id.krate).as_str() == "core"
247 {
248 append_mangled_type(&mut name, tcx.type_of(parent_def_id).skip_binder(), tcx);
249 continue;
250 }
251 }
252 }
253 if let Some(type_ns) = &type_ns {
254 name.push_str(&type_ns);
255 continue;
256 }
257 }
258 let da = component.disambiguator.to_string();
259 name.push_str(da.as_str());
260 }
261 }
262 Rc::new(name)
263}
264
265
266// fn push_component_name(component_data: DefPathData, target: &mut String) {

Callers 2

for_functionMethod · 0.85
new_staticMethod · 0.85

Calls 4

crate_nameFunction · 0.85
push_component_nameFunction · 0.85
append_mangled_typeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected