MCPcopy Create free account
hub / github.com/IntegralPilot/rustc_codegen_jvm / sanitize_class_segment

Function sanitize_class_segment

src/lower1/naming.rs:150–210  ·  view source on GitHub ↗
(seg: &str)

Source from the content-addressed store, hash-verified

148 link_name
149 };
150 validate_jvm_internal_class_name(class_name)?;
151 Ok(class_name.to_string())
152}
153
154pub fn mono_owner_class<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> String {
155 let def_id = instance.def_id();
156 // The runtime polls an async body through a carrier companion, independently of
157 // crate/module layout and generic method-holder partitioning.
158 if matches!(tcx.def_kind(def_id), DefKind::Closure) && tcx.coroutine_is_async(def_id) {
159 return format!(
160 "{}$Body",
161 jvm_names::anonymous_class_for_args(tcx, def_id, instance.args, true)
162 );
163 }
164 if tcx.generics_of(def_id).requires_monomorphization(tcx) {
165 // Definition-crate ownership agrees across all downstream emitters.
166 let identity = super::types::stable_instance_identity(tcx, def_id, instance.args);
167 generic_mono_owner(tcx, def_id, &identity)
168 } else if let Some(trait_def_id) = tcx
169 .opt_associated_item(def_id)
170 .and_then(|item| item.trait_container(tcx))
171 {
172 // A Java interface carries its dynamically dispatched method, but
173 // monomorphized Rust default bodies are static functions. Put those
174 // bodies beside the trait in its module rather than generating a
175 // second class file for the interface name.
176 jvm_names::owner_class_for_function(tcx, trait_def_id)
177 } else {
178 jvm_names::owner_class_for_function(tcx, def_id)
179 }
180}
181
182fn generic_mono_owner(tcx: TyCtxt<'_>, def_id: DefId, identity: &str) -> String {
183 // Bound class-header and ZIP-entry overhead without concentrating a whole
184 // module's specializations in one constant pool. The linker splits any
185 // bucket that still overflows; method identities remain independent of it.
186 format!(
187 "{}/mono/Mono_{}",
188 jvm_names::crate_root(tcx, def_id.krate),
189 &identity[..3],
190 )
191}
192
193/// Whether a static body belongs to a Java interface, including nested
194/// closures and coroutines whose immediate `DefId` is not an associated item.
195pub fn instance_is_trait_interface_owned<'tcx>(
196 tcx: TyCtxt<'tcx>,
197 instance: Instance<'tcx>,
198 owner_class: &str,
199) -> bool {
200 let mut current = Some(instance.def_id());
201 while let Some(def_id) = current {
202 let trait_def_id = matches!(tcx.def_kind(def_id), DefKind::Trait)
203 .then_some(def_id)
204 .or_else(|| {
205 tcx.opt_associated_item(def_id)
206 .and_then(|item| item.trait_container(tcx))
207 });

Callers 1

owner_class_from_pathFunction · 0.85

Calls 3

make_jvm_safeFunction · 0.85
lenMethod · 0.80
starts_withMethod · 0.45

Tested by

no test coverage detected