diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-08-07 15:04:40 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-08-07 15:04:40 -0700 |
| commit | 32e4fd62e968cba994aa4e4a85b00c072fe58bc1 (patch) | |
| tree | 6201e4b3e1007f8b02e7fb95ef8aed20026fbb40 /src/rustc | |
| parent | 42540841f300b360fe8c2f91ee10ad3719269974 (diff) | |
| download | rust-32e4fd62e968cba994aa4e4a85b00c072fe58bc1.tar.gz rust-32e4fd62e968cba994aa4e4a85b00c072fe58bc1.zip | |
Const slices now work. Something odd about non-const cases though, see #3138.
Diffstat (limited to 'src/rustc')
| -rw-r--r-- | src/rustc/middle/trans/consts.rs | 17 | ||||
| -rw-r--r-- | src/rustc/middle/typeck/check.rs | 3 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/rustc/middle/trans/consts.rs b/src/rustc/middle/trans/consts.rs index 49ea20c6e85..3f17352b915 100644 --- a/src/rustc/middle/trans/consts.rs +++ b/src/rustc/middle/trans/consts.rs @@ -32,15 +32,15 @@ fn const_lit(cx: @crate_ctxt, e: @ast::expr, lit: ast::lit) // duplicate constants. I think. Maybe LLVM has a magical mode that does so // later on? -fn const_vec_and_sz(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr]) - -> (ValueRef, ValueRef) { +fn const_vec(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr]) + -> (ValueRef, ValueRef, TypeRef) { let vec_ty = ty::expr_ty(cx.tcx, e); let unit_ty = ty::sequence_element_type(cx.tcx, vec_ty); let llunitty = type_of::type_of(cx, unit_ty); let v = C_array(llunitty, es.map(|e| const_expr(cx, e))); let unit_sz = shape::llsize_of(cx, llunitty); let sz = llvm::LLVMConstMul(C_uint(cx, es.len()), unit_sz); - return (v, sz); + return (v, sz, llunitty); } fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { @@ -157,7 +157,7 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { C_struct(fs.map(|f| const_expr(cx, f.node.expr))) } ast::expr_vec(es, m_imm) => { - let (v, _) = const_vec_and_sz(cx, e, es); + let (v, _, _) = const_vec(cx, e, es); v } ast::expr_vstore(e, ast::vstore_fixed(_)) => { @@ -173,15 +173,16 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { } } ast::expr_vec(es, m_imm) => { - let (cv, sz) = const_vec_and_sz(cx, e, es); - let subty = ty::expr_ty(cx.tcx, sub), - llty = type_of::type_of(cx, subty); + let (cv, sz, llunitty) = const_vec(cx, e, es); + let llty = val_ty(cv); let gv = do str::as_c_str("const") |name| { llvm::LLVMAddGlobal(cx.llmod, llty, name) }; llvm::LLVMSetInitializer(gv, cv); llvm::LLVMSetGlobalConstant(gv, True); - C_struct(~[gv, sz]) + let p = llvm::LLVMConstPointerCast(gv, T_ptr(llunitty)); + + C_struct(~[p, sz]) } _ => cx.sess.span_bug(e.span, ~"bad const-slice expr") diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index c62861e211d..5b0f663114d 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -2315,8 +2315,7 @@ fn ast_expr_vstore_to_vstore(fcx: @fn_ctxt, e: @ast::expr, n: uint, ast::vstore_box => ty::vstore_box, ast::vstore_slice(a_r) => match fcx.block_region() { result::ok(b_r) => { - let rscope = in_anon_rscope(fcx, b_r); - let r = astconv::ast_region_to_region(fcx, rscope, e.span, a_r); + let r = fcx.infcx.next_region_var_with_scope_lb(e.id); ty::vstore_slice(r) } result::err(msg) => { |
