Skip to content

Commit fb8786f

Browse files
committed
Refactor fn_ty, working towards #3320
1 parent 6995058 commit fb8786f

33 files changed

+699
-569
lines changed

src/rustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ fn get_enum_variants(intr: ident_interner, cdata: cmd, id: ast::node_id,
585585
let mut arg_tys: ~[ty::t] = ~[];
586586
match ty::get(ctor_ty).struct {
587587
ty::ty_fn(f) => {
588-
for f.inputs.each |a| { vec::push(arg_tys, a.ty); }
588+
for f.sig.inputs.each |a| { vec::push(arg_tys, a.ty); }
589589
}
590590
_ => { /* Nullary enum variant. */ }
591591
}

src/rustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, item: @item,
750750
encode_name(ecx, ebml_w, mty.ident);
751751
encode_type_param_bounds(ebml_w, ecx, ty_m.tps);
752752
encode_type(ecx, ebml_w, ty::mk_fn(tcx, mty.fty));
753-
encode_family(ebml_w, purity_fn_family(mty.fty.purity));
753+
encode_family(ebml_w, purity_fn_family(mty.fty.meta.purity));
754754
encode_self_type(ebml_w, mty.self_ty);
755755
ebml_w.end_tag();
756756
}

src/rustc/metadata/tydecode.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use syntax::ast_util;
99
use syntax::ast_util::respan;
1010
use middle::ty;
1111
use std::map::hashmap;
12+
use ty::{FnTyBase, FnMeta, FnSig};
1213

1314
export parse_ty_data, parse_def_id, parse_ident;
1415
export parse_bounds_data;
@@ -274,7 +275,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
274275
parse_ty_rust_fn(st, conv)
275276
}
276277
'X' => {
277-
return ty::mk_var(st.tcx, ty::ty_vid(parse_int(st) as uint));
278+
return ty::mk_var(st.tcx, ty::TyVid(parse_int(st) as uint));
278279
}
279280
'Y' => return ty::mk_type(st.tcx),
280281
'C' => {
@@ -372,7 +373,7 @@ fn parse_purity(c: char) -> purity {
372373
}
373374
}
374375

375-
fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty {
376+
fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy {
376377
let proto = parse_proto(st);
377378
let purity = parse_purity(next(st));
378379
let bounds = parse_bounds(st, conv);
@@ -392,8 +393,14 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty {
392393
}
393394
st.pos += 1u; // eat the ']'
394395
let (ret_style, ret_ty) = parse_ret_ty(st, conv);
395-
return {purity: purity, proto: proto, bounds: bounds, inputs: inputs,
396-
output: ret_ty, ret_style: ret_style};
396+
return FnTyBase {
397+
meta: FnMeta {purity: purity,
398+
proto: proto,
399+
bounds: bounds,
400+
ret_style: ret_style},
401+
sig: FnSig {inputs: inputs,
402+
output: ret_ty}
403+
};
397404
}
398405

399406

src/rustc/metadata/tyencode.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,19 @@ fn enc_purity(w: io::Writer, p: purity) {
342342
}
343343
}
344344

