Skip to content

Commit 7dafbb8

Browse files
committed
---
yaml --- r: 38431 b: refs/heads/try c: 802d475 h: refs/heads/master i: 38429: 1e8a15b 38427: 3cf1db2 38423: 27dcfb8 38415: c8f60df 38399: e67e3e3 v: v3
1 parent 26199a2 commit 7dafbb8

File tree

12 files changed

+53
-188
lines changed

12 files changed

+53
-188
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 09bb07bed9166105ea961a42b5fff7739ae0d2e9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
5-
refs/heads/try: 3aca4a166331e26a12f14e619c78ddd5ef590f70
5+
refs/heads/try: 802d4751903ba4913255a195f6aa9d582e3bb7f2
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/librustc/middle/check_const.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,11 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
138138
expr_call(callee, _, false) => {
139139
match def_map.find(callee.id) {
140140
Some(def_struct(*)) => {} // OK.
141-
Some(def_variant(*)) => {} // OK.
142141
_ => {
143142
sess.span_err(
144143
e.span,
145144
~"function calls in constants are limited to \
146-
struct and enum constructors");
145+
structure constructors");
147146
}
148147
}
149148
}

branches/try/src/librustc/middle/trans/base.rs

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -779,30 +779,6 @@ fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
779779
};
780780
}
781781
782-
fn get_discrim_val(cx: @crate_ctxt, span: span, enum_did: ast::def_id,
783-
variant_did: ast::def_id) -> ValueRef {
784-
// Can't use `discrims` from the crate context here because
785-
// those discriminants have an extra level of indirection,
786-
// and there's no LLVM constant load instruction.
787-
let mut lldiscrim_opt = None;
788-
for ty::enum_variants(cx.tcx, enum_did).each |variant_info| {
789-
if variant_info.id == variant_did {
790-
lldiscrim_opt = Some(C_int(cx,
791-
variant_info.disr_val));
792-
break;
793-
}
794-
}
795-
796-
match lldiscrim_opt {
797-
None => {
798-
cx.tcx.sess.span_bug(span, ~"didn't find discriminant?!");
799-
}
800-
Some(found_lldiscrim) => {
801-
found_lldiscrim
802-
}
803-
}
804-
}
805-
806782
fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
807783
unsafe {
808784
let _icx = ccx.insn_ctxt("lookup_discriminant");
@@ -2308,21 +2284,16 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
23082284
let my_path = vec::append(/*bad*/copy *pth,
23092285
~[path_name(i.ident)]);
23102286
match i.node {
2311-
ast::item_const(_, expr) => {
2287+
ast::item_const(_, _) => {
23122288
let typ = ty::node_id_to_type(ccx.tcx, i.id);
23132289
let s = mangle_exported_name(ccx, my_path, typ);
2314-
// We need the translated value here, because for enums the
2315-
// LLVM type is not fully determined by the Rust type.
2316-
let v = consts::const_expr(ccx, expr);
2317-
ccx.const_values.insert(id, v);
2318-
unsafe {
2319-
let llty = llvm::LLVMTypeOf(v);
2320-
let g = str::as_c_str(s, |buf| {
2321-
llvm::LLVMAddGlobal(ccx.llmod, llty, buf)
2322-
});
2323-
ccx.item_symbols.insert(i.id, s);
2324-
g
2325-
}
2290+
let g = str::as_c_str(s, |buf| {
2291+
unsafe {
2292+
llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, typ), buf)
2293+
}
2294+
});
2295+
ccx.item_symbols.insert(i.id, s);
2296+
g
23262297
}
23272298
ast::item_fn(_, purity, _, _) => {
23282299
let llfn = if purity != ast::extern_fn {

branches/try/src/librustc/middle/trans/consts.rs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,42 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
414414
// variant or we wouldn't have gotten here -- the constant
415415
// checker forbids paths that don't map to C-like enum
416416
// variants.
417-
let lldiscrim = base::get_discrim_val(cx, e.span,
418-
enum_did,
419-
variant_did);
420-
C_struct(~[lldiscrim])
417+
let ety = ty::expr_ty(cx.tcx, e);
418+
let llty = type_of::type_of(cx, ety);
419+
420+
// Can't use `discrims` from the crate context here
421+
// because those discriminants have an extra level of
422+
// indirection, and there's no LLVM constant load
423+
// instruction.
424+
let mut lldiscrim_opt = None;
425+
for ty::enum_variants(cx.tcx, enum_did).each
426+
|variant_info| {
427+
if variant_info.id == variant_did {
428+
lldiscrim_opt = Some(C_int(cx,
429+
variant_info.disr_val));
430+
break;
431+
}
432+
}
433+
434+
let lldiscrim;
435+
match lldiscrim_opt {
436+
None => {
437+
cx.tcx.sess.span_bug(e.span,
438+
~"didn't find discriminant?!");
439+
}
440+
Some(found_lldiscrim) => {
441+
lldiscrim = found_lldiscrim;
442+
}
443+
}
444+
let fields = if ty::enum_is_univariant(cx.tcx, enum_did) {
445+
~[lldiscrim]
446+
} else {
447+
let llstructtys =
448+
lib::llvm::struct_element_types(llty);
449+
~[lldiscrim, C_null(llstructtys[1])]
450+
};
451+
452+
C_named_struct(llty, fields)
421453
}
422454
Some(ast::def_struct(_)) => {
423455
let ety = ty::expr_ty(cx.tcx, e);
@@ -443,24 +475,6 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
443475
C_named_struct(llty, ~[ llstructbody ])
444476
}
445477
}
446-
Some(ast::def_variant(tid, vid)) => {
447-
let ety = ty::expr_ty(cx.tcx, e);
448-
let degen = ty::enum_is_univariant(cx.tcx, tid);
449-
let size = shape::static_size_of_enum(cx, ety);
450-
451-
let discrim = base::get_discrim_val(cx, e.span, tid, vid);
452-
let c_args = C_struct(args.map(|a| const_expr(cx, *a)));
453-
454-
let fields = if !degen {
455-
~[discrim, c_args]
456-
} else if size == 0 {
457-
~[discrim]
458-
} else {
459-
~[c_args]
460-
};
461-
462-
C_struct(fields)
463-
}
464478
_ => cx.sess.span_bug(e.span, ~"expected a struct def")
465479
}
466480
}
@@ -471,13 +485,12 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
471485
}
472486
}
473487

