Commit Graph

1273 Commits

Author SHA1 Message Date
Daniel Micay
ab0a884a73 fix dropping non-primitive immediates
Closes #9446
2013-10-01 00:38:37 -04:00
Daniel Micay
11b7109b7b rm only use of type_is_immediate outside of trans 2013-09-30 18:16:35 -04:00
bors
5011bbfbb6 auto merge of #9630 : blake2-ppc/rust/de-at-smaller, r=huonw
This is mostly an incremental change, picking off some uses of
@- or @mut-pointers that can be replaced by references.

Almost all of the builder functions in trans::build are updated,
mostly using `&Block` arguments instead of `@mut Block`.
2013-09-30 10:41:20 -07:00
blake2-ppc
f4d8d8c122 trans::build: Change @mut Block to &Block or &mut Block
Use &mut Block and &Block references where possible in the builder
functions in trans::build.

@mut Block remains in a few functions where I could not (not yet at
least) track down the runtime borrowck failures.
2013-09-30 19:37:22 +02:00
blake2-ppc
b88517ec93 trans: Change @ast::Pat and @mut CrateContext in a few places
Use borrowed references in a few locations that were encountered when
working on other changes.
2013-09-30 19:37:17 +02:00
blake2-ppc
948b5ab87a trans: Change @ast::Expr -> &ast::Expr where possible 2013-09-30 19:37:17 +02:00
Alex Crichton
7b18976f08 Remove all usage of @ast::Crate 2013-09-29 16:21:25 -07:00
bors
10e7f12daf auto merge of #9550 : alexcrichton/rust/remove-printf, r=thestinger
The 0.8 release was cut, down with printf!
2013-09-27 08:21:23 -07:00
bors
01313a131b auto merge of #9548 : thestinger/rust/internal, r=alexcrichton
Closes #9494
2013-09-27 06:21:22 -07:00
bors
ae8a2ff379 auto merge of #9538 : thestinger/rust/type_use, r=pcwalton
This is broken, and results in poor performance due to the undefined
behaviour in the LLVM IR. LLVM's `mergefunc` is a *much* better way of
doing this since it merges based on the equality of the bytecode.

For example, consider `std::repr`. It generates different code per
type, but is not included in the type bounds of generics.

The `mergefunc` pass works for most of our code but currently hits an
assert on libstd. It is receiving attention upstream so it will be
ready soon, but I don't think removing this broken code should wait any
longer. I've opened #9536 about enabling it by default.

Closes #8651
Closes #3547
Closes #2537
Closes #6971
Closes #9222
2013-09-27 03:31:13 -07:00
Erick Tryzelaar
4834661c66 std and rustc: Convert users of c_str to use .with_c_str 2013-09-26 22:20:39 -07:00
Alex Crichton
409182de6d Update the compiler to not use printf/printfln 2013-09-26 17:05:59 -07:00
Daniel Micay
2aadd3652d mark globals as internal when not building a library
Closes #9494
2013-09-26 19:21:22 -04:00
Daniel Micay
c3e4e06841 remove type_use
This is broken, and results in poor performance due to the undefined
behaviour in the LLVM IR. LLVM's `mergefunc` is a *much* better way of
doing this since it merges based on the equality of the bytecode.

For example, consider `std::repr`. It generates different code per
type, but is not included in the type bounds of generics.

The `mergefunc` pass works for most of our code but currently hits an
assert on libstd. It is receiving attention upstream so it will be
ready soon, but I don't think removing this broken code should wait any
longer. I've opened #9536 about enabling it by default.

Closes #8651
Closes #3547
Closes #2537
Closes #6971
Closes #9222
2013-09-26 17:27:23 -04:00
Alex Crichton
daee1b4d5c Ensure that skipped items aren't encoded
If an item is skipped due to it being unreachable or for some optimization, then
it shouldn't be encoded into the metadata (because it wasn't present in the
first place).
2013-09-26 13:54:50 -07:00
bors
5375cf8718 auto merge of #9491 : thestinger/rust/noreturn, r=huonw
Closes #9317
2013-09-25 07:25:56 -07:00
bors
797a373cd1 auto merge of #9492 : pnkfelix/rust/fsk-syntax-visit-refactor-remainder, r=huonw
r? anyone

