Skip to content

Commit

Permalink
auto merge of #19242 : jakub-/rust/roll-up, r=jakub-
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Nov 23, 2014
2 parents 220b99b + d6b023a commit 4e52595
Show file tree
Hide file tree
Showing 56 changed files with 578 additions and 550 deletions.
29 changes: 14 additions & 15 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -546,22 +546,26 @@ CFG_TARGET=$(to_llvm_triple $CFG_TARGET)
# there's no rpath. This is where the build system itself puts libraries;
# --libdir is used to configure the installation directory.
# FIXME: This needs to parameterized over target triples. Do it in platform.mk
CFG_LIBDIR_RELATIVE=lib
if [ "$CFG_OSTYPE" = "pc-windows-gnu" ]
then
CFG_LIBDIR_RELATIVE=bin
CFG_LIBDIR="${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}"
else
valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries (ignored on windows platform)"
CFG_LIBDIR_RELATIVE=lib
fi

case "$CFG_LIBDIR" in
"$CFG_PREFIX"/*) CAT_INC=2;;
"$CFG_PREFIX"*) CAT_INC=1;;
*)
err "libdir must begin with the prefix. Use --prefix to set it accordingly.";;
esac
valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries (do not set it on windows platform)"

case "$CFG_LIBDIR" in
"$CFG_PREFIX"/*) CAT_INC=2;;
"$CFG_PREFIX"*) CAT_INC=1;;
*)
err "libdir must begin with the prefix. Use --prefix to set it accordingly.";;
esac

CFG_LIBDIR_RELATIVE=`echo ${CFG_LIBDIR} | cut -c$((${#CFG_PREFIX}+${CAT_INC}))-`
CFG_LIBDIR_RELATIVE=`echo ${CFG_LIBDIR} | cut -c$((${#CFG_PREFIX}+${CAT_INC}))-`

if [ "$CFG_OSTYPE" = "pc-windows-gnu" ] && [ "$CFG_LIBDIR_RELATIVE" != "bin" ]; then
err "libdir on windows should be set to 'bin'"
fi

if [ $HELP -eq 1 ]
Expand Down Expand Up @@ -711,11 +715,6 @@ then
fi
step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
putvar CFG_LOCAL_RUST_ROOT
else
if [ ! -z "$CFG_LOCAL_RUST_ROOT" ]
then
warn "Use of --local-rust-root without --enable-local-rust"
fi
fi

# Force freebsd to build with clang; gcc doesn't like us there
Expand Down
7 changes: 5 additions & 2 deletions mk/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,14 @@ endif
# Target-and-rule "utility variables"
######################################################################

define DEF_X
define DEF_FOR_TARGET
X_$(1) := $(CFG_EXE_SUFFIX_$(1))
ifndef CFG_LLVM_TARGET_$(1)
CFG_LLVM_TARGET_$(1) := $(1)
endif
endef
$(foreach target,$(CFG_TARGET), \
$(eval $(call DEF_X,$(target))))
$(eval $(call DEF_FOR_TARGET,$(target))))

# "Source" files we generate in builddir along the way.
GENERATED :=
Expand Down
2 changes: 1 addition & 1 deletion mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.ll $$(MKFILE_DEPS) \
@mkdir -p $$(@D)
@$$(call E, compile: $$@)
$$(Q)$$(LLC_$$(CFG_BUILD)) $$(CFG_LLC_FLAGS_$(1)) \
-filetype=obj -mtriple=$(1) -relocation-model=pic -o $$@ $$<
-filetype=obj -mtriple=$$(CFG_LLVM_TARGET_$(1)) -relocation-model=pic -o $$@ $$<

$$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.c $$(MKFILE_DEPS)
@mkdir -p $$(@D)
Expand Down
2 changes: 1 addition & 1 deletion mk/stage0.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ifdef CFG_ENABLE_LOCAL_RUST
else
$(Q)$(CFG_PYTHON) $(S)src/etc/get-snapshot.py $(CFG_BUILD) $(SNAPSHOT_FILE)
endif
$(Q)touch $@
$(Q)if [ -e "$@" ]; then touch "$@"; else echo "ERROR: snapshot $@ not found"; exit 1; fi

# For other targets, let the host build the target:

Expand Down
2 changes: 1 addition & 1 deletion mk/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
$$(foreach dep,$$(TOOL_DEPS_$(4)), \
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
| $$(TBIN$(1)_T_$(4)_H_$(3))/
| $$(TBIN$(1)_T_$(2)_H_$(3))/
@$$(call E, rustc: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg $(4)

Expand Down
3 changes: 2 additions & 1 deletion src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::ascii::AsciiExt;
use std::io::{BufferedReader, File};
use regex::Regex;

Expand All @@ -31,7 +32,7 @@ pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
fn parse_expected(line_num: uint, line: &str, re: &Regex) -> Option<ExpectedError> {
re.captures(line).and_then(|caps| {
let adjusts = caps.name("adjusts").len();
let kind = caps.name("kind").to_ascii().to_lowercase().into_string();
let kind = caps.name("kind").to_ascii_lower();
let msg = caps.name("msg").trim().to_string();

debug!("line={} kind={} msg={}", line_num, kind, msg);
Expand Down
15 changes: 8 additions & 7 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[cfg(not(stage0))]

use self::TargetLocation::*;

use common::Config;
Expand Down Expand Up @@ -990,7 +990,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
let i = s.chars();
let c : Vec<char> = i.map( |c| {
if c.is_ascii() {
c.to_ascii().to_lowercase().to_char()
c.to_ascii().to_lowercase().as_char()
} else {
c
}
Expand Down Expand Up @@ -1161,7 +1161,7 @@ fn compile_test_(config: &Config, props: &TestProps,
let args = make_compile_args(config,
props,
link_args,
|a, b| ThisFile(make_exe_name(a, b)), testfile);
|a, b| TargetLocation::ThisFile(make_exe_name(a, b)), testfile);
compose_and_run_compiler(config, props, testfile, args, None)
}

Expand Down Expand Up @@ -1219,7 +1219,7 @@ fn compose_and_run_compiler(
crate_type,
|a,b| {
let f = make_lib_name(a, b, testfile);
ThisDirectory(f.dir_path())
TargetLocation::ThisDirectory(f.dir_path())
},
&abs_ab);
let auxres = compose_and_run(config,
Expand Down Expand Up @@ -1296,11 +1296,11 @@ fn make_compile_args(config: &Config,
args.push("prefer-dynamic".to_string());
}
let path = match xform_file {
ThisFile(path) => {
TargetLocation::ThisFile(path) => {
args.push("-o".to_string());
path
}
ThisDirectory(path) => {
TargetLocation::ThisDirectory(path) => {
args.push("--out-dir".to_string());
path
}
Expand Down Expand Up @@ -1672,7 +1672,8 @@ fn compile_test_and_save_bitcode(config: &Config, props: &TestProps,
let args = make_compile_args(config,
props,
link_args,
|a, b| ThisDirectory(output_base_name(a, b).dir_path()),
|a, b| TargetLocation::ThisDirectory(
output_base_name(a, b).dir_path()),
testfile);
compose_and_run_compiler(config, props, testfile, args, None)
}
Expand Down
2 changes: 0 additions & 2 deletions src/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![no_start]

#[cfg(rustdoc)]
extern crate "rustdoc" as this;

Expand Down
52 changes: 21 additions & 31 deletions src/etc/lldb_rust_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def print_struct_val(val, internal_dict):
return print_struct_val_starting_from(0, val, internal_dict)

def print_vec_slice_val(val, internal_dict):
output = "&["

length = val.GetChildAtIndex(1).GetValueAsUnsigned()

data_ptr_val = val.GetChildAtIndex(0)
Expand All @@ -56,16 +54,12 @@ def print_vec_slice_val(val, internal_dict):

start_address = data_ptr_val.GetValueAsUnsigned()

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

if i != length - 1:
output += ", "
element_val = val.CreateValueFromAddress( val.GetName() + ("[%s]" % i), address, element_type)
return print_val(element_val, internal_dict)

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

def print_struct_val_starting_from(field_start_index, val, internal_dict):
'''
Expand All @@ -77,39 +71,33 @@ def print_struct_val_starting_from(field_start_index, val, internal_dict):
t = val.GetType()
has_field_names = type_has_field_names(t)
type_name = extract_type_name(t.GetName())
output = ""

if not type_name.startswith("("):
# this is a tuple, so don't print the type name
output += type_name

if has_field_names:
output += " { \n"
template = "%(type_name)s {\n%(body)s\n}"
separator = ", \n"
else:
output += "("
template = "%(type_name)s(%(body)s)"
separator = ", "

if type_name.startswith("("):
# this is a tuple, so don't print the type name
type_name = ""

num_children = val.num_children

for child_index in range(field_start_index, num_children):
def render_child(child_index):
this = ""
if has_field_names:
field_name = t.GetFieldAtIndex(child_index).GetName()
output += field_name + ": "
this += field_name + ": "

field_val = val.GetChildAtIndex(child_index)
output += print_val(field_val, internal_dict)
return this + print_val(field_val, internal_dict)

if child_index != num_children - 1:
output += ", "

if has_field_names:
output += "\n"

if has_field_names:
output += "}"
else:
output += ")"
body = separator.join([render_child(idx) for idx in range(field_start_index, num_children)])

return output
return template % {"type_name": type_name,
"body": body}


def print_enum_val(val, internal_dict):
Expand Down Expand Up @@ -243,3 +231,5 @@ def is_vec_slice(val):

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

# vi: sw=2:ts=2
55 changes: 54 additions & 1 deletion src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ impl<T> Arc<T> {
}
}

/// Get the number of weak references to this value.
#[inline]
#[experimental]
pub fn weak_count<T>(this: &Arc<T>) -> uint { this.inner().weak.load(atomic::SeqCst) - 1 }

/// Get the number of strong references to this value.
#[inline]
#[experimental]
pub fn strong_count<T>(this: &Arc<T>) -> uint { this.inner().strong.load(atomic::SeqCst) }

#[unstable = "waiting on stability of Clone"]
impl<T> Clone for Arc<T> {
/// Duplicate an atomically reference counted wrapper.
Expand Down Expand Up @@ -321,7 +331,7 @@ mod tests {
use std::sync::atomic;
use std::task;
use std::vec::Vec;
use super::{Arc, Weak};
use super::{Arc, Weak, weak_count, strong_count};
use std::sync::Mutex;

struct Canary(*mut atomic::AtomicUint);
Expand Down Expand Up @@ -465,6 +475,49 @@ mod tests {
drop(arc_weak);
}

#[test]
fn test_strong_count() {
let a = Arc::new(0u32);
assert!(strong_count(&a) == 1);
let w = a.downgrade();
assert!(strong_count(&a) == 1);
let b = w.upgrade().expect("");
assert!(strong_count(&b) == 2);
assert!(strong_count(&a) == 2);
drop(w);
drop(a);
assert!(strong_count(&b) == 1);
let c = b.clone();
assert!(strong_count(&b) == 2);
assert!(strong_count(&c) == 2);
}

#[test]
fn test_weak_count() {
let a = Arc::new(0u32);
assert!(strong_count(&a) == 1);
assert!(weak_count(&a) == 0);
let w = a.downgrade();
assert!(strong_count(&a) == 1);
assert!(weak_count(&a) == 1);
let x = w.clone();
assert!(weak_count(&a) == 2);
drop(w);
drop(x);
assert!(strong_count(&a) == 1);
assert!(weak_count(&a) == 0);
let c = a.clone();
assert!(strong_count(&a) == 2);
assert!(weak_count(&a) == 0);
let d = c.downgrade();
assert!(weak_count(&c) == 1);
assert!(strong_count(&c) == 2);

drop(a);
drop(c);
drop(d);
}

#[test]
fn show_arc() {
let a = Arc::new(5u32);
Expand Down
10 changes: 3 additions & 7 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use core::clone::Clone;
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
use core::default::Default;
use core::fmt;
use core::intrinsics;
use core::kinds::Sized;
use core::mem;
use core::option::Option;
Expand Down Expand Up @@ -104,17 +103,14 @@ pub trait BoxAny {
}

#[stable]
impl BoxAny for Box<Any+'static> {
impl BoxAny for Box<Any> {
#[inline]
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any+'static>> {
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
if self.is::<T>() {
unsafe {
// Get the raw representation of the trait object
let to: TraitObject =
*mem::transmute::<&Box<Any>, &TraitObject>(&self);

// Prevent destructor on self being run
intrinsics::forget(self);
mem::transmute::<Box<Any>, TraitObject>(self);

// Extract the data pointer
Ok(mem::transmute(to.data))
Expand Down
Loading

0 comments on commit 4e52595

Please sign in to comment.