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

[WIP] Rework impl-trait-in-bindings feature #55807

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/librustc/ich/impls_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ impl_stable_hash_for!(enum mir::CastKind {
ReifyFnPointer,
ClosureFnPointer,
UnsafeFnPointer,
Hide,
Unsize
});

Expand Down
1 change: 1 addition & 0 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ for ty::adjustment::Adjust<'gcx> {
ty::adjustment::Adjust::UnsafeFnPointer |
ty::adjustment::Adjust::ClosureFnPointer |
ty::adjustment::Adjust::MutToConstPointer |
ty::adjustment::Adjust::Hide |
ty::adjustment::Adjust::Unsize => {}
ty::adjustment::Adjust::Deref(ref overloaded) => {
overloaded.hash_stable(hcx, hasher);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
Substs::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param))
}

/// True if errors have been reported since this infcx was
/// Returns `true` if errors have been reported since this infcx was
/// created. This is sometimes used as a heuristic to skip
/// reporting errors that often occur as a result of earlier
/// errors, but where it's hard to be 100% sure (e.g., unresolved
Expand Down Expand Up @@ -1251,7 +1251,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
value.fold_with(&mut r)
}

/// Returns true if `T` contains unresolved type variables. In the
/// Returns `true` if `T` contains unresolved type variables. In the
/// process of visiting `T`, this will resolve (where possible)
/// type variables in `T`, but it never constructs the final,
/// resolved type, so it's more efficient than
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
adjustment::Adjust::UnsafeFnPointer |
adjustment::Adjust::ClosureFnPointer |
adjustment::Adjust::MutToConstPointer |
adjustment::Adjust::Hide |
adjustment::Adjust::Unsize => {
// Creating a closure/fn-pointer or unsizing consumes
// the input and stores it into the resulting rvalue.
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
adjustment::Adjust::ClosureFnPointer |
adjustment::Adjust::MutToConstPointer |
adjustment::Adjust::Borrow(_) |
adjustment::Adjust::Hide |
adjustment::Adjust::Unsize => {
// Result is an rvalue.
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, target))
Expand Down
20 changes: 12 additions & 8 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2128,16 +2128,16 @@ impl<'tcx> Operand<'tcx> {
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub enum Rvalue<'tcx> {
/// x (either a move or copy, depending on type of x)
/// `x` (either a move or copy, depending on type of `x`)
Use(Operand<'tcx>),

/// [x; 32]
/// `[x; 32]`
Repeat(Operand<'tcx>, u64),

/// &x or &mut x
/// `&x` or `&mut x`
Ref(Region<'tcx>, BorrowKind, Place<'tcx>),

/// length of a [X] or [X;n] value
/// length of a `[X]` or `[X;n]` value
Len(Place<'tcx>),

Cast(CastKind, Operand<'tcx>, Ty<'tcx>),
Expand Down Expand Up @@ -2166,15 +2166,19 @@ pub enum Rvalue<'tcx> {
pub enum CastKind {
Misc,

/// Convert unique, zero-sized type for a fn to fn()
/// Convert a unique, zero-sized type for a fn to `fn()`
ReifyFnPointer,

/// Convert non capturing closure to fn()
/// Convert a non capturing closure to `fn()`
ClosureFnPointer,

/// Convert safe fn() to unsafe fn()
/// Convert a safe fn() to unsafe `fn()`
UnsafeFnPointer,

// "Hide" -- convert a value to an opaque type, i.e. `impl Trait`,
// thus hiding information about its conrete type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/conrete/concrete/

Hide,

/// "Unsize" -- convert a thin-or-fat pointer to a fat pointer.
/// codegen must figure out the details once full monomorphization
/// is known. For example, this could be used to cast from a
Expand All @@ -2185,7 +2189,7 @@ pub enum CastKind {

#[derive(Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub enum AggregateKind<'tcx> {
/// The type is of the element
/// The type is of the element.
Array(Ty<'tcx>),
Tuple,

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub enum TraitQueryMode {
Canonical,
}

/// An `Obligation` represents some trait reference (e.g. `int:Eq`) for
/// An `Obligation` represents some trait reference (e.g. `int: Eq`) for
/// which the vtable must be found. The process of finding a vtable is
/// called "resolving" the `Obligation`. This process consists of
/// either identifying an `impl` (e.g., `impl Eq for int`) that
Expand Down Expand Up @@ -1015,7 +1015,7 @@ fn vtable_methods<'a, 'tcx>(
)
}

impl<'tcx,O> Obligation<'tcx,O> {
impl<'tcx, O> Obligation<'tcx, O> {
pub fn new(cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
predicate: O)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a,
(impl_trait_ref, impl_obligations)
}

/// See `super::obligations_for_generics`
/// See `super::predicates_for_generics`.
pub fn predicates_for_generics<'tcx>(cause: ObligationCause<'tcx>,
recursion_depth: usize,
param_env: ty::ParamEnv<'tcx>,
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/ty/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use hir::def_id::DefId;
use ty::{self, Ty, TyCtxt};
use ty::subst::Substs;


/// Represents coercing a value to a different type of value.
///
/// We transform values by following a number of `Adjust` steps in order.
Expand Down Expand Up @@ -83,6 +82,9 @@ pub enum Adjust<'tcx> {
/// Take the address and produce either a `&` or `*` pointer.
Borrow(AutoBorrow<'tcx>),

/// Hide a value with an opaque type.
Hide,

/// Unsize a pointer/reference value, e.g. `&[T; n]` to
/// `&[T]`. Note that the source could be a thin or fat pointer.
/// This will do things like convert thin pointers to fat
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
self.instantiate_into(tcx, &mut instantiated, substs);
instantiated
}

pub fn instantiate_own(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: &Substs<'tcx>)
-> InstantiatedPredicates<'tcx> {
InstantiatedPredicates {
Expand Down Expand Up @@ -1028,8 +1029,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {

pub fn instantiate_supertrait(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
poly_trait_ref: &ty::PolyTraitRef<'tcx>)
-> InstantiatedPredicates<'tcx>
{
-> InstantiatedPredicates<'tcx> {
assert_eq!(self.parent, None);
InstantiatedPredicates {
predicates: self.predicates.iter().map(|(pred, _)| {
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
Some(ty::adjustment::Adjust::ClosureFnPointer),
ty::adjustment::Adjust::MutToConstPointer =>
Some(ty::adjustment::Adjust::MutToConstPointer),
ty::adjustment::Adjust::Hide =>
Some(ty::adjustment::Adjust::Hide),
ty::adjustment::Adjust::Unsize =>
Some(ty::adjustment::Adjust::Unsize),
ty::adjustment::Adjust::Deref(ref overloaded) => {
Expand Down Expand Up @@ -881,6 +883,7 @@ EnumTypeFoldableImpl! {
(ty::adjustment::Adjust::UnsafeFnPointer),
(ty::adjustment::Adjust::ClosureFnPointer),
(ty::adjustment::Adjust::MutToConstPointer),
(ty::adjustment::Adjust::Hide),
(ty::adjustment::Adjust::Unsize),
(ty::adjustment::Adjust::Deref)(a),
(ty::adjustment::Adjust::Borrow)(a),
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ pub enum TyKind<'tcx> {

/// Opaque (`impl Trait`) type found in a return type.
/// The `DefId` comes either from
/// * the `impl Trait` ast::Ty node,
/// * or the `existential type` declaration
/// * the `impl Trait` `ast::Ty` node,
/// * the `existential type` declaration.
/// The substitutions are for the generics of the function in question.
/// After typeck, the concrete type can be found in the `types` map.
Opaque(DefId, &'tcx Substs<'tcx>),
Expand Down Expand Up @@ -582,7 +582,7 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> {

#[inline]
pub fn projection_bounds<'a>(&'a self) ->
impl Iterator<Item=ExistentialProjection<'tcx>> + 'a {
impl Iterator<Item = ExistentialProjection<'tcx>> + 'a {
self.iter().filter_map(|predicate| {
match *predicate {
ExistentialPredicate::Projection(p) => Some(p),
Expand All @@ -592,7 +592,7 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> {
}

#[inline]
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item=DefId> + 'a {
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item = DefId> + 'a {
self.iter().filter_map(|predicate| {
match *predicate {
ExistentialPredicate::AutoTrait(d) => Some(d),
Expand All @@ -619,7 +619,7 @@ impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
}

pub fn iter<'a>(&'a self)
-> impl DoubleEndedIterator<Item=Binder<ExistentialPredicate<'tcx>>> + 'tcx {
-> impl DoubleEndedIterator<Item = Binder<ExistentialPredicate<'tcx>>> + 'tcx {
self.skip_binder().iter().cloned().map(Binder::bind)
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_codegen_llvm/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ impl OperandValue<'ll> {

impl FunctionCx<'a, 'll, 'tcx> {
fn maybe_codegen_consume_direct(&mut self,
bx: &Builder<'a, 'll, 'tcx>,
place: &mir::Place<'tcx>)
-> Option<OperandRef<'ll, 'tcx>>
bx: &Builder<'a, 'll, 'tcx>,
place: &mir::Place<'tcx>)
-> Option<OperandRef<'ll, 'tcx>>
{
debug!("maybe_codegen_consume_direct(place={:?})", place);

Expand Down Expand Up @@ -382,9 +382,9 @@ impl FunctionCx<'a, 'll, 'tcx> {
}

pub fn codegen_consume(&mut self,
bx: &Builder<'a, 'll, 'tcx>,
place: &mir::Place<'tcx>)
-> OperandRef<'ll, 'tcx>
bx: &Builder<'a, 'll, 'tcx>,
place: &mir::Place<'tcx>)
-> OperandRef<'ll, 'tcx>
{
debug!("codegen_consume(place={:?})", place);

Expand All @@ -406,9 +406,9 @@ impl FunctionCx<'a, 'll, 'tcx> {
}

pub fn codegen_operand(&mut self,
bx: &Builder<'a, 'll, 'tcx>,
operand: &mir::Operand<'tcx>)
-> OperandRef<'ll, 'tcx>
bx: &Builder<'a, 'll, 'tcx>,
operand: &mir::Operand<'tcx>)
-> OperandRef<'ll, 'tcx>
{
debug!("codegen_operand(operand={:?})", operand);

Expand Down
22 changes: 14 additions & 8 deletions src/librustc_codegen_llvm/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ use super::place::PlaceRef;

impl FunctionCx<'a, 'll, 'tcx> {
pub fn codegen_rvalue(&mut self,
bx: Builder<'a, 'll, 'tcx>,
dest: PlaceRef<'ll, 'tcx>,
rvalue: &mir::Rvalue<'tcx>)
-> Builder<'a, 'll, 'tcx>
bx: Builder<'a, 'll, 'tcx>,
dest: PlaceRef<'ll, 'tcx>,
rvalue: &mir::Rvalue<'tcx>)
-> Builder<'a, 'll, 'tcx>
{
debug!("codegen_rvalue(dest.llval={:?}, rvalue={:?})",
dest.llval, rvalue);
Expand Down Expand Up @@ -199,9 +199,9 @@ impl FunctionCx<'a, 'll, 'tcx> {
}

pub fn codegen_rvalue_operand(&mut self,
bx: Builder<'a, 'll, 'tcx>,
rvalue: &mir::Rvalue<'tcx>)
-> (Builder<'a, 'll, 'tcx>, OperandRef<'ll, 'tcx>)
bx: Builder<'a, 'll, 'tcx>,
rvalue: &mir::Rvalue<'tcx>)
-> (Builder<'a, 'll, 'tcx>, OperandRef<'ll, 'tcx>)
{
assert!(self.rvalue_creates_operand(rvalue), "cannot codegen {:?} to operand", rvalue);

Expand Down Expand Up @@ -240,9 +240,12 @@ impl FunctionCx<'a, 'll, 'tcx> {
}
}
mir::CastKind::UnsafeFnPointer => {
// this is a no-op at the LLVM level
// This is a no-op at the LLVM level.
operand.val
}
mir::CastKind::Hide => {
return (bx, operand);
}
mir::CastKind::Unsize => {
assert!(cast.is_llvm_scalar_pair());
match operand.val {
Expand Down Expand Up @@ -442,6 +445,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
};
(bx, operand)
}

mir::Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
let lhs = self.codegen_operand(&bx, lhs);
let rhs = self.codegen_operand(&bx, rhs);
Expand Down Expand Up @@ -521,10 +525,12 @@ impl FunctionCx<'a, 'll, 'tcx> {
};
(bx, operand)
}

mir::Rvalue::Use(ref operand) => {
let operand = self.codegen_operand(&bx, operand);
(bx, operand)
}

mir::Rvalue::Repeat(..) |
mir::Rvalue::Aggregate(..) => {
// According to `rvalue_creates_operand`, only ZST
Expand Down
Loading