Part of #7081.

Removed many unnecessary context arguments, turning them into visitors.  Removed some @allocation.

If this lands, then I think the only thing left that is unaddressed are:
 * the various lint visitors, and
 * middle/privacy.rs, which has `impl<'self> Visitor<&'self method_map> for PrivacyVisitor`
2013-09-25 06:10:57 -07:00
Felix S. Klock II
9d0727736b Fold context into CalleeTranslationVisitor. 2013-09-25 10:59:06 +02:00
Felix S. Klock II
2ceebf1070 Fold context into TransItemVisitor. 2013-09-25 10:58:40 +02:00
Felix S. Klock II
411dce85ea Fold type_use.rs Context into its Visitor. 2013-09-25 10:55:50 +02:00
Daniel Micay
e76bfae7eb add noreturn attribute to functions returning !
Closes #9317
2013-09-25 04:45:29 -04:00
bors
4531184614 auto merge of #9432 : alexcrichton/rust/correct-item-visibility, r=pcwalton
This fixes private statics and functions from being usable cross-crates, along
with some bad privacy error messages. This is a reopening of #8365 with all the
privacy checks in privacy.rs instead of resolve.rs (where they should be
anyway).

These maps of exported items will hopefully get used for generating
documentation by rustdoc

Closes #8592
2013-09-25 00:55:53 -07:00
bors
d7bb40c50c auto merge of #9470 : luqmana/rust/bba, r=brson
#8431

~~@brson: do we need to bump up the cratemap version for this change?~~ Tis a no.
2013-09-24 20:25:58 -07:00
Luqman Aden
90e009f9b6 Remove the annihilate function from the crate map. Fixes #8431 2013-09-24 20:34:11 -04:00
Daniel Micay
5867bbd794 mark functions internal if not building a library
the entry point is wrapped with what should be the only public function
2013-09-24 18:50:28 -04:00
Alex Crichton
10a583ce1a Correctly encode item visibility in metadata
This fixes private statics and functions from being usable cross-crates, along
with some bad privacy error messages. This is a reopening of #8365 with all the
privacy checks in privacy.rs instead of resolve.rs (where they should be
anyway).

These maps of exported items will hopefully get used for generating
documentation by rustdoc

Closes #8592
2013-09-24 09:57:25 -07:00
Patrick Walton
3b1d3e5bf8 librustc: Fix merge fallout. 2013-09-23 18:23:23 -07:00
Patrick Walton
68ea9aed96 librustc: Remove @fn managed closures from the language. 2013-09-23 18:23:21 -07:00
Patrick Walton
7796d519f9 librustc: Don't use garbage-collected closures to store cleanups. 2013-09-23 18:23:19 -07:00
Patrick Walton
16e87cb527 librustc: Make the fall-through case in match not use garbage collected functions 2013-09-23 18:23:18 -07:00
bors
9705399504 auto merge of #9301 : luqmana/rust/ncm, r=brson
Get rid of the crate_map arg!

r? @brson
2013-09-23 15:46:05 -07:00
Luqman Aden
20a10ff9c9 Find the cratemap at runtime on windows. 2013-09-23 18:26:16 -04:00
bors
89cc8529cc auto merge of #9332 : eugals/rust/master, r=alexcrichton
It is intended to optimize/beautify the code generated in a few trivial trait operations.
Let's take the following code as an example:
```
trait Stuff {
    fn bar(&self);
}

fn callBar(s: &Stuff) {
    s.bar();
}

struct Foo;

impl Stuff for Foo {
    fn bar(&self) {
    }
}

pub fn main() {
    let o = Foo;
    callBar(&o as &Stuff);
}
```

