Skip to content

Commit 5c30f7f

Browse files
committed
---
yaml --- r: 157046 b: refs/heads/try c: f168c12 h: refs/heads/master v: v3
1 parent 65d16bf commit 5c30f7f

31 files changed

+549
-763
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 2d27bfaeb6522d386d0a2735cb3f75cc5707314a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: d44ea720fa9dfe062ef06d0eb49a58d4e7e92344
5-
refs/heads/try: a9e85100cd598ddb9395b2ad31b31e0f9df84f22
5+
refs/heads/try: f168c12c5629afd45c9b3ed250350bf830b99642
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 6601b0501e31d08d3892a2d5a7d8a57ab120bf75

branches/try/src/doc/guide.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,13 +3466,14 @@ for destroying that resource as well. Given that we're discussing pointers
34663466
right now, let's discuss this in the context of memory allocation, though
34673467
it applies to other resources as well.
34683468

3469-
When you allocate heap memory, you need a mechanism to free that memory. Many
3470-
languages let the programmer control the allocation, and then use a garbage
3471-
collector to handle the deallocation. This is a valid, time-tested strategy,
3472-
but it's not without its drawbacks. Because the programmer does not have to
3473-
think as much about deallocation, allocation becomes something commonplace,
3474-
because it's easy. And if you need precise control over when something is
3475-
deallocated, leaving it up to your runtime can make this difficult.
3469+
When you allocate heap memory, you need a mechanism to free that memory. Many
3470+
languages use a garbage collector to handle deallocation. This is a valid,
3471+
time-tested strategy, but it's not without its drawbacks: it adds overhead, and
3472+
can lead to unpredictable pauses in execution. Because the programmer does not
3473+
have to think as much about deallocation, allocation becomes something
3474+
commonplace, leading to more memory usage. And if you need precise control
3475+
over when something is deallocated, leaving it up to your runtime can make this
3476+
difficult.
34763477

34773478
Rust chooses a different path, and that path is called **ownership**. Any
34783479
binding that creates a resource is the **owner** of that resource.
@@ -3498,17 +3499,19 @@ memory. The length of time that the borrower is borrowing the pointer
34983499
from you is called a **lifetime**.
34993500

35003501
If two distinct bindings share a pointer, and the memory that pointer points to
3501-
is immutable, then there are no problems. But if it's mutable, both pointers
3502-
can attempt to write to the memory at the same time, causing a **race
3503-
condition**. Therefore, if someone wants to mutate something that they've
3504-
borrowed from you, you must not have lent out that pointer to anyone else.
3502+
is immutable, then there are no problems. But if it's mutable, the result of
3503+
changing it can vary unpredictably depending on who happens to access it first,
3504+
which is called a **race condition**. To avoid this, if someone wants to mutate
3505+
something that they've borrowed from you, you must not have lent out that
3506+
pointer to anyone else.
35053507

35063508
Rust has a sophisticated system called the **borrow checker** to make sure that
35073509
everyone plays by these rules. At compile time, it verifies that none of these
3508-
rules are broken. If there's no problem, our program compiles successfully, and
3509-
there is no runtime overhead for any of this. The borrow checker works only at
3510-
compile time. If the borrow checker did find a problem, it will report a
3511-
**lifetime error**, and your program will refuse to compile.
3510+
rules are broken. If our program compiles successfully, Rust can guarantee it
3511+
is free of data races and other memory errors, and there is no runtime overhead
3512+
for any of this. The borrow checker works only at compile time. If the borrow
3513+
checker did find a problem, it will report a **lifetime error**, and your
3514+
program will refuse to compile.
35123515

35133516
That's a lot to take in. It's also one of the _most_ important concepts in
35143517
all of Rust. Let's see this syntax in action:

