From 1f4870ff1c8e2c2a5d4a0d73fc2b1c196b395f3e Mon Sep 17 00:00:00 2001 From: feniljain Date: Thu, 26 May 2022 16:05:25 +0530 Subject: [PATCH] fix: f32 and f64 representation during lowering --- crates/hir-def/src/body/lower.rs | 11 +++-- crates/hir-def/src/expr.rs | 23 ++++++++++- crates/ide/src/hover/tests.rs | 66 ++++++++++++++++++++++++++++++ crates/syntax/src/ast/token_ext.rs | 42 ++++++++++++++++--- 4 files changed, 132 insertions(+), 10 deletions(-) diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs index 0f9f0e0e1c5..5d7a1100cd5 100644 --- a/crates/hir-def/src/body/lower.rs +++ b/crates/hir-def/src/body/lower.rs @@ -29,8 +29,8 @@ use crate::{ builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint}, db::DefDatabase, expr::{ - dummy_expr_id, Array, BindingAnnotation, Expr, ExprId, Label, LabelId, Literal, MatchArm, - Pat, PatId, RecordFieldPat, RecordLitField, Statement, + dummy_expr_id, Array, BindingAnnotation, Expr, ExprId, FloatTypeWrapper, Label, LabelId, + Literal, MatchArm, Pat, PatId, RecordFieldPat, RecordLitField, Statement, }, intern::Interned, item_scope::BuiltinShadowMode, @@ -968,7 +968,10 @@ impl From for Literal { // FIXME: these should have actual values filled in, but unsure on perf impact LiteralKind::IntNumber(lit) => { if let builtin @ Some(_) = lit.suffix().and_then(BuiltinFloat::from_suffix) { - Literal::Float(Default::default(), builtin) + Literal::Float( + FloatTypeWrapper::new(lit.float_value().unwrap_or(Default::default())), + builtin, + ) } else if let builtin @ Some(_) = lit.suffix().and_then(BuiltinInt::from_suffix) { Literal::Int(lit.value().unwrap_or(0) as i128, builtin) } else { @@ -978,7 +981,7 @@ impl From for Literal { } LiteralKind::FloatNumber(lit) => { let ty = lit.suffix().and_then(BuiltinFloat::from_suffix); - Literal::Float(Default::default(), ty) + Literal::Float(FloatTypeWrapper::new(lit.value().unwrap_or(Default::default())), ty) } LiteralKind::ByteString(bs) => { let text = bs.value().map(Box::from).unwrap_or_else(Default::default); diff --git a/crates/hir-def/src/expr.rs b/crates/hir-def/src/expr.rs index fd09e651c99..97681abab1f 100644 --- a/crates/hir-def/src/expr.rs +++ b/crates/hir-def/src/expr.rs @@ -38,6 +38,24 @@ pub struct Label { } pub type LabelId = Idx