Skip to content

Commit

Permalink
auto merge of rust-lang#17466 : nikomatsakis/rust/oibt, r=pcwalton
Browse files Browse the repository at this point in the history
Moves the vast majority of builtin bound checking out of type contents and into the trait system.

This is a preliminary step for a lot of follow-on work:

- opt-in builtin types, obviously
- generalized where clauses, because TypeContents has this notion that a type parameter has a single set of builtin kinds, but with where clauses it depends on context
- generalized coherence, because this adds support for recursive trait selection

Unfortunately I wasn't able to completely remove Type Contents from the front-end checking in this PR. It's still used by EUV to decide what gets moved and what doesn't.

r? @pcwalton
  • Loading branch information
bors committed Sep 25, 2014
2 parents 3be6a2f + 6473909 commit 2550243
Show file tree
Hide file tree
Showing 47 changed files with 1,194 additions and 1,112 deletions.
1 change: 1 addition & 0 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc

DEPS_core :=
DEPS_libc := core
DEPS_rlibc := core
DEPS_unicode := core
DEPS_alloc := core libc native:jemalloc
Expand Down
28 changes: 12 additions & 16 deletions src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ fn start(_argc: int, _argv: *const *const u8) -> int {
// provided by libstd.
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "sized"] trait Sized { }
#[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} }
# // fn main() {} tricked you, rustdoc!
```

Expand All @@ -489,32 +489,28 @@ pub extern fn main(argc: int, argv: *const *const u8) -> int {
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "sized"] trait Sized { }
#[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} }
# // fn main() {} tricked you, rustdoc!
```


The compiler currently makes a few assumptions about symbols which are available
in the executable to call. Normally these functions are provided by the standard
xlibrary, but without it you must define your own.
library, but without it you must define your own.

The first of these two functions, `stack_exhausted`, is invoked whenever stack
The first of these three functions, `stack_exhausted`, is invoked whenever stack
overflow is detected. This function has a number of restrictions about how it
can be called and what it must do, but if the stack limit register is not being
maintained then a task always has an "infinite stack" and this function
shouldn't get triggered.

The second of these two functions, `eh_personality`, is used by the failure
mechanisms of the compiler. This is often mapped to GCC's personality function
(see the [libstd implementation](std/rt/unwind/index.html) for more
information), but crates which do not trigger failure can be assured that this
function is never called.

The final item in the example is a trait called `Sized`. This a trait
that represents data of a known static size: it is integral to the
Rust type system, and so the compiler expects the standard library to
provide it. Since you are not using the standard library, you have to
provide it yourself.
The second of these three functions, `eh_personality`, is used by the
failure mechanisms of the compiler. This is often mapped to GCC's
personality function (see the
[libstd implementation](std/rt/unwind/index.html) for more
information), but crates which do not trigger failure can be assured
that this function is never called. The final function, `fail_fmt`, is
also used by the failure mechanisms of the compiler.

## Using libcore

Expand Down Expand Up @@ -694,7 +690,7 @@ fn main(argc: int, argv: *const *const u8) -> int {
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "sized"] trait Sized {}
#[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} }
```

Note the use of `abort`: the `exchange_malloc` lang item is assumed to
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ pub use self::Sync as Share;

/// Types able to be transferred across task boundaries.
#[lang="send"]
pub trait Send {
pub trait Send for Sized? {
// empty.
}

/// Types with a constant size known at compile-time.
#[lang="sized"]
pub trait Sized {
pub trait Sized for Sized? {
// Empty.
}

/// Types that can be copied by simply copying bits (i.e. `memcpy`).
#[lang="copy"]
pub trait Copy {
pub trait Copy for Sized? {
// Empty.
}

Expand Down Expand Up @@ -87,7 +87,7 @@ pub trait Copy {
/// reference; not doing this is undefined behaviour (for example,
/// `transmute`-ing from `&T` to `&mut T` is illegal).
#[lang="sync"]
pub trait Sync {
pub trait Sync for Sized? {
// Empty
}

Expand Down
2 changes: 2 additions & 0 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
#![allow(missing_doc)]
#![allow(non_snake_case)]

extern crate core;

#[cfg(test)] extern crate std;
#[cfg(test)] extern crate test;
#[cfg(test)] extern crate native;
Expand Down
10 changes: 0 additions & 10 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ register_diagnostics!(
E0039,
E0040,
E0041,
E0042,
E0043,
E0044,
E0045,
E0046,
Expand Down Expand Up @@ -92,7 +90,6 @@ register_diagnostics!(
E0075,
E0076,
E0077,
E0078,
E0079,
E0080,
E0081,
Expand Down Expand Up @@ -130,7 +127,6 @@ register_diagnostics!(
E0121,
E0122,
E0124,
E0125,
E0126,
E0127,
E0128,
Expand All @@ -147,12 +143,6 @@ register_diagnostics!(
E0139,
E0140,
E0141,
E0143,
E0144,
E0145,
E0146,
E0148,
E0151,
E0152,
E0153,
E0154,
Expand Down
10 changes: 7 additions & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use lint;
use llvm::{ContextRef, ModuleRef};
use metadata::common::LinkMeta;
use metadata::creader;
use middle::{trans, stability, kind, ty, typeck, reachable};
use middle::{trans, stability, ty, typeck, reachable};
use middle::dependency_format;
use middle;
use plugin::load::Plugins;
Expand Down Expand Up @@ -462,8 +462,12 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
time(time_passes, "rvalue checking", (), |_|
middle::check_rvalues::check_crate(&ty_cx, krate));

time(time_passes, "kind checking", (), |_|
kind::check_crate(&ty_cx));
// Avoid overwhelming user with errors if type checking failed.
// I'm not sure how helpful this is, to be honest, but it avoids a
// lot of annoying errors in the compile-fail tests (basically,
// lint warnings and so on -- kindck used to do this abort, but
// kindck is gone now). -nmatsakis
ty_cx.sess.abort_if_errors();

let reachable_map =
time(time_passes, "reachability checking", (), |_|
Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ pub mod middle {
pub mod expr_use_visitor;
pub mod graph;
pub mod intrinsicck;
pub mod kind;
pub mod lang_items;
pub mod liveness;
pub mod mem_categorization;
Expand Down
Loading

0 comments on commit 2550243

Please sign in to comment.