At present it is translated into something like:
```
define void @_ZN7callBar_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }*, { %tydesc*, i8* }*) #4 {
"function top level":
  %__trait_callee = alloca { %tydesc*, i8* }
  %__auto_borrow_obj = alloca { %tydesc*, i8* }
  %2 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %3 = load %tydesc** %2
  %4 = getelementptr inbounds { %tydesc*, i8* }* %__auto_borrow_obj, i32 0, i32 0
  store %tydesc* %3, %tydesc** %4
  %5 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %6 = load i8** %5
  %7 = getelementptr inbounds { %tydesc*, i8* }* %__auto_borrow_obj, i32 0, i32 1
  store i8* %6, i8** %7
  %8 = bitcast { %tydesc*, i8* }* %__auto_borrow_obj to i8*
  %9 = bitcast { %tydesc*, i8* }* %__trait_callee to i8*
  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %9, i8* %8, i32 8, i32 4, i1 false)
  %10 = getelementptr inbounds { %tydesc*, i8* }* %__trait_callee, i32 0, i32 1
  %11 = load i8** %10
  %12 = bitcast i8* %11 to { i32, %tydesc*, i8*, i8*, i8 }*
  %13 = getelementptr inbounds { %tydesc*, i8* }* %__trait_callee, i32 0, i32 0
  %14 = bitcast %tydesc** %13 to [1 x i8*]**
  %15 = load [1 x i8*]** %14
  %16 = getelementptr inbounds [1 x i8*]* %15, i32 0, i32 1
  %17 = load i8** %16
  %18 = bitcast i8* %17 to void ({ i32, %tydesc*, i8*, i8*, i8 }*)*
  call void %18({ i32, %tydesc*, i8*, i8*, i8 }* %12)
  ret void
}

...

define void @_ZN4main_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }*) #4 {
"function top level":
  %o = alloca %struct.Foo
  %1 = alloca { %tydesc*, i8* }
  %__auto_borrow_obj = alloca { %tydesc*, i8* }
  %2 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %3 = bitcast i8** %2 to %struct.Foo**
  store %struct.Foo* %o, %struct.Foo** %3
  %4 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %5 = bitcast %tydesc** %4 to { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }**
  store { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }* @vtable1081, { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }** %5
  %6 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %7 = load %tydesc** %6
  %8 = getelementptr inbounds { %tydesc*, i8* }* %__auto_borrow_obj, i32 0, i32 0
  store %tydesc* %7, %tydesc** %8
  %9 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %10 = load i8** %9
  %11 = getelementptr inbounds { %tydesc*, i8* }* %__auto_borrow_obj, i32 0, i32 1
  store i8* %10, i8** %11
  call void @_ZN7callBar_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }* undef, { %tydesc*, i8* }* %__auto_borrow_obj)
  ret void
}
```

If you apply my patch, it would become way shorter and cleaner:
```
define void @_ZN7callBar_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }*, { %tydesc*, i8* }*) #4 {
"function top level":
  %2 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %3 = load i8** %2
  %4 = bitcast i8* %3 to { i32, %tydesc*, i8*, i8*, i8 }*
  %5 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %6 = bitcast %tydesc** %5 to [1 x i8*]**
  %7 = load [1 x i8*]** %6
  %8 = getelementptr inbounds [1 x i8*]* %7, i32 0, i32 1
  %9 = load i8** %8
  %10 = bitcast i8* %9 to void ({ i32, %tydesc*, i8*, i8*, i8 }*)*
  call void %10({ i32, %tydesc*, i8*, i8*, i8 }* %4)
  ret void
}

...

define void @_ZN4main_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }*) #4 {
"function top level":
  %o = alloca %struct.Foo
  %1 = alloca { %tydesc*, i8* }
  %2 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %3 = bitcast i8** %2 to %struct.Foo**
  store %struct.Foo* %o, %struct.Foo** %3
  %4 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %5 = bitcast %tydesc** %4 to { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }**
  store { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }* @vtable1081, { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }** %5
  call void @_ZN7callBar_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }* undef, { %tydesc*, i8* }* %1)
  ret void
}
```

Although this change doesn't increase the compilation speed much (I mentioned only about 1-2% boost on "rustc -O -Z time-passes syntax.rs"), but I still think it's a good thing to do as it greatly simplifies/clarifies LL generated in some cases which would definitely help in the future code generation investigations.

I don't provide any new test cases in this patch as it is merely an optimization.

