Skip to content

Commit 278067d

Browse files
committed
Auto merge of #57879 - Centril:rollup, r=Centril
Rollup of 9 pull requests Successful merges: - #57380 (Fix Instant/Duration math precision & associativity on Windows) - #57606 (Get rid of the fake stack frame for reading from constants) - #57803 (Several changes to libunwind for SGX target) - #57846 (rustdoc: fix ICE from loading proc-macro stubs) - #57860 (Add os::fortanix_sgx::ffi module) - #57861 (Don't export table by default in wasm) - #57863 (Add suggestion for incorrect field syntax.) - #57867 (Fix std::future::from_generator documentation) - #57873 (Stabilize no_panic_pow) Failed merges: r? @ghost
2 parents 01f8e25 + 5fa1016 commit 278067d

File tree

28 files changed

+432
-172
lines changed

28 files changed

+432
-172
lines changed

src/ci/docker/dist-various-2/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN /tmp/build-solaris-toolchain.sh sparcv9 sparcv9 solaris-sparc
3232
COPY dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh /tmp/
3333
# We pass the commit id of the port of LLVM's libunwind to the build script.
3434
# Any update to the commit id here, should cause the container image to be re-built from this point on.
35-
RUN /tmp/build-x86_64-fortanix-unknown-sgx-toolchain.sh "bbe23902411be88d7388f381becefadd6e3ef819"
35+
RUN /tmp/build-x86_64-fortanix-unknown-sgx-toolchain.sh "13fad13f8ea83a8da58d04a5faa45943151b3398"
3636

3737
COPY scripts/sccache.sh /scripts/
3838
RUN sh /scripts/sccache.sh

src/libcore/num/mod.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -847,13 +847,12 @@ overflow occurred.
847847
Basic usage:
848848
849849
```
850-
#![feature(no_panic_pow)]
851850
", $Feature, "assert_eq!(8", stringify!($SelfT), ".checked_pow(2), Some(64));
852851
assert_eq!(", stringify!($SelfT), "::max_value().checked_pow(2), None);",
853852
$EndFeature, "
854853
```"),
855854

