Skip to content

Commit 91374f8

Browse files
committed
rustc: combine BareFnTy and ClosureTy into FnSig.
1 parent 28f1cf4 commit 91374f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+420
-605
lines changed

src/librustc/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl_trans_normalize!('gcx,
600600
Ty<'gcx>,
601601
&'gcx Substs<'gcx>,
602602
ty::FnSig<'gcx>,
603-
&'gcx ty::BareFnTy<'gcx>,
603+
ty::PolyFnSig<'gcx>,
604604
ty::ClosureSubsts<'gcx>,
605605
ty::PolyTraitRef<'gcx>,
606606
ty::ExistentialTraitRef<'gcx>
@@ -1652,7 +1652,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
16521652
pub fn closure_type(&self,
16531653
def_id: DefId,
16541654
substs: ty::ClosureSubsts<'tcx>)
1655-
-> ty::ClosureTy<'tcx>
1655+
-> ty::PolyFnSig<'tcx>
16561656
{
16571657
if let InferTables::InProgress(tables) = self.tables {
16581658
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {

src/librustc/middle/effect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ enum RootUnsafeContext {
4444

4545
fn type_is_unsafe_function(ty: Ty) -> bool {
4646
match ty.sty {
47-
ty::TyFnDef(.., ref f) |
48-
ty::TyFnPtr(ref f) => f.unsafety == hir::Unsafety::Unsafe,
47+
ty::TyFnDef(.., f) |
48+
ty::TyFnPtr(f) => f.unsafety() == hir::Unsafety::Unsafe,
4949
_ => false,
5050
}
5151
}

src/librustc/middle/intrinsicck.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct ExprVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
4040
impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
4141
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
4242
let intrinsic = match self.infcx.tcx.item_type(def_id).sty {
43-
ty::TyFnDef(.., ref bfty) => bfty.abi == RustIntrinsic,
43+
ty::TyFnDef(.., bfty) => bfty.abi() == RustIntrinsic,
4444
_ => return false
4545
};
4646
intrinsic && self.infcx.tcx.item_name(def_id) == "transmute"
@@ -137,9 +137,9 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for ExprVisitor<'a, 'gcx, 'tcx> {
137137
let typ = self.infcx.tables.borrow().node_id_to_type(expr.id);
138138
let typ = self.infcx.tcx.lift_to_global(&typ).unwrap();
139139
match typ.sty {
140-
ty::TyFnDef(.., ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
141-
let from = bare_fn_ty.sig.skip_binder().inputs()[0];
142-
let to = bare_fn_ty.sig.skip_binder().output();
140+
ty::TyFnDef(.., sig) if sig.abi() == RustIntrinsic => {
141+
let from = sig.inputs().skip_binder()[0];
142+
let to = *sig.output().skip_binder();
143143
self.check_transmute(expr.span, from, to, expr.id);
144144
}
145145
_ => {

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14341434
let fn_ty = self.ir.tcx.item_type(self.ir.tcx.hir.local_def_id(id));
14351435
let fn_ret = match fn_ty.sty {
14361436
ty::TyClosure(closure_def_id, substs) =>
1437-
self.ir.tcx.closure_type(closure_def_id, substs).sig.output(),
1437+
self.ir.tcx.closure_type(closure_def_id, substs).output(),
14381438
_ => fn_ty.fn_ret()
14391439
};
14401440

src/librustc/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ fn confirm_closure_candidate<'cx, 'gcx, 'tcx>(
12241224

12251225
confirm_callable_candidate(selcx,
12261226
obligation,
1227-
&closure_type.sig,
1227+
closure_type,
12281228
util::TupleArgumentsFlag::No)
12291229
.with_addl_obligations(vtable.nested)
12301230
.with_addl_obligations(obligations)
@@ -1233,7 +1233,7 @@ fn confirm_closure_candidate<'cx, 'gcx, 'tcx>(
12331233
fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
12341234
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
12351235
obligation: &ProjectionTyObligation<'tcx>,
1236-
fn_sig: &ty::PolyFnSig<'tcx>,
1236+
fn_sig: ty::PolyFnSig<'tcx>,
12371237
flag: util::TupleArgumentsFlag)
12381238
-> Progress<'tcx>
12391239
{

src/librustc/traits/select.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1405,16 +1405,18 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
14051405
}
14061406

14071407
// provide an impl, but only for suitable `fn` pointers
1408-
ty::TyFnDef(.., &ty::BareFnTy {
1408+
ty::TyFnDef(.., ty::Binder(ty::FnSig {
14091409
unsafety: hir::Unsafety::Normal,
14101410
abi: Abi::Rust,
1411-
ref sig,
1412-
}) |
1413-
ty::TyFnPtr(&ty::BareFnTy {
1411+
variadic: false,
1412+
..
1413+
})) |
1414+
ty::TyFnPtr(ty::Binder(ty::FnSig {
14141415
unsafety: hir::Unsafety::Normal,
14151416
abi: Abi::Rust,
1416-
ref sig
1417-
}) if !sig.variadic() => {
1417+
variadic: false,
1418+
..
1419+
})) => {
14181420
candidates.vec.push(FnPointerCandidate);
14191421
}
14201422

@@ -2781,7 +2783,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27812783
let ty::Binder((trait_ref, _)) =
27822784
self.tcx().closure_trait_ref_and_return_type(obligation.predicate.def_id(),
27832785
obligation.predicate.0.self_ty(), // (1)
2784-
&closure_type.sig,
2786+
closure_type,
27852787
util::TupleArgumentsFlag::No);
27862788
// (1) Feels icky to skip the binder here, but OTOH we know
27872789
// that the self-type is an unboxed closure type and hence is

src/librustc/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
482482
pub fn closure_trait_ref_and_return_type(self,
483483
fn_trait_def_id: DefId,
484484
self_ty: Ty<'tcx>,
485-
sig: &ty::PolyFnSig<'tcx>,
485+
sig: ty::PolyFnSig<'tcx>,
486486
tuple_arguments: TupleArgumentsFlag)
487487
-> ty::Binder<(ty::TraitRef<'tcx>, Ty<'tcx>)>
488488
{

src/librustc/ty/context.rs

+16-40
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use ty::{self, TraitRef, Ty, TypeAndMut};
3232
use ty::{TyS, TypeVariants, Slice};
3333
use ty::{AdtKind, AdtDef, ClosureSubsts, Region};
3434
use hir::FreevarMap;
35-
use ty::{BareFnTy, InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
35+
use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
3636
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
3737
use ty::TypeVariants::*;
3838
use ty::layout::{Layout, TargetDataLayout};
@@ -53,6 +53,7 @@ use std::ops::Deref;
5353
use std::rc::Rc;
5454
use std::iter;
5555
use std::cmp::Ordering;
56+
use syntax::abi;
5657
use syntax::ast::{self, Name, NodeId};
5758
use syntax::attr;
5859
use syntax::symbol::{Symbol, keywords};
@@ -94,7 +95,6 @@ pub struct CtxtInterners<'tcx> {
9495
type_: RefCell<FxHashSet<Interned<'tcx, TyS<'tcx>>>>,
9596
type_list: RefCell<FxHashSet<Interned<'tcx, Slice<Ty<'tcx>>>>>,
9697
substs: RefCell<FxHashSet<Interned<'tcx, Substs<'tcx>>>>,
97-
bare_fn: RefCell<FxHashSet<Interned<'tcx, BareFnTy<'tcx>>>>,
9898
region: RefCell<FxHashSet<Interned<'tcx, Region>>>,
9999
existential_predicates: RefCell<FxHashSet<Interned<'tcx, Slice<ExistentialPredicate<'tcx>>>>>,
100100
}
@@ -106,7 +106,6 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
106106
type_: RefCell::new(FxHashSet()),
107107
type_list: RefCell::new(FxHashSet()),
108108
substs: RefCell::new(FxHashSet()),
109-
bare_fn: RefCell::new(FxHashSet()),
110109
region: RefCell::new(FxHashSet()),
111110
existential_predicates: RefCell::new(FxHashSet()),
112111
}
@@ -219,7 +218,7 @@ pub struct TypeckTables<'tcx> {
219218
pub upvar_capture_map: ty::UpvarCaptureMap<'tcx>,
220219

221220
/// Records the type of each closure.
222-
pub closure_tys: NodeMap<ty::ClosureTy<'tcx>>,
221+
pub closure_tys: NodeMap<ty::PolyFnSig<'tcx>>,
223222

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

862-
impl<'a, 'tcx> Lift<'tcx> for &'a BareFnTy<'a> {
863-
type Lifted = &'tcx BareFnTy<'tcx>;
864-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
865-
-> Option<&'tcx BareFnTy<'tcx>> {
866-
if tcx.interners.arena.in_arena(*self as *const _) {
867-
return Some(unsafe { mem::transmute(*self) });
868-
}
869-
// Also try in the global tcx if we're not that.
870-
if !tcx.is_global() {
871-
self.lift_to_tcx(tcx.global_tcx())
872-
} else {
873-
None
874-
}
875-
}
876-
}
877-
878-
879861
pub mod tls {
880862
use super::{CtxtInterners, GlobalCtxt, TyCtxt};
881863

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

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

1090-
impl<'tcx: 'lcx, 'lcx> Borrow<BareFnTy<'lcx>> for Interned<'tcx, BareFnTy<'tcx>> {
1091-
fn borrow<'a>(&'a self) -> &'a BareFnTy<'lcx> {
1092-
self.0
1093-
}
1094-
}
1095-
10961071
impl<'tcx> Borrow<Region> for Interned<'tcx, Region> {
10971072
fn borrow<'a>(&'a self) -> &'a Region {
10981073
self.0
@@ -1181,9 +1156,6 @@ fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
11811156
}
11821157

11831158
direct_interners!('tcx,
1184-
bare_fn: mk_bare_fn(|fty: &BareFnTy| {
1185-
keep_local(&fty.sig)
1186-
}) -> BareFnTy<'tcx>,
11871159
region: mk_region(|r| {
11881160
match r {
11891161
&ty::ReVar(_) | &ty::ReSkolemized(..) => true,
@@ -1209,12 +1181,11 @@ slice_interners!(
12091181

12101182
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12111183
/// Create an unsafe fn ty based on a safe fn ty.
1212-
pub fn safe_to_unsafe_fn_ty(self, bare_fn: &BareFnTy<'tcx>) -> Ty<'tcx> {
1213-
assert_eq!(bare_fn.unsafety, hir::Unsafety::Normal);
1214-
self.mk_fn_ptr(self.mk_bare_fn(ty::BareFnTy {
1184+
pub fn safe_to_unsafe_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
1185+
assert_eq!(sig.unsafety(), hir::Unsafety::Normal);
1186+
self.mk_fn_ptr(sig.map_bound(|sig| ty::FnSig {
12151187
unsafety: hir::Unsafety::Unsafe,
1216-
abi: bare_fn.abi,
1217-
sig: bare_fn.sig.clone()
1188+
..sig
12181189
}))
12191190
}
12201191

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

13421313
pub fn mk_fn_def(self, def_id: DefId,
13431314
substs: &'tcx Substs<'tcx>,
1344-
fty: &'tcx BareFnTy<'tcx>) -> Ty<'tcx> {
1315+
fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
13451316
self.mk_ty(TyFnDef(def_id, substs, fty))
13461317
}
13471318

1348-
pub fn mk_fn_ptr(self, fty: &'tcx BareFnTy<'tcx>) -> Ty<'tcx> {
1319+
pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
13491320
self.mk_ty(TyFnPtr(fty))
13501321
}
13511322

@@ -1439,14 +1410,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
14391410
}
14401411
}
14411412

1442-
pub fn mk_fn_sig<I>(self, inputs: I, output: I::Item, variadic: bool)
1413+
pub fn mk_fn_sig<I>(self,
1414+
inputs: I,
1415+
output: I::Item,
1416+
variadic: bool,
1417+
unsafety: hir::Unsafety,
1418+
abi: abi::Abi)
14431419
-> <I::Item as InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>>>::Output
14441420
where I: Iterator,
14451421
I::Item: InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>>
14461422
{
14471423
inputs.chain(iter::once(output)).intern_with(|xs| ty::FnSig {
14481424
inputs_and_output: self.intern_type_list(xs),
1449-
variadic: variadic
1425+
variadic, unsafety, abi
14501426
})
14511427
}
14521428

src/librustc/ty/fast_reject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
7676
Some(TupleSimplifiedType(tys.len()))
7777
}
7878
ty::TyFnDef(.., ref f) | ty::TyFnPtr(ref f) => {
79-
Some(FunctionSimplifiedType(f.sig.skip_binder().inputs().len()))
79+
Some(FunctionSimplifiedType(f.skip_binder().inputs().len()))
8080
}
8181
ty::TyProjection(_) | ty::TyParam(_) => {
8282
if can_simplify_params {

src/librustc/ty/flags.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ impl FlagComputation {
155155
self.add_tys(&ts[..]);
156156
}
157157

158-
&ty::TyFnDef(_, substs, ref f) => {
158+
&ty::TyFnDef(_, substs, f) => {
159159
self.add_substs(substs);
160-
self.add_fn_sig(&f.sig);
160+
self.add_fn_sig(f);
161161
}
162162

163-
&ty::TyFnPtr(ref f) => {
164-
self.add_fn_sig(&f.sig);
163+
&ty::TyFnPtr(f) => {
164+
self.add_fn_sig(f);
165165
}
166166
}
167167
}
@@ -177,7 +177,7 @@ impl FlagComputation {
177177
}
178178
}
179179

180-
fn add_fn_sig(&mut self, fn_sig: &ty::PolyFnSig) {
180+
fn add_fn_sig(&mut self, fn_sig: ty::PolyFnSig) {
181181
let mut computation = FlagComputation::new();
182182

183183
computation.add_tys(fn_sig.skip_binder().inputs());

src/librustc/ty/fold.rs

-13
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,6 @@ pub trait TypeFolder<'gcx: 'tcx, 'tcx> : Sized {
159159
sig.super_fold_with(self)
160160
}
161161

162-
fn fold_bare_fn_ty(&mut self,
163-
fty: &'tcx ty::BareFnTy<'tcx>)
164-
-> &'tcx ty::BareFnTy<'tcx>
165-
{
166-
fty.super_fold_with(self)
167-
}
168-
169-
fn fold_closure_ty(&mut self,
170-
fty: &ty::ClosureTy<'tcx>)
171-
-> ty::ClosureTy<'tcx> {
172-
fty.super_fold_with(self)
173-
}
174-
175162
fn fold_region(&mut self, r: &'tcx ty::Region) -> &'tcx ty::Region {
176163
r.super_fold_with(self)
177164
}

src/librustc/ty/maps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ define_maps! { <'tcx>
264264

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

269269
/// Caches CoerceUnsized kinds for impls on custom types.
270270
pub custom_coerce_unsized_kind: ItemSignature(DefId)

src/librustc/ty/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ use hir;
5555
use hir::itemlikevisit::ItemLikeVisitor;
5656

5757
pub use self::sty::{Binder, DebruijnIndex};
58-
pub use self::sty::{BareFnTy, FnSig, PolyFnSig};
59-
pub use self::sty::{ClosureTy, InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
58+
pub use self::sty::{FnSig, PolyFnSig};
59+
pub use self::sty::{InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
6060
pub use self::sty::{ClosureSubsts, TypeAndMut};
6161
pub use self::sty::{TraitRef, TypeVariants, PolyTraitRef};
6262
pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
@@ -2470,7 +2470,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24702470
pub fn closure_type(self,
24712471
def_id: DefId,
24722472
substs: ClosureSubsts<'tcx>)
2473-
-> ty::ClosureTy<'tcx>
2473+
-> ty::PolyFnSig<'tcx>
24742474
{
24752475
if let Some(ty) = self.maps.closure_type.borrow().get(&def_id) {
24762476
return ty.subst(self, substs.substs);

0 commit comments

Comments
 (0)