Skip to content

Commit 282dec1

Browse files
committed
---
yaml --- r: 7730 b: refs/heads/snap-stage3 c: 5e13d19 h: refs/heads/master v: v3
1 parent 49a9383 commit 282dec1

File tree

113 files changed

+875
-441
lines changed

Some content is hidden

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

113 files changed

+875
-441
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 7da3733c73e7a3ba4c18f3927bbbe185598ad233
4+
refs/heads/snap-stage3: 5e13d19cc07a1e8fbf478d21cabbd7b9f80e3b54
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/doc/rust.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,9 @@ fn main() {
761761
##### Export declarations
762762

763763
~~~~~~~~ {.ebnf .gram}
764-
export_decl : "export" ident [ ',' ident ] * ;
764+
export_decl : "export" ident [ ',' ident ] *
765+
| "export" ident "::{}"
766+
| "export" ident '{' ident [ ',' ident ] * '}' ;
765767
~~~~~~~~
766768

767769
An _export declaration_ restricts the set of local names within a module that
@@ -813,6 +815,40 @@ mod foo {
813815
}
814816
~~~~~~~~
815817

818+
When exporting the name of an `enum` type `t`, by default, the module also
819+
implicitly exports all of `t`'s constructors. For example:
820+
821+
~~~~~~~~
822+
mod foo {
823+
export t;
824+
825+
enum t {a, b, c};
826+
}
827+
~~~~~~~~
828+
829+
Here, `foo` imports `t`, `a`, `b`, and `c`.
830+
831+
The second and third forms of export declaration can be used to export
832+
an `enum` item without exporting all of its constructors. These two
833+
forms can only be used to export an `enum` item. The second form
834+
exports the `enum` type name without exporting any of its
835+
constructors, achieving a simple kind of data abstraction. The third
836+
form exports an `enum` type name along with a subset of its
837+
constructors. For example:
838+
839+
~~~~~~~~
840+
mod foo {
841+
export abstract{};
842+
export slightly_abstract{a, b};
843+
844+
enum abstract {x, y, z}
845+
enum slightly_abstract {a, b, c, d}
846+
}
847+
~~~~~~~~
848+
849+
Module `foo` exports the types `abstract` and `slightly_abstract`, as well as
850+
constructors `a` and `b`, but doesn't export constructors `x`, `y`, `z`, `c`,
851+
or `d`.
816852

817853
### Functions
818854

branches/snap-stage3/src/cargo/cargo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ fn load_pkg(filename: str) -> option::t<pkg> {
105105
let sess = @{
106106
cm: cm,
107107
mutable next_id: 1,
108-
diagnostic: diagnostic::mk_handler(cm, none)
108+
diagnostic: diagnostic::mk_handler(cm, none),
109+
mutable chpos: 0u,
110+
mutable byte_pos: 0u
109111
};
110112
let c = parser::parse_crate_from_crate_file(filename, [], sess);
111113

@@ -347,7 +349,7 @@ fn configure() -> cargo {
347349
c
348350
}
349351

350-
fn for_each_package(c: cargo, b: block(source, package)) {
352+
fn for_each_package(c: cargo, b: fn(source, package)) {
351353
c.sources.values({ |v|
352354
for p in copy v.packages {
353355
b(v, p);

branches/snap-stage3/src/comp/driver/driver.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ fn build_session(sopts: @session::options, input: str,
488488
parse_sess: @{
489489
cm: codemap,
490490
mutable next_id: 1,
491-
diagnostic: diagnostic_handler
491+
diagnostic: diagnostic_handler,
492+
mutable chpos: 0u,
493+
mutable byte_pos: 0u
492494
},
493495
codemap: codemap,
494496
// For a library crate, this is always none

branches/snap-stage3/src/comp/front/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn strip_items(crate: @ast::crate, in_cfg: in_cfg_pred)
2727

2828
let precursor =
2929
{fold_mod: bind fold_mod(ctxt, _, _),
30-
fold_block: bind fold_block(ctxt, _, _),
30+
fold_block: fold::wrap(bind fold_block(ctxt, _, _)),
3131
fold_native_mod: bind fold_native_mod(ctxt, _, _)
3232
with *fold::default_ast_fold()};
3333

branches/snap-stage3/src/comp/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn generate_test_harness(sess: session::session,
4444
mutable testfns: []};
4545

4646
let precursor =
47-
{fold_crate: bind fold_crate(cx, _, _),
47+
{fold_crate: fold::wrap(bind fold_crate(cx, _, _)),
4848
fold_item: bind fold_item(cx, _, _),
4949
fold_mod: bind fold_mod(cx, _, _) with *fold::default_ast_fold()};
5050

branches/snap-stage3/src/comp/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn have_crate_data(cstore: cstore, cnum: ast::crate_num) -> bool {
9393
ret p(cstore).metas.contains_key(cnum);
9494
}
9595

96-
fn iter_crate_data(cstore: cstore, i: block(ast::crate_num, crate_metadata)) {
96+
fn iter_crate_data(cstore: cstore, i: fn(ast::crate_num, crate_metadata)) {
9797
p(cstore).metas.items {|k,v| i(k, v);};
9898
}
9999

branches/snap-stage3/src/comp/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ fn list_crate_items(bytes: @[u8], md: ebml::doc, out: io::writer) {
460460
out.write_str("\n");
461461
}
462462

463-
fn iter_crate_items(bytes: @[u8], proc: block(str, ast::def_id)) {
463+
fn iter_crate_items(bytes: @[u8], proc: fn(str, ast::def_id)) {
464464
let md = ebml::new_doc(bytes);
465465
let paths = ebml::get_doc(md, tag_paths);
466466
let index = ebml::get_doc(paths, tag_index);

branches/snap-stage3/src/comp/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ fn create_index<T: copy>(index: [entry<T>], hash_fn: fn@(T) -> uint) ->
486486
}
487487

488488
fn encode_index<T>(ebml_w: ebml::writer, buckets: [@[entry<T>]],
489-
write_fn: block(io::writer, T)) {
489+
write_fn: fn(io::writer, T)) {
490490
let writer = ebml_w.writer;
491491
ebml::start_tag(ebml_w, tag_index);
492492
let bucket_locs: [uint] = [];

branches/snap-stage3/src/comp/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export parse_bounds_data;
1616
// data buffer. Whatever format you choose should not contain pipe characters.
1717

1818
// Callback to translate defs to strs or back:
19-
type conv_did = block(ast::def_id) -> ast::def_id;
19+
type conv_did = fn(ast::def_id) -> ast::def_id;
2020

2121
type pstate = {data: @[u8], crate: int, mutable pos: uint, tcx: ty::ctxt};
2222

@@ -138,7 +138,7 @@ fn parse_ty_constr_arg(st: @pstate) -> ast::constr_arg_general_<@path> {
138138
}
139139

140140
fn parse_constr<T: copy>(st: @pstate, conv: conv_did,
141-
pser: block(@pstate) -> ast::constr_arg_general_<T>)
141+
pser: fn(@pstate) -> ast::constr_arg_general_<T>)
142142
-> @ty::constr_general<T> {
143143
let sp = ast_util::dummy_sp(); // FIXME: use a real span
144144
let args: [@sp_constr_arg<T>] = [];

branches/snap-stage3/src/comp/middle/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ fn check_if(c: @ast::expr, then: ast::blk, els: option::t<@ast::expr>,
436436
*sc.invalid = append_invalid(*sc.invalid, then_invalid, orig_invalid);
437437
}
438438

439-
fn check_loop(cx: ctx, sc: scope, checker: block()) {
439+
fn check_loop(cx: ctx, sc: scope, checker: fn()) {
440440
let orig_invalid = filter_invalid(*sc.invalid, sc.bs);
441441
checker();
442442
let new_invalid = filter_invalid(*sc.invalid, sc.bs);

branches/snap-stage3/src/comp/middle/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn md_from_metadata<T>(val: debug_metadata) -> T unsafe {
140140
}
141141

142142
fn cached_metadata<T: copy>(cache: metadata_cache, mdtag: int,
143-
eq: block(md: T) -> bool) -> option::t<T> unsafe {
143+
eq: fn(md: T) -> bool) -> option::t<T> unsafe {
144144
if cache.contains_key(mdtag) {
145145
let items = cache.get(mdtag);
146146
for item in items {

branches/snap-stage3/src/comp/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn check_crate(tcx: ty::ctxt, method_map: typeck::method_map,
5858
// variables. `id` is the node_id for some expression that creates the
5959
// closure.
6060
fn with_appropriate_checker(cx: ctx, id: node_id,
61-
b: block(fn@(ctx, ty::t, sp: span))) {
61+
b: fn(fn@(ctx, ty::t, sp: span))) {
6262
let fty = ty::node_id_to_monotype(cx.tcx, id);
6363
alt ty::ty_fn_proto(cx.tcx, fty) {
6464
proto_uniq { b(check_send); }

branches/snap-stage3/src/comp/middle/last_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
203203
}
204204
}
205205

206-
fn visit_block(tp: block_type, cx: ctx, visit: block()) {
206+
fn visit_block(tp: block_type, cx: ctx, visit: fn()) {
207207
let local = @{type: tp, mutable second: false, mutable exits: []};
208208
cx.blocks = cons(local, @cx.blocks);
209209
visit();

branches/snap-stage3/src/comp/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl opt_ for option {
2626
}
2727

2828
// FIXME: Copied from driver.rs, to work around a bug(#1566)
29-
fn time(do_it: bool, what: str, thunk: block()) {
29+
fn time(do_it: bool, what: str, thunk: fn()) {
3030
if !do_it{ ret thunk(); }
3131
let start = std::time::precise_time_s();
3232
thunk();

branches/snap-stage3/src/comp/middle/pat_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn pat_id_map(tcx: ty::ctxt, pat: @pat) -> pat_id_map {
9191
// This does *not* normalize. The pattern should be already normalized
9292
// if you want to get a normalized pattern out of it.
9393
// Could return a constrained type in order to express that (future work)
94-
fn pat_bindings(pat: @pat, it: block(@pat)) {
94+
fn pat_bindings(pat: @pat, it: fn(@pat)) {
9595
alt pat.node {
9696
pat_ident(_, option::none) { it(pat); }
9797
pat_ident(_, option::some(sub)) { it(pat); pat_bindings(sub, it); }

branches/snap-stage3/src/comp/middle/resolve.rs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ fn resolve_constr(e: @env, c: @ast::constr, sc: scopes, _v: vt<scopes>) {
632632
fn resolve_import(e: env, defid: ast::def_id, name: ast::ident,
633633
ids: [ast::ident], sp: codemap::span, sc: scopes) {
634634
fn register(e: env, id: node_id, cx: ctxt, sp: codemap::span,
635-
name: ast::ident, lookup: block(namespace) -> option::t<def>,
635+
name: ast::ident, lookup: fn(namespace) -> option::t<def>,
636636
impls: [@_impl]) {
637637
let val = lookup(ns_val(ns_any_value)), typ = lookup(ns_type),
638638
md = lookup(ns_module);
@@ -1403,6 +1403,8 @@ fn index_mod(md: ast::_mod) -> mod_index {
14031403
}
14041404
//globbed imports have to be resolved lazily.
14051405
ast::view_item_import_glob(_, _) | ast::view_item_export(_, _) {}
1406+
// exports: ignore
1407+
_ {}
14061408
}
14071409
}
14081410
for it: @ast::item in md.items {
@@ -1710,7 +1712,7 @@ fn add_name(ch: checker, sp: span, name: ident) {
17101712

17111713
fn ident_id(&&i: ident) -> ident { ret i; }
17121714

1713-
fn ensure_unique<T>(e: env, sp: span, elts: [T], id: block(T) -> ident,
1715+
fn ensure_unique<T>(e: env, sp: span, elts: [T], id: fn(T) -> ident,
17141716
kind: str) {
17151717
let ch = checker(e, kind);
17161718
for elt: T in elts { add_name(ch, sp, id(elt)); }
@@ -1764,6 +1766,32 @@ fn check_exports(e: @env) {
17641766
}
17651767
}
17661768

1769+
fn check_enum_ok(e: @env, sp:span, id: ident, val: @indexed_mod)
1770+
-> node_id {
1771+
alt val.index.find(id) {
1772+
none { e.sess.span_fatal(sp, #fmt("error: undefined id %s\
1773+
in an export", id)); }
1774+
some(ms) {
1775+
let maybe_id = list::find(ms) {|m|
1776+
alt m {
1777+
mie_item(an_item) {
1778+
alt an_item.node {
1779+
item_tag(_,_) { /* OK */ some(an_item.id) }
1780+
_ { none }
1781+
}
1782+
}
1783+
_ { none }
1784+
}
1785+
};
1786+
alt maybe_id {
1787+
some(an_id) { ret an_id; }
1788+
_ { e.sess.span_fatal(sp, #fmt("error: %s does not refer \
1789+
to an enumeration", id)); }
1790+
}
1791+
}
1792+
}
1793+
}
1794+
17671795
e.mod_map.values {|val|
17681796
alt val.m {
17691797
some(m) {
@@ -1774,14 +1802,44 @@ fn check_exports(e: @env) {
17741802
check_export(e, ident, val, vi);
17751803
}
17761804
}
1805+
ast::view_item_export_tag_none(id, _) {
1806+
let _ = check_enum_ok(e, vi.span, id, val);
1807+
}
1808+
ast::view_item_export_tag_some(id, ids, _) {
1809+
// Check that it's an enum and all the given variants
1810+
// belong to it
1811+
let parent_id = check_enum_ok(e, vi.span, id, val);
1812+
for variant_id in ids {
1813+
alt val.index.find(variant_id.node.name) {
1814+
some(ms) {
1815+
list::iter(ms) {|m|
1816+
alt m {
1817+
mie_tag_variant(parent_item,_) {
1818+
if parent_item.id != parent_id {
1819+
e.sess.span_err(vi.span,
1820+
#fmt("variant %s \
1821+
doesn't belong to enum %s",
1822+
variant_id.node.name,
1823+
id));
1824+
}
1825+
}
1826+
_ { e.sess.span_err(vi.span,
1827+
#fmt("%s is not a \
1828+
variant", variant_id.node.name)); }
1829+
}}
1830+
}
1831+
_ { e.sess.span_err(vi.span, #fmt("%s is not a\
1832+
variant", variant_id.node.name)); }
1833+
}
1834+
}
1835+
}
17771836
_ { }
17781837
}
17791838
}
17801839
}
17811840
none { }
17821841
}
1783-
};
1784-
}
1842+
}}
17851843

17861844
// Impl resolution
17871845

branches/snap-stage3/src/comp/middle/trans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,8 +3233,8 @@ fn invoke_full(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef],
32333233
fn invoke_(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef],
32343234
to_zero: [{v: ValueRef, t: ty::t}],
32353235
to_revoke: [{v: ValueRef, t: ty::t}],
3236-
invoker: block(@block_ctxt, ValueRef, [ValueRef],
3237-
BasicBlockRef, BasicBlockRef)) -> @block_ctxt {
3236+
invoker: fn(@block_ctxt, ValueRef, [ValueRef],
3237+
BasicBlockRef, BasicBlockRef)) -> @block_ctxt {
32383238
// FIXME: May be worth turning this into a plain call when there are no
32393239
// cleanups to run
32403240
if bcx.unreachable { ret bcx; }
@@ -4106,7 +4106,7 @@ fn trans_fn_cleanups(fcx: @fn_ctxt, cx: @block_ctxt) {
41064106
}
41074107
}
41084108

4109-
fn block_locals(b: ast::blk, it: block(@ast::local)) {
4109+
fn block_locals(b: ast::blk, it: fn(@ast::local)) {
41104110
for s: @ast::stmt in b.node.stmts {
41114111
alt s.node {
41124112
ast::stmt_decl(d, _) {
@@ -4423,7 +4423,7 @@ enum self_arg { impl_self(ty::t), no_self, }
44234423
fn trans_closure(cx: @local_ctxt, sp: span, decl: ast::fn_decl,
44244424
body: ast::blk, llfndecl: ValueRef,
44254425
ty_self: self_arg, ty_params: [ast::ty_param],
4426-
id: ast::node_id, maybe_load_env: block(@fn_ctxt)) {
4426+
id: ast::node_id, maybe_load_env: fn(@fn_ctxt)) {
44274427
set_uwtable(llfndecl);
44284428

44294429
// Set up arguments to the function.

branches/snap-stage3/src/comp/middle/trans_closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import shape::{size_of};
5757
// closure is allocated in the task heap and is reference counted.
5858
// For a block, the closure is allocated on the stack. Note that in
5959
// all cases we allocate space for a ref count just to make our lives
60-
// easier when upcasting to block(T)->U, in the shape code, and so
60+
// easier when upcasting to fn(T)->U, in the shape code, and so
6161
// forth.
6262
//
6363
// ## Opaque Closures ##
@@ -637,7 +637,7 @@ fn trans_bind_1(cx: @block_ctxt, outgoing_fty: ty::t,
637637
fn make_null_test(
638638
in_bcx: @block_ctxt,
639639
ptr: ValueRef,
640-
blk: block(@block_ctxt) -> @block_ctxt)
640+
blk: fn(@block_ctxt) -> @block_ctxt)
641641
-> @block_ctxt {
642642
let not_null_bcx = new_sub_block_ctxt(in_bcx, "not null");
643643
let next_bcx = new_sub_block_ctxt(in_bcx, "next");

branches/snap-stage3/src/comp/middle/trans_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn trans_vtable(ccx: @crate_ctxt, id: ast::node_id, name: str,
157157
}
158158

159159
fn trans_wrapper(ccx: @crate_ctxt, pt: [ast::ident], llfty: TypeRef,
160-
fill: block(ValueRef, @block_ctxt) -> @block_ctxt)
160+
fill: fn(ValueRef, @block_ctxt) -> @block_ctxt)
161161
-> ValueRef {
162162
let lcx = @{path: pt, module_path: [], ccx: ccx};
163163
let name = link::mangle_internal_name_by_path(ccx, pt);

branches/snap-stage3/src/comp/middle/trans_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhs: ValueRef,
258258

259259
type val_and_ty_fn = fn@(@block_ctxt, ValueRef, ty::t) -> result;
260260

261-
type iter_vec_block = block(@block_ctxt, ValueRef, ty::t) -> @block_ctxt;
261+
type iter_vec_block = fn(@block_ctxt, ValueRef, ty::t) -> @block_ctxt;
262262

263263
fn iter_vec_raw(bcx: @block_ctxt, vptr: ValueRef, vec_ty: ty::t,
264264
fill: ValueRef, f: iter_vec_block) -> @block_ctxt {

branches/snap-stage3/src/comp/middle/tstate/auxiliary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ fn non_init_constraint_mentions(_fcx: fn_ctxt, c: norm_constraint, v: node_id)
968968
}
969969

970970
fn args_mention<T>(args: [@constr_arg_use],
971-
q: block([T], node_id) -> bool,
971+
q: fn([T], node_id) -> bool,
972972
s: [T]) -> bool {
973973
/*
974974
FIXME

0 commit comments

Comments
 (0)