345-
fn enc_ty_fn(w: io::Writer, cx: @ctxt, ft: ty::fn_ty) {
346-
enc_proto(w, cx, ft.proto);
347-
enc_purity(w, ft.purity);
348-
enc_bounds(w, cx, ft.bounds);
345+
fn enc_ty_fn(w: io::Writer, cx: @ctxt, ft: ty::FnTy) {
346+
enc_proto(w, cx, ft.meta.proto);
347+
enc_purity(w, ft.meta.purity);
348+
enc_bounds(w, cx, ft.meta.bounds);
349349
w.write_char('[');
350-
for ft.inputs.each |arg| {
350+
for ft.sig.inputs.each |arg| {
351351
enc_mode(w, cx, arg.mode);
352352
enc_ty(w, cx, arg.ty);
353353
}
354354
w.write_char(']');
355-
match ft.ret_style {
355+
match ft.meta.ret_style {
356356
noreturn => w.write_char('!'),
357-
_ => enc_ty(w, cx, ft.output)
357+
_ => enc_ty(w, cx, ft.sig.output)
358358
}
359359
}
360360

src/rustc/middle/borrowck/check_loans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ impl check_loan_ctxt {
218218
let callee_ty = ty::node_id_to_type(tcx, callee_id);
219219
match ty::get(callee_ty).struct {
220220
ty::ty_fn(fn_ty) => {
221-
match fn_ty.purity {
221+
match fn_ty.meta.purity {
222222
ast::pure_fn => return, // case (c) above
223223
ast::impure_fn | ast::unsafe_fn | ast::extern_fn => {
224224
self.report_purity_error(
225225
pc, callee_span,
226226
fmt!("access to %s function",
227-
pprust::purity_to_str(fn_ty.purity)));
227+
pprust::purity_to_str(fn_ty.meta.purity)));
228228
}
229229
}
230230
}

src/rustc/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl,
659659
match ty::get(fn_ty).struct {
660660
ty::ty_fn(fn_ty) => {
661661
let mut counter = 0;
662-
do vec::iter2(fn_ty.inputs, decl.inputs) |arg_ty, arg_ast| {
662+
do vec::iter2(fn_ty.sig.inputs, decl.inputs) |arg_ty, arg_ast| {
663663
counter += 1;
664664
debug!("arg %d, ty=%s, mode=%s",
665665
counter,

src/rustc/middle/trans/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,10 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
529529
let ccx = cx.ccx();
530530
let mut cx = cx;
531531
match ty::get(fn_ty).struct {
532-
ty::ty_fn({inputs: args, _}) => {
532+
ty::ty_fn(ref fn_ty) => {
533533
let mut j = 0u;
534534
let v_id = variant.id;
535-
for vec::each(args) |a| {
535+
for vec::each(fn_ty.sig.inputs) |a| {
536536
let llfldp_a = GEP_enum(cx, a_tup, tid, v_id, tps, j);
537537
let ty_subst = ty::subst_tps(ccx.tcx, tps, a.ty);
538538
cx = f(cx, llfldp_a, ty_subst);
@@ -1984,7 +1984,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
19841984
let main_takes_argv =
19851985
// invariant!
19861986
match ty::get(main_node_type).struct {
1987-
ty::ty_fn({inputs, _}) => inputs.len() != 0u,
1987+
ty::ty_fn(ref fn_ty) => fn_ty.sig.inputs.len() != 0u,
19881988
_ => ccx.sess.span_fatal(sp, ~"main has a non-function type")
19891989
};
19901990

src/rustc/middle/trans/closure.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,15 @@ fn make_fn_glue(
425425
}
426426
};
427427

428-
return match ty::get(t).struct {
429-
ty::ty_fn({proto: ty::proto_bare, _}) |
430-
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_slice(_)), _}) =>
431-
bcx,
432-
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_uniq), _}) =>
433-
fn_env(ty::ck_uniq),
434-
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_box), _}) =>
435-
fn_env(ty::ck_box),
436-
_ =>
437-
fail ~"make_fn_glue invoked on non-function type"
438-
};
428+
let proto = ty::ty_fn_proto(t);
429+
match proto {
430+
ty::proto_bare | ty::proto_vstore(ty::vstore_slice(_)) => bcx,
431+
ty::proto_vstore(ty::vstore_uniq) => fn_env(ty::ck_uniq),
432+
ty::proto_vstore(ty::vstore_box) => fn_env(ty::ck_box),
433+
ty::proto_vstore(ty::vstore_fixed(_)) => {
434+
cx.sess().bug(~"Closure with fixed vstore");
435+
}
436+
}
439437
}
440438

441439
fn make_opaque_cbox_take_glue(

src/rustc/middle/trans/expr.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,14 @@ fn trans_rvalue_dps(bcx: block, expr: @ast::expr, dest: Dest) -> block {
447447
ast::expr_fn_block(decl, body, cap_clause) => {
448448
let expr_ty = expr_ty(bcx, expr);
449449
match ty::get(expr_ty).struct {
450-
ty::ty_fn({proto, _}) => {
450+
ty::ty_fn(ref fn_ty) => {
451451
debug!("translating fn_block %s with type %s",
452452
expr_to_str(expr, tcx.sess.intr()),
453453
ty_to_str(tcx, expr_ty));
454-
return closure::trans_expr_fn(bcx, proto, decl, body,
455-
expr.id, cap_clause, None,
456-
dest);
454+
return closure::trans_expr_fn(
455+
bcx, fn_ty.meta.proto, decl, body,
456+
expr.id, cap_clause, None,
457+
dest);
457458
}
458459
_ => {
459460
bcx.sess().impossible_case(
@@ -463,11 +464,11 @@ fn trans_rvalue_dps(bcx: block, expr: @ast::expr, dest: Dest) -> block {
463464
}
464465
ast::expr_loop_body(blk) => {
465466
match ty::get(expr_ty(bcx, expr)).struct {
466-
ty::ty_fn({proto, _}) => {
467+
ty::ty_fn(ref fn_ty) => {
467468
match blk.node {
468469
ast::expr_fn_block(decl, body, cap) => {
469470
return closure::trans_expr_fn(
470-
bcx, proto, decl, body, blk.id,
471+
bcx, fn_ty.meta.proto, decl, body, blk.id,
471472
cap, Some(None), dest);
472473
}
473474
_ => {

src/rustc/middle/trans/foreign.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use util::ppaux::ty_to_str;
2020
use datum::*;
2121
use callee::*;
2222
use expr::{Dest, Ignore};
23+
use ty::{FnTyBase, FnMeta, FnSig};
2324

2425
export link_name, trans_foreign_mod, register_foreign_fn, trans_foreign_fn,
2526
trans_intrinsic;
@@ -439,12 +440,12 @@ type c_stack_tys = {
439440
fn c_arg_and_ret_lltys(ccx: @crate_ctxt,
440441
id: ast::node_id) -> (~[TypeRef], TypeRef, ty::t) {
441442
match ty::get(ty::node_id_to_type(ccx.tcx, id)).struct {
442-
ty::ty_fn({inputs: arg_tys, output: ret_ty, _}) => {
443-
let llargtys = type_of_explicit_args(ccx, arg_tys);
444-
let llretty = type_of::type_of(ccx, ret_ty);
445-
(llargtys, llretty, ret_ty)
446-
}
447-
_ => ccx.sess.bug(~"c_arg_and_ret_lltys called on non-function type")
443+
ty::ty_fn(ref fn_ty) => {
444+
let llargtys = type_of_explicit_args(ccx, fn_ty.sig.inputs);
445+
let llretty = type_of::type_of(ccx, fn_ty.sig.output);
446+
(llargtys, llretty, fn_ty.sig.output)
447+
}
448+
_ => ccx.sess.bug(~"c_arg_and_ret_lltys called on non-function type")
448449
}
449450
}
450451

@@ -953,20 +954,19 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
953954
~"frame_address" => {
954955
let frameaddress = ccx.intrinsics.get(~"llvm.frameaddress");
955956
let frameaddress_val = Call(bcx, frameaddress, ~[C_i32(0i32)]);
956-
let fty = ty::mk_fn(bcx.tcx(), {
957-
purity: ast::impure_fn,
958-
proto:
959-
ty::proto_vstore(ty::vstore_slice(
960-
ty::re_bound(ty::br_anon(0)))),
961-
bounds: @~[],
962-
inputs: ~[{
963-
mode: ast::expl(ast::by_val),
964-
ty: ty::mk_imm_ptr(
965-
bcx.tcx(),
966-
ty::mk_mach_uint(bcx.tcx(), ast::ty_u8))
967-
}],
968-
output: ty::mk_nil(bcx.tcx()),
969-
ret_style: ast::return_val
957+
let star_u8 = ty::mk_imm_ptr(
958+
bcx.tcx(),
959+
ty::mk_mach_uint(bcx.tcx(), ast::ty_u8));
960+
let fty = ty::mk_fn(bcx.tcx(), FnTyBase {
961+
meta: FnMeta {purity: ast::impure_fn,
962+
proto:
963+
ty::proto_vstore(ty::vstore_slice(
964+
ty::re_bound(ty::br_anon(0)))),
965+
bounds: @~[],
966+
ret_style: ast::return_val},
967+
sig: FnSig {inputs: ~[{mode: ast::expl(ast::by_val),
968+
ty: star_u8}],
969+
output: ty::mk_nil(bcx.tcx())}
970970
});
971971
let datum = Datum {val: get_param(decl, first_real_arg),
972972
mode: ByRef, ty: fty, source: FromLvalue};

src/rustc/middle/trans/monomorphize.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use base::{trans_item, get_item_val, no_self, self_arg, trans_fn,
1010
use syntax::parse::token::special_idents;
1111
use type_of::type_of_fn_from_ty;
1212
use back::link::mangle_exported_name;
13+
use middle::ty::{FnTyBase, FnMeta, FnSig};
1314

1415
fn monomorphic_fn(ccx: @crate_ctxt,
1516
fn_id: ast::def_id,
@@ -198,27 +199,36 @@ fn monomorphic_fn(ccx: @crate_ctxt,
198199
fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> Option<ty::t> {
199200
// FIXME[mono] could do this recursively. is that worthwhile? (#2529)
200201
match ty::get(ty).struct {
201-
ty::ty_box(*) => {
202-
Some(ty::mk_opaque_box(tcx))
203-
}
204-
ty::ty_fn(ref fty) => {
205-
Some(ty::mk_fn(tcx, {purity: ast::impure_fn,
206-
proto: fty.proto,
207-
bounds: @~[],
208-
inputs: ~[],
209-
output: ty::mk_nil(tcx),
210-
ret_style: ast::return_val}))
211-
}
212-
ty::ty_trait(_, _, _) => {
213-
Some(ty::mk_fn(tcx, {purity: ast::impure_fn,
214-
proto: ty::proto_vstore(ty::vstore_box),
215-
bounds: @~[],
216-
inputs: ~[],
217-
output: ty::mk_nil(tcx),
218-
ret_style: ast::return_val}))
219-
}
220-
ty::ty_ptr(_) => Some(ty::mk_uint(tcx)),
221-
_ => None
202+
ty::ty_box(*) => {
203+
Some(ty::mk_opaque_box(tcx))
204+
}
205+
ty::ty_fn(ref fty) => {
206+
Some(ty::mk_fn(
207+
tcx,
208+
FnTyBase {meta: FnMeta {purity: ast::impure_fn,
209+
proto: fty.meta.proto,
210+
bounds: @~[],
211+
ret_style: ast::return_val},
212+
sig: FnSig {inputs: ~[],
213+
output: ty::mk_nil(tcx)}}))
214+
}
215+
ty::ty_trait(_, _, _) => {
216+
let box_proto = ty::proto_vstore(ty::vstore_box);
217+
Some(ty::mk_fn(
218+
tcx,
219+
FnTyBase {meta: FnMeta {purity: ast::impure_fn,
220+
proto: box_proto,
221+
bounds: @~[],
222+
ret_style: ast::return_val},
223+
sig: FnSig {inputs: ~[],
224+
output: ty::mk_nil(tcx)}}))
225+
}
226+
ty::ty_ptr(_) => {
227+
Some(ty::mk_uint(tcx))
228+
}
229+
_ => {
230+
None
231+
}
222232
}
223233
}
224234

src/rustc/middle/trans/reflect.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,31 +178,31 @@ impl reflector {
178178

179179
// FIXME (#2594): fetch constants out of intrinsic:: for the
180180
// numbers.
181-
ty::ty_fn(fty) => {
182-
let pureval = match fty.purity {
181+
ty::ty_fn(ref fty) => {
182+
let pureval = match fty.meta.purity {
183183
ast::pure_fn => 0u,
184184
ast::unsafe_fn => 1u,
185185
ast::impure_fn => 2u,
186186
ast::extern_fn => 3u
187187
};
188-
let protoval = match fty.proto {
188+
let protoval = match fty.meta.proto {
189189
ty::proto_bare => 0u,
190190
ty::proto_vstore(ty::vstore_uniq) => 2u,
191191
ty::proto_vstore(ty::vstore_box) => 3u,
192192
ty::proto_vstore(ty::vstore_slice(_)) => 4u,
193193
ty::proto_vstore(ty::vstore_fixed(_)) =>
194194
fail ~"fixed unexpected"
195195
};
196-
let retval = match fty.ret_style {
196+
let retval = match fty.meta.ret_style {
197197
ast::noreturn => 0u,
198198
ast::return_val => 1u
199199
};
200200
let extra = ~[self.c_uint(pureval),
201-
self.c_uint(protoval),
202-
self.c_uint(vec::len(fty.inputs)),
203-
self.c_uint(retval)];
201+
self.c_uint(protoval),
202+
self.c_uint(vec::len(fty.sig.inputs)),
203+
self.c_uint(retval)];
204204
self.visit(~"enter_fn", extra);
205-
for fty.inputs.eachi |i, arg| {
205+
for fty.sig.inputs.eachi |i, arg| {
206206
let modeval = match arg.mode {
207207
ast::infer(_) => 0u,
208208
ast::expl(e) => match e {
@@ -220,7 +220,7 @@ impl reflector {
220220
}
221221
self.visit(~"fn_output",
222222
~[self.c_uint(retval),
223-
self.c_tydesc(fty.output)]);
223+
self.c_tydesc(fty.sig.output)]);
224224
self.visit(~"leave_fn", extra);
225225
}
226226

0 commit comments

Comments
 (0)