Commit Graph

2562 Commits

Author SHA1 Message Date
Dylan DPC
1dc672a766
Rollup merge of #95426 - b-naber:valtrees-slice, r=RalfJung,oli-obk
Include Refs in Valtree Creation

This adds references to `const_to_valtree`, which isn't used in the compiler yet, but after the previous changes we made to the thir and mir representations and this change we should be able to finally introduce them in the next PR.

I wasn't able to properly test this code, except indirectly by including a call of `const_to_valtree` in the code that currently creates constants (`turn_into_const_value`).

r? `@lcnr`

cc `@oli-obk` `@RalfJung`
2022-04-16 19:42:03 +02:00
bors
c8422403f7 Auto merge of #96108 - Dylan-DPC:rollup-t5f2fc9, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #93969 (Only add codegen backend to dep info if -Zbinary-dep-depinfo is used)
 - #94605 (Add missing links in platform support docs)
 - #95372 (make unaligned_references lint deny-by-default)
 - #95859 (Improve diagnostics for unterminated nested block comment)
 - #95961 (implement SIMD gather/scatter via vector getelementptr)
 - #96004 (Consider lifetimes when comparing types for equality in MIR validator)
 - #96050 (Remove some now-dead code that was only relevant before deaggregation.)
 - #96070 ([test] Add test cases for untested functions for BTreeMap)
 - #96099 (MaybeUninit array cleanup)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-16 09:19:26 +00:00
Dylan DPC
fd7a1f153d
Rollup merge of #96004 - JakobDegen:fix-validator-ice, r=petrochenkov
Consider lifetimes when comparing types for equality in MIR validator

Closes #95978 .
2022-04-16 07:12:46 +02:00
bors
080d5452e1 Auto merge of #94468 - Amanieu:global_asm_sym, r=nagisa
Implement sym operands for global_asm!

Tracking issue: #93333

This PR is pretty much a complete rewrite of `sym` operand support for inline assembly so that the same implementation can be shared by `asm!` and `global_asm!`. The main changes are:
- At the AST level, `sym` is represented as a special `InlineAsmSym` AST node containing a path instead of an `Expr`.
- At the HIR level, `sym` is split into `SymStatic` and `SymFn` depending on whether the path resolves to a static during AST lowering (defaults to `SynFn` if `get_early_res` fails).
  - `SymFn` is just an `AnonConst`. It runs through typeck and we just collect the resulting type at the end. An error is emitted if the type is not a `FnDef`.
  - `SymStatic` directly holds a path and the `DefId` of the `static` that it is pointing to.
- The representation at the MIR level is mostly unchanged. There is a minor change to THIR where `SymFn` is a constant instead of an expression.
- At the codegen level we need to apply the target's symbol mangling to the result of `tcx.symbol_name()` depending on the target. This is done by calling the LLVM name mangler, which handles all of the details.
  - On Mach-O, all symbols have a leading underscore.
  - On x86 Windows, different mangling is used for cdecl, stdcall, fastcall and vectorcall.
  - No mangling is needed on other platforms.

r? `@nagisa`
cc `@eddyb`
2022-04-16 04:46:01 +00:00
Dylan DPC
ba9c3a13ee
Rollup merge of #96026 - matthiaskrgr:clippy_compl_1304, r=Dylan-DPC
couple of clippy::complexity fixes
2022-04-15 20:50:47 +02:00
Dylan DPC
bdbf0998f3
Rollup merge of #95194 - kckeiks:update-algo-in-find-use-placement, r=pnkfelix
remove find_use_placement

A more robust solution to finding where to place use suggestions was added in #94584.
The algorithm uses the AST to find the span for the suggestion so we pass this span
down to the HIR during lowering and use it instead of calling `find_use_placement`

Fixes #94941
2022-04-15 20:50:45 +02:00
Dylan DPC
a32e0f3041
Rollup merge of #94849 - ouz-a:master4, r=oli-obk
Check var scope if it exist

Fixes #92893.

Added helper function to check the scope of a variable, if it doesn't have a scope call delay_span_bug, which avoids us trying to get a block/scope that doesn't exist.

Had to increase `ROOT_ENTRY_LIMIT` was getting tidy error
2022-04-15 20:50:44 +02:00
Dylan DPC
27e2d811e6
Rollup merge of #94457 - jhpratt:stabilize-derive_default_enum, r=davidtwco
Stabilize `derive_default_enum`