Sorry guys, I somehow messed my previous PR and I don't see any better way to fix as to recreate it here.
2013-09-20 07:06:13 -07:00
U-NOV2010\eugals
0c3b6ad6b8 will not copy trait_callee on stack if it's source expr is a plain borrowed ref 2013-09-19 18:34:30 +04:00
U-NOV2010\eugals
dfa3f5fa8d minor Type::opaque_trait code cleanup 2013-09-19 18:34:26 +04:00
U-NOV2010\eugals
2927ab13df optimized trans_to_datum::auto_borrow_obj code generation in case some trivial cases where simple copying can be applied 2013-09-19 18:34:23 +04:00
Chris Morgan
e2807a4565 Replace unreachable() calls with unreachable!().
This is the second of two parts of #8991, now possible as a new snapshot
has been made. (The first part implemented the unreachable!() macro; it
was #8992, 6b7b8f2682.)

``std::util::unreachable()`` is removed summarily; any code which used
it should now use the ``unreachable!()`` macro.

Closes #9312.

Closes #8991.
2013-09-19 15:04:03 +10:00
bors
8f65529627 auto merge of #9284 : thestinger/rust/main, r=luqmana
the real entry point will now pass the user's main function directly to
the scheduler
2013-09-18 15:05:56 -07:00
Luqman Aden
133200a6e2 libstd/librustc: Make the crate_map a weak symbol that libstd links against. 2013-09-18 17:44:04 -04:00
Luqman Aden
9621156fc3 librustc/libstd: No longer pass crate_map to start. 2013-09-18 16:51:27 -04:00
Alex Crichton
817576ee70 Register new snapshots 2013-09-18 11:07:22 -07:00
bors
9e636f106d auto merge of #9272 : luqmana/rust/esln, r=catamorphism
Fixes #9270
2013-09-18 06:45:53 -07:00
Daniel Micay
c0cc37b963 remove useless rust_main wrapper
the real entry point will now pass the user's main function directly to
the scheduler
2013-09-18 00:57:48 -04:00
Luqman Aden
1ce657aa1f librustc: Respect #[link_name] on extern statics. Fixes #9270 2013-09-17 21:03:56 -04:00
Alex Crichton
9adcbac30d Prevent a rare linkage issue with an xcrate static
If a static is flagged as address_insignificant, then for LLVM to actually
perform the relevant optimization it must have an internal linkage type. What
this means, though, is that the static will not be available to other crates.
Hence, if you have a generic function with an inner static, it will fail to link
when built as a library because other crates will attempt to use the inner
static externally.

This gets around the issue by inlining the static into the metadata. The same
relevant optimization is then applied separately in the external crate. What
this ends up meaning is that all statics tagged with #[address_insignificant]
will appear at most once per crate (by value), but they could appear in multiple
crates.

This should be the last blocker for using format! ...
2013-09-17 11:24:05 -07:00
bors
29cdf58861 auto merge of #9244 : thestinger/rust/drop, r=catamorphism
This doesn't close any bugs as the goal is to convert the parameter to by-value, but this is a step towards being able to make guarantees about `&T` pointers (where T is Freeze) to LLVM.
2013-09-17 07:15:42 -07:00
bors
d1c05504ba auto merge of #9130 : alexcrichton/rust/inline-globals, r=thestinger
In #8185 cross-crate condition handlers were fixed by ensuring that globals
didn't start appearing in different crates with different addressed. An
unfortunate side effect of that pull request is that constants weren't inlined
across crates (uint::bits is unknown to everything but libstd).

This commit fixes this inlining by using the `available_eternally` linkage
provided by LLVM. It partially reverts #8185, and then adds support for this
linkage type. The main caveat is that not all statics could be inlined into
other crates. Before this patch, all statics were considered "inlineable items",
but an unfortunate side effect of how we deal with `&static` and `&[static]`
means that these two cases cannot be inlined across crates. The translation of
constants was modified to propogate this condition of whether a constant
should be considered inlineable into other crates.

Closes #9036
2013-09-16 23:45:49 -07:00
Daniel Micay
4e161a4d40 switch Drop to &mut self 2013-09-16 22:19:23 -04:00
Daniel Micay
1afaf0b308 set attributes on invoke instructions too
also removes the unused `FastInvoke` wrapper, as it's never actually
going to be used (we can't *partially* switch to `fastcc`, and this is
only used for Rust functions)
2013-09-16 18:30:59 -04:00
Daniel Micay
22b6f7481f document why attributes are set on CallInst 2013-09-16 13:44:04 -04:00