Skip to content

Commit d4ab344

Browse files
committed
---
yaml --- r: 47060 b: refs/heads/try c: 0991437 h: refs/heads/master v: v3
1 parent f268033 commit d4ab344

29 files changed

+211
-366
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: aa8af12228f023877ab9f6c39878f95a8ee05bf9
5+
refs/heads/try: 0991437c3b8e801080119b754ce4ebf8d4ef9b01
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: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

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

1112
(defun rust-electric-brace (arg)
1213
(interactive "*P")
@@ -16,12 +17,6 @@
1617
'(font-lock-comment-face font-lock-string-face))))
1718
(cm-indent)))
1819

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-
2520
(defvar rust-indent-unit 4)
2621
(defvar rust-syntax-table (let ((table (make-syntax-table)))
2722
(c-populate-syntax-table table)
@@ -106,7 +101,14 @@
106101
(rust-push-context st 'string (current-column) t)
107102
(setf (rust-state-tokenize st) 'rust-token-string)
108103
(rust-token-string st))
109-
(def ?\' (rust-single-quote))
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))))
110112
(def ?/ (forward-char)
111113
(case (char-after)
112114
(?/ (end-of-line) 'font-lock-comment-face)
@@ -120,7 +122,12 @@
120122
((rust-eat-re "[a-z_]+") (setf rust-tcat 'macro)))
121123
'font-lock-preprocessor-face)
122124
(def ((?a . ?z) (?A . ?Z) ?_)
123-
(rust-token-identifier))
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)))
124131
(def ((?0 . ?9))
125132
(rust-eat-re "0x[0-9a-fA-F_]+\\|0b[01_]+\\|[0-9_]+\\(\\.[0-9_]+\\)?\\(e[+\\-]?[0-9_]+\\)?")
126133
(setf rust-tcat 'atom)
@@ -143,31 +150,6 @@
143150
(setf rust-tcat 'op) nil)
144151
table)))
145152

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-
171153
(defun rust-token-base (st)
172154
(funcall (char-table-range rust-char-table (char-after)) st))
173155

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

211-
(defun rust-is-capitalized (string)
212-
(let ((case-fold-search nil))
213-
(string-match-p "[A-Z]" string)))
214-
215193
(defun rust-token (st)
216194
(let ((cx (car (rust-state-context st))))
217195
(when (bolp)
@@ -228,8 +206,6 @@
228206
(setf tok (cond ((eq tok-id 'atom) 'font-lock-constant-face)
229207
(tok-id 'font-lock-keyword-face)
230208
((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)
233209
(t nil))))
234210
(when rust-tcat
235211
(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 once priv pub pure
17+
syn keyword rustKeyword loop match mod move 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/driver/driver.rs

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

8989
let mk = attr::mk_name_value_item_str;
9090

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")
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")
9795
};
9896

9997
return ~[ // Target bindings.
10098
attr::mk_word_item(str::from_slice(os::FAMILY)),
10199
mk(~"target_os", tos),
102100
mk(~"target_family", str::from_slice(os::FAMILY)),
103101
mk(~"target_arch", arch),
104-
mk(~"target_endian", end),
105102
mk(~"target_word_size", wordsz),
106103
mk(~"target_libc", libc),
107104
// Build bindings.

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ 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);
5859
visit::visit_crate(crate, (), v);
5960
dump_crates(e.crate_cache);
6061
warn_if_multiple_versions(e, diag, e.crate_cache);
@@ -125,6 +126,20 @@ struct Env {
125126
intr: @ident_interner
126127
}
127128

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+
128143
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
129144
match /*bad*/copy i.node {
130145
ast::view_item_use(ident, meta_items, id) => {
@@ -181,7 +196,7 @@ fn visit_item(e: @mut Env, i: @ast::item) {
181196
for link_args.each |a| {
182197
match attr::get_meta_item_value_str(attr::attr_meta(*a)) {
183198
Some(ref linkarg) => {
184-
cstore::add_used_link_args(cstore, (/*bad*/copy *linkarg));
199+
cstore::add_used_link_args(cstore, *linkarg);
185200
}
186201
None => {/* fallthrough */ }
187202
}

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) {
824+
fn@(id: ast::node_id, copy ebml_w) {
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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,6 @@ 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(),
30343033
names: new_namegen(sess.parse_sess.interner),
30353034
next_addrspace: new_addrspace_gen(),
30363035
symbol_hasher: symbol_hasher,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ 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>,
206205
names: namegen,
207206
next_addrspace: addrspace_gen,
208207
symbol_hasher: @hash::State,

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

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

1414
use middle::trans::common::*;
1515
use middle::trans::type_of;
16+
use middle::ty::field;
1617
use middle::ty;
17-
use util::ppaux::ty_to_str;
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+
}
1870

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

129181
// Computes the size of the data part of an enum.
130182
pub fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint {
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-
183+
if cx.enum_sizes.contains_key(&t) { return cx.enum_sizes.get(&t); }
137184
match ty::get(t).sty {
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;
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; }
163199
}
164-
_ => cx.sess.bug(~"static_size_of_enum called on non-enum")
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")
165204
}
166205
}
167206

0 commit comments

Comments
 (0)