Skip to content

Commit b423a0f

Browse files
eefriedmaneddyb
authored andcommitted
Split TyBareFn into TyFnDef and TyFnPtr.
There's a lot of stuff wrong with the representation of these types: TyFnDef doesn't actually uniquely identify a function, TyFnPtr is used to represent method calls, TyFnDef in the sub-expression of a cast isn't correctly reified, and probably some other stuff I haven't discovered yet. Splitting them seems like the right first step, though.
1 parent 4b86841 commit b423a0f

Some content is hidden

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

73 files changed

+406
-324
lines changed

src/librustc/middle/effect.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ enum RootUnsafeContext {
4444

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

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
556556
callee, callee_ty);
557557
let call_scope = self.tcx().region_maps.node_extent(call.id);
558558
match callee_ty.sty {
559-
ty::TyBareFn(..) => {
559+
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
560560
self.consume_expr(callee);
561561
}
562562
ty::TyError => { }

src/librustc/middle/infer/freshen.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
161161
ty::TySlice(..) |
162162
ty::TyRawPtr(..) |
163163
ty::TyRef(..) |
164-
ty::TyBareFn(..) |
164+
ty::TyFnDef(..) |
165+
ty::TyFnPtr(_) |
165166
ty::TyTrait(..) |
166167
ty::TyStruct(..) |
167168
ty::TyClosure(..) |

src/librustc/middle/intrinsicck.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use dep_graph::DepNode;
1212
use middle::def::Def;
1313
use middle::def_id::DefId;
1414
use middle::subst::{Subst, Substs, EnumeratedItems};
15-
use middle::ty::{TransmuteRestriction, TyCtxt, TyBareFn};
15+
use middle::ty::{TransmuteRestriction, TyCtxt};
1616
use middle::ty::{self, Ty, TypeFoldable};
1717

1818
use std::fmt;
@@ -53,7 +53,7 @@ struct IntrinsicCheckingVisitor<'a, 'tcx: 'a> {
5353
impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
5454
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
5555
let intrinsic = match self.tcx.lookup_item_type(def_id).ty.sty {
56-
ty::TyBareFn(_, ref bfty) => bfty.abi == RustIntrinsic,
56+
ty::TyFnDef(_, ref bfty) => bfty.abi == RustIntrinsic,
5757
_ => return false
5858
};
5959
intrinsic && self.tcx.item_name(def_id).as_str() == "transmute"
@@ -238,7 +238,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> {
238238
Def::Fn(did) if self.def_id_is_transmute(did) => {
239239
let typ = self.tcx.node_id_to_type(expr.id);
240240
match typ.sty {
241-
TyBareFn(_, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
241+
ty::TyFnDef(_, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
242242
if let ty::FnConverging(to) = bare_fn_ty.sig.0.output {
243243
let from = bare_fn_ty.sig.0.inputs[0];
244244
self.check_transmute(expr.span, from, to, expr.id);

src/librustc/middle/traits/coherence.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ fn ty_is_local_constructor<'tcx>(tcx: &TyCtxt<'tcx>,
301301
ty::TyUint(..) |
302302
ty::TyFloat(..) |
303303
ty::TyStr |
304-
ty::TyBareFn(..) |
304+
ty::TyFnDef(..) |
305+
ty::TyFnPtr(_) |
305306
ty::TyArray(..) |
306307
ty::TySlice(..) |
307308
ty::TyRawPtr(..) |

src/librustc/middle/traits/select.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12861286
}
12871287

12881288
// provide an impl, but only for suitable `fn` pointers
1289-
ty::TyBareFn(_, &ty::BareFnTy {
1289+
ty::TyFnDef(_, &ty::BareFnTy {
1290+
unsafety: hir::Unsafety::Normal,
1291+
abi: Abi::Rust,
1292+
sig: ty::Binder(ty::FnSig {
1293+
inputs: _,
1294+
output: ty::FnConverging(_),
1295+
variadic: false
1296+
})
1297+
}) |
1298+
ty::TyFnPtr(&ty::BareFnTy {
12901299
unsafety: hir::Unsafety::Normal,
12911300
abi: Abi::Rust,
12921301
sig: ty::Binder(ty::FnSig {
@@ -1646,7 +1655,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16461655
ty::TyInt(_) |
16471656
ty::TyBool |
16481657
ty::TyFloat(_) |
1649-
ty::TyBareFn(..) |
1658+
ty::TyFnDef(..) |
1659+
ty::TyFnPtr(_) |
16501660
ty::TyChar => {
16511661
// safe for everything
16521662
ok_if(Vec::new())
@@ -1850,7 +1860,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18501860
ty::TyInt(_) |
18511861
ty::TyBool |
18521862
ty::TyFloat(_) |
1853-
ty::TyBareFn(..) |
1863+
ty::TyFnDef(..) |
1864+
ty::TyFnPtr(_) |
18541865
ty::TyStr |
18551866
ty::TyError |
18561867
ty::TyInfer(ty::IntVar(_)) |

src/librustc/middle/ty/adjustment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ impl<'tcx> ty::TyS<'tcx> {
155155
match *adjustment {
156156
AdjustReifyFnPointer => {
157157
match self.sty {
158-
ty::TyBareFn(Some(_), b) => {
159-
cx.mk_fn(None, b)
158+
ty::TyFnDef(_, b) => {
159+
cx.mk_ty(ty::TyFnPtr(b))
160160
}
161161
_ => {
162162
cx.sess.bug(
@@ -168,7 +168,7 @@ impl<'tcx> ty::TyS<'tcx> {
168168

169169
AdjustUnsafeFnPointer => {
170170
match self.sty {
171-
ty::TyBareFn(None, b) => cx.safe_to_unsafe_fn_ty(b),
171+
ty::TyFnPtr(b) => cx.safe_to_unsafe_fn_ty(b),
172172
ref b => {
173173
cx.sess.bug(
174174
&format!("AdjustUnsafeFnPointer adjustment on non-fn-ptr: \

src/librustc/middle/ty/cast.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ impl<'tcx> CastTy<'tcx> {
6969
Some(CastTy::Int(IntTy::CEnum)),
7070
ty::TyRawPtr(ref mt) => Some(CastTy::Ptr(mt)),
7171
ty::TyRef(_, ref mt) => Some(CastTy::RPtr(mt)),
72-
ty::TyBareFn(..) => Some(CastTy::FnPtr),
72+
// FIXME: Treating TyFnDef as a pointer here is a bit dubious;
73+
// we should be coercing the operand to an actual pointer.
74+
ty::TyFnDef(..) | ty::TyFnPtr(..) => Some(CastTy::FnPtr),
7375
_ => None,
7476
}
7577
}

src/librustc/middle/ty/contents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'tcx> ty::TyS<'tcx> {
187187
// Scalar and unique types are sendable, and durable
188188
ty::TyInfer(ty::FreshIntTy(_)) | ty::TyInfer(ty::FreshFloatTy(_)) |
189189
ty::TyBool | ty::TyInt(_) | ty::TyUint(_) | ty::TyFloat(_) |
190-
ty::TyBareFn(..) | ty::TyChar => {
190+
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyChar => {
191191
TC::None
192192
}
193193

src/librustc/middle/ty/context.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,8 @@ impl<'tcx> TyCtxt<'tcx> {
734734
pub fn print_debug_stats(&self) {
735735
sty_debug_print!(
736736
self,
737-
TyEnum, TyBox, TyArray, TySlice, TyRawPtr, TyRef, TyBareFn, TyTrait,
738-
TyStruct, TyClosure, TyTuple, TyParam, TyInfer, TyProjection);
737+
TyEnum, TyBox, TyArray, TySlice, TyRawPtr, TyRef, TyFnDef, TyFnPtr,
738+
TyTrait, TyStruct, TyClosure, TyTuple, TyParam, TyInfer, TyProjection);
739739

740740
println!("Substs interner: #{}", self.substs_interner.borrow().len());
741741
println!("BareFnTy interner: #{}", self.bare_fn_interner.borrow().len());
@@ -792,12 +792,11 @@ impl<'tcx> TyCtxt<'tcx> {
792792
/// Create an unsafe fn ty based on a safe fn ty.
793793
pub fn safe_to_unsafe_fn_ty(&self, bare_fn: &BareFnTy<'tcx>) -> Ty<'tcx> {
794794
assert_eq!(bare_fn.unsafety, hir::Unsafety::Normal);
795-
let unsafe_fn_ty_a = self.mk_bare_fn(ty::BareFnTy {
795+
self.mk_fn_ptr(ty::BareFnTy {
796796
unsafety: hir::Unsafety::Unsafe,
797797
abi: bare_fn.abi,
798798
sig: bare_fn.sig.clone()
799-
});
800-
self.mk_fn(None, unsafe_fn_ty_a)
799+
})
801800
}
802801

803802
pub fn mk_bare_fn(&self, bare_fn: BareFnTy<'tcx>) -> &'tcx BareFnTy<'tcx> {
@@ -946,26 +945,29 @@ impl<'tcx> TyCtxt<'tcx> {
946945
self.mk_ty(TyBool)
947946
}
948947

949-
pub fn mk_fn(&self,
950-
opt_def_id: Option<DefId>,
951-
fty: &'tcx BareFnTy<'tcx>) -> Ty<'tcx> {
952-
self.mk_ty(TyBareFn(opt_def_id, fty))
948+
pub fn mk_fn_def(&self, def_id: DefId,
949+
fty: BareFnTy<'tcx>) -> Ty<'tcx> {
950+
self.mk_ty(TyFnDef(def_id, self.mk_bare_fn(fty)))
951+
}
952+
953+
pub fn mk_fn_ptr(&self, fty: BareFnTy<'tcx>) -> Ty<'tcx> {
954+
self.mk_ty(TyFnPtr(self.mk_bare_fn(fty)))
953955
}
954956

955957
pub fn mk_ctor_fn(&self,
956958
def_id: DefId,
957959
input_tys: &[Ty<'tcx>],
958960
output: Ty<'tcx>) -> Ty<'tcx> {
959961
let input_args = input_tys.iter().cloned().collect();
960-
self.mk_fn(Some(def_id), self.mk_bare_fn(BareFnTy {
962+
self.mk_fn_def(def_id, BareFnTy {
961963
unsafety: hir::Unsafety::Normal,
962964
abi: Abi::Rust,
963965
sig: ty::Binder(ty::FnSig {
964966
inputs: input_args,
965967
output: ty::FnConverging(output),
966968
variadic: false
967969
})
968-
}))
970+
})
969971
}
970972

971973
pub fn mk_trait(&self,

0 commit comments

Comments
 (0)