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 6 pull requests #116275

Merged
merged 25 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ec18811
run abi/compatibility test against a whole bunch of targets
RalfJung Sep 21, 2023
f99fdac
ci: upgrade to crosstool-ng 1.26.0
heiher Sep 28, 2023
02b01a4
make region struct and add neccesasry types
ouz-a Sep 21, 2023
e49aa04
add RegionDef
ouz-a Sep 21, 2023
5dc2214
add stable for RegionKind
ouz-a Sep 21, 2023
d835599
make reg public and add visit, fold
ouz-a Sep 21, 2023
2069e8c
fix imports
ouz-a Sep 28, 2023
da2f897
remove un-needed variants
ouz-a Sep 28, 2023
bb17fe8
add real folder to Region
ouz-a Sep 28, 2023
fed72e0
add visitor for Region
ouz-a Sep 28, 2023
9f2e15d
change visit to fold for ty and reg
ouz-a Sep 28, 2023
8c41cd0
simplify fold
ouz-a Sep 28, 2023
0cca109
visit and fold ty::ref
ouz-a Sep 28, 2023
eb77903
simplify visit
ouz-a Sep 28, 2023
34f10e2
remove unimplemented
ouz-a Sep 28, 2023
a95f20c
Add Exclusive forwarding impls (FnOnce, FnMut, Generator)
dtolnay Sep 28, 2023
b83dfb5
fix(suggestion): insert projection to associated types
bvanjoi May 31, 2023
90f317b
add needs-relocation-model-pic to compiletest
pietroalbini Sep 29, 2023
3853774
mark relevant tests as requiring unwinding
pietroalbini Jun 14, 2023
4a88646
Rollup merge of #112123 - bvanjoi:fix-98562, r=compiler-errors
matthiaskrgr Sep 29, 2023
26be575
Rollup merge of #116024 - ouz-a:smir_region, r=oli-obk
matthiaskrgr Sep 29, 2023
77e9dcd
Rollup merge of #116030 - RalfJung:abi-compat-test, r=wesleywiser
matthiaskrgr Sep 29, 2023
60ba6b4
Rollup merge of #116216 - heiher:crosstool, r=Kobzol
matthiaskrgr Sep 29, 2023
4db2b74
Rollup merge of #116241 - dtolnay:exclusivefwd, r=Amanieu
matthiaskrgr Sep 29, 2023
3ee2c52
Rollup merge of #116263 - ferrocene:pa-more-bare-metal-fixes, r=oli-obk
matthiaskrgr Sep 29, 2023
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
67 changes: 39 additions & 28 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,41 +329,52 @@ fn bounds_from_generic_predicates<'tcx>(
_ => {}
}
}
let generics = if types.is_empty() {
"".to_string()
} else {
format!(
"<{}>",
types
.keys()
.filter_map(|t| match t.kind() {
ty::Param(_) => Some(t.to_string()),
// Avoid suggesting the following:
// fn foo<T, <T as Trait>::Bar>(_: T) where T: Trait, <T as Trait>::Bar: Other {}
_ => None,
})
.collect::<Vec<_>>()
.join(", ")
)
};

let mut where_clauses = vec![];
let mut types_str = vec![];
for (ty, bounds) in types {
where_clauses
.extend(bounds.into_iter().map(|bound| format!("{}: {}", ty, tcx.def_path_str(bound))));
}
for projection in &projections {
let p = projection.skip_binder();
// FIXME: this is not currently supported syntax, we should be looking at the `types` and
// insert the associated types where they correspond, but for now let's be "lazy" and
// propose this instead of the following valid resugaring:
// `T: Trait, Trait::Assoc = K` → `T: Trait<Assoc = K>`
where_clauses.push(format!("{} = {}", tcx.def_path_str(p.projection_ty.def_id), p.term));
if let ty::Param(_) = ty.kind() {
let mut bounds_str = vec![];
for bound in bounds {
let mut projections_str = vec![];
for projection in &projections {
let p = projection.skip_binder();
let alias_ty = p.projection_ty;
if bound == tcx.parent(alias_ty.def_id) && alias_ty.self_ty() == ty {
let name = tcx.item_name(alias_ty.def_id);
projections_str.push(format!("{} = {}", name, p.term));
}
}
let bound_def_path = tcx.def_path_str(bound);
if projections_str.is_empty() {
where_clauses.push(format!("{}: {}", ty, bound_def_path));
} else {
bounds_str.push(format!("{}<{}>", bound_def_path, projections_str.join(", ")));
}
}
if bounds_str.is_empty() {
types_str.push(ty.to_string());
} else {
types_str.push(format!("{}: {}", ty, bounds_str.join(" + ")));
}
} else {
// Avoid suggesting the following:
// fn foo<T, <T as Trait>::Bar>(_: T) where T: Trait, <T as Trait>::Bar: Other {}
where_clauses.extend(
bounds.into_iter().map(|bound| format!("{}: {}", ty, tcx.def_path_str(bound))),
);
}
}

let generics =
if types_str.is_empty() { "".to_string() } else { format!("<{}>", types_str.join(", ")) };

