Commit Graph

128 Commits

Author SHA1 Message Date
whitequark 42754ce710 Add profiling support, through the rustc -Z profile flag.
When -Z profile is passed, the GCDAProfiling LLVM pass is added
to the pipeline, which uses debug information to instrument the IR.
After compiling with -Z profile, the $(OUT_DIR)/$(CRATE_NAME).gcno
file is created, containing initial profiling information.
After running the program built, the $(OUT_DIR)/$(CRATE_NAME).gcda
file is created, containing branch counters.

The created *.gcno and *.gcda files can be processed using
the "llvm-cov gcov" and "lcov" tools. The profiling data LLVM
generates does not faithfully follow the GCC's format for *.gcno
and *.gcda files, and so it will probably not work with other tools
(such as gcov itself) that consume these files.
2017-05-01 09:16:20 +00:00
kennytm 00dff0aa59
Support AddressSanitizer and ThreadSanitizer on x86_64-apple-darwin.
ASan and TSan are supported on macOS, and this commit enables their
support.

The sanitizers are always built as *.dylib on Apple platforms, so they
cannot be statically linked into the corresponding `rustc_?san.rlib`. The
dylibs are directly copied to `lib/rustlib/x86_64-apple-darwin/lib/`
instead.

Note, although Xcode also ships with their own copies of ASan/TSan dylibs,
we cannot use them due to version mismatch.

There is a caveat: the sanitizer libraries are linked as @rpath, so the
user needs to additionally pass `-C rpath`:

    rustc -Z sanitizer=address -C rpath file.rs
                               ^~~~~~~~

Otherwise there will be a runtime error:

    dyld: Library not loaded: @rpath/libclang_rt.asan_osx_dynamic.dylib
      Referenced from: /path/to/executable
      Reason: image not found
    Abort trap: 6

The next commit includes a temporary change in compiler to force the linker
to emit a usable @rpath.
2017-04-25 10:31:01 +08:00
Ariel Ben-Yehuda ece6c8434b cache attributes of items from foreign crates
this avoids parsing item attributes on each call to `item_attrs`, which takes
off 33% (!) of translation time and 50% (!) of trans-item collection time.
2017-04-22 21:00:50 +03:00
Niko Matsakis f227187cb8 remove `LinkMeta` from `SharedCrateContext`
A number of things were using `crate_hash` that really ought to be using
`crate_disambiguator` (e.g., to create the plugin symbol names). They
have been updated.

It is important to remove `LinkMeta` from `SharedCrateContext` since it
contains a hash of the entire crate, and hence it will change
whenever **anything** changes (which would then require
rebuilding **everything**).
2017-04-13 18:37:47 -04:00
Oliver Schneider eb447f4ef4
Fix various useless derefs and slicings 2017-03-27 08:58:00 +02:00
Alex Crichton e341d603fe Remove internal liblog
This commit deletes the internal liblog in favor of the implementation that
lives on crates.io. Similarly it's also setting a convention for adding crates
to the compiler. The main restriction right now is that we want compiler
implementation details to be unreachable from normal Rust code (e.g. requires a
feature), and by default everything in the sysroot is reachable via `extern
crate`.

The proposal here is to require that crates pulled in have these lines in their
`src/lib.rs`:

    #![cfg_attr(rustbuild, feature(staged_api, rustc_private))]
    #![cfg_attr(rustbuild, unstable(feature = "rustc_private", issue = "27812"))]

This'll mean that by default they're not using these attributes but when
compiled as part of the compiler they do a few things:

* Mark themselves as entirely unstable via the `staged_api` feature and the
  `#![unstable]` attribute.
* Allow usage of other unstable crates via `feature(rustc_private)` which is
  required if the crate relies on any other crates to compile (other than std).
2017-03-23 11:28:00 -07:00
Austin Bonander a906d9912b
Correctly get source for metadata crate type;
replace `unwrap()` with `expect()`
2017-03-21 16:34:56 -04:00
bors 9c15de4fd5 Auto merge of #40346 - jseyfried:path_and_tokenstream_attr, r=nrc
`TokenStream`-based attributes, paths in attribute and derive macro invocations

This PR
 - refactors `Attribute` to use  `Path` and `TokenStream` instead of `MetaItem`.
 - supports macro invocation paths for attribute procedural macros.
   - e.g. `#[::foo::attr_macro] struct S;`, `#[cfg_attr(all(), foo::attr_macro)] struct S;`
 - supports macro invocation paths for derive procedural macros.
   - e.g. `#[derive(foo::Bar, super::Baz)] struct S;`
 - supports arbitrary tokens as arguments to attribute procedural macros.
   - e.g. `#[foo::attr_macro arbitrary + tokens] struct S;`
 - supports using arbitrary tokens in "inert attributes" with derive procedural macros.
   - e.g. `#[derive(Foo)] struct S(#[inert arbitrary + tokens] i32);`
