Skip to content

Commit a67710e

Browse files
nikomatsakisbrson
authored andcommitted
---
yaml --- r: 5809 b: refs/heads/master c: e8a0e59 h: refs/heads/master i: 5807: ee2dee2 v: v3
1 parent 92ab381 commit a67710e

File tree

24 files changed

+138
-157
lines changed

24 files changed

+138
-157
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: f994871a3daaa52c22b89057c575e0f65ffae013
2+
refs/heads/master: e8a0e592da3e8f5cadc0c854c61b0934d10bc0a4

trunk/src/comp/back/link.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ tag output_type {
3434
output_type_exe;
3535
}
3636

37-
fn llvm_err(sess: session::session, msg: str) {
38-
unsafe {
39-
let buf = llvm::LLVMRustGetLastError();
40-
if buf == std::ptr::null() {
41-
sess.fatal(msg);
42-
} else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
43-
}
37+
fn llvm_err(sess: session::session, msg: str) unsafe {
38+
let buf = llvm::LLVMRustGetLastError();
39+
if buf == std::ptr::null() {
40+
sess.fatal(msg);
41+
} else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
4442
}
4543

46-
fn link_intrinsics(sess: session::session, llmod: ModuleRef) unsafe {
44+
fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
4745
let path = alt filesearch::search(
4846
sess.filesearch(),
4947
bind filesearch::pick_file("intrinsics.bc", _)) {
@@ -90,8 +88,7 @@ mod write {
9088
} else { stem = str::substr(output_path, 0u, dot_pos as uint); }
9189
ret stem + "." + extension;
9290
}
93-
fn run_passes(sess: session::session, llmod: ModuleRef, output: str)
94-
unsafe {
91+
fn run_passes(sess: session::session, llmod: ModuleRef, output: str) {
9592
let opts = sess.get_opts();
9693
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
9794
link_intrinsics(sess, llmod);

trunk/src/comp/driver/rustc.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ fn build_session_options(match: getopts::match)
325325

326326
let parse_only = opt_present(match, "parse-only");
327327
let no_trans = opt_present(match, "no-trans");
328-
let check_unsafe = opt_present(match, "check-unsafe");
329328

330329
let output_type =
331330
if parse_only || no_trans {
@@ -397,8 +396,7 @@ fn build_session_options(match: getopts::match)
397396
parse_only: parse_only,
398397
no_trans: no_trans,
399398
do_gc: do_gc,
400-
stack_growth: stack_growth,
401-
check_unsafe: check_unsafe};
399+
stack_growth: stack_growth};
402400
ret sopts;
403401
}
404402

trunk/src/comp/driver/session.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ type options =
4141
parse_only: bool,
4242
no_trans: bool,
4343
do_gc: bool,
44-
stack_growth: bool,
45-
check_unsafe: bool};
44+
stack_growth: bool};
4645

4746
type crate_metadata = {name: str, data: [u8]};
4847

trunk/src/comp/lib/llvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
956956
7 {
957957
ret "i" + std::int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
958958
}
959-
8 unsafe {
959+
8 {
960960
let s = "fn(";
961961
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
962962
let n_args: uint = llvm::LLVMCountParamTypes(ty);
@@ -969,7 +969,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
969969
s += type_to_str_inner(names, outer, out_ty);
970970
ret s;
971971
}
972-
9 unsafe {
972+
9 {
973973
let s: str = "{";
974974
let n_elts: uint = llvm::LLVMCountStructElementTypes(ty);
975975
let elts: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_elts);

trunk/src/comp/metadata/creader.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,27 +169,25 @@ fn find_library_crate_aux(nn: {prefix: str, suffix: str}, crate_name: str,
169169
});
170170
}
171171

