Skip to content

Rollup of 7 pull requests #114718

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

Merged
merged 18 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0b89aac
rustc: Move `crate_types` from `Session` to `GlobalCtxt`
petrochenkov Aug 8, 2023
907aa44
rustc: Move `stable_crate_id` from `Session` to `GlobalCtxt`
petrochenkov Aug 8, 2023
32e6a22
remove myself from the review rotation
pietroalbini Aug 10, 2023
26efc2f
update my entry in the mailmap
pietroalbini Aug 10, 2023
d558353
make the provisional cache slightly less broken
lcnr Aug 10, 2023
02529d2
add and move trait solver cycle tests
lcnr Aug 10, 2023
051eb7c
Unlock trailing where-clauses for lazy type aliases
fmease Aug 9, 2023
8b29ad7
Fix copy & paste doc error
spastorino Aug 7, 2023
5f0e662
Add impl trait declarations to SMIR
spastorino Aug 7, 2023
fad7c4d
Add spastorino to mailmap
spastorino Aug 10, 2023
540afe2
Comment nits
compiler-errors Aug 10, 2023
12551a5
Rollup merge of #114599 - spastorino:add-impl-trait-smir, r=oli-obk
compiler-errors Aug 11, 2023
94533d9
Rollup merge of #114622 - petrochenkov:noplugin, r=oli-obk
compiler-errors Aug 11, 2023
076c9d7
Rollup merge of #114662 - fmease:lazy-ty-aliases-unlock-trailing-wcs,…
compiler-errors Aug 11, 2023
2845bad
Rollup merge of #114693 - pietroalbini:pa-pietro-review-rotation, r=c…
compiler-errors Aug 11, 2023
a04dfc3
Rollup merge of #114694 - lcnr:provisional-cache, r=compiler-errors
compiler-errors Aug 11, 2023
891b384
Rollup merge of #114705 - spastorino:add-spastorino-mailmap, r=compil…
compiler-errors Aug 11, 2023
5f90689
Rollup merge of #114712 - compiler-errors:comment-nits, r=lcnr
compiler-errors Aug 11, 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
Prev Previous commit
Next Next commit
Add impl trait declarations to SMIR
  • Loading branch information
spastorino committed Aug 10, 2023
commit 5f0e662523c3bb37c6a3891a28e61775f4fb5dfb
12 changes: 12 additions & 0 deletions compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub fn trait_def(did: DefId) -> stable_mir::ty::TraitDef {
with_tables(|t| t.trait_def(did))
}

pub fn impl_def(did: DefId) -> stable_mir::ty::ImplDef {
with_tables(|t| t.impl_def(did))
}

impl<'tcx> Tables<'tcx> {
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
self.def_ids[item.0]
Expand All @@ -72,6 +76,10 @@ impl<'tcx> Tables<'tcx> {
self.def_ids[trait_def.0]
}

pub fn impl_trait_def_id(&self, impl_def: &stable_mir::ty::ImplDef) -> DefId {
self.def_ids[impl_def.0]
}

pub fn crate_item(&mut self, did: DefId) -> stable_mir::CrateItem {
stable_mir::CrateItem(self.create_def_id(did))
}
Expand Down Expand Up @@ -116,6 +124,10 @@ impl<'tcx> Tables<'tcx> {
stable_mir::ty::ConstDef(self.create_def_id(did))
}

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

fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
// FIXME: this becomes inefficient when we have too many ids
for (i, &d) in self.def_ids.iter().enumerate() {
Expand Down
36 changes: 36 additions & 0 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ impl<'tcx> Context for Tables<'tcx> {
trait_def.stable(self)
}

fn all_trait_impls(&mut self) -> stable_mir::ImplTraitDecls {
self.tcx
.trait_impls_in_crate(LOCAL_CRATE)
.iter()
.map(|impl_def_id| self.impl_def(*impl_def_id))
.collect()
}

fn trait_impl(&mut self, impl_def: &stable_mir::ty::ImplDef) -> stable_mir::ty::ImplTrait {
let def_id = self.impl_trait_def_id(impl_def);
let impl_trait = self.tcx.impl_trait_ref(def_id).unwrap();
impl_trait.stable(self)
}

fn mir_body(&mut self, item: &stable_mir::CrateItem) -> stable_mir::mir::Body {
let def_id = self.item_def_id(item);
let mir = self.tcx.optimized_mir(def_id);
Expand Down Expand Up @@ -840,6 +854,19 @@ where
}
}

impl<'tcx, S, V> Stable<'tcx> for ty::EarlyBinder<S>
where
S: Stable<'tcx, T = V>,
{
type T = stable_mir::ty::EarlyBinder<V>;

fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use stable_mir::ty::EarlyBinder;

EarlyBinder { value: self.as_ref().skip_binder().stable(tables) }
}
}

impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> {
type T = stable_mir::ty::FnSig;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
Expand Down Expand Up @@ -1154,3 +1181,12 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
}
}
}

impl<'tcx> Stable<'tcx> for ty::TraitRef<'tcx> {
type T = stable_mir::ty::TraitRef;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use stable_mir::ty::TraitRef;

TraitRef { def_id: rustc_internal::trait_def(self.def_id), args: self.args.stable(tables) }
}
}
7 changes: 6 additions & 1 deletion compiler/rustc_smir/src/stable_mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::cell::Cell;

use crate::rustc_smir::Tables;

use self::ty::{TraitDecl, TraitDef, Ty, TyKind};
use self::ty::{ImplDef, ImplTrait, TraitDecl, TraitDef, Ty, TyKind};

pub mod mir;
pub mod ty;
Expand All @@ -35,6 +35,9 @@ pub type CrateItems = Vec<CrateItem>;
/// A list of trait decls.
pub type TraitDecls = Vec<TraitDef>;

/// A list of impl trait decls.
pub type ImplTraitDecls = Vec<ImplDef>;

/// Holds information about a crate.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Crate {
Expand Down Expand Up @@ -89,6 +92,8 @@ pub trait Context {
fn mir_body(&mut self, item: &CrateItem) -> mir::Body;
fn all_trait_decls(&mut self) -> TraitDecls;
fn trait_decl(&mut self, trait_def: &TraitDef) -> TraitDecl;
fn all_trait_impls(&mut self) -> ImplTraitDecls;
fn trait_impl(&mut self, trait_impl: &ImplDef) -> ImplTrait;
/// Get information about the local crate.
fn local_crate(&self) -> Crate;
/// Retrieve a list of all external crates.
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ impl TraitDef {
}
}

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

impl ImplDef {
pub fn trait_impl(&self) -> ImplTrait {
with(|cx| cx.trait_impl(self))
}
}

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

Expand Down Expand Up @@ -196,6 +205,11 @@ pub struct Binder<T> {
pub bound_vars: Vec<BoundVariableKind>,
}

#[derive(Clone, Debug)]
pub struct EarlyBinder<T> {
pub value: T,
}

#[derive(Clone, Debug)]
pub enum BoundVariableKind {
Ty(BoundTyKind),
Expand Down Expand Up @@ -432,3 +446,10 @@ pub struct TraitDecl {
pub implement_via_object: bool,
pub deny_explicit_impl: bool,
}

pub type ImplTrait = EarlyBinder<TraitRef>;

pub struct TraitRef {
pub def_id: TraitDef,
pub args: GenericArgs,
}