Commit Graph

269686 Commits

Author SHA1 Message Date
Ralf Jung
36dda4571d add a HACK to allow stdarch migration 2024-10-25 20:31:40 +02:00
Ralf Jung
16b9bb744d get rid of the internal unlikely macro 2024-10-25 20:31:40 +02:00
Ralf Jung
3854e16fa2 proc_macro_harness: adjust the span we use for const fn calls 2024-10-25 20:31:40 +02:00
Ralf Jung
a0215d8e46 Re-do recursive const stability checks
Fundamentally, we have *three* disjoint categories of functions:
1. const-stable functions
2. private/unstable functions that are meant to be callable from const-stable functions
3. functions that can make use of unstable const features

This PR implements the following system:
- `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions.
- `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category.
- `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls.

Also, several holes in recursive const stability checking are being closed.
There's still one potential hole that is hard to avoid, which is when MIR
building automatically inserts calls to a particular function in stable
functions -- which happens in the panic machinery. Those need to *not* be
`rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be
sure they follow recursive const stability. But that's a fairly rare and special
case so IMO it's fine.

The net effect of this is that a `#[unstable]` or unmarked function can be
constified simply by marking it as `const fn`, and it will then be
const-callable from stable `const fn` and subject to recursive const stability
requirements. If it is publicly reachable (which implies it cannot be unmarked),
it will be const-unstable under the same feature gate. Only if the function ever
becomes `#[stable]` does it need a `#[rustc_const_unstable]` or
`#[rustc_const_stable]` marker to decide if this should also imply
const-stability.

Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to
use unstable const lang features (including intrinsics), or (b) `#[stable]`
functions that are not yet intended to be const-stable. Adding
`#[rustc_const_stable]` is only needed for functions that are actually meant to
be directly callable from stable const code. `#[rustc_const_stable_indirect]` is
used to mark intrinsics as const-callable and for `#[rustc_const_unstable]`
functions that are actually called from other, exposed-on-stable `const fn`. No
other attributes are required.
2024-10-25 20:31:40 +02:00
Esteban Küber
5980a32ef1 Pass long type path into note_obligation_cause_code to avoid printing same path multiple times
Because `note_obligation_cause_code` is recursive, if multiple types are too
long to print to the terminal, a `long_ty_file` will be created. Before, one was
created *per recursion*. Now, it is passed in so it gets printed only once.

Part of #132013.
2024-10-25 18:06:39 +00:00
Esteban Küber
aa82fd6d1d Tweak highlighting when trait is available for different type
When printing

```
  = help: the trait `chumsky::private::ParserSealed<'_, &'a str, ((), ()), chumsky::extra::Full<EmptyErr, (), ()>>` is implemented for `Then<Ignored<chumsky::combinator::Filter<chumsky::primitive::Any<&str, chumsky::extra::Full<EmptyErr, (), ()>>, {closure@src/main.rs:9:17: 9:27}>, char>, chumsky::combinator::Map<impl CSTParser<'a, O>, O, {closure@src/main.rs:11:24: 11:27}>, (), (), chumsky::extra::Full<EmptyErr, (), ()>>`
  = help: for that trait implementation, expected `((), ())`, found `()`
