Skip to content

Rollup of PRs in the queue; Friday #23337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bce7a6f
Remove dead code flagged by lint
sanxiyn Jan 21, 2015
b042ffc
Extend dead code lint to detect more unused enum variants
sanxiyn Jan 21, 2015
de52403
Avoid passing -L "" to rustc.
rprichard Mar 12, 2015
90fc28d
debuginfo: Add GDB pretty printers for slices, Vec<>, and String.
michaelwoerister Mar 12, 2015
5d9ed0b
Update the ways to get a pointer from a box
gkoz Mar 12, 2015
ccfc381
Fixed several grammar errors and broke up very long line.
tanadeau Mar 12, 2015
ae21b4f
remove mention of specialization from `Hash` trait
apasel422 Mar 12, 2015
ebcb1dc
Fix naming of beta artifacts again
brson Mar 13, 2015
0942803
Add an "allocator" attribute to mark functions as allocators
dotdash Mar 13, 2015
4e25765
rustdoc: Fix ICE with cross-crate default impls
alexcrichton Mar 13, 2015
7d2ee7a
Rollup merge of #23307 - michaelwoerister:lldb-vec-pp-bug, r=alexcric…
Manishearth Mar 13, 2015
6354387
Rollup merge of #23310 - michaelwoerister:gdb-std-pp, r=alexcrichton
Manishearth Mar 13, 2015
99ce371
Rollup merge of #23325 - brson:beta, r=alexcrichton
Manishearth Mar 13, 2015
da054a5
Rollup merge of #23328 - alexcrichton:rustdoc-default-impl, r=brson
Manishearth Mar 13, 2015
b00c310
Rollup merge of #23312 - gkoz:ptr_from_box_docs, r=steveklabnik
Manishearth Mar 13, 2015
63bdfbf
Rollup merge of #23317 - tanadeau:fix-formatting-and-grammar, r=steve…
Manishearth Mar 13, 2015
63cd9f9
Rollup merge of #23321 - apasel422:hash, r=alexcrichton
Manishearth Mar 13, 2015
d0f98fc
Rollup merge of #23322 - dotdash:jemalloc_attrs, r=brson
Manishearth Mar 13, 2015
0e4b8d6
Rollup merge of #23324 - rprichard:fix-freebsd, r=brson
Manishearth Mar 13, 2015
0d37323
Rollup merge of #21468 - sanxiyn:dead-variant, r=
Manishearth Mar 13, 2015
825f49a
Fix def -> PathResolution
Manishearth Mar 13, 2015
40b6464
rm unused import
Manishearth Mar 13, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mk/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ $$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger
touch -r $$@.start_time $$@ && rm $$@.start_time

ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
LLVM_STDCPP_LOCATION_$(1) = $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
-print-file-name=libstdc++.a)
LLVM_STDCPP_RUSTFLAGS_$(1) = -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
-print-file-name=libstdc++.a))"
else
LLVM_STDCPP_LOCATION_$(1) =
LLVM_STDCPP_RUSTFLAGS_$(1) =
endif


Expand Down
4 changes: 2 additions & 2 deletions mk/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)
CFG_DISABLE_UNSTABLE_FEATURES=1
endif
ifeq ($(CFG_RELEASE_CHANNEL),beta)
CFG_RELEASE=$(CFG_RELEASE_NUM)-beta(CFG_PRERELEASE_VERSION)
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-beta(CFG_PRERELEASE_VERSION)
CFG_RELEASE=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION)
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION)
CFG_DISABLE_UNSTABLE_FEATURES=1
endif
ifeq ($(CFG_RELEASE_CHANNEL),nightly)
Expand Down
2 changes: 1 addition & 1 deletion mk/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
$$(RUST_LIB_FLAGS_ST$(1)) \
-L "$$(RT_OUTPUT_DIR_$(2))" \
-L "$$(LLVM_LIBDIR_$(2))" \
-L "$$(dir $$(LLVM_STDCPP_LOCATION_$(2)))" \
$$(LLVM_STDCPP_RUSTFLAGS_$(2)) \
$$(RUSTFLAGS_$(4)) \
--out-dir $$(@D) \
-C extra-filename=-$$(CFG_FILENAME_EXTRA) \
Expand Down
6 changes: 4 additions & 2 deletions src/doc/trpl/hello-cargo.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ Hello, world!
Bam! We build our project with `cargo build`, and run it with
`./target/debug/hello_world`. This hasn't bought us a whole lot over our simple use
of `rustc`, but think about the future: when our project has more than one
file, we would need to call `rustc` more than once, and pass it a bunch of options to
file, we would need to call `rustc` more than once and pass it a bunch of options to
tell it to build everything together. With Cargo, as our project grows, we can
just `cargo build` and it'll work the right way. When you're project is finally ready for release, you can use `cargo build --release` to compile your crates with optimizations.
just `cargo build`, and it'll work the right way. When your project is finally
ready for release, you can use `cargo build --release` to compile your crates with
optimizations.

