Commit Graph

1036 Commits

Author SHA1 Message Date
bors
8a7ca936e6 Auto merge of #105587 - tgross35:once-cell-min, r=m-ou-se
Partial stabilization of `once_cell`

This PR aims to stabilize a portion of the `once_cell` feature:

- `core::cell::OnceCell`
- `std::cell::OnceCell` (re-export of the above)
- `std::sync::OnceLock`

This will leave `LazyCell` and `LazyLock` unstabilized, which have been moved to the `lazy_cell` feature flag.

Tracking issue: https://github.com/rust-lang/rust/issues/74465 (does not fully close, but it may make sense to move to a new issue)

Future steps for separate PRs:
- ~~Add `#[inline]` to many methods~~ #105651
- Update cranelift usage of the `once_cell` crate
- Update rust-analyzer usage of the `once_cell` crate
- Update error messages discussing once_cell

## To be stabilized API summary

```rust
// core::cell (in core/cell/once.rs)

pub struct OnceCell<T> { .. }

impl<T> OnceCell<T> {
    pub const fn new() -> OnceCell<T>;
    pub fn get(&self) -> Option<&T>;
    pub fn get_mut(&mut self) -> Option<&mut T>;
    pub fn set(&self, value: T) -> Result<(), T>;
    pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T;
    pub fn into_inner(self) -> Option<T>;
    pub fn take(&mut self) -> Option<T>;
}

impl<T: Clone> Clone for OnceCell<T>;
impl<T: Debug> Debug for OnceCell<T>
impl<T> Default for OnceCell<T>;
impl<T> From<T> for OnceCell<T>;
impl<T: PartialEq> PartialEq for OnceCell<T>;
impl<T: Eq> Eq for OnceCell<T>;
```

```rust
// std::sync (in std/sync/once_lock.rs)

impl<T> OnceLock<T> {
    pub const fn new() -> OnceLock<T>;
    pub fn get(&self) -> Option<&T>;
    pub fn get_mut(&mut self) -> Option<&mut T>;
    pub fn set(&self, value: T) -> Result<(), T>;
    pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T;
    pub fn into_inner(self) -> Option<T>;
    pub fn take(&mut self) -> Option<T>;
}

impl<T: Clone> Clone for OnceLock<T>;
impl<T: Debug> Debug for OnceLock<T>;
impl<T> Default for OnceLock<T>;
impl<#[may_dangle] T> Drop for OnceLock<T>;
impl<T> From<T> for OnceLock<T>;
impl<T: PartialEq> PartialEq for OnceLock<T>
impl<T: Eq> Eq for OnceLock<T>;
impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T>;
unsafe impl<T: Send> Send for OnceLock<T>;
unsafe impl<T: Sync + Send> Sync for OnceLock<T>;
impl<T: UnwindSafe> UnwindSafe for OnceLock<T>;
```

No longer planned as part of this PR, and moved to the `rust_cell_try` feature gate:

```rust
impl<T> OnceCell<T> {
    pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>;
}

impl<T> OnceLock<T> {
    pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>;
}
```

I am new to this process so would appreciate mentorship wherever needed.
2023-03-30 10:12:23 +00:00
Trevor Gross
dc4ba57566 Stabilize a portion of 'once_cell'
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-29 18:04:44 -04:00
Santiago Pastorino
66714658d0
Properly skip RPITITs from ModChild and give a name in AssocItem 2023-03-29 11:19:49 -03:00
bors
4c0f5008ce Auto merge of #109547 - matthiaskrgr:rollup-zczqgdk, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #108629 (rustdoc: add support for type filters in arguments and generics)
 - #108924 (panic_immediate_abort requires abort as a panic strategy)
 - #108961 (Refine error spans for const args in hir typeck)
 - #108986 (sync LVI tests)
 - #109142 (Add block-based mutex unlocking example)
 - #109368 (fix typo in the creation of OpenOption for RustyHermit)
 - #109493 (Return nested obligations from canonical response var unification)
 - #109515 (Add AixLinker to support linking on AIX)
 - #109536 (resolve: Rename some cstore methods to match queries and add comments)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-24 02:29:48 +00:00
Matthias Krüger
4d21d302a1
Rollup merge of #109536 - petrochenkov:qcstore3, r=cjgillot
resolve: Rename some cstore methods to match queries and add comments

about costs associated with replacing them with query calls.

Supersedes https://github.com/rust-lang/rust/pull/108346.
r? `@cjgillot`
2023-03-24 01:22:07 +01:00
bors
cf073ec2cb Auto merge of #109202 - compiler-errors:new-solver-fast-reject-faster-2, r=lcnr
Don't pass `TreatProjections` separately to `fast_reject`

Don't pass `TreatProjections` separately to `fast_reject`, and instead use the original approach of switching on two variants of `TreatParams` (undoes this: https://github.com/rust-lang/rust/pull/108830#pullrequestreview-1330371417).

Fixes the regression introduced in https://github.com/rust-lang/rust/pull/108830#issuecomment-1468116419
2023-03-23 23:53:56 +00:00
Michael Goulet
fc0cbe8340 Don't split up TreatProjections and TreatParams anymore 2023-03-23 18:57:02 +00:00
Matthias Krüger
2a39cf560f
Rollup merge of #109231 - Zoxc:fs-non-canon, r=eholk
Add `try_canonicalize` to `rustc_fs_util` and use it over `fs::canonicalize`

