Skip to content

Commit 5aeb894

Browse files
committed
Auto merge of #64012 - Centril:rollup-cukawo8, r=Centril
Rollup of 4 pull requests Successful merges: - #61626 (Get rid of special const intrinsic query in favour of `const_eval`) - #63600 (Merge oli-obk mail addresses) - #63684 (Constify LinkedList new function) - #63982 (When accessing private field of union, do not misidentify it as a struct) Failed merges: r? @ghost
2 parents 72b2abf + 132659a commit 5aeb894

File tree

19 files changed

+196
-192
lines changed

19 files changed

+196
-192
lines changed

.mailmap

+13-6
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,19 @@ Neil Pankey <[email protected]> <[email protected]>
184184
Nick Platt <[email protected]>
185185
Nicole Mazzuca <[email protected]>
186186
187-
Oliver Schneider <[email protected]> oli-obk <[email protected]>
188-
Oliver Schneider <[email protected]> Oliver 'ker' Schneider <[email protected]>
189-
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
190-
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
191-
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
192-
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
187+
188+
189+
190+
191+
192+
193+
194+
195+
196+
197+
198+
199+
Oliver Scherer <[email protected]>
193200
Ožbolt Menegatti <[email protected]> gareins <[email protected]>
194201
Paul Faria <[email protected]> Paul Faria <[email protected]>
195202
Peer Aramillo Irizar <[email protected]> parir <[email protected]>

