Skip to content

Commit a16b21c

Browse files
committed
---
yaml --- r: 47061 b: refs/heads/try c: 9ea05a4 h: refs/heads/master i: 47059: f268033 v: v3
1 parent d4ab344 commit a16b21c

31 files changed

+397
-226
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: 3bbcac322669cff3abde5be937cc4ec3860f3985
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
5-
refs/heads/try: 0991437c3b8e801080119b754ce4ebf8d4ef9b01
5+
refs/heads/try: 9ea05a4d3e5a8ca5a5ca9585f88d3fadda83b60c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/etc/emacs/rust-mode.el

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
(require 'cm-mode)
99
(require 'cc-mode)
10-
(eval-when-compile (require 'cl))
1110

1211
(defun rust-electric-brace (arg)
1312
(interactive "*P")
@@ -17,6 +16,12 @@
1716
'(font-lock-comment-face font-lock-string-face))))
1817
(cm-indent)))
1918

19+
(defcustom rust-capitalized-idents-are-types t
20+
"If non-nil, capitalized identifiers will be treated as types for the purposes of font-lock mode"
21+
:type 'boolean
22+
:require 'rust-mode
23+
:group 'rust-mode)
24+
2025
(defvar rust-indent-unit 4)
2126
(defvar rust-syntax-table (let ((table (make-syntax-table)))
2227
(c-populate-syntax-table table)
@@ -101,14 +106,7 @@
101106
(rust-push-context st 'string (current-column) t)
102107
(setf (rust-state-tokenize st) 'rust-token-string)
103108
(rust-token-string st))
104-
(def ?\' (forward-char)
105-
(setf rust-tcat 'atom)
106-
(let ((is-escape (eq (char-after) ?\\))
107-
(start (point)))
108-
(if (not (rust-eat-until-unescaped ?\'))
109-
'font-lock-warning-face
110-
(if (or is-escape (= (point) (+ start 2)))
111-
'font-lock-string-face 'font-lock-warning-face))))
109+
(def ?\' (rust-single-quote))
112110
(def ?/ (forward-char)
113111
(case (char-after)
114112
(?/ (end-of-line) 'font-lock-comment-face)
@@ -122,12 +120,7 @@
122120
((rust-eat-re "[a-z_]+") (setf rust-tcat 'macro)))
123121
'font-lock-preprocessor-face)
124122
(def ((?a . ?z) (?A . ?Z) ?_)
125-
(rust-eat-re "[a-zA-Z_][a-zA-Z0-9_]*")
126-
(setf rust-tcat 'ident)
127-
(if (and (eq (char-after) ?:) (eq (char-after (+ (point) 1)) ?:)
128-
(not (eq (char-after (+ (point) 2)) ?:)))
129-
(progn (forward-char 2) 'font-lock-builtin-face)
130-
(match-string 0)))
123+
(rust-token-identifier))
131124
(def ((?0 . ?9))
132125
(rust-eat-re "0x[0-9a-fA-F_]+\\|0b[01_]+\\|[0-9_]+\\(\\.[0-9_]+\\)?\\(e[+\\-]?[0-9_]+\\)?")
133126
(setf rust-tcat 'atom)
@@ -150,6 +143,31 @@
150143
(setf rust-tcat 'op) nil)
151144
table)))
152145

146+
(defun rust-token-identifier ()
147+
(rust-eat-re "[a-zA-Z_][a-zA-Z0-9_]*")
148+
(setf rust-tcat 'ident)
149+
(if (and (eq (char-after) ?:) (eq (char-after (+ (point) 1)) ?:)
150+
(not (eq (char-after (+ (point) 2)) ?:)))
151+
(progn (forward-char 2) 'font-lock-builtin-face)
152+
(match-string 0)))
153+
154+
(defun rust-single-quote ()
155+
(forward-char)
156+
(setf rust-tcat 'atom)
157+
; Is this a lifetime?
158+
(if (or (looking-at "[a-zA-Z_]$")
159+
(looking-at "[a-zA-Z_][^']"))
160+
; If what we see is 'abc, use font-lock-builtin-face:
161+
(progn (rust-eat-re "[a-zA-Z_][a-zA-Z_0-9]*")
162+
'font-lock-builtin-face)
163+
; Otherwise, handle as a character constant:
164+
(let ((is-escape (eq (char-after) ?\\))
165+
(start (point)))
166+
(if (not (rust-eat-until-unescaped ?\'))
167+
'font-lock-warning-face
168+
(if (or is-escape (= (point) (+ start 2)))
169+
'font-lock-string-face 'font-lock-warning-face)))))
170+
153171
(defun rust-token-base (st)
154172
(funcall (char-table-range rust-char-table (char-after)) st))
155173

@@ -190,6 +208,10 @@
190208
(dolist (cx (rust-state-context st))
191209
(when (eq (rust-context-type cx) ?\}) (return (rust-context-info cx)))))
192210

211+
(defun rust-is-capitalized (string)
212+
(let ((case-fold-search nil))
213+
(string-match-p "[A-Z]" string)))
214+
193215
(defun rust-token (st)
194216
(let ((cx (car (rust-state-context st))))
195217
(when (bolp)
@@ -206,6 +228,8 @@
206228
(setf tok (cond ((eq tok-id 'atom) 'font-lock-constant-face)
207229
(tok-id 'font-lock-keyword-face)
208230
((equal (rust-state-last-token st) 'def) 'font-lock-function-name-face)
231+
((and rust-capitalized-idents-are-types
232+
(rust-is-capitalized tok)) 'font-lock-type-face)
209233
(t nil))))
210234
(when rust-tcat
211235
(when (eq (rust-context-align cx) 'unset)

branches/try/src/etc/vim/syntax/rust.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ syn match rustAssert "\<assert\(\w\)*"
1414
syn keyword rustKeyword as break
1515
syn keyword rustKeyword copy do drop else extern
1616
syn keyword rustKeyword for if impl let log
17-
syn keyword rustKeyword loop match mod move once priv pub pure
17+
syn keyword rustKeyword loop match mod once priv pub pure
1818
syn keyword rustKeyword ref return static
1919
syn keyword rustKeyword unsafe use while
2020
" FIXME: Scoped impl's name is also fallen in this category

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,7 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
497497

498498
let cmh_items = attr::sort_meta_items(cmh_items);
499499

500-
symbol_hasher.reset();
501-
for cmh_items.each |m| {
500+
fn hash(symbol_hasher: &hash::State, m: &@ast::meta_item) {
502501
match m.node {
503502
ast::meta_name_value(ref key, value) => {
504503
symbol_hasher.write_str(len_and_str((*key)));
@@ -507,13 +506,20 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
507506
ast::meta_word(ref name) => {
508507
symbol_hasher.write_str(len_and_str((*name)));
509508
}
510-
ast::meta_list(_, _) => {
511-
// FIXME (#607): Implement this
512-
fail!(~"unimplemented meta_item variant");
509+
ast::meta_list(ref name, ref mis) => {
510+
symbol_hasher.write_str(len_and_str((*name)));
511+
for mis.each |m_| {
512+
hash(symbol_hasher, m_);
513+
}
513514
}
514515
}
515516
}
516517

518+
symbol_hasher.reset();
519+
for cmh_items.each |m| {
520+
hash(symbol_hasher, m);
521+
}
522+
517523
for dep_hashes.each |dh| {
518524
symbol_hasher.write_str(len_and_str(*dh));
519525
}

branches/try/src/librustc/driver/driver.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,20 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
8888

8989
let mk = attr::mk_name_value_item_str;
9090

91-
let (arch,wordsz) = match sess.targ_cfg.arch {
92-
session::arch_x86 => (~"x86",~"32"),
93-
session::arch_x86_64 => (~"x86_64",~"64"),
94-
session::arch_arm => (~"arm",~"32")
91+
// ARM is bi-endian, however using NDK seems to default
92+
// to little-endian unless a flag is provided.
93+
let (end,arch,wordsz) = match sess.targ_cfg.arch {
94+
session::arch_x86 => (~"little",~"x86",~"32"),
95+
session::arch_x86_64 => (~"little",~"x86_64",~"64"),
96+
session::arch_arm => (~"little",~"arm",~"32")
9597
};
9698

9799
return ~[ // Target bindings.
98100
attr::mk_word_item(str::from_slice(os::FAMILY)),
99101
mk(~"target_os", tos),
100102
mk(~"target_family", str::from_slice(os::FAMILY)),
101103
mk(~"target_arch", arch),
104+
mk(~"target_endian", end),
102105
mk(~"target_word_size", wordsz),
103106
mk(~"target_libc", libc),
104107
// Build bindings.

branches/try/src/librustc/metadata/creader.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub fn read_crates(diag: span_handler,
5555
visit_view_item: |a| visit_view_item(e, a),
5656
visit_item: |a| visit_item(e, a),
5757
.. *visit::default_simple_visitor()});
58-
visit_crate(e, crate);
5958
visit::visit_crate(crate, (), v);
6059
dump_crates(e.crate_cache);
6160
warn_if_multiple_versions(e, diag, e.crate_cache);
@@ -126,20 +125,6 @@ struct Env {
126125
intr: @ident_interner
127126
}
128127

129-
fn visit_crate(e: @mut Env, c: ast::crate) {
130-
let cstore = e.cstore;
131-
let link_args = attr::find_attrs_by_name(c.node.attrs, "link_args");
132-
133-
for link_args.each |a| {
134-
match attr::get_meta_item_value_str(attr::attr_meta(*a)) {
135-
Some(ref linkarg) => {
136-
cstore::add_used_link_args(cstore, (/*bad*/copy *linkarg));
137-
}
138-
None => {/* fallthrough */ }
139-
}
140-
}
141-
}
142-
143128
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
144129
match /*bad*/copy i.node {
145130
ast::view_item_use(ident, meta_items, id) => {
@@ -196,7 +181,7 @@ fn visit_item(e: @mut Env, i: @ast::item) {
196181
for link_args.each |a| {
197182
match attr::get_meta_item_value_str(attr::attr_meta(*a)) {
198183
Some(ref linkarg) => {
199-
cstore::add_used_link_args(cstore, *linkarg);
184+
cstore::add_used_link_args(cstore, (/*bad*/copy *linkarg));
200185
}
201186
None => {/* fallthrough */ }
202187
}

branches/try/src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn get_used_libraries(cstore: @mut CStore) -> ~[~str] {
119119
return /*bad*/copy cstore.used_libraries;
120120
}
121121

122-
pub fn add_used_link_args(cstore: @mut CStore, args: &str) {
122+
pub fn add_used_link_args(cstore: @mut CStore, args: ~str) {
123123
cstore.used_link_args.push_all(str::split_char(args, ' '));
124124
}
125125

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
821821
let ebml_w = copy ebml_w;
822822
ast_util::visit_ids_for_inlined_item(
823823
ii,
824-
fn@(id: ast::node_id, copy ebml_w) {
824+
fn@(id: ast::node_id) {
825825
// Note: this will cause a copy of ebml_w, which is bad as
826826
// it has mut fields. But I believe it's harmless since
827827
// we generate balanced EBML.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,7 @@ pub fn trans_crate(sess: session::Session,
30303030
const_values: HashMap(),
30313031
module_data: HashMap(),
30323032
lltypes: ty::new_ty_hash(),
3033+
llsizingtypes: ty::new_ty_hash(),
30333034
names: new_namegen(sess.parse_sess.interner),
30343035
next_addrspace: new_addrspace_gen(),
30353036
symbol_hasher: symbol_hasher,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ pub struct crate_ctxt {
202202
const_values: HashMap<ast::node_id, ValueRef>,
203203
module_data: HashMap<~str, ValueRef>,
204204
lltypes: HashMap<ty::t, TypeRef>,
205+
llsizingtypes: HashMap<ty::t, TypeRef>,
205206
names: namegen,
206207
next_addrspace: addrspace_gen,
207208
symbol_hasher: @hash::State,

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

Lines changed: 33 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,8 @@
1313

1414
use middle::trans::common::*;
1515
use middle::trans::type_of;
16-
use middle::ty::field;
1716
use middle::ty;
18-
19-
use syntax::parse::token::special_idents;
20-
21-
// Creates a simpler, size-equivalent type. The resulting type is guaranteed
22-
// to have (a) the same size as the type that was passed in; (b) to be non-
23-
// recursive. This is done by replacing all boxes in a type with boxed unit
24-
// types.
25-
// This should reduce all pointers to some simple pointer type, to
26-
// ensure that we don't recurse endlessly when computing the size of a
27-
// nominal type that has pointers to itself in it.
28-
pub fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t {
29-
fn nilptr(tcx: ty::ctxt) -> ty::t {
30-
ty::mk_ptr(tcx, ty::mt {ty: ty::mk_nil(tcx), mutbl: ast::m_imm})
31-
}
32-
fn simplifier(tcx: ty::ctxt, typ: ty::t) -> ty::t {
33-
match ty::get(typ).sty {
34-
ty::ty_box(_) | ty::ty_opaque_box | ty::ty_uniq(_) |
35-
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_box) |
36-
ty::ty_estr(ty::vstore_uniq) | ty::ty_estr(ty::vstore_box) |
37-
ty::ty_ptr(_) | ty::ty_rptr(*) => nilptr(tcx),
38-
39-
ty::ty_bare_fn(*) | // FIXME(#4804) Bare fn repr
40-
ty::ty_closure(*) => ty::mk_tup(tcx, ~[nilptr(tcx), nilptr(tcx)]),
41-
42-
ty::ty_evec(_, ty::vstore_slice(_)) |
43-
ty::ty_estr(ty::vstore_slice(_)) => {
44-
ty::mk_tup(tcx, ~[nilptr(tcx), ty::mk_int(tcx)])
45-
}
46-
// Reduce a class type to a record type in which all the fields are
47-
// simplified
48-
ty::ty_struct(did, ref substs) => {
49-
let simpl_fields = (if ty::ty_dtor(tcx, did).is_present() {
50-
// remember the drop flag
51-
~[field {
52-
ident: special_idents::dtor,
53-
mt: ty::mt {ty: ty::mk_u8(tcx), mutbl: ast::m_mutbl}
54-
}] }
55-
else { ~[] }) +
56-
do ty::lookup_struct_fields(tcx, did).map |f| {
57-
let t = ty::lookup_field_type(tcx, did, f.id, substs);
58-
field {
59-
ident: f.ident,
60-
mt: ty::mt {ty: simplify_type(tcx, t), mutbl: ast::m_const
61-
}}
62-
};
63-
ty::mk_rec(tcx, simpl_fields)
64-
}
65-
_ => typ
66-
}
67-
}
68-
ty::fold_ty(tcx, typ, |t| simplifier(tcx, t))
69-
}
17+
use util::ppaux::ty_to_str;
7018

7119
// ______________________________________________________________________
7220
// compute sizeof / alignof
@@ -180,27 +128,40 @@ pub fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
180128

181129
// Computes the size of the data part of an enum.
182130
pub fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint {
183-
if cx.enum_sizes.contains_key(&t) { return cx.enum_sizes.get(&t); }
131+
if cx.enum_sizes.contains_key(&t) {
132+
return cx.enum_sizes.get(&t);
133+
}
134+
135+
debug!("static_size_of_enum %s", ty_to_str(cx.tcx, t));
136+
184137
match ty::get(t).sty {
185-
ty::ty_enum(tid, ref substs) => {
186-
// Compute max(variant sizes).
187-
let mut max_size = 0u;
188-
let variants = ty::enum_variants(cx.tcx, tid);
189-
for vec::each(*variants) |variant| {
190-
let tup_ty = simplify_type(
191-
cx.tcx,
192-
ty::mk_tup(cx.tcx, /*bad*/copy variant.args));
193-
// Perform any type parameter substitutions.
194-
let tup_ty = ty::subst(cx.tcx, substs, tup_ty);
195-
// Here we possibly do a recursive call.
196-
let this_size =
197-
llsize_of_real(cx, type_of::type_of(cx, tup_ty));
198-
if max_size < this_size { max_size = this_size; }
138+
ty::ty_enum(tid, ref substs) => {
139+
// Compute max(variant sizes).
140+
let mut max_size = 0;
141+
let variants = ty::enum_variants(cx.tcx, tid);
142+
for variants.each |variant| {
143+
if variant.args.len() == 0 {
144+
loop;
145+
}
146+
147+
let lltypes = variant.args.map(|&variant_arg| {
148+
let substituted = ty::subst(cx.tcx, substs, variant_arg);
149+
type_of::sizing_type_of(cx, substituted)
150+
});
151+
152+
debug!("static_size_of_enum: variant %s type %s",
153+
cx.tcx.sess.str_of(variant.name),
154+
ty_str(cx.tn, T_struct(lltypes)));
155+
156+
let this_size = llsize_of_real(cx, T_struct(lltypes));
157+
if max_size < this_size {
158+
max_size = this_size;
159+
}
160+
}
161+
cx.enum_sizes.insert(t, max_size);
162+
return max_size;
199163
}
200-
cx.enum_sizes.insert(t, max_size);
201-
return max_size;
202-
}
203-
_ => cx.sess.bug(~"static_size_of_enum called on non-enum")
164+
_ => cx.sess.bug(~"static_size_of_enum called on non-enum")
204165
}
205166
}
206167

0 commit comments

Comments
 (0)