This adds `try_canonicalize` which tries to call `fs::canonicalize`, but falls back to `std::path::absolute` if it fails. Existing `canonicalize` calls are replaced with it. `fs::canonicalize` is not guaranteed to work on Windows.
2023-03-23 19:55:45 +01:00
Vadim Petrochenkov
1cec923fbb rustc_metadata: Freeze cstore after the full crate list is queried 2023-03-23 20:44:48 +04:00
Vadim Petrochenkov
71927ad083 resolve: Rename some cstore methods to match queries and add comments
about costs associated with replacing them with query calls.
2023-03-23 20:44:02 +04:00
bors
99c49d95cd Auto merge of #109517 - matthiaskrgr:rollup-m3orqzd, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #108541 (Suppress `opaque_hidden_inferred_bound` for nested RPITs)
 - #109137 (resolve: Querify most cstore access methods (subset 2))
 - #109380 (add `known-bug` test for unsoundness issue)
 - #109462 (Make alias-eq have a relation direction (and rename it to alias-relate))
 - #109475 (Simpler checked shifts in MIR building)
 - #109504 (Stabilize `arc_into_inner` and `rc_into_inner`.)
 - #109506 (make param bound vars visibly bound vars with -Zverbose)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-23 12:35:05 +00:00
Matthias Krüger
3e33fb9f12
Rollup merge of #109137 - petrochenkov:qcstore2, r=cjgillot
resolve: Querify most cstore access methods (subset 2)

These changes are less likely to cause perf regressions than the rest of https://github.com/rust-lang/rust/pull/108346.
2023-03-23 08:35:34 +01:00
Matthias Krüger
577d85f92f
Rollup merge of #109358 - petrochenkov:nosess, r=cjgillot
rustc: Remove unused `Session` argument from some attribute functions

(One auxiliary test file containing one of these functions was unused, so I removed it instead of updating.)
2023-03-22 22:44:41 +01:00
Matthias Krüger
950aa3ef86
Rollup merge of #109213 - oli-obk:cstore, r=cjgillot
Eagerly intern and check CrateNum/StableCrateId collisions

r? ``@cjgillot``

