Skip to content

Commit

Permalink
Auto merge of #811 - beetrees:f16-f128, r=jackh726
Browse files Browse the repository at this point in the history
Add `f16` and `f128`

Needed for rust-lang/rust-analyzer#17451.
  • Loading branch information
bors committed Jun 24, 2024
2 parents ee7f299 + 4f08b97 commit 77406aa
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,10 @@ impl Lower for FloatTy {

fn lower(&self) -> Self::Lowered {
match self {
FloatTy::F16 => chalk_ir::FloatTy::F16,
FloatTy::F32 => chalk_ir::FloatTy::F32,
FloatTy::F64 => chalk_ir::FloatTy::F64,
FloatTy::F128 => chalk_ir::FloatTy::F128,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions chalk-ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@ pub enum UintTy {
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[allow(missing_docs)]
pub enum FloatTy {
F16,
F32,
F64,
F128,
}

/// Types of scalar values.
Expand Down
2 changes: 2 additions & 0 deletions chalk-parse/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@ pub enum UintTy {

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum FloatTy {
F16,
F32,
F64,
F128,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions chalk-parse/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,10 @@ UintTy: UintTy = {
};

FloatTy: FloatTy = {
"f16" => FloatTy::F16,
"f32" => FloatTy::F32,
"f64" => FloatTy::F64,
"f128" => FloatTy::F128,
};

ScalarType: ScalarType = {
Expand Down
2 changes: 2 additions & 0 deletions chalk-solve/src/display/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ impl<I: Interner> RenderAsRust<I> for Scalar {
U128 => "u128",
},
Scalar::Float(float) => match float {
F16 => "f16",
F32 => "f32",
F64 => "f64",
F128 => "f128",
},
}
)
Expand Down
2 changes: 1 addition & 1 deletion tests/display/built_ins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn test_scalar_types() {
// words, test the matrix of {every scalar} x {concrete type usages}. This
// test should be updated to include new scalars, but it isn't super
// important that it includes every place a concrete type can be used.
let basic = &["bool", "char", "f32", "f64"];
let basic = &["bool", "char", "f16", "f32", "f64", "f128"];
let ints = {
let prefixes = &["u", "i"];
let sizes = &["size", "8", "16", "32", "64", "128"];
Expand Down
2 changes: 2 additions & 0 deletions tests/lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,10 @@ fn scalars() {
impl Foo for u64 { }
impl Foo for u128 { }
impl Foo for usize { }
impl Foo for f16 { }
impl Foo for f32 { }
impl Foo for f64 { }
impl Foo for f128 { }
impl Foo for bool { }
impl Foo for char { }
}
Expand Down
10 changes: 10 additions & 0 deletions tests/test/scalars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ fn scalar_trait_impl() {
impl Foo for u64 { }
impl Foo for u128 { }
impl Foo for usize { }
impl Foo for f16 { }
impl Foo for f32 { }
impl Foo for f64 { }
impl Foo for f128 { }
impl Foo for bool { }
impl Foo for char { }

Expand All @@ -88,8 +90,10 @@ fn scalar_trait_impl() {
goal { u64: Foo } yields { expect![["Unique"]] }
goal { u128: Foo } yields { expect![["Unique"]] }
goal { usize: Foo } yields { expect![["Unique"]] }
goal { f16: Foo } yields { expect![["Unique"]] }
goal { f32: Foo } yields { expect![["Unique"]] }
goal { f64: Foo } yields { expect![["Unique"]] }
goal { f128: Foo } yields { expect![["Unique"]] }
goal { bool: Foo } yields { expect![["Unique"]] }
goal { char: Foo } yields { expect![["Unique"]] }

Expand All @@ -105,8 +109,10 @@ fn scalar_trait_impl() {
goal { u64: UnsignedFoo } yields { expect![["Unique"]] }
goal { u128: UnsignedFoo } yields { expect![["Unique"]] }
goal { usize: UnsignedFoo } yields { expect![["Unique"]] }
goal { f16: UnsignedFoo } yields { expect![["No possible solution"]] }
goal { f32: UnsignedFoo } yields { expect![["No possible solution"]] }
goal { f64: UnsignedFoo } yields { expect![["No possible solution"]] }
goal { f128: UnsignedFoo } yields { expect![["No possible solution"]] }
goal { bool: UnsignedFoo } yields { expect![["No possible solution"]] }
goal { char: UnsignedFoo } yields { expect![["No possible solution"]] }

Expand All @@ -128,8 +134,10 @@ fn scalars_are_well_formed() {
goal { WellFormed(u64) } yields { expect![["Unique"]] }
goal { WellFormed(u128) } yields { expect![["Unique"]] }
goal { WellFormed(usize) } yields { expect![["Unique"]] }
goal { WellFormed(f16) } yields { expect![["Unique"]] }
goal { WellFormed(f32) } yields { expect![["Unique"]] }
goal { WellFormed(f64) } yields { expect![["Unique"]] }
goal { WellFormed(f128) } yields { expect![["Unique"]] }
goal { WellFormed(bool) } yields { expect![["Unique"]] }
goal { WellFormed(char) } yields { expect![["Unique"]] }
}
Expand All @@ -154,8 +162,10 @@ fn scalars_are_sized() {
goal { u64: Sized } yields { expect![["Unique"]] }
goal { u128: Sized } yields { expect![["Unique"]] }
goal { usize: Sized } yields { expect![["Unique"]] }
goal { f16: Sized } yields { expect![["Unique"]] }
goal { f32: Sized } yields { expect![["Unique"]] }
goal { f64: Sized } yields { expect![["Unique"]] }
goal { f128: Sized } yields { expect![["Unique"]] }
goal { bool: Sized } yields { expect![["Unique"]] }
goal { char: Sized } yields { expect![["Unique"]] }
}
Expand Down

0 comments on commit 77406aa

Please sign in to comment.