Skip to content

Commit a831e7c

Browse files
committed
Merge remote-tracking branch 'mozilla/master'
2 parents fcb3814 + 0794195 commit a831e7c

32 files changed

+254
-100
lines changed

AUTHORS.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Graydon Hoare <graydon@mozilla.com>
55
Other authors:
66

77
Adam Bozanich <adam.boz@gmail.com>
8+
Aleksander Balicki <balicki.aleksander@gmail.com>
89
Andreas Gal <gal@mozilla.com>
910
Austin Seipp <mad.one@gmail.com>
1011
Ben Striegel <ben.striegel@gmail.com>

mk/install.mk

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
# Installation macro. Call with source directory as arg 1,
66
# destination directory as arg 2, and filename/libname-glob as arg 3
77
ifdef VERBOSE
8-
INSTALL = cp $(1)/$(3) $(2)/$(3)
9-
INSTALL_LIB = cp `ls -rt1 $(1)/$(3) | tail -1` $(2)/
8+
INSTALL = install -m755 -T $(1)/$(3) $(2)/$(3)
9+
INSTALL_LIB = install -m644 `ls -rt1 $(1)/$(3) | tail -1` $(2)/
1010
else
11-
INSTALL = $(Q)$(call E, install: $(2)/$(3)) && cp $(1)/$(3) $(2)/$(3)
11+
INSTALL = $(Q)$(call E, install: $(2)/$(3)) && install -m755 -T $(1)/$(3) $(2)/$(3)
1212
INSTALL_LIB = $(Q)$(call E, install_lib: $(2)/$(3)) && \
13-
cp `ls -rt1 $(1)/$(3) | tail -1` $(2)/
13+
install -m644 `ls -rt1 $(1)/$(3) | tail -1` $(2)/
1414
endif
1515

1616
# The stage we install from

