Skip to content

Commit

Permalink
rustc: combine BareFnTy and ClosureTy into FnSig.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Feb 25, 2017
1 parent 28f1cf4 commit 91374f8
Show file tree
Hide file tree
Showing 64 changed files with 420 additions and 605 deletions.
4 changes: 2 additions & 2 deletions src/librustc/infer/mod.rs
Expand Up @@ -600,7 +600,7 @@ impl_trans_normalize!('gcx,
Ty<'gcx>,
&'gcx Substs<'gcx>,
ty::FnSig<'gcx>,
&'gcx ty::BareFnTy<'gcx>,
ty::PolyFnSig<'gcx>,
ty::ClosureSubsts<'gcx>,
ty::PolyTraitRef<'gcx>,
ty::ExistentialTraitRef<'gcx>
Expand Down Expand Up @@ -1652,7 +1652,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
pub fn closure_type(&self,
def_id: DefId,
substs: ty::ClosureSubsts<'tcx>)
-> ty::ClosureTy<'tcx>
-> ty::PolyFnSig<'tcx>
{
if let InferTables::InProgress(tables) = self.tables {
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/effect.rs
Expand Up @@ -44,8 +44,8 @@ enum RootUnsafeContext {

fn type_is_unsafe_function(ty: Ty) -> bool {
match ty.sty {
ty::TyFnDef(.., ref f) |
ty::TyFnPtr(ref f) => f.unsafety == hir::Unsafety::Unsafe,
ty::TyFnDef(.., f) |
ty::TyFnPtr(f) => f.unsafety() == hir::Unsafety::Unsafe,
_ => false,
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/intrinsicck.rs
Expand Up @@ -40,7 +40,7 @@ struct ExprVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
let intrinsic = match self.infcx.tcx.item_type(def_id).sty {
ty::TyFnDef(.., ref bfty) => bfty.abi == RustIntrinsic,
ty::TyFnDef(.., bfty) => bfty.abi() == RustIntrinsic,
_ => return false
};
intrinsic && self.infcx.tcx.item_name(def_id) == "transmute"
Expand Down Expand Up @@ -137,9 +137,9 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for ExprVisitor<'a, 'gcx, 'tcx> {
let typ = self.infcx.tables.borrow().node_id_to_type(expr.id);
let typ = self.infcx.tcx.lift_to_global(&typ).unwrap();
match typ.sty {
ty::TyFnDef(.., ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
let from = bare_fn_ty.sig.skip_binder().inputs()[0];
let to = bare_fn_ty.sig.skip_binder().output();
ty::TyFnDef(.., sig) if sig.abi() == RustIntrinsic => {
let from = sig.inputs().skip_binder()[0];
let to = *sig.output().skip_binder();
self.check_transmute(expr.span, from, to, expr.id);
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Expand Up @@ -1434,7 +1434,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
let fn_ty = self.ir.tcx.item_type(self.ir.tcx.hir.local_def_id(id));
let fn_ret = match fn_ty.sty {
ty::TyClosure(closure_def_id, substs) =>
self.ir.tcx.closure_type(closure_def_id, substs).sig.output(),
self.ir.tcx.closure_type(closure_def_id, substs).output(),
_ => fn_ty.fn_ret()
};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/project.rs
Expand Up @@ -1224,7 +1224,7 @@ fn confirm_closure_candidate<'cx, 'gcx, 'tcx>(

confirm_callable_candidate(selcx,
obligation,
&closure_type.sig,
closure_type,
util::TupleArgumentsFlag::No)
.with_addl_obligations(vtable.nested)
.with_addl_obligations(obligations)
Expand All @@ -1233,7 +1233,7 @@ fn confirm_closure_candidate<'cx, 'gcx, 'tcx>(
fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>,
fn_sig: &ty::PolyFnSig<'tcx>,
fn_sig: ty::PolyFnSig<'tcx>,
flag: util::TupleArgumentsFlag)
-> Progress<'tcx>
{
Expand Down
16 changes: 9 additions & 7 deletions src/librustc/traits/select.rs
Expand Up @@ -1405,16 +1405,18 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
}

// provide an impl, but only for suitable `fn` pointers
ty::TyFnDef(.., &ty::BareFnTy {
ty::TyFnDef(.., ty::Binder(ty::FnSig {
unsafety: hir::Unsafety::Normal,
abi: Abi::Rust,
ref sig,
}) |
ty::TyFnPtr(&ty::BareFnTy {
variadic: false,
..
})) |
ty::TyFnPtr(ty::Binder(ty::FnSig {
unsafety: hir::Unsafety::Normal,
abi: Abi::Rust,
ref sig
}) if !sig.variadic() => {
variadic: false,
..
})) => {
candidates.vec.push(FnPointerCandidate);
}

Expand Down Expand Up @@ -2781,7 +2783,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
let ty::Binder((trait_ref, _)) =
self.tcx().closure_trait_ref_and_return_type(obligation.predicate.def_id(),
obligation.predicate.0.self_ty(), // (1)
&closure_type.sig,
closure_type,
util::TupleArgumentsFlag::No);
// (1) Feels icky to skip the binder here, but OTOH we know
// that the self-type is an unboxed closure type and hence is
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/util.rs
Expand Up @@ -482,7 +482,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn closure_trait_ref_and_return_type(self,
fn_trait_def_id: DefId,
self_ty: Ty<'tcx>,
sig: &ty::PolyFnSig<'tcx>,
sig: ty::PolyFnSig<'tcx>,
tuple_arguments: TupleArgumentsFlag)
-> ty::Binder<(ty::TraitRef<'tcx>, Ty<'tcx>)>
{
Expand Down
56 changes: 16 additions & 40 deletions src/librustc/ty/context.rs
Expand Up @@ -32,7 +32,7 @@ use ty::{self, TraitRef, Ty, TypeAndMut};
use ty::{TyS, TypeVariants, Slice};
use ty::{AdtKind, AdtDef, ClosureSubsts, Region};
use hir::FreevarMap;
use ty::{BareFnTy, InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
use ty::TypeVariants::*;
use ty::layout::{Layout, TargetDataLayout};
Expand All @@ -53,6 +53,7 @@ use std::ops::Deref;
use std::rc::Rc;
use std::iter;
use std::cmp::Ordering;
use syntax::abi;
use syntax::ast::{self, Name, NodeId};
use syntax::attr;
use syntax::symbol::{Symbol, keywords};
Expand Down Expand Up @@ -94,7 +95,6 @@ pub struct CtxtInterners<'tcx> {
type_: RefCell<FxHashSet<Interned<'tcx, TyS<'tcx>>>>,
type_list: RefCell<FxHashSet<Interned<'tcx, Slice<Ty<'tcx>>>>>,
substs: RefCell<FxHashSet<Interned<'tcx, Substs<'tcx>>>>,
bare_fn: RefCell<FxHashSet<Interned<'tcx, BareFnTy<'tcx>>>>,
region: RefCell<FxHashSet<Interned<'tcx, Region>>>,
existential_predicates: RefCell<FxHashSet<Interned<'tcx, Slice<ExistentialPredicate<'tcx>>>>>,
}
Expand All @@ -106,7 +106,6 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
type_: RefCell::new(FxHashSet()),
type_list: RefCell::new(FxHashSet()),
substs: RefCell::new(FxHashSet()),
bare_fn: RefCell::new(FxHashSet()),
region: RefCell::new(FxHashSet()),
existential_predicates: RefCell::new(FxHashSet()),
}
Expand Down Expand Up @@ -219,7 +218,7 @@ pub struct TypeckTables<'tcx> {
pub upvar_capture_map: ty::UpvarCaptureMap<'tcx>,

/// Records the type of each closure.
pub closure_tys: NodeMap<ty::ClosureTy<'tcx>>,
pub closure_tys: NodeMap<ty::PolyFnSig<'tcx>>,

/// Records the kind of each closure.
pub closure_kinds: NodeMap<ty::ClosureKind>,
Expand Down Expand Up @@ -859,23 +858,6 @@ impl<'a, 'tcx> Lift<'tcx> for &'a Slice<ExistentialPredicate<'a>> {
}
}

impl<'a, 'tcx> Lift<'tcx> for &'a BareFnTy<'a> {
type Lifted = &'tcx BareFnTy<'tcx>;
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
-> Option<&'tcx BareFnTy<'tcx>> {
if tcx.interners.arena.in_arena(*self as *const _) {
return Some(unsafe { mem::transmute(*self) });
}
// Also try in the global tcx if we're not that.
if !tcx.is_global() {
self.lift_to_tcx(tcx.global_tcx())
} else {
None
}
}
}


pub mod tls {
use super::{CtxtInterners, GlobalCtxt, TyCtxt};

Expand Down Expand Up @@ -1028,7 +1010,6 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
TyDynamic, TyClosure, TyTuple, TyParam, TyInfer, TyProjection, TyAnon);

println!("Substs interner: #{}", self.interners.substs.borrow().len());
println!("BareFnTy interner: #{}", self.interners.bare_fn.borrow().len());
println!("Region interner: #{}", self.interners.region.borrow().len());
println!("Stability interner: #{}", self.stability_interner.borrow().len());
println!("Layout interner: #{}", self.layout_interner.borrow().len());
Expand Down Expand Up @@ -1087,12 +1068,6 @@ impl<'tcx: 'lcx, 'lcx> Borrow<[Kind<'lcx>]> for Interned<'tcx, Substs<'tcx>> {
}
}

impl<'tcx: 'lcx, 'lcx> Borrow<BareFnTy<'lcx>> for Interned<'tcx, BareFnTy<'tcx>> {
fn borrow<'a>(&'a self) -> &'a BareFnTy<'lcx> {
self.0
}
}

impl<'tcx> Borrow<Region> for Interned<'tcx, Region> {
fn borrow<'a>(&'a self) -> &'a Region {
self.0
Expand Down Expand Up @@ -1181,9 +1156,6 @@ fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
}

direct_interners!('tcx,
bare_fn: mk_bare_fn(|fty: &BareFnTy| {
keep_local(&fty.sig)
}) -> BareFnTy<'tcx>,
region: mk_region(|r| {
match r {
&ty::ReVar(_) | &ty::ReSkolemized(..) => true,
Expand All @@ -1209,12 +1181,11 @@ slice_interners!(

impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
/// Create an unsafe fn ty based on a safe fn ty.
pub fn safe_to_unsafe_fn_ty(self, bare_fn: &BareFnTy<'tcx>) -> Ty<'tcx> {
assert_eq!(bare_fn.unsafety, hir::Unsafety::Normal);
self.mk_fn_ptr(self.mk_bare_fn(ty::BareFnTy {
pub fn safe_to_unsafe_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
assert_eq!(sig.unsafety(), hir::Unsafety::Normal);
self.mk_fn_ptr(sig.map_bound(|sig| ty::FnSig {
unsafety: hir::Unsafety::Unsafe,
abi: bare_fn.abi,
sig: bare_fn.sig.clone()
..sig
}))
}

Expand Down Expand Up @@ -1341,11 +1312,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

pub fn mk_fn_def(self, def_id: DefId,
substs: &'tcx Substs<'tcx>,
fty: &'tcx BareFnTy<'tcx>) -> Ty<'tcx> {
fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
self.mk_ty(TyFnDef(def_id, substs, fty))
}

pub fn mk_fn_ptr(self, fty: &'tcx BareFnTy<'tcx>) -> Ty<'tcx> {
pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
self.mk_ty(TyFnPtr(fty))
}

Expand Down Expand Up @@ -1439,14 +1410,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
}

pub fn mk_fn_sig<I>(self, inputs: I, output: I::Item, variadic: bool)
pub fn mk_fn_sig<I>(self,
inputs: I,
output: I::Item,
variadic: bool,
unsafety: hir::Unsafety,
abi: abi::Abi)
-> <I::Item as InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>>>::Output
where I: Iterator,
I::Item: InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>>
{
inputs.chain(iter::once(output)).intern_with(|xs| ty::FnSig {
inputs_and_output: self.intern_type_list(xs),
variadic: variadic
variadic, unsafety, abi
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/fast_reject.rs
Expand Up @@ -76,7 +76,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
Some(TupleSimplifiedType(tys.len()))
}
ty::TyFnDef(.., ref f) | ty::TyFnPtr(ref f) => {
Some(FunctionSimplifiedType(f.sig.skip_binder().inputs().len()))
Some(FunctionSimplifiedType(f.skip_binder().inputs().len()))
}
ty::TyProjection(_) | ty::TyParam(_) => {
if can_simplify_params {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/ty/flags.rs
Expand Up @@ -155,13 +155,13 @@ impl FlagComputation {
self.add_tys(&ts[..]);
}

&ty::TyFnDef(_, substs, ref f) => {
&ty::TyFnDef(_, substs, f) => {
self.add_substs(substs);
self.add_fn_sig(&f.sig);
self.add_fn_sig(f);
}

&ty::TyFnPtr(ref f) => {
self.add_fn_sig(&f.sig);
&ty::TyFnPtr(f) => {
self.add_fn_sig(f);
}
}
}
Expand All @@ -177,7 +177,7 @@ impl FlagComputation {
}
}

fn add_fn_sig(&mut self, fn_sig: &ty::PolyFnSig) {
fn add_fn_sig(&mut self, fn_sig: ty::PolyFnSig) {
let mut computation = FlagComputation::new();

computation.add_tys(fn_sig.skip_binder().inputs());
Expand Down
13 changes: 0 additions & 13 deletions src/librustc/ty/fold.rs
Expand Up @@ -159,19 +159,6 @@ pub trait TypeFolder<'gcx: 'tcx, 'tcx> : Sized {
sig.super_fold_with(self)
}

fn fold_bare_fn_ty(&mut self,
fty: &'tcx ty::BareFnTy<'tcx>)
-> &'tcx ty::BareFnTy<'tcx>
{
fty.super_fold_with(self)
}

fn fold_closure_ty(&mut self,
fty: &ty::ClosureTy<'tcx>)
-> ty::ClosureTy<'tcx> {
fty.super_fold_with(self)
}

fn fold_region(&mut self, r: &'tcx ty::Region) -> &'tcx ty::Region {
r.super_fold_with(self)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/maps.rs
Expand Up @@ -264,7 +264,7 @@ define_maps! { <'tcx>

/// Records the type of each closure. The def ID is the ID of the
/// expression defining the closure.
pub closure_type: ItemSignature(DefId) -> ty::ClosureTy<'tcx>,
pub closure_type: ItemSignature(DefId) -> ty::PolyFnSig<'tcx>,

/// Caches CoerceUnsized kinds for impls on custom types.
pub custom_coerce_unsized_kind: ItemSignature(DefId)
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/mod.rs
Expand Up @@ -55,8 +55,8 @@ use hir;
use hir::itemlikevisit::ItemLikeVisitor;

pub use self::sty::{Binder, DebruijnIndex};
pub use self::sty::{BareFnTy, FnSig, PolyFnSig};
pub use self::sty::{ClosureTy, InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
pub use self::sty::{FnSig, PolyFnSig};
pub use self::sty::{InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
pub use self::sty::{ClosureSubsts, TypeAndMut};
pub use self::sty::{TraitRef, TypeVariants, PolyTraitRef};
pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
Expand Down Expand Up @@ -2470,7 +2470,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn closure_type(self,
def_id: DefId,
substs: ClosureSubsts<'tcx>)
-> ty::ClosureTy<'tcx>
-> ty::PolyFnSig<'tcx>
{
if let Some(ty) = self.maps.closure_type.borrow().get(&def_id) {
return ty.subst(self, substs.substs);
Expand Down

0 comments on commit 91374f8

Please sign in to comment.