```

Highlight only the `expected` and `found` types, instead of the full type in the first `help`.
2024-10-25 18:06:39 +00:00
Esteban Küber
24ac777a64 Add test for #132013 2024-10-25 18:06:36 +00:00
binarycat
09773b4f24 allow type-based search on foreign functions
fixes https://github.com/rust-lang/rust/issues/131804
2024-10-25 12:19:04 -05:00
bors
6faf0bd3e5 Auto merge of #127731 - veluca93:abi_checks, r=RalfJung
Emit future-incompatibility lint when calling/declaring functions with vectors that require missing target feature

On some architectures, vector types may have a different ABI depending on whether the relevant target features are enabled. (The ABI when the feature is disabled is often not specified, but LLVM implements some de-facto ABI.)

As discussed in https://github.com/rust-lang/lang-team/issues/235, this turns out to very easily lead to unsound code.

This commit makes it a post-monomorphization error to declare or call functions using those vector types in a context in which the corresponding target features are disabled, if using an ABI for which the difference is relevant. This ensures that these functions are always called with a consistent ABI.

See the [nomination comment](https://github.com/rust-lang/rust/pull/127731#issuecomment-2288558187) for more discussion.

r? RalfJung

Part of https://github.com/rust-lang/rust/issues/116558
2024-10-25 15:17:47 +00:00
Ralf Jung
3432b91bbc
Merge pull request #3989 from RalfJung/ci
CI workflow: tweak conclusion job
2024-10-25 14:50:10 +00:00
Ralf Jung
cbf6c86f56
Merge pull request #3990 from RalfJung/errno-cleanup
Consistently use io error handlers
2024-10-25 14:45:03 +00:00
Ralf Jung
2350ba7276 some more opportunities for set_last_error_and_return 2024-10-25 16:10:48 +02:00
Ralf Jung
82b041e356 get rid of fd_not_found; improve error handling in FileMetadata 2024-10-25 16:06:03 +02:00
WANG Rui
baa3b6d95e Enable LSX feature for LoongArch Linux targets 2024-10-25 21:35:19 +08:00
Ralf Jung
e5d32b6757 CI workflow: tweak conclusion job 2024-10-25 15:26:44 +02:00
Ralf Jung
a21369fc21
Merge pull request #3984 from noahmbright/unix_shims
Clear `eval_libc` errors from unix shims
2024-10-25 13:19:48 +00:00
Noah Bright
c1004ff861 Clear more eval_libc errors from unix shims 2024-10-25 08:42:23 -04:00
bors
45089ec19e Auto merge of #131207 - davidtwco:pac-ret-lto-test, r=Mark-Simulacrum
ci: aarch64-gnu-debug job

- Adds a new CI job which checks that the compiler builds with `--enable-debug` and tests that `needs-force-clang-based-tests` pass (where cross-language LTO is tested).
- Add a test confirming that `-Zbranch-protection=pac-ret` and cross-language LTO work together.

r? `@Mark-Simulacrum`

try-job: aarch64-gnu-debug
2024-10-25 12:36:24 +00:00
Laurențiu Nicola
08b504ae8f Stop producing .gz artifacts for Windows 2024-10-25 15:14:52 +03:00
Lukas Wirth
57683cfe1f Factor out token ranking 2024-10-25 12:03:12 +02:00
Ralf Jung
854e3c43e0 library: consistently use American spelling for 'behavior' 2024-10-25 12:02:47 +02:00
Lukas Wirth
cf5ab635ab
Merge pull request #18409 from Veykril/veykril/push-rkrkpvzvumvx
Only construct a resolver in macro descension when needed
2024-10-25 08:40:55 +00:00
Lukas Wirth
c6d1f78fa3 Only construct a resolver in macro descension when needed 2024-10-25 10:23:59 +02:00
onur-ozkan
03d23a797d remove change-id from CI script
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-10-25 10:52:23 +03:00
bors
97ae1df8aa Auto merge of #132128 - workingjubilee:rollup-uwqp2i2, r=workingjubilee
Rollup of 4 pull requests

Successful merges:

 - #131457 (Expand `ptr::fn_addr_eq()` documentation.)
 - #132085 (Update StableMIR doc to reflect current status)
 - #132118 (Add support for `~const` item bounds)
 - #132125 (coverage: Emit LLVM intrinsics using the normal helper method)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-25 07:42:32 +00:00
Luca Versari
5af56cac38 Emit error when calling/declaring functions with unavailable vectors.
On some architectures, vector types may have a different ABI when
relevant target features are enabled.

As discussed in https://github.com/rust-lang/lang-team/issues/235, this
turns out to very easily lead to unsound code.

This commit makes it an error to declare or call functions using those
vector types in a context in which the corresponding target features are
disabled, if using an ABI for which the difference is relevant.
2024-10-25 08:46:40 +02:00
Jubilee
7f93af1a1e
Rollup merge of #132125 - Zalathar:coverage-intrinsics, r=jieyouxu
coverage: Emit LLVM intrinsics using the normal helper method

Codegen already has convenient ways to declare and emit LLVM intrinsics, so there's no need for coverage instrumentation to jump through hoops to emit them manually.
2024-10-24 23:23:56 -07:00
Jubilee
3c6d34f4c4
Rollup merge of #132118 - compiler-errors:tilde-const-item-bounds, r=lcnr
Add support for `~const` item bounds

Supports the only missing capability of `~const` associated types that I can think of now (this is obviously excluding `~const` opaques, which I see as an extension to this; I'll probably do that next).

r? ``@lcnr`` mostly b/c it changes candidate assembly, or reassign

cc ``@fee1-dead``
2024-10-24 23:23:56 -07:00
Jubilee
7782b0dd56
Rollup merge of #132085 - celinval:update-smir-doc, r=compiler-errors
Update StableMIR doc to reflect current status

Update stable-mir documentation, since we no longer use git subtree, and we have 2 different crates.
2024-10-24 23:23:55 -07:00
Jubilee
fd78b671a8
Rollup merge of #131457 - kpreid:fnaddr, r=dtolnay
Expand `ptr::fn_addr_eq()` documentation.

* Describe more clearly what is (not) guaranteed, and de-emphasize the description of rustc implementation details.
* Explain what you *can* reliably use it for.

Tracking issue for `ptr_fn_addr_eq`: #129322

The motivation for this PR is that I just learned that `ptr::fn_addr_eq()` exists, read the documentation, and thought: “*I* know what this means, but someone not already familiar with how `rustc` works could be left wondering whether this is even good for anything.” Fixing that seems especially important if we’re going to recommend people use it instead of `==` (as per #118833).
2024-10-24 23:23:54 -07:00
Lukas Wirth
e37c6dc03e
Merge pull request #18408 from Veykril/veykril/push-ulxyznwzokut
fix: Don't compute diagnostics for non local files
2024-10-25 05:55:32 +00:00
Lukas Wirth
bf77cf7f90 Add server cancellation support to pull diagnostic handler 2024-10-25 07:39:28 +02:00
Lukas Wirth
1613548cdb Don't compute diagnostics for non local files 2024-10-25 07:28:29 +02:00
Lukas Wirth
f2d12fff1f
Merge pull request #18407 from hackervole/code-fix-welcome-setup-tips
Fix formatting on welcome page, read only paths setting example
2024-10-25 05:15:39 +00:00
bors
017ae1b21f Auto merge of #132105 - GuillaumeGomez:doctest-nested-main, r=notriddle
[rustdoc] Do not consider nested functions as main function even if named `main` in doctests

Fixes #131893.

If a nested function is called `main`, it is not considered as the entry point of the program. Therefore, doctests should not consider such functions as such either.

r? `@notriddle`
2024-10-25 05:11:05 +00:00
Chayim Refael Friedman
3f638482a3 Shrink TypeRef from 16 from 32 bytes
Only references and arrays need to be boxed, and they comprise only 9.4% of the types (according to counting on r-a's code).

This saves 17mb.
2024-10-25 06:44:56 +03:00
Chayim Refael Friedman
fd7648d920 Shrink Path to 16 bytes
Thanks to the observation (supported by counting) that the vast majority paths have neither generics no type anchors, and thanks to a new datastructure `ThinVecWithHeader` that is essentially `(T, Box<[U]>)` but with the size of a single pointer, we are able to reach this feat.

This (together with `ThinVecWithHeader`) makes the possibility to shrink `TypeRef`, because most types are paths.
2024-10-25 06:44:56 +03:00
Zalathar
8f07514520 coverage: SSA doesn't need to know about instrprof_increment 2024-10-25 14:24:05 +11:00
HackerVole
183796ed0e editors/code: Add md for walkthrough setup example
Add a separate markdown file containing the settings.json snippet from
the "Useful Setup Tips". This fixes the rendering and also makes the
text selectable.

Also use double-backticks for `code` rendering.
2024-10-24 23:20:40 -04:00
Chayim Refael Friedman
61d14ba937 Do not allocate attributes entry if there are no attributes
This saves 8mb.
2024-10-25 06:15:06 +03:00
Chayim Refael Friedman
a16a3d345f Shrink ItemTreeSourceMaps
This saves 16mb on `analysis-stats .`.
2024-10-25 06:15:06 +03:00
Chayim Refael Friedman
fc5bce925c Reuse empty GenericParams
This saves back 15mb that went for typeref source maps.
2024-10-25 06:15:06 +03:00
Chayim Refael Friedman
ab81593ed8 Fix memory usage calculation's queries list 2024-10-25 06:15:06 +03:00
Chayim Refael Friedman
a05b16bdb5 Build source map for hir_def::TypeRefs
So that given a `TypeRef` we will be able to trace it back to source code.

This is necessary to be able to provide diagnostics for lowering to chalk tys, since the input to that is `TypeRef`.

This means that `TypeRef`s now have an identity, which means storing them in arena and not interning them, which is an unfortunate (but necessary) loss but also a pretty massive change. Luckily, because of the separation layer we have for IDE and HIR, this change never crosses the IDE boundary.
2024-10-25 06:15:04 +03:00
Zalathar
b3d65852c3 coverage: Emit MC/DC intrinsics using the normal helper method 2024-10-25 14:01:36 +11:00
Zalathar
4923e856be coverage: Emit llvm.instrprof.increment using the normal helper method 2024-10-25 13:55:44 +11:00
许杰友 Jieyou Xu (Joe)
3528149f73 Introduce Enabled{Lang,Lib}Feature
Instead of passing around random n-tuples of e.g. `(gate_name, attr_sp,
since)`.
2024-10-25 10:30:37 +08:00
Zalathar
0356908cf5 coverage: Store covfun_section_name in the codegen context
Adding an extra `OnceCell` to `CrateCoverageContext` is much nicer than trying
to thread this string through multiple layers of function calls that already
have access to the context.
2024-10-25 12:42:42 +11:00
Zalathar
0a96176533 coverage: Make obtaining the codegen coverage context infallible
In all the situations where this context is needed, it should always be
available.
2024-10-25 12:42:42 +11:00
Zalathar
9f8a6be221 coverage: Consolidate creation of covmap/covfun records
There is no need for this code to be split across multiple functions in
multiple files.
2024-10-25 12:42:23 +11:00