Skip to content

Commit bfef261

Browse files
committed
Reorder ConstMethods.
It's crazy to have the integer methods in something close to random order. The reordering makes the gaps clear: `const_i64`, `const_i128`, `const_isize`, and `const_u16`. I guess they just aren't needed.
1 parent fda530d commit bfef261

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

compiler/rustc_codegen_gcc/src/common.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,14 @@ impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
8080
self.const_undef(typ)
8181
}
8282

83-
fn const_int(&self, typ: Type<'gcc>, int: i64) -> RValue<'gcc> {
84-
self.gcc_int(typ, int)
85-
}
86-
87-
fn const_uint(&self, typ: Type<'gcc>, int: u64) -> RValue<'gcc> {
88-
self.gcc_uint(typ, int)
89-
}
90-
91-
fn const_uint_big(&self, typ: Type<'gcc>, num: u128) -> RValue<'gcc> {
92-
self.gcc_uint_big(typ, num)
93-
}
94-
9583
fn const_bool(&self, val: bool) -> RValue<'gcc> {
9684
self.const_uint(self.type_i1(), val as u64)
9785
}
9886

87+
fn const_i8(&self, i: i8) -> RValue<'gcc> {
88+
self.const_int(self.type_i8(), i as i64)
89+
}
90+
9991
fn const_i16(&self, i: i16) -> RValue<'gcc> {
10092
self.const_int(self.type_i16(), i as i64)
10193
}
@@ -104,8 +96,12 @@ impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
10496
self.const_int(self.type_i32(), i as i64)
10597
}
10698

107-
fn const_i8(&self, i: i8) -> RValue<'gcc> {
108-
self.const_int(self.type_i8(), i as i64)
99+
fn const_int(&self, typ: Type<'gcc>, int: i64) -> RValue<'gcc> {
100+
self.gcc_int(typ, int)
101+
}
102+
103+
fn const_u8(&self, i: u8) -> RValue<'gcc> {
104+
self.const_uint(self.type_u8(), i as u64)
109105
}
110106

111107
fn const_u32(&self, i: u32) -> RValue<'gcc> {
@@ -130,8 +126,12 @@ impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
130126
self.const_uint(self.usize_type, i)
131127
}
132128

133-
fn const_u8(&self, i: u8) -> RValue<'gcc> {
134-
self.const_uint(self.type_u8(), i as u64)
129+
fn const_uint(&self, typ: Type<'gcc>, int: u64) -> RValue<'gcc> {
130+
self.gcc_uint(typ, int)
131+
}
132+
133+
fn const_uint_big(&self, typ: Type<'gcc>, num: u128) -> RValue<'gcc> {
134+
self.gcc_uint_big(typ, num)
135135
}
136136

137137
fn const_real(&self, typ: Type<'gcc>, val: f64) -> RValue<'gcc> {

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,14 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
126126
unsafe { llvm::LLVMGetPoison(t) }
127127
}
128128

129-
fn const_int(&self, t: &'ll Type, i: i64) -> &'ll Value {
130-
unsafe { llvm::LLVMConstInt(t, i as u64, True) }
131-
}
132-
133-
fn const_uint(&self, t: &'ll Type, i: u64) -> &'ll Value {
134-
unsafe { llvm::LLVMConstInt(t, i, False) }
135-
}
136-
137-
fn const_uint_big(&self, t: &'ll Type, u: u128) -> &'ll Value {
138-
unsafe {
139-
let words = [u as u64, (u >> 64) as u64];
140-
llvm::LLVMConstIntOfArbitraryPrecision(t, 2, words.as_ptr())
141-
}
142-
}
143-
144129
fn const_bool(&self, val: bool) -> &'ll Value {
145130
self.const_uint(self.type_i1(), val as u64)
146131
}
147132

133+
fn const_i8(&self, i: i8) -> &'ll Value {
134+
self.const_int(self.type_i8(), i as i64)
135+
}
136+
148137
fn const_i16(&self, i: i16) -> &'ll Value {
149138
self.const_int(self.type_i16(), i as i64)
150139
}
@@ -153,8 +142,12 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
153142
self.const_int(self.type_i32(), i as i64)
154143
}
155144

156-
fn const_i8(&self, i: i8) -> &'ll Value {
157-
self.const_int(self.type_i8(), i as i64)
145+
fn const_int(&self, t: &'ll Type, i: i64) -> &'ll Value {
146+
unsafe { llvm::LLVMConstInt(t, i as u64, True) }
147+
}
148+
149+
fn const_u8(&self, i: u8) -> &'ll Value {
150+
self.const_uint(self.type_i8(), i as u64)
158151
}
159152

160153
fn const_u32(&self, i: u32) -> &'ll Value {
@@ -179,8 +172,15 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
179172
self.const_uint(self.isize_ty, i)
180173
}
181174

182-
fn const_u8(&self, i: u8) -> &'ll Value {
183-
self.const_uint(self.type_i8(), i as u64)
175+
fn const_uint(&self, t: &'ll Type, i: u64) -> &'ll Value {
176+
unsafe { llvm::LLVMConstInt(t, i, False) }
177+
}
178+
179+
fn const_uint_big(&self, t: &'ll Type, u: u128) -> &'ll Value {
180+
unsafe {
181+
let words = [u as u64, (u >> 64) as u64];
182+
llvm::LLVMConstIntOfArbitraryPrecision(t, 2, words.as_ptr())
183+
}
184184
}
185185

186186
fn const_real(&self, t: &'ll Type, val: f64) -> &'ll Value {

compiler/rustc_codegen_ssa/src/traits/consts.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ pub trait ConstCodegenMethods<'tcx>: BackendTypes {
1414
/// (including code that e.g. copies uninit memory with `MaybeUninit`) can never encounter a
1515
/// poison value.
1616
fn const_poison(&self, t: Self::Type) -> Self::Value;
17-
fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
18-
fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value;
19-
fn const_uint_big(&self, t: Self::Type, u: u128) -> Self::Value;
17+
2018
fn const_bool(&self, val: bool) -> Self::Value;
19+
20+
fn const_i8(&self, i: i8) -> Self::Value;
2121
fn const_i16(&self, i: i16) -> Self::Value;
2222
fn const_i32(&self, i: i32) -> Self::Value;
23-
fn const_i8(&self, i: i8) -> Self::Value;
23+
fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
24+
fn const_u8(&self, i: u8) -> Self::Value;
2425
fn const_u32(&self, i: u32) -> Self::Value;
2526
fn const_u64(&self, i: u64) -> Self::Value;
2627
fn const_u128(&self, i: u128) -> Self::Value;
2728
fn const_usize(&self, i: u64) -> Self::Value;
28-
fn const_u8(&self, i: u8) -> Self::Value;
29+
fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value;
30+
fn const_uint_big(&self, t: Self::Type, u: u128) -> Self::Value;
2931
fn const_real(&self, t: Self::Type, val: f64) -> Self::Value;
3032

3133
fn const_str(&self, s: &str) -> (Self::Value, Self::Value);

0 commit comments

Comments
 (0)