let where_clauses = if where_clauses.is_empty() {
String::new()
"".to_string()
} else {
format!(" where {}", where_clauses.join(", "))
};

(generics, where_clauses)
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl<'tcx> Tables<'tcx> {
stable_mir::ty::ImplDef(self.create_def_id(did))
}

pub fn region_def(&mut self, did: DefId) -> stable_mir::ty::RegionDef {
stable_mir::ty::RegionDef(self.create_def_id(did))
}

pub fn prov(&mut self, aid: AllocId) -> stable_mir::ty::Prov {
stable_mir::ty::Prov(self.create_alloc_id(aid))
}
Expand Down
39 changes: 35 additions & 4 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//!
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.

use hir::def::DefKind;
use crate::rustc_smir::hir::def::DefKind;
use crate::rustc_smir::stable_mir::ty::{BoundRegion, EarlyBoundRegion, Region};
use rustc_hir as hir;
use rustc_middle::mir;
use rustc_middle::mir::interpret::{alloc_range, AllocId};
Expand Down Expand Up @@ -1500,9 +1501,39 @@ impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
type T = stable_mir::ty::Region;

fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
// FIXME: add a real implementation of stable regions
opaque(self)
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
Region { kind: self.kind().stable(tables) }
}
}

impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
type T = stable_mir::ty::RegionKind;

fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use stable_mir::ty::RegionKind;
match self {
ty::ReEarlyBound(early_reg) => RegionKind::ReEarlyBound(EarlyBoundRegion {
def_id: tables.region_def(early_reg.def_id),
index: early_reg.index,
name: early_reg.name.to_string(),
}),
ty::ReLateBound(db_index, bound_reg) => RegionKind::ReLateBound(
db_index.as_u32(),
BoundRegion { var: bound_reg.var.as_u32(), kind: bound_reg.kind.stable(tables) },
),
ty::ReStatic => RegionKind::ReStatic,
ty::RePlaceholder(place_holder) => {
RegionKind::RePlaceholder(stable_mir::ty::Placeholder {
universe: place_holder.universe.as_u32(),
bound: BoundRegion {
var: place_holder.bound.var.as_u32(),
kind: place_holder.bound.kind.stable(tables),
},
})
}
ty::ReErased => RegionKind::ReErased,
_ => unreachable!("{self:?}"),
}
}
}

Expand Down
25 changes: 20 additions & 5 deletions compiler/stable_mir/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ use crate::Opaque;

use super::ty::{
Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig, GenericArgKind,
GenericArgs, Promoted, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst,
GenericArgs, Promoted, Region, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst,
};

