Skip to content

Commit 16c6fbc

Browse files
committed
Remove inherent methods from llvm::TypeKind
1 parent 4a54b26 commit 16c6fbc

File tree

3 files changed

+40
-29
lines changed

3 files changed

+40
-29
lines changed

compiler/rustc_codegen_llvm/src/llvm/conversions.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Conversions from backend-independent data types to/from LLVM FFI types.
22
3-
use rustc_codegen_ssa::common::{AtomicRmwBinOp, IntPredicate, RealPredicate};
3+
use rustc_codegen_ssa::common::{AtomicRmwBinOp, IntPredicate, RealPredicate, TypeKind};
44
use rustc_middle::ty::AtomicOrdering;
55
use rustc_session::config::DebugInfo;
66
use rustc_target::spec::SymbolVisibility;
@@ -9,10 +9,22 @@ use crate::llvm;
99

1010
/// Helper trait for converting backend-independent types to LLVM-specific
1111
/// types, for FFI purposes.
12+
///
13+
/// FIXME(#147327): These trait/method names were chosen to avoid churn in
14+
/// existing code, but are not great and could probably be made clearer.
1215
pub(crate) trait FromGeneric<T> {
1316
fn from_generic(other: T) -> Self;
1417
}
1518

19+
/// Helper trait for converting LLVM-specific types to backend-independent
20+
/// types, for FFI purposes.
21+
///
22+
/// FIXME(#147327): These trait/method names were chosen to avoid churn in
23+
/// existing code, but are not great and could probably be made clearer.
24+
pub(crate) trait ToGeneric<T> {
25+
fn to_generic(&self) -> T;
26+
}
27+
1628
impl FromGeneric<SymbolVisibility> for llvm::Visibility {
1729
fn from_generic(visibility: SymbolVisibility) -> Self {
1830
match visibility {
@@ -113,3 +125,29 @@ impl FromGeneric<DebugInfo> for llvm::debuginfo::DebugEmissionKind {
113125
}
114126
}
115127
}
128+
129+
impl ToGeneric<TypeKind> for llvm::TypeKind {
130+
fn to_generic(&self) -> TypeKind {
131+
match self {
132+
Self::Void => TypeKind::Void,
133+
Self::Half => TypeKind::Half,
134+
Self::Float => TypeKind::Float,
135+
Self::Double => TypeKind::Double,
136+
Self::X86_FP80 => TypeKind::X86_FP80,
137+
Self::FP128 => TypeKind::FP128,
138+
Self::PPC_FP128 => TypeKind::PPC_FP128,
139+
Self::Label => TypeKind::Label,
140+
Self::Integer => TypeKind::Integer,
141+
Self::Function => TypeKind::Function,
142+
Self::Struct => TypeKind::Struct,
143+
Self::Array => TypeKind::Array,
144+
Self::Pointer => TypeKind::Pointer,
145+
Self::Vector => TypeKind::Vector,
146+
Self::Metadata => TypeKind::Metadata,
147+
Self::Token => TypeKind::Token,
148+
Self::ScalableVector => TypeKind::ScalableVector,
149+
Self::BFloat => TypeKind::BFloat,
150+
Self::X86_AMX => TypeKind::X86_AMX,
151+
}
152+
}
153+
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -360,33 +360,6 @@ pub(crate) enum TypeKind {
360360
X86_AMX = 19,
361361
}
362362

363-
impl TypeKind {
364-
pub(crate) fn to_generic(self) -> rustc_codegen_ssa::common::TypeKind {
365-
use rustc_codegen_ssa::common::TypeKind as Common;
366-
match self {
367-
Self::Void => Common::Void,
368-
Self::Half => Common::Half,
369-
Self::Float => Common::Float,
370-
Self::Double => Common::Double,
371-
Self::X86_FP80 => Common::X86_FP80,
372-
Self::FP128 => Common::FP128,
373-
Self::PPC_FP128 => Common::PPC_FP128,
374-
Self::Label => Common::Label,
375-
Self::Integer => Common::Integer,
376-
Self::Function => Common::Function,
377-
Self::Struct => Common::Struct,
378-
Self::Array => Common::Array,
379-
Self::Pointer => Common::Pointer,
380-
Self::Vector => Common::Vector,
381-
Self::Metadata => Common::Metadata,
382-
Self::Token => Common::Token,
383-
Self::ScalableVector => Common::ScalableVector,
384-
Self::BFloat => Common::BFloat,
385-
Self::X86_AMX => Common::X86_AMX,
386-
}
387-
}
388-
}
389-
390363
/// LLVMAtomicRmwBinOp
391364
#[derive(Copy, Clone)]
392365
#[repr(C)]

compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_target::callconv::{CastTarget, FnAbi};
1515
use crate::abi::{FnAbiLlvmExt, LlvmType};
1616
use crate::context::{CodegenCx, GenericCx, SCx};
1717
pub(crate) use crate::llvm::Type;
18-
use crate::llvm::{FALSE, Metadata, TRUE, ToLlvmBool};
18+
use crate::llvm::{FALSE, Metadata, TRUE, ToGeneric, ToLlvmBool};
1919
use crate::type_of::LayoutLlvmExt;
2020
use crate::value::Value;
2121
use crate::{common, llvm};

0 commit comments

Comments
 (0)