Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #105331

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
51ac2af
interpret: clobber return place when calling function
RalfJung Dec 3, 2022
5b8f741
Remove unneeded field from `SwitchTargets`
JakobDegen Dec 4, 2022
c823dfa
remove no-op 'let _ = '
RalfJung Dec 4, 2022
01a4898
Fix --pass in compiletest
JakobDegen Dec 4, 2022
44948d1
Recurse into nested impl-trait when computing variance.
cjgillot Dec 4, 2022
6cc86db
Add small comment explaining what `method-margins.goml` test is about
GuillaumeGomez Dec 4, 2022
5811057
fix dupe word typos
Rageking8 Dec 5, 2022
9dbb189
Replace usage of `ResumeTy` in async lowering with `Context`
Swatinem Dec 4, 2022
65072ee
rustdoc: remove no-op mobile CSS `.sidebar { margin: 0; padding: 0 }`
notriddle Dec 5, 2022
a192284
Update books
rustbot Dec 5, 2022
d5cb5fb
normalize inherent associated types after substitution
fmease Dec 5, 2022
f532ae6
Rollup merge of #105207 - RalfJung:interpret-clobber-return, r=oli-obk
matthiaskrgr Dec 5, 2022
d8ca0a6
Rollup merge of #105234 - JakobDegen:unneeded-field, r=oli-obk
matthiaskrgr Dec 5, 2022
4ba15b2
Rollup merge of #105243 - RalfJung:no-op-let, r=Mark-Simulacrum
matthiaskrgr Dec 5, 2022
bcedb5b
Rollup merge of #105246 - JakobDegen:run-mir-tests, r=jyn514
matthiaskrgr Dec 5, 2022
3566eb4
Rollup merge of #105250 - Swatinem:async-rm-resumety, r=oli-obk
matthiaskrgr Dec 5, 2022
361ea42
Rollup merge of #105254 - cjgillot:issue-105251, r=oli-obk
matthiaskrgr Dec 5, 2022
c46b162
Rollup merge of #105256 - GuillaumeGomez:comment-method-margins, r=no…
matthiaskrgr Dec 5, 2022
fbf5d8e
Rollup merge of #105289 - Rageking8:fix-dupe-word-typos, r=cjgillot
matthiaskrgr Dec 5, 2022
e8a29dd
Rollup merge of #105309 - notriddle:notriddle/sidebar-margin-padding,…
matthiaskrgr Dec 5, 2022
8d90e63
Rollup merge of #105313 - rustbot:docs-update, r=ehuss
matthiaskrgr Dec 5, 2022
22680a9
Rollup merge of #105315 - fmease:norm-subst-iat, r=compiler-errors
matthiaskrgr Dec 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_hir::def::Res;
use rustc_hir::definitions::DefPathData;
use rustc_session::errors::report_lit_error;
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
use rustc_span::symbol::{sym, Ident};
use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::DUMMY_SP;
use thin_vec::thin_vec;

Expand Down Expand Up @@ -592,14 +592,38 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> hir::ExprKind<'hir> {
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));

// Resume argument type: `ResumeTy`
let unstable_span =
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span, None);
// Resume argument type, which should be `&mut Context<'_>`.
// NOTE: Using the `'static` lifetime here is technically cheating.
// The `Future::poll` argument really is `&'a mut Context<'b>`, but we cannot
// express the fact that we are not storing it across yield-points yet,
// and we would thus run into lifetime errors.
// See <https://github.com/rust-lang/rust/issues/68923>.
// Our lowering makes sure we are not mis-using the `_task_context` input type
// in the sense that we are indeed not using it across yield points. We
// get a fresh `&mut Context` for each resume / call of `Future::poll`.
// This "cheating" was previously done with a `ResumeTy` that contained a raw
// pointer, and a `get_context` accessor that pulled the `Context` lifetimes
// out of thin air.
let context_lifetime_ident = Ident::with_dummy_span(kw::StaticLifetime);
let context_lifetime = self.arena.alloc(hir::Lifetime {
hir_id: self.next_id(),
ident: context_lifetime_ident,
res: hir::LifetimeName::Static,
});
let context_path =
hir::QPath::LangItem(hir::LangItem::Context, self.lower_span(span), None);
let context_ty = hir::MutTy {
ty: self.arena.alloc(hir::Ty {
hir_id: self.next_id(),
kind: hir::TyKind::Path(context_path),
span: self.lower_span(span),
}),
mutbl: hir::Mutability::Mut,
};
let input_ty = hir::Ty {
hir_id: self.next_id(),
kind: hir::TyKind::Path(resume_ty),
span: unstable_span,
kind: hir::TyKind::Rptr(context_lifetime, context_ty),
span: self.lower_span(span),
};

// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
Expand Down Expand Up @@ -710,7 +734,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
/// mut __awaitee => loop {
/// match unsafe { ::std::future::Future::poll(
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
/// ::std::future::get_context(task_context),
/// task_context,
/// ) } {
/// ::std::task::Poll::Ready(result) => break result,
/// ::std::task::Poll::Pending => {}
Expand Down Expand Up @@ -751,7 +775,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// unsafe {
// ::std::future::Future::poll(
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
// ::std::future::get_context(task_context),
// task_context,
// )
// }
let poll_expr = {
Expand All @@ -769,16 +793,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
arena_vec![self; ref_mut_awaitee],
Some(expr_hir_id),
);
let get_context = self.expr_call_lang_item_fn_mut(
gen_future_span,
hir::LangItem::GetContext,
arena_vec![self; task_context],
Some(expr_hir_id),
);
let call = self.expr_call_lang_item_fn(
span,
hir::LangItem::FuturePoll,
arena_vec![self; new_unchecked, get_context],
arena_vec![self; new_unchecked, task_context],
Some(expr_hir_id),
);
self.arena.alloc(self.expr_unsafe(call))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
self.check_activations(location);

match &terminator.kind {
TerminatorKind::SwitchInt { ref discr, switch_ty: _, targets: _ } => {
TerminatorKind::SwitchInt { ref discr, targets: _ } => {
self.consume_operand(location, discr);
}
TerminatorKind::Drop { place: drop_place, target: _, unwind: _ } => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
self.check_activations(loc, span, flow_state);

match term.kind {
TerminatorKind::SwitchInt { ref discr, switch_ty: _, targets: _ } => {
TerminatorKind::SwitchInt { ref discr, targets: _ } => {
self.consume_operand(loc, (discr, span), flow_state);
}
TerminatorKind::Drop { place, target: _, unwind: _ } => {
Expand Down
19 changes: 2 additions & 17 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,25 +1360,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);
}
}
TerminatorKind::SwitchInt { ref discr, switch_ty, .. } => {
TerminatorKind::SwitchInt { ref discr, .. } => {
self.check_operand(discr, term_location);

let discr_ty = discr.ty(body, tcx);
if let Err(terr) = self.sub_types(
discr_ty,
switch_ty,
term_location.to_locations(),
ConstraintCategory::Assignment,
) {
span_mirbug!(
self,
term,
"bad SwitchInt ({:?} on {:?}): {:?}",
switch_ty,
discr_ty,
terr
);
}
let switch_ty = discr.ty(body, tcx);
if !switch_ty.is_integral() && !switch_ty.is_char() && !switch_ty.is_bool() {
span_mirbug!(self, term, "bad SwitchInt discr ty {:?}", switch_ty);
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
}
}

TerminatorKind::SwitchInt { discr, switch_ty, targets } => {
let discr = codegen_operand(fx, discr).load_scalar(fx);
TerminatorKind::SwitchInt { discr, targets } => {
let discr = codegen_operand(fx, discr);
let switch_ty = discr.layout().ty;
let discr = discr.load_scalar(fx);

let use_bool_opt = switch_ty.kind() == fx.tcx.types.bool.kind()
|| (targets.iter().count() == 1 && targets.iter().next().unwrap().0 == 0);
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
helper: TerminatorCodegenHelper<'tcx>,
bx: &mut Bx,
discr: &mir::Operand<'tcx>,
switch_ty: Ty<'tcx>,
targets: &SwitchTargets,
) {
let discr = self.codegen_operand(bx, &discr);
// `switch_ty` is redundant, sanity-check that.
assert_eq!(discr.layout.ty, switch_ty);
let switch_ty = discr.layout.ty;
let mut target_iter = targets.iter();
if target_iter.len() == 1 {
// If there are two targets (one conditional, one fallback), emit `br` instead of
Expand Down Expand Up @@ -1293,8 +1291,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
helper.funclet_br(self, bx, target, mergeable_succ())
}

mir::TerminatorKind::SwitchInt { ref discr, switch_ty, ref targets } => {
self.codegen_switchint_terminator(helper, bx, discr, switch_ty, targets);
mir::TerminatorKind::SwitchInt { ref discr, ref targets } => {
self.codegen_switchint_terminator(helper, bx, discr, targets);
MergingSucc::False
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
let align = ImmTy::from_uint(target_align, args[1].layout).into();
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?;

// We replace the entire entire function call with a "tail call".
// We replace the entire function call with a "tail call".
// Note that this happens before the frame of the original function
// is pushed on the stack.
self.eval_fn_call(
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
return_to_block: StackPopCleanup,
) -> InterpResult<'tcx> {
trace!("body: {:#?}", body);
// Clobber previous return place contents, nobody is supposed to be able to see them any more
// This also checks dereferenceable, but not align. We rely on all constructed places being
// sufficiently aligned (in particular we rely on `deref_operand` checking alignment).
self.write_uninit(return_place)?;
// first push a stack frame so we have access to the local substs
let pre_frame = Frame {
body,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

Goto { target } => self.go_to_block(target),

SwitchInt { ref discr, ref targets, switch_ty } => {
SwitchInt { ref discr, ref targets } => {
let discr = self.read_immediate(&self.eval_operand(discr, None)?)?;
trace!("SwitchInt({:?})", *discr);
assert_eq!(discr.layout.ty, switch_ty);

// Branch to the `otherwise` case by default, if no match is found.
let mut target_block = targets.otherwise();
Expand Down
13 changes: 2 additions & 11 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,17 +682,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
TerminatorKind::Goto { target } => {
self.check_edge(location, *target, EdgeKind::Normal);
}
TerminatorKind::SwitchInt { targets, switch_ty, discr } => {
let ty = discr.ty(&self.body.local_decls, self.tcx);
if ty != *switch_ty {
self.fail(
location,
format!(
"encountered `SwitchInt` terminator with type mismatch: {:?} != {:?}",
ty, switch_ty,
),
);
}
TerminatorKind::SwitchInt { targets, discr } => {
let switch_ty = discr.ty(&self.body.local_decls, self.tcx);

let target_width = self.tcx.sess.target.pointer_width;

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,9 @@ language_item_table! {

// FIXME(swatinem): the following lang items are used for async lowering and
// should become obsolete eventually.
ResumeTy, sym::ResumeTy, resume_ty, Target::Struct, GenericRequirement::None;
IdentityFuture, sym::identity_future, identity_future_fn, Target::Fn, GenericRequirement::None;
GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None;

Context, sym::Context, context, Target::Struct, GenericRequirement::None;
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;

FromFrom, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
adt_substs,
);
let ty = tcx.bound_type_of(assoc_ty_did).subst(tcx, item_substs);
let ty = self.normalize_ty(span, ty);
return Ok((ty, DefKind::AssocTy, assoc_ty_did));
}
}
Expand Down
42 changes: 38 additions & 4 deletions compiler/rustc_hir_analysis/src/variance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use rustc_arena::DroplessArena;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, CrateVariancesMap, TyCtxt, TypeSuperVisitable, TypeVisitable};
use rustc_middle::ty::{self, CrateVariancesMap, SubstsRef, Ty, TyCtxt};
use rustc_middle::ty::{DefIdTree, TypeSuperVisitable, TypeVisitable};
use std::ops::ControlFlow;

/// Defines the `TermsContext` basically houses an arena where we can
Expand Down Expand Up @@ -75,18 +76,50 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
// type Foo<'a, 'b, 'c> = impl Trait<'a> + 'b;
// ```
// we may not use `'c` in the hidden type.
struct OpaqueTypeLifetimeCollector {
struct OpaqueTypeLifetimeCollector<'tcx> {
tcx: TyCtxt<'tcx>,
root_def_id: DefId,
variances: Vec<ty::Variance>,
}

impl<'tcx> ty::TypeVisitor<'tcx> for OpaqueTypeLifetimeCollector {
impl<'tcx> OpaqueTypeLifetimeCollector<'tcx> {
#[instrument(level = "trace", skip(self), ret)]
fn visit_opaque(&mut self, def_id: DefId, substs: SubstsRef<'tcx>) -> ControlFlow<!> {
if def_id != self.root_def_id && self.tcx.is_descendant_of(def_id, self.root_def_id) {
let child_variances = self.tcx.variances_of(def_id);
for (a, v) in substs.iter().zip(child_variances) {
if *v != ty::Bivariant {
a.visit_with(self)?;
}
}
ControlFlow::CONTINUE
} else {
substs.visit_with(self)
}
}
}

impl<'tcx> ty::TypeVisitor<'tcx> for OpaqueTypeLifetimeCollector<'tcx> {
#[instrument(level = "trace", skip(self), ret)]
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::RegionKind::ReEarlyBound(ebr) = r.kind() {
self.variances[ebr.index as usize] = ty::Invariant;
}
r.super_visit_with(self)
}

#[instrument(level = "trace", skip(self), ret)]
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
match t.kind() {
ty::Opaque(def_id, substs) => self.visit_opaque(*def_id, substs),
ty::Projection(proj)
if self.tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder =>
{
self.visit_opaque(proj.item_def_id, proj.substs)
}
_ => t.super_visit_with(self),
}
}
}

// By default, RPIT are invariant wrt type and const generics, but they are bivariant wrt
Expand All @@ -111,7 +144,8 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
}
}

let mut collector = OpaqueTypeLifetimeCollector { variances };
let mut collector =
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id.to_def_id());
for pred in tcx.bound_explicit_item_bounds(item_def_id.to_def_id()).transpose_iter() {
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,6 @@ pub enum TerminatorKind<'tcx> {
SwitchInt {
/// The discriminant value being tested.
discr: Operand<'tcx>,

/// The type of value being tested.
/// This is always the same as the type of `discr`.
/// FIXME: remove this redundant information. Currently, it is relied on by pretty-printing.
switch_ty: Ty<'tcx>,

targets: SwitchTargets,
},

Expand Down
Loading