src/comp/metadata/decoder.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn item_family(item: ebml::doc) -> u8 {
8383

8484
fn item_symbol(item: ebml::doc) -> str {
8585
let sym = ebml::get_doc(item, tag_items_data_item_symbol);
86-
ret str::unsafe_from_bytes(ebml::doc_data(sym));
86+
ret str::from_bytes(ebml::doc_data(sym));
8787
}
8888

8989
fn variant_enum_id(d: ebml::doc) -> ast::def_id {
@@ -162,7 +162,7 @@ fn enum_variant_ids(item: ebml::doc, cdata: cmd) -> [ast::def_id] {
162162
// definition the path refers to.
163163
fn resolve_path(path: [ast::ident], data: @[u8]) -> [ast::def_id] {
164164
fn eq_item(data: [u8], s: str) -> bool {
165-
ret str::eq(str::unsafe_from_bytes(data), s);
165+
ret str::eq(str::from_bytes(data), s);
166166
}
167167
let s = str::connect(path, "::");
168168
let md = ebml::new_doc(data);
@@ -178,7 +178,7 @@ fn resolve_path(path: [ast::ident], data: @[u8]) -> [ast::def_id] {
178178

179179
fn item_name(item: ebml::doc) -> ast::ident {
180180
let name = ebml::get_doc(item, tag_paths_data_name);
181-
str::unsafe_from_bytes(ebml::doc_data(name))
181+
str::from_bytes(ebml::doc_data(name))
182182
}
183183

184184
fn lookup_item_name(data: @[u8], id: ast::node_id) -> ast::ident {
@@ -325,7 +325,7 @@ fn read_path(d: ebml::doc) -> {path: str, pos: uint} {
325325
let desc = ebml::doc_data(d);
326326
let pos = ebml::be_uint_from_bytes(@desc, 0u, 4u);
327327
let pathbytes = vec::slice::<u8>(desc, 4u, vec::len::<u8>(desc));
328-
let path = str::unsafe_from_bytes(pathbytes);
328+
let path = str::from_bytes(pathbytes);
329329
ret {path: path, pos: pos};
330330
}
331331

@@ -358,21 +358,21 @@ fn get_meta_items(md: ebml::doc) -> [@ast::meta_item] {
358358
let items: [@ast::meta_item] = [];
359359
ebml::tagged_docs(md, tag_meta_item_word) {|meta_item_doc|
360360
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
361-
let n = str::unsafe_from_bytes(ebml::doc_data(nd));
361+
let n = str::from_bytes(ebml::doc_data(nd));
362362
items += [attr::mk_word_item(n)];
363363
};
364364
ebml::tagged_docs(md, tag_meta_item_name_value) {|meta_item_doc|
365365
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
366366
let vd = ebml::get_doc(meta_item_doc, tag_meta_item_value);
367-
let n = str::unsafe_from_bytes(ebml::doc_data(nd));
368-
let v = str::unsafe_from_bytes(ebml::doc_data(vd));
367+
let n = str::from_bytes(ebml::doc_data(nd));
368+
let v = str::from_bytes(ebml::doc_data(vd));
369369
// FIXME (#611): Should be able to decode meta_name_value variants,
370370
// but currently they can't be encoded
371371
items += [attr::mk_name_value_item_str(n, v)];
372372
};
373373
ebml::tagged_docs(md, tag_meta_item_list) {|meta_item_doc|
374374
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
375-
let n = str::unsafe_from_bytes(ebml::doc_data(nd));
375+
let n = str::from_bytes(ebml::doc_data(nd));
376376
let subitems = get_meta_items(meta_item_doc);
377377
items += [attr::mk_list_item(n, subitems)];
378378
};
@@ -427,7 +427,7 @@ fn get_crate_deps(data: @[u8]) -> [crate_dep] {
427427
let depsdoc = ebml::get_doc(cratedoc, tag_crate_deps);
428428
let crate_num = 1;
429429
ebml::tagged_docs(depsdoc, tag_crate_dep) {|depdoc|
430-
let depname = str::unsafe_from_bytes(ebml::doc_data(depdoc));
430+
let depname = str::from_bytes(ebml::doc_data(depdoc));
431431
deps += [{cnum: crate_num, ident: depname}];
432432
crate_num += 1;
433433
};
@@ -447,7 +447,7 @@ fn list_crate_deps(data: @[u8], out: io::writer) {
447447
fn get_crate_hash(data: @[u8]) -> str {
448448
let cratedoc = ebml::new_doc(data);
449449
let hashdoc = ebml::get_doc(cratedoc, tag_crate_hash);
450-
ret str::unsafe_from_bytes(ebml::doc_data(hashdoc));
450+
ret str::from_bytes(ebml::doc_data(hashdoc));
451451
}
452452

453453
fn list_crate_items(bytes: @[u8], md: ebml::doc, out: io::writer) {

src/comp/metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ fn encode_hash(ebml_w: ebml::writer, hash: str) {
661661
ebml::end_tag(ebml_w);
662662
}
663663

664-
fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> str {
664+
fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> [u8] {
665665

666666
let abbrevs = ty::new_ty_hash();
667667
let ecx = @{ccx: cx, type_abbrevs: abbrevs};
@@ -694,7 +694,7 @@ fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> str {
694694
// Pad this, since something (LLVM, presumably) is cutting off the
695695
// remaining % 4 bytes.
696696
buf_w.write([0u8, 0u8, 0u8, 0u8]);
697-
io::mem_buffer_str(buf)
697+
io::mem_buffer_buf(buf)
698698
}
699699

700700
// Get the encoded string for a type

src/comp/metadata/tydecode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn parse_ident_(st: @pstate, is_last: fn@(char) -> bool) ->
3939
ast::ident {
4040
let rslt = "";
4141
while !is_last(peek(st) as char) {
42-
rslt += str::unsafe_from_byte(next(st));
42+
rslt += str::from_byte(next(st));
4343
}
4444
ret rslt;
4545
}
@@ -226,7 +226,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
226226
while peek(st) as char != ']' {
227227
let name = "";
228228
while peek(st) as char != '=' {
229-
name += str::unsafe_from_byte(next(st));
229+
name += str::from_byte(next(st));
230230
}
231231
st.pos = st.pos + 1u;
232232
fields += [{ident: name, mt: parse_mt(st, conv)}];

src/comp/middle/mut.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import syntax::visit;
55
import syntax::ast_util;
66
import driver::session::session;
77

8-
enum deref_t { unbox, field, index, }
8+
enum deref_t { unbox(bool), field, index, }
99

1010
type deref = @{mut: bool, kind: deref_t, outer_t: ty::t};
1111

@@ -20,15 +20,15 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
2020
while true {
2121
alt ty::struct(tcx, t) {
2222
ty::ty_box(mt) {
23-
ds += [@{mut: mt.mut == mut, kind: unbox, outer_t: t}];
23+
ds += [@{mut: mt.mut == mut, kind: unbox(false), outer_t: t}];
2424
t = mt.ty;
2525
}
2626
ty::ty_uniq(mt) {
27-
ds += [@{mut: mt.mut == mut, kind: unbox, outer_t: t}];
27+
ds += [@{mut: mt.mut == mut, kind: unbox(false), outer_t: t}];
2828
t = mt.ty;
2929
}
3030
ty::ty_res(_, inner, tps) {
31-
ds += [@{mut: false, kind: unbox, outer_t: t}];
31+
ds += [@{mut: false, kind: unbox(false), outer_t: t}];
3232
t = ty::substitute_type_params(tcx, tps, inner);
3333
}
3434
ty::ty_enum(did, tps) {
@@ -37,7 +37,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
3737
vec::len(variants[0].args) != 1u {
3838
break;
3939
}
40-
ds += [@{mut: false, kind: unbox, outer_t: t}];
40+
ds += [@{mut: false, kind: unbox(false), outer_t: t}];
4141
t = ty::substitute_type_params(tcx, tps, variants[0].args[0]);
4242
}
4343
_ { break; }
@@ -85,15 +85,16 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
8585
expr_unary(op, base) {
8686
if op == deref {
8787
let base_t = ty::expr_ty(tcx, base);
88-
let is_mut = false;
88+
let is_mut = false, ptr = false;
8989
alt ty::struct(tcx, base_t) {
9090
ty::ty_box(mt) { is_mut = mt.mut == mut; }
9191
ty::ty_uniq(mt) { is_mut = mt.mut == mut; }
9292
ty::ty_res(_, _, _) { }
9393
ty::ty_enum(_, _) { }
94-
ty::ty_ptr(mt) { is_mut = mt.mut == mut; }
94+
ty::ty_ptr(mt) { is_mut = mt.mut == mut; ptr = true; }
9595
}
96-
ds += [@{mut: is_mut, kind: unbox, outer_t: base_t}];
96+
ds += [@{mut: is_mut, kind: unbox(ptr && is_mut),
97+
outer_t: base_t}];
9798
ex = base;
9899
} else { break; }
99100
}
@@ -187,7 +188,7 @@ fn check_lval(cx: @ctx, dest: @expr, msg: msg) {
187188
} else if !root.ds[0].mut {
188189
let name =
189190
alt root.ds[0].kind {
190-
mut::unbox { "immutable box" }
191+
mut::unbox(_) { "immutable box" }
191192
mut::field { "immutable field" }
192193
mut::index { "immutable vec content" }
193194
};
@@ -212,7 +213,8 @@ fn check_move_rhs(cx: @ctx, src: @expr) {
212213
let root = expr_root(cx.tcx, src, false);
213214

214215
// Not a path and no-derefs means this is a temporary.
215-
if vec::len(*root.ds) != 0u {
216+
if vec::len(*root.ds) != 0u &&
217+
root.ds[vec::len(*root.ds) - 1u].kind != unbox(true) {
216218
cx.tcx.sess.span_err(src.span, "moving out of a data structure");
217219
}
218220
}

src/comp/middle/trans/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn sanitize(s: str) -> str {
268268
c != ' ' as u8 && c != '\t' as u8 && c != ';' as u8
269269
{
270270
let v = [c];
271-
result += str::unsafe_from_bytes(v);
271+
result += str::from_bytes(v);
272272
}
273273
}
274274
}
@@ -5412,7 +5412,7 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
54125412

54135413
fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
54145414
if !cx.sess.building_library { ret; }
5415-
let llmeta = C_postr(metadata::encoder::encode_metadata(cx, crate));
5415+
let llmeta = C_bytes(metadata::encoder::encode_metadata(cx, crate));
54165416
let llconst = C_struct([llmeta]);
54175417
let llglobal = str::as_buf("rust_metadata", {|buf|
54185418
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst), buf)

src/comp/middle/ty.rs

+20-11
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export type_is_str;
172172
export type_is_unique;
173173
export type_is_enum;
174174
export type_is_c_like_enum;
175+
export type_structurally_contains;
175176
export type_structurally_contains_uniques;
176177
export type_autoderef;
177178
export type_param;
@@ -2420,7 +2421,8 @@ mod unify {
24202421
fn fixup_vars(tcx: ty_ctxt, sp: option::t<span>, vb: @var_bindings,
24212422
typ: t) -> fixup_result {
24222423
fn subst_vars(tcx: ty_ctxt, sp: option::t<span>, vb: @var_bindings,
2423-
unresolved: @mutable option::t<int>, vid: int) -> t {
2424+
unresolved: @mutable option::t<int>,
2425+
vars_seen: std::list::list<int>, vid: int) -> t {
24242426
// Should really return a fixup_result instead of a t, but fold_ty
24252427
// doesn't allow returning anything but a t.
24262428
if vid as uint >= ufind::set_count(vb.sets) {
@@ -2431,21 +2433,28 @@ mod unify {
24312433
alt smallintmap::find::<t>(vb.types, root_id) {
24322434
none { *unresolved = some(vid); ret ty::mk_var(tcx, vid); }
24332435
some(rt) {
2434-
if occurs_check_fails(tcx, sp, vid, rt) {
2435-
// Return the type unchanged, so we can error out
2436-
// downstream
2437-
ret rt;
2436+
let give_up = false;
2437+
std::list::iter(vars_seen) {|v|
2438+
if v == vid {
2439+
give_up = true;
2440+
option::may(sp) {|sp|
2441+
tcx.sess.span_fatal(
2442+
sp, "can not instantiate infinite type");
2443+
}
2444+
}
24382445
}
2439-
ret fold_ty(tcx,
2440-
fm_var(bind subst_vars(tcx, sp, vb, unresolved,
2441-
_)), rt);
2446+
// Return the type unchanged, so we can error out
2447+
// downstream
2448+
if give_up { ret rt; }
2449+
ret fold_ty(tcx, fm_var(bind subst_vars(
2450+
tcx, sp, vb, unresolved, std::list::cons(vid, @vars_seen),
2451+
_)), rt);
24422452
}
24432453
}
24442454
}
24452455
let unresolved = @mutable none::<int>;
2446-
let rty =
2447-
fold_ty(tcx, fm_var(bind subst_vars(tcx, sp, vb, unresolved, _)),
2448-
typ);
2456+
let rty = fold_ty(tcx, fm_var(bind subst_vars(
2457+
tcx, sp, vb, unresolved, std::list::nil, _)), typ);
24492458
let ur = *unresolved;
24502459
alt ur {
24512460
none { ret fix_ok(rty); }

src/comp/middle/typeck.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,9 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
259259
alt tcx.ast_ty_to_ty_cache.find(ast_ty) {
260260
some(some(ty)) { ret ty; }
261261
some(none) {
262-
tcx.sess.span_fatal(ast_ty.span,
263-
"illegal recursive type \
264-
insert a enum in the cycle, \
265-
if this is desired)");
262+
tcx.sess.span_fatal(ast_ty.span, "illegal recursive type. \
263+
insert a enum in the cycle, \
264+
if this is desired)");
266265
}
267266
none { }
268267
} /* go on */
@@ -2298,7 +2297,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
22982297
let msg = #fmt["attempted access of field %s on type %s, but \
22992298
no method implementation was found",
23002299
field, ty_to_str(tcx, t_err)];
2301-
tcx.sess.span_fatal(expr.span, msg);
2300+
tcx.sess.span_err(expr.span, msg);
2301+
// NB: Adding a bogus type to allow typechecking to continue
2302+
write::ty_only_fixup(fcx, id, ty::mk_nil(tcx));
23022303
}
23032304
}
23042305
}
@@ -2490,7 +2491,7 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
24902491
demand::simple(fcx, e.span, declty, cty);
24912492
}
24922493

2493-
fn check_enum_variants(ccx: @crate_ctxt, _sp: span, vs: [ast::variant],
2494+
fn check_enum_variants(ccx: @crate_ctxt, sp: span, vs: [ast::variant],
24942495
id: ast::node_id) {
24952496
// FIXME: this is kinda a kludge; we manufacture a fake function context
24962497
// and statement context for checking the initializer expression.
@@ -2512,7 +2513,7 @@ fn check_enum_variants(ccx: @crate_ctxt, _sp: span, vs: [ast::variant],
25122513
some(e) {
25132514
check_expr(fcx, e);
25142515
let cty = expr_ty(fcx.ccx.tcx, e);
2515-
let declty =ty::mk_int(fcx.ccx.tcx);
2516+
let declty = ty::mk_int(fcx.ccx.tcx);
25162517
demand::simple(fcx, e.span, declty, cty);
25172518
// FIXME: issue #1417
25182519
// Also, check_expr (from check_const pass) doesn't guarantee that
@@ -2537,6 +2538,20 @@ fn check_enum_variants(ccx: @crate_ctxt, _sp: span, vs: [ast::variant],
25372538
disr_vals += [disr_val];
25382539
disr_val += 1;
25392540
}
2541+
let outer = true, did = local_def(id);
2542+
if ty::type_structurally_contains(ccx.tcx, rty, {|sty|
2543+
alt sty {
2544+
ty::ty_enum(id, _) if id == did {
2545+
if outer { outer = false; false }
2546+
else { true }
2547+
}
2548+
_ { false }
2549+
}
2550+
}) {
2551+
ccx.tcx.sess.span_fatal(sp, "illegal recursive enum type. \
2552+
wrap the inner value in a box to \
2553+
make it represenable");
2554+
}
25402555
}
25412556

25422557
// A generic function for checking the pred in a check

src/comp/syntax/parse/lexer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ fn gather_comments_and_literals(cm: codemap::codemap,
672672
path: str,
673673
srdr: io::reader) ->
674674
{cmnts: [cmnt], lits: [lit]} {
675-
let src = @str::unsafe_from_bytes(srdr.read_whole_stream());
675+
let src = @str::from_bytes(srdr.read_whole_stream());
676676
let itr = @interner::mk::<str>(str::hash, str::eq);
677677
let rdr = new_reader(cm, span_diagnostic,
678678
codemap::new_filemap(path, src, 0u, 0u), itr);

src/comp/util/ppaux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
118118
}
119119
ty_var(v) { "<T" + int::str(v) + ">" }
120120
ty_param(id, _) {
121-
"'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)])
121+
"'" + str::from_bytes([('a' as u8) + (id as u8)])
122122
}
123123
_ { ty_to_short_str(cx, typ) }
124124
}

0 commit comments

Comments
 (0)