Commit graph

299 commits

Author SHA1 Message Date
Dylan DPC
55cfcd596f
Rollup merge of #80323 - camelid:codegen-base-docs, r=nagisa
Update and improve `rustc_codegen_{llvm,ssa}` docs

Fixes #75342.

These docs were very out of date and misleading. They even said that
they codegen'd the *AST*!

For some reason, the `rustc_codegen_ssa::base` docs were exactly
identical to the `rustc_codegen_llvm::base` docs. They didn't really
make sense, because they had LLVM-specific information even though
`rustc_codegen_ssa` is supposed to be somewhat generic. So I removed
them as they were misleading.

r? ``@pnkfelix`` maybe?
2020-12-31 22:20:43 +01:00
Mara Bos
9e8edc8c22
Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkov
Rename kw::Invalid -> kw::Empty

See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471
for context.

r? `@petrochenkov`
2020-12-30 20:56:58 +00:00
Joshua Nelson
edeac1778c Rename kw::Invalid -> kw::Empty
See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471
for context.
2020-12-30 09:50:02 -05:00
Yuki Okushi
41fa0dba27
Rollup merge of #80509 - matthiaskrgr:ptr_arg, r=varkor
where possible, pass slices instead of &Vec or &String (clippy::ptr_arg)
2020-12-30 22:49:26 +09:00
Matthias Krüger
bdc9291ed9 where possible, pass slices instead of &Vec or &String (clippy::ptr_arg) 2020-12-30 13:11:52 +01:00
Matthias Krüger
17a8c1017f don't clone copy types 2020-12-29 19:40:03 +01:00
Dylan DPC
c51172f38a
Rollup merge of #80344 - matthiaskrgr:matches, r=Dylan-DPC
use matches!() macro in more places
2020-12-28 14:13:12 +01:00
Dylan DPC
98d80bda01
Rollup merge of #79662 - bjorn3:move_more_code_out_of_codegen_backend, r=oli-obk
Move some more code out of CodegenBackend::{codegen_crate,link}

Kind of a follow up to #77795
2020-12-28 14:12:59 +01:00
Matthias Krüger
d12a358673 use matches!() macro in more places 2020-12-24 13:35:12 +01:00
Camelid
5b32ab671a Update and improve rustc_codegen_{llvm,ssa} docs
These docs were very out of date and misleading. They even said that
they codegen'd the *AST*!

For some reason, the `rustc_codegen_ssa::base` docs were exactly
identical to the `rustc_codegen_llvm::base` docs. They didn't really
make sense, because they had LLVM-specific information even though
`rustc_codegen_ssa` is supposed to be somewhat generic. So I removed
them as they were misleading.
2020-12-22 19:42:23 -08:00
Victor Ding
732afd41cf Exclude unnecessary info from CodegenResults
`foreign_module` and `wasm_import_module` are not needed for linking,
and hence can be removed from CodegenResults.
2020-12-23 12:51:10 +11:00
Shaheen Gandhi
8553aeeb66 Use -target when linking binaries for Mac Catalyst 2020-12-19 19:32:37 -08:00
Tomasz Miąsko
4ad53dc9f5 Use pointer type in AtomicPtr::swap implementation 2020-12-20 00:00:00 +00:00
Julian Orth
be1511408e Optimize DST field access
For

    struct X<T: ?Sized>(T)
    struct Y<T: ?Sized>(u8, T)

the offset of the unsized field is

    0
    mem::align_of_val(&self.1)

respectively. This patch changes the expression used to compute these
offsets so that the optimizer can perform this optimization.

Consider

```rust
fn test(x: &X<dyn Any>) -> &dyn Any {
    &x.0
}
```

Before:

```asm
test:
	movq	%rsi, %rdx
	movq	16(%rsi), %rax
	leaq	-1(%rax), %rcx
	negq	%rax
	andq	%rcx, %rax
	addq	%rdi, %rax
	retq
```

After:

```asm
test:
	movq	%rsi, %rdx
	movq	%rdi, %rax
	retq
```
2020-12-19 20:43:15 +01:00
Guillaume Gomez
1f5d8de062
Rollup merge of #80040 - tmiasko:always-lower-intrinsics, r=Dylan-DPC
Always run intrinsics lowering pass

Move intrinsics lowering pass from the optimization phase (where it
would not run if -Zmir-opt-level=0), to the drop lowering phase where it
runs unconditionally.

The implementation of those intrinsics in code generation and
interpreter is unnecessary. Remove it.
2020-12-17 11:36:52 +01:00
bjorn3
2c0dccb7f2 Move some code out of CodegenBackend::{codegen_crate,link} 2020-12-17 10:02:06 +01:00
David Wood
99ad915e32
compiletest: add split dwarf compare mode
This commit adds a Split DWARF compare mode to compiletest so that
debuginfo tests are also tested using Split DWARF in split mode (and
manually in single mode).

Signed-off-by: David Wood <david@davidtw.co>
2020-12-16 10:33:51 +00:00
David Wood
e3fdae9d81
cg_llvm: implement split dwarf support
This commit implements Split DWARF support, wiring up the flag (added in
earlier commits) to the modified FFI wrapper (also from earlier
commits).

Signed-off-by: David Wood <david@davidtw.co>
2020-12-16 10:33:47 +00:00
David Wood
6890312ea3
cg_ssa: introduce TargetMachineFactoryFn alias
This commit removes the `TargetMachineFactory` struct and adds a
`TargetMachineFactoryFn` type alias which is used everywhere that the
previous, long type was used.

Signed-off-by: David Wood <david@davidtw.co>
2020-12-16 10:33:43 +00:00
David Wood
cf49c2a1ef
cg_ssa: correct documentation comments
This commit changes some comments to documentation comments so that
they can be read on the generated rustdoc.

Signed-off-by: David Wood <david@davidtw.co>
2020-12-16 10:33:42 +00:00
bors
e99a89c7c0 Auto merge of #73210 - wesleywiser:consts_in_debuginfo, r=oli-obk
[mir-opt] Allow debuginfo to be generated for a constant or a Place

Prior to this commit, debuginfo was always generated by mapping a name
to a Place. This has the side-effect that `SimplifyLocals` cannot remove
locals that are only used for debuginfo because their other uses have
been const-propagated.

To allow these locals to be removed, we now allow debuginfo to point to
a constant value. The `ConstProp` pass detects when debuginfo points to
a local with a known constant value and replaces it with the value. This
allows the later `SimplifyLocals` pass to remove the local.
2020-12-15 08:46:00 +00:00
Tomasz Miąsko
a9ff4bd838 Always run intrinsics lowering pass
Move intrinsics lowering pass from the optimization phase (where it
would not run if -Zmir-opt-level=0), to the drop lowering phase where it
runs unconditionally.

