Skip to content

Commit 7c98ce8

Browse files
committed
---
yaml --- r: 139352 b: refs/heads/try2 c: 995425b h: refs/heads/master v: v3
1 parent f5c792e commit 7c98ce8

Some content is hidden

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

53 files changed

+640
-137
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 069529bc5cc14f63035609cdfae5b21ca7999d4b
8+
refs/heads/try2: 995425badba216e38c8eb1e4c6dd6989c50660b3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/metadata/tydecode.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use core::vec;
2424
use syntax::ast;
2525
use syntax::ast::*;
2626
use syntax::codemap::{respan, dummy_sp};
27+
use syntax::opt_vec;
2728

2829
// Compact string representation for ty::t values. API ty_str &
2930
// parse_from_str. Extra parameters are for converting to/from def_ids in the
@@ -479,7 +480,9 @@ fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig {
479480
}
480481
st.pos += 1u; // eat the ']'
481482
let ret_ty = parse_ty(st, conv);
482-
ty::FnSig {inputs: inputs, output: ret_ty}
483+
ty::FnSig {bound_lifetime_names: opt_vec::Empty, // FIXME(#4846)
484+
inputs: inputs,
485+
output: ret_ty}
483486
}
484487
485488
// Rust metadata parsing

branches/try2/src/librustc/middle/trans/foreign.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use util::ppaux::ty_to_str;
4040
use syntax::codemap::span;
4141
use syntax::{ast, ast_util};
4242
use syntax::{attr, ast_map};
43+
use syntax::opt_vec;
4344
use syntax::parse::token::special_idents;
4445

4546
fn abi_info(arch: session::arch) -> @cabi::ABIInfo {
@@ -615,7 +616,8 @@ pub fn trans_intrinsic(ccx: @CrateContext,
615616
sigil: ast::BorrowedSigil,
616617
onceness: ast::Many,
617618
region: ty::re_bound(ty::br_anon(0)),
618-
sig: FnSig {inputs: ~[arg {mode: ast::expl(ast::by_copy),
619+
sig: FnSig {bound_lifetime_names: opt_vec::Empty,
620+
inputs: ~[arg {mode: ast::expl(ast::by_copy),
619621
ty: star_u8}],
620622
output: ty::mk_nil(bcx.tcx())}
621623
});

branches/try2/src/librustc/middle/trans/monomorphize.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use syntax::ast;
3737
use syntax::ast_map;
3838
use syntax::ast_map::{path, path_mod, path_name};
3939
use syntax::ast_util::local_def;
40+
use syntax::opt_vec;
4041
use syntax::parse::token::special_idents;
4142

4243
pub fn monomorphic_fn(ccx: @CrateContext,
@@ -282,7 +283,8 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt,
282283
ty::BareFnTy {
283284
purity: ast::impure_fn,
284285
abi: ast::RustAbi,
285-
sig: FnSig {inputs: ~[],
286+
sig: FnSig {bound_lifetime_names: opt_vec::Empty,
287+
inputs: ~[],
286288
output: ty::mk_nil(tcx)}}))
287289
}
288290
ty::ty_closure(ref fty) => {
@@ -316,7 +318,8 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt,
316318
sigil: sigil,
317319
onceness: ast::Many,
318320
region: ty::re_static,
319-
sig: ty::FnSig {inputs: ~[],
321+
sig: ty::FnSig {bound_lifetime_names: opt_vec::Empty,
322+
inputs: ~[],
320323
output: ty::mk_nil(tcx)}})
321324
}
322325
}

branches/try2/src/librustc/middle/ty.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ use syntax::codemap::span;
4545
use syntax::codemap;
4646
use syntax::print::pprust;
4747
use syntax::{ast, ast_map};
48+
use syntax::opt_vec::OptVec;
49+
use syntax::opt_vec;
4850
use syntax;
4951

