Commit graph

192 commits

Author SHA1 Message Date
Nicholas Nethercote ca5525d564 Improve AdtDef interning.
This commit makes `AdtDef` use `Interned`. Much the commit is tedious
changes to introduce getter functions. The interesting changes are in
`compiler/rustc_middle/src/ty/adt.rs`.
2022-03-11 13:31:24 +11:00
Nicholas Nethercote 4f008e06c3 Clarify Layout interning.
`Layout` is another type that is sometimes interned, sometimes not, and
we always use references to refer to it so we can't take any advantage
of the uniqueness properties for hashing or equality checks.

This commit renames `Layout` as `LayoutS`, and then introduces a new
`Layout` that is a newtype around an `Interned<LayoutS>`. It also
interns more layouts than before. Previously layouts within layouts
(via the `variants` field) were never interned, but now they are. Hence
the lifetime on the new `Layout` type.

Unlike other interned types, these ones are in `rustc_target` instead of
`rustc_middle`. This reflects the existing structure of the code, which
does layout-specific stuff in `rustc_target` while `TyAndLayout` is
generic over the `Ty`, allowing the type-specific stuff to occur in
`rustc_middle`.

The commit also adds a `HashStable` impl for `Interned`, which was
needed. It hashes the contents, unlike the `Hash` impl which hashes the
pointer.
2022-03-07 13:41:47 +11:00
Nicholas Nethercote 4852291417 Introduce ConstAllocation.
Currently some `Allocation`s are interned, some are not, and it's very
hard to tell at a use point which is which.

This commit introduces `ConstAllocation` for the known-interned ones,
which makes the division much clearer. `ConstAllocation::inner()` is
used to get the underlying `Allocation`.

In some places it's natural to use an `Allocation`, in some it's natural
to use a `ConstAllocation`, and in some places there's no clear choice.
I've tried to make things look as nice as possible, while generally
favouring `ConstAllocation`, which is the type that embodies more
information. This does require quite a few calls to `inner()`.

The commit also tweaks how `PartialOrd` works for `Interned`. The
previous code was too clever by half, building on `T: Ord` to make the
code shorter. That caused problems with deriving `PartialOrd` and `Ord`
for `ConstAllocation`, so I changed it to build on `T: PartialOrd`,
which is slightly more verbose but much more standard and avoided the
problems.
2022-03-07 08:25:50 +11:00
mark e489a94dee rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
Tomasz Miąsko f047af24b3 Normalize main return type during mono item collection & codegen 2022-02-23 22:33:50 +01:00
bjorn3 f596dce542 Merge commit '35d9c6bf256968e1b40e0d554607928bdf9cebea' into sync_cg_clif-2022-02-23 2022-02-23 11:49:34 +01:00
Matthias Krüger 1cf2e6993e
Rollup merge of #94169 - Amanieu:asm_stuff, r=nagisa
Fix several asm! related issues

This is a combination of several fixes, each split into a separate commit. Splitting these into PRs is not practical since they conflict with each other.

Fixes #92378
Fixes #85247

r? ``@nagisa``
2022-02-22 12:16:28 +01:00
Amanieu d'Antras fc41d4bf35 Take CodegenFnAttrs into account when validating asm! register operands
Checking of asm! register operands now properly takes function
attributes such as #[target_feature] and #[instruction_set] into
account.
2022-02-21 18:28:22 +00:00
Amanieu d'Antras 1ceb104851 On ARM, use relocation_model to detect whether r9 should be reserved
The previous approach of checking for the reserve-r9 target feature
didn't actually work because LLVM only sets this feature very late when
initializing the per-function subtarget.
2022-02-21 18:28:22 +00:00
lcnr 1245131a11 use List<Ty<'tcx>> for tuples 2022-02-21 07:09:11 +01:00
Mark Rousskov 9763486034 Move ty::print methods to Drop-based scope guards 2022-02-16 17:24:23 -05:00
Nicholas Nethercote a95fb8b150 Overhaul Const.
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as
this:
```
pub struct Const<'tcx>(&'tcx Interned<ConstS>);
```
This now matches `Ty` and `Predicate` more closely, including using
pointer-based `eq` and `hash`.