branches/try/src/libcore/intrinsics.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,17 @@ extern "rust-intrinsic" {
260260
/// NB: This is very different from the `unreachable!()` macro!
261261
pub fn unreachable() -> !;
262262

263+
/// Inform the optimizer that a condition is always true.
264+
/// If the condition is false, the behavior is undefined.
265+
///
266+
/// No code is generated for this intrinsic, but the optimizer will try
267+
/// to preserve it (and its condition) between passes, which may interfere
268+
/// with optimization of surrounding code and reduce performance. It should
269+
/// not be used if the invariant can be discovered by the optimizer on its
270+
/// own, or if it does not enable any significant optimizations.
271+
#[cfg(not(stage0))]
272+
pub fn assume(b: bool);
273+
263274
/// Execute a breakpoint trap, for inspection by a debugger.
264275
pub fn breakpoint();
265276

branches/try/src/librustc/diagnostics.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ register_diagnostics!(
4444
E0025,
4545
E0026,
4646
E0027,
47-
E0028,
4847
E0029,
4948
E0030,
5049
E0031,
51-
E0032,
5250
E0033,
5351
E0034,
5452
E0035,

branches/try/src/librustc/metadata/decoder.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,14 @@ pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
673673
let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
674674
item, tcx, cdata);
675675
let name = item_name(&*intr, item);
676-
let arg_tys = match ty::get(ctor_ty).sty {
677-
ty::ty_bare_fn(ref f) => f.sig.inputs.clone(),
678-
_ => Vec::new(), // Nullary enum variant.
676+
let (ctor_ty, arg_tys) = match ty::get(ctor_ty).sty {
677+
ty::ty_bare_fn(ref f) =>
678+
(Some(ctor_ty), f.sig.inputs.clone()),
679+
_ => // Nullary or struct enum variant.
680+
(None, get_struct_fields(intr.clone(), cdata, did.node)
681+
.iter()
682+
.map(|field_ty| get_type(cdata, field_ty.id.node, tcx).ty)
683+
.collect())
679684
};
680685
match variant_disr_val(item) {
681686
Some(val) => { disr_val = val; }

branches/try/src/librustc/middle/privacy.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -667,21 +667,12 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
667667

668668
let struct_type = ty::lookup_item_type(self.tcx, id).ty;
669669
let struct_desc = match ty::get(struct_type).sty {
670-
ty::ty_struct(_, _) => format!("struct `{}`", ty::item_path_str(self.tcx, id)),
671-
ty::ty_bare_fn(ty::BareFnTy { sig: ty::FnSig { output, .. }, .. }) => {
672-
// Struct `id` is really a struct variant of an enum,
673-
// and we're really looking at the variant's constructor
674-
// function. So get the return type for a detailed error
675-
// message.
676-
let enum_id = match ty::get(output).sty {
677-
ty::ty_enum(id, _) => id,
678-
_ => self.tcx.sess.span_bug(span, "enum variant doesn't \
679-
belong to an enum")
680-
};
670+
ty::ty_struct(_, _) =>
671+
format!("struct `{}`", ty::item_path_str(self.tcx, id)),
672+
ty::ty_enum(enum_id, _) =>
681673
format!("variant `{}` of enum `{}`",
682674
ty::with_path(self.tcx, id, |mut p| p.last().unwrap()),
683-
ty::item_path_str(self.tcx, enum_id))
684-
}
675+
ty::item_path_str(self.tcx, enum_id)),
685676
_ => self.tcx.sess.span_bug(span, "can't find struct for field")
686677
};
687678
let msg = match name {

branches/try/src/librustc/middle/resolve.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5077,7 +5077,6 @@ impl<'a> Resolver<'a> {
50775077
PatEnum(ref path, _) => {
50785078
// This must be an enum variant, struct or const.
50795079
match self.resolve_path(pat_id, path, ValueNS, false) {
5080-
Some(def @ (DefFn(..), _)) |
50815080
Some(def @ (DefVariant(..), _)) |
50825081
Some(def @ (DefStruct(..), _)) |
50835082
Some(def @ (DefConst(..), _)) => {

branches/try/src/librustc/middle/trans/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
860860
ifn!("llvm.lifetime.end" fn(t_i64, i8p) -> void);
861861

862862
ifn!("llvm.expect.i1" fn(i1, i1) -> i1);
863+
ifn!("llvm.assume" fn(i1) -> void);
863864

864865
// Some intrinsics were introduced in later versions of LLVM, but they have
865866
// fallbacks in libc or libm and such. Currently, all of these intrinsics

branches/try/src/librustc/middle/trans/intrinsic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub fn get_simple_intrinsic(ccx: &CrateContext, item: &ast::ForeignItem) -> Opti
8181
"bswap16" => "llvm.bswap.i16",
8282
"bswap32" => "llvm.bswap.i32",
8383
"bswap64" => "llvm.bswap.i64",
84+
"assume" => "llvm.assume",
8485
_ => return None
8586
};
8687
Some(ccx.get_intrinsic(&name))

branches/try/src/librustc/middle/ty.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use syntax::ast::{CrateNum, DefId, FnStyle, Ident, ItemTrait, LOCAL_CRATE};
5050
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
5151
use syntax::ast::{Onceness, StmtExpr, StmtSemi, StructField, UnnamedField};
5252
use syntax::ast::{Visibility};
53-
use syntax::ast_util::{mod, PostExpansionMethod, is_local, lit_is_str};
53+
use syntax::ast_util::{mod, is_local, lit_is_str, local_def, PostExpansionMethod};
5454
use syntax::attr::{mod, AttrMetaMethods};
5555
use syntax::codemap::Span;
5656
use syntax::parse::token::{mod, InternedString};
@@ -4221,7 +4221,7 @@ pub fn ty_to_def_id(ty: t) -> Option<ast::DefId> {
42214221
pub struct VariantInfo {
42224222
pub args: Vec<t>,
42234223
pub arg_names: Option<Vec<ast::Ident> >,
4224-
pub ctor_ty: t,
4224+
pub ctor_ty: Option<t>,
42254225
pub name: ast::Name,
42264226
pub id: ast::DefId,
42274227
pub disr_val: Disr,
@@ -4249,7 +4249,7 @@ impl VariantInfo {
42494249
return VariantInfo {
42504250
args: arg_tys,
42514251
arg_names: None,
4252-
ctor_ty: ctor_ty,
4252+
ctor_ty: Some(ctor_ty),
42534253
name: ast_variant.node.name.name,
42544254
id: ast_util::local_def(ast_variant.node.id),
42554255
disr_val: discriminant,
@@ -4262,7 +4262,8 @@ impl VariantInfo {
42624262

42634263
assert!(fields.len() > 0);
42644264

4265-
let arg_tys = ty_fn_args(ctor_ty).iter().map(|a| *a).collect();
4265+
let arg_tys = struct_def.fields.iter()
4266+
.map(|field| node_id_to_type(cx, field.node.id)).collect();
42664267
let arg_names = fields.iter().map(|field| {
42674268
match field.node.kind {
42684269
NamedField(ident, _) => ident,
@@ -4274,7 +4275,7 @@ impl VariantInfo {
42744275
return VariantInfo {
42754276
args: arg_tys,
42764277
arg_names: Some(arg_names),
4277-
ctor_ty: ctor_ty,
4278+
ctor_ty: None,
42784279
name: ast_variant.node.name.name,
42794280
id: ast_util::local_def(ast_variant.node.id),
42804281
disr_val: discriminant,

0 commit comments

Comments
 (0)