Skip to content

Commit bfc1fd7

Browse files
committed
---
yaml --- r: 138939 b: refs/heads/try2 c: b5334c3 h: refs/heads/master i: 138937: 93524c9 138935: da0d66a v: v3
1 parent eb2101d commit bfc1fd7

File tree

13 files changed

+407
-169
lines changed

13 files changed

+407
-169
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e28d4b3516f0703ddb5407bf8cd7fc7e273743bb
8+
refs/heads/try2: b5334c3095a024f934a91ba82bd88fe2696919d1
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/RELEASES.txt

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,85 @@
1-
Version 0.6 (?)
1+
Version 0.6 (March 2013)
22
---------------------------
33

4+
* ~??? changes, numerous bugfixes
5+
6+
* TODO:
7+
* Ord/Cmp
8+
* Lifetime changes
9+
* Implicit self
10+
* Remove `static` keyword
11+
* Static method syntax
12+
* `as Trait`
13+
* `copy` removed?
14+
15+
* Syntax changes
16+
* The self type parameter in traits is now spelled `Self`
17+
* Replaced the `Durable` trait with the `'static` lifetime
18+
* The old closure type syntax with the trailing sigil has been
19+
removed in favor of the more consistent leading sigil
20+
* `super` is a keyword, and may be prefixed to paths
21+
* Trait bounds are separated with `+` instead of whitespace
22+
* Traits are implemented with `impl Trait for Type`
23+
instead of `impl Type: Trait`
24+
* The `export` keyword has finally been removed
25+
* The `move` keyword has been removed (linear types move by default)
26+
* The interior mutability qualifier on vectors, `[mut T]`, has been
27+
removed. Use `&mut [T]`, etc.
28+
* `mut` is no longer valid in `~mut T`. Use inherited mutability
29+
* `fail` is no longer a keyword. Use `fail!()`
30+
* `assert` is no longer a keyword. Use `assert!()`
31+
* `log` is no longer a keyword. use `debug!`, etc.
32+
* 1-tuples may be represented as `(T,)`
33+
* Struct fields may no longer be `mut`. Use inherited mutability,
34+
`@mut T`, `core::mut` or `core::cell`
35+
* `extern mod { ... }` is no longer valid syntax for foreign
36+
function modules. Use extern blocks: `extern { ... }`
37+
* Newtype enums removed. Used tuple-structs.
38+
* Trait implementations no longer support visibility modifiers
39+
40+
* Semantic changes
41+
* Linear types move by default, eliminating the `move` keyword
42+
* All foreign functions are considered unsafe
43+
* &mut is now unaliasable
44+
* Writes to borrowed @mut pointers are prevented dynamically
45+
* () has size 0
46+
* The name of the main function can be customized using #[main]
47+
* The default type of an inferred closure is &fn instead of @fn
48+
* Name resolution continues to be tweaked
49+
* Method visibility is inherited from the implementation declaration
50+
51+
* Other language changes
52+
* Structural records have been removed
53+
* Many more types can be used in constants, including enums
54+
`static lifetime pointers and vectors
55+
* Pattern matching over vectors improved and expanded
56+
* Typechecking of closure types has been overhauled to
57+
improve inference and eliminate unsoundness
58+
459
* Libraries
5-
* `core::send_map` renamed to `core::hashmap`
60+
* Lots of effort to organize the container API's around `core::container`
61+
* `core::send_map` renamed to `core::hashmap`
62+
* Added big integers to `std::bigint`
63+
* Removed `core::oldcomm` module
64+
* Added pipe-based `core::comm` module
65+
* Reimplemented `std::treemap`
66+
* Numeric traits have been reorganized under `core::num`
67+
* `core::dvec` removed. Use `@mut ~[T]` or other language types
68+
* `vec::slice` finally returns a slice
69+
* `debug!` and friends don't require a format string, e.g. `debug!(Foo)`
70+
71+
* Tools
72+
* Replaced the 'cargo' package manager with 'rustpkg'
73+
* Added all-purpose 'rust' tool
74+
* `rustc --test` now supports a benchmarks with the `#[bench]` attribute
75+
* rustc now attempts to offer spelling suggestions
76+
77+
* Misc
78+
* Improved support for ARM and Android
79+
* Preliminary MIPS backend
80+
* Improved foreign function ABI implementation for x86, x86_64
81+
* Various and memory usage improvements
82+
* Rust code may be embedded in foreign code under limited circumstances
683

784
Version 0.5 (December 2012)
885
---------------------------

branches/try2/src/libcore/option.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ let unwrapped_msg = match msg {
4242
*/
4343

4444
use cmp::{Eq,Ord};
45+
use ops::Add;
4546
use kinds::Copy;
4647
use util;
4748
use num::Zero;
@@ -85,6 +86,18 @@ impl<T:Ord> Ord for Option<T> {
8586
}
8687
}
8788