It seems better to check things ahead of time than checking them afterwards.
The [previous version](https://github.com/rust-lang/rust/pull/108390) was a bit nonsensical, so this addresses the feedback
2023-03-22 22:44:40 +01:00
Vadim Petrochenkov
67a2c5bec8 rustc: Remove unused Session argument from some attribute functions 2023-03-22 13:55:55 +04:00
Michael Goulet
c3e6f68931 RPITITs are DefKind::Opaque with new lowering strategy 2023-03-21 23:36:07 +00:00
Santiago Pastorino
c1f3529c91 Always encode RPITITs 2023-03-21 23:35:46 +00:00
Michael Goulet
d213114cb5 LocalCrate key 2023-03-21 15:38:52 +00:00
Michael Goulet
2eb1c08e43 Use local key in providers 2023-03-21 15:38:51 +00:00
Oli Scherer
460ecd288a Eagerly intern and check CrateNum/StableCrateId collisions 2023-03-21 12:08:17 +00:00
Matthias Krüger
cd9fadea5b
Rollup merge of #109362 - nnethercote:split-meta-stats-items, r=bjorn3
Split `items` from `-Zmeta-stats` in two.

Because it's one of the biggest sections.

r? `@bjorn3`
2023-03-20 07:10:34 +01:00
Michael Goulet
4fd66d70cb Update some names and comments 2023-03-20 04:51:53 +00:00
Nicholas Nethercote
cb587e7f61 Split items from -Zmeta-stats in two.
Because it's one of the biggest sections.
2023-03-20 07:23:47 +11:00
Dylan DPC
881c9898ad
Rollup merge of #109324 - cjgillot:fixed-unused-params, r=Nilstrieb
Implement FixedSizeEncoding for UnusedGenericParams.

Using a `Lazy` for actually a `u32` value is 50% overhead, so let's encode the bitset directly.
2023-03-19 15:33:59 +05:30
Dylan DPC
1f0fcf13f5
Rollup merge of #109243 - chenyukang:yukang/fix-ice-109144, r=petrochenkov
The name of NativeLib will be presented

Fixes #109144

I was working on a quick fix, but found change the name from `Option<Symbol>` to `Symbol` make life a little bit easier.
2023-03-19 15:33:59 +05:30
yukang
d5558e67ef The name of NativeLib will be presented 2023-03-19 11:23:19 +08:00
Camille GILLOT
38be6f2cbb Implement FixedSizeEncoding for UnusedGenericParams. 2023-03-18 18:53:07 +00:00
Matthias Krüger
246d989a30
Rollup merge of #109198 - compiler-errors:new-rpitit-default-body, r=spastorino
Install projection from RPITIT to default trait method opaque correctly

1. For new lowering strategy `-Zlower-impl-trait-in-trait-to-assoc-ty`, install the correct default trait method projection predicates (RPITIT -> opaque). This makes default trait body tests pass!

2. Fix two WF-checking bugs -- first, we want to make sure that we're always looking for an opaque type in `check_return_position_impl_trait_in_trait_bounds`. That's because the RPITIT projections are normalized to opaques during wfcheck. Second, fix RPITIT's param-envs by not adding the projection predicates that we install on trait methods to make default RPITITs work -- I left a comment why.

3. Also, just a small drive-by for `rustc_on_unimplemented`. Not sure if it affects any tests, but can't hurt.

r? ````@spastorino,```` based off of #109140
2023-03-17 08:42:40 +01:00
yukang
c22f154e3f Do not ICE for native_lib without name 2023-03-17 07:59:08 +08:00
John Kåre Alsaker
4f7cd3d459 Add try_canonicalize to rustc_fs_util and use it over fs::canonicalize 2023-03-16 21:50:23 +01:00
Vadim Petrochenkov
d99e01fa7e resolve: Remove item_attrs_untracked 2023-03-16 17:22:18 +04:00
Vadim Petrochenkov
f28f77f2d9 resolve: Remove item_generics_num_lifetimes 2023-03-16 17:22:18 +04:00
Santiago Pastorino
26c4c1ea97
Rename impl_trait_in_trait_parent to impl_trait_in_trait_parent_fn 2023-03-15 12:27:16 -03:00
Dylan DPC
2aa3eea5fc
Rollup merge of #109109 - compiler-errors:polymorphize-foreign, r=Nilstrieb
Use `unused_generic_params` from crate metadata

Due to the way that `separate_provide_extern` interacted with the implementation of `<ty::InstanceDef<'tcx> as Key>::query_crate_is_local`, we actually never hit the foreign provider for `unused_generic_params`.

Additionally, since the *local* provider of `unused_generic_params` calls `should_polymorphize`, which always returns false if the def-id is foreign, this means that we never actually polymorphize monomorphic instances originating from foreign crates.

We don't actually encode `unused_generic_params` for items where all generics are used, so I had to tweak the foreign provider to fall back to `ty::UnusedGenericParams::new_all_used()` to avoid more ICEs when the above bugs were fixed.
2023-03-15 17:51:31 +05:30
bors
992d154f3a Auto merge of #109089 - compiler-errors:opt_rpitit_info-follow-up, r=spastorino
Encode `opt_rpitit_info` for associated types

Follow-up, only last commit matters

r? `@spastorino`

This needs a perf run after the parent pr lands
2023-03-15 08:13:23 +00:00
Michael Goulet
0404e264a2 Encode opt_rpitit_info for associated types 2023-03-14 22:10:09 +00:00
Michael Goulet
ee2d42882f Use unused_generic_params from crate metadata 2023-03-14 16:33:12 +00:00
Santiago Pastorino
b535da6841
Get impl defaultness using query 2023-03-14 10:16:19 -03:00
bors
0058748944 Auto merge of #109057 - compiler-errors:rpitit-info-again, r=spastorino
Don't `opt_rpitit_info` as a separate query

... another attempt to undo regressions

r? `@ghost`
2023-03-14 06:42:15 +00:00
bors
bd43458d4c Auto merge of #108992 - petrochenkov:qcstore2, r=cjgillot
resolve: Querify most cstore access methods (subset)

A subset of https://github.com/rust-lang/rust/pull/108346 that is not on a hot path in any way.
2023-03-14 03:38:42 +00:00
Michael Goulet
ce8dae5800 Don't opt_rpitit_info as a separate query 2023-03-13 17:02:47 +00:00
Michael Goulet
84d254ead0 Better names? 2023-03-13 16:34:16 +00:00
Michael Goulet
c32527fb92 Treat projections with infer as placeholder during fast reject in new solver 2023-03-13 16:34:16 +00:00
Vadim Petrochenkov
4a61922ef0 metadata/resolve: Minor refactoring to "tcx -> cstore" conversions 2023-03-13 17:31:55 +04:00
Vadim Petrochenkov
98cce81917 metadata: Remove some more untracked CStore methods 2023-03-13 17:31:55 +04:00
Vadim Petrochenkov
b3ee735993 resolve: Remove struct_field_names_untracked 2023-03-13 17:31:55 +04:00
Vadim Petrochenkov
c7f424b80a resolve: Remove fn_has_self_parameter_untracked 2023-03-13 17:31:54 +04:00
Vadim Petrochenkov
c05b7bd7d0 resolve: Remove struct_field_visibilities_untracked 2023-03-13 17:31:54 +04:00
Vadim Petrochenkov
17127f3e78 resolve: Remove visibility_untracked 2023-03-13 17:31:54 +04:00
bors
f41927f309 Auto merge of #108820 - cjgillot:ensure-on-disk, r=oli-obk
Ensure value is on the on-disk cache before returning from `ensure()`.

The current logic for `ensure()` a query just checks that the node is green in the dependency graph.
However, a lot of places use `ensure()` to prevent the query from being called later. This is the case before stealing a query result.

If the query is actually green but the value is not available in the on-disk cache, `ensure` would return, but a subsequent call to the full query would run the code, and attempt to read from a stolen value.

This PR conforms the query system to the usage by checking whether the queried value is loadable from disk before returning.

Sadly, I can't manage to craft a proper test...

Should fix all instances of "attempted to read from stolen value".
2023-03-12 14:00:28 +00:00
bors
24c0b81c1f Auto merge of #109043 - matthiaskrgr:rollup-genkz0e, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #108726 (tidy: enforce comment blocks to have an even number of backticks)
 - #108797 (Allow binary files to go through the `FileLoader`)
 - #108841 (Add suggestion to diagnostic when user has array but trait wants slice. (rebased))
 - #108984 (bootstrap: document tidy)
 - #109013 (Give proper error message when tcx wasn't passed to decoder)
 - #109017 (remove duplicated calls to sort_string)
 - #109018 (Expand on the allocator comment in `rustc-main`)
 - #109028 (Add eslint checks for rustdoc-js tester)
 - #109034 (Commit some tests for the new solver + lazy norm)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-12 09:44:17 +00:00
Matthias Krüger
738c4bf176
Rollup merge of #109013 - Nilstrieb:obscurity-is-not-a-necessity, r=fee1-dead
Give proper error message when tcx wasn't passed to decoder

I hit this yesterday and found it very confusing, even though the solution to the problem is very simple.
2023-03-12 08:13:27 +01:00
bors
150cb38147 Auto merge of #108794 - nnethercote:avoid-unnecessary-hashing, r=cjgillot
Avoid unnecessary hashing

I noticed some stable hashing being done in a non-incremental build. It turns out that some of this is necessary to compute the crate hash, but some of it is not. Removing the unnecessary hashing is a perf win.

r? `@cjgillot`
2023-03-12 06:48:30 +00:00
bors
501ad021b9 Auto merge of #108682 - est31:simplify_dirs, r=davidtwco
Simplify message paths

This makes it easier to open the messages file. Right now I have to first click on the `locales` dir to open it, and then on the `en-US.ftl` file. `Cargo.toml` and `build.rs` files are also in the top level, and I think there should not be more than one file, so a directory isn't really needed. The [chosen strategy for pontoon adoption](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/pontoon.20and.20next.20steps) is out of tree. Even if this descision is changed in the future, the `messages.ftl` approach is also compatible with non-english translations living in-tree, as long as the non-english translations don't live in the `compiler/rustc_foo/` directories but in different ones. That would also be helpful for grepability purposes.

The commit was the result of automated changes:

```
for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done

for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
```

r? `@davidtwco`
2023-03-12 03:51:21 +00:00
Camille GILLOT
e955ec0908 Use ensure_with_value in a few more places. 2023-03-11 22:42:13 +00:00
est31
7e2ecb3cd8 Simplify message paths
This makes it easier to open the messages file while developing on features.

The commit was the result of automatted changes:

for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done

for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
2023-03-11 22:51:57 +01:00
Nilstrieb
b7a7077ba4 Give proper error message when tcx wasn't passed to decoder 2023-03-11 11:29:08 +01:00
Nicholas Nethercote
9570023ce1 Only compute the crate hash when necessary.
The crate hash is needed:
- if debug assertions are enabled, or
- if incr. comp. is enabled, or
- if metadata is being generated, or
- if `-C instrumentation-coverage` is enabled.

This commit avoids computing the crate hash when these conditions are
all false, such as when doing a release build of a binary crate.

It uses `Option` to store the hashes when needed, rather than
computing them on demand, because some of them are needed in multiple
places and computing them on demand would make compilation slower.

The commit also removes `Owner::hash_without_bodies`. There is no
benefit to pre-computing that one, it can just be done in the normal
fashion.
2023-03-08 09:30:22 +11:00
Santiago Pastorino
c2238527e6
Add tcx::lower_impl_trait_in_trait_to_assoc_ty to avoid accessing through sess.opts.unstable_opts 2023-03-06 11:35:17 -03:00
bors
a512c6c771 Auto merge of #101550 - CraftSpider:link-dead-windows, r=wesleywiser
Make compressed rmeta contain compressed data length after header

Fixes #90056, which is caused by link.exe introducing padding to the `.rustc` section, since it assumes this will have no effect besides allowing it to possibly use the extra space in future links.
2023-03-05 02:00:58 +00:00
est31
6df5ae4fb0 Match unmatched backticks in comments in compiler/ 2023-03-03 08:39:00 +01:00
Santiago Pastorino
73e2fe0494
Properly implement should_encode_fn_impl_trait_in_trait using new unstable option 2023-03-01 14:13:41 -03:00
Rune Tynan
79f0021c16
Update header comment 2023-02-28 15:52:00 -05:00
Michael Goulet
ecac8fd5af Descriptive error when users try to combine RPITIT/AFIT with specialization 2023-02-28 02:03:43 +00:00
Michael Goulet
1a599d7d97
Rollup merge of #107675 - jsgf:link-directives, r=davidtwco
Implement -Zlink-directives=yes/no

`-Zlink-directives=no` will ignored `#[link]` directives while compiling a crate, so nothing is emitted into the crate's metadata.  The assumption is that the build system already knows about the crate's native dependencies and can provide them at link time without these directives.

This is another way to address issue # #70093, which is currently addressed by `-Zlink-native-libraries` (implemented in #70095). The latter is implemented at link time, which has the effect of ignoring `#[link]` in *every* crate. This makes it a very large hammer as it requires all native dependencies to be known to the build system to be at all usable, including those in sysroot libraries. I think this means its effectively unused, and definitely under-used.

Being able to control this on a crate-by-crate basis should make it much easier to apply when needed.

I'm not sure if we need both mechanisms, but we can decide that later.

cc `@pcwalton` `@cramertj`
2023-02-25 11:53:09 -08:00
Nicholas Nethercote
2200911616 Rename many interner functions.
(This is a large commit. The changes to
`compiler/rustc_middle/src/ty/context.rs` are the most important ones.)

The current naming scheme is a mess, with a mix of `_intern_`, `intern_`
and `mk_` prefixes, with little consistency. In particular, in many
cases it's easy to use an iterator interner when a (preferable) slice
interner is available.

The guiding principles of the new naming system:
- No `_intern_` prefixes.
- The `intern_` prefix is for internal operations.
- The `mk_` prefix is for external operations.
- For cases where there is a slice interner and an iterator interner,
  the former is `mk_foo` and the latter is `mk_foo_from_iter`.

Also, `slice_interners!` and `direct_interners!` can now be `pub` or
non-`pub`, which helps enforce the internal/external operations
division.

It's not perfect, but I think it's a clear improvement.

The following lists show everything that was renamed.

slice_interners
- const_list
  - mk_const_list -> mk_const_list_from_iter
  - intern_const_list -> mk_const_list
- substs
  - mk_substs -> mk_substs_from_iter
  - intern_substs -> mk_substs
  - check_substs -> check_and_mk_substs (this is a weird one)
- canonical_var_infos
  - intern_canonical_var_infos -> mk_canonical_var_infos
- poly_existential_predicates
  - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter
  - intern_poly_existential_predicates -> mk_poly_existential_predicates
  - _intern_poly_existential_predicates -> intern_poly_existential_predicates
- predicates
  - mk_predicates -> mk_predicates_from_iter
  - intern_predicates -> mk_predicates
  - _intern_predicates -> intern_predicates
- projs
  - intern_projs -> mk_projs
- place_elems
  - mk_place_elems -> mk_place_elems_from_iter
  - intern_place_elems -> mk_place_elems
- bound_variable_kinds
  - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter
  - intern_bound_variable_kinds -> mk_bound_variable_kinds

direct_interners
- region
  - intern_region (unchanged)
- const
  - mk_const_internal -> intern_const
- const_allocation
  - intern_const_alloc -> mk_const_alloc
- layout
  - intern_layout -> mk_layout
- adt_def
  - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid)
  - alloc_adt_def(!) -> mk_adt_def