172-
fn get_metadata_section(filename: str) -> option::t<@[u8]> {
173-
unsafe {
174-
let mb = str::as_buf(filename, {|buf|
175-
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
176-
});
177-
if mb as int == 0 { ret option::none::<@[u8]>; }
178-
let of = mk_object_file(mb);
179-
let si = mk_section_iter(of.llof);
180-
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
181-
let name_buf = llvm::LLVMGetSectionName(si.llsi);
182-
let name = str::str_from_cstr(name_buf);
183-
if str::eq(name, x86::get_meta_sect_name()) {
184-
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
185-
let csz = llvm::LLVMGetSectionSize(si.llsi);
186-
let cvbuf: *u8 = std::unsafe::reinterpret_cast(cbuf);
187-
ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
188-
}
189-
llvm::LLVMMoveToNextSection(si.llsi);
172+
fn get_metadata_section(filename: str) -> option::t<@[u8]> unsafe {
173+
let mb = str::as_buf(filename, {|buf|
174+
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
175+
});
176+
if mb as int == 0 { ret option::none::<@[u8]>; }
177+
let of = mk_object_file(mb);
178+
let si = mk_section_iter(of.llof);
179+
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
180+
let name_buf = llvm::LLVMGetSectionName(si.llsi);
181+
let name = str::str_from_cstr(name_buf);
182+
if str::eq(name, x86::get_meta_sect_name()) {
183+
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
184+
let csz = llvm::LLVMGetSectionSize(si.llsi);
185+
let cvbuf: *u8 = std::unsafe::reinterpret_cast(cbuf);
186+
ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
190187
}
191-
ret option::none::<@[u8]>;
188+
llvm::LLVMMoveToNextSection(si.llsi);
192189
}
190+
ret option::none::<@[u8]>;
193191
}
194192

195193
fn load_library_crate(sess: session::session, span: span, ident: ast::ident,

trunk/src/comp/metadata/decoder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ fn family_has_type_params(fam_ch: u8) -> bool {
256256
'u' { true }
257257
'p' { true }
258258
'F' { true }
259+
'U' { true }
260+
'P' { true }
259261
'y' { true }
260262
't' { true }
261263
'T' { false }
@@ -285,6 +287,8 @@ fn item_family_to_str(fam: u8) -> str {
285287
'u' { ret "unsafe fn"; }
286288
'p' { ret "pure fn"; }
287289
'F' { ret "native fn"; }
290+
'U' { ret "unsafe native fn"; }
291+
'P' { ret "pure native fn"; }
288292
'y' { ret "type"; }
289293
'T' { ret "native type"; }
290294
't' { ret "type"; }

trunk/src/comp/middle/gc.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ type ctxt = @{mutable next_tydesc_num: uint};
1616

1717
fn mk_ctxt() -> ctxt { ret @{mutable next_tydesc_num: 0u}; }
1818

19-
fn add_global(ccx: @crate_ctxt, llval: ValueRef, name: str)
20-
-> ValueRef unsafe {
19+
fn add_global(ccx: @crate_ctxt, llval: ValueRef, name: str) -> ValueRef {
2120
let llglobal =
2221
str::as_buf(name,
2322
{|buf|
@@ -28,8 +27,7 @@ fn add_global(ccx: @crate_ctxt, llval: ValueRef, name: str)
2827
ret llglobal;
2928
}
3029

31-
fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) ->
32-
@block_ctxt unsafe {
30+
fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
3331
let bcx = cx;
3432
if !type_is_gc_relevant(bcx_tcx(cx), ty) ||
3533
ty::type_has_dynamic_size(bcx_tcx(cx), ty) {

trunk/src/comp/middle/shape.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn eq_res_info(a: res_info, b: res_info) -> bool {
7272
}
7373

7474
fn mk_global(ccx: @crate_ctxt, name: str, llval: ValueRef, internal: bool) ->
75-
ValueRef unsafe {
75+
ValueRef {
7676
let llglobal =
7777
str::as_buf(name,
7878
{|buf|
@@ -245,7 +245,7 @@ fn s_float(_tcx: ty_ctxt) -> u8 {
245245
ret shape_f64; // TODO: x86-64
246246
}
247247

248-
fn mk_ctxt(llmod: ModuleRef) -> ctxt unsafe {
248+
fn mk_ctxt(llmod: ModuleRef) -> ctxt {
249249
let llshapetablesty = trans_common::T_named_struct("shapes");
250250
let llshapetables =
251251
str::as_buf("shapes",
@@ -580,7 +580,7 @@ fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
580580
ret mk_global(ccx, "resource_shapes", C_struct(dtors), true);
581581
}
582582

583-
fn gen_shape_tables(ccx: @crate_ctxt) unsafe {
583+
fn gen_shape_tables(ccx: @crate_ctxt) {
584584
let lltagstable = gen_tag_shapes(ccx);
585585
let llresourcestable = gen_resource_shapes(ccx);
586586
trans_common::set_struct_body(ccx.shape_cx.llshapetablesty,

trunk/src/comp/middle/trans_build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,16 @@ fn _UndefReturn(Fn: ValueRef) -> ValueRef {
492492
}
493493

494494
fn Call(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
495+
if cx.unreachable { ret _UndefReturn(Fn); }
495496
unsafe {
496-
if cx.unreachable { ret _UndefReturn(Fn); }
497497
ret llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
498498
vec::len(Args), noname());
499499
}
500500
}
501501

502502
fn FastCall(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
503+
if cx.unreachable { ret _UndefReturn(Fn); }
503504
unsafe {
504-
if cx.unreachable { ret _UndefReturn(Fn); }
505505
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
506506
vec::len(Args), noname());
507507
llvm::LLVMSetInstructionCallConv(v, lib::llvm::LLVMFastCallConv);
@@ -511,8 +511,8 @@ fn FastCall(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
511511

512512
fn CallWithConv(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef], Conv: uint)
513513
-> ValueRef {
514+
if cx.unreachable { ret _UndefReturn(Fn); }
514515
unsafe {
515-
if cx.unreachable { ret _UndefReturn(Fn); }
516516
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
517517
vec::len(Args), noname());
518518
llvm::LLVMSetInstructionCallConv(v, Conv);

trunk/src/comp/middle/trans_common.rs

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,12 @@ fn val_ty(v: ValueRef) -> TypeRef { ret llvm::LLVMTypeOf(v); }
427427
fn val_str(tn: type_names, v: ValueRef) -> str { ret ty_str(tn, val_ty(v)); }
428428

429429
// Returns the nth element of the given LLVM structure type.
430-
fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef {
431-
unsafe {
432-
let elt_count = llvm::LLVMCountStructElementTypes(llstructty);
433-
assert (n < elt_count);
434-
let elt_tys = std::vec::init_elt(T_nil(), elt_count);
435-
llvm::LLVMGetStructElementTypes(llstructty, to_ptr(elt_tys));
436-
ret llvm::LLVMGetElementType(elt_tys[n]);
437-
}
430+
fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef unsafe {
431+
let elt_count = llvm::LLVMCountStructElementTypes(llstructty);
432+
assert (n < elt_count);
433+
let elt_tys = std::vec::init_elt(T_nil(), elt_count);
434+
llvm::LLVMGetStructElementTypes(llstructty, to_ptr(elt_tys));
435+
ret llvm::LLVMGetElementType(elt_tys[n]);
438436
}
439437

440438
fn find_scope_cx(cx: @block_ctxt) -> @block_ctxt {
@@ -541,10 +539,8 @@ fn T_named_struct(name: str) -> TypeRef {
541539
ret str::as_buf(name, {|buf| llvm::LLVMStructCreateNamed(c, buf) });
542540
}
543541

544-
fn set_struct_body(t: TypeRef, elts: [TypeRef]) {
545-
unsafe {
546-
llvm::LLVMStructSetBody(t, to_ptr(elts), std::vec::len(elts), False);
547-
}
542+
fn set_struct_body(t: TypeRef, elts: [TypeRef]) unsafe {
543+
llvm::LLVMStructSetBody(t, to_ptr(elts), std::vec::len(elts), False);
548544
}
549545

550546
fn T_empty_struct() -> TypeRef { ret T_struct([]); }
@@ -581,18 +577,16 @@ fn T_task() -> TypeRef {
581577
ret t;
582578
}
583579

584-
fn T_tydesc_field(cx: crate_ctxt, field: int) -> TypeRef {
580+
fn T_tydesc_field(cx: crate_ctxt, field: int) -> TypeRef unsafe {
585581
// Bit of a kludge: pick the fn typeref out of the tydesc..
586582

587-
unsafe {
588-
let tydesc_elts: [TypeRef] =
589-
std::vec::init_elt::<TypeRef>(T_nil(),
590-
abi::n_tydesc_fields as uint);
591-
llvm::LLVMGetStructElementTypes(cx.tydesc_type,
592-
to_ptr::<TypeRef>(tydesc_elts));
593-
let t = llvm::LLVMGetElementType(tydesc_elts[field]);
594-
ret t;
595-
}
583+
let tydesc_elts: [TypeRef] =
584+
std::vec::init_elt::<TypeRef>(T_nil(),
585+
abi::n_tydesc_fields as uint);
586+
llvm::LLVMGetStructElementTypes(cx.tydesc_type,
587+
to_ptr::<TypeRef>(tydesc_elts));
588+
let t = llvm::LLVMGetElementType(tydesc_elts[field]);
589+
ret t;
596590
}
597591

598592
fn T_glue_fn(cx: crate_ctxt) -> TypeRef {
@@ -798,43 +792,33 @@ fn C_postr(s: str) -> ValueRef {
798792
});
799793
}
800794

801-
fn C_zero_byte_arr(size: uint) -> ValueRef {
802-
unsafe {
803-
let i = 0u;
804-
let elts: [ValueRef] = [];
805-
while i < size { elts += [C_u8(0u)]; i += 1u; }
806-
ret llvm::LLVMConstArray(T_i8(), std::vec::to_ptr(elts),
807-
std::vec::len(elts));
808-
}
795+
fn C_zero_byte_arr(size: uint) -> ValueRef unsafe {
796+
let i = 0u;
797+
let elts: [ValueRef] = [];
798+
while i < size { elts += [C_u8(0u)]; i += 1u; }
799+
ret llvm::LLVMConstArray(T_i8(), std::vec::to_ptr(elts),
800+
std::vec::len(elts));
809801
}
810802

811-
fn C_struct(elts: [ValueRef]) -> ValueRef {
812-
unsafe {
813-
ret llvm::LLVMConstStruct(std::vec::to_ptr(elts), std::vec::len(elts),
814-
False);
815-
}
803+
fn C_struct(elts: [ValueRef]) -> ValueRef unsafe {
804+
ret llvm::LLVMConstStruct(std::vec::to_ptr(elts), std::vec::len(elts),
805+
False);
816806
}
817807

818-
fn C_named_struct(T: TypeRef, elts: [ValueRef]) -> ValueRef {
819-
unsafe {
820-
ret llvm::LLVMConstNamedStruct(T, std::vec::to_ptr(elts),
821-
std::vec::len(elts));
822-
}
808+
fn C_named_struct(T: TypeRef, elts: [ValueRef]) -> ValueRef unsafe {
809+
ret llvm::LLVMConstNamedStruct(T, std::vec::to_ptr(elts),
810+
std::vec::len(elts));
823811
}
824812

825-
fn C_array(ty: TypeRef, elts: [ValueRef]) -> ValueRef {
826-
unsafe {
827-
ret llvm::LLVMConstArray(ty, std::vec::to_ptr(elts),
828-
std::vec::len(elts));
829-
}
813+
fn C_array(ty: TypeRef, elts: [ValueRef]) -> ValueRef unsafe {
814+
ret llvm::LLVMConstArray(ty, std::vec::to_ptr(elts),
815+
std::vec::len(elts));
830816
}
831817

832-
fn C_bytes(bytes: [u8]) -> ValueRef {
833-
unsafe {
834-
ret llvm::LLVMConstString(
835-
unsafe::reinterpret_cast(vec::to_ptr(bytes)),
836-
vec::len(bytes), False);
837-
}
818+
fn C_bytes(bytes: [u8]) -> ValueRef unsafe {
819+
ret llvm::LLVMConstString(
820+
unsafe::reinterpret_cast(vec::to_ptr(bytes)),
821+
vec::len(bytes), False);
838822
}
839823

840824
fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {

trunk/src/comp/middle/trans_objects.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ fn create_backwarding_vtbl(cx: @local_ctxt, sp: span, inner_obj_ty: ty::t,
569569
// finish_vtbl: Given a vector of vtable entries, create the table in
570570
// read-only memory and return a pointer to it.
571571
fn finish_vtbl(cx: @local_ctxt, llmethods: [ValueRef], name: str) ->
572-
ValueRef unsafe {
572+
ValueRef {
573573
let vtbl = C_struct(llmethods);
574574
let vtbl_name = mangle_internal_name_by_path(cx.ccx, cx.path + [name]);
575575
let gvar =
@@ -619,7 +619,7 @@ fn begin_fn(cx: @local_ctxt, sp: span, m: @ty::method,
619619
// returns the value returned from that call.
620620
fn process_bkwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
621621
ty_params: [ast::ty_param], outer_obj_ty: ty::t,
622-
_additional_field_tys: [ty::t]) -> ValueRef unsafe {
622+
_additional_field_tys: [ty::t]) -> ValueRef {
623623

624624
let llbackwarding_fn = begin_fn(cx, sp, m, ty_params, "backwarding_fn");
625625
let fcx = new_fn_ctxt(cx, sp, llbackwarding_fn);

0 commit comments

Comments
 (0)