where `#[proc_macro_derive(Foo, attributes(inert))]`

r? @nrc
2017-03-19 10:56:08 +00:00
Jeffrey Seyfried 68c1cc68b4 Refactor `Attribute` to use `Path` and `TokenStream` instead of `MetaItem`. 2017-03-14 04:03:43 +00:00
Corey Farwell 97a1b6a055 Update usages of 'OSX' (and other old names) to 'macOS'.
As of last year with version 'Sierra', the Mac operating system is now
called 'macOS'.
2017-03-12 14:59:04 -04:00
Austin Bonander 2fcbb48c72 Implement function-like procedural macros ( `#[proc_macro]`) 2017-02-28 18:34:22 -08:00
Peter Wagenet ae32b6eafd Better handling of lib defaults 2017-02-23 09:36:33 -08:00
Jeffrey Seyfried 2cc61eebb7 Allow using inert attributes from `proc_macro_derive`s with `#![feature(proc_macro)]`. 2017-02-12 07:20:04 +00:00
Jorge Aparicio 9af6aa3889 sanitizer support 2017-02-08 18:51:43 -05:00
Corey Farwell 805a99e6cb Rollup merge of #39442 - keeperofdakeys:expand-derives, r=jseyfried
Expand derive macros in the MacroExpander

This removes the expand_derives function, and sprinkles the functionality throughout the Invocation Collector, Expander and Resolver.

Fixes https://github.com/rust-lang/rust/issues/39326

r? @jseyfried
2017-02-05 09:14:46 -05:00
Josh Driver 0a7380d7fc Rename CustomDerive to ProcMacroDerive for macros 1.1 2017-02-05 09:31:02 +10:30
bors ea7a6486a2 Auto merge of #38426 - vadimcn:nobundle, r=alexcrichton
Implement kind="static-nobundle" (RFC 1717)

