Skip to content

Commit 690c799

Browse files
committed
Add more documentation
1 parent e8e8c1c commit 690c799

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::ty::layout::{self, LayoutOf, VariantIdx};
1616
use rustc::ty::subst::Subst;
1717
use rustc::traits::Reveal;
1818
use rustc_data_structures::fx::FxHashMap;
19-
use crate::interpret::eval_nulary_intrinsic;
19+
use crate::interpret::eval_nullary_intrinsic;
2020

2121
use syntax::source_map::{Span, DUMMY_SP};
2222

@@ -607,13 +607,15 @@ pub fn const_eval_provider<'tcx>(
607607
}
608608
}
609609

610+
// We call `const_eval` for zero arg intrinsics, too, in order to cache their value.
611+
// Catch such calls and evaluate them instead of trying to load a constant's MIR.
610612
if let ty::InstanceDef::Intrinsic(def_id) = key.value.instance.def {
611613
let ty = key.value.instance.ty(tcx);
612614
let substs = match ty.sty {
613615
ty::FnDef(_, substs) => substs,
614616
_ => bug!("intrinsic with type {:?}", ty),
615617
};
616-
return Ok(eval_nulary_intrinsic(tcx, key.param_env, def_id, substs));
618+
return Ok(eval_nullary_intrinsic(tcx, key.param_env, def_id, substs));
617619
}
618620

619621
tcx.const_eval_raw(key).and_then(|val| {

src/librustc_mir/interpret/intrinsics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ fn numeric_intrinsic<'tcx, Tag>(
3838
Ok(Scalar::from_uint(bits_out, size))
3939
}
4040

41-
42-
crate fn eval_nulary_intrinsic<'tcx>(
41+
/// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated
42+
/// inside an `InterpCx` and instead have their value computed directly from rustc internal info.
43+
crate fn eval_nullary_intrinsic<'tcx>(
4344
tcx: TyCtxt<'tcx>,
4445
param_env: ty::ParamEnv<'tcx>,
4546
def_id: DefId,

src/librustc_mir/interpret/intrinsics/type_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl Write for AbsolutePathPrinter<'_> {
214214
}
215215

216216
/// Directly returns an `Allocation` containing an absolute path representation of the given type.
217-
pub(crate) fn alloc_type_name<'tcx>(
217+
crate fn alloc_type_name<'tcx>(
218218
tcx: TyCtxt<'tcx>,
219219
ty: Ty<'tcx>
220220
) -> &'tcx Allocation {

src/librustc_mir/interpret/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ pub use self::validity::RefTracking;
3636

3737
pub use self::intern::intern_const_alloc_recursive;
3838

39-
pub(crate) use self::intrinsics::eval_nulary_intrinsic;
39+
crate use self::intrinsics::eval_nullary_intrinsic;

0 commit comments

Comments
 (0)