856-
#[unstable(feature = "no_panic_pow", issue = "48320")]
855+
#[stable(feature = "no_panic_pow", since = "1.34.0")]
857856
#[inline]
858857
pub fn checked_pow(self, mut exp: u32) -> Option<Self> {
859858
let mut base = self;
@@ -966,15 +965,14 @@ saturating at the numeric bounds instead of overflowing.
966965
Basic usage:
967966
968967
```
969-
#![feature(no_panic_pow)]
970968
", $Feature, "use std::", stringify!($SelfT), ";
971969
972970
assert_eq!((-4", stringify!($SelfT), ").saturating_pow(3), -64);
973971
assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(2), ", stringify!($SelfT), "::MAX);
974972
assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(3), ", stringify!($SelfT), "::MIN);",
975973
$EndFeature, "
976974
```"),
977-
#[unstable(feature = "no_panic_pow", issue = "48320")]
975+
#[stable(feature = "no_panic_pow", since = "1.34.0")]
978976
#[inline]
979977
pub fn saturating_pow(self, exp: u32) -> Self {
980978
match self.checked_pow(exp) {
@@ -1297,13 +1295,12 @@ wrapping around at the boundary of the type.
12971295
Basic usage:
12981296
12991297
```
1300-
#![feature(no_panic_pow)]
13011298
", $Feature, "assert_eq!(3", stringify!($SelfT), ".wrapping_pow(4), 81);
13021299
assert_eq!(3i8.wrapping_pow(5), -13);
13031300
assert_eq!(3i8.wrapping_pow(6), -39);",
13041301
$EndFeature, "
13051302
```"),
1306-
#[unstable(feature = "no_panic_pow", issue = "48320")]
1303+
#[stable(feature = "no_panic_pow", since = "1.34.0")]
13071304
#[inline]
13081305
pub fn wrapping_pow(self, mut exp: u32) -> Self {
13091306
let mut base = self;
@@ -1669,12 +1666,11 @@ whether an overflow happened.
16691666
Basic usage:
16701667
16711668
```
1672-
#![feature(no_panic_pow)]
16731669
", $Feature, "assert_eq!(3", stringify!($SelfT), ".overflowing_pow(4), (81, false));
16741670
assert_eq!(3i8.overflowing_pow(5), (-13, true));",
16751671
$EndFeature, "
16761672
```"),
1677-
#[unstable(feature = "no_panic_pow", issue = "48320")]
1673+
#[stable(feature = "no_panic_pow", since = "1.34.0")]
16781674
#[inline]
16791675
pub fn overflowing_pow(self, mut exp: u32) -> (Self, bool) {
16801676
let mut base = self;
@@ -2789,11 +2785,10 @@ overflow occurred.
27892785
Basic usage:
27902786
27912787
```
2792-
#![feature(no_panic_pow)]
27932788
", $Feature, "assert_eq!(2", stringify!($SelfT), ".checked_pow(5), Some(32));
27942789
assert_eq!(", stringify!($SelfT), "::max_value().checked_pow(2), None);", $EndFeature, "
27952790
```"),
2796-
#[unstable(feature = "no_panic_pow", issue = "48320")]
2791+
#[stable(feature = "no_panic_pow", since = "1.34.0")]
27972792
#[inline]
27982793
pub fn checked_pow(self, mut exp: u32) -> Option<Self> {
27992794
let mut base = self;
@@ -2893,14 +2888,13 @@ saturating at the numeric bounds instead of overflowing.
28932888
Basic usage:
28942889
28952890
```
2896-
#![feature(no_panic_pow)]
28972891
", $Feature, "use std::", stringify!($SelfT), ";
28982892
28992893
assert_eq!(4", stringify!($SelfT), ".saturating_pow(3), 64);
29002894
assert_eq!(", stringify!($SelfT), "::MAX.saturating_pow(2), ", stringify!($SelfT), "::MAX);",
29012895
$EndFeature, "
29022896
```"),
2903-
#[unstable(feature = "no_panic_pow", issue = "48320")]
2897+
#[stable(feature = "no_panic_pow", since = "1.34.0")]
29042898
#[inline]
29052899
pub fn saturating_pow(self, exp: u32) -> Self {
29062900
match self.checked_pow(exp) {
@@ -3178,11 +3172,10 @@ wrapping around at the boundary of the type.
31783172
Basic usage:
31793173
31803174
```
3181-
#![feature(no_panic_pow)]
31823175
", $Feature, "assert_eq!(3", stringify!($SelfT), ".wrapping_pow(5), 243);
31833176
assert_eq!(3u8.wrapping_pow(6), 217);", $EndFeature, "
31843177
```"),
3185-
#[unstable(feature = "no_panic_pow", issue = "48320")]
3178+
#[stable(feature = "no_panic_pow", since = "1.34.0")]
31863179
#[inline]
31873180
pub fn wrapping_pow(self, mut exp: u32) -> Self {
31883181
let mut base = self;
@@ -3497,11 +3490,10 @@ whether an overflow happened.
34973490
Basic usage:
34983491
34993492
```
3500-
#![feature(no_panic_pow)]
35013493
", $Feature, "assert_eq!(3", stringify!($SelfT), ".overflowing_pow(5), (243, false));
35023494
assert_eq!(3u8.overflowing_pow(6), (217, true));", $EndFeature, "
35033495
```"),
3504-
#[unstable(feature = "no_panic_pow", issue = "48320")]
3496+
#[stable(feature = "no_panic_pow", since = "1.34.0")]
35053497
#[inline]
35063498
pub fn overflowing_pow(self, mut exp: u32) -> (Self, bool) {
35073499
let mut base = self;

src/librustc_codegen_ssa/back/linker.rs

-3
Original file line numberDiff line numberDiff line change
@@ -911,9 +911,6 @@ impl<'a> WasmLd<'a> {
911911
// For now we just never have an entry symbol
912912
cmd.arg("--no-entry");
913913

914-
// Make the default table accessible
915-
cmd.arg("--export-table");
916-
917914
// Rust code should never have warnings, and warnings are often
918915
// indicative of bugs, let's prevent them.
919916
cmd.arg("--fatal-warnings");

src/librustc_codegen_ssa/mir/constant.rs

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5959
let field = const_field(
6060
bx.tcx(),
6161
ty::ParamEnv::reveal_all(),
62-
self.instance,
6362
None,
6463
mir::Field::new(field as usize),
6564
c,

src/librustc_mir/const_eval.rs

+13-67
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ use rustc::hir::{self, def_id::DefId};
1010
use rustc::hir::def::Def;
1111
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled};
1212
use rustc::mir;
13-
use rustc::ty::{self, TyCtxt, Instance, query::TyCtxtAt};
13+
use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
1414
use rustc::ty::layout::{self, LayoutOf, TyLayout, VariantIdx};
1515
use rustc::ty::subst::Subst;
1616
use rustc::traits::Reveal;
17-
use rustc_data_structures::indexed_vec::IndexVec;
1817
use rustc_data_structures::fx::FxHashMap;
1918
use rustc::util::common::ErrorReported;
2019

@@ -35,72 +34,20 @@ const STEPS_UNTIL_DETECTOR_ENABLED: isize = 1_000_000;
3534
/// Should be a power of two for performance reasons.
3635
const DETECTOR_SNAPSHOT_PERIOD: isize = 256;
3736

38-
/// Warning: do not use this function if you expect to start interpreting the given `Mir`.
39-
/// The `EvalContext` is only meant to be used to query values from constants and statics.
40-
///
41-
/// This function is used during const propagation. We cannot use `mk_eval_cx`, because copy
42-
/// propagation happens *during* the computation of the MIR of the current function. So if we
43-
/// tried to call the `optimized_mir` query, we'd get a cycle error because we are (transitively)
44-
/// inside the `optimized_mir` query of the `Instance` given.
45-
///
46-
/// Since we are looking at the MIR of the function in an abstract manner, we don't have a
47-
/// `ParamEnv` available to us. This function creates a `ParamEnv` for the given instance.
48-
pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>(
49-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
50-
instance: Instance<'tcx>,
51-
mir: &'mir mir::Mir<'tcx>,
52-
span: Span,
53-
) -> EvalResult<'tcx, CompileTimeEvalContext<'a, 'mir, 'tcx>> {
54-
debug!("mk_borrowck_eval_cx: {:?}", instance);
55-
let param_env = tcx.param_env(instance.def_id());
56-
mk_eval_cx_inner(tcx, instance, mir, span, param_env)
57-
}
58-
59-
/// This is just a helper function to reduce code duplication between `mk_borrowck_eval_cx` and
60-
/// `mk_eval_cx`. Do not call this function directly.
61-
fn mk_eval_cx_inner<'a, 'mir, 'tcx>(
62-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
63-
instance: Instance<'tcx>,
64-
mir: &'mir mir::Mir<'tcx>,
65-
span: Span,
66-
param_env: ty::ParamEnv<'tcx>,
67-
) -> EvalResult<'tcx, CompileTimeEvalContext<'a, 'mir, 'tcx>> {
68-
let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new());
69-
// Insert a stack frame so any queries have the correct substs.
70-
// We also avoid all the extra work performed by push_stack_frame,
71-
// like initializing local variables
72-
ecx.stack.push(interpret::Frame {
73-
block: mir::START_BLOCK,
74-
locals: IndexVec::new(),
75-
local_layouts: IndexVec::new(),
76-
instance,
77-
span,
78-
mir,
79-
return_place: None,
80-
return_to_block: StackPopCleanup::Goto(None), // never pop
81-
stmt: 0,
82-
extra: (),
83-
});
84-
Ok(ecx)
85-
}
86-
87-
/// Warning: do not use this function if you expect to start interpreting the given `Mir`.
8837
/// The `EvalContext` is only meant to be used to do field and index projections into constants for
8938
/// `simd_shuffle` and const patterns in match arms.
9039
///
9140
/// The function containing the `match` that is currently being analyzed may have generic bounds
9241
/// that inform us about the generic bounds of the constant. E.g. using an associated constant
9342
/// of a function's generic parameter will require knowledge about the bounds on the generic
9443
/// parameter. These bounds are passed to `mk_eval_cx` via the `ParamEnv` argument.
95-
fn mk_eval_cx<'a, 'tcx>(
44+
pub(crate) fn mk_eval_cx<'a, 'mir, 'tcx>(
9645
tcx: TyCtxt<'a, 'tcx, 'tcx>,
97-
instance: Instance<'tcx>,
46+
span: Span,
9847
param_env: ty::ParamEnv<'tcx>,
99-
) -> EvalResult<'tcx, CompileTimeEvalContext<'a, 'tcx, 'tcx>> {
100-
debug!("mk_eval_cx: {:?}, {:?}", instance, param_env);
101-
let span = tcx.def_span(instance.def_id());
102-
let mir = tcx.optimized_mir(instance.def.def_id());
103-
mk_eval_cx_inner(tcx, instance, mir, span, param_env)
48+
) -> CompileTimeEvalContext<'a, 'mir, 'tcx> {
49+
debug!("mk_eval_cx: {:?}", param_env);
50+
EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new())
10451
}
10552

10653
pub(crate) fn eval_promoted<'a, 'mir, 'tcx>(
@@ -109,7 +56,8 @@ pub(crate) fn eval_promoted<'a, 'mir, 'tcx>(
10956
mir: &'mir mir::Mir<'tcx>,
11057
param_env: ty::ParamEnv<'tcx>,
11158
) -> EvalResult<'tcx, MPlaceTy<'tcx>> {
112-
let mut ecx = mk_borrowck_eval_cx(tcx, cid.instance, mir, DUMMY_SP).unwrap();
59+
let span = tcx.def_span(cid.instance.def_id());
60+
let mut ecx = mk_eval_cx(tcx, span, param_env);
11361
eval_body_using_ecx(&mut ecx, cid, Some(mir), param_env)
11462
}
11563

@@ -530,13 +478,12 @@ impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx>
530478
pub fn const_field<'a, 'tcx>(
531479
tcx: TyCtxt<'a, 'tcx, 'tcx>,
532480
param_env: ty::ParamEnv<'tcx>,
533-
instance: ty::Instance<'tcx>,
534481
variant: Option<VariantIdx>,
535482
field: mir::Field,
536483
value: ty::Const<'tcx>,
537484
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
538-
trace!("const_field: {:?}, {:?}, {:?}", instance, field, value);
539-
let ecx = mk_eval_cx(tcx, instance, param_env).unwrap();
485+
trace!("const_field: {:?}, {:?}", field, value);
486+
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env);
540487
let result = (|| {
541488
// get the operand again
542489
let op = lazy_const_to_op(&ecx, ty::LazyConst::Evaluated(value), value.ty)?;
@@ -561,11 +508,10 @@ pub fn const_field<'a, 'tcx>(
561508
pub fn const_variant_index<'a, 'tcx>(
562509
tcx: TyCtxt<'a, 'tcx, 'tcx>,
563510
param_env: ty::ParamEnv<'tcx>,
564-
instance: ty::Instance<'tcx>,
565511
val: ty::Const<'tcx>,
566512
) -> EvalResult<'tcx, VariantIdx> {
567-
trace!("const_variant_index: {:?}, {:?}", instance, val);
568-
let ecx = mk_eval_cx(tcx, instance, param_env).unwrap();
513+
trace!("const_variant_index: {:?}", val);
514+
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env);
569515
let op = lazy_const_to_op(&ecx, ty::LazyConst::Evaluated(val), val.ty)?;
570516
Ok(ecx.read_discriminant(op)?.1)
571517
}
@@ -585,7 +531,7 @@ fn validate_and_turn_into_const<'a, 'tcx>(
585531
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
586532
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
587533
let cid = key.value;
588-
let ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap();
534+
let ecx = mk_eval_cx(tcx, tcx.def_span(key.value.instance.def_id()), key.param_env);
589535
let val = (|| {
590536
let op = ecx.raw_const_to_mplace(constant)?.into();
591537
// FIXME: Once the visitor infrastructure landed, change validation to

src/librustc_mir/hair/pattern/_match.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,24 @@ pub enum Constructor<'tcx> {
427427
}
428428

429429
impl<'tcx> Constructor<'tcx> {
430-
fn variant_index_for_adt(&self, adt: &'tcx ty::AdtDef) -> VariantIdx {
430+
fn variant_index_for_adt<'a>(
431+
&self,
432+
cx: &MatchCheckCtxt<'a, 'tcx>,
433+
adt: &'tcx ty::AdtDef,
434+
) -> VariantIdx {
431435
match self {
432436
&Variant(vid) => adt.variant_index_with_id(vid),
433437
&Single => {
434438
assert!(!adt.is_enum());
435439
VariantIdx::new(0)
436440
}
441+
&ConstantValue(c) => {
442+
::const_eval::const_variant_index(
443+
cx.tcx,
444+
cx.param_env,
445+
c,
446+
).unwrap()
447+
},
437448
_ => bug!("bad constructor {:?} for adt {:?}", self, adt)
438449
}
439450
}
@@ -567,7 +578,7 @@ impl<'tcx> Witness<'tcx> {
567578
PatternKind::Variant {
568579
adt_def: adt,
569580
substs,
570-
variant_index: ctor.variant_index_for_adt(adt),
581+
variant_index: ctor.variant_index_for_adt(cx, adt),
571582
subpatterns: pats
572583
}
573584
} else {
@@ -1329,7 +1340,7 @@ fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>,
13291340
///
13301341
/// For instance, a tuple pattern (_, 42, Some([])) has the arity of 3.
13311342
/// A struct pattern's arity is the number of fields it contains, etc.
1332-
fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> u64 {
1343+
fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty: Ty<'tcx>) -> u64 {
13331344
debug!("constructor_arity({:#?}, {:?})", ctor, ty);
13341345
match ty.sty {
13351346
ty::Tuple(ref fs) => fs.len() as u64,
@@ -1340,7 +1351,7 @@ fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> u64 {
13401351
},
13411352
ty::Ref(..) => 1,
13421353
ty::Adt(adt, _) => {
1343-
adt.variants[ctor.variant_index_for_adt(adt)].fields.len() as u64
1354+
adt.variants[ctor.variant_index_for_adt(cx, adt)].fields.len() as u64
13441355
}
13451356
_ => 0
13461357
}
@@ -1351,7 +1362,7 @@ fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> u64 {
13511362
///
13521363
/// For instance, a tuple pattern (43u32, 'a') has sub pattern types [u32, char].
13531364
fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>,
1354-
ctor: &Constructor,
1365+
ctor: &Constructor<'tcx>,
13551366
ty: Ty<'tcx>) -> Vec<Ty<'tcx>>
13561367
{
13571368
debug!("constructor_sub_pattern_tys({:#?}, {:?})", ctor, ty);
@@ -1368,7 +1379,7 @@ fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>,
13681379
// Use T as the sub pattern type of Box<T>.
13691380
vec![substs.type_at(0)]
13701381
} else {
1371-
adt.variants[ctor.variant_index_for_adt(adt)].fields.iter().map(|field| {
1382+
adt.variants[ctor.variant_index_for_adt(cx, adt)].fields.iter().map(|field| {
13721383
let is_visible = adt.is_enum()
13731384
|| field.vis.is_accessible_from(cx.module, cx.tcx);
13741385
if is_visible {

src/librustc_mir/hair/pattern/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
885885
let adt_subpattern = |i, variant_opt| {
886886
let field = Field::new(i);
887887
let val = const_field(
888-
self.tcx, self.param_env, instance,
888+
self.tcx, self.param_env,
889889
variant_opt, field, cv,
890890
).expect("field access failed");
891891
self.const_to_pat(instance, val, id, span)
@@ -928,7 +928,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
928928
},
929929
ty::Adt(adt_def, substs) if adt_def.is_enum() => {
930930
let variant_index = const_variant_index(
931-
self.tcx, self.param_env, instance, cv
931+
self.tcx, self.param_env, cv
932932
).expect("const_variant_index failed");
933933
let subpatterns = adt_subpatterns(
934934
adt_def.variants[variant_index].fields.len(),

src/librustc_mir/interpret/cast.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
109109
// The src operand does not matter, just its type
110110
match src.layout.ty.sty {
111111
ty::Closure(def_id, substs) => {
112-
let substs = self.tcx.subst_and_normalize_erasing_regions(
113-
self.substs(),
114-
ty::ParamEnv::reveal_all(),
115-
&substs,
116-
);
112+
let substs = self.subst_and_normalize_erasing_regions(substs)?;
117113
let instance = ty::Instance::resolve_closure(
118114
*self.tcx,
119115
def_id,

0 commit comments

Comments
 (0)