Skip to content

Commit 9252525

Browse files
committed
Auto merge of #21598 - eddyb:there-are-no-boxed-closures, r=brson
2 parents 47621db + 9690be5 commit 9252525

Some content is hidden

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

63 files changed

+584
-816
lines changed

src/doc/reference.md

-4
Original file line numberDiff line numberDiff line change
@@ -2489,10 +2489,6 @@ The currently implemented features of the reference compiler are:
24892489
for now until the specification of identifiers is fully
24902490
fleshed out.
24912491

2492-
* `once_fns` - Onceness guarantees a closure is only executed once. Defining a
2493-
closure as `once` is unlikely to be supported going forward. So
2494-
they are hidden behind this feature until they are to be removed.
2495-
24962492
* `plugin` - Usage of [compiler plugins][plugin] for custom lints or syntax extensions.
24972493
These depend on compiler internals and are subject to change.
24982494

src/librustc/lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ impl LintPass for Stability {
17321732
ty::MethodStatic(def_id) => {
17331733
def_id
17341734
}
1735-
ty::MethodStaticUnboxedClosure(def_id) => {
1735+
ty::MethodStaticClosure(def_id) => {
17361736
def_id
17371737
}
17381738
ty::MethodTypeParam(ty::MethodParam {
@@ -1940,7 +1940,7 @@ impl LintPass for UnconditionalRecursion {
19401940
ty::MethodTraitObject(_) => return false,
19411941

19421942
// This `did` refers directly to the method definition.
1943-
ty::MethodStatic(did) | ty::MethodStaticUnboxedClosure(did) => did,
1943+
ty::MethodStatic(did) | ty::MethodStaticClosure(did) => did,
19441944

19451945
// MethodTypeParam are methods from traits:
19461946

src/librustc/metadata/common.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f
139139
tag_table_adjustments = 0x51,
140140
tag_table_moves_map = 0x52,
141141
tag_table_capture_map = 0x53,
142-
tag_table_unboxed_closures = 0x54,
142+
tag_table_closures = 0x54,
143143
tag_table_upvar_borrow_map = 0x55,
144144
tag_table_capture_modes = 0x56,
145145
tag_table_object_cast_map = 0x57,
@@ -225,10 +225,10 @@ pub struct LinkMeta {
225225
pub crate_hash: Svh,
226226
}
227227

228-
pub const tag_unboxed_closures: uint = 0x95;
229-
pub const tag_unboxed_closure: uint = 0x96;
230-
pub const tag_unboxed_closure_type: uint = 0x97;
231-
pub const tag_unboxed_closure_kind: uint = 0x98;
228+
pub const tag_closures: uint = 0x95;
229+
pub const tag_closure: uint = 0x96;
230+
pub const tag_closure_type: uint = 0x97;
231+
pub const tag_closure_kind: uint = 0x98;
232232

233233
pub const tag_struct_fields: uint = 0x99;
234234
pub const tag_struct_field: uint = 0x9a;

src/librustc/metadata/encoder.rs

+20-26
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,12 @@ fn encode_visibility(rbml_w: &mut Encoder, visibility: ast::Visibility) {
618618
rbml_w.end_tag();
619619
}
620620

621-
fn encode_unboxed_closure_kind(rbml_w: &mut Encoder,
622-
kind: ty::UnboxedClosureKind) {
623-
rbml_w.start_tag(tag_unboxed_closure_kind);
621+
fn encode_closure_kind(rbml_w: &mut Encoder, kind: ty::ClosureKind) {
622+
rbml_w.start_tag(tag_closure_kind);
624623
let ch = match kind {
625-
ty::FnUnboxedClosureKind => 'f',
626-
ty::FnMutUnboxedClosureKind => 'm',
627-
ty::FnOnceUnboxedClosureKind => 'o',
624+
ty::FnClosureKind => 'f',
625+
ty::FnMutClosureKind => 'm',
626+
ty::FnOnceClosureKind => 'o',
628627
};
629628
rbml_w.wr_str(&ch.to_string()[]);
630629
rbml_w.end_tag();
@@ -1838,24 +1837,19 @@ fn encode_macro_defs(rbml_w: &mut Encoder,
18381837
rbml_w.end_tag();
18391838
}
18401839

1841-
fn encode_unboxed_closures<'a>(
1842-
ecx: &'a EncodeContext,
1843-
rbml_w: &'a mut Encoder) {
1844-
rbml_w.start_tag(tag_unboxed_closures);
1845-
for (unboxed_closure_id, unboxed_closure) in ecx.tcx
1846-
.unboxed_closures
1847-
.borrow()
1848-
.iter() {
1849-
if unboxed_closure_id.krate != ast::LOCAL_CRATE {
1840+
fn encode_closures<'a>(ecx: &'a EncodeContext, rbml_w: &'a mut Encoder) {
1841+
rbml_w.start_tag(tag_closures);
1842+
for (closure_id, closure) in ecx.tcx.closures.borrow().iter() {
1843+
if closure_id.krate != ast::LOCAL_CRATE {
18501844
continue
18511845
}
18521846

1853-
rbml_w.start_tag(tag_unboxed_closure);
1854-
encode_def_id(rbml_w, *unboxed_closure_id);
1855-
rbml_w.start_tag(tag_unboxed_closure_type);
1856-
write_closure_type(ecx, rbml_w, &unboxed_closure.closure_type);
1847+
rbml_w.start_tag(tag_closure);
1848+
encode_def_id(rbml_w, *closure_id);
1849+
rbml_w.start_tag(tag_closure_type);
1850+
write_closure_type(ecx, rbml_w, &closure.closure_type);
18571851
rbml_w.end_tag();
1858-
encode_unboxed_closure_kind(rbml_w, unboxed_closure.kind);
1852+
encode_closure_kind(rbml_w, closure.kind);
18591853
rbml_w.end_tag();
18601854
}
18611855
rbml_w.end_tag();
@@ -2069,7 +2063,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
20692063
native_lib_bytes: u64,
20702064
plugin_registrar_fn_bytes: u64,
20712065
macro_defs_bytes: u64,
2072-
unboxed_closure_bytes: u64,
2066+
closure_bytes: u64,
20732067
impl_bytes: u64,
20742068
misc_bytes: u64,
20752069
item_bytes: u64,
@@ -2084,7 +2078,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
20842078
native_lib_bytes: 0,
20852079
plugin_registrar_fn_bytes: 0,
20862080
macro_defs_bytes: 0,
2087-
unboxed_closure_bytes: 0,
2081+
closure_bytes: 0,
20882082
impl_bytes: 0,
20892083
misc_bytes: 0,
20902084
item_bytes: 0,
@@ -2154,10 +2148,10 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
21542148
encode_macro_defs(&mut rbml_w, krate);
21552149
stats.macro_defs_bytes = rbml_w.writer.tell().unwrap() - i;
21562150

2157-
// Encode the types of all unboxed closures in this crate.
2151+
// Encode the types of all closures in this crate.
21582152
i = rbml_w.writer.tell().unwrap();
2159-
encode_unboxed_closures(&ecx, &mut rbml_w);
2160-
stats.unboxed_closure_bytes = rbml_w.writer.tell().unwrap() - i;
2153+
encode_closures(&ecx, &mut rbml_w);
2154+
stats.closure_bytes = rbml_w.writer.tell().unwrap() - i;
21612155

21622156
// Encode the def IDs of impls, for coherence checking.
21632157
i = rbml_w.writer.tell().unwrap();
@@ -2199,7 +2193,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
21992193
println!(" native bytes: {}", stats.native_lib_bytes);
22002194
println!("plugin registrar bytes: {}", stats.plugin_registrar_fn_bytes);
22012195
println!(" macro def bytes: {}", stats.macro_defs_bytes);
2202-
println!(" unboxed closure bytes: {}", stats.unboxed_closure_bytes);
2196+
println!(" closure bytes: {}", stats.closure_bytes);
22032197
println!(" impl bytes: {}", stats.impl_bytes);
22042198
println!(" misc bytes: {}", stats.misc_bytes);
22052199
println!(" item bytes: {}", stats.item_bytes);

src/librustc/metadata/tydecode.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ pub enum DefIdSource {
5757
// Identifies a region parameter (`fn foo<'X>() { ... }`).
5858
RegionParameter,
5959

60-
// Identifies an unboxed closure
61-
UnboxedClosureSource
60+
// Identifies a closure
61+
ClosureSource
6262
}
6363

6464
// type conv_did = impl FnMut(DefIdSource, ast::DefId) -> ast::DefId;
@@ -537,11 +537,11 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
537537
}
538538
'k' => {
539539
assert_eq!(next(st), '[');
540-
let did = parse_def_(st, UnboxedClosureSource, conv);
540+
let did = parse_def_(st, ClosureSource, conv);
541541
let region = parse_region_(st, conv);
542542
let substs = parse_substs_(st, conv);
543543
assert_eq!(next(st), ']');
544-
return ty::mk_unboxed_closure(st.tcx, did,
544+
return ty::mk_closure(st.tcx, did,
545545
st.tcx.mk_region(region), st.tcx.mk_substs(substs));
546546
}
547547
'P' => {

src/librustc/metadata/tyencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
139139
enc_substs(w, cx, substs);
140140
mywrite!(w, "]");
141141
}
142-
ty::ty_unboxed_closure(def, region, substs) => {
142+
ty::ty_closure(def, region, substs) => {
143143
mywrite!(w, "k[{}|", (cx.ds)(def));
144144
enc_region(w, cx, *region);
145145
enc_substs(w, cx, substs);

src/librustc/middle/astencode.rs

+42-51
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use metadata::encoder as e;
2121
use middle::region;
2222
use metadata::tydecode;
2323
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter};
24-
use metadata::tydecode::{RegionParameter, UnboxedClosureSource};
24+
use metadata::tydecode::{RegionParameter, ClosureSource};
2525
use metadata::tyencode;
2626
use middle::mem_categorization::Typer;
2727
use middle::subst;
@@ -448,10 +448,8 @@ impl tr for def::Def {
448448
def::DefPrimTy(p) => def::DefPrimTy(p),
449449
def::DefTyParam(s, index, def_id, n) => def::DefTyParam(s, index, def_id.tr(dcx), n),
450450
def::DefUse(did) => def::DefUse(did.tr(dcx)),
451-
def::DefUpvar(nid1, nid2, nid3) => {
452-
def::DefUpvar(dcx.tr_id(nid1),
453-
dcx.tr_id(nid2),
454-
dcx.tr_id(nid3))
451+
def::DefUpvar(nid1, nid2) => {
452+
def::DefUpvar(dcx.tr_id(nid1), dcx.tr_id(nid2))
455453
}
456454
def::DefStruct(did) => def::DefStruct(did.tr(dcx)),
457455
def::DefRegion(nid) => def::DefRegion(dcx.tr_id(nid)),
@@ -618,8 +616,8 @@ impl<'tcx> tr for MethodOrigin<'tcx> {
618616
fn tr(&self, dcx: &DecodeContext) -> MethodOrigin<'tcx> {
619617
match *self {
620618
ty::MethodStatic(did) => ty::MethodStatic(did.tr(dcx)),
621-
ty::MethodStaticUnboxedClosure(did) => {
622-
ty::MethodStaticUnboxedClosure(did.tr(dcx))
619+
ty::MethodStaticClosure(did) => {
620+
ty::MethodStaticClosure(did.tr(dcx))
623621
}
624622
ty::MethodTypeParam(ref mp) => {
625623
ty::MethodTypeParam(
@@ -643,24 +641,23 @@ impl<'tcx> tr for MethodOrigin<'tcx> {
643641
}
644642
}
645643

646-
pub fn encode_unboxed_closure_kind(ebml_w: &mut Encoder,
647-
kind: ty::UnboxedClosureKind) {
644+
pub fn encode_closure_kind(ebml_w: &mut Encoder, kind: ty::ClosureKind) {
648645
use serialize::Encoder;
649646

650-
ebml_w.emit_enum("UnboxedClosureKind", |ebml_w| {
647+
ebml_w.emit_enum("ClosureKind", |ebml_w| {
651648
match kind {
652-
ty::FnUnboxedClosureKind => {
653-
ebml_w.emit_enum_variant("FnUnboxedClosureKind", 0, 3, |_| {
649+
ty::FnClosureKind => {
650+
ebml_w.emit_enum_variant("FnClosureKind", 0, 3, |_| {
654651
Ok(())
655652
})
656653
}
657-
ty::FnMutUnboxedClosureKind => {
658-
ebml_w.emit_enum_variant("FnMutUnboxedClosureKind", 1, 3, |_| {
654+
ty::FnMutClosureKind => {
655+
ebml_w.emit_enum_variant("FnMutClosureKind", 1, 3, |_| {
659656
Ok(())
660657
})
661658
}
662-
ty::FnOnceUnboxedClosureKind => {
663-
ebml_w.emit_enum_variant("FnOnceUnboxedClosureKind",
659+
ty::FnOnceClosureKind => {
660+
ebml_w.emit_enum_variant("FnOnceClosureKind",
664661
2,
665662
3,
666663
|_| {
@@ -736,7 +733,7 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> {
736733
this.read_enum_variant(&["vtable_static",
737734
"vtable_param",
738735
"vtable_error",
739-
"vtable_unboxed_closure"],
736+
"vtable_closure"],
740737
|this, i| {
741738
Ok(match i {
742739
0 => {
@@ -763,7 +760,7 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> {
763760
)
764761
}
765762
2 => {
766-
ty::vtable_unboxed_closure(
763+
ty::vtable_closure(
767764
this.read_enum_variant_arg(0u, |this| {
768765
Ok(this.read_def_id_nodcx(cdata))
769766
}).unwrap()
@@ -865,8 +862,8 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
865862
})
866863
}
867864

868-
ty::MethodStaticUnboxedClosure(def_id) => {
869-
this.emit_enum_variant("MethodStaticUnboxedClosure", 1, 1, |this| {
865+
ty::MethodStaticClosure(def_id) => {
866+
this.emit_enum_variant("MethodStaticClosure", 1, 1, |this| {
870867
Ok(this.emit_def_id(def_id))
871868
})
872869
}
@@ -1322,15 +1319,12 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
13221319
})
13231320
}
13241321

1325-
for unboxed_closure in tcx.unboxed_closures
1326-
.borrow()
1327-
.get(&ast_util::local_def(id))
1328-
.iter() {
1329-
rbml_w.tag(c::tag_table_unboxed_closures, |rbml_w| {
1322+
for closure in tcx.closures.borrow().get(&ast_util::local_def(id)).iter() {
1323+
rbml_w.tag(c::tag_table_closures, |rbml_w| {
13301324
rbml_w.id(id);
13311325
rbml_w.tag(c::tag_table_val, |rbml_w| {
1332-
rbml_w.emit_closure_type(ecx, &unboxed_closure.closure_type);
1333-
encode_unboxed_closure_kind(rbml_w, unboxed_closure.kind)
1326+
rbml_w.emit_closure_type(ecx, &closure.closure_type);
1327+
encode_closure_kind(rbml_w, closure.kind)
13341328
})
13351329
})
13361330
}
@@ -1369,8 +1363,8 @@ trait rbml_decoder_decoder_helpers<'tcx> {
13691363
-> subst::Substs<'tcx>;
13701364
fn read_auto_adjustment<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
13711365
-> ty::AutoAdjustment<'tcx>;
1372-
fn read_unboxed_closure<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1373-
-> ty::UnboxedClosure<'tcx>;
1366+
fn read_closure<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1367+
-> ty::Closure<'tcx>;
13741368
fn read_auto_deref_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
13751369
-> ty::AutoDerefRef<'tcx>;
13761370
fn read_autoref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
@@ -1436,7 +1430,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
14361430
-> ty::MethodOrigin<'tcx>
14371431
{
14381432
self.read_enum("MethodOrigin", |this| {
1439-
let variants = &["MethodStatic", "MethodStaticUnboxedClosure",
1433+
let variants = &["MethodStatic", "MethodStaticClosure",
14401434
"MethodTypeParam", "MethodTraitObject"];
14411435
this.read_enum_variant(variants, |this, i| {
14421436
Ok(match i {
@@ -1447,7 +1441,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
14471441

14481442
1 => {
14491443
let def_id = this.read_def_id(dcx);
1450-
ty::MethodStaticUnboxedClosure(def_id)
1444+
ty::MethodStaticClosure(def_id)
14511445
}
14521446

14531447
2 => {
@@ -1797,8 +1791,8 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
17971791
}).unwrap()
17981792
}
17991793

1800-
fn read_unboxed_closure<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
1801-
-> ty::UnboxedClosure<'tcx> {
1794+
fn read_closure<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
1795+
-> ty::Closure<'tcx> {
18021796
let closure_type = self.read_opaque(|this, doc| {
18031797
Ok(tydecode::parse_ty_closure_data(
18041798
doc.data,
@@ -1808,21 +1802,21 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
18081802
|s, a| this.convert_def_id(dcx, s, a)))
18091803
}).unwrap();
18101804
let variants = &[
1811-
"FnUnboxedClosureKind",
1812-
"FnMutUnboxedClosureKind",
1813-
"FnOnceUnboxedClosureKind"
1805+
"FnClosureKind",
1806+
"FnMutClosureKind",
1807+
"FnOnceClosureKind"
18141808
];
1815-
let kind = self.read_enum("UnboxedClosureKind", |this| {
1809+
let kind = self.read_enum("ClosureKind", |this| {
18161810
this.read_enum_variant(variants, |_, i| {
18171811
Ok(match i {
1818-
0 => ty::FnUnboxedClosureKind,
1819-
1 => ty::FnMutUnboxedClosureKind,
1820-
2 => ty::FnOnceUnboxedClosureKind,
1821-
_ => panic!("bad enum variant for ty::UnboxedClosureKind"),
1812+
0 => ty::FnClosureKind,
1813+
1 => ty::FnMutClosureKind,
1814+
2 => ty::FnOnceClosureKind,
1815+
_ => panic!("bad enum variant for ty::ClosureKind"),
18221816
})
18231817
})
18241818
}).unwrap();
1825-
ty::UnboxedClosure {
1819+
ty::Closure {
18261820
closure_type: closure_type,
18271821
kind: kind,
18281822
}
@@ -1864,7 +1858,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
18641858
-> ast::DefId {
18651859
let r = match source {
18661860
NominalType | TypeWithId | RegionParameter => dcx.tr_def_id(did),
1867-
TypeParameter | UnboxedClosureSource => dcx.tr_intern_def_id(did)
1861+
TypeParameter | ClosureSource => dcx.tr_intern_def_id(did)
18681862
};
18691863
debug!("convert_def_id(source={:?}, did={:?})={:?}", source, did, r);
18701864
return r;
@@ -1959,14 +1953,11 @@ fn decode_side_tables(dcx: &DecodeContext,
19591953
let adj: ty::AutoAdjustment = val_dsr.read_auto_adjustment(dcx);
19601954
dcx.tcx.adjustments.borrow_mut().insert(id, adj);
19611955
}
1962-
c::tag_table_unboxed_closures => {
1963-
let unboxed_closure =
1964-
val_dsr.read_unboxed_closure(dcx);
1965-
dcx.tcx
1966-
.unboxed_closures
1967-
.borrow_mut()
1968-
.insert(ast_util::local_def(id),
1969-
unboxed_closure);
1956+
c::tag_table_closures => {
1957+
let closure =
1958+
val_dsr.read_closure(dcx);
1959+
dcx.tcx.closures.borrow_mut().insert(ast_util::local_def(id),
1960+
closure);
19701961
}
19711962
_ => {
19721963
dcx.tcx.sess.bug(

0 commit comments

Comments
 (0)