pub trait Folder: Sized {
type Break;
fn visit_ty(&mut self, ty: &Ty) -> ControlFlow<Self::Break, Ty> {
fn fold_ty(&mut self, ty: &Ty) -> ControlFlow<Self::Break, Ty> {
ty.super_fold(self)
}
fn fold_const(&mut self, c: &Const) -> ControlFlow<Self::Break, Const> {
c.super_fold(self)
}
fn fold_reg(&mut self, reg: &Region) -> ControlFlow<Self::Break, Region> {
reg.super_fold(self)
}
}

pub trait Foldable: Sized + Clone {
Expand All @@ -26,7 +29,7 @@ pub trait Foldable: Sized + Clone {

impl Foldable for Ty {
fn fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
folder.visit_ty(self)
folder.fold_ty(self)
}
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
let mut kind = self.kind();
Expand Down Expand Up @@ -106,6 +109,15 @@ impl Foldable for GenericArgs {
}
}

impl Foldable for Region {
fn fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
folder.fold_reg(self)
}
fn super_fold<V: Folder>(&self, _: &mut V) -> ControlFlow<V::Break, Self> {
ControlFlow::Continue(self.clone())
}
}

impl Foldable for GenericArgKind {
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
let mut this = self.clone();
Expand Down Expand Up @@ -136,7 +148,10 @@ impl Foldable for RigidTy {
}
RigidTy::Slice(inner) => *inner = inner.fold(folder)?,
RigidTy::RawPtr(ty, _) => *ty = ty.fold(folder)?,
RigidTy::Ref(_, ty, _) => *ty = ty.fold(folder)?,
RigidTy::Ref(reg, ty, _) => {
*reg = reg.fold(folder)?;
*ty = ty.fold(folder)?
}
RigidTy::FnDef(_, args) => *args = args.fold(folder)?,
RigidTy::FnPtr(sig) => *sig = sig.fold(folder)?,
RigidTy::Closure(_, args) => *args = args.fold(folder)?,
Expand Down Expand Up @@ -214,7 +229,7 @@ pub enum Never {}
impl Folder for GenericArgs {
type Break = Never;

fn visit_ty(&mut self, ty: &Ty) -> ControlFlow<Self::Break, Ty> {
fn fold_ty(&mut self, ty: &Ty) -> ControlFlow<Self::Break, Ty> {
ControlFlow::Continue(match ty.kind() {
TyKind::Param(p) => self[p],
_ => *ty,
Expand Down
46 changes: 44 additions & 2 deletions compiler/stable_mir/src/ty.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
mir::Safety,
mir::{Body, Mutability},
with, AllocId, DefId,
with, AllocId, DefId, Symbol,
};
use crate::Opaque;
use std::fmt::{self, Debug, Formatter};
Expand Down Expand Up @@ -34,7 +34,46 @@ pub struct Const {
}

type Ident = Opaque;
pub type Region = Opaque;

#[derive(Debug, Clone)]
pub struct Region {
pub kind: RegionKind,
}

#[derive(Debug, Clone)]
pub enum RegionKind {
ReEarlyBound(EarlyBoundRegion),
ReLateBound(DebruijnIndex, BoundRegion),
ReStatic,
RePlaceholder(Placeholder<BoundRegion>),
ReErased,
}

pub(crate) type DebruijnIndex = u32;

#[derive(Debug, Clone)]
pub struct EarlyBoundRegion {
pub def_id: RegionDef,
pub index: u32,
pub name: Symbol,
}

pub(crate) type BoundVar = u32;

#[derive(Debug, Clone)]
pub struct BoundRegion {
pub var: BoundVar,
pub kind: BoundRegionKind,
}

pub(crate) type UniverseIndex = u32;

#[derive(Debug, Clone)]
pub struct Placeholder<T> {
pub universe: UniverseIndex,
pub bound: T,
}

#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Span(pub usize);

Expand Down Expand Up @@ -152,6 +191,9 @@ pub struct ConstDef(pub DefId);
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct ImplDef(pub DefId);

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct RegionDef(pub DefId);

#[derive(Clone, Debug)]
pub struct GenericArgs(pub Vec<GenericArgKind>);

Expand Down
20 changes: 18 additions & 2 deletions compiler/stable_mir/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::Opaque;

use super::ty::{
Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs,
Promoted, RigidTy, TermKind, Ty, UnevaluatedConst,
Promoted, Region, RigidTy, TermKind, Ty, UnevaluatedConst,
};

pub trait Visitor: Sized {
Expand All @@ -15,6 +15,9 @@ pub trait Visitor: Sized {
fn visit_const(&mut self, c: &Const) -> ControlFlow<Self::Break> {
c.super_visit(self)
}
fn visit_reg(&mut self, reg: &Region) -> ControlFlow<Self::Break> {
reg.super_visit(self)
}
}

pub trait Visitable {
Expand Down Expand Up @@ -101,6 +104,16 @@ impl Visitable for GenericArgs {
}
}

impl Visitable for Region {
fn visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
visitor.visit_reg(self)
}

fn super_visit<V: Visitor>(&self, _: &mut V) -> ControlFlow<V::Break> {
ControlFlow::Continue(())
}
}

impl Visitable for GenericArgKind {
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
match self {
Expand Down Expand Up @@ -128,7 +141,10 @@ impl Visitable for RigidTy {
}
RigidTy::Slice(inner) => inner.visit(visitor),
RigidTy::RawPtr(ty, _) => ty.visit(visitor),
RigidTy::Ref(_, ty, _) => ty.visit(visitor),
RigidTy::Ref(reg, ty, _) => {
reg.visit(visitor);
ty.visit(visitor)
}
RigidTy::FnDef(_, args) => args.visit(visitor),
RigidTy::FnPtr(sig) => sig.visit(visitor),
RigidTy::Closure(_, args) => args.visit(visitor),
Expand Down
46 changes: 45 additions & 1 deletion library/core/src/sync/exclusive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use core::fmt;
use core::future::Future;
use core::marker::Tuple;
use core::ops::{Generator, GeneratorState};
use core::pin::Pin;
use core::task::{Context, Poll};

Expand Down Expand Up @@ -168,10 +170,52 @@ impl<T> From<T> for Exclusive<T> {
}

#[unstable(feature = "exclusive_wrapper", issue = "98407")]
impl<T: Future + ?Sized> Future for Exclusive<T> {
impl<F, Args> FnOnce<Args> for Exclusive<F>
where
F: FnOnce<Args>,
Args: Tuple,
{
type Output = F::Output;

extern "rust-call" fn call_once(self, args: Args) -> Self::Output {
self.into_inner().call_once(args)
}
}

#[unstable(feature = "exclusive_wrapper", issue = "98407")]
impl<F, Args> FnMut<Args> for Exclusive<F>
where
F: FnMut<Args>,
Args: Tuple,
{
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output {
self.get_mut().call_mut(args)
}
}

#[unstable(feature = "exclusive_wrapper", issue = "98407")]
impl<T> Future for Exclusive<T>
where
T: Future + ?Sized,
{
type Output = T::Output;

#[inline]
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.get_pin_mut().poll(cx)
}
}

#[unstable(feature = "generator_trait", issue = "43122")] // also #98407
impl<R, G> Generator<R> for Exclusive<G>
where
G: Generator<R> + ?Sized,
{
type Yield = G::Yield;
type Return = G::Return;

#[inline]
fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
G::resume(self.get_pin_mut(), arg)
}
}
Loading
Loading