474-
fn trans_const(ccx: @crate_ctxt, _e: @ast::expr, id: ast::node_id) {
488+
fn trans_const(ccx: @crate_ctxt, e: @ast::expr, id: ast::node_id) {
475489
unsafe {
476490
let _icx = ccx.insn_ctxt("trans_const");
477491
let g = base::get_item_val(ccx, id);
478-
// At this point, get_item_val has already translated the
479-
// constant's initializer to determine its LLVM type.
480-
let v = ccx.const_values.get(id);
492+
let v = const_expr(ccx, e);
493+
ccx.const_values.insert(id, v);
481494
llvm::LLVMSetInitializer(g, v);
482495
llvm::LLVMSetGlobalConstant(g, True);
483496
}

branches/try/src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,7 @@ fn trans_def_lvalue(bcx: block,
798798
ast::def_const(did) => {
799799
let const_ty = expr_ty(bcx, ref_expr);
800800
let val = if did.crate == ast::local_crate {
801-
// The LLVM global has the type of its initializer,
802-
// which may not be equal to the enum's type for
803-
// non-C-like enums.
804-
PointerCast(bcx, base::get_item_val(ccx, did.node),
805-
T_ptr(type_of(bcx.ccx(), const_ty)))
801+
base::get_item_val(ccx, did.node)
806802
} else {
807803
base::trans_external_path(ccx, did, const_ty)
808804
};

branches/try/src/libstd/net_tcp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ pub mod test {
13191319
}
13201320
// Strange failure on Windows. --pcwalton
13211321
#[test]
1322-
#[ignore(cfg(target_os = "windows"))]
1322+
#[ignore(cfg(target_os = "win32"))]
13231323
fn test_gl_tcp_ipv4_server_client_reader_writer() {
13241324
impl_gl_tcp_ipv4_server_client_reader_writer();
13251325
}
@@ -1360,7 +1360,7 @@ pub mod test {
13601360
}
13611361
#[test]
13621362
#[ignore(cfg(target_os = "linux"))]
1363-
#[ignore(cfg(target_os = "windows"))]
1363+
#[ignore(cfg(target_os = "win32"))]
13641364
fn test_gl_tcp_ipv4_server_client_reader_writer() {
13651365
impl_gl_tcp_ipv4_server_client_reader_writer();
13661366
}

branches/try/src/test/run-pass/const-big-enum.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

branches/try/src/test/run-pass/const-enum-byref-self.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

branches/try/src/test/run-pass/const-enum-byref.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

branches/try/src/test/run-pass/const-newtype-enum.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

branches/try/src/test/run-pass/const-nullary-enum.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -21,10 +21,5 @@ fn main() {
2121
Bar => {}
2222
Baz | Boo => fail
2323
}
24-
match Y {
25-
Baz => {}
26-
Bar | Boo => fail
27-
}
2824
}
2925

30-
const Y: Foo = Baz;

branches/try/src/test/run-pass/const-nullary-univariant-enum.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,4 @@ const X: Foo = Bar;
1616

1717
fn main() {
1818
assert((X as uint) == 0xDEADBEE);
19-
assert((Y as uint) == 0xDEADBEE);
2019
}
21-
22-
const Y: Foo = Bar;

0 commit comments

Comments
 (0)