5052
// Data types
@@ -376,10 +378,12 @@ pub struct ClosureTy {
376378
* Signature of a function type, which I have arbitrarily
377379
* decided to use to refer to the input/output types.
378380
*
381+
* - `lifetimes` is the list of region names bound in this fn.
379382
* - `inputs` is the list of arguments and their modes.
380383
* - `output` is the return type. */
381384
#[deriving(Eq)]
382385
pub struct FnSig {
386+
bound_lifetime_names: OptVec<ast::ident>,
383387
inputs: ~[arg],
384388
output: t
385389
}
@@ -1062,7 +1066,8 @@ pub fn mk_ctor_fn(cx: ctxt, input_tys: &[ty::t], output: ty::t) -> t {
10621066
BareFnTy {
10631067
purity: ast::pure_fn,
10641068
abi: ast::RustAbi,
1065-
sig: FnSig {inputs: input_args,
1069+
sig: FnSig {bound_lifetime_names: opt_vec::Empty,
1070+
inputs: input_args,
10661071
output: output}})
10671072
}
10681073

@@ -1203,6 +1208,7 @@ pub fn fold_sig(sig: &FnSig, fldop: &fn(t) -> t) -> FnSig {
12031208
};
12041209

12051210
FnSig {
1211+
bound_lifetime_names: copy sig.bound_lifetime_names,
12061212
inputs: args,
12071213
output: fldop(sig.output)
12081214
}

branches/try2/src/librustc/middle/typeck/astconv.rs

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use middle::const_eval;
5858
use middle::ty::{arg, field, substs};
5959
use middle::ty::{ty_param_substs_and_ty};
6060
use middle::ty;
61-
use middle::typeck::rscope::{in_binding_rscope, in_binding_rscope_ext};
61+
use middle::typeck::rscope::{in_binding_rscope};
6262
use middle::typeck::rscope::{region_scope, type_rscope, RegionError};
6363
use middle::typeck::rscope::{RegionParamNames};
6464

@@ -67,6 +67,7 @@ use core::vec;
6767
use syntax::{ast, ast_util};
6868
use syntax::codemap::span;
6969
use syntax::opt_vec::OptVec;
70+
use syntax::opt_vec;
7071
use syntax::print::pprust::{lifetime_to_str, path_to_str};
7172
use syntax::parse::token::special_idents;
7273
use util::common::indenter;
@@ -347,7 +348,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>(
347348
}
348349
ast::ty_bare_fn(ref bf) => {
349350
ty::mk_bare_fn(tcx, ty_of_bare_fn(self, rscope, bf.purity,
350-
bf.abi, &bf.decl))
351+
bf.abi, &bf.lifetimes, &bf.decl))
351352
}
352353
ast::ty_closure(ref f) => {
353354
let fn_decl = ty_of_closure(self,
@@ -508,45 +509,50 @@ pub fn ty_of_arg<AC:AstConv,RS:region_scope + Copy + Durable>(
508509
arg {mode: mode, ty: ty}
509510
}
510511

511-
pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>(
512-
self: &AC,
513-
rscope: &RS,
514-
purity: ast::purity,
515-
abi: ast::Abi,
516-
decl: &ast::fn_decl)
517-
-> ty::BareFnTy {
518-
debug!("ty_of_bare_fn");
519-
520-
// new region names that appear inside of the fn decl are bound to
521-
// that function type
522-
let rb = in_binding_rscope(rscope);
523-
524-
let input_tys = decl.inputs.map(|a| ty_of_arg(self, &rb, *a, None));
525-
let output_ty = match decl.output.node {
526-
ast::ty_infer => self.ty_infer(decl.output.span),
527-
_ => ast_ty_to_ty(self, &rb, decl.output)
528-
};
529-
530-
ty::BareFnTy {
531-
purity: purity,
532-
abi: abi,
533-
sig: ty::FnSig {inputs: input_tys, output: output_ty}
534-
}
512+
pub fn bound_lifetimes<AC:AstConv>(
513+
self: &AC,
514+
ast_lifetimes: &OptVec<ast::Lifetime>) -> OptVec<ast::ident>
515+
{
516+
/*!
517+
*
518+
* Converts a list of lifetimes into a list of bound identifier
519+
* names. Does not permit special names like 'static or 'self to
520+
* be bound. Note that this function is for use in closures,
521+
* methods, and fn definitions. It is legal to bind 'self in a
522+
* type. Eventually this distinction should go away and the same
523+
* rules should apply everywhere ('self would not be a special name
524+
* at that point).
525+
*/
526+
527+
let special_idents = [special_idents::static, special_idents::self_];
528+
let mut bound_lifetime_names = opt_vec::Empty;
529+
ast_lifetimes.map_to_vec(|ast_lifetime| {
530+
if special_idents.any(|&i| i == ast_lifetime.ident) {
531+
self.tcx().sess.span_err(
532+
ast_lifetime.span,
533+
fmt!("illegal lifetime parameter name: `%s`",
534+
lifetime_to_str(ast_lifetime, self.tcx().sess.intr())));
535+
} else {
536+
bound_lifetime_names.push(ast_lifetime.ident);
537+
}
538+
});
539+
bound_lifetime_names
535540
}
536541

537-
pub fn ty_of_bare_fn_ext<AC:AstConv,RS:region_scope + Copy + Durable>(
538-
self: &AC,
539-
rscope: &RS,
540-
purity: ast::purity,
541-
abi: ast::Abi,
542-
decl: &ast::fn_decl,
543-
+region_param_names: RegionParamNames)
544-
-> ty::BareFnTy {
545-
debug!("ty_of_bare_fn_ext");
542+
pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>(
543+
self: &AC,
544+
rscope: &RS,
545+
purity: ast::purity,
546+
abi: ast::Abi,
547+
lifetimes: &OptVec<ast::Lifetime>,
548+
decl: &ast::fn_decl) -> ty::BareFnTy
549+
{
550+
debug!("ty_of_bare_fn");
546551

547552
// new region names that appear inside of the fn decl are bound to
548553
// that function type
549-
let rb = in_binding_rscope_ext(rscope, region_param_names);
554+
let bound_lifetime_names = bound_lifetimes(self, lifetimes);
555+
let rb = in_binding_rscope(rscope, RegionParamNames(copy bound_lifetime_names));
550556

551557
let input_tys = decl.inputs.map(|a| ty_of_arg(self, &rb, *a, None));
552558
let output_ty = match decl.output.node {
@@ -557,7 +563,9 @@ pub fn ty_of_bare_fn_ext<AC:AstConv,RS:region_scope + Copy + Durable>(
557563
ty::BareFnTy {
558564
purity: purity,
559565
abi: abi,
560-
sig: ty::FnSig {inputs: input_tys, output: output_ty}
566+
sig: ty::FnSig {bound_lifetime_names: bound_lifetime_names,
567+
inputs: input_tys,
568+
output: output_ty}
561569
}
562570
}
563571

@@ -569,10 +577,16 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
569577
onceness: ast::Onceness,
570578
opt_lifetime: Option<@ast::Lifetime>,
571579
decl: &ast::fn_decl,
572-
expected_tys: Option<ty::FnSig>,
580+
expected_sig: Option<ty::FnSig>,
573581
lifetimes: &OptVec<ast::Lifetime>,
574582
span: span)
575-
-> ty::ClosureTy {
583+
-> ty::ClosureTy
584+
{
585+
// The caller should not both provide explicit bound lifetime
586+
// names and expected types. Either we infer the bound lifetime
587+
// names or they are provided, but not both.
588+
fail_unless!(lifetimes.is_empty() || expected_sig.is_none());
589+
576590
debug!("ty_of_fn_decl");
577591
let _i = indenter();
578592

@@ -599,19 +613,19 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
599613

600614
// new region names that appear inside of the fn decl are bound to
601615
// that function type
602-
let region_param_names = RegionParamNames::from_lifetimes(lifetimes);
603-
let rb = in_binding_rscope_ext(rscope, region_param_names);
616+
let bound_lifetime_names = bound_lifetimes(self, lifetimes);
617+
let rb = in_binding_rscope(rscope, RegionParamNames(copy bound_lifetime_names));
604618

605619
let input_tys = do decl.inputs.mapi |i, a| {
606-
let expected_arg_ty = do expected_tys.chain_ref |e| {
620+
let expected_arg_ty = do expected_sig.chain_ref |e| {
607621
// no guarantee that the correct number of expected args
608622
// were supplied
609623
if i < e.inputs.len() {Some(e.inputs[i])} else {None}
610624
};
611625
ty_of_arg(self, &rb, *a, expected_arg_ty)
612626
};
613627

614-
let expected_ret_ty = expected_tys.map(|e| e.output);
628+
let expected_ret_ty = expected_sig.map(|e| e.output);
615629
let output_ty = match decl.output.node {
616630
ast::ty_infer if expected_ret_ty.is_some() => expected_ret_ty.get(),
617631
ast::ty_infer => self.ty_infer(decl.output.span),
@@ -623,7 +637,8 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
623637
sigil: sigil,
624638
onceness: onceness,
625639
region: bound_region,
626-
sig: ty::FnSig {inputs: input_tys,
640+
sig: ty::FnSig {bound_lifetime_names: bound_lifetime_names,
641+
inputs: input_tys,
627642
output: output_ty}
628643
}
629644
}

branches/try2/src/librustc/middle/typeck/check/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
15961596
// sigils.
15971597
let expected_sty = unpack_expected(fcx, expected, |x| Some(copy *x));
15981598
let mut error_happened = false;
1599-
let (expected_tys,
1599+
let (expected_sig,
16001600
expected_purity,
16011601
expected_sigil,
16021602
expected_onceness) = {
@@ -1631,13 +1631,14 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
16311631
expected_onceness,
16321632
None,
16331633
decl,
1634-
expected_tys,
1634+
expected_sig,
16351635
&opt_vec::Empty,
16361636
expr.span);
16371637

16381638
let mut fty_sig;
16391639
let fty = if error_happened {
16401640
fty_sig = FnSig {
1641+
bound_lifetime_names: opt_vec::Empty,
16411642
inputs: fn_ty.sig.inputs.map(|an_arg| {
16421643
arg { mode: an_arg.mode,
16431644
ty: ty::mk_err(tcx)
@@ -3455,6 +3456,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
34553456
onceness: ast::Once,
34563457
region: ty::re_bound(ty::br_anon(0)),
34573458
sig: ty::FnSig {
3459+
bound_lifetime_names: opt_vec::Empty,
34583460
inputs: ~[arg {mode: ast::expl(ast::by_copy),
34593461
ty: ty::mk_imm_ptr(
34603462
ccx.tcx,
@@ -3686,7 +3688,8 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
36863688
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
36873689
purity: ast::unsafe_fn,
36883690
abi: ast::RustAbi,
3689-
sig: FnSig {inputs: inputs,
3691+
sig: FnSig {bound_lifetime_names: opt_vec::Empty,
3692+
inputs: inputs,
36903693
output: output}
36913694
});
36923695
let i_ty = ty::lookup_item_type(ccx.tcx, local_def(it.id));

0 commit comments

Comments
 (0)