The implementation of those intrinsics in code generation and
interpreter is unnecessary. Remove it.
2020-12-15 00:00:00 +00:00
Tomasz Miąsko
686237c49a Lower discriminant_value intrinsic
This allows const propagation to evaluate comparisons involving
field-less enums using derived implementations of `PartialEq` (after
inlining `eq`).
2020-12-11 03:25:40 +01:00
bors
d7560e8968 Auto merge of #79801 - eddyb:scalar-transmute, r=nagisa
rustc_codegen_ssa: use bitcasts instead of type punning for scalar transmutes.

This specifically helps with `f32` <-> `u32` (`from_bits`, `to_bits`) in Rust-GPU (`rustc_codegen_spirv`), where (AFAIK) we don't yet have enough infrastructure to turn type punning memory accesses into SSA bitcasts.
(There may be more instances, but the one I've seen myself is `f32::signum` from `num-traits` inspecting e.g. the sign bit)

Sadly I've had to make an exception for `transmute`s between pointers and non-pointers, as LLVM disallows using `bitcast` for them.

r? `@nagisa` cc `@khyperia`
2020-12-10 12:55:12 +00:00
Corey Farwell
74207767c0 rustfmt 2020-12-10 00:18:30 -05:00
Corey Farwell
5940c19315 Enable ASan, TSan, UBSan for aarch64-apple-darwin. 2020-12-09 23:53:53 -05:00
bors
f0f68778f7 Auto merge of #77611 - oli-obk:atomic_miri_leakage, r=nagisa
Directly use raw pointers in `AtomicPtr` store/load

I was unable to find any reason for this limitation in the latest source of LLVM or in the documentation [here](http://llvm.org/docs/Atomics.html#libcalls-atomic).

fixes https://github.com/rust-lang/miri/issues/1574
2020-12-09 19:53:23 +00:00
Eduard-Mihai Burtescu
97c7022d08 rustc_codegen_ssa: use bitcasts instead of type punning for scalar transmutes. 2020-12-07 18:19:43 +02:00
Wesley Wiser
01aec8d185 [mir-opt] Allow debuginfo to be generated for a constant or a Place
Prior to this commit, debuginfo was always generated by mapping a name
to a Place. This has the side-effect that `SimplifyLocals` cannot remove
locals that are only used for debuginfo because their other uses have
been const-propagated.

To allow these locals to be removed, we now allow debuginfo to point to
a constant value. The `ConstProp` pass detects when debuginfo points to
a local with a known constant value and replaces it with the value. This
allows the later `SimplifyLocals` pass to remove the local.
2020-12-06 20:48:25 -05:00
Rich Kadel
def932ca86 Combination of commits
Fixes multiple issue with counters, with simplification

  Includes a change to the implicit else span in ast_lowering, so coverage
  of the implicit else no longer spans the `then` block.

  Adds coverage for unused closures and async function bodies.

  Fixes: #78542

Adding unreachable regions for known MIR missing from coverage map

Cleaned up PR commits, and removed link-dead-code requirement and tests

  Coverage no longer depends on Issue #76038 (`-C link-dead-code` is
  no longer needed or enforced, so MSVC can use the same tests as
  Linux and MacOS now)

Restrict adding unreachable regions to covered files

  Improved the code that adds coverage for uncalled functions (with MIR
  but not-codegenned) to avoid generating coverage in files not already
  included in the files with covered functions.

Resolved last known issue requiring --emit llvm-ir workaround

  Fixed bugs in how unreachable code spans were added.
2020-12-03 09:50:10 -08:00
Guillaume Gomez
8b0c31d492
Rollup merge of #79508 - jryans:check-dsymutil-result, r=nagisa
Warn if `dsymutil` returns an error code

This checks the error code returned by `dsymutil` and warns if it failed. It
also provides the stdout and stderr logs from `dsymutil`, similar to the native
linker step.

I tried to think of ways to test this change, but so far I haven't found a good way, as you'd likely need to inject some nonsensical args into `dsymutil` to induce failure, which feels too artificial to me. Also, https://github.com/rust-lang/rust/issues/79361 suggests Rust is on the verge of disabling `dsymutil` by default, so perhaps it's okay for this change to be untested. In any case, I'm happy to add a test if someone sees a good approach.

Fixes https://github.com/rust-lang/rust/issues/78770
2020-12-01 23:46:09 +01:00
Mara Bos
08b171726c
Rollup merge of #79184 - nanguye2496:nanguye2496/fix_slice_and_str_type_name, r=varkor
Stop adding '*' at the end of slice and str typenames for MSVC case

When computing debug info for MSVC debuggers, Rust compiler emits C++ style type names for compatibility with .natvis visualizers. All Ref types are treated as equivalences of C++ pointers in this process, and, as a result, their type names end with a '\*'. Since Slice and Str are treated as Ref by the compiler, their type names also end with a '\*'. This causes the .natvis engine for WinDbg fails to display data of Slice and Str objects. We addressed this problem simply by removing the '*' at the end of type names for Slice and Str types.

Debug info in WinDbg before the fix:
![image](https://user-images.githubusercontent.com/74681961/99594120-9a4dcf80-29a7-11eb-8cce-aedaf1da6d21.png)

Debug info in WinDbg after the fix:
![image](https://user-images.githubusercontent.com/74681961/99597173-717c0900-29ac-11eb-861e-98143a9177cf.png)

This change has also been tested with debuggers for Visual Studio, VS Code C++ and VS Code LLDB to make sure that it does not affect the behavior of other kinds of debugger.
2020-12-01 10:50:10 +00:00
Nam Nguyen
36e6aa0aa6 Stop adding '*' at the end of type names for Ref and Slice when computing debug info for MSVC debuggers 2020-11-30 14:31:34 -08:00
J. Ryan Stinnett
4ed9083561 Warn if dsymutil returns an error code
This checks the error code returned by `dsymutil` and warns if it failed. It
also provides the stdout and stderr logs from `dsymutil`, similar to the native
linker step.

Fixes https://github.com/rust-lang/rust/issues/78770
2020-11-30 09:59:56 +00:00
oli
392ea29757 Cast pointers to usize before passing them to atomic operations as some platforms do not support atomic operations on pointers. 2020-11-29 12:58:03 +00:00
oli
aabe70f90e Directly use raw pointers in AtomicPtr store/load 2020-11-28 17:13:47 +00:00
bors
4ae328bef4 Auto merge of #78296 - Aaron1011:fix/stmt-tokens, r=petrochenkov
Properly handle attributes on statements

We now collect tokens for the underlying node wrapped by `StmtKind`
nstead of storing tokens directly in `Stmt`.

`LazyTokenStream` now supports capturing a trailing semicolon after it
is initially constructed. This allows us to avoid refactoring statement
parsing to wrap the parsing of the semicolon in `parse_tokens`.

Attributes on item statements
(e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as
item attributes, not statement attributes, which is consistent with how
we handle attributes on other kinds of statements. The feature-gating
code is adjusted so that proc-macro attributes are still allowed on item
statements on stable.

Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be
adjusted to support being passed `Annotatable::Stmt`.
2020-11-28 07:48:56 +00:00
bors
774bce7f5e Auto merge of #77484 - terhechte:support-ios-catalyst-macabi-arm64-target-triple, r=nikomatsakis
Add support for Arm64 Catalyst on ARM Macs

This is an iteration on https://github.com/rust-lang/rust/pull/63467 which was merged a while ago. In the aforementioned PR, I added support for the `X86_64-apple-ios-macabi` target triple, which is Catalyst, iOS apps running on macOS.

Very soon, Apple will launch ARM64 based Macs which will introduce `aarch64_apple_darwin.rs`, macOS apps using the Darwin ABI running on ARM. This PR adds support for Catalyst apps on ARM Macs: iOS apps compiled for the darwin ABI.

I don't have access to a Apple Developer Transition Kit (DTK), so I can't really test if the generated binaries work correctly. I'm vaguely hopeful that somebody with access to a DTK could give this a spin.
2020-11-27 15:58:26 +00:00
Aaron Hill
6f91c32da6
Fix new 'unnecessary trailing semicolon' warnings 2020-11-26 17:08:36 -05:00
Benedikt Terhechte
96779647c4 Add support for Arm64 Catalyst on ARM Macs 2020-11-26 11:31:59 +01:00
Rich Kadel
5d5dc4c9d8 Updated links to LLVM 11 docs and types 2020-11-23 19:15:10 -08:00
LingMan
674f196c50 Use Option::and_then instead of open-coding it 2020-11-22 23:44:05 +01:00
bjorn3
42b0b8080d Replace ByVal attribute with on_stack field for Indirect
This makes it clearer that only PassMode::Indirect allows ByVal
2020-11-21 19:22:30 +01:00
Mara Bos
c7e9029b80
Rollup merge of #78361 - DevJPM:master, r=workingjubilee
Updated the list of white-listed target features for x86

This PR both adds in-source documentation on what to look out for when adding a new (X86) feature set and [adds all that are detectable at run-time in Rust stable as of 1.27.0](https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/src/detect/arch/x86.rs).

This should only enable the use of the corresponding LLVM intrinsics.
Actual intrinsics need to be added separately in rust-lang/stdarch.

It also re-orders the run-time-detect test statements to be more consistent
with the actual list of intrinsics whitelisted and removes underscores not present
in the actual names (which might be mistaken as being part of the name)

The reference for LLVM's feature names used is [this file](https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/Support/X86TargetParser.def).

This PR was motivated as the compiler end's part for allowing #67329 to be adressed over on rust-lang/stdarch
2020-11-18 15:46:19 +01:00
Bastian Kauschke
2bf93bd852 compiler: fold by value 2020-11-16 22:34:57 +01:00
DevJPM
72b83af2ff Re-enable LLVM 9 target features with LLVM 9 being the minimum now
With #78848 merged, the minimum supported LLVM version is now 9
which means we can actually use the target features introduced in LLVM 9
2020-11-15 11:34:08 +01:00
Vadim Petrochenkov
04d41e1f40 rustc_target: Mark UEFI targets as is_like_windows/is_like_msvc
Document what `is_like_windows` and `is_like_msvc` mean in more detail.
2020-11-12 19:40:41 +03:00
Jonas Schievink
105f4b8792
Rollup merge of #78875 - petrochenkov:cleantarg, r=Mark-Simulacrum
rustc_target: Further cleanup use of target options

Follow up to https://github.com/rust-lang/rust/pull/77729.

Implements items 2 and 4 from the list in https://github.com/rust-lang/rust/pull/77729#issue-500228243.

The first commit collapses uses of `target.options.foo` into `target.foo`.

The second commit renames some target options to avoid tautology:
`target.target_endian` -> `target.endian`
`target.target_c_int_width` -> `target.c_int_width`
`target.target_os` -> `target.os`
`target.target_env` -> `target.env`
`target.target_vendor` -> `target.vendor`
`target.target_family` -> `target.os_family`
`target.target_mcount` -> `target.mcount`

r? `@Mark-Simulacrum`
2020-11-10 14:45:21 +01:00
Dylan DPC
c150b933ac
Rollup merge of #78844 - tmiasko:monomorphize-sizeof, r=oli-obk
Monomorphize a type argument of size-of operation during codegen

This wasn't necessary until MIR inliner started to consider drop glue as
a candidate for inlining; introducing for the first time a generic use
of size-of operation.

No test at this point since this only happens with a custom inlining
threshold.
2020-11-09 19:07:02 +01:00
Dylan DPC
b4589a86cc
Rollup merge of #78674 - tmiasko:inline-substs-for-mir-body, r=oli-obk
inliner: Use substs_for_mir_body

Changes from 68965 extended the kind of instances that are being
inlined. For some of those, the `instance_mir` returns a MIR body that
is already expressed in terms of the types found in substitution array,
and doesn't need further substitution.

Use `substs_for_mir_body` to take that into account.

Resolves #78529.
Resolves #78560.
2020-11-09 01:13:42 +01:00
Vadim Petrochenkov
dc004d4809 rustc_target: Rename some target options to avoid tautology
`target.target_endian` -> `target.endian`
`target.target_c_int_width` -> `target.c_int_width`
`target.target_os` -> `target.os`
`target.target_env` -> `target.env`
`target.target_vendor` -> `target.vendor`
`target.target_family` -> `target.os_family`
`target.target_mcount` -> `target.mcount`
2020-11-08 17:29:13 +03:00
Vadim Petrochenkov
bf66988aa1 Collapse all uses of target.options.foo into target.foo
with an eye on merging `TargetOptions` into `Target`.

`TargetOptions` as a separate structure is mostly an implementation detail of `Target` construction, all its fields logically belong to `Target` and available from `Target` through `Deref` impls.
2020-11-08 17:29:13 +03:00
Tomasz Miąsko
f78f36cdb7 Monomorphize a type argument of size-of operation during codegen
This wasn't necessary until MIR inliner started to consider drop glue as
a candidate for inlining; introducing for the first time a generic use
of size-of operation.

No test at this point since this only happens with a custom inlining
threshold.
2020-11-07 00:00:00 +00:00
Rich Kadel
1973f84ebb Addressed all feedback to date 2020-11-05 18:24:17 -08:00
Rich Kadel
5545c56e9d Added comments on remapping expression IDs, and URL to spanviews 2020-11-05 18:24:16 -08:00
Rich Kadel
198ba3bd1c Injecting expressions in place of counters where helpful
Implementing the Graph traits for the BasicCoverageBlock
graph.

optimized replacement of counters with expressions plus new BCB graphviz

* Avoid adding coverage to unreachable blocks.
* Special case for Goto at the end of the body. Make it non-reportable.

Improved debugging and formatting options (from env)

Don't automatically add counters to BCBs without CoverageSpans. They may
still get counters but only if there are dependencies from
other BCBs that have spans, I think.

Make CodeRegions optional for Counters too. It is
possible to inject counters (`llvm.instrprof.increment` intrinsic calls
without corresponding code regions in the coverage map. An expression
can still uses these counter values.

Refactored instrument_coverage.rs -> instrument_coverage/mod.rs, and
then broke up the mod into multiple files.

Compiling with coverage, with the expression optimization, works on
the json5format crate and its dependencies.

Refactored debug features from mod.rs to debug.rs
2020-11-05 18:24:15 -08:00
Rich Kadel
c7747cc772 Rust coverage before splitting instrument_coverage.rs 2020-11-05 18:24:12 -08:00
Tomasz Miąsko
8a8ee1a3ed inliner: Use substs_for_mir_body
Changes from 68965 extended the kind of instances that are being
inlined. For some of those, the `instance_mir` returns a MIR body that
is already expressed in terms of the types found in substitution array,
and doesn't need further substitution.

Use `substs_for_mir_body` to take that into account.
2020-11-06 00:00:00 +00:00
bors
89631663b7 Auto merge of #78280 - bugadani:span, r=lcnr
Codegen: Query span as late as possible
2020-11-04 17:17:01 +00:00
bors
7b5a9e9cd2 Auto merge of #78448 - rylev:cache-foreign_modules, r=wesleywiser
foreign_modules query hash table lookups

When compiling a large monolithic crate we're seeing huge times in the `foreign_modules` query due to repeated iteration over foreign modules (in order to find a module by its id). This implements hash table lookups so that which massively reduces time spent in that query in this particular case. We'll need to see if the overhead of creating the hash table has a negative impact on performance in more normal compilation scenarios.

I'm working with `@wesleywiser` on this.
2020-11-03 04:27:27 +00:00
Ryan Levick
81444b2049 Remove some cruft from foreign_modules refactor 2020-10-27 20:17:48 +01:00
Ryan Levick
69dc98161a Cache foreign_modules query 2020-10-27 16:21:55 +01:00
Dániel Buga
caf9131e65 Query span as late as possible 2020-10-27 10:17:01 +01:00
Yuki Okushi
46b8e46fe1
Rollup merge of #78396 - josephlr:ermsb, r=petrochenkov
Add compiler support for LLVM's x86_64 ERMSB feature

This change is needed for compiler-builtins to check for this feature
when implementing memcpy/memset. See:
  https://github.com/rust-lang/compiler-builtins/pull/365

Without this change, the following code compiles, but does nothing:
```rust
#[cfg(target_feature = "ermsb")]
pub unsafe fn ermsb_memcpy() { ... }
```

The change just does compile-time detection. I think that runtime
detection will have to come in a follow-up CL to std-detect.

Like all the CPU feature flags, this just references #44839

Signed-off-by: Joe Richey <joerichey@google.com>
2020-10-27 08:45:24 +09:00
bors
0da6d42f29 Auto merge of #68965 - eddyb:mir-inline-scope, r=nagisa,oli-obk
rustc_mir: track inlined callees in SourceScopeData.

We now record which MIR scopes are the roots of *other* (inlined) functions's scope trees, which allows us to generate the correct debuginfo in codegen, similar to what LLVM inlining generates.
This PR makes the `ui` test `backtrace-debuginfo` pass, if the MIR inliner is turned on by default.

Also, `#[track_caller]` is now correct in the face of MIR inlining (cc `@anp).`

Fixes #76997.

r? `@rust-lang/wg-mir-opt`
2020-10-26 18:50:22 +00:00
oli
7101ce9127 Deduplicate span and dbg_scope adjustment 2020-10-26 13:04:52 +00:00
oli
f8aae50469 Prefer bug! over unwrap() 2020-10-26 12:49:49 +00:00
Joe Richey
ad552bc17e
Add compiler support for LLVM's x86 ERMSB feature
This change is needed for compiler-builtins to check for this feature
when implementing memcpy/memset. See:
  https://github.com/rust-lang/compiler-builtins/pull/365

The change just does compile-time detection. I think that runtime
detection will have to come in a follow-up CL to std-detect.

Like all the CPU feature flags, this just references #44839

Signed-off-by: Joe Richey <joerichey@google.com>
2020-10-26 03:46:54 -07:00
DevJPM
3daa93f555 Updated documentation, x86 feature detection testing, and removed LLVM 9 exclusive features
Updated the added documentation in llvm_util.rs to note which copies of LLVM need to be inspected.
Removed avx512bf16 and avx512vp2intersect because they are unsupported before LLVM 9 with the build with external LLVM 8 being supported
Re-introduced detection testing previously removed for un-requestable features tsc and mmx
2020-10-26 08:36:14 +01:00
DevJPM
9feb567399 Updated the list of white-listed target features for x86
This PR both adds in-source documentation on what to look out for
when adding a new (X86) feature set and adds all that are detectable at run-time in Rust stable
as of 1.27.0.

This should only enable the use of the corresponding LLVM intrinsics.
Actual intrinsics need to be added separately in rust-lang/stdarch.

It also re-orders the run-time-detect test statements to be more consistent
with the actual list of intrinsics whitelisted and removes underscores not present
in the actual names (which might be mistaken as being part of the name)
2020-10-25 17:06:40 +01:00
Rich Kadel
a7bc1a2edf Make codegen coverage_context optional, and check
Addresses Issue #78286

Libraries compiled with coverage and linked with out enabling coverage
would fail when attempting to add the library's coverage statements to
the codegen coverage context (None).

Now, if coverage statements are encountered while compiling / linking
with `-Z instrument-coverage` disabled, codegen will *not* attempt to
add code regions to a coverage map, and it will not inject the LLVM
instrprof_increment intrinsic calls.
2020-10-23 12:00:30 -07:00
Eduard-Mihai Burtescu
0ce4452fce rustc_codegen_llvm: add support for inlined function debuginfo. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
737499593d rustc_codegen_llvm: expose DILocation to rustc_codegen_ssa. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
fa2b381ec8 rustc_codegen_llvm: move DISubprogram creation to a dbg_scope_fn method. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
9d57c417fc rustc_codegen_llvm: create DIFiles from just SourceFiles. 2020-10-21 04:43:56 +03:00
Eduard-Mihai Burtescu
6451b39a25 rustc_mir: support MIR-inlining #[track_caller] functions. 2020-10-21 04:43:56 +03:00
khyperia
3d484481c7 Make set_span take mut self 2020-10-17 13:28:58 +02:00
bors
a78a62fc99 Auto merge of #77972 - Mark-Simulacrum:side-effect-loop, r=nagisa
Prevent miscompilation in trivial loop {}

Ideally, we would want to handle a broader set of cases to fully fix the
underlying bug here. That is currently relatively expensive at compile and
runtime, so we don't do that for now.

Performance results indicate this is not a major regression, if at all, so it should be safe to land.

cc #28728
2020-10-16 14:06:37 +00:00
Mark Rousskov
e2efec8976 Prevent miscompilation in trivial loop {}
Ideally, we would want to handle a broader set of cases to fully fix the
underlying bug here. That is currently relatively expensive at compile and
runtime, so we don't do that for now.
2020-10-15 09:42:06 -04:00
est31
d683e3ac23 Remove rustc_session::config::Config
The wrapper type led to tons of target.target
across the compiler. Its ptr_width field isn't
required any more, as target_pointer_width
is already present in parsed form.
2020-10-15 12:02:24 +02:00
est31
4fa5578774 Replace target.target with target and target.ptr_width with target.pointer_width
Preparation for a subsequent change that replaces
rustc_target::config::Config with its wrapped Target.

On its own, this commit breaks the build. I don't like making
build-breaking commits, but in this instance I believe that it
makes review easier, as the "real" changes of this PR can be
seen much more easily.

Result of running:

find compiler/ -type f -exec sed -i -e 's/target\.target\([)\.,; ]\)/target\1/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target\.target$/target/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target.ptr_width/target.pointer_width/g' {} \;
./x.py fmt
2020-10-15 12:02:24 +02:00
est31
0d1aa1e034 Rename target_pointer_width to pointer_width and turn it into an u32
Rename target_pointer_width to pointer_width because it is already
member of the Target struct.

The compiler supports only three valid values for target_pointer_width:
16, 32, 64. Thus it can safely be turned into an int.
This means less allocations and clones as well as easier handling of the type.
2020-10-15 12:02:23 +02:00
Yuki Okushi
022d20759b
Rollup merge of #77739 - est31:remove_unused_code, r=petrochenkov,varkor
Remove unused code

Rustc has a builtin lint for detecting unused code inside a crate, but when an item is marked `pub`, the code, even if unused inside the entire workspace, is never marked as such. Therefore, I've built [warnalyzer](https://github.com/est31/warnalyzer) to detect unused items in a cross-crate setting.

Closes https://github.com/est31/warnalyzer/issues/2
2020-10-15 07:32:29 +09:00
est31
feaac592a3 Remove unused code from rustc_codegen_* 2020-10-14 04:14:32 +02:00
Dylan DPC
17ee28b71f
Rollup merge of #77795 - bjorn3:codegen_backend_interface_refactor, r=oli-obk
Codegen backend interface refactor

This moves several things away from the codegen backend to rustc_interface. There are a few behavioral changes where previously the incremental cache (incorrectly) wouldn't get finalized, but now it does. See the individual commit messages.
2020-10-14 02:30:38 +02:00
est31
a0fc455d30 Replace absolute paths with relative ones
Modern compilers allow reaching external crates
like std or core via relative paths in modules
outside of lib.rs and main.rs.
2020-10-13 14:16:45 +02:00
bors
f54072bb81 Auto merge of #76830 - Artoria2e5:tune, r=nagisa
Pass tune-cpu to LLVM

I think this is how it should work...

See https://internals.rust-lang.org/t/expose-tune-cpu-from-llvm/13088 for the background. Or the documentation diff.
2020-10-13 02:49:00 +00:00
bors
afb4514c09 Auto merge of #77796 - jonas-schievink:switchint-refactor, r=oli-obk
Refactor how SwitchInt stores jump targets

Closes https://github.com/rust-lang/rust/issues/65693
2020-10-13 00:57:03 +00:00
bjorn3
b620e49cca Remove dump_incremental_data 2020-10-12 10:34:30 +02:00
Jonas Schievink
4f5394199b Fix -Clinker-plugin-lto with opt-levels s and z 2020-10-12 01:45:00 +02:00
Jonas Schievink
9a47f74bfe Use SmallVec in SwitchTargets
This allows building common SwitchTargets (eg. for `if`s) without
allocation.
2020-10-11 01:14:12 +02:00
Jonas Schievink
432535da2b Refactor how SwitchInt stores jump targets 2020-10-10 17:46:11 +02:00
bjorn3
69f26b7761 Use fixed type for CodegenResults
This also moves the -Zno-link implementation to rustc_interface
2020-10-10 16:18:36 +02:00
bjorn3
f141acf067 Move finalize_session_directory call out of cg_llvm
This causes it to be called even when passing `-Zno-link`, when linking
fails or when neither `--emit link` nor `--emit metadata` is used.
2020-10-10 15:20:35 +02:00
bjorn3
69f45cd965 Move save_work_product_index call out of cg_llvm 2020-10-10 15:14:58 +02:00
bjorn3
46f2f023b0 Move supported_target_features query provider to cg_ssa 2020-10-09 19:35:17 +02:00
khyperia
c5bc95676b Let backends access span information
Sometimes, a backend may need to emit warnings, errors, or otherwise
need to know the span of the current item in a basic block. So, add a
set_span method to give the backend that information.
2020-10-06 15:39:12 +02:00
bors
a1dfd2490a Auto merge of #77080 - richkadel:llvm-coverage-counters-2, r=tmandry
Working branch-level code coverage

Add a generalized implementation for computing branch-level coverage spans.

This iteration resolves some of the challenges I had identified a few weeks ago.

I've tried to implement a solution that is general enough to work for a lot of different graphs/patterns. It's encouraging to see the results on fairly large and complex crates seem to meet my expectations. This may be a "functionally complete" implementation.

Except for bug fixes or edge cases I haven't run into yet, the next and essentially final step, I think, is to replace some Counters with CounterExpressions (where their counter values can be computed by adding or subtracting other counters/expressions).

Examples of branch-level coverage support enabled in this PR:

* https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_drop_trait.txt
* https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_if.txt
* https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_if_else.txt
* https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_simple_loop.txt
* https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_simple_match.txt
* ... _and others in the same directory_

Examples of coverage analysis results (MIR spanview files) used to inject counters in the right `BasicBlocks`:

* https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_drop_trait/coverage_of_drop_trait.main.-------.InstrumentCoverage.0.html
* https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_if/coverage_of_if.main.-------.InstrumentCoverage.0.html
* https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_if_else/coverage_of_if_else.main.-------.InstrumentCoverage.0.html
* https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_simple_loop/coverage_of_simple_loop.main.-------.InstrumentCoverage.0.html
* https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_simple_match/coverage_of_simple_match.main.-------.InstrumentCoverage.0.html
* ... _and others in the same directory_

Here is some sample coverage output after compiling a few real-world crates with the new branch-level coverage features:

<img width="801" alt="Screen Shot 2020-09-25 at 1 03 11 PM" src="https://user-images.githubusercontent.com/3827298/94316848-fd882c00-ff39-11ea-9cff-0402d3abd1e7.png">
<img width="721" alt="Screen Shot 2020-09-25 at 1 00 36 PM" src="https://user-images.githubusercontent.com/3827298/94316886-11cc2900-ff3a-11ea-9d03-80b26c8a5173.png">
<img width="889" alt="Screen Shot 2020-09-25 at 12 54 57 PM" src="https://user-images.githubusercontent.com/3827298/94316900-18f33700-ff3a-11ea-8a80-58f67d84b8de.png">

r? `@tmandry`
FYI: `@wesleywiser`
2020-10-05 19:34:44 +00:00
Rich Kadel
f5aebad28f Updates to experimental coverage counter injection
This is a combination of 18 commits.

Commit #2:

Additional examples and some small improvements.

Commit #3:

fixed mir-opt non-mir extensions and spanview title elements

Corrected a fairly recent assumption in runtest.rs that all MIR dump
files end in .mir. (It was appending .mir to the graphviz .dot and
spanview .html file names when generating blessed output files. That
also left outdated files in the baseline alongside the files with the
incorrect names, which I've now removed.)

Updated spanview HTML title elements to match their content, replacing a
hardcoded and incorrect name that was left in accidentally when
originally submitted.

Commit #4:

added more test examples

also improved Makefiles with support for non-zero exit status and to
force validation of tests unless a specific test overrides it with a
specific comment.

Commit #5:

Fixed rare issues after testing on real-world crate

Commit #6:

Addressed PR feedback, and removed temporary -Zexperimental-coverage

-Zinstrument-coverage once again supports the latest capabilities of
LLVM instrprof coverage instrumentation.

Also fixed a bug in spanview.

Commit #7:

Fix closure handling, add tests for closures and inner items

And cleaned up other tests for consistency, and to make it more clear
where spans start/end by breaking up lines.

Commit #8:

renamed "typical" test results "expected"

Now that the `llvm-cov show` tests are improved to normally expect
matching actuals, and to allow individual tests to override that
expectation.

Commit #9:

test coverage of inline generic struct function

Commit #10:

Addressed review feedback

* Removed unnecessary Unreachable filter.
* Replaced a match wildcard with remining variants.
* Added more comments to help clarify the role of successors() in the
CFG traversal

Commit #11:

refactoring based on feedback

* refactored `fn coverage_spans()`.
* changed the way I expand an empty coverage span to improve performance
* fixed a typo that I had accidently left in, in visit.rs

Commit #12:

Optimized use of SourceMap and SourceFile

Commit #13:

Fixed a regression, and synched with upstream

Some generated test file names changed due to some new change upstream.

Commit #14:

Stripping out crate disambiguators from demangled names

These can vary depending on the test platform.

Commit #15:

Ignore llvm-cov show diff on test with generics, expand IO error message

Tests with generics produce llvm-cov show results with demangled names
that can include an unstable "crate disambiguator" (hex value). The
value changes when run in the Rust CI Windows environment. I added a sed
filter to strip them out (in a prior commit), but sed also appears to
fail in the same environment. Until I can figure out a workaround, I'm
just going to ignore this specific test result. I added a FIXME to
follow up later, but it's not that critical.

I also saw an error with Windows GNU, but the IO error did not
specify a path for the directory or file that triggered the error. I
updated the error messages to provide more info for next, time but also
noticed some other tests with similar steps did not fail. Looks
spurious.

Commit #16:

Modify rust-demangler to strip disambiguators by default

Commit #17:

Remove std::process::exit from coverage tests

Due to Issue #77553, programs that call std::process::exit() do not
generate coverage results on Windows MSVC.

Commit #18:

fix: test file paths exceeding Windows max path len
2020-10-05 08:02:58 -07:00
Mark Rousskov
e8325b0f40 Instruct lld that our @ files are posix-style, not Windows
An upstream LLVM change changed behavior here to respect the host system quoting
rules; previously the posix-style format was always used for @files.
2020-10-05 08:01:44 -04:00
Mingye Wang
a35a93f09c Pass tune-cpu to LLVM
I think this is how it should work...
2020-10-05 07:50:44 +08:00
Jonas Schievink
5889cf3146
Rollup merge of #77521 - bjorn3:target_feature_whitelist, r=lcnr
Move target feature whitelist from cg_llvm to cg_ssa

These target features have to be supported or at least emulated by alternative codegen backends anyway as they are used by common crates. By moving this list to cg_ssa, other codegen backends don't have to copy
this code.
2020-10-04 15:45:48 +02:00
bjorn3
17d1cbbbe0 Move target feature whitelist from cg_llvm to cg_ssa
These target features have to be supported or at least emulated by
alternative codegen backends anyway as they are used by common crates.
By moving this list to cg_ssa, other codegen backends don't have to copy
this code.
2020-10-04 11:49:00 +02:00
Harald Hoyer
cadd12b5f0 Implement Make handle_alloc_error default to panic (for no_std + liballoc)
Related: https://github.com/rust-lang/rust/issues/66741

Guarded with `#![feature(default_alloc_error_handler)]` a default
`alloc_error_handler` is called, if a custom allocator is used and no
other custom `#[alloc_error_handler]` is defined.

The panic message does not contain the size anymore, because it would
pull in the fmt machinery, which would blow up the code size
significantly.
2020-10-02 09:00:29 +02:00
Dylan DPC
37df40bd1c
Rollup merge of #77202 - ehuss:defer-apple-sdkroot, r=petrochenkov
Defer Apple SDKROOT detection to link time.

This defers the detection of the SDKROOT for Apple iOS/tvOS targets to link time, instead of when the `Target` is defined. This allows commands that don't need to link to work (like `rustdoc` or `rustc --print=target-list`). This also makes `--print=target-list` a bit faster.

This also removes the note in the platform support documentation about these targets being missing. When I wrote it, I misunderstood how the SDKROOT stuff worked.

Notes:
* This means that JSON spec targets can't explicitly override these flags. I think that is probably fine, as I believe the value is generally required, and can be set with the SDKROOT environment variable.
* This changes `x86_64-apple-tvos` to use `appletvsimulator`. I think the original code was wrong (it was using `iphonesimulator`). Also, `x86_64-apple-tvos` seems broken in general, and I cannot build it locally. The `data_layout` does not appear to be correct (it is a copy of the arm64 layout instead of the x86_64 layout). I have not tried building Apple's LLVM to see if that helps, but I suspect it is just wrong (I'm uncertain since I don't know how the tvOS simulator works with its bitcode-only requirements).
* I'm tempted to remove the use of `Result` for built-in target definitions, since I don't think they should be fallible. This was added in https://github.com/rust-lang/rust/pull/34980, but that only relates to JSON definitions. I think the built-in targets shouldn't fail. I can do this now, or not.

Fixes #36156
Fixes #76584
2020-10-01 02:13:34 +02:00
Eric Huss
7420d7a980 Move add_apple_sdk out of add_pre_link_args. 2020-09-26 19:12:38 -07:00
Jonas Schievink
3d1d24da94
Rollup merge of #77208 - mati865:late-link-args-order, r=petrochenkov
Late link args order

MSYS2 changed how winpthreads is built and as the result it now depends on more mingw-w64 libraries.

This PR affects only MinGW targets since nobody else is using `late_link_args_{dynamic,static}`. Now the order is similar to how it used to be before https://github.com/rust-lang/rust/pull/67502.
2020-09-27 01:53:23 +02:00
Ralf Jung
9e02642fb3
Rollup merge of #77211 - est31:remove_unused_allow, r=oli-obk
Remove unused #[allow(...)] statements from compiler/
2020-09-26 12:58:34 +02:00
Ralf Jung
7c47b1e5f4
Rollup merge of #77161 - est31:swich_len_already_trusted, r=petrochenkov
Remove TrustedLen requirement from BuilderMethods::switch

The main use case of TrustedLen is allowing APIs to specialize on it,
but no use of it uses that specialization. Instead, only the .len()
function provided by ExactSizeIterator is used, which is already
required to be accurate.

Thus, the TrustedLen requirement on BuilderMethods::switch is redundant.
2020-09-26 12:58:24 +02:00
est31
12187b7f86 Remove unused #[allow(...)] statements from compiler/ 2020-09-26 01:25:55 +02:00
marmeladema
bb8e1764bb Simplify some match statements on `DefPathDataName' 2020-09-25 22:46:15 +01:00
marmeladema
657ecdb75e Rename DefPathData::get_name() to DefPathData::name() 2020-09-25 22:46:15 +01:00
marmeladema
f1878d19fa Move from {{closure}}#0 syntax to {closure#0} for (def) path components 2020-09-25 22:46:14 +01:00
Eric Huss
c29a29cba0 Defer Apple SDKROOT detection to link time. 2020-09-25 12:07:46 -07:00
Jonas Schievink
1b8c939a8d
Rollup merge of #76973 - lzutao:unstably-const-assume, r=oli-obk
Unstably allow assume intrinsic in const contexts

Not sure much about this usage because there are concerns
about [blocking  optimization][1] and [slowing down LLVM][2] when using `assme` intrinsic
in inline functions.
But since Oli suggested in https://github.com/rust-lang/rust/issues/76960#issuecomment-695772221,
here we are.

[1]: https://github.com/rust-lang/rust/pull/54995#issuecomment-429302709
[2]: https://github.com/rust-lang/rust/issues/49572#issuecomment-589615423
2020-09-25 19:42:29 +02:00
bors
5b9e886403 Auto merge of #73453 - erikdesjardins:tuplayout, r=eddyb
Ignore ZST offsets when deciding whether to use Scalar/ScalarPair layout

This is important because Scalar/ScalarPair layout previously would not be used if any ZST had nonzero offset.
For example, before this change, only `((), u128)` would be laid out like `u128`, not `(u128, ())`.

Fixes #63244
2020-09-25 14:42:20 +00:00
Mateusz Mikuła
bfdb7903c9 Link dynamic and static late_link_args before generic ones 2020-09-25 13:35:49 +02:00
est31
12ada5cf4b Remove TrustedLen requirement from BuilderMethods::switch
The main use case of TrustedLen is allowing APIs to specialize on it,
but no use of it uses that specialization. Instead, only the .len()
function provided by ExactSizeIterator is used, which is already
required to be accurate.

Thus, the TrustedLen requirement on BuilderMethods::switch is redundant.
2020-09-24 19:10:34 +02:00
Erik Hofmayer
138a2e5eaa /nightly/nightly-rustc 2020-09-23 21:51:56 +02:00
Erik Hofmayer
dd66ea2d3d Updated html_root_url for compiler crates 2020-09-23 21:14:43 +02:00
Ralf Jung
02d787bef8
Rollup merge of #76872 - khyperia:remove_declare_methods, r=eddyb
Remove DeclareMethods

Most of the `DeclareMethods` API was only used internally by rustc_codegen_llvm. As such, it makes no sense to require other backends to implement them.

(`get_declared_value` and `declare_cfn` were used, in one place, specific to the `main` symbol, which I've replaced with a more specialized function to allow more flexibility in implementation - the intent is that `declare_c_main` can go away once we do something more clever, e.g. @eddyb has ideas around having a MIR shim or somesuch we can explore in a follow-up PR)
2020-09-21 10:40:35 +02:00
Ralf Jung
c847eaa91d
Rollup merge of #76832 - khyperia:backend_target_override, r=eddyb
Let backends define custom targets

Add a target_override hook that takes priority over builtin targets.
2020-09-20 15:51:48 +02:00
Lzu Tao
3e08354fb0 Correct file path after some restructures in compiler 2020-09-20 13:48:16 +00:00
bors
41507ed0d5 Auto merge of #76964 - RalfJung:rollup-ybn06fs, r=RalfJung
Rollup of 15 pull requests

Successful merges:

 - #76722 (Test and fix Send and Sync traits of BTreeMap artefacts)
 - #76766 (Extract some intrinsics out of rustc_codegen_llvm)
 - #76800 (Don't generate bootstrap usage unless it's needed)
 - #76809 (simplfy condition in ItemLowerer::with_trait_impl_ref())
 - #76815 (Fix wording in mir doc)
 - #76818 (Don't compile regex at every function call.)
 - #76821 (Remove redundant nightly features)
 - #76823 (black_box: silence unused_mut warning when building with cfg(miri))
 - #76825 (use `array_windows` instead of `windows` in the compiler)
 - #76827 (fix array_windows docs)
 - #76828 (use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip))
 - #76840 (Move to intra doc links in core/src/future)
 - #76845 (Use intra docs links in core::{ascii, option, str, pattern, hash::map})
 - #76853 (Use intra-doc links in library/core/src/task/wake.rs)
 - #76871 (support panic=abort in Miri)

Failed merges:

r? `@ghost`
2020-09-20 11:02:36 +00:00
Ralf Jung
4322e1b92d
Rollup merge of #76821 - est31:remove_redundant_nightly_features, r=oli-obk,Mark-Simulacrum
Remove redundant nightly features

Removes a bunch of redundant/outdated nightly features. The first commit removes a `core_intrinsics` use for which a stable wrapper has been provided since. The second commit replaces the `const_generics` feature with `min_const_generics` which might get stabilized this year. The third commit is the result of a trial/error run of removing every single feature and then adding it back if compile failed. A bunch of unused features are the result that the third commit removes.
2020-09-20 12:08:22 +02:00
Oliver Scherer
2d7ac728e4 Stop using the const_eval query for initializers of statics
As a side effect, we now represent most promoteds as `ConstValue::Scalar` again. This is useful because all implict promoteds are just references anyway and most explicit promoteds are numeric arguments to `asm!` or SIMD instructions.
2020-09-19 10:36:36 +02:00
khyperia
0bc405e352 Remove DeclareMethods 2020-09-18 13:11:59 +02:00
khyperia
48655c2d2c PR feedback 2020-09-17 12:18:09 +02:00
khyperia
c946c40d9d Let backends define custom targets
Add a target_override hook that takes priority over builtin targets.
2020-09-17 12:01:12 +02:00
est31
ebdea01143 Remove redundant #![feature(...)] 's from compiler/ 2020-09-17 07:58:45 +02:00
khyperia
21b0c1286a Extract some intrinsics out of rustc_codegen_llvm
A significant amount of intrinsics do not actually need backend-specific
behaviors to be implemented, instead relying on methods already in
rustc_codegen_ssa. So, extract those methods out to rustc_codegen_ssa,
so that each backend doesn't need to reimplement the same code.
2020-09-15 23:35:31 +02:00
Matthias Krüger
9bb10cc907 use push(char) instead of push_str(&str) to add single chars to strings
clippy::single-char-push-str
2020-09-10 13:58:41 +02:00
Victor Ding
c81b43d8ac Add -Z combine_cgu flag
Introduce a compiler option to let rustc combines all regular CGUs into
a single one at the end of compilation.

Part of Issue #64191
2020-09-09 17:32:23 +10:00
LeSeulArtichaut
3e14b684dd Change ty.kind to a method 2020-09-04 17:47:51 +02:00
bors
af3c6e733a Auto merge of #73996 - da-x:short-unique-paths, r=petrochenkov
diagnostics: shorten paths of unique symbols

This is a step towards implementing a fix for #50310, and continuation of the discussion in [Pre-RFC: Nicer Types In Diagnostics - compiler - Rust Internals](https://internals.rust-lang.org/t/pre-rfc-nicer-types-in-diagnostics/11139). Impressed upon me from previous discussion in #21934 that an RFC for this is not needed, and I should just come up with code.

The recent improvements to `use` suggestions that I've contributed have given rise to this implementation. Contrary to previous suggestions, it's rather simple logic, and I believe it only reduces the amount of cognitive load that a developer would need when reading type errors.

-----

If a symbol name can only be imported from one place, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path to the last component.

This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable from anywhere.
2020-09-03 23:27:45 +00:00
Dylan DPC
a4e30a6ae7
Rollup merge of #76167 - mati865:mingw-self-contained-heuristic, r=petrochenkov
Replace MinGW library hack with heuristic controlling link mode

Depends on https://github.com/rust-lang/rust/pull/76158
Closes https://github.com/rust-lang/rust/issues/68887
2020-09-03 02:22:06 +02:00
Dan Aloni
07e7823c01 pretty: trim paths of unique symbols
If a symbol name can only be imported from one place for a type, and
as long as it was not glob-imported anywhere in the current crate, we
can trim its printed path and print only the name.

This has wide implications on error messages with types, for example,
shortening `std::vec::Vec` to just `Vec`, as long as there is no other
`Vec` importable anywhere.

This adds a new '-Z trim-diagnostic-paths=false' option to control this
feature.

On the good path, with no diagnosis printed, we should try to avoid
issuing this query, so we need to prevent trimmed_def_paths query on
several cases.

This change also relies on a previous commit that differentiates
between `Debug` and `Display` on various rustc types, where the latter
is trimmed and presented to the user and the former is not.
2020-09-02 22:26:37 +03:00
Tyler Mandry
4a6aa350c7
Rollup merge of #76158 - mati865:self-contained-option, r=petrochenkov
Stabilise link-self-contained option

MCP has been accepted: https://github.com/rust-lang/compiler-team/issues/343

I'll add improved heuristic in next PR.
2020-09-01 18:24:36 -07:00
Mateusz Mikuła
770231e54d Replace MinGW library hack with heuristic controlling link mode 2020-09-01 19:52:39 +02:00
bors
397db054cb Auto merge of #75529 - bugadani:bounds-check, r=nagisa
Eliminate some other bound checks when index comes from an enum

#36962 introduced an assumption for the upper limit of the enum's value. This PR adds an assumption to the lower value as well.

I've modified the original codegen test to show that derived (in that case, adding 1) values also don't generate bounds checks.

However, this test is actually carefully crafted to not hit a bug: if the enum's variants are modified to 1 and 2 instead of 2 and 3, the test fails by adding a bounds check. I suppose this is an LLVM issue and #75525, while not exactly in this context should be tracking it.

I'm not at all confident if this patch can be accepted, or even if it _should_ be accepted in this state. But I'm curious about what others think :)

~Improves~ Should improve #13926 but does not close it because it's not exactly predictable, where bounds checks may pop up against the assumptions.
2020-09-01 13:36:52 +00:00
bors
6f1bbf5ee0 Auto merge of #76071 - khyperia:configurable_to_immediate, r=eddyb
Make to_immediate/from_immediate configurable by backends

`librustc_codegen_ssa` has the concept of an immediate vs. memory type, and `librustc_codegen_llvm` uses this distinction to implement `bool`s being `i8` in memory, and `i1` in immediate contexts. However, some of that implementation leaked into `codegen_ssa` when converting to/from immediate values. So, move those methods into builder traits, so that behavior can be configured by backends.

This is useful if a backend is able to keep bools as bools, or, needs to do more trickery than just bools to bytes.

(Note that there's already a large amount of things abstracted with "immediate types" - this is just bringing this particular thing in line to be abstracted as well)

---

Pinging @eddyb since that's who I was talking about this change with when they suggested I submit a PR.
2020-09-01 07:44:34 +00:00
Tyler Mandry
6d834a4046
Rollup merge of #76002 - richkadel:llvm-coverage-map-gen-6b.3, r=tmandry
Fix `-Z instrument-coverage` on MSVC

Found that `-C link-dead-code` (which was enabled automatically
under `-Z instrument-coverage`) was causing the linking error that
resulted in segmentation faults in coverage instrumented binaries. Link
dead code is now disabled under MSVC, allowing `-Z instrument-coverage`
to be enabled under MSVC for the first time.

More details are included in Issue #76038 .

Note this PR makes it possible to support `Z instrument-coverage` but
does not enable instrument coverage for MSVC in existing tests. It will be
enabled in another PR to follow this one (both PRs coming from original
PR #75828).

r? @tmandry
FYI: @wesleywiser
2020-08-31 19:18:14 -07:00
Rich Kadel
ddb054aee8 Fix -Z instrument-coverage on MSVC
Found that -C link-dead-code (which was enabled automatically
under -Z instrument-coverage) was causing the linking error that
resulted in segmentation faults in coverage instrumented binaries. Link
dead code is now disabled under MSVC, allowing `-Z instrument-coverage`
to be enabled under MSVC for the first time.

More details are included in Issue #76038.

(This PR was broken out from PR #75828)
2020-08-31 18:41:13 -07:00
Mateusz Mikuła
23f0ccfe5d Stabilise link-self-contained option 2020-08-31 15:13:31 +02:00
Dániel Buga
c88b167f15 Additional assumption to elide bounds check 2020-08-31 08:19:15 +02:00
Erik Desjardins
24e0913e37 handle vector layout 2020-08-30 14:58:03 -04:00
Erik Desjardins
68217c9e0f ignore zst offsets instead 2020-08-30 14:58:03 -04:00
David Wood
6ff471b1cf
ty: remove obsolete printer
This commit removes the obsolete printer and replaces all uses of it
with `FmtPrinter`. Of the replaced uses, all but one use was in `debug!`
logging, two cases were notable:

- `MonoItem::to_string` is used in `-Z print-mono-items` and therefore
  affects the output of all codegen-units tests.
- `DefPathBasedNames` was used in `librustc_codegen_llvm/type_of.rs`
  with `LLVMStructCreateNamed` and that'll now get different values, but
  this should result in no functional change.

Signed-off-by: David Wood <david@davidtw.co>
2020-08-30 18:59:07 +01:00
mark
9e5f7d5631 mv compiler to compiler/ 2020-08-30 18:45:07 +03:00