You'll also notice that Cargo has created a new file: `Cargo.lock`.

Expand Down
89 changes: 88 additions & 1 deletion src/etc/gdb_rust_pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ def rust_pretty_printer_lookup_function(val):
if type_code == gdb.TYPE_CODE_STRUCT:
struct_kind = classify_struct(val.type)

if struct_kind == STRUCT_KIND_SLICE:
return RustSlicePrinter(val)

if struct_kind == STRUCT_KIND_STR_SLICE:
return RustStringSlicePrinter(val)

if struct_kind == STRUCT_KIND_STD_VEC:
return RustStdVecPrinter(val)

if struct_kind == STRUCT_KIND_STD_STRING:
return RustStdStringPrinter(val)

if struct_kind == STRUCT_KIND_TUPLE:
return RustTuplePrinter(val)

Expand Down Expand Up @@ -172,6 +181,28 @@ def children(self):
def display_hint(self):
return "array"

class RustSlicePrinter:
def __init__(self, val):
self.val = val

def display_hint(self):
return "array"

def to_string(self):
length = int(self.val["length"])
return self.val.type.tag + ("(len: %i)" % length)

def children(self):
cs = []
length = int(self.val["length"])
data_ptr = self.val["data_ptr"]
assert data_ptr.type.code == gdb.TYPE_CODE_PTR
pointee_type = data_ptr.type.target()

for index in range(0, length):
cs.append((str(index), (data_ptr + index).dereference()))

return cs

class RustStringSlicePrinter:
def __init__(self, val):
Expand All @@ -181,6 +212,35 @@ def to_string(self):
slice_byte_len = self.val["length"]
return '"%s"' % self.val["data_ptr"].string(encoding="utf-8", length=slice_byte_len)

class RustStdVecPrinter:
def __init__(self, val):
self.val = val

def display_hint(self):
return "array"

def to_string(self):
length = int(self.val["len"])
cap = int(self.val["cap"])
return self.val.type.tag + ("(len: %i, cap: %i)" % (length, cap))

def children(self):
cs = []
(length, data_ptr) = extract_length_and_data_ptr_from_std_vec(self.val)
pointee_type = data_ptr.type.target()

for index in range(0, length):
cs.append((str(index), (data_ptr + index).dereference()))
return cs

class RustStdStringPrinter:
def __init__(self, val):
self.val = val

def to_string(self):
(length, data_ptr) = extract_length_and_data_ptr_from_std_vec(self.val["vec"])
return '"%s"' % data_ptr.string(encoding="utf-8", length=length)


class RustCStyleEnumPrinter:
def __init__(self, val):
Expand All @@ -204,19 +264,38 @@ def to_string(self):
STRUCT_KIND_TUPLE_VARIANT = 3
STRUCT_KIND_STRUCT_VARIANT = 4
STRUCT_KIND_CSTYLE_VARIANT = 5
STRUCT_KIND_STR_SLICE = 6
STRUCT_KIND_SLICE = 6
STRUCT_KIND_STR_SLICE = 7
STRUCT_KIND_STD_VEC = 8
STRUCT_KIND_STD_STRING = 9


def classify_struct(type):
# print("\nclassify_struct: tag=%s\n" % type.tag)
if type.tag == "&str":
return STRUCT_KIND_STR_SLICE

if type.tag.startswith("&[") and type.tag.endswith("]"):
return STRUCT_KIND_SLICE

fields = list(type.fields())
field_count = len(fields)

if field_count == 0:
return STRUCT_KIND_REGULAR_STRUCT