This implements the "static-nobundle" library kind (last item from #37403).

Rustc handles "static-nobundle" libs very similarly to dylibs, except that on Windows, uses of their symbols do not get marked with "dllimport".  Which is the whole point of this feature.
2017-02-04 21:13:07 +00:00
Vadim Chugunov 7504897e6b Don't link "nobundle" libs which had already been included in upstream crate. 2017-02-03 18:25:45 -08:00
Vadim Chugunov 3ae2174fc5 Feature gate 2017-01-19 13:53:33 -08:00
Vadim Chugunov 91f8144906 Implement the "static-nobundle" library kind (RFC 1717).
These are static libraries that are not bundled (as the name implies) into rlibs and staticlibs that rustc generates,
and must be present when the final binary artifact is being linked.
2017-01-19 13:52:38 -08:00
Austin Bonander 375cbd20cf Implement `#[proc_macro_attribute]`
* Add support for `#[proc_macro]`

* Reactivate `proc_macro` feature and gate `#[proc_macro_attribute]` under it

* Have `#![feature(proc_macro)]` imply `#![feature(use_extern_macros)]`,
error on legacy import of proc macros via `#[macro_use]`
2017-01-16 22:41:22 -08:00
Michael Woerister 02c7b117da metadata: Add is_exported_symbol() method to CrateStore. 2017-01-09 10:06:58 -05:00
Nick Cameron 7720cf02e3 Change --crate-type metadata to --emit=metadata 2016-12-29 13:24:45 +13:00
Michael Woerister e0d26294cd definitions: Add some timing stats for DefPathTable decoding. 2016-12-16 19:14:16 -05:00
Michael Woerister ed5a88e3d0 definitions: Store DefPath data in separate table in metadata 2016-12-16 19:14:16 -05:00
Vadim Chugunov 7d05d1e7f0 Consider only libs that aren't excluded by #[link(cfg=...)] 2016-12-05 16:44:27 -08:00
Vadim Chugunov 923034ffd2 Rename _all_ library instances. 2016-12-02 17:51:54 -08:00
Vadim Chugunov a23c470433 Tighten up error checking of library renames. 2016-12-01 16:56:49 -08:00
Vadim Chugunov a9a6f8c8ed Remove the "linked_from" feature. 2016-12-01 16:56:49 -08:00
Vadim Chugunov 13477c77bf Implement native library kind and name overrides from the command line. 2016-12-01 16:22:04 -08:00
Vadim Chugunov bc019dfb39 Emit 'dllimport' attribute for dylib foreign items on Windows. 2016-12-01 16:22:04 -08:00
Jeffrey Seyfried 1fd9041b82 Avoid loading needless proc-macro dependencies. 2016-11-28 03:37:02 +00:00
Paul Lietar 2cdde5aef4 Delay error reporting of filename mismatch.
When cross compiling with procedural macros, the crate loader starts by
looking for a target crate, before trying with a host crate.

Rather than emitting an error immediately if the host and target
extension differ, the compiler should delay it until both attempts have
failed.

Fixes #37899

r? @jseyfried
2016-11-24 22:26:35 +00:00
bors 5196ca8518 Auto merge of #37681 - nrc:crate-metadata, r=@alexcrichton
add --crate-type metadata

r? @alexcrichton
2016-11-22 21:54:10 -06:00
Nick Cameron af1b19555c Rebasing and review changes 2016-11-23 12:50:39 +13:00
bors ebec55406b Auto merge of #37824 - jseyfried:symbols, r=eddyb
Clean up `ast::Attribute`, `ast::CrateConfig`, and string interning

This PR
 - removes `ast::Attribute_` (changing `Attribute` from `Spanned<Attribute_>` to a struct),
 - moves a `MetaItem`'s name from the `MetaItemKind` variants to a field of `MetaItem`,
 - avoids needlessly wrapping `ast::MetaItem` with `P`,
 - moves string interning into `syntax::symbol` (`ast::Name` is a reexport of `symbol::Symbol` for now),
 - replaces `InternedString` with `Symbol` in the AST, HIR, and various other places, and
 - refactors `ast::CrateConfig` from a `Vec` to a `HashSet`.

r? @eddyb
2016-11-21 08:08:47 -06:00
Jeffrey Seyfried e85a0d70b8 Use `Symbol` instead of `InternedString` in the AST, HIR, and various other places. 2016-11-21 09:00:55 +00:00
Jeffrey Seyfried d2f8fb0a0a Move `syntax::util::interner` -> `syntax::symbol`, cleanup. 2016-11-20 23:40:20 +00:00
Nick Cameron 534556a445 Read in rmeta crates 2016-11-21 07:10:12 +13:00
Nick Cameron b286a2f081 Add --crate-type metadata
With the same semantics as -Zno-trans
2016-11-21 07:08:35 +13:00
Jeffrey Seyfried 95ee919a2d Fix bug in proc-macro dependencies. 2016-11-20 13:48:03 +00:00
Jeffrey Seyfried a2626410d7 Refactor `MetaItemKind` to use `Name`s instead of `InternedString`s. 2016-11-20 11:46:06 +00:00
Jeffrey Seyfried 04886f2c98 Fix bug in loading proc macro dependencies. 2016-11-18 00:03:10 +00:00
Alex Crichton 06242ff15d rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.

[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md

This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.

Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.

Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.

Essentially, what'll happen is:

* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
  linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
  linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
  are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
  are used and `-lc` is not passed.

This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.

cc #37406
2016-11-16 07:00:09 -08:00
Jeffrey Seyfried 0a998b86e9 Support `#[macro_reexport]`ing custom derives. 2016-11-10 11:19:34 +00:00
Jeffrey Seyfried 872943c317 Improve macro reexports. 2016-11-10 10:04:24 +00:00
Jeffrey Seyfried dd0781ea25 Register and stability check `#[no_link]` crates. 2016-11-10 09:21:29 +00:00
Jeffrey Seyfried a1d45d94b0 Refactor `explicitly_linked: bool` -> `dep_kind: DepKind`. 2016-11-10 09:21:04 +00:00
Jeffrey Seyfried c102d7fb68 Clean up `CrateSource`. 2016-11-10 09:20:59 +00:00
Eduard-Mihai Burtescu 5ebd7c50a0 Rollup merge of #37614 - keeperofdakeys:proc_macro, r=jseyfried
macros 1.1: Allow proc_macro functions to declare attributes to be mark as used

This PR allows proc macro functions to declare attribute names that should be marked as used when attached to the deriving item. There are a few questions for this PR.

- Currently this uses a separate attribute named `#[proc_macro_attributes(..)]`, is this the best choice?
- In order to make this work, the `check_attribute` function had to be modified to not error on attributes marked as used. This is a pretty large change in semantics, is there a better way to do this?
- I've got a few clones where I don't know if I need them (like turning `item` into a `TokenStream`), can these be avoided?
- Is switching to `MultiItemDecorator` the right thing here?

Also fixes https://github.com/rust-lang/rust/issues/37563.
2016-11-09 20:51:18 +02:00