From 98cd96ce96c8be7248e3d375053938354c82878a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 5 Dec 2011 13:19:02 -0800 Subject: [PATCH 1/9] test: Add more tests for stack growth --- src/rt/rust_upcall.cpp | 14 ++++- src/test/run-pass/morestack4.rs | 100 ++++++++++++++++++++++++++++++++ src/test/run-pass/morestack5.rs | 26 +++++++++ 3 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 src/test/run-pass/morestack4.rs create mode 100644 src/test/run-pass/morestack5.rs diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index a8f39cf91da9..e6e89c62cc09 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -209,14 +209,22 @@ upcall_dynastack_free(void *ptr) { return rust_scheduler::get_task()->dynastack.free(ptr); } +extern "C" void record_sp(void *limit); + /** - * Allocates |nbytes| bytes in the C stack and returns a pointer to the start - * of the allocated space. + * Switch to the C stack and call the given function, passing a single pointer + * argument. */ extern "C" CDECL void upcall_call_shim_on_c_stack(void *args, void *fn_ptr) { - rust_scheduler *sched = rust_scheduler::get_task()->sched; + // FIXME (1226) - The shim functions generated by rustc contain the + // morestack prologue, so we need to let them know they have enough + // stack. + record_sp(0); + rust_task *task = rust_scheduler::get_task(); + rust_scheduler *sched = task->sched; sched->c_context.call_shim_on_c_stack(args, fn_ptr); + task->record_stack_limit(); } struct rust_new_stack2_args { diff --git a/src/test/run-pass/morestack4.rs b/src/test/run-pass/morestack4.rs new file mode 100644 index 000000000000..cdba6dd766ea --- /dev/null +++ b/src/test/run-pass/morestack4.rs @@ -0,0 +1,100 @@ +// xfail-test +// compile-flags:--stack-growth + +// This is testing for stack frames greater than 256 bytes, +// for which function prologues are generated differently + +type biggy = { + a00: u64, + a01: u64, + a02: u64, + a03: u64, + a04: u64, + a05: u64, + a06: u64, + a07: u64, + a08: u64, + a09: u64, + a10: u64, + a11: u64, + a12: u64, + a13: u64, + a14: u64, + a15: u64, + a16: u64, + a17: u64, + a18: u64, + a19: u64, + a20: u64, + a21: u64, + a22: u64, + a23: u64, + a24: u64, + a25: u64, + a26: u64, + a27: u64, + a28: u64, + a29: u64, + a30: u64, + a31: u64, + a32: u64, + a33: u64, + a34: u64, + a35: u64, + a36: u64, + a37: u64, + a38: u64, + a39: u64, +}; + + +fn getbig(i: biggy) { + if i.a00 != 0u64 { + getbig({a00: i.a00 - 1u64 with i}); + } +} + +fn main() { + getbig({ + a00: 100000u64, + a01: 100000u64, + a02: 100000u64, + a03: 100000u64, + a04: 100000u64, + a05: 100000u64, + a06: 100000u64, + a07: 100000u64, + a08: 100000u64, + a09: 100000u64, + a10: 100000u64, + a11: 100000u64, + a12: 100000u64, + a13: 100000u64, + a14: 100000u64, + a15: 100000u64, + a16: 100000u64, + a17: 100000u64, + a18: 100000u64, + a19: 100000u64, + a20: 100000u64, + a21: 100000u64, + a22: 100000u64, + a23: 100000u64, + a24: 100000u64, + a25: 100000u64, + a26: 100000u64, + a27: 100000u64, + a28: 100000u64, + a29: 100000u64, + a30: 100000u64, + a31: 100000u64, + a32: 100000u64, + a33: 100000u64, + a34: 100000u64, + a35: 100000u64, + a36: 100000u64, + a37: 100000u64, + a38: 100000u64, + a39: 100000u64, + }); +} \ No newline at end of file diff --git a/src/test/run-pass/morestack5.rs b/src/test/run-pass/morestack5.rs new file mode 100644 index 000000000000..bedf3f47ee96 --- /dev/null +++ b/src/test/run-pass/morestack5.rs @@ -0,0 +1,26 @@ +// xfail-test +// compile-flags:--stack-growth + +// This test will call __morestack with various minimum stack sizes + +use std; +import std::task; + +native mod rustrt { + fn set_min_stack(size: uint); +} + +fn getbig(&&i: int) { + if i != 0 { + getbig(i - 1); + } +} + +fn main() { + let sz = 400u; + while sz < 500u { + rustrt::set_min_stack(sz); + task::join(task::spawn_joinable(200, getbig)); + sz += 1u; + } +} \ No newline at end of file From 3b8bfaf5343dd13839df465cde6a4df50136ff03 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 5 Dec 2011 17:11:33 -0800 Subject: [PATCH 2/9] rt: Use an out pointer for rust_new_stack upcall_call_shim_on_c_stack does not handle return values --- src/rt/arch/i386/morestack.S | 9 +++++---- src/rt/arch/x86_64/morestack.S | 6 +++++- src/rt/rust_upcall.cpp | 30 +++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/rt/arch/i386/morestack.S b/src/rt/arch/i386/morestack.S index 7b5446ae2357..30084ec2de0c 100644 --- a/src/rt/arch/i386/morestack.S +++ b/src/rt/arch/i386/morestack.S @@ -75,11 +75,12 @@ MORESTACK: // The arguments to rust_new_stack2 movl 40(%esp),%eax // Size of stack arguments - movl %eax,16(%esp) + movl %eax,20(%esp) leal 48(%esp),%eax // Address of stack arguments - movl %eax,12(%esp) + movl %eax,16(%esp) movl 36(%esp),%eax // The amount of stack needed - movl %eax,8(%esp) + movl %eax,12(%esp) + movl $0, 8(%esp) // Out pointer #ifdef __APPLE__ call 1f @@ -97,7 +98,7 @@ MORESTACK: movl 32(%esp),%edx // Grab the return pointer. inc %edx // Skip past the ret instruction in the parent fn - movl %eax,%esp // Switch stacks. + movl 8(%esp),%esp // Switch stacks. call *%edx // Re-enter the function that called us. // Now the function that called us has returned, so we need to delete the diff --git a/src/rt/arch/x86_64/morestack.S b/src/rt/arch/x86_64/morestack.S index 4147052345d6..ef0edcee7209 100644 --- a/src/rt/arch/x86_64/morestack.S +++ b/src/rt/arch/x86_64/morestack.S @@ -81,9 +81,12 @@ MORESTACK: movq %rbp, %rcx addq $24, %rcx // Base pointer, return address x2 + pushq $0 // Alignment + pushq %r11 // Size of stack arguments pushq %rcx // Address of stack arguments pushq %r10 // The amount of stack needed + pushq $0 // Out pointer movq UPCALL_NEW_STACK@GOTPCREL(%rip), %rsi movq %rsp, %rdi @@ -95,7 +98,8 @@ MORESTACK: #endif // Pop the new_stack_args struct - addq $24, %rsp + popq %rax + addq $32, %rsp // Pop the saved arguments popq %r9 diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index e6e89c62cc09..670dbc3a24a8 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -217,28 +217,40 @@ extern "C" void record_sp(void *limit); */ extern "C" CDECL void upcall_call_shim_on_c_stack(void *args, void *fn_ptr) { + rust_task *task = rust_scheduler::get_task(); + // FIXME (1226) - The shim functions generated by rustc contain the // morestack prologue, so we need to let them know they have enough // stack. - record_sp(0); - rust_task *task = rust_scheduler::get_task(); + //record_sp(0); + rust_scheduler *sched = task->sched; - sched->c_context.call_shim_on_c_stack(args, fn_ptr); - task->record_stack_limit(); + try { + sched->c_context.call_shim_on_c_stack(args, fn_ptr); + } catch (...) { + //task = rust_scheduler::get_task(); + //task->record_stack_limit(); + throw; + } + //task = rust_scheduler::get_task(); + //task->record_stack_limit(); } struct rust_new_stack2_args { - size_t stk_sz; - void *args_addr; - size_t args_sz; + void *new_stack; + size_t stk_sz; + void *args_addr; + size_t args_sz; }; // A new stack function suitable for calling through // upcall_call_shim_on_c_stack -extern "C" CDECL void * +extern "C" CDECL void upcall_new_stack(struct rust_new_stack2_args *args) { rust_task *task = rust_scheduler::get_task(); - return task->new_stack(args->stk_sz, args->args_addr, args->args_sz); + args->new_stack = task->new_stack(args->stk_sz, + args->args_addr, + args->args_sz); } extern "C" CDECL void From a731f165df26cb7575133d549ffd2f548bb3de99 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 5 Dec 2011 17:20:59 -0800 Subject: [PATCH 3/9] test: Test hitting the dynamic linker in the red zone --- src/rt/rust_builtin.cpp | 6 +++ src/rt/rust_upcall.cpp | 6 +-- src/rt/rustrt.def.in | 1 + src/test/run-pass/morestack6.rs | 81 +++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/test/run-pass/morestack6.rs diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 41c8bc68d2b0..dd5831c29173 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -273,6 +273,12 @@ debug_ptrcast(type_desc *from_ty, return ptr; } +extern "C" CDECL void * +debug_get_stk_seg() { + rust_task *task = rust_scheduler::get_task(); + return task->stk; +} + extern "C" CDECL rust_vec* rust_list_files(rust_str *path) { rust_task *task = rust_scheduler::get_task(); diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index 670dbc3a24a8..f202cd1fd674 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -222,7 +222,7 @@ upcall_call_shim_on_c_stack(void *args, void *fn_ptr) { // FIXME (1226) - The shim functions generated by rustc contain the // morestack prologue, so we need to let them know they have enough // stack. - //record_sp(0); + record_sp(0); rust_scheduler *sched = task->sched; try { @@ -232,8 +232,8 @@ upcall_call_shim_on_c_stack(void *args, void *fn_ptr) { //task->record_stack_limit(); throw; } - //task = rust_scheduler::get_task(); - //task->record_stack_limit(); + task = rust_scheduler::get_task(); + task->record_stack_limit(); } struct rust_new_stack2_args { diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index de9079800e23..ba1a9c1403da 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -8,6 +8,7 @@ del_port debug_ptrcast debug_tag debug_tydesc +debug_get_stk_seg do_gc drop_task get_port_id diff --git a/src/test/run-pass/morestack6.rs b/src/test/run-pass/morestack6.rs new file mode 100644 index 000000000000..ef1a87aeea6e --- /dev/null +++ b/src/test/run-pass/morestack6.rs @@ -0,0 +1,81 @@ +// xfail-test +// compile-flags:--stack-growth + +// This test attempts to force the dynamic linker to resolve +// external symbols as close to the red zone as possible. + +use std; +import std::task; +import std::rand; + +native mod rustrt { + fn set_min_stack(size: uint); + fn debug_get_stk_seg() -> *u8; + + fn unsupervise(); + fn last_os_error() -> str; + fn rust_getcwd() -> str; + fn refcount(box: @int); + fn do_gc(); + fn pin_task(); + fn unpin_task(); + fn get_task_id(); + fn sched_threads(); + fn rust_get_task(); +} + +fn calllink01() { rustrt::unsupervise(); } +fn calllink02() { rustrt::last_os_error(); } +fn calllink03() { rustrt::rust_getcwd(); } +fn calllink04() { rustrt::refcount(@0); } +fn calllink05() { rustrt::do_gc(); } +fn calllink06() { rustrt::pin_task(); } +fn calllink07() { rustrt::unpin_task(); } +fn calllink08() { rustrt::get_task_id(); } +fn calllink09() { rustrt::sched_threads(); } +fn calllink10() { rustrt::rust_get_task(); } + +fn runtest(&&args:(fn(), u32)) { + let (f, frame_backoff) = args; + runtest2(f, frame_backoff, 0 as *u8); +} + +fn runtest2(f: fn(), frame_backoff: u32, last_stk: *u8) -> u32 { + let curr_stk = rustrt::debug_get_stk_seg(); + if (last_stk != curr_stk && last_stk != 0 as *u8) { + // We switched stacks, go back and try to hit the dynamic linker + frame_backoff + } else { + let frame_backoff = runtest2(f, frame_backoff, curr_stk); + if frame_backoff > 1u32 { + frame_backoff - 1u32 + } else if frame_backoff == 1u32 { + f(); + 0u32 + } else { + 0u32 + } + } +} + +fn main() { + let fns = [ + calllink01, + calllink02, + calllink03, + calllink04, + calllink05, + calllink06, + calllink07, + calllink08, + calllink09, + calllink10 + ]; + let rng = rand::mk_rng(); + for f in fns { + let sz = rng.next() % 256u32 + 256u32; + let frame_backoff = rng.next() % 10u32 + 1u32; + rustrt::set_min_stack(sz as uint); + task::join(task::spawn_joinable((f, frame_backoff), runtest)); + } +} \ No newline at end of file From 58844aee421eccc5399d6a5bec278de5149e8117 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 5 Dec 2011 17:42:58 -0800 Subject: [PATCH 4/9] rt: Make stack unwinding work more correctly with stack growth --- src/rt/rust_task.cpp | 3 +++ src/rt/rust_upcall.cpp | 4 ++-- src/test/run-fail/morestack2.rs | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/test/run-fail/morestack2.rs diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index f0ab8c57c35d..a34ec4d86619 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -131,6 +131,9 @@ rust_task::~rust_task() // (ref_count == 1 && this == sched->root_task)); // Delete all the stacks. There may be more than one if the task failed + // FIXME: This is not correct. During unwinding we need to delete + // the stacks and record the stack limit, otherwise the stack + // stack is corrupted when destructors are running. while (stk != NULL) { del_stk(this, stk); } diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index f202cd1fd674..653db471fc01 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -228,8 +228,8 @@ upcall_call_shim_on_c_stack(void *args, void *fn_ptr) { try { sched->c_context.call_shim_on_c_stack(args, fn_ptr); } catch (...) { - //task = rust_scheduler::get_task(); - //task->record_stack_limit(); + task = rust_scheduler::get_task(); + task->record_stack_limit(); throw; } task = rust_scheduler::get_task(); diff --git a/src/test/run-fail/morestack2.rs b/src/test/run-fail/morestack2.rs new file mode 100644 index 000000000000..4e92a144085a --- /dev/null +++ b/src/test/run-fail/morestack2.rs @@ -0,0 +1,35 @@ +// xfail-test +// error-pattern:explicit failure +// compile-flags:--stack-growth + +// This time we're testing that the stack limits are restored +// correctly after calling into the C stack and unwinding. +// See the hack in upcall_call_shim_on_c_stack where it messes +// with the stack limit. + +native mod rustrt { + fn pin_task(); +} + +fn getbig_call_c_and_fail(i: int) { + if i != 0 { + getbig_call_c_and_fail(i - 1); + } else { + rustrt::pin_task(); + fail; + } +} + +resource and_then_get_big_again(_i: ()) { + fn getbig(i: int) { + if i != 0 { + getbig(i - 1); + } + } + getbig(100000); +} + +fn main() { + let r = and_then_get_big_again(()); + getbig_call_c_and_fail(100000); +} \ No newline at end of file From 8d8148f1f740ce80a07a19830cfae8a1851a7c4f Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 5 Dec 2011 19:21:46 -0800 Subject: [PATCH 5/9] test: More tests for unwinding + morestack --- src/test/run-fail/morestack2.rs | 12 +++++++++--- src/test/run-fail/morestack3.rs | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/test/run-fail/morestack3.rs diff --git a/src/test/run-fail/morestack2.rs b/src/test/run-fail/morestack2.rs index 4e92a144085a..02b1adae4816 100644 --- a/src/test/run-fail/morestack2.rs +++ b/src/test/run-fail/morestack2.rs @@ -7,7 +7,10 @@ // See the hack in upcall_call_shim_on_c_stack where it messes // with the stack limit. +use std; + native mod rustrt { + fn set_min_stack(size: uint); fn pin_task(); } @@ -26,10 +29,13 @@ resource and_then_get_big_again(_i: ()) { getbig(i - 1); } } - getbig(100000); + getbig(10000); } fn main() { - let r = and_then_get_big_again(()); - getbig_call_c_and_fail(100000); + rustrt::set_min_stack(256u); + std::task::spawn((), fn (&&_i: ()) { + let r = and_then_get_big_again(()); + getbig_call_c_and_fail(10000); + }); } \ No newline at end of file diff --git a/src/test/run-fail/morestack3.rs b/src/test/run-fail/morestack3.rs new file mode 100644 index 000000000000..9fdd0326b661 --- /dev/null +++ b/src/test/run-fail/morestack3.rs @@ -0,0 +1,34 @@ +// xfail-test +// error-pattern:explicit failure +// compile-flags:--stack-growth + +// Just testing unwinding + +use std; + +native mod rustrt { + fn set_min_stack(size: uint); +} + +fn getbig_and_fail(&&i: int) { + let r = and_then_get_big_again(@0); + if i != 0 { + getbig_and_fail(i - 1); + } else { + fail; + } +} + +resource and_then_get_big_again(_i: @int) { + fn getbig(i: int) { + if i != 0 { + getbig(i - 1); + } + } + getbig(1000); +} + +fn main() { + rustrt::set_min_stack(256u); + std::task::spawn(1000, getbig_and_fail); +} \ No newline at end of file From b513a5a5001b850a153db12d9621d00a70ff929a Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Tue, 6 Dec 2011 01:11:11 -0600 Subject: [PATCH 6/9] Make valgrind usage more consistent and less error prone. I was still having issues with the build system somehow getting confused as to which set of valgrind headers to use when compiling rt. This commit moves all the valgrind headers into their own directory under rt and makes the usage more consistent. The compiler is now passed the -DNVALGRIND flag when valgrind is not installed, as opposed to passing -DHAVE_VALGRIND. We also pass -I src/rt to the compiler when building rt so you can more easily import what you want. I also cleaned up some erroneous #includes along the way. It should be safe to always just import the local valgrind headers and use them without question. NVALGRIND turns the operations to no-ops when it is active, and the build and tests run cleanly with or without. --- mk/platform.mk | 4 ++-- mk/rt.mk | 2 +- src/rt/arch/i386/context.h | 4 +--- src/rt/arch/x86_64/context.h | 6 +----- src/rt/rust_task.cpp | 4 ++-- src/rt/rust_timer.cpp | 2 +- src/rt/{ => vg}/memcheck.h | 0 src/rt/{ => vg}/valgrind.h | 0 8 files changed, 8 insertions(+), 14 deletions(-) rename src/rt/{ => vg}/memcheck.h (100%) rename src/rt/{ => vg}/valgrind.h (100%) diff --git a/mk/platform.mk b/mk/platform.mk index 28ecb0a10e92..430a835ba86a 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -17,8 +17,8 @@ CFG_GCCISH_LINK_FLAGS := # embedded into the executable, so use a no-op command. CFG_DSYMUTIL := true -ifneq ($(CFG_VALGRIND),) - CFG_GCCISH_CFLAGS += -DHAVE_VALGRIND +ifeq ($(CFG_VALGRIND),) + CFG_GCCISH_CFLAGS += -DNVALGRIND endif ifneq ($(findstring freebsd,$(CFG_OSTYPE)),) diff --git a/mk/rt.mk b/mk/rt.mk index e45430f76907..0d9bb5c34086 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -125,7 +125,7 @@ else endif RUNTIME_DEF_$(1) := rt/rustrt$$(CFG_DEF_SUFFIX) -RUNTIME_INCS_$(1) := -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \ +RUNTIME_INCS_$(1) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \ -I $$(S)src/rt/arch/$$(HOST_$(1)) \ -I $$(S)src/libuv/include RUNTIME_OBJS_$(1) := $$(RUNTIME_CS_$(1):rt/%.cpp=rt/$(1)/%.o) \ diff --git a/src/rt/arch/i386/context.h b/src/rt/arch/i386/context.h index fc5eb900a5c7..03b97fa7b517 100644 --- a/src/rt/arch/i386/context.h +++ b/src/rt/arch/i386/context.h @@ -7,7 +7,7 @@ #include #include -#include "../../memcheck.h" +#include "vg/memcheck.h" template T align_down(T sp) @@ -51,9 +51,7 @@ public: uint32_t bot = regs.esp; uint32_t top = align_down(bot - nbytes); -#ifdef HAVE_VALGRIND (void)VALGRIND_MAKE_MEM_UNDEFINED(top - 4, bot - top + 4); -#endif return reinterpret_cast(top); } diff --git a/src/rt/arch/x86_64/context.h b/src/rt/arch/x86_64/context.h index 11c850927476..59d7bfa51f33 100644 --- a/src/rt/arch/x86_64/context.h +++ b/src/rt/arch/x86_64/context.h @@ -8,9 +8,7 @@ #include #include -#ifdef HAVE_VALGRIND -#include -#endif +#include "vg/memcheck.h" template T align_down(T sp) @@ -51,9 +49,7 @@ public: uint64_t bot = regs.data[RUSTRT_RSP]; uint64_t top = align_down(bot - nbytes); -#ifdef HAVE_VALGRIND (void)VALGRIND_MAKE_MEM_UNDEFINED(top - 4, bot - top + 4); -#endif return reinterpret_cast(top); } diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index a34ec4d86619..b540225243f9 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -2,8 +2,8 @@ #include "rust_internal.h" #include "rust_cc.h" -#include "valgrind.h" -#include "memcheck.h" +#include "vg/valgrind.h" +#include "vg/memcheck.h" #ifndef __WIN32__ #include diff --git a/src/rt/rust_timer.cpp b/src/rt/rust_timer.cpp index eb1f30b93ee1..ffa987667637 100644 --- a/src/rt/rust_timer.cpp +++ b/src/rt/rust_timer.cpp @@ -1,5 +1,5 @@ #include "rust_internal.h" -#include "valgrind.h" +#include "vg/valgrind.h" // The mechanism in this file is very crude; every domain (thread) spawns its // own secondary timer thread, and that timer thread *never idles*. It diff --git a/src/rt/memcheck.h b/src/rt/vg/memcheck.h similarity index 100% rename from src/rt/memcheck.h rename to src/rt/vg/memcheck.h diff --git a/src/rt/valgrind.h b/src/rt/vg/valgrind.h similarity index 100% rename from src/rt/valgrind.h rename to src/rt/vg/valgrind.h From 447414f00774d37d934867f5a476cf00e1f95423 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 5 Dec 2011 16:46:37 -0800 Subject: [PATCH 7/9] Establish 'core' library separate from 'std'. --- Makefile.in | 30 +++++++++++++++++++++++----- configure | 4 ++-- doc/lib.css | 8 ++++++++ doc/std.css | 8 -------- mk/dist.mk | 1 + mk/docs.mk | 32 ++++++++++++++++++------------ mk/host.mk | 16 +++++++++++++++ mk/install.mk | 2 ++ mk/pp.mk | 3 ++- mk/stage0.mk | 9 +++++++++ mk/target.mk | 7 +++++++ mk/tests.mk | 4 +++- mk/tools.mk | 3 +++ src/libcore/core.rc | 17 ++++++++++++++++ src/{lib => libstd}/bitv.rs | 0 src/{lib => libstd}/bool.rs | 0 src/{lib => libstd}/box.rs | 0 src/{lib => libstd}/c_vec.rs | 0 src/{lib => libstd}/char.rs | 0 src/{lib => libstd}/cmath.rs | 0 src/{lib => libstd}/comm.rs | 0 src/{lib => libstd}/ctypes.rs | 0 src/{lib => libstd}/dbg.rs | 0 src/{lib => libstd}/deque.rs | 0 src/{lib => libstd}/ebml.rs | 0 src/{lib => libstd}/either.rs | 0 src/{lib => libstd}/extfmt.rs | 0 src/{lib => libstd}/float.rs | 0 src/{lib => libstd}/four.rs | 0 src/{lib => libstd}/fs.rs | 0 src/{lib => libstd}/fun_treemap.rs | 0 src/{lib => libstd}/generic_os.rs | 0 src/{lib => libstd}/getopts.rs | 0 src/{lib => libstd}/int.rs | 0 src/{lib => libstd}/io.rs | 0 src/{lib => libstd}/json.rs | 0 src/{lib => libstd}/linux_os.rs | 0 src/{lib => libstd}/list.rs | 0 src/{lib => libstd}/macos_os.rs | 0 src/{lib => libstd}/map.rs | 0 src/{lib => libstd}/math.rs | 0 src/{lib => libstd}/math_f32.rs | 0 src/{lib => libstd}/math_f64.rs | 0 src/{lib => libstd}/net.rs | 0 src/{lib => libstd}/option.rs | 0 src/{lib => libstd}/posix_fs.rs | 0 src/{lib => libstd}/ptr.rs | 0 src/{lib => libstd}/rand.rs | 0 src/{lib => libstd}/result.rs | 0 src/{lib => libstd}/rope.rs | 0 src/{lib => libstd}/run_program.rs | 0 src/{lib => libstd}/sha1.rs | 0 src/{lib => libstd}/smallintmap.rs | 0 src/{lib => libstd}/sort.rs | 0 src/{lib => libstd}/std.rc | 0 src/{lib => libstd}/str.rs | 0 src/{lib => libstd}/sys.rs | 0 src/{lib => libstd}/task.rs | 0 src/{lib => libstd}/tempfile.rs | 0 src/{lib => libstd}/term.rs | 0 src/{lib => libstd}/test.rs | 0 src/{lib => libstd}/time.rs | 0 src/{lib => libstd}/treemap.rs | 0 src/{lib => libstd}/tri.rs | 0 src/{lib => libstd}/u32.rs | 0 src/{lib => libstd}/u64.rs | 0 src/{lib => libstd}/u8.rs | 0 src/{lib => libstd}/ufind.rs | 0 src/{lib => libstd}/uint.rs | 0 src/{lib => libstd}/unicode.rs | 0 src/{lib => libstd}/unsafe.rs | 0 src/{lib => libstd}/util.rs | 0 src/{lib => libstd}/uv.rs | 0 src/{lib => libstd}/vec.rs | 0 src/{lib => libstd}/win32_fs.rs | 0 src/{lib => libstd}/win32_os.rs | 0 76 files changed, 114 insertions(+), 30 deletions(-) create mode 100644 doc/lib.css delete mode 100644 doc/std.css create mode 100644 src/libcore/core.rc rename src/{lib => libstd}/bitv.rs (100%) rename src/{lib => libstd}/bool.rs (100%) rename src/{lib => libstd}/box.rs (100%) rename src/{lib => libstd}/c_vec.rs (100%) rename src/{lib => libstd}/char.rs (100%) rename src/{lib => libstd}/cmath.rs (100%) rename src/{lib => libstd}/comm.rs (100%) rename src/{lib => libstd}/ctypes.rs (100%) rename src/{lib => libstd}/dbg.rs (100%) rename src/{lib => libstd}/deque.rs (100%) rename src/{lib => libstd}/ebml.rs (100%) rename src/{lib => libstd}/either.rs (100%) rename src/{lib => libstd}/extfmt.rs (100%) rename src/{lib => libstd}/float.rs (100%) rename src/{lib => libstd}/four.rs (100%) rename src/{lib => libstd}/fs.rs (100%) rename src/{lib => libstd}/fun_treemap.rs (100%) rename src/{lib => libstd}/generic_os.rs (100%) rename src/{lib => libstd}/getopts.rs (100%) rename src/{lib => libstd}/int.rs (100%) rename src/{lib => libstd}/io.rs (100%) rename src/{lib => libstd}/json.rs (100%) rename src/{lib => libstd}/linux_os.rs (100%) rename src/{lib => libstd}/list.rs (100%) rename src/{lib => libstd}/macos_os.rs (100%) rename src/{lib => libstd}/map.rs (100%) rename src/{lib => libstd}/math.rs (100%) rename src/{lib => libstd}/math_f32.rs (100%) rename src/{lib => libstd}/math_f64.rs (100%) rename src/{lib => libstd}/net.rs (100%) rename src/{lib => libstd}/option.rs (100%) rename src/{lib => libstd}/posix_fs.rs (100%) rename src/{lib => libstd}/ptr.rs (100%) rename src/{lib => libstd}/rand.rs (100%) rename src/{lib => libstd}/result.rs (100%) rename src/{lib => libstd}/rope.rs (100%) rename src/{lib => libstd}/run_program.rs (100%) rename src/{lib => libstd}/sha1.rs (100%) rename src/{lib => libstd}/smallintmap.rs (100%) rename src/{lib => libstd}/sort.rs (100%) rename src/{lib => libstd}/std.rc (100%) rename src/{lib => libstd}/str.rs (100%) rename src/{lib => libstd}/sys.rs (100%) rename src/{lib => libstd}/task.rs (100%) rename src/{lib => libstd}/tempfile.rs (100%) rename src/{lib => libstd}/term.rs (100%) rename src/{lib => libstd}/test.rs (100%) rename src/{lib => libstd}/time.rs (100%) rename src/{lib => libstd}/treemap.rs (100%) rename src/{lib => libstd}/tri.rs (100%) rename src/{lib => libstd}/u32.rs (100%) rename src/{lib => libstd}/u64.rs (100%) rename src/{lib => libstd}/u8.rs (100%) rename src/{lib => libstd}/ufind.rs (100%) rename src/{lib => libstd}/uint.rs (100%) rename src/{lib => libstd}/unicode.rs (100%) rename src/{lib => libstd}/unsafe.rs (100%) rename src/{lib => libstd}/util.rs (100%) rename src/{lib => libstd}/uv.rs (100%) rename src/{lib => libstd}/vec.rs (100%) rename src/{lib => libstd}/win32_fs.rs (100%) rename src/{lib => libstd}/win32_os.rs (100%) diff --git a/Makefile.in b/Makefile.in index 52ab6d98edaa..ec08f124b728 100644 --- a/Makefile.in +++ b/Makefile.in @@ -104,6 +104,7 @@ endif CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt) CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm) +CFG_CORELIB :=$(call CFG_LIB_NAME,core) CFG_STDLIB :=$(call CFG_LIB_NAME,ruststd) CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc) @@ -144,9 +145,9 @@ else endif ifeq ($(CFG_NATURALDOCS),) - $(info cfg: no naturaldocs found, omitting doc/std/index.html) + $(info cfg: no naturaldocs found, omitting library doc build) else - DOCS += doc/std/index.html + DOCS += doc/core/index.html doc/std/index.html endif ifdef CFG_DISABLE_DOCS @@ -183,12 +184,21 @@ GENERATED := %:: s.% %:: SCCS/s.% +###################################################################### +# Core library variables +###################################################################### + +CORELIB_CRATE := $(S)src/libcore/core.rc +CORELIB_INPUTS := $(wildcard $(addprefix $(S)src/libcore/, \ + core.rc *.rs */*.rs)) + ###################################################################### # Standard library variables ###################################################################### -STDLIB_CRATE := $(S)src/lib/std.rc -STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/lib/,*.rc *.rs */*.rs)) +STDLIB_CRATE := $(S)src/libstd/std.rc +STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \ + std.rc *.rs */*.rs)) ###################################################################### # rustc crate variables @@ -268,13 +278,21 @@ TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2) TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/lib -# The name of the standard library used by rustc +# The name of the core and standard libraries used by rustc ifdef CFG_DISABLE_SHAREDSTD + HCORELIB_DEFAULT$(1)_H_$(3) = \ + $$(HLIB$(1)_H_$(3))/libcore.rlib + TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \ + $$(TLIB$(1)_T_$(2)_H_$(3))/libcore.rlib HSTDLIB_DEFAULT$(1)_H_$(3) = \ $$(HLIB$(1)_H_$(3))/libstd.rlib TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \ $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib else + HCORELIB_DEFAULT$(1)_H_$(3) = \ + $$(HLIB$(1)_H_$(3))/$(CFG_CORELIB) + TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_CORELIB) HSTDLIB_DEFAULT$(1)_H_$(3) = \ $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB) TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \ @@ -286,6 +304,7 @@ HSREQ$(1)_H_$(3) = \ $$(HBIN$(1)_H_$(3))/rustc$$(X) \ $$(HLIB$(1)_H_$(3))/$$(CFG_RUNTIME) \ $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLLVM) \ + $$(HCORELIB_DEFAULT$(1)_H_$(3)) \ $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \ $$(MKFILE_DEPS) @@ -299,6 +318,7 @@ TSREQ$(1)_T_$(2)_H_$(3) = \ # Prerequisites for complete stageN targets SREQ$(1)_T_$(2)_H_$(3) = \ $$(TSREQ$(1)_T_$(2)_H_$(3)) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) ifeq ($(1),0) diff --git a/configure b/configure index d583e6a4b43b..009e24059cf1 100755 --- a/configure +++ b/configure @@ -355,8 +355,8 @@ fi step_msg "making directories" for i in \ - doc doc/std \ - nd nd/std \ + doc doc/core doc/std \ + nd nd/core nd/std \ dl tmp do make_dir $i diff --git a/doc/lib.css b/doc/lib.css new file mode 100644 index 000000000000..443f11805840 --- /dev/null +++ b/doc/lib.css @@ -0,0 +1,8 @@ +/* +Custom styles for the library docs generated by naturaldocs +*/ + +p { + text-indent: 0; + margin-bottom: 1em; + } diff --git a/doc/std.css b/doc/std.css deleted file mode 100644 index 9593f25e8f66..000000000000 --- a/doc/std.css +++ /dev/null @@ -1,8 +0,0 @@ -/* -Custom styles for the standard library docs generated by naturaldocs -*/ - -p { - text-indent: 0; - margin-bottom: 1em; - } \ No newline at end of file diff --git a/mk/dist.mk b/mk/dist.mk index 54fcfdeb0134..a8df2c28fbef 100644 --- a/mk/dist.mk +++ b/mk/dist.mk @@ -46,6 +46,7 @@ PKG_FILES = \ $(PKG_3RDPARTY)) \ $(PKG_UV) \ $(COMPILER_INPUTS) \ + $(CORELIB_INPUTS) \ $(STDLIB_INPUTS) \ $(ALL_TEST_INPUTS) \ $(FUZZER_CRATE) \ diff --git a/mk/docs.mk b/mk/docs.mk index b4250194c483..4a5821ec2df5 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -29,19 +29,25 @@ docsnap: doc/rust.pdf @$(call E, snap: doc/rust-$(shell date +"%Y-%m-%d")-snap.pdf) $(Q)mv $< doc/rust-$(shell date +"%Y-%m-%d")-snap.pdf -doc/std/index.html: nd/std/Languages.txt nd/std/Topics.txt nd/std/std.css \ - $(STDLIB_CRATE) $(STDLIB_INPUTS) - @$(call E, naturaldocs: $@) - naturaldocs -i $(S)src/lib -o HTML doc/std -p nd/std -r -s Default std +define libdoc +doc/$(1)/index.html: nd/$(1)/Languages.txt nd/$(1)/Topics.txt \ + nd/$(1)/lib.css $(2) + @$$(call E, naturaldocs: $$@) + naturaldocs -i $(S)src/lib$(1) -o HTML doc/$(1) -p nd/$(1) -r -s Default lib -nd/std/Languages.txt: $(S)doc/Languages.txt - @$(call E, cp: $@) - $(Q)cp $< $@ +nd/$(1)/Languages.txt: $(S)doc/Languages.txt + @$$(call E, cp: $$@) + $(Q)cp $$< $$@ -nd/std/Topics.txt: $(S)doc/Topics.txt - @$(call E, cp: $@) - $(Q)cp $< $@ +nd/$(1)/Topics.txt: $(S)doc/Topics.txt + @$$(call E, cp: $$@) + $(Q)cp $$< $$@ -nd/std/std.css: $(S)doc/std.css - @$(call E, cp: $@) - $(Q)cp $< $@ +nd/$(1)/lib.css: $(S)doc/lib.css + @$$(call E, cp: $$@) + $(Q)cp $$< $$@ + +endef + +$(eval $(call libdoc,core,$(CORELIB_CRATE) $(CORELIB_INPUTS))) +$(eval $(call libdoc,std,$(STDLIB_CRATE) $(STDLIB_INPUTS))) diff --git a/mk/host.mk b/mk/host.mk index eae38abc64ff..add7278dee29 100644 --- a/mk/host.mk +++ b/mk/host.mk @@ -15,6 +15,7 @@ $$(HBIN$(2)_H_$(4))/rustc$$(X): \ $$(TBIN$(1)_T_$(4)_H_$(3))/rustc$$(X) \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUSTLLVM) \ + $$(HCORELIB_DEFAULT$(2)_H_$(4)) \ $$(HSTDLIB_DEFAULT$(2)_H_$(4)) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ @@ -25,6 +26,7 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_LIBRUSTC): \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC) \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUSTLLVM) \ + $$(HCORELIB_DEFAULT$(2)_H_$(3)) \ $$(HSTDLIB_DEFAULT$(2)_H_$(3)) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ @@ -34,14 +36,28 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME): \ @$$(call E, cp: $$@) $$(Q)cp $$< $$@ +$$(HLIB$(2)_H_$(4))/$$(CFG_CORELIB): \ + $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_CORELIB) \ + $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) + @$$(call E, cp: $$@) + $$(Q)cp $$< $$@ + $$(HLIB$(2)_H_$(4))/$$(CFG_STDLIB): \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \ + $$(HLIB$(2)_H_$(4))/$$(CFG_CORELIB) \ + $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) + @$$(call E, cp: $$@) + $$(Q)cp $$< $$@ + +$$(HLIB$(2)_H_$(4))/libcore.rlib: \ + $$(TLIB$(1)_T_$(4)_H_$(3))/libcore.rlib \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ $$(HLIB$(2)_H_$(4))/libstd.rlib: \ $$(TLIB$(1)_T_$(4)_H_$(3))/libstd.rlib \ + $$(HLIB$(2)_H_$(4))/libcore.rlib \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ diff --git a/mk/install.mk b/mk/install.mk index fc69b7131d77..c22a4a370108 100644 --- a/mk/install.mk +++ b/mk/install.mk @@ -33,6 +33,7 @@ PTL$(1)$(2) = $$(PTR$(1)$(2))/lib install-target-$(1)-host-$(2): $$(SREQ$$(ISTAGE)_T_$(1)_H_$(2)) $$(Q)mkdir -p $$(PTL$(1)$(2)) $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_RUNTIME)) + $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_CORELIB)) $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_STDLIB)) $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),intrinsics.bc) $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),libmorestack.a) @@ -61,6 +62,7 @@ install-host: $(SREQ$(ISTAGE)_T_$(CFG_HOST_TRIPLE)_H_$(CFG_HOST_TRIPLE)) $(Q)mkdir -p $(PREFIX_ROOT)/share/man/man1 $(Q)$(call INSTALL,$(HB),$(PHB),rustc$(X)) $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUNTIME)) + $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_CORELIB)) $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_STDLIB)) $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUSTLLVM)) $(Q)$(call INSTALL,$(S)/man, \ diff --git a/mk/pp.mk b/mk/pp.mk index 7ee3cee8c416..df414901f7f5 100644 --- a/mk/pp.mk +++ b/mk/pp.mk @@ -2,7 +2,8 @@ ifdef PPFILES PP_INPUTS_FILTERED := $(wildcard $(PPFILES)) else - PP_INPUTS = $(wildcard $(addprefix $(S)src/lib/,*.rs */*.rs)) \ + PP_INPUTS = $(wildcard $(addprefix $(S)src/libcore/,*.rs */*.rs)) \ + $(wildcard $(addprefix $(S)src/libstd/,*.rs */*.rs)) \ $(wildcard $(addprefix $(S)src/comp/,*.rs */*.rs */*/*.rs)) \ $(wildcard $(S)src/test/*/*.rs \ $(S)src/test/*/*/*.rs) \ diff --git a/mk/stage0.mk b/mk/stage0.mk index a7e2341f6544..7614c2304068 100644 --- a/mk/stage0.mk +++ b/mk/stage0.mk @@ -13,6 +13,10 @@ $(HLIB0_H_$(CFG_HOST_TRIPLE))/$(CFG_RUNTIME): \ $(HBIN0_H_$(CFG_HOST_TRIPLE))/rustc$(X) $(Q)touch $@ +$(HLIB0_H_$(CFG_HOST_TRIPLE))/$(CFG_CORELIB): \ + $(HBIN0_H_$(CFG_HOST_TRIPLE))/rustc$(X) + $(Q)touch $@ + $(HLIB0_H_$(CFG_HOST_TRIPLE))/$(CFG_STDLIB): \ $(HBIN0_H_$(CFG_HOST_TRIPLE))/rustc$(X) $(Q)touch $@ @@ -38,6 +42,11 @@ $$(HLIB0_H_$(1))/$$(CFG_RUNTIME): \ @$$(call E, cp: $$@) $$(Q)cp $$< $$@ +$$(HLIB0_H_$(1))/$(CFG_CORELIB): \ + $$(TLIB$(2)_T_$(1)_H_$(3))/$$(CFG_CORELIB) + @$$(call E, cp: $$@) + $$(Q)cp $$< $$@ + $$(HLIB0_H_$(1))/$(CFG_STDLIB): \ $$(TLIB$(2)_T_$(1)_H_$(3))/$$(CFG_STDLIB) @$$(call E, cp: $$@) diff --git a/mk/target.mk b/mk/target.mk index 5b91d70ae9a0..ecedff1c5d1f 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -22,8 +22,15 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a: \ @$$(call E, cp: $$@) $$(Q)cp $$< $$@ +$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB): \ + $$(CORELIB_CRATE) $$(CORELIB_INPUTS) \ + $$(TSREQ$(1)_T_$(2)_H_$(3)) + @$$(call E, compile_and_link: $$@) + $$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$< + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \ $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \ $$(TSREQ$(1)_T_$(2)_H_$(3)) @$$(call E, compile_and_link: $$@) $$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$< diff --git a/mk/tests.mk b/mk/tests.mk index dbda3ecb5cb3..e429c8ef98af 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -87,6 +87,8 @@ tidy: $(wildcard $(S)src/etc/*.py) \ $(COMPILER_CRATE) \ $(COMPILER_INPUTS) \ + $(CORELIB_CRATE) \ + $(CORELIB_INPUTS) \ $(STDLIB_CRATE) \ $(STDLIB_INPUTS) \ $(COMPILETEST_CRATE) \ @@ -475,4 +477,4 @@ endef $(foreach stage,$(STAGES), \ $(eval $(call DEF_CHECK_FOR_STAGE,$(stage)))) -check-fast: check-fast-H-$(CFG_HOST_TRIPLE) \ No newline at end of file +check-fast: check-fast-H-$(CFG_HOST_TRIPLE) diff --git a/mk/tools.mk b/mk/tools.mk index 3a944f76f32a..84d7c55ac35e 100644 --- a/mk/tools.mk +++ b/mk/tools.mk @@ -19,6 +19,7 @@ define TOOLS_STAGE_N $$(TBIN$(1)_T_$(4)_H_$(3))/fuzzer$$(X): \ $$(FUZZER_CRATE) $$(FUZZER_INPUTS) \ $$(TSREQ$(1)_T_$(4)_H_$(3)) \ + $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_CORELIB) \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC) @$$(call E, compile_and_link: $$@) @@ -37,6 +38,7 @@ $$(HBIN$(2)_H_$(4))/fuzzer$$(X): \ $$(TBIN$(1)_T_$(4)_H_$(3))/compiletest$$(X): \ $$(COMPILETEST_CRATE) $$(COMPILETEST_INPUTS) \ $$(TSREQ$(1)_T_$(4)_H_$(3)) \ + $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_CORELIB) \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) @$$(call E, compile_and_link: $$@) $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< @@ -50,6 +52,7 @@ $$(HBIN$(2)_H_$(4))/compiletest$$(X): \ $$(TBIN$(1)_T_$(4)_H_$(3))/cargo$$(X): \ $$(CARGO_CRATE) $$(CARGO_INPUTS) \ $$(TSREQ$(1)_T_$(4)_H_$(3)) \ + $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_CORELIB) \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC) @$$(call E, compile_and_link: $$@) diff --git a/src/libcore/core.rc b/src/libcore/core.rc new file mode 100644 index 000000000000..6feaf8fbfabf --- /dev/null +++ b/src/libcore/core.rc @@ -0,0 +1,17 @@ +#[link(name = "core", + vers = "0.1", + uuid = "c70c24a7-5551-4f73-8e37-380b11d80be8", + url = "http://rust-lang.org/src/core")]; + +#[comment = "The Rust core library"]; +#[license = "BSD"]; + + +// Local Variables: +// mode: rust; +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; +// End: diff --git a/src/lib/bitv.rs b/src/libstd/bitv.rs similarity index 100% rename from src/lib/bitv.rs rename to src/libstd/bitv.rs diff --git a/src/lib/bool.rs b/src/libstd/bool.rs similarity index 100% rename from src/lib/bool.rs rename to src/libstd/bool.rs diff --git a/src/lib/box.rs b/src/libstd/box.rs similarity index 100% rename from src/lib/box.rs rename to src/libstd/box.rs diff --git a/src/lib/c_vec.rs b/src/libstd/c_vec.rs similarity index 100% rename from src/lib/c_vec.rs rename to src/libstd/c_vec.rs diff --git a/src/lib/char.rs b/src/libstd/char.rs similarity index 100% rename from src/lib/char.rs rename to src/libstd/char.rs diff --git a/src/lib/cmath.rs b/src/libstd/cmath.rs similarity index 100% rename from src/lib/cmath.rs rename to src/libstd/cmath.rs diff --git a/src/lib/comm.rs b/src/libstd/comm.rs similarity index 100% rename from src/lib/comm.rs rename to src/libstd/comm.rs diff --git a/src/lib/ctypes.rs b/src/libstd/ctypes.rs similarity index 100% rename from src/lib/ctypes.rs rename to src/libstd/ctypes.rs diff --git a/src/lib/dbg.rs b/src/libstd/dbg.rs similarity index 100% rename from src/lib/dbg.rs rename to src/libstd/dbg.rs diff --git a/src/lib/deque.rs b/src/libstd/deque.rs similarity index 100% rename from src/lib/deque.rs rename to src/libstd/deque.rs diff --git a/src/lib/ebml.rs b/src/libstd/ebml.rs similarity index 100% rename from src/lib/ebml.rs rename to src/libstd/ebml.rs diff --git a/src/lib/either.rs b/src/libstd/either.rs similarity index 100% rename from src/lib/either.rs rename to src/libstd/either.rs diff --git a/src/lib/extfmt.rs b/src/libstd/extfmt.rs similarity index 100% rename from src/lib/extfmt.rs rename to src/libstd/extfmt.rs diff --git a/src/lib/float.rs b/src/libstd/float.rs similarity index 100% rename from src/lib/float.rs rename to src/libstd/float.rs diff --git a/src/lib/four.rs b/src/libstd/four.rs similarity index 100% rename from src/lib/four.rs rename to src/libstd/four.rs diff --git a/src/lib/fs.rs b/src/libstd/fs.rs similarity index 100% rename from src/lib/fs.rs rename to src/libstd/fs.rs diff --git a/src/lib/fun_treemap.rs b/src/libstd/fun_treemap.rs similarity index 100% rename from src/lib/fun_treemap.rs rename to src/libstd/fun_treemap.rs diff --git a/src/lib/generic_os.rs b/src/libstd/generic_os.rs similarity index 100% rename from src/lib/generic_os.rs rename to src/libstd/generic_os.rs diff --git a/src/lib/getopts.rs b/src/libstd/getopts.rs similarity index 100% rename from src/lib/getopts.rs rename to src/libstd/getopts.rs diff --git a/src/lib/int.rs b/src/libstd/int.rs similarity index 100% rename from src/lib/int.rs rename to src/libstd/int.rs diff --git a/src/lib/io.rs b/src/libstd/io.rs similarity index 100% rename from src/lib/io.rs rename to src/libstd/io.rs diff --git a/src/lib/json.rs b/src/libstd/json.rs similarity index 100% rename from src/lib/json.rs rename to src/libstd/json.rs diff --git a/src/lib/linux_os.rs b/src/libstd/linux_os.rs similarity index 100% rename from src/lib/linux_os.rs rename to src/libstd/linux_os.rs diff --git a/src/lib/list.rs b/src/libstd/list.rs similarity index 100% rename from src/lib/list.rs rename to src/libstd/list.rs diff --git a/src/lib/macos_os.rs b/src/libstd/macos_os.rs similarity index 100% rename from src/lib/macos_os.rs rename to src/libstd/macos_os.rs diff --git a/src/lib/map.rs b/src/libstd/map.rs similarity index 100% rename from src/lib/map.rs rename to src/libstd/map.rs diff --git a/src/lib/math.rs b/src/libstd/math.rs similarity index 100% rename from src/lib/math.rs rename to src/libstd/math.rs diff --git a/src/lib/math_f32.rs b/src/libstd/math_f32.rs similarity index 100% rename from src/lib/math_f32.rs rename to src/libstd/math_f32.rs diff --git a/src/lib/math_f64.rs b/src/libstd/math_f64.rs similarity index 100% rename from src/lib/math_f64.rs rename to src/libstd/math_f64.rs diff --git a/src/lib/net.rs b/src/libstd/net.rs similarity index 100% rename from src/lib/net.rs rename to src/libstd/net.rs diff --git a/src/lib/option.rs b/src/libstd/option.rs similarity index 100% rename from src/lib/option.rs rename to src/libstd/option.rs diff --git a/src/lib/posix_fs.rs b/src/libstd/posix_fs.rs similarity index 100% rename from src/lib/posix_fs.rs rename to src/libstd/posix_fs.rs diff --git a/src/lib/ptr.rs b/src/libstd/ptr.rs similarity index 100% rename from src/lib/ptr.rs rename to src/libstd/ptr.rs diff --git a/src/lib/rand.rs b/src/libstd/rand.rs similarity index 100% rename from src/lib/rand.rs rename to src/libstd/rand.rs diff --git a/src/lib/result.rs b/src/libstd/result.rs similarity index 100% rename from src/lib/result.rs rename to src/libstd/result.rs diff --git a/src/lib/rope.rs b/src/libstd/rope.rs similarity index 100% rename from src/lib/rope.rs rename to src/libstd/rope.rs diff --git a/src/lib/run_program.rs b/src/libstd/run_program.rs similarity index 100% rename from src/lib/run_program.rs rename to src/libstd/run_program.rs diff --git a/src/lib/sha1.rs b/src/libstd/sha1.rs similarity index 100% rename from src/lib/sha1.rs rename to src/libstd/sha1.rs diff --git a/src/lib/smallintmap.rs b/src/libstd/smallintmap.rs similarity index 100% rename from src/lib/smallintmap.rs rename to src/libstd/smallintmap.rs diff --git a/src/lib/sort.rs b/src/libstd/sort.rs similarity index 100% rename from src/lib/sort.rs rename to src/libstd/sort.rs diff --git a/src/lib/std.rc b/src/libstd/std.rc similarity index 100% rename from src/lib/std.rc rename to src/libstd/std.rc diff --git a/src/lib/str.rs b/src/libstd/str.rs similarity index 100% rename from src/lib/str.rs rename to src/libstd/str.rs diff --git a/src/lib/sys.rs b/src/libstd/sys.rs similarity index 100% rename from src/lib/sys.rs rename to src/libstd/sys.rs diff --git a/src/lib/task.rs b/src/libstd/task.rs similarity index 100% rename from src/lib/task.rs rename to src/libstd/task.rs diff --git a/src/lib/tempfile.rs b/src/libstd/tempfile.rs similarity index 100% rename from src/lib/tempfile.rs rename to src/libstd/tempfile.rs diff --git a/src/lib/term.rs b/src/libstd/term.rs similarity index 100% rename from src/lib/term.rs rename to src/libstd/term.rs diff --git a/src/lib/test.rs b/src/libstd/test.rs similarity index 100% rename from src/lib/test.rs rename to src/libstd/test.rs diff --git a/src/lib/time.rs b/src/libstd/time.rs similarity index 100% rename from src/lib/time.rs rename to src/libstd/time.rs diff --git a/src/lib/treemap.rs b/src/libstd/treemap.rs similarity index 100% rename from src/lib/treemap.rs rename to src/libstd/treemap.rs diff --git a/src/lib/tri.rs b/src/libstd/tri.rs similarity index 100% rename from src/lib/tri.rs rename to src/libstd/tri.rs diff --git a/src/lib/u32.rs b/src/libstd/u32.rs similarity index 100% rename from src/lib/u32.rs rename to src/libstd/u32.rs diff --git a/src/lib/u64.rs b/src/libstd/u64.rs similarity index 100% rename from src/lib/u64.rs rename to src/libstd/u64.rs diff --git a/src/lib/u8.rs b/src/libstd/u8.rs similarity index 100% rename from src/lib/u8.rs rename to src/libstd/u8.rs diff --git a/src/lib/ufind.rs b/src/libstd/ufind.rs similarity index 100% rename from src/lib/ufind.rs rename to src/libstd/ufind.rs diff --git a/src/lib/uint.rs b/src/libstd/uint.rs similarity index 100% rename from src/lib/uint.rs rename to src/libstd/uint.rs diff --git a/src/lib/unicode.rs b/src/libstd/unicode.rs similarity index 100% rename from src/lib/unicode.rs rename to src/libstd/unicode.rs diff --git a/src/lib/unsafe.rs b/src/libstd/unsafe.rs similarity index 100% rename from src/lib/unsafe.rs rename to src/libstd/unsafe.rs diff --git a/src/lib/util.rs b/src/libstd/util.rs similarity index 100% rename from src/lib/util.rs rename to src/libstd/util.rs diff --git a/src/lib/uv.rs b/src/libstd/uv.rs similarity index 100% rename from src/lib/uv.rs rename to src/libstd/uv.rs diff --git a/src/lib/vec.rs b/src/libstd/vec.rs similarity index 100% rename from src/lib/vec.rs rename to src/libstd/vec.rs diff --git a/src/lib/win32_fs.rs b/src/libstd/win32_fs.rs similarity index 100% rename from src/lib/win32_fs.rs rename to src/libstd/win32_fs.rs diff --git a/src/lib/win32_os.rs b/src/libstd/win32_os.rs similarity index 100% rename from src/lib/win32_os.rs rename to src/libstd/win32_os.rs From baf3de4733d834c5e515aa222ae0e6bdc9cb6ea8 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 6 Dec 2011 13:02:59 -0800 Subject: [PATCH 8/9] Rename --noverify flag to --no-verify. --- src/comp/driver/rustc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 7ed81be5eda2..95f9f06a9948 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -260,7 +260,7 @@ options: --pretty [type] pretty-print the input instead of compiling --ls list the symbols defined by a crate file -L add a directory to the library search path - --noverify suppress LLVM verification step (slight speedup) + --no-verify suppress LLVM verification step (slight speedup) --parse-only parse only; do not compile, assemble, or link --no-trans run all passes except translation; no output -g produce debug info @@ -362,7 +362,7 @@ fn build_session_options(match: getopts::match) } else if opt_present(match, "emit-llvm") { link::output_type_bitcode } else { link::output_type_exe }; - let verify = !opt_present(match, "noverify"); + let verify = !opt_present(match, "no-verify"); let save_temps = opt_present(match, "save-temps"); let debuginfo = opt_present(match, "g"); let stats = opt_present(match, "stats"); @@ -463,7 +463,7 @@ fn opts() -> [getopts::opt] { optflag("c"), optopt("o"), optflag("g"), optflag("save-temps"), optopt("sysroot"), optopt("target"), optflag("stats"), optflag("time-passes"), optflag("time-llvm-passes"), - optflag("noverify"), + optflag("no-verify"), optmulti("cfg"), optflag("test"), optflag("lib"), optflag("static"), optflag("gc"), optflag("stack-growth"), From 89efb7d9810643eb1b25c04e63203b591915448f Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 6 Dec 2011 13:58:45 -0800 Subject: [PATCH 9/9] libstd: Update docs --- doc/Languages.txt | 1 + src/libstd/c_vec.rs | 52 ++++++++++++++++++++ src/libstd/ctypes.rs | 108 ++++++++++++++++++++++++++++++++++++++++- src/libstd/float.rs | 13 ++--- src/libstd/io.rs | 6 +++ src/libstd/math.rs | 3 ++ src/libstd/math_f32.rs | 1 + src/libstd/math_f64.rs | 1 + src/libstd/str.rs | 3 +- src/libstd/tempfile.rs | 3 ++ 10 files changed, 178 insertions(+), 13 deletions(-) diff --git a/doc/Languages.txt b/doc/Languages.txt index c83e0d86ca96..565e4c27109f 100644 --- a/doc/Languages.txt +++ b/doc/Languages.txt @@ -120,6 +120,7 @@ Language: Rust Block Comment: /* */ Package Separator: :: Function Prototype Enders: ; { + Predicate Prototype Enders: ; { Type Prototype Enders: ; } Class Prototype Enders: { Variant Prototype Enders: ; diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index ff5f636d103c..7c2f1be70840 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -57,6 +57,16 @@ resource dtor_res(dtor: option::t) { Section: Introduction forms */ +/* +Function: create + +Create a c_vec::t from a native buffer with a given size. + +Parameters: + +base - A native pointer to a buffer +size - The number of elements in the buffer +*/ unsafe fn create(base: *mutable T, size: uint) -> t { ret t({base: base, size: size, @@ -64,6 +74,19 @@ unsafe fn create(base: *mutable T, size: uint) -> t { }); } +/* +Function: create_with_dtor + +Create a c_vec::t from a native buffer, with a given size, +and a function to run upon destruction. + +Parameters: + +base - A native pointer to a buffer +size - The number of elements in the buffer +dtor - A function to run when the value is destructed, useful + for freeing the buffer, etc. +*/ unsafe fn create_with_dtor(base: *mutable T, size: uint, dtor: fn@()) -> t { ret t({base: base, @@ -76,11 +99,29 @@ unsafe fn create_with_dtor(base: *mutable T, size: uint, dtor: fn@()) Section: Operations */ +/* +Function: get + +Retrieves an element at a given index + +Failure: + +If `ofs` is greater or equal to the length of the vector +*/ fn get(t: t, ofs: uint) -> T { assert ofs < (*t).size; ret unsafe { *ptr::mut_offset((*t).base, ofs) }; } +/* +Function: set + +Sets the value of an element at a given index + +Failure: + +If `ofs` is greater or equal to the length of the vector +*/ fn set(t: t, ofs: uint, v: T) { assert ofs < (*t).size; unsafe { *ptr::mut_offset((*t).base, ofs) = v }; @@ -90,10 +131,21 @@ fn set(t: t, ofs: uint, v: T) { Section: Elimination forms */ +// FIXME: Rename to len +/* +Function: size + +Returns the length of the vector +*/ fn size(t: t) -> uint { ret (*t).size; } +/* +Function: ptr + +Returns a pointer to the first element of the vector +*/ unsafe fn ptr(t: t) -> *mutable T { ret (*t).base; } diff --git a/src/libstd/ctypes.rs b/src/libstd/ctypes.rs index 82e414a864ce..509eb3ef0576 100644 --- a/src/libstd/ctypes.rs +++ b/src/libstd/ctypes.rs @@ -4,39 +4,143 @@ Module: ctypes Definitions useful for C interop */ +/* +FIXME: Add a test that uses some native code to verify these sizes, +which are not obviously correct for all potential platforms. +*/ + +/* +Type: c_int + +A signed integer with the same size as a C `int` +*/ type c_int = i32; + +/* +Type: c_uint + +An unsigned integer with the same size as a C `unsigned int` +*/ type c_uint = u32; -type void = int; // Not really the same as C +/* +Type: long + +A signed integer with the same size as a C `long` +*/ type long = int; + +/* +Type: unsigned + +An unsigned integer with the same size as a C `unsigned int` +*/ type unsigned = u32; + +/* +Type: ulong + +An unsigned integer with the same size as a C `unsigned long` +*/ type ulong = uint; -type intptr_t = uint; +/* +Type: intptr_t + +A signed integer with the same size as a pointer. This is +guaranteed to always be the same type as a Rust `int` +*/ +type intptr_t = uint; // FIXME: int + +/* +Type: uintptr_t + +An unsigned integer with the same size as a pointer. This is +guaranteed to always be the same type as a Rust `uint`. +*/ type uintptr_t = uint; type uint32_t = u32; +/* +Type: void + +A type, a pointer to which can be used as C `void *` + +Note that this does not directly correspond to the C `void` type, +which is an incomplete type. Using pointers to this type +when interoperating with C void pointers can help in documentation. +*/ +type void = int; + // machine type equivalents of rust int, uint, float +/* +Type: m_int + +FIXME: What C type does this represent? +*/ #[cfg(target_arch="x86")] type m_int = i32; #[cfg(target_arch="x86_64")] type m_int = i64; +/* +Type: m_uint + +FIXME: What C type does this represent? +*/ #[cfg(target_arch="x86")] type m_uint = u32; #[cfg(target_arch="x86_64")] type m_uint = u64; // This *must* match with "import m_float = fXX" in std::math per arch +/* +Type: m_float + +FIXME: What C type does this represent? +*/ type m_float = f64; +/* +Type: size_t + +An unsigned integer corresponding to the C `size_t` +*/ type size_t = uint; + +/* +Type: ssize_t + +A signed integer correpsonding to the C `ssize_t` +*/ type ssize_t = int; + +/* +Type: off_t + +An unsigned integer corresponding to the C `off_t` +*/ type off_t = uint; +/* +Type: fd_t + +A type that can be used for C file descriptors +*/ type fd_t = i32; // not actually a C type, but should be. + +/* +Type: pid_t + +A type for representing process ID's, corresponding to C `pid_t` +*/ type pid_t = i32; // enum is implementation-defined, but is 32-bits in practice +/* +Type: enum + +An unsigned integer with the same size as a C enum +*/ type enum = u32; diff --git a/src/libstd/float.rs b/src/libstd/float.rs index f916e97bbf8d..015dceb1dc1c 100644 --- a/src/libstd/float.rs +++ b/src/libstd/float.rs @@ -253,25 +253,18 @@ fn pow_uint_to_uint_as_float(x: uint, pow: uint) -> float { } -/** - * Section: Constants - */ - -//TODO: Once this is possible, replace the body of these functions -//by an actual constant. - /* Const: NaN */ const NaN: float = 0./0.; -/* Predicate: isNaN */ -pure fn isNaN(f: float) -> bool { f != f } - /* Const: infinity */ const infinity: float = 1./0.; /* Const: neg_infinity */ const neg_infinity: float = -1./0.; +/* Predicate: isNaN */ +pure fn isNaN(f: float) -> bool { f != f } + /* Function: add */ pure fn add(x: float, y: float) -> float { ret x + y; } diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 910ec8bb9ea3..06e1be2fc4b4 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -1,3 +1,9 @@ +/* +Module: io + +Basic input/output +*/ + import ctypes::fd_t; import ctypes::c_int; diff --git a/src/libstd/math.rs b/src/libstd/math.rs index 72056548ca57..31bfe2ba3a64 100644 --- a/src/libstd/math.rs +++ b/src/libstd/math.rs @@ -23,6 +23,9 @@ import ctypes::c_int; import m_float = math_f64; // FIXME replace with redirect to m_float::consts::FOO as soon as it works +/* +Module: consts +*/ mod consts { /* Const: pi diff --git a/src/libstd/math_f32.rs b/src/libstd/math_f32.rs index 2172c9f8a99c..6c36db51a67c 100644 --- a/src/libstd/math_f32.rs +++ b/src/libstd/math_f32.rs @@ -17,6 +17,7 @@ export export consts; +/* Module: consts */ mod consts { /* diff --git a/src/libstd/math_f64.rs b/src/libstd/math_f64.rs index 639dc4a29b25..cc8fad9f6652 100644 --- a/src/libstd/math_f64.rs +++ b/src/libstd/math_f64.rs @@ -17,6 +17,7 @@ export export consts; +/* Module: consts */ mod consts { /* diff --git a/src/libstd/str.rs b/src/libstd/str.rs index fb24c59f62f3..2bae8d699a5c 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -174,7 +174,8 @@ fn byte_len_range(s: str, byte_offset: uint, char_len: uint) -> uint { /* Function: bytes -Converts a string to a vector of bytes +Converts a string to a vector of bytes. The result vector is not +null-terminated. */ fn bytes(s: str) -> [u8] unsafe { let v = unsafe::reinterpret_cast(s); diff --git a/src/libstd/tempfile.rs b/src/libstd/tempfile.rs index 5f504ba23494..ee7d5e3b2d92 100644 --- a/src/libstd/tempfile.rs +++ b/src/libstd/tempfile.rs @@ -9,6 +9,9 @@ import option; import option::{none, some}; import rand; +/* +Function: mkdtemp +*/ fn mkdtemp(prefix: str, suffix: str) -> option::t { let r = rand::mk_rng(); let i = 0u;