1 #![allow(clippy::float_cmp)]
3 use crate::{clip, is_direct_expn_of, sext, unsext};
4 use if_chain::if_chain;
5 use rustc_ast::ast::{self, LitFloatType, LitKind};
6 use rustc_data_structures::sync::Lrc;
7 use rustc_hir::def::{DefKind, Res};
8 use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp};
9 use rustc_lint::LateContext;
10 use rustc_middle::mir;
11 use rustc_middle::mir::interpret::Scalar;
12 use rustc_middle::ty::SubstsRef;
13 use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt};
14 use rustc_middle::{bug, span_bug};
15 use rustc_span::symbol::Symbol;
16 use std::cmp::Ordering::{self, Equal};
17 use std::hash::{Hash, Hasher};
20 /// A `LitKind`-like enum to fold constant `Expr`s into.
21 #[derive(Debug, Clone)]
23 /// A `String` (e.g., "abc").
25 /// A binary string (e.g., `b"abc"`).
27 /// A single `char` (e.g., `'a'`).
29 /// An integer's bit representation.
35 /// `true` or `false`.
37 /// An array of constants.
39 /// Also an array, but with only one constant, repeated N times.
40 Repeat(Box<Constant>, u64),
41 /// A tuple of constants.
47 /// A literal with syntax error.
51 impl PartialEq for Constant {
52 fn eq(&self, other: &Self) -> bool {
54 (&Self::Str(ref ls), &Self::Str(ref rs)) => ls == rs,
55 (&Self::Binary(ref l), &Self::Binary(ref r)) => l == r,
56 (&Self::Char(l), &Self::Char(r)) => l == r,
57 (&Self::Int(l), &Self::Int(r)) => l == r,
58 (&Self::F64(l), &Self::F64(r)) => {
59 // We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
60 // `Fw32 == Fw64`, so don’t compare them.
61 // `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
62 l.to_bits() == r.to_bits()
64 (&Self::F32(l), &Self::F32(r)) => {
65 // We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
66 // `Fw32 == Fw64`, so don’t compare them.
67 // `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
68 f64::from(l).to_bits() == f64::from(r).to_bits()
70 (&Self::Bool(l), &Self::Bool(r)) => l == r,
71 (&Self::Vec(ref l), &Self::Vec(ref r)) | (&Self::Tuple(ref l), &Self::Tuple(ref r)) => l == r,
72 (&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => ls == rs && lv == rv,
73 (&Self::Ref(ref lb), &Self::Ref(ref rb)) => *lb == *rb,
74 // TODO: are there inter-type equalities?
80 impl Hash for Constant {
81 fn hash<H>(&self, state: &mut H)
85 std::mem::discriminant(self).hash(state);
90 Self::Binary(ref b) => {
100 f64::from(f).to_bits().hash(state);
103 f.to_bits().hash(state);
108 Self::Vec(ref v) | Self::Tuple(ref v) => {
111 Self::Repeat(ref c, l) => {
118 Self::Ref(ref r) => {
127 pub fn partial_cmp(tcx: TyCtxt<'_>, cmp_type: Ty<'_>, left: &Self, right: &Self) -> Option<Ordering> {
128 match (left, right) {
129 (&Self::Str(ref ls), &Self::Str(ref rs)) => Some(ls.cmp(rs)),
130 (&Self::Char(ref l), &Self::Char(ref r)) => Some(l.cmp(r)),
131 (&Self::Int(l), &Self::Int(r)) => match *cmp_type.kind() {
132 ty::Int(int_ty) => Some(sext(tcx, l, int_ty).cmp(&sext(tcx, r, int_ty))),
133 ty::Uint(_) => Some(l.cmp(&r)),
134 _ => bug!("Not an int type"),
136 (&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r),
137 (&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r),
138 (&Self::Bool(ref l), &Self::Bool(ref r)) => Some(l.cmp(r)),
139 (&Self::Tuple(ref l), &Self::Tuple(ref r)) if l.len() == r.len() => match *cmp_type.kind() {
140 ty::Tuple(tys) if tys.len() == l.len() => l
144 .map(|((li, ri), cmp_type)| Self::partial_cmp(tcx, cmp_type, li, ri))
145 .find(|r| r.map_or(true, |o| o != Ordering::Equal))
146 .unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
149 (&Self::Vec(ref l), &Self::Vec(ref r)) => {
150 let cmp_type = match *cmp_type.kind() {
151 ty::Array(ty, _) | ty::Slice(ty) => ty,
155 .map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
156 .find(|r| r.map_or(true, |o| o != Ordering::Equal))
157 .unwrap_or_else(|| Some(l.len().cmp(&r.len())))
159 (&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => {
160 match Self::partial_cmp(
162 match *cmp_type.kind() {
163 ty::Array(ty, _) => ty,
169 Some(Equal) => Some(ls.cmp(rs)),
173 (&Self::Ref(ref lb), &Self::Ref(ref rb)) => Self::partial_cmp(
175 match *cmp_type.kind() {
176 ty::Ref(_, ty, _) => ty,
182 // TODO: are there any useful inter-type orderings?
187 /// Returns the integer value or `None` if `self` or `val_type` is not integer type.
188 pub fn int_value(&self, cx: &LateContext<'_>, val_type: Ty<'_>) -> Option<FullInt> {
189 if let Constant::Int(const_int) = *self {
190 match *val_type.kind() {
191 ty::Int(ity) => Some(FullInt::S(sext(cx.tcx, const_int, ity))),
192 ty::Uint(_) => Some(FullInt::U(const_int)),
201 pub fn peel_refs(mut self) -> Self {
202 while let Constant::Ref(r) = self {
209 /// Parses a `LitKind` to a `Constant`.
210 pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
212 LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
213 LitKind::Byte(b) => Constant::Int(u128::from(b)),
214 LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
215 LitKind::Char(c) => Constant::Char(c),
216 LitKind::Int(n, _) => Constant::Int(n),
217 LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
218 ast::FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
219 ast::FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
221 LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() {
222 ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
223 ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
226 LitKind::Bool(b) => Constant::Bool(b),
227 LitKind::Err => Constant::Err,
231 pub fn constant<'tcx>(
232 lcx: &LateContext<'tcx>,
233 typeck_results: &ty::TypeckResults<'tcx>,
235 ) -> Option<(Constant, bool)> {
236 let mut cx = ConstEvalLateContext {
239 param_env: lcx.param_env,
240 needed_resolution: false,
241 substs: lcx.tcx.intern_substs(&[]),
243 cx.expr(e).map(|cst| (cst, cx.needed_resolution))
246 pub fn constant_simple<'tcx>(
247 lcx: &LateContext<'tcx>,
248 typeck_results: &ty::TypeckResults<'tcx>,
250 ) -> Option<Constant> {
251 constant(lcx, typeck_results, e).and_then(|(cst, res)| if res { None } else { Some(cst) })
254 pub fn constant_full_int<'tcx>(
255 lcx: &LateContext<'tcx>,
256 typeck_results: &ty::TypeckResults<'tcx>,
258 ) -> Option<FullInt> {
259 constant_simple(lcx, typeck_results, e)?.int_value(lcx, typeck_results.expr_ty(e))
262 #[derive(Copy, Clone, Debug, Eq)]
268 impl PartialEq for FullInt {
270 fn eq(&self, other: &Self) -> bool {
271 self.cmp(other) == Ordering::Equal
275 impl PartialOrd for FullInt {
277 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
278 Some(self.cmp(other))
282 impl Ord for FullInt {
284 fn cmp(&self, other: &Self) -> Ordering {
287 fn cmp_s_u(s: i128, u: u128) -> Ordering {
288 u128::try_from(s).map_or(Ordering::Less, |x| x.cmp(&u))
291 match (*self, *other) {
292 (S(s), S(o)) => s.cmp(&o),
293 (U(s), U(o)) => s.cmp(&o),
294 (S(s), U(o)) => cmp_s_u(s, o),
295 (U(s), S(o)) => cmp_s_u(o, s).reverse(),
300 /// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckResults`.
301 pub fn constant_context<'a, 'tcx>(
302 lcx: &'a LateContext<'tcx>,
303 typeck_results: &'a ty::TypeckResults<'tcx>,
304 ) -> ConstEvalLateContext<'a, 'tcx> {
305 ConstEvalLateContext {
308 param_env: lcx.param_env,
309 needed_resolution: false,
310 substs: lcx.tcx.intern_substs(&[]),
314 pub struct ConstEvalLateContext<'a, 'tcx> {
315 lcx: &'a LateContext<'tcx>,
316 typeck_results: &'a ty::TypeckResults<'tcx>,
317 param_env: ty::ParamEnv<'tcx>,
318 needed_resolution: bool,
319 substs: SubstsRef<'tcx>,
322 impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
323 /// Simple constant folding: Insert an expression, get a constant or none.
324 pub fn expr(&mut self, e: &Expr<'_>) -> Option<Constant> {
326 ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.typeck_results.expr_ty(e)),
327 ExprKind::Block(block, _) => self.block(block),
328 ExprKind::Lit(ref lit) => {
329 if is_direct_expn_of(e.span, "cfg").is_some() {
332 Some(lit_to_mir_constant(&lit.node, self.typeck_results.expr_ty_opt(e)))
335 ExprKind::Array(vec) => self.multi(vec).map(Constant::Vec),
336 ExprKind::Tup(tup) => self.multi(tup).map(Constant::Tuple),
337 ExprKind::Repeat(value, _) => {
338 let n = match self.typeck_results.expr_ty(e).kind() {
339 ty::Array(_, n) => n.try_eval_usize(self.lcx.tcx, self.lcx.param_env)?,
340 _ => span_bug!(e.span, "typeck error"),
342 self.expr(value).map(|v| Constant::Repeat(Box::new(v), n))
344 ExprKind::Unary(op, operand) => self.expr(operand).and_then(|o| match op {
345 UnOp::Not => self.constant_not(&o, self.typeck_results.expr_ty(e)),
346 UnOp::Neg => self.constant_negate(&o, self.typeck_results.expr_ty(e)),
347 UnOp::Deref => Some(if let Constant::Ref(r) = o { *r } else { o }),
349 ExprKind::If(cond, then, ref otherwise) => self.ifthenelse(cond, then, *otherwise),
350 ExprKind::Binary(op, left, right) => self.binop(op, left, right),
351 ExprKind::Call(callee, args) => {
352 // We only handle a few const functions for now.
355 if let ExprKind::Path(qpath) = &callee.kind;
356 let res = self.typeck_results.qpath_res(qpath, callee.hir_id);
357 if let Some(def_id) = res.opt_def_id();
358 let def_path = self.lcx.get_def_path(def_id);
359 let def_path: Vec<&str> = def_path.iter().take(4).map(Symbol::as_str).collect();
360 if let ["core", "num", int_impl, "max_value"] = *def_path;
362 let value = match int_impl {
363 "<impl i8>" => i8::MAX as u128,
364 "<impl i16>" => i16::MAX as u128,
365 "<impl i32>" => i32::MAX as u128,
366 "<impl i64>" => i64::MAX as u128,
367 "<impl i128>" => i128::MAX as u128,
370 Some(Constant::Int(value))
376 ExprKind::Index(arr, index) => self.index(arr, index),
377 ExprKind::AddrOf(_, _, inner) => self.expr(inner).map(|r| Constant::Ref(Box::new(r))),
378 // TODO: add other expressions.
383 #[expect(clippy::cast_possible_wrap)]
384 fn constant_not(&self, o: &Constant, ty: Ty<'_>) -> Option<Constant> {
385 use self::Constant::{Bool, Int};
387 Bool(b) => Some(Bool(!b)),
391 ty::Int(ity) => Some(Int(unsext(self.lcx.tcx, value as i128, ity))),
392 ty::Uint(ity) => Some(Int(clip(self.lcx.tcx, value, ity))),
400 fn constant_negate(&self, o: &Constant, ty: Ty<'_>) -> Option<Constant> {
401 use self::Constant::{Int, F32, F64};
404 let ity = match *ty.kind() {
409 let value = sext(self.lcx.tcx, value, ity);
410 let value = value.checked_neg()?;
412 Some(Int(unsext(self.lcx.tcx, value, ity)))
414 F32(f) => Some(F32(-f)),
415 F64(f) => Some(F64(-f)),
420 /// Create `Some(Vec![..])` of all constants, unless there is any
421 /// non-constant part.
422 fn multi(&mut self, vec: &[Expr<'_>]) -> Option<Vec<Constant>> {
423 vec.iter().map(|elem| self.expr(elem)).collect::<Option<_>>()
426 /// Lookup a possibly constant expression from an `ExprKind::Path`.
427 fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option<Constant> {
428 let res = self.typeck_results.qpath_res(qpath, id);
430 Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => {
431 // Check if this constant is based on `cfg!(..)`,
432 // which is NOT constant for our purposes.
433 if let Some(node) = self.lcx.tcx.hir().get_if_local(def_id) &&
434 let Node::Item(&Item {
435 kind: ItemKind::Const(_, body_id),
438 let Node::Expr(&Expr {
439 kind: ExprKind::Lit(_),
442 }) = self.lcx.tcx.hir().get(body_id.hir_id) &&
443 is_direct_expn_of(span, "cfg").is_some() {
447 let substs = self.typeck_results.node_substs(id);
448 let substs = if self.substs.is_empty() {
451 EarlyBinder(substs).subst(self.lcx.tcx, self.substs)
459 mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
463 .map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty))?;
464 let result = miri_to_const(self.lcx.tcx, result);
465 if result.is_some() {
466 self.needed_resolution = true;
470 // FIXME: cover all usable cases.
475 fn index(&mut self, lhs: &'_ Expr<'_>, index: &'_ Expr<'_>) -> Option<Constant> {
476 let lhs = self.expr(lhs);
477 let index = self.expr(index);
480 (Some(Constant::Vec(vec)), Some(Constant::Int(index))) => match vec.get(index as usize) {
481 Some(Constant::F32(x)) => Some(Constant::F32(*x)),
482 Some(Constant::F64(x)) => Some(Constant::F64(*x)),
485 (Some(Constant::Vec(vec)), _) => {
486 if !vec.is_empty() && vec.iter().all(|x| *x == vec[0]) {
488 Some(Constant::F32(x)) => Some(Constant::F32(*x)),
489 Some(Constant::F64(x)) => Some(Constant::F64(*x)),
500 /// A block can only yield a constant if it only has one constant expression.
501 fn block(&mut self, block: &Block<'_>) -> Option<Constant> {
502 if block.stmts.is_empty() {
503 block.expr.as_ref().and_then(|b| self.expr(b))
509 fn ifthenelse(&mut self, cond: &Expr<'_>, then: &Expr<'_>, otherwise: Option<&Expr<'_>>) -> Option<Constant> {
510 if let Some(Constant::Bool(b)) = self.expr(cond) {
514 otherwise.as_ref().and_then(|expr| self.expr(expr))
521 fn binop(&mut self, op: BinOp, left: &Expr<'_>, right: &Expr<'_>) -> Option<Constant> {
522 let l = self.expr(left)?;
523 let r = self.expr(right);
525 (Constant::Int(l), Some(Constant::Int(r))) => match *self.typeck_results.expr_ty_opt(left)?.kind() {
527 let l = sext(self.lcx.tcx, l, ity);
528 let r = sext(self.lcx.tcx, r, ity);
529 let zext = |n: i128| Constant::Int(unsext(self.lcx.tcx, n, ity));
531 BinOpKind::Add => l.checked_add(r).map(zext),
532 BinOpKind::Sub => l.checked_sub(r).map(zext),
533 BinOpKind::Mul => l.checked_mul(r).map(zext),
534 BinOpKind::Div if r != 0 => l.checked_div(r).map(zext),
535 BinOpKind::Rem if r != 0 => l.checked_rem(r).map(zext),
536 BinOpKind::Shr => l.checked_shr(r.try_into().ok()?).map(zext),
537 BinOpKind::Shl => l.checked_shl(r.try_into().ok()?).map(zext),
538 BinOpKind::BitXor => Some(zext(l ^ r)),
539 BinOpKind::BitOr => Some(zext(l | r)),
540 BinOpKind::BitAnd => Some(zext(l & r)),
541 BinOpKind::Eq => Some(Constant::Bool(l == r)),
542 BinOpKind::Ne => Some(Constant::Bool(l != r)),
543 BinOpKind::Lt => Some(Constant::Bool(l < r)),
544 BinOpKind::Le => Some(Constant::Bool(l <= r)),
545 BinOpKind::Ge => Some(Constant::Bool(l >= r)),
546 BinOpKind::Gt => Some(Constant::Bool(l > r)),
550 ty::Uint(_) => match op.node {
551 BinOpKind::Add => l.checked_add(r).map(Constant::Int),
552 BinOpKind::Sub => l.checked_sub(r).map(Constant::Int),
553 BinOpKind::Mul => l.checked_mul(r).map(Constant::Int),
554 BinOpKind::Div => l.checked_div(r).map(Constant::Int),
555 BinOpKind::Rem => l.checked_rem(r).map(Constant::Int),
556 BinOpKind::Shr => l.checked_shr(r.try_into().ok()?).map(Constant::Int),
557 BinOpKind::Shl => l.checked_shl(r.try_into().ok()?).map(Constant::Int),
558 BinOpKind::BitXor => Some(Constant::Int(l ^ r)),
559 BinOpKind::BitOr => Some(Constant::Int(l | r)),
560 BinOpKind::BitAnd => Some(Constant::Int(l & r)),
561 BinOpKind::Eq => Some(Constant::Bool(l == r)),
562 BinOpKind::Ne => Some(Constant::Bool(l != r)),
563 BinOpKind::Lt => Some(Constant::Bool(l < r)),
564 BinOpKind::Le => Some(Constant::Bool(l <= r)),
565 BinOpKind::Ge => Some(Constant::Bool(l >= r)),
566 BinOpKind::Gt => Some(Constant::Bool(l > r)),
571 (Constant::F32(l), Some(Constant::F32(r))) => match op.node {
572 BinOpKind::Add => Some(Constant::F32(l + r)),
573 BinOpKind::Sub => Some(Constant::F32(l - r)),
574 BinOpKind::Mul => Some(Constant::F32(l * r)),
575 BinOpKind::Div => Some(Constant::F32(l / r)),
576 BinOpKind::Rem => Some(Constant::F32(l % r)),
577 BinOpKind::Eq => Some(Constant::Bool(l == r)),
578 BinOpKind::Ne => Some(Constant::Bool(l != r)),
579 BinOpKind::Lt => Some(Constant::Bool(l < r)),
580 BinOpKind::Le => Some(Constant::Bool(l <= r)),
581 BinOpKind::Ge => Some(Constant::Bool(l >= r)),
582 BinOpKind::Gt => Some(Constant::Bool(l > r)),
585 (Constant::F64(l), Some(Constant::F64(r))) => match op.node {
586 BinOpKind::Add => Some(Constant::F64(l + r)),
587 BinOpKind::Sub => Some(Constant::F64(l - r)),
588 BinOpKind::Mul => Some(Constant::F64(l * r)),
589 BinOpKind::Div => Some(Constant::F64(l / r)),
590 BinOpKind::Rem => Some(Constant::F64(l % r)),
591 BinOpKind::Eq => Some(Constant::Bool(l == r)),
592 BinOpKind::Ne => Some(Constant::Bool(l != r)),
593 BinOpKind::Lt => Some(Constant::Bool(l < r)),
594 BinOpKind::Le => Some(Constant::Bool(l <= r)),
595 BinOpKind::Ge => Some(Constant::Bool(l >= r)),
596 BinOpKind::Gt => Some(Constant::Bool(l > r)),
599 (l, r) => match (op.node, l, r) {
600 (BinOpKind::And, Constant::Bool(false), _) => Some(Constant::Bool(false)),
601 (BinOpKind::Or, Constant::Bool(true), _) => Some(Constant::Bool(true)),
602 (BinOpKind::And, Constant::Bool(true), Some(r)) | (BinOpKind::Or, Constant::Bool(false), Some(r)) => {
605 (BinOpKind::BitXor, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l ^ r)),
606 (BinOpKind::BitAnd, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l & r)),
607 (BinOpKind::BitOr, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l | r)),
614 pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -> Option<Constant> {
615 use rustc_middle::mir::interpret::ConstValue;
617 mir::ConstantKind::Val(ConstValue::Scalar(Scalar::Int(int)), _) => {
618 match result.ty().kind() {
619 ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)),
620 ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))),
621 ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(
622 int.try_into().expect("invalid f32 bit representation"),
624 ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits(
625 int.try_into().expect("invalid f64 bit representation"),
627 ty::RawPtr(type_and_mut) => {
628 if let ty::Uint(_) = type_and_mut.ty.kind() {
629 return Some(Constant::RawPtr(int.assert_bits(int.size())));
633 // FIXME: implement other conversions.
637 mir::ConstantKind::Val(ConstValue::Slice { data, start, end }, _) => match result.ty().kind() {
638 ty::Ref(_, tam, _) => match tam.kind() {
639 ty::Str => String::from_utf8(
641 .inspect_with_uninit_and_ptr_outside_interpreter(start..end)
650 mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() {
651 ty::Array(sub_type, len) => match sub_type.kind() {
652 ty::Float(FloatTy::F32) => match len.kind().try_to_machine_usize(tcx) {
655 .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap()))
658 .map(|&chunk| Some(Constant::F32(f32::from_le_bytes(chunk))))
659 .collect::<Option<Vec<Constant>>>()
663 ty::Float(FloatTy::F64) => match len.kind().try_to_machine_usize(tcx) {
666 .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap()))
669 .map(|&chunk| Some(Constant::F64(f64::from_le_bytes(chunk))))
670 .collect::<Option<Vec<Constant>>>()
674 // FIXME: implement other array type conversions.
679 // FIXME: implement other conversions.