if (field_count == 3 and
fields[0].name == "ptr" and
fields[1].name == "len" and
fields[2].name == "cap" and
type.tag.startswith("Vec<")):
return STRUCT_KIND_STD_VEC

if (field_count == 1 and
fields[0].name == "vec" and
type.tag == "String"):
return STRUCT_KIND_STD_STRING

if fields[0].name == "RUST$ENUM$DISR":
if field_count == 1:
return STRUCT_KIND_CSTYLE_VARIANT
Expand Down Expand Up @@ -254,3 +333,11 @@ def get_field_at_index(val, index):
return field
i += 1
return None

def extract_length_and_data_ptr_from_std_vec(vec_val):
length = int(vec_val["len"])
vec_ptr_val = vec_val["ptr"]
unique_ptr_val = vec_ptr_val[first_field(vec_ptr_val)]
data_ptr = unique_ptr_val[first_field(unique_ptr_val)]
assert data_ptr.type.code == gdb.TYPE_CODE_PTR
return (length, data_ptr)
98 changes: 77 additions & 21 deletions src/etc/lldb_rust_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,12 @@ def print_struct_val(val, internal_dict):

if is_vec_slice(val):
return print_vec_slice_val(val, internal_dict)
elif is_std_vec(val):
return print_std_vec_val(val, internal_dict)
else:
return print_struct_val_starting_from(0, val, internal_dict)


def print_vec_slice_val(val, internal_dict):
length = val.GetChildAtIndex(1).GetValueAsUnsigned()

data_ptr_val = val.GetChildAtIndex(0)
data_ptr_type = data_ptr_val.GetType()
assert data_ptr_type.IsPointerType()

element_type = data_ptr_type.GetPointeeType()
element_type_size = element_type.GetByteSize()

start_address = data_ptr_val.GetValueAsUnsigned()

def render_element(i):
address = start_address + i * element_type_size
element_val = val.CreateValueFromAddress(val.GetName() +
("[%s]" % i), address, element_type)
return print_val(element_val, internal_dict)

return "&[%s]" % (', '.join([render_element(i) for i in range(length)]))


