Skip to content

Commit 18aacf5

Browse files
committed
---
yaml --- r: 51306 b: refs/heads/incoming c: 1e1efbf h: refs/heads/master v: v3
1 parent 0ebe443 commit 18aacf5

File tree

10 files changed

+59
-195
lines changed

10 files changed

+59
-195
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: 9b9ffd5b4196d409dd76c224442ee0fee91fd9e4
9+
refs/heads/incoming: 1e1efbf2c355c4ddb1356abe535d79525bad72ba
1010
refs/heads/dist-snap: 8b98e5a296d95c5e832db0756828e5bec31c6f50
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/librustc/back/link.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,11 @@ pub fn link_binary(sess: Session,
818818
do cstore::iter_crate_data(cstore) |crate_num, _| {
819819
let link_args = csearch::get_link_args_for_crate(cstore, crate_num);
820820
do vec::consume(link_args) |_, link_arg| {
821-
cc_args.push(link_arg);
821+
// Linker arguments that don't begin with - are likely file names,
822+
// so they should not be necessary.
823+
if link_arg.starts_with("-") {
824+
cc_args.push(link_arg);
825+
}
822826
}
823827
}
824828

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ pub fn check_expr(sess: Session,
9191
v: visit::vt<bool>) {
9292
if is_const {
9393
match e.node {
94-
expr_unary(deref, _) => { }
95-
expr_unary(box(_), _) | expr_unary(uniq(_), _) => {
94+
expr_unary(box(_), _) | expr_unary(uniq(_), _) |
95+
expr_unary(deref, _) => {
9696
sess.span_err(e.span,
9797
~"disallowed operator in constant expression");
9898
return;

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

Lines changed: 51 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use core::prelude::*;
1212

13-
use back::abi;
1413
use lib::llvm::{llvm, ValueRef, TypeRef, Bool, True, False};
1514
use metadata::csearch;
1615
use middle::const_eval;
@@ -95,56 +94,30 @@ pub fn const_vec(cx: @CrateContext, e: @ast::expr, es: &[@ast::expr])
9594
}
9695
}
9796

98-
fn const_addr_of(cx: @CrateContext, cv: ValueRef) -> ValueRef {
97+
pub fn const_deref(cx: @CrateContext, v: ValueRef) -> ValueRef {
9998
unsafe {
100-
let gv = do str::as_c_str("const") |name| {
101-
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv), name)
99+
let v = match cx.const_globals.find(&(v as int)) {
100+
Some(v) => v,
101+
None => v
102102
};
103-
llvm::LLVMSetInitializer(gv, cv);
104-
llvm::LLVMSetGlobalConstant(gv, True);
105-
gv
106-
}
107-
}
108-
109-
fn const_deref_ptr(cx: @CrateContext, v: ValueRef) -> ValueRef {
110-
let v = match cx.const_globals.find(&(v as int)) {
111-
Some(v) => v,
112-
None => v
113-
};
114-
unsafe {
115103
fail_unless!(llvm::LLVMIsGlobalConstant(v) == True);
116-
llvm::LLVMGetInitializer(v)
104+
let v = llvm::LLVMGetInitializer(v);
105+
v
117106
}
118107
}
119108

120-
fn const_deref_newtype(cx: @CrateContext, v: ValueRef, t: ty::t)
121-
-> ValueRef {
122-
let repr = adt::represent_type(cx, t);
123-
adt::const_get_field(cx, repr, v, 0, 0)
124-
}
125-
126-
fn const_deref(cx: @CrateContext, v: ValueRef, t: ty::t, explicit: bool)
127-
-> (ValueRef, ty::t) {
128-
match ty::deref(cx.tcx, t, explicit) {
129-
Some(ref mt) => {
130-
fail_unless!(mt.mutbl != ast::m_mutbl);
131-
let dv = match ty::get(t).sty {
132-
ty::ty_ptr(*) | ty::ty_rptr(*) => {
133-
const_deref_ptr(cx, v)
134-
}
135-
ty::ty_enum(*) | ty::ty_struct(*) => {
136-
const_deref_newtype(cx, v, t)
137-
}
138-
_ => {
139-
cx.sess.bug(fmt!("Unexpected dereferenceable type %s",
140-
ty_to_str(cx.tcx, t)))
141-
}
142-
};
143-
(dv, mt.ty)
144-
}
145-
None => {
146-
cx.sess.bug(fmt!("Can't dereference const of type %s",
147-
ty_to_str(cx.tcx, t)))
109+
pub fn const_autoderef(cx: @CrateContext, ty: ty::t, v: ValueRef)
110+
-> (ty::t, ValueRef) {
111+
let mut t1 = ty;
112+
let mut v1 = v;
113+
loop {
114+
// Only rptrs can be autoderef'ed in a const context.
115+
match ty::get(t1).sty {
116+
ty::ty_rptr(_, mt) => {
117+
t1 = mt.ty;
118+
v1 = const_deref(cx, v1);
119+
}
120+
_ => return (t1,v1)
148121
}
149122
}
150123
}
@@ -169,68 +142,15 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
169142
}
170143

171144
pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
172-
let mut llconst = const_expr_unadjusted(cx, e);
173-
let ety = ty::expr_ty(cx.tcx, e);
174-
match cx.tcx.adjustments.find(&e.id) {
175-
None => { }
176-
Some(@ty::AutoAddEnv(ty::re_static, ast::BorrowedSigil)) => {
177-
llconst = C_struct(~[llconst, C_null(T_opaque_box_ptr(cx))])
178-
}
179-
Some(@ty::AutoAddEnv(ref r, ref s)) => {
180-
cx.sess.span_bug(e.span, fmt!("unexpected const function: \
181-
region %? sigil %?", *r, *s))
182-
}
183-
Some(@ty::AutoDerefRef(ref adj)) => {
184-
let mut ty = ety;
185-
let mut maybe_ptr = None;
186-
for adj.autoderefs.times {
187-
let (dv, dt) = const_deref(cx, llconst, ty, false);
188-
maybe_ptr = Some(llconst);
189-
llconst = dv;
190-
ty = dt;
191-
}
192-
193-
match adj.autoref {
194-
None => { }
195-
Some(ref autoref) => {
196-
fail_unless!(autoref.region == ty::re_static);
197-
fail_unless!(autoref.mutbl != ast::m_mutbl);
198-
// Don't copy data to do a deref+ref.
199-
let llptr = match maybe_ptr {
200-
Some(ptr) => ptr,
201-
None => const_addr_of(cx, llconst)
202-
};
203-
match autoref.kind {
204-
ty::AutoPtr => {
205-
llconst = llptr;
206-
}
207-
ty::AutoBorrowVec => {
208-
let size = machine::llsize_of(cx,
209-
val_ty(llconst));
210-
fail_unless!(abi::slice_elt_base == 0);
211-
fail_unless!(abi::slice_elt_len == 1);
212-
llconst = C_struct(~[llptr, size]);
213-
}
214-
_ => {
215-
cx.sess.span_bug(e.span,
216-
fmt!("unimplemented const \
217-
autoref %?", autoref))
218-
}
219-
}
220-
}
221-
}
222-
}
223-
}
224-
225-
let ety_adjusted = ty::expr_ty_adjusted(cx.tcx, e);
226-
let llty = type_of::sizing_type_of(cx, ety_adjusted);
145+
let ety = ty::expr_ty_adjusted(cx.tcx, e);
146+
let llty = type_of::sizing_type_of(cx, ety);
147+
let llconst = const_expr_unchecked(cx, e);
227148
let csize = machine::llsize_of_alloc(cx, val_ty(llconst));
228149
let tsize = machine::llsize_of_alloc(cx, llty);
229150
if csize != tsize {
230151
unsafe {
231-
// XXX these values could use some context
232152
llvm::LLVMDumpValue(llconst);
233-
llvm::LLVMDumpValue(C_undef(llty));
153+
llvm::LLVMDumpValue(C_null(llty));
234154
}
235155
cx.sess.bug(fmt!("const %s of type %s has size %u instead of %u",
236156
expr_repr(cx.tcx, e), ty_to_str(cx.tcx, ety),
@@ -239,7 +159,7 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
239159
llconst
240160
}
241161

242-
fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
162+
fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
243163
unsafe {
244164
let _icx = cx.insn_ctxt("const_expr");
245165
return match /*bad*/copy e.node {
@@ -303,10 +223,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
303223
return match u {
304224
ast::box(_) |
305225
ast::uniq(_) |
306-
ast::deref => {
307-
let (dv, _dt) = const_deref(cx, te, ty, true);
308-
dv
309-
}
226+
ast::deref => const_deref(cx, te),
310227
ast::not => {
311228
match ty::get(ty).sty {
312229
ty::ty_bool => {
@@ -326,18 +243,20 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
326243
}
327244
}
328245
ast::expr_field(base, field, _) => {
329-
let bt = ty::expr_ty_adjusted(cx.tcx, base);
246+
let bt = ty::expr_ty(cx.tcx, base);
330247
let brepr = adt::represent_type(cx, bt);
331248
let bv = const_expr(cx, base);
249+
let (bt, bv) = const_autoderef(cx, bt, bv);
332250
do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| {
333251
let ix = ty::field_idx_strict(cx.tcx, field, field_tys);
334252
adt::const_get_field(cx, brepr, bv, discr, ix)
335253
}
336254
}
337255

338256
ast::expr_index(base, index) => {
339-
let bt = ty::expr_ty_adjusted(cx.tcx, base);
257+
let bt = ty::expr_ty(cx.tcx, base);
340258
let bv = const_expr(cx, base);
259+
let (bt, bv) = const_autoderef(cx, bt, bv);
341260
let iv = match const_eval::eval_const_expr(cx.tcx, index) {
342261
const_eval::const_int(i) => i as u64,
343262
const_eval::const_uint(u) => u,
@@ -356,7 +275,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
356275
let llunitty = type_of::type_of(cx, unit_ty);
357276
let unit_sz = machine::llsize_of(cx, llunitty);
358277

359-
(const_deref_ptr(cx, const_get_elt(cx, bv, [0])),
278+
(const_deref(cx, const_get_elt(cx, bv, [0])),
360279
llvm::LLVMConstUDiv(const_get_elt(cx, bv, [1]),
361280
unit_sz))
362281
},
@@ -436,7 +355,13 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
436355
}
437356
}
438357
ast::expr_addr_of(ast::m_imm, sub) => {
439-
const_addr_of(cx, const_expr(cx, sub))
358+
let cv = const_expr(cx, sub);
359+
let gv = do str::as_c_str("const") |name| {
360+
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv), name)
361+
};
362+
llvm::LLVMSetInitializer(gv, cv);
363+
llvm::LLVMSetGlobalConstant(gv, True);
364+
gv
440365
}
441366
ast::expr_tup(es) => {
442367
let ety = ty::expr_ty(cx.tcx, e);
@@ -495,12 +420,26 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
495420
fail_unless!(pth.types.len() == 0);
496421
match cx.tcx.def_map.find(&e.id) {
497422
Some(ast::def_fn(def_id, _purity)) => {
498-
if !ast_util::is_local(def_id) {
423+
let f = if !ast_util::is_local(def_id) {
499424
let ty = csearch::get_type(cx.tcx, def_id).ty;
500425
base::trans_external_path(cx, def_id, ty)
501426
} else {
502427
fail_unless!(ast_util::is_local(def_id));
503428
base::get_item_val(cx, def_id.node)
429+
};
430+
let ety = ty::expr_ty_adjusted(cx.tcx, e);
431+
match ty::get(ety).sty {
432+
ty::ty_bare_fn(*) | ty::ty_ptr(*) => {
433+
llvm::LLVMConstPointerCast(f, T_ptr(T_i8()))
434+
}
435+
ty::ty_closure(*) => {
436+
C_struct(~[f, C_null(T_opaque_box_ptr(cx))])
437+
}
438+
_ => {
439+
cx.sess.span_bug(e.span, fmt!(
440+
"unexpected const fn type: %s",
441+
ty_to_str(cx.tcx, ety)))
442+
}
504443
}
505444
}
506445
Some(ast::def_const(def_id)) => {

branches/incoming/src/libsyntax/print/pprust.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,11 +1192,6 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
11921192
ast::expr_addr_of(m, expr) => {
11931193
word(s.s, ~"&");
11941194
print_mutability(s, m);
1195-
// Avoid `& &e` => `&&e`.
1196-
match (m, &expr.node) {
1197-
(ast::m_imm, &ast::expr_addr_of(*)) => space(s.s),
1198-
_ => { }
1199-
}
12001195
print_expr(s, expr);
12011196
}
12021197
ast::expr_lit(lit) => print_literal(s, lit),

branches/incoming/src/test/run-pass/const-autoderef-newtype.rs

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

branches/incoming/src/test/run-pass/const-autoderef.rs

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

branches/incoming/src/test/run-pass/const-deref.rs

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

branches/incoming/src/test/run-pass/const-region-ptrs-noncopy.rs

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

0 commit comments

Comments
 (0)