- external_constraints
  - intern_external_constraints -> mk_external_constraints

Other
- type_list
  - mk_type_list -> mk_type_list_from_iter
  - intern_type_list -> mk_type_list
- tup
  - mk_tup -> mk_tup_from_iter
  - intern_tup -> mk_tup
2023-02-24 07:32:24 +11:00
Jeremy Fitzhardinge
fc5db2cd4f Implement -Zlink-directives=yes/no
`-Zlink-directives=no` will ignored `#[link]` directives while compiling a
crate, so nothing is emitted into the crate's metadata.  The assumption is
that the build system already knows about the crate's native dependencies
and can provide them at link time without these directives.

This is another way to address issue # #70093, which is currently addressed
by `-Zlink-native-libraries` (implemented in #70095). The latter is
implemented at link time, which has the effect of ignoring `#[link]`
in *every* crate. This makes it a very large hammer as it requires all
native dependencies to be known to the build system to be at all usable,
including those in sysroot libraries. I think this means its effectively
unused, and definitely under-used.

Being able to control this on a crate-by-crate basis should make it much
easier to apply when needed.

I'm not sure if we need both mechanisms, but we can decide that later.
2023-02-22 10:18:01 -08:00
David Wood
d1fcf61117 errors: generate typed identifiers in each crate
Instead of loading the Fluent resources for every crate in
`rustc_error_messages`, each crate generates typed identifiers for its
own diagnostics and creates a static which are pulled together in the
`rustc_driver` crate and provided to the diagnostic emitter.

Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-22 09:15:53 +00:00
Dylan DPC
076e627023
Rollup merge of #108141 - spastorino:add_rpitit_queries, r=compiler-errors
Add rpitit queries

This is part of the changes we are making to lower RPITITs as an associated type. The rest of the stuff will follow under a `-Z` flag.

I still need to add comments to the code, explain stuff and also I'd need to avoid encoding in metadata when rpitit queries return `&[]`

r? `@compiler-errors`
2023-02-21 14:19:59 +05:30
Rune Tynan
c14edf90db
Replace u32_len with constant 2023-02-20 13:38:29 -05:00
Rune Tynan
a9c3eb91e9
Bind header+u32 to variable for clearer math 2023-02-20 13:38:28 -05:00
Rune Tynan
7df53d5e18
Fix metadata encoding and decoding to use the right length 2023-02-20 13:38:27 -05:00
Rune Tynan
dce3947110
Try adding metadata length prefix, and obey it while decoding 2023-02-20 13:38:16 -05:00
Oli Scherer
acbcfaaf7b Stop passing in values that one can also get from the tcx lazily 2023-02-20 15:28:59 +00:00
Oli Scherer
1202fce40e Remove definitions field that is only needed for one method 2023-02-20 15:28:59 +00:00
Oli Scherer
ade3dceb38 Make untracked.cstore lockable so that resolution can still write to it when using TyCtxt 2023-02-20 15:28:58 +00:00
Santiago Pastorino
4e703a2772
Add associated_items_for_impl_trait_in_trait query 2023-02-19 11:18:56 -03:00
Santiago Pastorino
833b9154ac
Make encode_attrs use opt_local_def_id_to_hir_id so we can feed it with None for definitions that have no HIR 2023-02-17 15:56:11 -03:00
Nicholas Nethercote
bcf0ec0191 Replace mk_foo calls with infer_foo where possible.
There are several `mk_foo`/`intern_foo` pairs, where the former takes an
iterator and the latter takes a slice. (This naming convention is bad,
but that's a fix for another PR.)

This commit changes several `mk_foo` occurrences into `intern_foo`,
avoiding the need for some `.iter()`/`.into_iter()` calls. Affected
cases:
- mk_type_list
- mk_tup
- mk_substs
- mk_const_list
2023-02-17 22:24:31 +11:00
bors
9556b56dbd Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU
Switch to `EarlyBinder` for `type_of` query

Part of the work to finish #105779 and implement https://github.com/rust-lang/types-team/issues/78.

Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This adds `EarlyBinder` to the return type of the `type_of` query and removes `bound_type_of`.

r? `@lcnr`
2023-02-17 04:45:15 +00:00
bors
ea218392a4 Auto merge of #108145 - matthiaskrgr:rollup-bgadak1, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #104068 (rustdoc: Add PartialOrd trait to doc comment explanation)
 - #107489 (Implement partial support for non-lifetime binders)
 - #107905 (Pass arguments to `x` subcommands with `--`)
 - #108009 (Move some tests)
 - #108086 (wasm: Register the `relaxed-simd` target feature)
 - #108104 (don't into self)
 - #108133 (Small cleanups around `EarlyBinder`)
 - #108136 (Do not ICE on unmet trait alias impl bounds)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-17 01:14:39 +00:00
Kyle Matsuda
c183110cc2 remove bound_type_of query; make type_of return EarlyBinder; change type_of in metadata 2023-02-16 17:05:56 -07:00
Kyle Matsuda
d822b97a27 change usages of type_of to bound_type_of 2023-02-16 17:01:52 -07:00
Matthias Krüger
e1e58fc1d3
Rollup merge of #108133 - kylematsuda:earlybinder-cleanups, r=compiler-errors
Small cleanups around `EarlyBinder`

Cleaning up a few things that were brought up by `@lcnr` in reviewing #106696:

- [make `issue33140_self_ty` query return `Option<EarlyBinder<Ty>>`](https://github.com/rust-lang/rust/pull/106696#discussion_r1067821423)
- [small style improvement](https://github.com/rust-lang/rust/pull/106696#discussion_r1067816772)
2023-02-17 00:19:37 +01:00
Kyle Matsuda
382ade6a60 fix ugly skip_binder 2023-02-16 10:52:57 -07:00
John Kåre Alsaker
a51a20531d Factor query arena allocation out from query caches 2023-02-16 14:54:53 +01:00
Michael Goulet
eff2cb7760 Rename some region-specific stuff 2023-02-16 03:39:59 +00:00
Camille GILLOT
03dff82d59 Add of_trait to DefKind::Impl. 2023-02-14 19:55:44 +00:00
Vadim Petrochenkov
fd73d01c98 rustc_resolve: Remove Resolver::clone_output
And remove `Clone` impls and `Lrc`s that are no longer necessary
2023-02-13 00:10:15 +04:00
Vadim Petrochenkov
9080b79f2b rustdoc: Eliminate remaining uses of resolver 2023-02-13 00:10:15 +04:00
bors
51cb5614dd Auto merge of #105601 - BelovDV:change-rlib-with-not-stable, r=petrochenkov
Enable new rlib in non stable cases

If bundled static library uses cfg (unstable) or whole-archive (wasn't supported) bundled libs are packed even without packed_bundled_libs.

r? `@petrochenkov`
2023-02-12 07:15:27 +00:00
Daniil Belov
601fc8b36b [link] enable packed bundled lib in non stable cases 2023-02-10 12:51:12 +03:00
Vadim Petrochenkov
b62b82aef4 Resolve documentation links in rustc and store the results in metadata
This commit implements MCP https://github.com/rust-lang/compiler-team/issues/584

It also removes code that is no longer used, and that includes code cloning resolver, so issue #83761 is fixed.
2023-02-10 09:34:13 +04:00
Matthias Krüger
6d225bb080
Rollup merge of #100599 - MatthewPeterKelly:add-E0523-description-and-test, r=compiler-errors,GuillaumeGomez
Add compiler error E0523 long description and test

This PR is one step towards addressing:  https://github.com/rust-lang/rust/issues/61137.
2023-02-07 17:57:13 +01:00
Matthew Kelly
2bcd4e256a Add extended error message for E0523
Adds the extended error documentation for E0523 to indicate that the
error is no longer produced by the compiler.

Update the E0464 documentation to include example code that produces the
error.

Remove the error message E0523 from the compiler and replace it with an
internal compiler error.
2023-02-06 06:58:30 -05:00
Vadim Petrochenkov
f4e2b954a1 rustc_metadata: Encode/decode DefPathHashes without an Option 2023-02-05 18:53:47 +04:00
Vadim Petrochenkov
c60cc43985 rustc_metadata: Encode/decode some LazyArrays without an Option
Also add asserts to decoding `LazyArray`s with `Option`
2023-02-05 18:19:52 +04:00
Vadim Petrochenkov
eb5f2d3980 rustc_metadata: Support encoding/decoding LazyArray without an Option 2023-02-05 18:19:52 +04:00
Vadim Petrochenkov
8cc5aa561c rustc_metadata: Refactor lazy table reading/writing
Change wording from "nullable" to "default".
Introduce a trait `IsDefault` for detecting values that are encoded as zeros or not encoded at all.
Add panics to impossible cases.
Some other minor cleanups.
2023-02-05 18:19:52 +04:00
est31
4442f13b03 rustc_metadata: remove huge error imports 2023-02-05 03:47:38 +01:00
Michael Woerister
227b2858da Retry opening proc-macro DLLs a few times on Windows. 2023-02-02 16:18:16 +01:00
Guillaume Gomez
53bb6322db
Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obk
Improve enum checks

Some light refactoring.
2023-01-31 23:38:52 +01:00
Maybe Waffle
f1d273cbfb Replace some _ == _ || _ == _s with matches!(_, _ | _)s 2023-01-30 12:26:26 +00:00
Maybe Waffle
fd649a3cc5 Replace enum ==s with matches where it makes sense 2023-01-30 12:26:26 +00:00
Camille GILLOT
1d3f5b49d6 Test drop_tracking_mir before querying generator. 2023-01-29 13:50:07 +00:00
bors
bcb064a7f4 Auto merge of #107406 - cjgillot:eliminate-witnesses, r=compiler-errors
Only compute mir_generator_witnesses query in drop_tracking_mir mode.

Attempt to fix the perf regression in https://github.com/rust-lang/rust/pull/101692

r? `@ghost`
2023-01-29 01:27:11 +00:00
Camille GILLOT
15d6325747 Remove HirId -> LocalDefId map from HIR. 2023-01-28 09:55:26 +00:00
Camille GILLOT
4db4860503 Only compute mir_generator_witnesses query in drop_tracking_mir mode. 2023-01-28 08:41:22 +00:00
Camille GILLOT
400cb9aa41 Separate witness type computation from the generator transform. 2023-01-27 19:00:26 +00:00
bors
7919ef0ec5 Auto merge of #107055 - kylematsuda:eb-fn-sig, r=lcnr
Switch to `EarlyBinder` for `fn_sig` query

Part of the work to finish #105779 (also see https://github.com/rust-lang/types-team/issues/78).

Several queries `X` have a `bound_X` variant that wraps the output in [`EarlyBinder`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/subst/struct.EarlyBinder.html). This adds `EarlyBinder` to the return type of the `fn_sig` query and removes `bound_fn_sig`.

r? `@lcnr`
2023-01-27 15:02:44 +00:00
bors
6874f4e3fc Auto merge of #107054 - petrochenkov:effvisdoc3, r=GuillaumeGomez
rustdoc: Collect "rustdoc-reachable" items during early doc link resolution

This pass only needs to know about visibilities, attributes and reexports, so it can be run early, similarly to `compute_effective_visibilities` in rustc.
Results of this pass can be used to prune the list of extern impls early thus improving performance of https://github.com/rust-lang/rust/pull/94857.
2023-01-27 09:01:05 +00:00
Yuki Okushi
eb5e63e3f0
Rollup merge of #107171 - petrochenkov:encattrs, r=cjgillot
rustc_metadata: Fix `encode_attrs`

This function didn't do what the authors intended it to do.

- Due to `move` in the closure `is_public` wasn't captured by mutalbe reference and wasn't used as a cache.
- Due to iterator cloning all the `should_encode_attr` logic run for the second time to calculate `may_have_doc_links`

This PR fixes these issues, and calculates all the needed attribute flags in one go.

(Noticed while implementing https://github.com/rust-lang/rust/pull/107136.)
2023-01-27 12:57:54 +09:00
Kyle Matsuda
c2414dfaa4 change fn_sig query to use EarlyBinder; remove bound_fn_sig query; add EarlyBinder to fn_sig in metadata 2023-01-26 20:28:25 -07:00
Kyle Matsuda
e982971ff2 replace usages of fn_sig query with bound_fn_sig 2023-01-26 20:15:36 -07:00
Matthias Krüger
82455a799e
Rollup merge of #107189 - cjgillot:meta-adt, r=compiler-errors
Encode info for Adt in a single place.

Split from https://github.com/rust-lang/rust/pull/98867
2023-01-26 15:02:21 +01:00
Vadim Petrochenkov
957bc606dd rustdoc: Collect rustdoc-reachable items during early doc link resolution 2023-01-25 23:14:09 +04:00
Vadim Petrochenkov
c70b7aafae rustc_metadata: Fix encode_attrs
This function didn't do what the authors intended it to do.

- Due to `move` in the closure `is_public` wasn't captured by mutalbe reference and wasn't used as a cache.
- Due to iterator cloning all the `should_encode_attr` logic run for the second time to calculate `may_have_doc_links`

This PR fixes these issues, and calculates all the needed attribute flags in one go.
2023-01-25 10:08:48 +04:00
Vadim Petrochenkov
91fdbd7343 rustc_metadata: Support non-Option nullable values in metadata tables
This is a convenience feature for cases in which "no value in the table" and "default value in the table" are equivalent.
Tables using `Table<DefIndex, ()>` are migrated in this PR, some other cases can be migrated later.

This helps `DocFlags` in https://github.com/rust-lang/rust/pull/107136 in particular.
2023-01-23 19:35:03 +04:00
Camille GILLOT
4d11206ee7 Tweak comments. 2023-01-22 11:13:19 +00:00
Camille GILLOT
6ecf30d67d Inline encode_enum_variant_info. 2023-01-22 11:04:53 +00:00
Camille GILLOT
d7f6564fdd Encode AdtDef in the def-id loop. 2023-01-22 11:04:52 +00:00
Vadim Petrochenkov
415c14129b rustc_metadata: Encode doc(hidden) flag to metadata
To retrieve these flags rustdoc currently has to mass decode full attributes for items in the whole crate tree, so it's better to pre-compute it in advance.

This is especially for short-term performance of https://github.com/rust-lang/rust/pull/107054 because resolver cannot use memoization of query results yet.
2023-01-21 22:35:20 +04:00
bors
005fc0f00f Auto merge of #106977 - michaelwoerister:unord_id_collections, r=oli-obk
Use UnordMap and UnordSet for id collections (DefIdMap, LocalDefIdMap, etc)

This PR changes the `rustc_data_structures::define_id_collections!` macro to use `UnordMap` and `UnordSet` instead of `FxHashMap` and `FxHashSet`. This should account for a large portion of hash-maps being used in places where they can cause trouble.

The changes required are moderate but non-zero:
- In some places the collections are extracted into sorted vecs.
- There are a few instances where for-loops have been changed to extends.

~~Let's see what the performance impact is. With a bit more refactoring, we might be able to get rid of some of the additional sorting -- but the change set is already big enough. Unless there's a performance impact, I'd like to do further changes in subsequent PRs.~~

Performance does not seem to be negatively affected ([perf-run here](https://github.com/rust-lang/rust/pull/106977#issuecomment-1396776699)).

Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).

r? `@ghost`
2023-01-21 14:18:17 +00:00
Michael Goulet
7e0b1f1115 Conditionally encode boolean 2023-01-19 16:09:10 +00:00
Michael Goulet
200f466d1a Encode whether foreign opaques are TAITs or not 2023-01-19 15:45:49 +00:00
Michael Woerister
72ee14ce39 Allow for more efficient sorting when exporting Unord collections. 2023-01-19 10:40:54 +01:00
Michael Woerister
c3d2573120 Use UnordMap instead of FxHashMap in define_id_collections!(). 2023-01-19 10:40:47 +01:00
Michael Goulet
a637e2a950
Rollup merge of #106917 - compiler-errors:const-closure-foreign, r=tmiasko
Encode const mir for closures if they're const

Fixes #106913
2023-01-18 18:00:29 -05:00
Matthias Krüger
68f12338af
Rollup merge of #104505 - WaffleLapkin:no-double-spaces-in-comments, r=jackh726
Remove double spaces after dots in comments

Most of the comments do not have double spaces, so I assume these are typos.
2023-01-17 20:21:25 +01:00
Maybe Waffle
6a28fb42a8 Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
Michael Goulet
3a4fdcf86c Encode const mir for closures if they're const 2023-01-16 14:59:27 +00:00
Kyle Matsuda
6e969ea85e fix various subst_identity vs skip_binder 2023-01-14 00:30:03 -07:00
Kyle Matsuda
f29a334c90 change impl_trait_ref query to return EarlyBinder; remove bound_impl_trait_ref query; add EarlyBinder to impl_trait_ref in metadata 2023-01-14 00:29:56 -07:00
Kyle Matsuda
be130b57d4 change usages of impl_trait_ref to bound_impl_trait_ref 2023-01-14 00:23:32 -07:00
Kyle Matsuda
ef58baf8b8 change const_param_default query to return EarlyBinder; remove bound_const_param_default query; add EarlyBinder to const_param_default in metadata 2023-01-14 00:13:07 -07:00
Kyle Matsuda
bd6c63597b change usages of const_param_default query to bound_const_param_default 2023-01-14 00:13:07 -07:00
Deadbeef
6e63f7be54 attempt to make a minimal example work 2023-01-12 02:28:37 +00:00
Nilstrieb
2855794257 Use newtype for unused generic parameters 2023-01-09 19:10:00 +01:00
nils
fd7a159710 Fix uninlined_format_args for some compiler crates
Convert all the crates that have had their diagnostic migration
completed (except save_analysis because that will be deleted soon and
apfloat because of the licensing problem).
2023-01-05 19:01:12 +01:00
bors
3b1c8a94a4 Auto merge of #105609 - bjorn3:shrink_rustc_dev, r=jyn514
Only include metadata for non-dynamic libraries in rustc-dev

The actual object code should be linked from librustc_driver.so, which is still included in rustc-dev. This saves on download time and disk usage.

Fixes https://github.com/rust-lang/rust/issues/103538
2023-01-03 08:05:54 +00:00
bjorn3
7837058073 Add help for the error message when missing rustc_driver 2022-12-31 17:20:13 +00:00
Ezra Shaw
24b39ece2f
refactor: merge E0465 into E0464 2022-12-31 20:44:54 +13:00
bors
83a28ef095 Auto merge of #106129 - compiler-errors:compare_method-tweaks, r=BoxyUwU
Some `compare_method` tweaks

1. Make some of the comparison functions' names more regular
2. Reduce pub scope of some of the things in `compare_method`
~3. Remove some unnecessary opaque type handling code -- `InferCtxt` already is in a mode that doesn't define opaque types~
  * moved to a different PR
4. Bubble up `ErrorGuaranteed` for region constraint errors in `compare_method` - Improves a redundant error message in one unit test.
5. Move the `compare_method` module to have a more general name, since it's more like `compare_impl_item` :)
6. Rename `collect_trait_impl_trait_tys`
2022-12-28 13:07:30 +00:00
Michael Goulet
96d8011fa8 better names and a comment 2022-12-28 04:18:37 +00:00
Matthias Krüger
23967a9990
Rollup merge of #106137 - matthiaskrgr:clippy_style, r=jyn514
fix more clippy::style findings

match_result_ok
obfuscated_if_else
single_char_add
writeln_empty_string
collapsible_match
iter_cloned_collect
unnecessary_mut_passed

r? `@compiler-errors`
2022-12-25 22:15:00 +01:00
Matthias Krüger
6689d2df08
Rollup merge of #105955 - Nilstrieb:no-trivial-opt-wrappers-we-have-field-accesses-for-that, r=cjgillot
Remove wrapper functions for some unstable options

They are trivial and just forward to the option. Like most other options, we can just access it directly.
2022-12-25 22:15:00 +01:00
Matthias Krüger
d8874f259a fix more clippy::style findings
match_result_ok
obfuscated_if_else
single_char_add
writeln_empty_string
collapsible_match
iter_cloned_collect
unnecessary_mut_passed
2022-12-25 17:32:26 +01:00
KaDiWa
7b371d2ad9
fix some typos 2022-12-25 00:43:50 +01:00
Matthias Krüger
d23cb738d2
Rollup merge of #105975 - jeremystucki:rustc-remove-needless-lifetimes, r=eholk
rustc: Remove needless lifetimes
2022-12-24 00:31:41 +01:00
Nilstrieb
d846cf0971 A few metadata nits 2022-12-22 23:21:00 +01:00