This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](https://github.com/rust-lang/rfcs/pull/3107) and tracked in #87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility).

```````@rustbot``````` label +S-waiting-on-review +T-lang
2022-04-15 20:50:43 +02:00
ouz-a
c20bb1d59f Update issue-92893.stderr 2022-04-14 23:42:15 +03:00
Amanieu d'Antras
dc345d8bff Reimplement lowering of sym operands for asm! so that it also works with global_asm! 2022-04-14 15:32:03 +01:00
Matthias Krüger
7c2d57e0fa couple of clippy::complexity fixes 2022-04-13 22:51:34 +02:00
bors
f38c5c8e5d Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011
Remove NodeIdHashingMode.

r? `@ghost`
2022-04-13 11:27:17 +00:00
Jakob Degen
d5f3863204 Consider lifetimes when comparing types for equality in MIR validator 2022-04-13 05:51:08 -04:00
bors
e3c43e64ec Auto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk
Use mir constant in thir instead of ty::Const

This is blocked on https://github.com/rust-lang/rust/pull/94059 (does include its changes, the first two commits in this PR correspond to those changes) and https://github.com/rust-lang/rust/pull/93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary).

This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`.

Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented.

r? `@oli-obk`
2022-04-13 07:50:56 +00:00
Dylan DPC
d63a46ad28
Rollup merge of #95970 - WaffleLapkin:nicer_trait_suggestions, r=compiler-errors
Fix suggestions in case of `T:` bounds

This PR fixes a corner case in `suggest_constraining_type_params` that was causing incorrect suggestions.

For the following functions:
```rust
fn a<T:>(t: T) { [t, t]; }
fn b<T>(t: T) where T: { [t, t]; }
```

We previously suggested the following:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy:>(t: T) { [t, t]; }
  |       ++++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: + Copy { [t, t]; }
  |                        ++++++
```

Note that neither `T: Copy:` not `where T: + Copy` is a correct bound.

With this commit the suggestions are correct:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy>(t: T) { [t, t]; }
  |         ++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: Copy { [t, t]; }
  |                        ++++
```

r? `@compiler-errors`

I've tried fixing #95898 here too, but got too confused with how `suggest_traits_to_import` works and what it does 😅
2022-04-12 23:17:00 +02:00
Camille GILLOT
443333dc1f Remove NodeIdHashingMode. 2022-04-12 19:59:32 +02:00
Maybe Waffle
de2edb226b Fix wrong suggestions for T:
This commit fixes a corner case in `suggest_constraining_type_params`
that was causing incorrect suggestions.

For the following functions:
```rust
fn a<T:>(t: T) { [t, t]; }
fn b<T>(t: T) where T: { [t, t]; }
```
We previously suggested the following:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy:>(t: T) { [t, t]; }
  |       ++++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: + Copy { [t, t]; }
  |                        ++++++
```
Note that neither `T: Copy:` not `where T: + Copy` is a correct bound.

With this commit the suggestions are correct:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy>(t: T) { [t, t]; }
  |         ++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: Copy { [t, t]; }
  |                        ++++
```
2022-04-12 11:29:23 +04:00
Jakob Degen
8732bf5db3 Remove rule that place loads may not happen with variant index set 2022-04-11 15:56:04 -04:00
Jakob Degen
4bce639c3b Add more clarifications in response to Ralf's comments 2022-04-11 15:56:04 -04:00
Jakob Degen
411ae6f5ad Address various comments and change some details around place to value conversions 2022-04-11 15:22:32 -04:00
Jakob Degen
1d318e42e7 Improve MIR phases documentation with summaries of changes 2022-04-11 15:22:32 -04:00
Jakob Degen
f1f25c0f81 Improve documentation for MIR terminators 2022-04-11 15:22:32 -04:00
Jakob Degen
8e01cd6127 Improve documentation for MIR statement kinds. 2022-04-11 15:22:29 -04:00
Jakob Degen
634369170a Add documentation for the semantics of MIR rvalues 2022-04-11 15:18:54 -04:00
Jakob Degen
2f4a7a0742 Adjust computation of place types to detect more invalid places 2022-04-11 15:18:53 -04:00
Jakob Degen
dae5c842fc Improve documentation of Place and Operand 2022-04-11 15:18:53 -04:00
bors
625e4dd13a Auto merge of #95125 - JakobDegen:uninit-variant-rvalue, r=oli-obk
Add new `Deinit` statement

This rvalue replaces `SetDiscriminant` for ADTs. This PR is an alternative to #94590 , which only specifies that the behavior of `SetDiscriminant` is the same as what this rvalue would do. The motivation for this change are discussed in that PR and [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/SetDiscriminant.20and.20aggregate.20initialization.20.2394590)

r? `@oli-obk`
2022-04-11 14:49:30 +00:00
Jakob Degen
48b01a0d0e Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00
Jakob Degen
4cbe13adab Document semantics of Deinit and SetDiscriminant MIR statements 2022-04-11 08:55:03 -04:00
Jakob Degen
9b6b1a625b Add new Deinit statement kind 2022-04-11 08:55:03 -04:00
Matthias Krüger
053f70332f
Rollup merge of #95907 - compiler-errors:diag, r=Dylan-DPC
address fixme for diagnostic variable name

quick rename
2022-04-11 12:06:57 +02:00
Michael Goulet
137c207d20 FIXME for diagnostic variable name 2022-04-10 11:11:25 -07:00
Camille GILLOT
69d8183337 Store LocalDefId in is_late_bound_map.
This allows to avoid looking at HIR from borrowck.
2022-04-10 13:36:06 +02:00
bors
559c01931b Auto merge of #95435 - cjgillot:one-name, r=oli-obk
Make def names and HIR names consistent.

The name in the `DefKey` is interned to create the `DefId`, so it does not
require any query to access.  This can be leveraged to avoid a few useless
HIR accesses for names.

~In order to achieve that, generic parameters created from universal
impl-trait are given the pretty-printed ast as a name, instead of
`{{opaque}}`.~

~Drive-by: the `TyCtxt::opt_item_name` used a dummy span for non-local
definitions.  We have access to `def_ident_span`, so we use it.~
2022-04-09 22:48:00 +00:00
bors
8c1fb2eb23 Auto merge of #95697 - klensy:no-strings, r=petrochenkov
refactor: simplify few string related interactions

Few small optimizations:

check_doc_keyword: don't alloc string for emptiness check
check_doc_alias_value: get argument as Symbol to prevent needless string convertions
check_doc_attrs: don't alloc vec, iterate over slice.
replace as_str() check with symbol check
get_single_str_from_tts: don't prealloc string
trivial string to str replace
LifetimeScopeForPath::NonElided use Vec<Symbol> instead of Vec<String>
AssertModuleSource use FxHashSet<Symbol> instead of BTreeSet<String>
CrateInfo.crate_name replace FxHashMap<CrateNum, String> with FxHashMap<CrateNum, Symbol>
2022-04-09 13:15:26 +00:00
Dylan DPC
dfb4194e3b
Rollup merge of #95785 - RalfJung:interpret-size-mismatch, r=oli-obk
interpret: err instead of ICE on size mismatches in to_bits_or_ptr_internal

We did this a while ago already for `to_i32()` and friends, but missed this one. That became quite annoying when I was debugging an ICE caused by `read_pointer` in a Miri shim where the code was passing an argument at the wrong type.

Having `scalar_to_ptr` be fallible is consistent with all the other `Scalar::to_*` methods being fallible. I added `unwrap` only in code outside the interpreter, which is no worse off than before now in terms of panics.

r? ````@oli-obk````
2022-04-09 12:52:05 +02:00
Camille GILLOT
f89d64d7aa Use def_key in tcx.item_name when possible. 2022-04-09 10:54:43 +02:00
bors
e980c62955 Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote
Cached stable hash cleanups

r? `@nnethercote`

Add a sanity assertion in debug mode to check that the cached hashes are actually the ones we get if we compute the hash each time.

Add a new data structure that bundles all the hash-caching work to make it easier to re-use it for different interned data structures
2022-04-09 02:31:24 +00:00
Oli Scherer
25d6f8e0f6 Avoid looking at the internals of Interned directly 2022-04-08 15:57:44 +00:00
b-naber
82217a6587 create leafs for slices 2022-04-08 15:45:14 +02:00
b-naber
3be987e076 dont make lit_to_mir_constant a query 2022-04-08 11:56:21 +02:00
klensy
d0cc98689e check_doc_keyword: don't alloc string for emptiness check
check_doc_alias_value: get argument as Symbol to prevent needless string convertions

check_doc_attrs: don't alloc vec, iterate over slice. Vec introduced in #83149, but no perf run posted on merge

replace as_str() check with symbol check

get_single_str_from_tts: don't prealloc string

trivial string to str replace

LifetimeScopeForPath::NonElided use Vec<Symbol> instead of Vec<String>

AssertModuleSource use BTreeSet<Symbol> instead of BTreeSet<String>

CrateInfo.crate_name replace FxHashMap<CrateNum, String> with FxHashMap<CrateNum, Symbol>
2022-04-08 11:45:57 +03:00
Jacob Pratt
abf2b4c04d
Stabilize derive_default_enum 2022-04-07 20:03:19 -04:00
Camille GILLOT
b5dfa6a78d Compute ty_param_owner using DefIdTree. 2022-04-07 22:30:16 +02:00
Ralf Jung
38004b72bc interpret: err instead of ICE on size mismatches in to_bits_or_ptr_internal 2022-04-07 16:24:48 -04:00
Oli Scherer
7d2cad68d2 Deduplicate the error printing code for hidden type mismatches 2022-04-07 13:52:59 +00:00
Oli Scherer
25876b3541 Report opaque type mismatches directly during borrowck of the function instead of within the type_of query.
This allows us to only store a single hidden type per opaque type instead of having to store one per set of substitutions.
2022-04-07 13:39:52 +00:00
Oli Scherer
2e0ef701c2 Document and rename the new wrapper type 2022-04-07 13:01:48 +00:00
b-naber
c3491378e3 get rid of visit_constant in thir visitor 2022-04-06 10:43:58 +02:00
Pietro Albini
181d28bb61
trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00