see struct_llfields in librustc_codegen_llvm for implementation hints
(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>)
| 698 | |
| 699 | // see struct_llfields in librustc_codegen_llvm for implementation hints |
| 700 | fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) -> Word { |
| 701 | let size = if ty.is_unsized() { None } else { Some(ty.size) }; |
| 702 | let align = ty.align.abi; |
| 703 | // FIXME(eddyb) use `AccumulateVec`s just like `rustc` itself does. |
| 704 | let mut field_types = Vec::new(); |
| 705 | let mut field_offsets = Vec::new(); |
| 706 | let mut field_names = Vec::new(); |
| 707 | for i in ty.fields.index_by_increasing_offset() { |
| 708 | let field_ty = ty.field(cx, i); |
| 709 | field_types.push(field_ty.spirv_type(span, cx)); |
| 710 | let offset = ty.fields.offset(i); |
| 711 | field_offsets.push(offset); |
| 712 | if let Variants::Single { index } = ty.variants { |
| 713 | if let TyKind::Adt(adt, _) = ty.ty.kind() { |
| 714 | let field = &adt.variants()[index].fields[i.into()]; |
| 715 | field_names.push(field.name); |
| 716 | } else { |
| 717 | // FIXME(eddyb) this looks like something that should exist in rustc. |
| 718 | field_names.push(Symbol::intern(&format!("{i}"))); |
| 719 | } |
| 720 | } else { |
| 721 | if let TyKind::Adt(_, _) = ty.ty.kind() { |
| 722 | } else { |
| 723 | span_bug!(span, "Variants::Multiple not TyKind::Adt"); |
| 724 | } |
| 725 | if i == 0 { |
| 726 | field_names.push(cx.sym.discriminant); |
| 727 | } else { |
| 728 | cx.tcx.sess.fatal("Variants::Multiple has multiple fields") |
| 729 | } |
| 730 | }; |
| 731 | } |
| 732 | SpirvType::Adt { |
| 733 | def_id: def_id_for_spirv_type_adt(ty), |
| 734 | size, |
| 735 | align, |
| 736 | field_types: &field_types, |
| 737 | field_offsets: &field_offsets, |
| 738 | field_names: Some(&field_names), |
| 739 | } |
| 740 | .def_with_name(cx, span, TyLayoutNameKey::from(ty)) |
| 741 | } |
| 742 | |
| 743 | /// Grab a `DefId` from the type if possible to avoid too much deduplication, |
| 744 | /// which could result in one SPIR-V `OpType*` having many names |
no test coverage detected