- /*let def_id = instance.def_id();
- let containing_scope = get_containing_scope(self, instance);
- let span = self.tcx.def_span(def_id);
- let loc = self.lookup_debug_loc(span.lo());
- let file_metadata = file_metadata(self, &loc.file);
-
- let function_type_metadata = unsafe {
- let fn_signature = get_function_signature(self, fn_abi);
- llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(self), fn_signature)
- };
-
- // Find the enclosing function, in case this is a closure.
- let def_key = self.tcx().def_key(def_id);
- let mut name = def_key.disambiguated_data.data.to_string();
-
- let enclosing_fn_def_id = self.tcx().closure_base_def_id(def_id);
-
- // Get_template_parameters() will append a `<...>` clause to the function
- // name if necessary.
- let generics = self.tcx().generics_of(enclosing_fn_def_id);
- let substs = instance.substs.truncate_to(self.tcx(), generics);
- let template_parameters = get_template_parameters(self, &generics, substs, &mut name);
-
- let linkage_name = &mangled_name_of_instance(self, instance).name;
- // Omit the linkage_name if it is the same as subprogram name.
- let linkage_name = if &name == linkage_name { "" } else { linkage_name };
-
- // FIXME(eddyb) does this need to be separate from `loc.line` for some reason?
- let scope_line = loc.line;
-
- let mut flags = DIFlags::FlagPrototyped;
-
- if fn_abi.ret.layout.abi.is_uninhabited() {
- flags |= DIFlags::FlagNoReturn;
- }
-
- let mut spflags = DISPFlags::SPFlagDefinition;
- if is_node_local_to_unit(self, def_id) {
- spflags |= DISPFlags::SPFlagLocalToUnit;
- }
- if self.sess().opts.optimize != config::OptLevel::No {
- spflags |= DISPFlags::SPFlagOptimized;
- }
- if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) {
- if id.to_def_id() == def_id {
- spflags |= DISPFlags::SPFlagMainSubprogram;
- }
- }
-
- unsafe {
- return llvm::LLVMRustDIBuilderCreateFunction(
- DIB(self),
- containing_scope,
- name.as_ptr().cast(),
- name.len(),
- linkage_name.as_ptr().cast(),
- linkage_name.len(),
- file_metadata,
- loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
- function_type_metadata,
- scope_line.unwrap_or(UNKNOWN_LINE_NUMBER),
- flags,
- spflags,
- maybe_definition_llfn,
- template_parameters,
- None,
- );
- }
-
- fn get_function_signature<'ll, 'tcx>(
- cx: &CodegenCx<'ll, 'tcx>,
- fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
- ) -> &'ll DIArray {
- if cx.sess().opts.debuginfo == DebugInfo::Limited {
- return create_DIArray(DIB(cx), &[]);
- }
-
- let mut signature = Vec::with_capacity(fn_abi.args.len() + 1);
-
- // Return type -- llvm::DIBuilder wants this at index 0
- signature.push(if fn_abi.ret.is_ignore() {
- None
- } else {
- Some(type_metadata(cx, fn_abi.ret.layout.ty, rustc_span::DUMMY_SP))
- });
-
- // Arguments types
- if cx.sess().target.options.is_like_msvc {
- // FIXME(#42800):
- // There is a bug in MSDIA that leads to a crash when it encounters
- // a fixed-size array of `u8` or something zero-sized in a
- // function-type (see #40477).
- // As a workaround, we replace those fixed-size arrays with a
- // pointer-type. So a function `fn foo(a: u8, b: [u8; 4])` would
- // appear as `fn foo(a: u8, b: *const u8)` in debuginfo,
- // and a function `fn bar(x: [(); 7])` as `fn bar(x: *const ())`.
- // This transformed type is wrong, but these function types are
- // already inaccurate due to ABI adjustments (see #42800).
- signature.extend(fn_abi.args.iter().map(|arg| {
- let t = arg.layout.ty;
- let t = match t.kind() {
- ty::Array(ct, _)
- if (*ct == cx.tcx.types.u8) || cx.layout_of(ct).is_zst() =>
- {
- cx.tcx.mk_imm_ptr(ct)
- }
- _ => t,
- };
- Some(type_metadata(cx, t, rustc_span::DUMMY_SP))
- }));
- } else {
- signature.extend(
- fn_abi
- .args
- .iter()
- .map(|arg| Some(type_metadata(cx, arg.layout.ty, rustc_span::DUMMY_SP))),
- );
- }
-
- create_DIArray(DIB(cx), &signature[..])
- }
-
- fn get_template_parameters<'ll, 'tcx>(
- cx: &CodegenCx<'ll, 'tcx>,
- generics: &ty::Generics,
- substs: SubstsRef<'tcx>,
- name_to_append_suffix_to: &mut String,
- ) -> &'ll DIArray {
- if substs.types().next().is_none() {
- return create_DIArray(DIB(cx), &[]);
- }
-
- name_to_append_suffix_to.push('<');
- for (i, actual_type) in substs.types().enumerate() {
- if i != 0 {
- name_to_append_suffix_to.push(',');
- }
-
- let actual_type =
- cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), actual_type);
- // Add actual type name to <...> clause of function name
- let actual_type_name = compute_debuginfo_type_name(cx.tcx(), actual_type, true);
- name_to_append_suffix_to.push_str(&actual_type_name[..]);
- }
- name_to_append_suffix_to.push('>');
-
- // Again, only create type information if full debuginfo is enabled
- let template_params: Vec<_> = if cx.sess().opts.debuginfo == DebugInfo::Full {
- let names = get_parameter_names(cx, generics);
- substs
- .iter()
- .zip(names)
- .filter_map(|(kind, name)| {
- if let GenericArgKind::Type(ty) = kind.unpack() {
- let actual_type =
- cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
- let actual_type_metadata =
- type_metadata(cx, actual_type, rustc_span::DUMMY_SP);
- let name = name.as_str();
- Some(unsafe {
- Some(llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
- DIB(cx),
- None,
- name.as_ptr().cast(),
- name.len(),
- actual_type_metadata,
- ))
- })
- } else {
- None
- }
- })
- .collect()
- } else {
- vec![]
- };
-
- create_DIArray(DIB(cx), &template_params[..])
- }
-
- fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
- let mut names = generics
- .parent
- .map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
- names.extend(generics.params.iter().map(|param| param.name));
- names
- }
-
- fn get_containing_scope<'ll, 'tcx>(
- cx: &CodegenCx<'ll, 'tcx>,
- instance: Instance<'tcx>,
- ) -> &'ll DIScope {
- // First, let's see if this is a method within an inherent impl. Because
- // if yes, we want to make the result subroutine DIE a child of the
- // subroutine's self-type.
- let self_type = cx.tcx.impl_of_method(instance.def_id()).and_then(|impl_def_id| {
- // If the method does *not* belong to a trait, proceed
- if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
- let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
- instance.substs,
- ty::ParamEnv::reveal_all(),
- &cx.tcx.type_of(impl_def_id),
- );
-
- // Only "class" methods are generally understood by LLVM,
- // so avoid methods on other types (e.g., `<*mut T>::null`).
- match impl_self_ty.kind() {
- ty::Adt(def, ..) if !def.is_box() => {
- // Again, only create type information if full debuginfo is enabled
- if cx.sess().opts.debuginfo == DebugInfo::Full
- && !impl_self_ty.needs_subst()
- {
- Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP))
- } else {
- Some(namespace::item_namespace(cx, def.did))
- }
- }
- _ => None,
- }
- } else {
- // For trait method impls we still use the "parallel namespace"
- // strategy
- None
- }
- });
-
- self_type.unwrap_or_else(|| {
- namespace::item_namespace(
- cx,
- DefId {
- krate: instance.def_id().krate,
- index: cx
- .tcx
- .def_key(instance.def_id())
- .parent
- .expect("get_containing_scope: missing parent?"),
- },
- )
- })
- }*/