Notable changes:
- `mk_const` now takes a `ConstS`.
- `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a
  we need separate arena for it, because we can't use the `Dropless` one any
  more.
- Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes
- Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes.
- Lots of tedious sigil fiddling.
2022-02-15 16:19:59 +11:00
Nicholas Nethercote 7024dc523a Overhaul RegionKind and Region.
Specifically, change `Region` from this:
```
pub type Region<'tcx> = &'tcx RegionKind;
```
to this:
```
pub struct Region<'tcx>(&'tcx Interned<RegionKind>);
```

This now matches `Ty` and `Predicate` more closely.

Things to note
- Regions have always been interned, but we haven't been using pointer-based
  `Eq` and `Hash`. This is now happening.
- I chose to impl `Deref` for `Region` because it makes pattern matching a lot
  nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`.
- Various methods are moved from `RegionKind` to `Region`.
- There is a lot of tedious sigil changes.
- A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a
  `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`.
- A couple of test outputs change slightly, I'm not sure why, but the new
  outputs are a little better.
2022-02-15 16:08:52 +11:00
Nicholas Nethercote e9a0c429c5 Overhaul TyS and Ty.
Specifically, change `Ty` from this:
```
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
```
to this
```
pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>);
```
There are two benefits to this.
- It's now a first class type, so we can define methods on it. This
  means we can move a lot of methods away from `TyS`, leaving `TyS` as a
  barely-used type, which is appropriate given that it's not meant to
  be used directly.
- The uniqueness requirement is now explicit, via the `Interned` type.
  E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather
  than via `TyS`, which wasn't obvious at all.

Much of this commit is boring churn. The interesting changes are in
these files:
- compiler/rustc_middle/src/arena.rs
- compiler/rustc_middle/src/mir/visit.rs
- compiler/rustc_middle/src/ty/context.rs
- compiler/rustc_middle/src/ty/mod.rs

Specifically:
- Most mentions of `TyS` are removed. It's very much a dumb struct now;
  `Ty` has all the smarts.
- `TyS` now has `crate` visibility instead of `pub`.
- `TyS::make_for_test` is removed in favour of the static `BOOL_TY`,
  which just works better with the new structure.
- The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls
  of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned`
  (pointer-based, for the `Equal` case) and partly on `TyS`
  (contents-based, for the other cases).
- There are many tedious sigil adjustments, i.e. adding or removing `*`
  or `&`. They seem to be unavoidable.
2022-02-15 16:03:24 +11:00
bjorn3 609784711a Unconditionally update symbols
All paths to an ArchiveBuilder::build call update_symbols first.
2022-02-10 18:27:18 +01:00
pierwill 4f89224f7f Use an indexmap to avoid sorting LocalDefIds
Update `indexmap` to 1.8.0.

Bless test
2022-01-22 22:34:16 -06:00
lcnr 4bd571c4ff remove is_noop 2022-01-19 13:58:29 +01:00
bjorn3 042aa379a5 Pass target_features set instead of has_feature closure
This avoids unnecessary monomorphizations in codegen backends
2022-01-17 18:06:30 +01:00
bjorn3 991cbd1503 Use Symbol for target features in asm handling
This saves a couple of Symbol::intern calls
2022-01-17 18:06:27 +01:00
bors a34c079752 Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes #70173.
Closes #92794.
Closes #87612.
Closes #82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
2022-01-17 09:40:29 +00:00
Ellen 71bbb603f4 initial revert 2022-01-15 01:16:55 +00:00
Tomasz Miąsko 000b36c505 Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
Aaron Hill 450ef8613c
Store a Symbol instead of an Ident in VariantDef/FieldDef
The field is also renamed from `ident` to `name. In most cases,
we don't actually need the `Span`. A new `ident` method is added
to `VariantDef` and `FieldDef`, which constructs the full `Ident`
using `tcx.def_ident_span()`. This method is used in the cases
where we actually need an `Ident`.

This makes incremental compilation properly track changes
to the `Span`, without all of the invalidations caused by storing
a `Span` directly via an `Ident`.
2022-01-11 10:16:22 -05:00
Matthias Krüger 57a4f4a634
Rollup merge of #90102 - nbdd0121:box3, r=jonas-schievink
Remove `NullOp::Box`

Follow up of #89030 and MCP rust-lang/compiler-team#460.

~1 month later nothing seems to be broken, apart from a small regression that #89332 (1aac85bb716c09304b313d69d30d74fe7e8e1a8e) shows could be regained by remvoing the diverging path, so it shall be safe to continue and remove `NullOp::Box` completely.

r? `@jonas-schievink`
`@rustbot` label T-compiler
2022-01-03 14:44:15 +01:00
bjorn3 a8e6d5b04d Merge commit '40b00f4200fbdeefd11815398cb46394b8cb0a5e' into sync_cg_clif-2021-12-30 2021-12-30 14:53:41 +01:00
bjorn3 3426a730ff Merge commit '97e504549371d7640cf011d266e3c17394fdddac' into sync_cg_clif-2021-12-20 2021-12-20 18:56:35 +01:00
bors a41a6925ba Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
Remove `SymbolStr`