89+
impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
90+
#[inline(always)]
91+
pure fn add(&self, other: &Option<T>) -> Option<T> {
92+
match (*self, *other) {
93+
(None, None) => None,
94+
(_, None) => *self,
95+
(None, _) => *other,
96+
(Some(ref lhs), Some(ref rhs)) => Some(*lhs + *rhs)
97+
}
98+
}
99+
}
100+
88101
#[inline(always)]
89102
pub pure fn get<T:Copy>(opt: Option<T>) -> T {
90103
/*!

branches/try2/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(box(_), _) | expr_unary(uniq(_), _) |
95-
expr_unary(deref, _) => {
94+
expr_unary(deref, _) => { }
95+
expr_unary(box(_), _) | expr_unary(uniq(_), _) => {
9696
sess.span_err(e.span,
9797
~"disallowed operator in constant expression");
9898
return;

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

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

1111
use core::prelude::*;
1212

13+
use back::abi;
1314
use lib::llvm::{llvm, ValueRef, TypeRef, Bool, True, False};
1415
use metadata::csearch;
1516
use middle::const_eval;
@@ -94,30 +95,56 @@ pub fn const_vec(cx: @CrateContext, e: @ast::expr, es: &[@ast::expr])
9495
}
9596
}
9697

97-
pub fn const_deref(cx: @CrateContext, v: ValueRef) -> ValueRef {
98+
fn const_addr_of(cx: @CrateContext, cv: ValueRef) -> ValueRef {
9899
unsafe {
99-
let v = match cx.const_globals.find(&(v as int)) {
100-
Some(v) => v,
101-
None => v
100+
let gv = do str::as_c_str("const") |name| {
101+
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv), name)
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 {
103115
fail_unless!(llvm::LLVMIsGlobalConstant(v) == True);
104-
let v = llvm::LLVMGetInitializer(v);
105-
v
116+
llvm::LLVMGetInitializer(v)
106117
}
107118
}
108119

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)
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)))
121148
}
122149
}
123150
}
@@ -142,15 +169,68 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
142169
}
143170

144171
pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
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);
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);
148227
let csize = machine::llsize_of_alloc(cx, val_ty(llconst));
149228
let tsize = machine::llsize_of_alloc(cx, llty);
150229
if csize != tsize {
151230
unsafe {
231+
// XXX these values could use some context
152232
llvm::LLVMDumpValue(llconst);
153-
llvm::LLVMDumpValue(C_null(llty));
233+
llvm::LLVMDumpValue(C_undef(llty));
154234
}
155235
cx.sess.bug(fmt!("const %s of type %s has size %u instead of %u",
156236
expr_repr(cx.tcx, e), ty_to_str(cx.tcx, ety),
@@ -159,7 +239,7 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
159239
llconst
160240
}
161241

162-
fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
242+
fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
163243
unsafe {
164244
let _icx = cx.insn_ctxt("const_expr");
165245
return match /*bad*/copy e.node {
@@ -223,7 +303,10 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
223303
return match u {
224304
ast::box(_) |
225305
ast::uniq(_) |
226-
ast::deref => const_deref(cx, te),
306+
ast::deref => {
307+
let (dv, _dt) = const_deref(cx, te, ty, true);
308+
dv
309+
}
227310
ast::not => {
228311
match ty::get(ty).sty {
229312
ty::ty_bool => {
@@ -243,20 +326,18 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
243326
}
244327
}
245328
ast::expr_field(base, field, _) => {
246-
let bt = ty::expr_ty(cx.tcx, base);
329+
let bt = ty::expr_ty_adjusted(cx.tcx, base);
247330
let brepr = adt::represent_type(cx, bt);
248331
let bv = const_expr(cx, base);
249-
let (bt, bv) = const_autoderef(cx, bt, bv);
250332
do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| {
251333
let ix = ty::field_idx_strict(cx.tcx, field, field_tys);
252334
adt::const_get_field(cx, brepr, bv, discr, ix)
253335
}
254336
}
255337

256338
ast::expr_index(base, index) => {
257-
let bt = ty::expr_ty(cx.tcx, base);
339+
let bt = ty::expr_ty_adjusted(cx.tcx, base);
258340
let bv = const_expr(cx, base);
259-
let (bt, bv) = const_autoderef(cx, bt, bv);
260341
let iv = match const_eval::eval_const_expr(cx.tcx, index) {
261342
const_eval::const_int(i) => i as u64,
262343
const_eval::const_uint(u) => u,
@@ -275,7 +356,7 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
275356
let llunitty = type_of::type_of(cx, unit_ty);
276357
let unit_sz = machine::llsize_of(cx, llunitty);
277358

278-
(const_deref(cx, const_get_elt(cx, bv, [0])),
359+
(const_deref_ptr(cx, const_get_elt(cx, bv, [0])),
279360
llvm::LLVMConstUDiv(const_get_elt(cx, bv, [1]),
280361
unit_sz))
281362
},
@@ -355,13 +436,7 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
355436
}
356437
}
357438
ast::expr_addr_of(ast::m_imm, 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
439+
const_addr_of(cx, const_expr(cx, sub))
365440
}
366441
ast::expr_tup(es) => {
367442
let ety = ty::expr_ty(cx.tcx, e);
@@ -420,26 +495,12 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
420495
fail_unless!(pth.types.len() == 0);
421496
match cx.tcx.def_map.find(&e.id) {
422497
Some(ast::def_fn(def_id, _purity)) => {
423-
let f = if !ast_util::is_local(def_id) {
498+
if !ast_util::is_local(def_id) {
424499
let ty = csearch::get_type(cx.tcx, def_id).ty;
425500
base::trans_external_path(cx, def_id, ty)
426501
} else {
427502
fail_unless!(ast_util::is_local(def_id));
428503
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-
}
443504
}
444505
}
445506
Some(ast::def_const(def_id)) => {

0 commit comments

Comments
 (0)