Commit graph

220875 commits

Author SHA1 Message Date
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
bors f98598c6cd Auto merge of #108089 - Zoxc:windows-tls, r=bjorn3
Support TLS access into dylibs on Windows

This allows access to `#[thread_local]`  in upstream dylibs on Windows by introducing a MIR shim to return the address of the thread local. Accesses that go into an upstream dylib will call the MIR shim to get the address of it.

`convert_tls_rvalues` is introduced in `rustc_codegen_ssa` which rewrites MIR TLS accesses to dummy calls which are replaced with calls to the MIR shims when the dummy calls are lowered to backend calls.

A new `dll_tls_export` target option enables this behavior with a `false` value which is set for Windows platforms.

This fixes https://github.com/rust-lang/rust/issues/84933.
2023-03-29 16:20:37 +00:00
John Kåre Alsaker d499bbb99d Use #[cfg(target_thread_local)] on items 2023-03-29 14:50:10 +02:00
bors 8679208664 Auto merge of #109670 - lqd:init-mask, r=oli-obk
Make init mask lazy for fully initialized/uninitialized const allocations

There are a few optimization opportunities in the `InitMask` and related const `Allocation`s (e.g. by taking advantage of the fact that it's a bitset that represents initialization, which is often entirely initialized or uninitialized in a single call, or gradually built up, etc).

There's a few overwrites to the same state, multiple writes in a row to the same indices, the RLE scheme for `memcpy` doesn't always compress, etc.

Here, we start with:
- avoiding materializing the bitset's blocks if the allocation is fully initialized/uninitialized
- dealloc blocks when fully overwriting, including when participating in `memcpy`s
- take care of the fixme about allocating blocks of 0s before overwriting them to the expected value
- expanding unit test coverage of the init mask

This should be most visible on benchmarks and crates where const allocations dominate the runtime (like `ctfe-stress-5` of course), but I was especially looking at the worst cases from #93215.

This first change allows the majority of `set_range` calls to stay with a lazy init mask when bootstrapping rustc (not that the init mask is a big part of the process in cpu time or memory usage).

r? `@oli-obk`

I have another in-progress branch where I'll switch the singular initialized/uninitialized value to a watermark, recording the point after which everything is uninitialized. That will take care of cases where full initialization is monotonic and done in multiple steps (e.g. an array of a type without padding), which should then allow the vast majority of const allocations' init masks to stay lazy during bootstrapping (though interestingly I've seen such gradual initialization in both left-to-right and right-to-left directions, and I don't think a single watermark can handle both).
2023-03-29 12:43:59 +00:00
bors cf32b9de1e Auto merge of #109720 - Dylan-DPC:rollup-u564m8s, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #108335 (rustdoc + rustdoc-json support for `feature(non_lifetime_binders)`)
 - #109534 (rustdoc: Unsupport importing `doc(primitive)` and `doc(keyword)` modules)
 - #109659 (llvm-wrapper: adapt for LLVM API change)
 - #109664 (Use span of placeholders in format_args!() expansion.)
 - #109683 (Check for overflow in `assemble_candidates_after_normalizing_self_ty`)
 - #109713 (Fix mismatched punctuation in Debug impl of AttrId)
 - #109718 (Rename `IndexVec::last` → `last_index`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-29 09:45:26 +00:00
Dylan DPC 14157561fb
Rollup merge of #109718 - scottmcm:indexvec-last, r=Nilstrieb
Rename `IndexVec::last` → `last_index`

As I've been trying to replace a `Vec` with an `IndexVec`, having `last` exist on both but returning very different types makes the transition a bit awkward -- the errors are later, where you get things like "there's no `ty` method on `mir::Field`" rather than a more localized error like "hey, there's no `last` on `IndexVec`".

So I propose renaming `last` to `last_index` to help distinguish `Vec::last`, which returns an element, and `IndexVec::last_index`, which returns an index.

(Similarly, `Iterator::last` also returns an element, not an index.)
2023-03-29 14:07:31 +05:30
Dylan DPC 2a4455d141
Rollup merge of #109713 - dtolnay:debugattrid, r=compiler-errors
Fix mismatched punctuation in Debug impl of AttrId

I noticed this odd line in `ast-tree` output.

```console
$ echo '#[attr] struct S;' | rustc -Zunpretty=ast-tree -
```

```rust
...
            attrs: [
                Attribute {
                    kind: Normal(
                        NormalAttr {
                            item: AttrItem {
                                path: Path {
                                    segments: [
                                        PathSegment {
                                            ident: attr#0,
                                            args: None,
                                        },
                                    ],
                                    tokens: None,
                                },
                                args: Empty,
                            },
                        },
                    ),
                    id: AttrId(0)],      // <------
                    style: Outer,
                },
```
2023-03-29 14:07:30 +05:30
Dylan DPC 09e937744a
Rollup merge of #109683 - compiler-errors:self-ty-overflow, r=lcnr
Check for overflow in `assemble_candidates_after_normalizing_self_ty`

Prevents a stack overflow (⚠️ ) in the new solver when we have param-env candidates that look like: `T: Trait<Assoc = <T as Trait>::Assoc>`

The current error message looks bad, but that's because we don't distinguish overflow and other ambiguity errors. I'll break that out into a separate PR since the fix may be controversial.

r? `@lcnr`
2023-03-29 14:07:29 +05:30
Dylan DPC a3eb2f0f22
Rollup merge of #109664 - m-ou-se:format-args-placeholder-span, r=oli-obk
Use span of placeholders in format_args!() expansion.

`format_args!("{}", x)` expands to something that contains `Argument::new_display(&x)`. That entire expression was generated with the span of `x`.

After this PR, `&x` uses the span of `x`, but the `new_display` call uses the span of the `{}` placeholder within the format string. If an implicitly captured argument was used like in `format_args!("{x}")`, both use the span of the `{x}` placeholder.

This fixes https://github.com/rust-lang/rust/issues/109576, and also allows for more improvements to similar diagnostics in the future, since the usage of `x` can now be traced to the exact `{}` placeholder that required it to be `Display` (or `Debug` etc.)
2023-03-29 14:07:28 +05:30
Dylan DPC 39f93d3c98
Rollup merge of #109659 - krasimirgg:llvm17lto, r=nikic
llvm-wrapper: adapt for LLVM API change

Adapts the wrapper for the LLVM commit 377e1311d5.

Found by the experimental rust + LLVM @ HEAD bot: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/18141#01872217-de22-4826-b0d6-2dd4884d8893
2023-03-29 14:07:27 +05:30
Dylan DPC 1db9eae033
Rollup merge of #109534 - petrochenkov:noprimuse, r=GuillaumeGomez
rustdoc: Unsupport importing `doc(primitive)` and `doc(keyword)` modules

These are internal features used for a specific purpose, and modules without imports are enough for that purpose.
2023-03-29 14:07:27 +05:30
Dylan DPC 777df024b1
Rollup merge of #108335 - compiler-errors:non_lifetime_binders-rustdoc, r=GuillaumeGomez
rustdoc + rustdoc-json support for `feature(non_lifetime_binders)`

Makes `for<T> T: Trait` and `for<const N: usize> ..` in where clause operate correctly.

Fixes #108158
2023-03-29 14:07:26 +05:30
Scott McMurray 843c5e361e Rename IndexVec::lastlast_index
As I've been trying to replace a `Vec` with an `IndexVec`, having `last` exist on both but returning very different types makes the transition a bit awkward -- the errors are later, where you get things like "there's no `ty` method on `mir::Field`" rather than a more localized error like "hey, there's no `last` on `IndexVec`".

So I propose renaming `last` to `last_index` to help distinguish `Vec::last`, which returns an element, and `IndexVec::last_index`, which returns an index.

(Similarly, `Iterator::last` also returns an element, not an index.)
2023-03-29 00:27:24 -07:00
bors f346fb0bc6 Auto merge of #108792 - Amanieu:ohos, r=petrochenkov
Add OpenHarmony targets

- `aarch64-unknown-linux-ohos`
- `armv7-unknown-linux-ohos`

Compiler team MCP: https://github.com/rust-lang/compiler-team/issues/568
2023-03-29 07:16:16 +00:00
John Kåre Alsaker 3019a341f3 Use #[inline] on Windows for thread local access 2023-03-29 08:55:25 +02:00
John Kåre Alsaker 0d89c6a2d4 Support TLS access into dylibs on Windows 2023-03-29 08:55:21 +02:00
bors 40cd0310db Auto merge of #109714 - matthiaskrgr:rollup-wipns5h, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #109149 (Improve error message when writer is forgotten in write and writeln macro)
 - #109367 (Streamline fast rejection)
 - #109548 (AnnotationColumn struct to fix hard tab column numbers in errors)
 - #109694 (do not panic on failure to acquire jobserver token)
 - #109705 (new solver: check for intercrate mode when accessing the cache)
 - #109708 (Specialization involving RPITITs is broken so ignore the diagnostic differences)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-29 04:23:06 +00:00
Matthias Krüger 439c68ceeb
Rollup merge of #109708 - spastorino:new-rpitit-20, r=compiler-errors
Specialization involving RPITITs is broken so ignore the diagnostic differences

Just bless the corresponding test for `-Zlower-impl-trait-in-trait-to-assoc-ty`

r? `@compiler-errors`
2023-03-29 06:02:43 +02:00
Matthias Krüger 9d6c36e70b
Rollup merge of #109705 - lcnr:coherence-caching, r=compiler-errors
new solver: check for intercrate mode when accessing the cache

r? ``@compiler-errors``
2023-03-29 06:02:43 +02:00
Matthias Krüger 09c139846b
Rollup merge of #109694 - BelovDV:fix-panic-jobserver-token, r=bjorn3
do not panic on failure to acquire jobserver token

Purpose: remove `panic`.

Rust fails to acquire token if an error in build system occurs - environment variable contains incorrect `jobserver-auth`. It isn't ice so compiler shouldn't panic on such error.

Related issue: #46981
2023-03-29 06:02:42 +02:00
Matthias Krüger 6be27b19a6
Rollup merge of #109548 - pommicket:better-column-numbers-with-hard-tabs, r=petrochenkov
AnnotationColumn struct to fix hard tab column numbers in errors

Fixes #109537

i don't know if this is the best way of fixing this but it works
2023-03-29 06:02:42 +02:00
Matthias Krüger ba2164306a
Rollup merge of #109367 - nnethercote:opt-fast-rejection, r=compiler-errors
Streamline fast rejection

Some reworkings of this code that make it a little nicer.

r? `@lcnr`
2023-03-29 06:02:41 +02:00
Matthias Krüger 23813d8720
Rollup merge of #109149 - mj10021:issue-108713-fix, r=compiler-errors,WaffleLapkin
Improve error message when writer is forgotten in write and writeln macro

Modified write! macro error message when writer is forgotten as in issue #108713

Fixes #108713

r? ``@WaffleLapkin``
2023-03-29 06:02:41 +02:00
John Kåre Alsaker 51c93553d4 Test that TLS access works outside of the dylib it's defined in 2023-03-29 05:56:11 +02:00
David Tolnay c5da0619d1
Fix mismatched punctuation in Debug impl of AttrId 2023-03-28 20:21:23 -07:00
bors acd27bb557 Auto merge of #109612 - scottmcm:instcombine-transmutes, r=cjgillot
Simplify transmutes in MIR InstCombine

Thanks to the combination of #108246 and #108442 it could already remove identity transmutes.

With this PR, it can also simplify them to `IntToInt` casts, `Discriminant` reads, or `Field` projections.
2023-03-29 01:51:11 +00:00
Scott McMurray f20af8d43d Simplify transmutes in MIR InstCombine
Thanks to the combination of #108246 and #108442 it could already remove identity transmutes.

With this PR, it can also simplify them to `IntToInt` casts, `Discriminant` reads, or `Field` projections.
2023-03-28 18:18:10 -07:00
bors cdbbce0a9e Auto merge of #108095 - soc:drop-contains, r=Amanieu
Drop unstable `Option::contains`, `Result::contains`, `Result::contains_err`

This is a proposal to drop the three functions `Option::contains`, `Result::contains` and `Result::contains_err`.

The discovery of `Option::is_some_with`/`Result::is_ok_with`/`Result::is_err_with` in https://github.com/rust-lang/rust/pull/93051 obviates the need for these methods (non-stabilization tracked in https://github.com/rust-lang/rust/issues/62358).

An additional benefit of change is that it avoids spurious error messages in IDEs, when `contains` is supplied by a third-party library:
![option-result-unstable](https://user-images.githubusercontent.com/42493/219127961-13cb559e-6ee8-4449-8dc9-d28d07270ad5.png)
2023-03-28 23:20:30 +00:00
Santiago Pastorino eb7f64582d
Specialization involving RPITITs is broken so ignore the diagnostic differences for them 2023-03-28 17:54:24 -03:00
Nicholas Nethercote 03923661af Inline and remove SelectionContext::fast_reject_trait_refs.
Because it has a single call site, and it lets us move a small amount of
the work outside the loop.
2023-03-29 06:48:52 +11:00
Nicholas Nethercote 9fa69473fd Inline and remove generic_args_may_unify.
It has a single callsite.
2023-03-29 06:48:52 +11:00
Nicholas Nethercote 47225e8700 Introduce DeepRejectCtxt::substs_refs_may_unify.
It factors out a repeated code pattern.
2023-03-29 06:48:48 +11:00
lcnr 27a3b10ed2 check for intercrate mode when accessing the cache 2023-03-28 21:45:35 +02:00
Michael Goulet ef5f773bff Check for overflow in assemble_candidates_after_normalizing_self_ty 2023-03-28 17:07:01 +00:00
Michael Goulet be9fd75d32 rustdoc + rustdoc-json support for non_lifetime_binders 2023-03-28 16:50:49 +00:00
bors 478cbb42b7 Auto merge of #109692 - Nilstrieb:rollup-hq65rps, r=Nilstrieb
Rollup of 8 pull requests

Successful merges:

 - #91793 (socket ancillary data implementation for FreeBSD (from 13 and above).)
 - #92284 (Change advance(_back)_by to return the remainder instead of the number of processed elements)
 - #102472 (stop special-casing `'static` in evaluation)
 - #108480 (Use Rayon's TLV directly)
 - #109321 (Erase impl regions when checking for impossible to eagerly monomorphize items)
 - #109470 (Correctly substitute GAT's type used in `normalize_param_env` in `check_type_bounds`)
 - #109562 (Update ar_archive_writer to 0.1.3)
 - #109629 (remove obsolete `givens` from regionck)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-28 15:18:16 +00:00
Amanieu d'Antras e3968be331 Add OpenHarmony targets
- `aarch64-unknown-linux-ohos`
- `armv7-unknown-linux-ohos`
2023-03-28 16:01:13 +01:00
Daniil Belov be6a09f96b [fix] don't panic on failure to acquire jobserver token 2023-03-28 17:22:30 +03:00
Vadim Petrochenkov 52b15b4bf9 rustdoc: Unsupport importing doc(primitive) and doc(keyword) modules
These are internal features used for a specific purpose, and modules without imports are enough for that purpose.
2023-03-28 17:31:39 +04:00
Rémy Rakic a857ba25f9 address review comments
Move tests and limit the init mask's structures/fields visibility.
2023-03-28 13:22:01 +00:00
pommicket b82608aa56 Create AnnotationColumn struct to fix hard tab column numbers in errors 2023-03-28 09:18:55 -04:00
bors bf57e8ada6 Auto merge of #108080 - oli-obk:FnPtr-trait, r=lcnr
Add a builtin `FnPtr` trait that is implemented for all function pointers

r? `@ghost`

Rebased version of https://github.com/rust-lang/rust/pull/99531 (plus adjustments mentioned in the PR).

If perf is happy with this version, I would like to land it, even if the diagnostics fix in 9df8e1befb5031a5bf9d8dfe25170620642d3c59 only works for `FnPtr` specifically, and does not generally improve blanket impls.
2023-03-28 12:50:01 +00:00
nils 60ce19d848
Rollup merge of #109629 - aliemjay:remove-givens, r=lcnr
remove obsolete `givens` from regionck

Revives #107376. The only change is the last commit (2a3177a8bc) which should fix the regression.

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

r? `@lcnr`
2023-03-28 12:51:14 +02:00
nils ef5ef53a6f
Rollup merge of #109562 - bjorn3:update_ar_archive_writer, r=Mark-Simulacrum
Update ar_archive_writer to 0.1.3

This updates object to 0.30 and fixes a bug where the symbol table would be omitted for archives where there are object files yet none that export any symbol. This bug could lead to linker errors for crates like rustc_std_workspace_core which don't contain any code of their own but exist solely for their dependencies. This is likely the cause of the linker issues I was experiencing on Webassembly. It has been shown to cause issues on other platforms too.

cc rust-lang/ar_archive_writer#5
2023-03-28 12:51:14 +02:00
nils 7e90732abe
Rollup merge of #109470 - compiler-errors:gat-normalize-bound, r=jackh726
Correctly substitute GAT's type used in `normalize_param_env` in `check_type_bounds`

Given:

```rust
trait Foo {
    type Assoc<T>: PartialEq<Self::Assoc<i32>>;
}

impl Foo for () {
    type Assoc<T> = Wrapper<T>;
}

struct Wrapper<T>(T);

impl<T> PartialEq<Wrapper<i32>> for Wrapper<T> { }
```

We add an additional predicate in the `normalize_param_env` in `check_type_bounds` that is used to normalize the GAT's bounds to check them in the impl. Problematically, though, that predicate is constructed to be `for<^0> <() as Foo>::Assoc<^0> => Wrapper<T>`, instead of `for<^0> <() as Foo>::Assoc<^0> => Wrapper<^0>`.

That means `Self::Assoc<i32>` in the bounds that we're checking normalizes to `Wrapper<T>`, instead of `Wrapper<i32>`, and so the bound `Self::Assoc<T>: PartialEq<Self::Assoc<i32>>` normalizes to `Wrapper<T>: PartialEq<Wrapper<T>>`, which does not hold.

Fixes this by properly substituting the RHS of that normalizes predicate that we add to the `normalize_param_env`. That means the bound is properly normalized to `Wrapper<T>: PartialEq<Wrapper<i32>>`, which *does* hold.

---

The second commit in this PR just cleans up some substs stuff and some naming.

r? `@jackh726` cc #87900
2023-03-28 12:51:13 +02:00
nils 64710790d6
Rollup merge of #109321 - compiler-errors:illegal-mono-w-regions, r=cjgillot
Erase impl regions when checking for impossible to eagerly monomorphize items

We were inserting `ReErased` for method substs, but not for impl substs, leading to the call for `subst_and_check_impossible_predicates` being a bit weaker than it should be (since it ignores predicates that need substitution -- incl early-bound regions).

Fixes #109297
2023-03-28 12:51:13 +02:00
nils c31f75209f
Rollup merge of #108480 - Zoxc:rayon-tlv, r=cuviper
Use Rayon's TLV directly

This accesses Rayon's `TLV` thread local directly avoiding wrapper functions. This makes rustc work with https://github.com/rust-lang/rustc-rayon/pull/10.

r? `@cuviper`
2023-03-28 12:51:12 +02:00
nils 4bd33fdb4a
Rollup merge of #102472 - lcnr:static-in-eval, r=jackh726
stop special-casing `'static` in evaluation

fixes #102360

I have no idea whether this actually removed all places where `'static` matters. Without canonicalization it's very easy to accidentally rely on `'static` again. Blocked on changing the `order_dependent_trait_objects` future-compat lint to a hard error

r? `@nikomatsakis`
2023-03-28 12:51:12 +02:00
nils 0883848882
Rollup merge of #92284 - the8472:simplify-advance-by, r=scottmcm
Change advance(_back)_by to return the remainder instead of the number of processed elements

When advance_by can't advance the iterator by the number of requested elements it now returns the amount by which it couldn't be advanced instead of the amount by which it did.

This simplifies adapters like chain, flatten or cycle because the remainder doesn't have to be calculated as the difference between requested steps and completed steps anymore.

Additionally switching from `Result<(), usize>` to `Result<(), NonZeroUsize>` reduces the size of the result and makes converting from/to a usize representing the number of remaining steps cheap.
2023-03-28 12:51:11 +02:00
nils 857b631616
Rollup merge of #91793 - devnexen:anc_data_fbsd, r=ChrisDenton
socket ancillary data implementation for FreeBSD (from 13 and above).

introducing new build config as well.
2023-03-28 12:51:10 +02:00