Skip to content

Commit 11e2015

Browse files
committed
---
yaml --- r: 47731 b: refs/heads/incoming c: c53b4f3 h: refs/heads/master i: 47729: f3212aa 47727: 505868c v: v3
1 parent 19eb6a9 commit 11e2015

File tree

15 files changed

+291
-227
lines changed

15 files changed

+291
-227
lines changed

[refs]

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

branches/incoming/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/incoming/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/incoming/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/incoming/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

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

Lines changed: 15 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -89,95 +89,6 @@ pub fn type_of_non_gc_box(cx: @crate_ctxt, t: ty::t) -> TypeRef {
8989
}
9090
}
9191

92-
// A "sizing type" is an LLVM type, the size and alignment of which are
93-
// guaranteed to be equivalent to what you would get out of `type_of()`. It's
94-
// useful because:
95-
//
96-
// (1) It may be cheaper to compute the sizing type than the full type if all
97-
// you're interested in is the size and/or alignment;
98-
//
99-
// (2) It won't make any recursive calls to determine the structure of the
100-
// type behind pointers. This can help prevent infinite loops for
101-
// recursive types. For example, `static_size_of_enum()` relies on this
102-
// behavior.
103-
104-
pub fn sizing_type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
105-
if cx.llsizingtypes.contains_key(&t) {
106-
return cx.llsizingtypes.get(&t);
107-
}
108-
109-
let llsizingty = match ty::get(t).sty {
110-
ty::ty_nil | ty::ty_bot => T_nil(),
111-
ty::ty_bool => T_bool(),
112-
ty::ty_int(t) => T_int_ty(cx, t),
113-
ty::ty_uint(t) => T_uint_ty(cx, t),
114-
ty::ty_float(t) => T_float_ty(cx, t),
115-
116-
ty::ty_estr(ty::vstore_uniq) |
117-
ty::ty_estr(ty::vstore_box) |
118-
ty::ty_evec(_, ty::vstore_uniq) |
119-
ty::ty_evec(_, ty::vstore_box) |
120-
ty::ty_box(*) |
121-
ty::ty_opaque_box |
122-
ty::ty_uniq(*) |
123-
ty::ty_ptr(*) |
124-
ty::ty_rptr(*) |
125-
ty::ty_type |
126-
ty::ty_opaque_closure_ptr(*) => T_ptr(T_i8()),
127-
128-
ty::ty_estr(ty::vstore_slice(*)) |
129-
ty::ty_evec(_, ty::vstore_slice(*)) => {
130-
T_struct(~[T_ptr(T_i8()), T_ptr(T_i8())])
131-
}
132-
133-
// FIXME(#4804) Bare fn repr
134-
ty::ty_bare_fn(*) => T_struct(~[T_ptr(T_i8()), T_ptr(T_i8())]),
135-
ty::ty_closure(*) => T_struct(~[T_ptr(T_i8()), T_ptr(T_i8())]),
136-
ty::ty_trait(_, _, vstore) => T_opaque_trait(cx, vstore),
137-
138-
ty::ty_estr(ty::vstore_fixed(size)) => T_array(T_i8(), size),
139-
ty::ty_evec(mt, ty::vstore_fixed(size)) => {
140-
T_array(sizing_type_of(cx, mt.ty), size)
141-
}
142-
143-
ty::ty_unboxed_vec(mt) => T_vec(cx, sizing_type_of(cx, mt.ty)),
144-
145-
ty::ty_tup(ref elems) => {
146-
T_struct(elems.map(|&t| sizing_type_of(cx, t)))
147-
}
148-
149-
ty::ty_rec(ref fields) => {
150-
T_struct(fields.map(|f| sizing_type_of(cx, f.mt.ty)))
151-
}
152-
153-
ty::ty_struct(def_id, ref substs) => {
154-
let fields = ty::lookup_struct_fields(cx.tcx, def_id);
155-
let lltype = T_struct(fields.map(|field| {
156-
let field_type = ty::lookup_field_type(cx.tcx,
157-
def_id,
158-
field.id,
159-
substs);
160-
sizing_type_of(cx, field_type)
161-
}));
162-
if ty::ty_dtor(cx.tcx, def_id).is_present() {
163-
T_struct(~[lltype, T_i8()])
164-
} else {
165-
lltype
166-
}
167-
}
168-
169-
ty::ty_enum(def_id, _) => T_struct(enum_body_types(cx, def_id, t)),
170-
171-
ty::ty_self | ty::ty_infer(*) | ty::ty_param(*) | ty::ty_err(*) => {
172-
cx.tcx.sess.bug(~"fictitious type in sizing_type_of()")
173-
}
174-
};
175-
176-
cx.llsizingtypes.insert(t, llsizingty);
177-
llsizingty
178-
}
179-
180-
// NB: If you update this, be sure to update `sizing_type_of()` as well.
18192
pub fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
18293
debug!("type_of %?: %?", t, ty::get(t));
18394

@@ -325,23 +236,23 @@ pub fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
325236
return llty;
326237
}
327238

328-
pub fn enum_body_types(cx: @crate_ctxt, did: ast::def_id, t: ty::t)
329-
-> ~[TypeRef] {
330-
let univar = ty::enum_is_univariant(cx.tcx, did);
331-
let size = machine::static_size_of_enum(cx, t);
332-
if !univar {
333-
~[T_enum_discrim(cx), T_array(T_i8(), size)]
334-
} else {
335-
~[T_array(T_i8(), size)]
336-
}
337-
}
338-
339-
pub fn fill_type_of_enum(cx: @crate_ctxt,
340-
did: ast::def_id,
341-
t: ty::t,
239+
pub fn fill_type_of_enum(cx: @crate_ctxt, did: ast::def_id, t: ty::t,
342240
llty: TypeRef) {
241+
343242
debug!("type_of_enum %?: %?", t, ty::get(t));
344-
common::set_struct_body(llty, enum_body_types(cx, did, t));
243+
244+
let lltys = {
245+
let univar = ty::enum_is_univariant(cx.tcx, did);
246+
let size = machine::static_size_of_enum(cx, t);
247+
if !univar {
248+
~[T_enum_discrim(cx), T_array(T_i8(), size)]
249+
}
250+
else {
251+
~[T_array(T_i8(), size)]
252+
}
253+
};
254+
255+
common::set_struct_body(llty, lltys);
345256
}
346257

347258
// Want refinements! (Or case classes, I guess

branches/incoming/src/libsyntax/ast.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ pub impl to_bytes::IterBytes for ident {
6767
// Functions may or may not have names.
6868
pub type fn_ident = Option<ident>;
6969
70+
pub struct Lifetime {
71+
id: node_id,
72+
span: span,
73+
ident: ident
74+
}
75+
7076
#[auto_encode]
7177
#[auto_decode]
7278
#[deriving_eq]

0 commit comments

Comments
 (0)