Skip to content

Commit 21f0fd7

Browse files
committed
---
yaml --- r: 95358 b: refs/heads/dist-snap c: 7bad416 h: refs/heads/master v: v3
1 parent 139419b commit 21f0fd7

File tree

8 files changed

+44
-132
lines changed

8 files changed

+44
-132
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 399a42575a3a5392277e4034812ce32c4f491929
9+
refs/heads/dist-snap: 7bad4167654ef846155bae7165fd0ffcc24fcbbe
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/lib/llvm.rs

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
use std::c_str::ToCStr;
1717
use std::hashmap::HashMap;
18-
use std::libc::{c_uint, c_ushort};
18+
use std::libc::{c_uint, c_ushort, c_void, free};
19+
use std::str::raw::from_c_str;
1920
use std::option;
2021

2122
use middle::trans::type_::Type;
@@ -1666,6 +1667,7 @@ pub mod llvm {
16661667
-> ValueRef;
16671668

16681669
pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1670+
pub fn LLVMTypeToString(Type: TypeRef) -> *c_char;
16691671

16701672
pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
16711673

@@ -1789,68 +1791,15 @@ impl TypeNames {
17891791
self.named_types.find_equiv(&s).map(|x| Type::from_ref(*x))
17901792
}
17911793

1792-
// We have a depth count, because we seem to make infinite types.
1793-
pub fn type_to_str_depth(&self, ty: Type, depth: int) -> ~str {
1794-
match self.find_name(&ty) {
1795-
option::Some(name) => return name.to_owned(),
1796-
None => ()
1797-
}
1798-
1799-
if depth == 0 {
1800-
return ~"###";
1801-
}
1802-
1794+
pub fn type_to_str(&self, ty: Type) -> ~str {
18031795
unsafe {
1804-
let kind = ty.kind();
1805-
1806-
match kind {
1807-
Void => ~"Void",
1808-
Half => ~"Half",
1809-
Float => ~"Float",
1810-
Double => ~"Double",
1811-
X86_FP80 => ~"X86_FP80",
1812-
FP128 => ~"FP128",
1813-
PPC_FP128 => ~"PPC_FP128",
1814-
Label => ~"Label",
1815-
Vector => ~"Vector",
1816-
Metadata => ~"Metadata",
1817-
X86_MMX => ~"X86_MMAX",
1818-
Integer => {
1819-
format!("i{}", llvm::LLVMGetIntTypeWidth(ty.to_ref()) as int)
1820-
}
1821-
Function => {
1822-
let out_ty = ty.return_type();
1823-
let args = ty.func_params();
1824-
let args =
1825-
args.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
1826-
let out_ty = self.type_to_str_depth(out_ty, depth-1);
1827-
format!("fn({}) -> {}", args, out_ty)
1828-
}
1829-
Struct => {
1830-
let tys = ty.field_types();
1831-
let tys = tys.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
1832-
format!("\\{{}\\}", tys)
1833-
}
1834-
Array => {
1835-
let el_ty = ty.element_type();
1836-
let el_ty = self.type_to_str_depth(el_ty, depth-1);
1837-
let len = ty.array_length();
1838-
format!("[{} x {}]", el_ty, len)
1839-
}
1840-
Pointer => {
1841-
let el_ty = ty.element_type();
1842-
let el_ty = self.type_to_str_depth(el_ty, depth-1);
1843-
format!("*{}", el_ty)
1844-
}
1845-
_ => fail2!("Unknown Type Kind ({})", kind as uint)
1846-
}
1796+
let s = llvm::LLVMTypeToString(ty.to_ref());
1797+
let ret = from_c_str(s);
1798+
free(s as *c_void);
1799+
ret
18471800
}
18481801
}
18491802

1850-
pub fn type_to_str(&self, ty: Type) -> ~str {
1851-
self.type_to_str_depth(ty, 30)
1852-
}
1853-
18541803
pub fn types_to_str(&self, tys: &[Type]) -> ~str {
18551804
let strs = tys.map(|t| self.type_to_str(*t));
18561805
format!("[{}]", strs.connect(","))

branches/dist-snap/src/librustpkg/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ impl RustcFlags {
210210
}
211211

212212
/// Returns true if any of the flags given are incompatible with the cmd
213-
pub fn flags_forbidden_for_cmd(flags: &RustcFlags,
213+
pub fn flags_ok_for_cmd(flags: &RustcFlags,
214214
cfgs: &[~str],
215215
cmd: &str, user_supplied_opt_level: bool) -> bool {
216216
let complain = |s| {
217-
println!("The {} option can only be used with the `build` command:
217+
println!("The {} option can only be used with the build command:
218218
rustpkg [options..] build {} [package-ID]", s, s);
219219
};
220220

branches/dist-snap/src/librustpkg/exit_codes.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,3 @@
99
// except according to those terms.
1010

1111
pub static COPY_FAILED_CODE: int = 65;
12-
pub static BAD_FLAG_CODE: int = 67;
13-
pub static NONEXISTENT_PACKAGE_CODE: int = 68;
14-

branches/dist-snap/src/librustpkg/rustpkg.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use package_source::PkgSrc;
5050
use target::{WhatToBuild, Everything, is_lib, is_main, is_test, is_bench, Tests};
5151
// use workcache_support::{discover_outputs, digest_only_date};
5252
use workcache_support::digest_only_date;
53-
use exit_codes::{COPY_FAILED_CODE, BAD_FLAG_CODE};
53+
use exit_codes::COPY_FAILED_CODE;
5454

5555
pub mod api;
5656
mod conditions;
@@ -701,7 +701,7 @@ pub fn main_args(args: &[~str]) -> int {
701701
return 1;
702702
}
703703
};
704-
let help = matches.opt_present("h") ||
704+
let mut help = matches.opt_present("h") ||
705705
matches.opt_present("help");
706706
let no_link = matches.opt_present("no-link");
707707
let no_trans = matches.opt_present("no-trans");
@@ -798,11 +798,8 @@ pub fn main_args(args: &[~str]) -> int {
798798
return 0;
799799
}
800800
Some(cmd) => {
801-
let bad_option = context::flags_forbidden_for_cmd(&rustc_flags,
802-
cfgs,
803-
*cmd,
804-
user_supplied_opt_level);
805-
if help || bad_option {
801+
help |= context::flags_ok_for_cmd(&rustc_flags, cfgs, *cmd, user_supplied_opt_level);
802+
if help {
806803
match *cmd {
807804
~"build" => usage::build(),
808805
~"clean" => usage::clean(),
@@ -817,12 +814,7 @@ pub fn main_args(args: &[~str]) -> int {
817814
~"unprefer" => usage::unprefer(),
818815
_ => usage::general()
819816
};
820-
if bad_option {
821-
return BAD_FLAG_CODE;
822-
}
823-
else {
824-
return 0;
825-
}
817+
return 0;
826818
} else {
827819
cmd
828820
}

branches/dist-snap/src/librustpkg/tests.rs

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use syntax::diagnostic;
3636
use target::*;
3737
use package_source::PkgSrc;
3838
use source_control::{CheckedOutSources, DirToUse, safe_git_clone};
39-
use exit_codes::{BAD_FLAG_CODE, COPY_FAILED_CODE};
4039
use util::datestamp;
4140

4241
fn fake_ctxt(sysroot: Path, workspace: &Path) -> BuildContext {
@@ -245,26 +244,14 @@ fn rustpkg_exec() -> Path {
245244
fn command_line_test(args: &[~str], cwd: &Path) -> ProcessOutput {
246245
match command_line_test_with_env(args, cwd, None) {
247246
Success(r) => r,
248-
Fail(error) => fail2!("Command line test failed with error {}", error)
247+
_ => fail2!("Command line test failed")
249248
}
250249
}
251250

252251
fn command_line_test_partial(args: &[~str], cwd: &Path) -> ProcessResult {
253252
command_line_test_with_env(args, cwd, None)
254253
}
255254

256-
fn command_line_test_expect_fail(args: &[~str],
257-
cwd: &Path,
258-
env: Option<~[(~str, ~str)]>,
259-
expected_exitcode: int) {
260-
match command_line_test_with_env(args, cwd, env) {
261-
Success(_) => fail2!("Should have failed with {}, but it succeeded", expected_exitcode),
262-
Fail(error) if error == expected_exitcode => (), // ok
263-
Fail(other) => fail2!("Expected to fail with {}, but failed with {} instead",
264-
expected_exitcode, other)
265-
}
266-
}
267-
268255
enum ProcessResult {
269256
Success(ProcessOutput),
270257
Fail(int) // exit code
@@ -1461,11 +1448,11 @@ fn compile_flag_fail() {
14611448
let p_id = PkgId::new("foo");
14621449
let workspace = create_local_package(&p_id);
14631450
let workspace = workspace.path();
1464-
command_line_test_expect_fail([test_sysroot().to_str(),
1451+
command_line_test([test_sysroot().to_str(),
14651452
~"install",
14661453
~"--no-link",
14671454
~"foo"],
1468-
workspace, None, BAD_FLAG_CODE);
1455+
workspace);
14691456
assert!(!built_executable_exists(workspace, "foo"));
14701457
assert!(!object_file_exists(workspace, "foo"));
14711458
}
@@ -1501,11 +1488,14 @@ fn notrans_flag_fail() {
15011488
let flags_to_test = [~"--no-trans", ~"--parse-only",
15021489
~"--pretty", ~"-S"];
15031490
for flag in flags_to_test.iter() {
1504-
command_line_test_expect_fail([test_sysroot().to_str(),
1491+
command_line_test([test_sysroot().to_str(),
15051492
~"install",
15061493
flag.clone(),
15071494
~"foo"],
1508-
workspace, None, BAD_FLAG_CODE);
1495+
workspace);
1496+
// Ideally we'd test that rustpkg actually fails, but
1497+
// since task failure doesn't set the exit code properly,
1498+
// we can't tell
15091499
assert!(!built_executable_exists(workspace, "foo"));
15101500
assert!(!object_file_exists(workspace, "foo"));
15111501
assert!(!lib_exists(workspace, &Path("foo"), NoVersion));
@@ -1532,11 +1522,11 @@ fn dash_S_fail() {
15321522
let p_id = PkgId::new("foo");
15331523
let workspace = create_local_package(&p_id);
15341524
let workspace = workspace.path();
1535-
command_line_test_expect_fail([test_sysroot().to_str(),
1525+
command_line_test([test_sysroot().to_str(),
15361526
~"install",
15371527
~"-S",
15381528
~"foo"],
1539-
workspace, None, BAD_FLAG_CODE);
1529+
workspace);
15401530
assert!(!built_executable_exists(workspace, "foo"));
15411531
assert!(!object_file_exists(workspace, "foo"));
15421532
assert!(!assembly_file_exists(workspace, "foo"));
@@ -1597,13 +1587,11 @@ fn test_emit_llvm_S_fail() {
15971587
let p_id = PkgId::new("foo");
15981588
let workspace = create_local_package(&p_id);
15991589
let workspace = workspace.path();
1600-
command_line_test_expect_fail([test_sysroot().to_str(),
1590+
command_line_test([test_sysroot().to_str(),
16011591
~"install",
16021592
~"-S", ~"--emit-llvm",
16031593
~"foo"],
1604-
workspace,
1605-
None,
1606-
BAD_FLAG_CODE);
1594+
workspace);
16071595
assert!(!built_executable_exists(workspace, "foo"));
16081596
assert!(!object_file_exists(workspace, "foo"));
16091597
assert!(!llvm_assembly_file_exists(workspace, "foo"));
@@ -1632,13 +1620,11 @@ fn test_emit_llvm_fail() {
16321620
let p_id = PkgId::new("foo");
16331621
let workspace = create_local_package(&p_id);
16341622
let workspace = workspace.path();
1635-
command_line_test_expect_fail([test_sysroot().to_str(),
1623+
command_line_test([test_sysroot().to_str(),
16361624
~"install",
16371625
~"--emit-llvm",
16381626
~"foo"],
1639-
workspace,
1640-
None,
1641-
BAD_FLAG_CODE);
1627+
workspace);
16421628
assert!(!built_executable_exists(workspace, "foo"));
16431629
assert!(!object_file_exists(workspace, "foo"));
16441630
assert!(!llvm_bitcode_file_exists(workspace, "foo"));
@@ -1679,10 +1665,11 @@ fn test_build_install_flags_fail() {
16791665
~[~"--target", host_triple()],
16801666
~[~"--target-cpu", ~"generic"],
16811667
~[~"-Z", ~"--time-passes"]];
1682-
let cwd = os::getcwd();
16831668
for flag in forbidden.iter() {
1684-
command_line_test_expect_fail([test_sysroot().to_str(),
1685-
~"list"] + *flag, &cwd, None, BAD_FLAG_CODE);
1669+
let output = command_line_test_output([test_sysroot().to_str(),
1670+
~"list"] + *flag);
1671+
assert!(output.len() > 1);
1672+
assert!(output[1].find_str("can only be used with").is_some());
16861673
}
16871674
}
16881675

@@ -1699,7 +1686,6 @@ fn test_optimized_build() {
16991686
assert!(built_executable_exists(workspace, "foo"));
17001687
}
17011688

1702-
#[test]
17031689
fn pkgid_pointing_to_subdir() {
17041690
// The actual repo is mocki.8713187.xyz/mozilla/some_repo
17051691
// rustpkg should recognize that and treat the part after some_repo/ as a subdir
@@ -1731,7 +1717,6 @@ fn pkgid_pointing_to_subdir() {
17311717
assert_executable_exists(workspace, "testpkg");
17321718
}
17331719
1734-
#[test]
17351720
fn test_recursive_deps() {
17361721
let a_id = PkgId::new("a");
17371722
let b_id = PkgId::new("b");
@@ -1777,7 +1762,6 @@ fn test_install_to_rust_path() {
17771762
assert!(!executable_exists(second_workspace, "foo"));
17781763
}
17791764
1780-
#[test]
17811765
fn test_target_specific_build_dir() {
17821766
let p_id = PkgId::new("foo");
17831767
let workspace = create_local_package(&p_id);
@@ -1886,9 +1870,8 @@ fn correct_package_name_with_rust_path_hack() {
18861870
let rust_path = Some(~[(~"RUST_PATH", format!("{}:{}", dest_workspace.to_str(),
18871871
foo_workspace.push_many(["src", "foo-0.1"]).to_str()))]);
18881872
// bar doesn't exist, but we want to make sure rustpkg doesn't think foo is bar
1889-
command_line_test_expect_fail([~"install", ~"--rust-path-hack", ~"bar"],
1890-
// FIXME #3408: Should be NONEXISTENT_PACKAGE_CODE
1891-
dest_workspace, rust_path, COPY_FAILED_CODE);
1873+
command_line_test_with_env([~"install", ~"--rust-path-hack", ~"bar"],
1874+
dest_workspace, rust_path);
18921875
assert!(!executable_exists(dest_workspace, "bar"));
18931876
assert!(!lib_exists(dest_workspace, &bar_id.path.clone(), bar_id.version.clone()));
18941877
assert!(!executable_exists(dest_workspace, "foo"));
@@ -2067,23 +2050,6 @@ fn test_7402() {
20672050
assert_executable_exists(dest_workspace, "foo");
20682051
}
20692052

2070-
#[test]
2071-
fn test_compile_error() {
2072-
let foo_id = PkgId::new("foo");
2073-
let foo_workspace = create_local_package(&foo_id);
2074-
let foo_workspace = foo_workspace.path();
2075-
let main_crate = foo_workspace.push_many(["src", "foo-0.1", "main.rs"]);
2076-
// Write something bogus
2077-
writeFile(&main_crate, "pub fn main() { if 42 != ~\"the answer\" { fail!(); } }");
2078-
let result = command_line_test_partial([~"build", ~"foo"], foo_workspace);
2079-
match result {
2080-
Success(*) => fail2!("Failed by succeeding!"), // should be a compile error
2081-
Fail(status) => {
2082-
debug2!("Failed with status {:?}... that's good, right?", status);
2083-
}
2084-
}
2085-
}
2086-
20872053
/// Returns true if p exists and is executable
20882054
fn is_executable(p: &Path) -> bool {
20892055
use std::libc::consts::os::posix88::{S_IXUSR};

branches/dist-snap/src/rustllvm/RustWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,10 @@ extern "C" void LLVMDICompositeTypeSetTypeArray(
803803
{
804804
unwrapDI<DICompositeType>(CompositeType).setTypeArray(unwrapDI<DIArray>(TypeArray));
805805
}
806+
807+
extern "C" char *LLVMTypeToString(LLVMTypeRef Type) {
808+
std::string s;
809+
llvm::raw_string_ostream os(s);
810+
unwrap<llvm::Type>(Type)->print(os);
811+
return strdup(os.str().data());
812+
}

branches/dist-snap/src/rustllvm/rustllvm.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,4 @@ LLVMRustSetNormalizedTarget
628628
LLVMRustAddAlwaysInlinePass
629629
LLVMAddReturnAttribute
630630
LLVMRemoveReturnAttribute
631+
LLVMTypeToString

0 commit comments

Comments
 (0)