]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/interpret/const_eval.rs
Allow the linker to choose the LTO-plugin (which is useful when using LLD)
[rust.git] / src / librustc_mir / interpret / const_eval.rs
1 use rustc::hir;
2 use rustc::mir::interpret::{ConstEvalErr};
3 use rustc::mir;
4 use rustc::ty::{self, TyCtxt, Ty, Instance};
5 use rustc::ty::layout::{self, LayoutOf, Primitive};
6 use rustc::ty::subst::Subst;
7
8 use syntax::ast::Mutability;
9 use syntax::codemap::Span;
10 use syntax::codemap::DUMMY_SP;
11
12 use rustc::mir::interpret::{
13     EvalResult, EvalError, EvalErrorKind, GlobalId,
14     Value, Scalar, AllocId, Allocation, ConstValue,
15 };
16 use super::{Place, EvalContext, StackPopCleanup, ValTy, PlaceExtra, Memory, MemoryKind};
17
18 use std::fmt;
19 use std::error::Error;
20
21 pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>(
22     tcx: TyCtxt<'a, 'tcx, 'tcx>,
23     instance: Instance<'tcx>,
24     mir: &'mir mir::Mir<'tcx>,
25     span: Span,
26 ) -> EvalResult<'tcx, EvalContext<'a, 'mir, 'tcx, CompileTimeEvaluator>> {
27     debug!("mk_borrowck_eval_cx: {:?}", instance);
28     let param_env = tcx.param_env(instance.def_id());
29     let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeEvaluator, ());
30     // insert a stack frame so any queries have the correct substs
31     ecx.push_stack_frame(
32         instance,
33         span,
34         mir,
35         Place::undef(),
36         StackPopCleanup::None,
37     )?;
38     Ok(ecx)
39 }
40
41 pub fn mk_eval_cx<'a, 'tcx>(
42     tcx: TyCtxt<'a, 'tcx, 'tcx>,
43     instance: Instance<'tcx>,
44     param_env: ty::ParamEnv<'tcx>,
45 ) -> EvalResult<'tcx, EvalContext<'a, 'tcx, 'tcx, CompileTimeEvaluator>> {
46     debug!("mk_eval_cx: {:?}, {:?}", instance, param_env);
47     let span = tcx.def_span(instance.def_id());
48     let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeEvaluator, ());
49     let mir = ecx.load_mir(instance.def)?;
50     // insert a stack frame so any queries have the correct substs
51     ecx.push_stack_frame(
52         instance,
53         mir.span,
54         mir,
55         Place::undef(),
56         StackPopCleanup::None,
57     )?;
58     Ok(ecx)
59 }
60
61 pub fn eval_promoted<'a, 'mir, 'tcx>(
62     ecx: &mut EvalContext<'a, 'mir, 'tcx, CompileTimeEvaluator>,
63     cid: GlobalId<'tcx>,
64     mir: &'mir mir::Mir<'tcx>,
65     param_env: ty::ParamEnv<'tcx>,
66 ) -> EvalResult<'tcx, (Value, Scalar, Ty<'tcx>)> {
67     ecx.with_fresh_body(|ecx| {
68         eval_body_using_ecx(ecx, cid, Some(mir), param_env)
69     })
70 }
71
72 pub fn value_to_const_value<'tcx>(
73     ecx: &EvalContext<'_, '_, 'tcx, CompileTimeEvaluator>,
74     val: Value,
75     ty: Ty<'tcx>,
76 ) -> &'tcx ty::Const<'tcx> {
77     let layout = ecx.layout_of(ty).unwrap();
78     match (val, &layout.abi) {
79         (Value::Scalar(Scalar::Bits { defined: 0, ..}), _) if layout.is_zst() => {},
80         (Value::ByRef(..), _) |
81         (Value::Scalar(_), &layout::Abi::Scalar(_)) |
82         (Value::ScalarPair(..), &layout::Abi::ScalarPair(..)) => {},
83         _ => bug!("bad value/layout combo: {:#?}, {:#?}", val, layout),
84     }
85     let val = (|| {
86         match val {
87             Value::Scalar(val) => Ok(ConstValue::Scalar(val)),
88             Value::ScalarPair(a, b) => Ok(ConstValue::ScalarPair(a, b)),
89             Value::ByRef(ptr, align) => {
90                 let ptr = ptr.to_ptr().unwrap();
91                 let alloc = ecx.memory.get(ptr.alloc_id)?;
92                 assert!(alloc.align.abi() >= align.abi());
93                 assert!(alloc.bytes.len() as u64 - ptr.offset.bytes() >= layout.size.bytes());
94                 let mut alloc = alloc.clone();
95                 alloc.align = align;
96                 let alloc = ecx.tcx.intern_const_alloc(alloc);
97                 Ok(ConstValue::ByRef(alloc, ptr.offset))
98             }
99         }
100     })();
101     match val {
102         Ok(val) => ty::Const::from_const_value(ecx.tcx.tcx, val, ty),
103         Err(err) => {
104             let (frames, span) = ecx.generate_stacktrace(None);
105             let err = ConstEvalErr {
106                 span,
107                 error: err,
108                 stacktrace: frames,
109             };
110             err.report_as_error(
111                 ecx.tcx,
112                 "failed to convert Value to ConstValue, this is a bug",
113             );
114             span_bug!(span, "miri error occured when converting Value to ConstValue")
115         }
116     }
117 }
118
119 fn eval_body_and_ecx<'a, 'mir, 'tcx>(
120     tcx: TyCtxt<'a, 'tcx, 'tcx>,
121     cid: GlobalId<'tcx>,
122     mir: Option<&'mir mir::Mir<'tcx>>,
123     param_env: ty::ParamEnv<'tcx>,
124 ) -> (EvalResult<'tcx, (Value, Scalar, Ty<'tcx>)>, EvalContext<'a, 'mir, 'tcx, CompileTimeEvaluator>) {
125     debug!("eval_body_and_ecx: {:?}, {:?}", cid, param_env);
126     // we start out with the best span we have
127     // and try improving it down the road when more information is available
128     let span = tcx.def_span(cid.instance.def_id());
129     let span = mir.map(|mir| mir.span).unwrap_or(span);
130     let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeEvaluator, ());
131     let r = eval_body_using_ecx(&mut ecx, cid, mir, param_env);
132     (r, ecx)
133 }
134
135 fn eval_body_using_ecx<'a, 'mir, 'tcx>(
136     ecx: &mut EvalContext<'a, 'mir, 'tcx, CompileTimeEvaluator>,
137     cid: GlobalId<'tcx>,
138     mir: Option<&'mir mir::Mir<'tcx>>,
139     param_env: ty::ParamEnv<'tcx>,
140 ) -> EvalResult<'tcx, (Value, Scalar, Ty<'tcx>)> {
141     debug!("eval_body: {:?}, {:?}", cid, param_env);
142     let tcx = ecx.tcx.tcx;
143     let mut mir = match mir {
144         Some(mir) => mir,
145         None => ecx.load_mir(cid.instance.def)?,
146     };
147     if let Some(index) = cid.promoted {
148         mir = &mir.promoted[index];
149     }
150     let layout = ecx.layout_of(mir.return_ty().subst(tcx, cid.instance.substs))?;
151     assert!(!layout.is_unsized());
152     let ptr = ecx.memory.allocate(
153         layout.size,
154         layout.align,
155         None,
156     )?;
157     let internally_mutable = !layout.ty.is_freeze(tcx, param_env, mir.span);
158     let is_static = tcx.is_static(cid.instance.def_id());
159     let mutability = if is_static == Some(hir::Mutability::MutMutable) || internally_mutable {
160         Mutability::Mutable
161     } else {
162         Mutability::Immutable
163     };
164     let cleanup = StackPopCleanup::MarkStatic(mutability);
165     let name = ty::tls::with(|tcx| tcx.item_path_str(cid.instance.def_id()));
166     let prom = cid.promoted.map_or(String::new(), |p| format!("::promoted[{:?}]", p));
167     trace!("const_eval: pushing stack frame for global: {}{}", name, prom);
168     assert!(mir.arg_count == 0);
169     ecx.push_stack_frame(
170         cid.instance,
171         mir.span,
172         mir,
173         Place::from_ptr(ptr, layout.align),
174         cleanup,
175     )?;
176
177     while ecx.step()? {}
178     let ptr = ptr.into();
179     // always try to read the value and report errors
180     let value = match ecx.try_read_value(ptr, layout.align, layout.ty)? {
181         Some(val) if is_static.is_none() => val,
182         // point at the allocation
183         _ => Value::ByRef(ptr, layout.align),
184     };
185     Ok((value, ptr, layout.ty))
186 }
187
188 pub struct CompileTimeEvaluator;
189
190 impl<'tcx> Into<EvalError<'tcx>> for ConstEvalError {
191     fn into(self) -> EvalError<'tcx> {
192         EvalErrorKind::MachineError(self.to_string()).into()
193     }
194 }
195
196 #[derive(Clone, Debug)]
197 enum ConstEvalError {
198     NeedsRfc(String),
199     NotConst(String),
200 }
201
202 impl fmt::Display for ConstEvalError {
203     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
204         use self::ConstEvalError::*;
205         match *self {
206             NeedsRfc(ref msg) => {
207                 write!(
208                     f,
209                     "\"{}\" needs an rfc before being allowed inside constants",
210                     msg
211                 )
212             }
213             NotConst(ref msg) => write!(f, "{}", msg),
214         }
215     }
216 }
217
218 impl Error for ConstEvalError {
219     fn description(&self) -> &str {
220         use self::ConstEvalError::*;
221         match *self {
222             NeedsRfc(_) => "this feature needs an rfc before being allowed inside constants",
223             NotConst(_) => "this feature is not compatible with constant evaluation",
224         }
225     }
226
227     fn cause(&self) -> Option<&dyn Error> {
228         None
229     }
230 }
231
232 impl<'mir, 'tcx> super::Machine<'mir, 'tcx> for CompileTimeEvaluator {
233     type MemoryData = ();
234     type MemoryKinds = !;
235     fn eval_fn_call<'a>(
236         ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
237         instance: ty::Instance<'tcx>,
238         destination: Option<(Place, mir::BasicBlock)>,
239         args: &[ValTy<'tcx>],
240         span: Span,
241         sig: ty::FnSig<'tcx>,
242     ) -> EvalResult<'tcx, bool> {
243         debug!("eval_fn_call: {:?}", instance);
244         if !ecx.tcx.is_const_fn(instance.def_id()) {
245             let def_id = instance.def_id();
246             let (op, oflo) = if let Some(op) = ecx.tcx.is_binop_lang_item(def_id) {
247                 op
248             } else {
249                 return Err(
250                     ConstEvalError::NotConst(format!("calling non-const fn `{}`", instance)).into(),
251                 );
252             };
253             let (dest, bb) = destination.expect("128 lowerings can't diverge");
254             let dest_ty = sig.output();
255             if oflo {
256                 ecx.intrinsic_with_overflow(op, args[0], args[1], dest, dest_ty)?;
257             } else {
258                 ecx.intrinsic_overflowing(op, args[0], args[1], dest, dest_ty)?;
259             }
260             ecx.goto_block(bb);
261             return Ok(true);
262         }
263         let mir = match ecx.load_mir(instance.def) {
264             Ok(mir) => mir,
265             Err(err) => {
266                 if let EvalErrorKind::NoMirFor(ref path) = err.kind {
267                     return Err(
268                         ConstEvalError::NeedsRfc(format!("calling extern function `{}`", path))
269                             .into(),
270                     );
271                 }
272                 return Err(err);
273             }
274         };
275         let (return_place, return_to_block) = match destination {
276             Some((place, block)) => (place, StackPopCleanup::Goto(block)),
277             None => (Place::undef(), StackPopCleanup::None),
278         };
279
280         ecx.push_stack_frame(
281             instance,
282             span,
283             mir,
284             return_place,
285             return_to_block,
286         )?;
287
288         Ok(false)
289     }
290
291
292     fn call_intrinsic<'a>(
293         ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
294         instance: ty::Instance<'tcx>,
295         args: &[ValTy<'tcx>],
296         dest: Place,
297         dest_layout: layout::TyLayout<'tcx>,
298         target: mir::BasicBlock,
299     ) -> EvalResult<'tcx> {
300         let substs = instance.substs;
301
302         let intrinsic_name = &ecx.tcx.item_name(instance.def_id()).as_str()[..];
303         match intrinsic_name {
304             "min_align_of" => {
305                 let elem_ty = substs.type_at(0);
306                 let elem_align = ecx.layout_of(elem_ty)?.align.abi();
307                 let align_val = Scalar::Bits {
308                     bits: elem_align as u128,
309                     defined: dest_layout.size.bits() as u8,
310                 };
311                 ecx.write_scalar(dest, align_val, dest_layout.ty)?;
312             }
313
314             "size_of" => {
315                 let ty = substs.type_at(0);
316                 let size = ecx.layout_of(ty)?.size.bytes() as u128;
317                 let size_val = Scalar::Bits {
318                     bits: size,
319                     defined: dest_layout.size.bits() as u8,
320                 };
321                 ecx.write_scalar(dest, size_val, dest_layout.ty)?;
322             }
323
324             "type_id" => {
325                 let ty = substs.type_at(0);
326                 let type_id = ecx.tcx.type_id_hash(ty) as u128;
327                 let id_val = Scalar::Bits {
328                     bits: type_id,
329                     defined: dest_layout.size.bits() as u8,
330                 };
331                 ecx.write_scalar(dest, id_val, dest_layout.ty)?;
332             }
333             "ctpop" | "cttz" | "cttz_nonzero" | "ctlz" | "ctlz_nonzero" | "bswap" => {
334                 let ty = substs.type_at(0);
335                 let layout_of = ecx.layout_of(ty)?;
336                 let bits = ecx.value_to_scalar(args[0])?.to_bits(layout_of.size)?;
337                 let kind = match layout_of.abi {
338                     ty::layout::Abi::Scalar(ref scalar) => scalar.value,
339                     _ => Err(::rustc::mir::interpret::EvalErrorKind::TypeNotPrimitive(ty))?,
340                 };
341                 let out_val = if intrinsic_name.ends_with("_nonzero") {
342                     if bits == 0 {
343                         return err!(Intrinsic(format!("{} called on 0", intrinsic_name)));
344                     }
345                     numeric_intrinsic(intrinsic_name.trim_right_matches("_nonzero"), bits, kind)?
346                 } else {
347                     numeric_intrinsic(intrinsic_name, bits, kind)?
348                 };
349                 ecx.write_scalar(dest, out_val, ty)?;
350             }
351
352             name => return Err(
353                 ConstEvalError::NeedsRfc(format!("calling intrinsic `{}`", name)).into()
354             ),
355         }
356
357         ecx.goto_block(target);
358
359         // Since we pushed no stack frame, the main loop will act
360         // as if the call just completed and it's returning to the
361         // current frame.
362         Ok(())
363     }
364
365     fn try_ptr_op<'a>(
366         _ecx: &EvalContext<'a, 'mir, 'tcx, Self>,
367         _bin_op: mir::BinOp,
368         left: Scalar,
369         _left_ty: Ty<'tcx>,
370         right: Scalar,
371         _right_ty: Ty<'tcx>,
372     ) -> EvalResult<'tcx, Option<(Scalar, bool)>> {
373         if left.is_bits() && right.is_bits() {
374             Ok(None)
375         } else {
376             Err(
377                 ConstEvalError::NeedsRfc("pointer arithmetic or comparison".to_string()).into(),
378             )
379         }
380     }
381
382     fn mark_static_initialized<'a>(
383         _mem: &mut Memory<'a, 'mir, 'tcx, Self>,
384         _id: AllocId,
385         _mutability: Mutability,
386     ) -> EvalResult<'tcx, bool> {
387         Ok(false)
388     }
389
390     fn init_static<'a>(
391         ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
392         cid: GlobalId<'tcx>,
393     ) -> EvalResult<'tcx, AllocId> {
394         Ok(ecx
395             .tcx
396             .alloc_map
397             .lock()
398             .intern_static(cid.instance.def_id()))
399     }
400
401     fn box_alloc<'a>(
402         _ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
403         _ty: Ty<'tcx>,
404         _dest: Place,
405     ) -> EvalResult<'tcx> {
406         Err(
407             ConstEvalError::NeedsRfc("heap allocations via `box` keyword".to_string()).into(),
408         )
409     }
410
411     fn global_item_with_linkage<'a>(
412         _ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
413         _instance: ty::Instance<'tcx>,
414         _mutability: Mutability,
415     ) -> EvalResult<'tcx> {
416         Err(
417             ConstEvalError::NotConst("statics with `linkage` attribute".to_string()).into(),
418         )
419     }
420 }
421
422 pub fn const_val_field<'a, 'tcx>(
423     tcx: TyCtxt<'a, 'tcx, 'tcx>,
424     param_env: ty::ParamEnv<'tcx>,
425     instance: ty::Instance<'tcx>,
426     variant: Option<usize>,
427     field: mir::Field,
428     value: &'tcx ty::Const<'tcx>,
429 ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
430     trace!("const_val_field: {:?}, {:?}, {:?}", instance, field, value);
431     let mut ecx = mk_eval_cx(tcx, instance, param_env).unwrap();
432     let result = (|| {
433         let ty = value.ty;
434         let value = ecx.const_to_value(value.val)?;
435         let layout = ecx.layout_of(ty)?;
436         let (ptr, align) = match value {
437             Value::ByRef(ptr, align) => (ptr, align),
438             Value::ScalarPair(..) | Value::Scalar(_) => {
439                 let ptr = ecx.alloc_ptr(ty)?.into();
440                 ecx.write_value_to_ptr(value, ptr, layout.align, ty)?;
441                 (ptr, layout.align)
442             },
443         };
444         let place = Place::Ptr {
445             ptr,
446             align,
447             extra: variant.map_or(PlaceExtra::None, PlaceExtra::DowncastVariant),
448         };
449         let (place, layout) = ecx.place_field(place, field, layout)?;
450         let (ptr, align) = place.to_ptr_align();
451         let mut new_value = Value::ByRef(ptr, align);
452         new_value = ecx.try_read_by_ref(new_value, layout.ty)?;
453         use rustc_data_structures::indexed_vec::Idx;
454         match (value, new_value) {
455             (Value::Scalar(_), Value::ByRef(..)) |
456             (Value::ScalarPair(..), Value::ByRef(..)) |
457             (Value::Scalar(_), Value::ScalarPair(..)) => bug!(
458                 "field {} of {:?} yielded {:?}",
459                 field.index(),
460                 value,
461                 new_value,
462             ),
463             _ => {},
464         }
465         Ok(value_to_const_value(&ecx, new_value, layout.ty))
466     })();
467     result.map_err(|err| {
468         let (trace, span) = ecx.generate_stacktrace(None);
469         ConstEvalErr {
470             error: err,
471             stacktrace: trace,
472             span,
473         }.into()
474     })
475 }
476
477 pub fn const_variant_index<'a, 'tcx>(
478     tcx: TyCtxt<'a, 'tcx, 'tcx>,
479     param_env: ty::ParamEnv<'tcx>,
480     instance: ty::Instance<'tcx>,
481     val: &'tcx ty::Const<'tcx>,
482 ) -> EvalResult<'tcx, usize> {
483     trace!("const_variant_index: {:?}, {:?}", instance, val);
484     let mut ecx = mk_eval_cx(tcx, instance, param_env).unwrap();
485     let value = ecx.const_to_value(val.val)?;
486     let (ptr, align) = match value {
487         Value::ScalarPair(..) | Value::Scalar(_) => {
488             let layout = ecx.layout_of(val.ty)?;
489             let ptr = ecx.memory.allocate(layout.size, layout.align, Some(MemoryKind::Stack))?.into();
490             ecx.write_value_to_ptr(value, ptr, layout.align, val.ty)?;
491             (ptr, layout.align)
492         },
493         Value::ByRef(ptr, align) => (ptr, align),
494     };
495     let place = Place::from_scalar_ptr(ptr, align);
496     ecx.read_discriminant_as_variant_index(place, val.ty)
497 }
498
499 pub fn const_value_to_allocation_provider<'a, 'tcx>(
500     tcx: TyCtxt<'a, 'tcx, 'tcx>,
501     val: &'tcx ty::Const<'tcx>,
502 ) -> &'tcx Allocation {
503     match val.val {
504         ConstValue::ByRef(alloc, offset) => {
505             assert_eq!(offset.bytes(), 0);
506             return alloc;
507         },
508         _ => ()
509     }
510     let result = || -> EvalResult<'tcx, &'tcx Allocation> {
511         let mut ecx = EvalContext::new(
512             tcx.at(DUMMY_SP),
513             ty::ParamEnv::reveal_all(),
514             CompileTimeEvaluator,
515             ());
516         let value = ecx.const_to_value(val.val)?;
517         let layout = ecx.layout_of(val.ty)?;
518         let ptr = ecx.memory.allocate(layout.size, layout.align, Some(MemoryKind::Stack))?;
519         ecx.write_value_to_ptr(value, ptr.into(), layout.align, val.ty)?;
520         let alloc = ecx.memory.get(ptr.alloc_id)?;
521         Ok(tcx.intern_const_alloc(alloc.clone()))
522     };
523     result().expect("unable to convert ConstValue to Allocation")
524 }
525
526 pub fn const_eval_provider<'a, 'tcx>(
527     tcx: TyCtxt<'a, 'tcx, 'tcx>,
528     key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
529 ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
530     trace!("const eval: {:?}", key);
531     let cid = key.value;
532     let def_id = cid.instance.def.def_id();
533
534     if let Some(id) = tcx.hir.as_local_node_id(def_id) {
535         let tables = tcx.typeck_tables_of(def_id);
536         let span = tcx.def_span(def_id);
537
538         // Do match-check before building MIR
539         if tcx.check_match(def_id).is_err() {
540             return Err(ConstEvalErr {
541                 error: EvalErrorKind::CheckMatchError.into(),
542                 stacktrace: vec![],
543                 span,
544             }.into());
545         }
546
547         if let hir::BodyOwnerKind::Const = tcx.hir.body_owner_kind(id) {
548             tcx.mir_const_qualif(def_id);
549         }
550
551         // Do not continue into miri if typeck errors occurred; it will fail horribly
552         if tables.tainted_by_errors {
553             return Err(ConstEvalErr {
554                 error: EvalErrorKind::CheckMatchError.into(),
555                 stacktrace: vec![],
556                 span,
557             }.into());
558         }
559     };
560
561     let (res, ecx) = eval_body_and_ecx(tcx, cid, None, key.param_env);
562     res.and_then(|(mut val, _, miri_ty)| {
563         if tcx.is_static(def_id).is_none() {
564             val = ecx.try_read_by_ref(val, miri_ty)?;
565         }
566         Ok(value_to_const_value(&ecx, val, miri_ty))
567     }).map_err(|err| {
568         let (trace, span) = ecx.generate_stacktrace(None);
569         let err = ConstEvalErr {
570             error: err,
571             stacktrace: trace,
572             span,
573         };
574         if tcx.is_static(def_id).is_some() {
575             err.report_as_error(ecx.tcx, "could not evaluate static initializer");
576         }
577         err.into()
578     })
579 }
580
581 fn numeric_intrinsic<'tcx>(
582     name: &str,
583     bits: u128,
584     kind: Primitive,
585 ) -> EvalResult<'tcx, Scalar> {
586     let defined = match kind {
587         Primitive::Int(integer, _) => integer.size().bits() as u8,
588         _ => bug!("invalid `{}` argument: {:?}", name, bits),
589     };
590     let extra = 128 - defined as u128;
591     let bits_out = match name {
592         "ctpop" => bits.count_ones() as u128,
593         "ctlz" => bits.leading_zeros() as u128 - extra,
594         "cttz" => (bits << extra).trailing_zeros() as u128 - extra,
595         "bswap" => (bits << extra).swap_bytes(),
596         _ => bug!("not a numeric intrinsic: {}", name),
597     };
598     Ok(Scalar::Bits { bits: bits_out, defined })
599 }