def print_struct_val_starting_from(field_start_index, val, internal_dict):
'''
Prints a struct, tuple, or tuple struct value with Rust syntax.
Expand Down Expand Up @@ -100,6 +81,16 @@ def render_child(child_index):
this += field_name + ": "

field_val = val.GetChildAtIndex(child_index)

if not field_val.IsValid():
field = t.GetFieldAtIndex(child_index)
# LLDB is not good at handling zero-sized values, so we have to help
# it a little
if field.GetType().GetByteSize() == 0:
return this + extract_type_name(field.GetType().GetName())
else:
return this + "<invalid value>"

return this + print_val(field_val, internal_dict)

body = separator.join([render_child(idx) for idx in range(field_start_index, num_children)])
Expand Down Expand Up @@ -195,6 +186,30 @@ def print_fixed_size_vec_val(val, internal_dict):
return output


def print_vec_slice_val(val, internal_dict):
length = val.GetChildAtIndex(1).GetValueAsUnsigned()

data_ptr_val = val.GetChildAtIndex(0)
data_ptr_type = data_ptr_val.GetType()

return "&[%s]" % print_array_of_values(val.GetName(),
data_ptr_val,
length,
internal_dict)


def print_std_vec_val(val, internal_dict):
length = val.GetChildAtIndex(1).GetValueAsUnsigned()

# Vec<> -> Unique<> -> NonZero<> -> *T
data_ptr_val = val.GetChildAtIndex(0).GetChildAtIndex(0).GetChildAtIndex(0)
data_ptr_type = data_ptr_val.GetType()

return "vec![%s]" % print_array_of_values(val.GetName(),
data_ptr_val,
length,
internal_dict)

#=--------------------------------------------------------------------------------------------------
# Helper Functions
#=--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -243,3 +258,44 @@ def is_vec_slice(val):

type_name = extract_type_name(ty.GetName()).replace("&'static", "&").replace(" ", "")
return type_name.startswith("&[") and type_name.endswith("]")

def is_std_vec(val):
ty = val.GetType()
if ty.GetTypeClass() != lldb.eTypeClassStruct:
return False

if ty.GetNumberOfFields() != 3:
return False

if ty.GetFieldAtIndex(0).GetName() != "ptr":
return False

if ty.GetFieldAtIndex(1).GetName() != "len":
return False

if ty.GetFieldAtIndex(2).GetName() != "cap":
return False

return ty.GetName().startswith("collections::vec::Vec<")


def print_array_of_values(array_name, data_ptr_val, length, internal_dict):
'''Prints a contigous memory range, interpreting it as values of the
pointee-type of data_ptr_val.'''

data_ptr_type = data_ptr_val.GetType()
assert data_ptr_type.IsPointerType()

element_type = data_ptr_type.GetPointeeType()
element_type_size = element_type.GetByteSize()

start_address = data_ptr_val.GetValueAsUnsigned()

def render_element(i):
address = start_address + i * element_type_size
element_val = data_ptr_val.CreateValueFromAddress(array_name + ("[%s]" % i),
address,
element_type)
return print_val(element_val, internal_dict)

return ', '.join([render_element(i) for i in range(length)])
1 change: 1 addition & 0 deletions src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ mod imp {
extern {}

extern {
#[allocator]
fn je_mallocx(size: size_t, flags: c_int) -> *mut c_void;
fn je_rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void;
fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

#![feature(no_std)]
#![no_std]
#![feature(allocator)]
#![feature(lang_items, unsafe_destructor)]
#![feature(box_syntax)]
#![feature(optin_builtin_traits)]
Expand Down
4 changes: 1 addition & 3 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ mod sip;
/// A hashable type.
///
/// The `H` type parameter is an abstract hash state that is used by the `Hash`
/// to compute the hash. Specific implementations of this trait may specialize
/// for particular instances of `H` in order to be able to optimize the hashing
/// behavior.
/// to compute the hash.
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Hash {
/// Feeds this value into the state given, updating the hasher as necessary.
Expand Down
29 changes: 16 additions & 13 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,34 @@
//! let my_speed_ptr: *mut i32 = &mut my_speed;
//! ```
//!
//! To get a pointer to a boxed value, dereference the box:
//!
//! ```
//! let my_num: Box<i32> = Box::new(10);
//! let my_num_ptr: *const i32 = &*my_num;
//! let mut my_speed: Box<i32> = Box::new(88);
//! let my_speed_ptr: *mut i32 = &mut *my_speed;
//! ```
//!
//! This does not take ownership of the original allocation
//! and requires no resource management later,
//! but you must not use the pointer after its lifetime.
//!
//! ## 2. Transmute an owned box (`Box<T>`).
//! ## 2. Consume a box (`Box<T>`).
//!
//! The `transmute` function takes, by value, whatever it's given
//! and returns it as whatever type is requested, as long as the
//! types are the same size. Because `Box<T>` and `*mut T` have the same
//! representation they can be trivially,
//! though unsafely, transformed from one type to the other.
//! The `into_raw` function consumes a box and returns
//! the raw pointer. It doesn't destroy `T` or deallocate any memory.
//!
//! ```
//! use std::mem;
//! use std::boxed;
//!
//! unsafe {
//! let my_num: Box<i32> = Box::new(10);
//! let my_num: *const i32 = mem::transmute(my_num);
//! let my_speed: Box<i32> = Box::new(88);
//! let my_speed: *mut i32 = mem::transmute(my_speed);
//! let my_speed: *mut i32 = boxed::into_raw(my_speed);
//!
//! // By taking ownership of the original `Box<T>` though
//! // we are obligated to transmute it back later to be destroyed.
//! drop(mem::transmute::<_, Box<i32>>(my_speed));
//! drop(mem::transmute::<_, Box<i32>>(my_num));
//! // we are obligated to put it together later to be destroyed.
//! drop(Box::from_raw(my_speed));
//! }
//! ```
//!
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,8 @@ pub fn is_defaulted_trait(cstore: &cstore::CStore, trait_def_id: ast::DefId) ->
let cdata = cstore.get_crate_data(trait_def_id.krate);
decoder::is_defaulted_trait(&*cdata, trait_def_id.node)
}

pub fn is_default_impl(cstore: &cstore::CStore, impl_did: ast::DefId) -> bool {
let cdata = cstore.get_crate_data(impl_did.krate);
decoder::is_default_impl(&*cdata, impl_did.node)
}
Loading