This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences.

Best reviewed one commit at a time.

r? `@oli-obk`
2021-12-19 09:31:37 +00:00
Nicholas Nethercote 056d48a2c9 Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
Nicholas Nethercote 8cddcd39ba Remove SymbolStr.
By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!
2021-12-15 13:30:26 +11:00
Matthias Krüger ccfc22b6d8
Rollup merge of #91868 - tmiasko:llvm-time-trace-out, r=oli-obk
Use `OutputFilenames` to generate output file for `-Zllvm-time-trace`

The resulting profile will include the crate name and will be stored in
the `--out-dir` directory.

This implementation makes it convenient to use LLVM time trace together
with cargo, in the contrast to the previous implementation which would
overwrite profiles or store them in `.cargo/registry/..`.
2021-12-15 01:28:06 +01:00
Amanieu d'Antras d1204ac3b1 Remove invalid doc links. 2021-12-13 20:40:17 +00:00
Tomasz Miąsko 3f2a1c9c17 Use OutputFilenames to generate output file for -Zllvm-time-trace
The resulting profile will include the crate name and will be stored in
the `--out-dir` directory.

This implementation makes it convenient to use LLVM time trace together
with cargo, in the contrast to the previous implementation which would
overwrite profiles or store them in `.cargo/registry/..`.
2021-12-13 00:00:00 +00:00
Mara Bos 1acb44f03c Use IntoIterator for array impl everywhere. 2021-12-04 19:40:33 +01:00
cynecx 6cbf44f1d4 cg_cranelift: check may_unwind flag instead of cleanup 2021-12-03 23:51:49 +01:00
cynecx 91021de1f6 LLVM codgen support for unwinding inline assembly 2021-12-03 23:51:49 +01:00
Petr Sumbera 128ceec92d fix sparc64 ABI for aggregates with floating point members 2021-12-01 10:03:45 +01:00
Gary Guo 1b7f5a3818 Remove NullOp::Box 2021-10-20 19:42:35 +01:00
Camille GILLOT aa404c24dd Make hash_result an Option. 2021-10-20 18:29:18 +02:00
Amanieu d'Antras 8007dfa3b2 Remove alloc::prelude
As per the libs team decision in #58935.

Closes #58935
2021-10-15 01:41:31 +02:00
Deadbeef 5387b6542f
Add const_eval_select intrinsic 2021-10-12 05:42:23 +00:00
bors 44995f7afb Auto merge of #89619 - michaelwoerister:incr-vtables, r=nagisa
Turn vtable_allocation() into a query

This PR removes the untracked vtable-const-allocation cache from the `tcx` and turns the `vtable_allocation()` method into a query.

The change is pretty straightforward and should be backportable without too much effort.

Fixes https://github.com/rust-lang/rust/issues/89598.
2021-10-08 09:04:06 +00:00
Michael Woerister b7cc99142a Turn tcx.vtable_allocation() into a query. 2021-10-07 20:03:00 +02:00
Camille GILLOT 8961616e60 Move rustc_middle::middle::cstore to rustc_session. 2021-10-03 16:08:51 +02:00
Camille Gillot 79d14751a3 Update compiler/rustc_codegen_cranelift/scripts/filter_profile.rs
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2021-09-30 19:41:32 +02:00
Camille GILLOT b244b98e7c Move EncodedMetadata to rustc_metadata. 2021-09-30 19:41:32 +02:00
Camille GILLOT df54d3980b Move encode_metadata out of CrateStore. 2021-09-30 19:41:31 +02:00
bors b2804655f5 Auto merge of #89092 - bjorn3:sync_cg_clif-2021-09-19, r=bjorn3
Sync rustc_codegen_cranelift

Nothing exciting this time. Mostly internal refactorings.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
2021-09-26 23:31:01 +00:00
Gary Guo c38da2e0a3 Introduce Rvalue::ShallowInitBox 2021-09-25 01:08:41 +01:00
Mark Rousskov c746be2219 Migrate to 2021 2021-09-20 22:21:42 -04:00
Mark Rousskov 5e1a614b53 Adjust to SourceType::InTree in several places
These were left over in migrations to subtrees, which should generally be treated
as-if it was local.

Also fixes a warning caused by this change.
2021-09-20 08:45:39 -04:00