src/liballoc/collections/linked_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<T> LinkedList<T> {
276276
/// ```
277277
#[inline]
278278
#[stable(feature = "rust1", since = "1.0.0")]
279-
pub fn new() -> Self {
279+
pub const fn new() -> Self {
280280
LinkedList {
281281
head: None,
282282
tail: None,

src/librustc/mir/interpret/error.rs

+9
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ fn print_backtrace(backtrace: &mut Backtrace) {
215215
eprintln!("\n\nAn error occurred in miri:\n{:?}", backtrace);
216216
}
217217

218+
impl From<ErrorHandled> for InterpErrorInfo<'tcx> {
219+
fn from(err: ErrorHandled) -> Self {
220+
match err {
221+
ErrorHandled::Reported => err_inval!(ReferencedConstant),
222+
ErrorHandled::TooGeneric => err_inval!(TooGeneric),
223+
}.into()
224+
}
225+
}
226+
218227
impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
219228
fn from(kind: InterpError<'tcx>) -> Self {
220229
let backtrace = match env::var("RUSTC_CTFE_BACKTRACE") {

src/librustc/query/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,6 @@ rustc_queries! {
463463
no_force
464464
desc { "extract field of const" }
465465
}
466-
467-
/// Produces an absolute path representation of the given type. See also the documentation
468-
/// on `std::any::type_name`.
469-
query type_name(key: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
470-
eval_always
471-
no_force
472-
desc { "get absolute path of type" }
473-
}
474-
475466
}
476467

477468
TypeChecking {

src/librustc_codegen_llvm/intrinsic.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_codegen_ssa::glue;
1515
use rustc_codegen_ssa::base::{to_immediate, wants_msvc_seh, compare_simd_types};
1616
use rustc::ty::{self, Ty};
1717
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, Primitive};
18+
use rustc::mir::interpret::GlobalId;
1819
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
1920
use rustc::hir;
2021
use syntax::ast::{self, FloatTy};
@@ -81,13 +82,14 @@ fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: &str) -> Option<&'ll Valu
8182
impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
8283
fn codegen_intrinsic_call(
8384
&mut self,
84-
callee_ty: Ty<'tcx>,
85+
instance: ty::Instance<'tcx>,
8586
fn_ty: &FnType<'tcx, Ty<'tcx>>,
8687
args: &[OperandRef<'tcx, &'ll Value>],
8788
llresult: &'ll Value,
8889
span: Span,
8990
) {
9091
let tcx = self.tcx;
92+
let callee_ty = instance.ty(tcx);
9193

9294
let (def_id, substs) = match callee_ty.sty {
9395
ty::FnDef(def_id, substs) => (def_id, substs),
@@ -133,10 +135,6 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
133135
let llfn = self.get_intrinsic(&("llvm.debugtrap"));
134136
self.call(llfn, &[], None)
135137
}
136-
"size_of" => {
137-
let tp_ty = substs.type_at(0);
138-
self.const_usize(self.size_of(tp_ty).bytes())
139-
}
140138
"va_start" => {
141139
self.va_start(args[0].immediate())
142140
}
@@ -188,10 +186,6 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
188186
self.const_usize(self.size_of(tp_ty).bytes())
189187
}
190188
}
191-
"min_align_of" => {
192-
let tp_ty = substs.type_at(0);
193-
self.const_usize(self.align_of(tp_ty).bytes())
194-
}
195189
"min_align_of_val" => {
196190
let tp_ty = substs.type_at(0);
197191
if let OperandValue::Pair(_, meta) = args[0].val {
@@ -201,18 +195,19 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
201195
self.const_usize(self.align_of(tp_ty).bytes())
202196
}
203197
}
204-
"pref_align_of" => {
205-
let tp_ty = substs.type_at(0);
206-
self.const_usize(self.layout_of(tp_ty).align.pref.bytes())
207-
}
198+
"size_of" |
199+
"pref_align_of" |
200+
"min_align_of" |
201+
"needs_drop" |
202+
"type_id" |
208203
"type_name" => {
209-
let tp_ty = substs.type_at(0);
210-
let ty_name = self.tcx.type_name(tp_ty);
204+
let gid = GlobalId {
205+
instance,
206+
promoted: None,
207+
};
208+
let ty_name = self.tcx.const_eval(ty::ParamEnv::reveal_all().and(gid)).unwrap();
211209
OperandRef::from_const(self, ty_name).immediate_or_packed_pair(self)
212210
}
213-
"type_id" => {
214-
self.const_u64(self.tcx.type_id_hash(substs.type_at(0)))
215-
}
216211
"init" => {
217212
let ty = substs.type_at(0);
218213
if !self.layout_of(ty).is_zst() {
@@ -235,11 +230,6 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
235230
"uninit" | "forget" => {
236231
return;
237232
}
238-
"needs_drop" => {
239-
let tp_ty = substs.type_at(0);
240-
241-
self.const_bool(self.type_needs_drop(tp_ty))
242-
}
243233
"offset" => {
244234
let ptr = args[0].immediate();
245235
let offset = args[1].immediate();

src/librustc_codegen_ssa/mir/block.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
668668
}).collect();
669669

670670

671-
let callee_ty = instance.as_ref().unwrap().ty(bx.tcx());
672-
bx.codegen_intrinsic_call(callee_ty, &fn_ty, &args, dest,
671+
bx.codegen_intrinsic_call(*instance.as_ref().unwrap(), &fn_ty, &args, dest,
673672
terminator.source_info.span);
674673

675674
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {

src/librustc_codegen_ssa/traits/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::BackendTypes;
22
use crate::mir::operand::OperandRef;
3-
use rustc::ty::Ty;
3+
use rustc::ty::{self, Ty};
44
use rustc_target::abi::call::FnType;
55
use syntax_pos::Span;
66

@@ -10,7 +10,7 @@ pub trait IntrinsicCallMethods<'tcx>: BackendTypes {
1010
/// add them to librustc_codegen_llvm/context.rs
1111
fn codegen_intrinsic_call(
1212
&mut self,
13-
callee_ty: Ty<'tcx>,
13+
instance: ty::Instance<'tcx>,
1414
fn_ty: &FnType<'tcx, Ty<'tcx>>,
1515
args: &[OperandRef<'tcx, Self::Value>],
1616
llresult: Self::Value,

src/librustc_mir/const_eval.rs

+70-52
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc::ty::{self, Ty, TyCtxt, subst::Subst};
1515
use rustc::ty::layout::{self, LayoutOf, VariantIdx};
1616
use rustc::traits::Reveal;
1717
use rustc_data_structures::fx::FxHashMap;
18+
use crate::interpret::eval_nullary_intrinsic;
1819

1920
use syntax::source_map::{Span, DUMMY_SP};
2021

@@ -604,6 +605,23 @@ pub fn const_eval_provider<'tcx>(
604605
other => return other,
605606
}
606607
}
608+
609+
// We call `const_eval` for zero arg intrinsics, too, in order to cache their value.
610+
// Catch such calls and evaluate them instead of trying to load a constant's MIR.
611+
if let ty::InstanceDef::Intrinsic(def_id) = key.value.instance.def {
612+
let ty = key.value.instance.ty(tcx);
613+
let substs = match ty.sty {
614+
ty::FnDef(_, substs) => substs,
615+
_ => bug!("intrinsic with type {:?}", ty),
616+
};
617+
return eval_nullary_intrinsic(tcx, key.param_env, def_id, substs)
618+
.map_err(|error| {
619+
let span = tcx.def_span(def_id);
620+
let error = ConstEvalErr { error: error.kind, stacktrace: vec![], span };
621+
error.report_as_error(tcx.at(span), "could not evaluate nullary intrinsic")
622+
})
623+
}
624+
607625
tcx.const_eval_raw(key).and_then(|val| {
608626
validate_and_turn_into_const(tcx, val, key)
609627
})
@@ -666,63 +684,63 @@ pub fn const_eval_raw_provider<'tcx>(
666684
})
667685
}).map_err(|error| {
668686
let err = error_to_const_error(&ecx, error);
669-
// errors in statics are always emitted as fatal errors
670-
if tcx.is_static(def_id) {
671-
// Ensure that if the above error was either `TooGeneric` or `Reported`
672-
// an error must be reported.
687+
// errors in statics are always emitted as fatal errors
688+
if tcx.is_static(def_id) {
689+
// Ensure that if the above error was either `TooGeneric` or `Reported`
690+
// an error must be reported.
673691
let v = err.report_as_error(ecx.tcx, "could not evaluate static initializer");
674-
tcx.sess.delay_span_bug(
675-
err.span,
676-
&format!("static eval failure did not emit an error: {:#?}", v)
677-
);
678-
v
679-
} else if def_id.is_local() {
680-
// constant defined in this crate, we can figure out a lint level!
681-
match tcx.def_kind(def_id) {
682-
// constants never produce a hard error at the definition site. Anything else is
683-
// a backwards compatibility hazard (and will break old versions of winapi for sure)
684-
//
685-
// note that validation may still cause a hard error on this very same constant,
686-
// because any code that existed before validation could not have failed validation
687-
// thus preventing such a hard error from being a backwards compatibility hazard
688-
Some(DefKind::Const) | Some(DefKind::AssocConst) => {
689-
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
692+
tcx.sess.delay_span_bug(
693+
err.span,
694+
&format!("static eval failure did not emit an error: {:#?}", v)
695+
);
696+
v
697+
} else if def_id.is_local() {
698+
// constant defined in this crate, we can figure out a lint level!
699+
match tcx.def_kind(def_id) {
700+
// constants never produce a hard error at the definition site. Anything else is
701+
// a backwards compatibility hazard (and will break old versions of winapi for sure)
702+
//
703+
// note that validation may still cause a hard error on this very same constant,
704+
// because any code that existed before validation could not have failed validation
705+
// thus preventing such a hard error from being a backwards compatibility hazard
706+
Some(DefKind::Const) | Some(DefKind::AssocConst) => {
707+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
708+
err.report_as_lint(
709+
tcx.at(tcx.def_span(def_id)),
710+
"any use of this value will cause an error",
711+
hir_id,
712+
Some(err.span),
713+
)
714+
},
715+
// promoting runtime code is only allowed to error if it references broken constants
716+
// any other kind of error will be reported to the user as a deny-by-default lint
717+
_ => if let Some(p) = cid.promoted {
718+
let span = tcx.promoted_mir(def_id)[p].span;
719+
if let err_inval!(ReferencedConstant) = err.error {
720+
err.report_as_error(
721+
tcx.at(span),
722+
"evaluation of constant expression failed",
723+
)
724+
} else {
690725
err.report_as_lint(
691-
tcx.at(tcx.def_span(def_id)),
692-
"any use of this value will cause an error",
693-
hir_id,
726+
tcx.at(span),
727+
"reaching this expression at runtime will panic or abort",
728+
tcx.hir().as_local_hir_id(def_id).unwrap(),
694729
Some(err.span),
695730
)
696-
},
697-
// promoting runtime code is only allowed to error if it references broken constants
698-
// any other kind of error will be reported to the user as a deny-by-default lint
699-
_ => if let Some(p) = cid.promoted {
700-
let span = tcx.promoted_mir(def_id)[p].span;
701-
if let err_inval!(ReferencedConstant) = err.error {
702-
err.report_as_error(
703-
tcx.at(span),
704-
"evaluation of constant expression failed",
705-
)
706-
} else {
707-
err.report_as_lint(
708-
tcx.at(span),
709-
"reaching this expression at runtime will panic or abort",
710-
tcx.hir().as_local_hir_id(def_id).unwrap(),
711-
Some(err.span),
712-
)
713-
}
714-
// anything else (array lengths, enum initializers, constant patterns) are reported
715-
// as hard errors
716-
} else {
717-
err.report_as_error(
731+
}
732+
// anything else (array lengths, enum initializers, constant patterns) are reported
733+
// as hard errors
734+
} else {
735+
err.report_as_error(
718736
ecx.tcx,
719-
"evaluation of constant value failed",
720-
)
721-
},
722-
}
723-
} else {
724-
// use of broken constant from other crate
725-
err.report_as_error(ecx.tcx, "could not evaluate constant")
737+
"evaluation of constant value failed",
738+
)
739+
},
726740
}
741+
} else {
742+
// use of broken constant from other crate
743+
err.report_as_error(ecx.tcx, "could not evaluate constant")
744+
}
727745
})
728746
}

src/librustc_mir/interpret/eval_context.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
1414
use rustc::ty::query::TyCtxtAt;
1515
use rustc_data_structures::indexed_vec::IndexVec;
1616
use rustc::mir::interpret::{
17-
ErrorHandled,
1817
GlobalId, Scalar, Pointer, FrameInfo, AllocId,
1918
InterpResult, truncate, sign_extend,
2019
};
@@ -669,14 +668,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
669668
// Our result will later be validated anyway, and there seems no good reason
670669
// to have to fail early here. This is also more consistent with
671670
// `Memory::get_static_alloc` which has to use `const_eval_raw` to avoid cycles.
672-
let val = self.tcx.const_eval_raw(param_env.and(gid)).map_err(|err| {
673-
match err {
674-
ErrorHandled::Reported =>
675-
err_inval!(ReferencedConstant),
676-
ErrorHandled::TooGeneric =>
677-
err_inval!(TooGeneric),
678-
}
679-
})?;
671+
let val = self.tcx.const_eval_raw(param_env.and(gid))?;
680672
self.raw_const_to_mplace(val)
681673
}
682674

0 commit comments

Comments
 (0)