Skip to content

Commit

Permalink
Stuff works!
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Regueiro committed Nov 11, 2018
1 parent 8dc79e0 commit 98cec39
Show file tree
Hide file tree
Showing 25 changed files with 162 additions and 126 deletions.
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
4 changes: 1 addition & 3 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ 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::Hide(ref revealed_ty) => {
revealed_ty.hash_stable(hcx, hasher);
}
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
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
adjustment::Adjust::UnsafeFnPointer |
adjustment::Adjust::ClosureFnPointer |
adjustment::Adjust::MutToConstPointer |
adjustment::Adjust::Hide(_) |
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
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
adjustment::Adjust::ClosureFnPointer |
adjustment::Adjust::MutToConstPointer |
adjustment::Adjust::Borrow(_) |
adjustment::Adjust::Hide(_) |
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.
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
3 changes: 1 addition & 2 deletions 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 @@ -84,7 +83,7 @@ pub enum Adjust<'tcx> {
Borrow(AutoBorrow<'tcx>),

/// Hide a value with an opaque type.
Hide(Ty<'tcx>),
Hide,

/// Unsize a pointer/reference value, e.g. `&[T; n]` to
/// `&[T]`. Note that the source could be a thin or fat pointer.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +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(ref revealed_ty) =>
tcx.lift(revealed_ty).map(ty::adjustment::Adjust::Hide),
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 @@ -883,7 +883,7 @@ EnumTypeFoldableImpl! {
(ty::adjustment::Adjust::UnsafeFnPointer),
(ty::adjustment::Adjust::ClosureFnPointer),
(ty::adjustment::Adjust::MutToConstPointer),
(ty::adjustment::Adjust::Hide)(a),
(ty::adjustment::Adjust::Hide),
(ty::adjustment::Adjust::Unsize),
(ty::adjustment::Adjust::Deref)(a),
(ty::adjustment::Adjust::Borrow)(a),
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_codegen_llvm/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ 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 => {
// This is a no-op at the LLVM level.
operand.val
}
mir::CastKind::Unsize => {
Expand Down
47 changes: 33 additions & 14 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
locations: Locations,
category: ConstraintCategory,
) -> Fallible<()> {
// FIXME(alexreg): see issue #54600.
if let Err(terr) = self.sub_types(sub, sup, locations, category) {
if let TyKind::Opaque(..) = sup.sty {
// When you have `let x: impl Foo = ...` in a closure,
Expand Down Expand Up @@ -1059,17 +1060,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {

fn eq_opaque_type_and_type(
&mut self,
revealed_ty: Ty<'tcx>,
anon_ty: Ty<'tcx>,
anon_owner_def_id: DefId,
concrete_ty: Ty<'tcx>,
opaque_ty: Ty<'tcx>,
parent_def_id: DefId,
locations: Locations,
category: ConstraintCategory,
) -> Fallible<()> {
debug!(
"eq_opaque_type_and_type( \
revealed_ty={:?}, \
anon_ty={:?})",
revealed_ty, anon_ty
concrete_ty={:?}, \
opaque_ty={:?})",
concrete_ty, opaque_ty
);
let infcx = self.infcx;
let tcx = infcx.tcx;
Expand All @@ -1085,21 +1086,21 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
let dummy_body_id = ObligationCause::dummy().body_id;
let (output_ty, opaque_type_map) =
obligations.add(infcx.instantiate_opaque_types(
anon_owner_def_id,
parent_def_id,
dummy_body_id,
param_env,
&anon_ty,
&opaque_ty,
));
debug!(
"eq_opaque_type_and_type: \
instantiated output_ty={:?} \
opaque_type_map={:#?} \
revealed_ty={:?}",
output_ty, opaque_type_map, revealed_ty
concrete_ty={:?}",
output_ty, opaque_type_map, concrete_ty
);
obligations.add(infcx
.at(&ObligationCause::dummy(), param_env)
.eq(output_ty, revealed_ty)?);
.eq(output_ty, concrete_ty)?);

for (&opaque_def_id, opaque_decl) in &opaque_type_map {
let opaque_defn_ty = tcx.type_of(opaque_def_id);
Expand Down Expand Up @@ -1524,7 +1525,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
}
}
None => {
// FIXME(canndrew): This is_never should probably be an is_uninhabited
// FIXME(canndrew): this `is_never` should probably be an `is_uninhabited`.
if !sig.output().is_never() {
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
}
Expand Down Expand Up @@ -1910,6 +1911,25 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
}
}

CastKind::Hide => {
let predicates = match ty.sty {
ty::Opaque(def_id, substs) => {
let bounds = tcx.predicates_of(def_id);
let result = bounds.instantiate(tcx, substs);
// TODO: do I need to normalize associated types here somehow.
// as is done in coercion.rs?
result
}
_ => bug!(),
};

self.prove_predicates(
predicates.predicates,
location.to_locations(),
ConstraintCategory::Cast,
);
}

CastKind::Unsize => {
let &ty = ty;
let trait_ref = ty::TraitRef {
Expand All @@ -1932,7 +1952,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
self.add_reborrow_constraint(location, region, borrowed_place);
}

// FIXME: These other cases have to be implemented in future PRs
// FIXME: these other cases have to be implemented in future PRs.
Rvalue::Use(..)
| Rvalue::Len(..)
| Rvalue::BinaryOp(..)
Expand Down Expand Up @@ -2164,7 +2184,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
}

// For closures, we have some **extra requirements** we
//
// have to check. In particular, in their upvars and
// signatures, closures often reference various regions
// from the surrounding function -- we call those the
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
| ExprKind::ReifyFnPointer { .. }
| ExprKind::ClosureFnPointer { .. }
| ExprKind::UnsafeFnPointer { .. }
| ExprKind::Hide { .. }
| ExprKind::Unsize { .. }
| ExprKind::Repeat { .. }
| ExprKind::Borrow { .. }
Expand All @@ -205,7 +206,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
| ExprKind::InlineAsm { .. }
| ExprKind::Yield { .. }
| ExprKind::Call { .. } => {
// these are not places, so we need to make a temporary.
// These are not places, so we need to make a temporary.
debug_assert!(match Category::of(&expr.kind) {
Some(Category::Place) => false,
_ => true,
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let source = unpack!(block = this.as_operand(block, scope, source));
block.and(Rvalue::Cast(CastKind::ClosureFnPointer, source, expr.ty))
}
ExprKind::Hide { source } => {
let source = this.hir.mirror(source);

let source = unpack!(block = this.as_operand(block, scope, source));
block.and(Rvalue::Cast(CastKind::Hide, source, expr.ty))
}
ExprKind::Unsize { source } => {
let source = unpack!(block = this.as_operand(block, scope, source));
block.and(Rvalue::Cast(CastKind::Unsize, source, expr.ty))
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/build/expr/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl Category {
| ExprKind::ReifyFnPointer { .. }
| ExprKind::ClosureFnPointer { .. }
| ExprKind::UnsafeFnPointer { .. }
| ExprKind::Hide { .. }
| ExprKind::Unsize { .. }
| ExprKind::Repeat { .. }
| ExprKind::Borrow { .. }
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
| ExprKind::ReifyFnPointer { .. }
| ExprKind::ClosureFnPointer { .. }
| ExprKind::UnsafeFnPointer { .. }
| ExprKind::Hide { .. }
| ExprKind::Unsize { .. }
| ExprKind::Repeat { .. }
| ExprKind::Borrow { .. }
Expand Down
Loading

0 comments on commit 98cec39

Please sign in to comment.