Commit Graph

41308 Commits

Author SHA1 Message Date
Matthias Krüger
fbed195b4d
Rollup merge of #133226 - compiler-errors:opt-in-pointer-like, r=lcnr
Make `PointerLike` opt-in instead of built-in

The `PointerLike` trait currently is a built-in trait that computes the layout of the type. This is a bit problematic, because types implement this trait automatically. Since this can be broken due to semver-compatible changes to a type's layout, this is undesirable. Also, calling `layout_of` in the trait system also causes cycles.

This PR makes the trait implemented via regular impls, and adds additional validation on top to make sure that those impls are valid. This could eventually be `derive()`d for custom smart pointers, and we can trust *that* as a semver promise rather than risking library authors accidentally breaking it.

On the other hand, we may never expose `PointerLike`, but at least now the implementation doesn't invoke `layout_of` which could cause ICEs or cause cycles.

Right now for a `PointerLike` impl to be valid, it must be an ADT that is `repr(transparent)` and the non-1zst field needs to implement `PointerLike`. There are also some primitive impls for `&T`/ `&mut T`/`*const T`/`*mut T`/`Box<T>`.
2024-11-20 20:10:13 +01:00
Matthias Krüger
7fc2b33722
Rollup merge of #132708 - estebank:const-as-binding, r=Nadrieril
Point at `const` definition when used instead of a binding in a `let` statement

Modify `PatKind::InlineConstant` to be `ExpandedConstant` standing in not only for inline `const` blocks but also for `const` items. This allows us to track named `const`s used in patterns when the pattern is a single binding. When we detect that there is a refutable pattern involving a `const` that could have been a binding instead, we point at the `const` item, and suggest renaming. We do this for both `let` bindings and `match` expressions missing a catch-all arm if there's at least one single binding pattern referenced.

After:

```
error[E0005]: refutable pattern in local binding
  --> $DIR/bad-pattern.rs:19:13
   |
LL |     const PAT: u32 = 0;
   |     -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable
...
LL |         let PAT = v1;
   |             ^^^ pattern `1_u32..=u32::MAX` not covered
   |
   = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
   = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
   = note: the matched value is of type `u32`
help: introduce a variable instead
   |
LL |         let PAT_var = v1;
   |             ~~~~~~~
```

Before:

```
error[E0005]: refutable pattern in local binding
  --> $DIR/bad-pattern.rs:19:13
   |
LL |         let PAT = v1;
   |             ^^^
   |             |
   |             pattern `1_u32..=u32::MAX` not covered
   |             missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable
   |             help: introduce a variable instead: `PAT_var`
   |
   = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
   = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
   = note: the matched value is of type `u32`
```

CC #132582.
2024-11-20 20:10:12 +01:00
Michael Goulet
228068bc6e Make PointerLike opt-in as a trait 2024-11-20 16:36:12 +00:00
Michael Goulet
06e66d78c3 Rip out built-in PointerLike impl 2024-11-20 16:13:57 +00:00
Matthias Krüger
b1413e0583
Rollup merge of #133241 - RalfJung:typing-env, r=lcnr
interpret: make typing_env field private

This was made public in https://github.com/rust-lang/rust/pull/133212 but IMO it should remain private. (Specifically, this prevents it from being mutated.)

r? `@lcnr`
2024-11-20 15:48:29 +01:00
Matthias Krüger
d3326564b2
Rollup merge of #133239 - kleisauke:fix-llvm-triple-x86_64-win7-windows-msvc, r=ChrisDenton
Fix LLVM target triple for `x86_64-win7-windows-msvc`

The vendor field needs to be `pc` rather than `win7`.
2024-11-20 15:48:28 +01:00
Ralf Jung
d04088fa36 interpret: make typing_env field private 2024-11-20 11:05:53 +01:00
Kleis Auke Wolthuizen
57ed8e8436 Fix LLVM target triple for x86_64-win7-windows-msvc
The vendor field needs to be `pc` rather than `win7`.
2024-11-20 10:47:28 +01:00
bors
fda6892747 Auto merge of #133234 - jhpratt:rollup-42dmg4p, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - #132732 (Use attributes for `dangling_pointers_from_temporaries` lint)
 - #133108 (lints_that_dont_need_to_run: never skip future-compat-reported lints)
 - #133190 (CI: use free runner in dist-aarch64-msvc)
 - #133196 (Make rustc --explain compatible with BusyBox less)
 - #133216 (Implement `~const Fn` trait goal in the new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-20 09:27:56 +00:00
Jacob Pratt
b9cd5eb190
Rollup merge of #133216 - compiler-errors:const-fn, r=lcnr
Implement `~const Fn` trait goal in the new solver

Split out from https://github.com/rust-lang/rust/pull/132329 since this should be easier to review on its own.

r? lcnr
2024-11-20 01:54:27 -05:00
Jacob Pratt
cd36973a13
Rollup merge of #133196 - omnivagant:correct-less-r-flag, r=tgross35
Make rustc --explain compatible with BusyBox less

busybox less does not support the -r flag and less(1) says:

  USE OF THE -r OPTION IS NOT RECOMMENDED.
2024-11-20 01:54:26 -05:00
Jacob Pratt
a175db1424
Rollup merge of #133108 - RalfJung:future-compat-needs-to-run, r=lcnr
lints_that_dont_need_to_run: never skip future-compat-reported lints

Follow-up to https://github.com/rust-lang/rust/pull/125116: future-compat lints show up with `--json=future-incompat` even if they are otherwise allowed in the crate. So let's ensure we do not skip those as part of the `lints_that_dont_need_to_run` logic.

I could not find a current future compat lint that is emitted by a lint pass, so there's no clear way to add a test for this.

Cc `@blyxyas` `@cjgillot`
2024-11-20 01:54:25 -05:00
Jacob Pratt
25dc4d0394
Rollup merge of #132732 - gavincrawford:as_ptr_attribute, r=Urgau
Use attributes for `dangling_pointers_from_temporaries` lint

Checking for dangling pointers by function name isn't ideal, and leaves out certain pointer-returning methods that don't follow the `as_ptr` naming convention. Using an attribute for this lint cleans things up and allows more thorough coverage of other methods, such as `UnsafeCell::get()`.
2024-11-20 01:54:24 -05:00
bors
70e814bd9e Auto merge of #133212 - lcnr:questionable-uwu, r=compiler-errors
continue `ParamEnv` to `TypingEnv` transition

cc #132279

r? `@compiler-errors`
2024-11-20 06:22:01 +00:00
bors
bcfea1f8d2 Auto merge of #133194 - khuey:master, r=jieyouxu
Drop debug info instead of panicking if we exceed LLVM's capability to represent it

Recapping a bit of history here:

In #128861 I made debug info correctly represent parameters to inline functions by removing a fake lexical block that had been inserted to suppress LLVM assertions and by deduplicating those parameters.

LLVM, however, expects to see a single parameter _with distinct locations_, particularly distinct inlinedAt values on the DILocations. This generally worked because no matter how deep the chain of inlines it takes two different call sites in the original function to result in the same function being present multiple times, and a function call requires a non-zero number of characters, but macros threw a wrench in that in #131944. At the time I thought the issue there was limited to proc-macros, where an arbitrary amount of code can be generated at a single point in the source text.

In #132613 I added discriminators to DILocations that would otherwise be the same to repair #131944[^1]. This works, but LLVM's capacity for discriminators is not infinite (LLVM actually only allocates 12 bits for this internally). At the time I thought it would be very rare for anyone to hit the limit, but #132900 proved me wrong. In the relatively-minimized test case it also became clear to me that the issue affects regular macros too, because the call to the inlined function will (without collapse_debuginfo on the macro) be attributed to the (repeated, if the macro is used more than once) textual callsite in the macro definition.

This PR fixes the panic by dropping debug info when we exceed LLVM's maximum discriminator value. There's also a preceding commit for a related but distinct issue: macros that use collapse_debuginfo should in fact have their inlinedAts collapsed to the macro callsite and thus not need discriminators at all (and not panic/warn accordingly when the discriminator limit is exhausted).

Fixes #132900

r? `@jieyouxu`

[^1]: Editor's note: `fix` is a magic keyword in PR description that apparently will close the linked issue (it's closed already in this case, but still).
2024-11-20 02:10:50 +00:00
bors
875df370be Auto merge of #133219 - matthiaskrgr:rollup-hnuq0zf, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #123947 (Add vec_deque::Iter::as_slices and friends)
 - #125405 (Add std:🧵:add_spawn_hook.)
 - #133175 (ci: use free runner in dist-i686-msvc)
 - #133183 (Mention std::fs::remove_dir_all in std::fs::remove_dir)
 - #133188 (Add `visit` methods to ast nodes that already have `walk`s on ast visitors)
 - #133201 (Remove `TokenKind::InvalidPrefix`)
 - #133207 (Default-enable `llvm_tools_enabled` when no `config.toml` is present)
 - #133213 (Correct the tier listing of `wasm32-wasip2`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-19 23:04:44 +00:00
Matthias Krüger
49aec06ab0
Rollup merge of #133207 - jieyouxu:macos-objcopy, r=Kobzol,bjorn3
Default-enable `llvm_tools_enabled` when no `config.toml` is present

Fixes #133195. cc `@wesleywiser` could you double check if with this patch and no `config.toml` that you can run `./x test tests/ui --stage 1`?

`llvm-objcopy` is usually required by cg_ssa on macOS to workaround bad `strip`s.

cc `@bjorn3` I hope this doesn't break cg_clif...

r? bootstrap
2024-11-19 22:24:47 +01:00
Matthias Krüger
841243f319
Rollup merge of #133201 - nnethercote:rm-TokenKind-InvalidPrefix, r=compiler-errors
Remove `TokenKind::InvalidPrefix`

It's not needed. Best reviewed one commit at a time.

r? `@estebank`
2024-11-19 22:24:47 +01:00
Matthias Krüger
022bb9c3bb
Rollup merge of #133188 - maxcabrajac:walk_no_visit, r=petrochenkov
Add `visit` methods to ast nodes that already have `walk`s on ast visitors

Some `walk` functions are called directly, because there were no correspondent visit functions.

related to #128974 & #127615

r? `@petrochenkov`
2024-11-19 22:24:46 +01:00
Michael Goulet
def7ed08e7 Implement ~const Fn trait goals in the new solver 2024-11-19 21:22:17 +00:00
Ralf Jung
df94818366 lints_that_dont_need_to_run: never skip future-compat-reported lints 2024-11-19 22:04:10 +01:00
lcnr
002efeb72a additional TypingEnv cleanups 2024-11-19 21:36:23 +01:00
lcnr
d61effe58f resolve_instance: stop relying on Reveal 2024-11-19 21:36:23 +01:00
lcnr
7a90e84f4d InterpCx store TypingEnv instead of a ParamEnv 2024-11-19 21:36:23 +01:00
bors
ee612c45f0 Auto merge of #132761 - nnethercote:resolve-tweaks, r=petrochenkov
Resolve tweaks

A couple of small perf improvements, and some minor refactorings, all in `rustc_resolve`.

r? `@petrochenkov`
2024-11-19 19:54:35 +00:00
lcnr
b9dea31ea9 TypingMode::from_param_env begone 2024-11-19 19:32:52 +01:00
lcnr
4813fda2e6 rustdoc: yeet TypingEnv::from_param_env 2024-11-19 18:35:41 +01:00
lcnr
f74951fdf1 generic_const_exprs: yeet TypingEnv::from_param_env 2024-11-19 18:06:20 +01:00
lcnr
ffd7a50314 impl trait overcaptures, yeet TypingMode::from_param_env 2024-11-19 18:06:20 +01:00
lcnr
07a5272476 pattern lowering, yeet TypingEnv::from_param_env 2024-11-19 18:06:20 +01:00
lcnr
decf37bd16 liveness checking, yeet TypingEnv::from_param_env 2024-11-19 18:06:20 +01:00
lcnr
1ec964873e unconditional recursion, yeet TypingEnv::from_param_env 2024-11-19 18:06:20 +01:00
lcnr
948cec0fad move fn is_item_raw to TypingEnv 2024-11-19 18:06:20 +01:00
gavincrawford
01fd384d58
Correct comments concerning updated dangling pointer lint 2024-11-19 10:05:24 -07:00
bors
78993684f2 Auto merge of #133205 - matthiaskrgr:rollup-xhhhp5u, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #131081 (Use `ConstArgKind::Path` for all single-segment paths, not just params under `min_generic_const_args`)
 - #132577 (Report the `unexpected_cfgs` lint in external macros)
 - #133023 (Merge `-Zhir-stats` into `-Zinput-stats`)
 - #133200 (ignore an occasionally-failing test in Miri)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-19 16:31:58 +00:00
bors
89b6885529 Auto merge of #133164 - RalfJung:promoted-oom, r=jieyouxu
interpret: do not ICE when a promoted fails with OOM

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

try-job: aarch64-apple
try-job: dist-x86_64-linux
2024-11-19 13:24:09 +00:00
Kyle Huey
f5b023bd9c When the required discriminator value exceeds LLVM's limits, drop the debug info for the function instead of panicking.
The maximum discriminator value LLVM can currently encode is 2^12. If macro use
results in more than 2^12 calls to the same function attributed to the same
callsite, and those calls are MIR-inlined, we will require more than the maximum
discriminator value to completely represent the debug information. Once we reach
that point drop the debug info instead.
2024-11-19 05:19:09 -08:00
Kyle Huey
1e4ebb0ccd Honor collapse_debuginfo when dealing with MIR-inlined functions inside macros.
The test relies on the fact that inlining more than 2^12 calls at the same
callsite will trigger a panic (and after the following commit, a warning) due to
LLVM limitations but with collapse_debuginfo the callsites should not be the
same.
2024-11-19 05:18:56 -08:00
Jieyou Xu
4b5c88301b Explicitly disable llvm tools for cranelift 2024-11-19 20:29:54 +08:00
bors
7d40450b2d Auto merge of #132623 - nnethercote:rustc_borrowck-cleanups-2, r=Nadrieril
`rustc_borrowck` cleanups, part 2

The code under `do_mir_borrowck` is pretty messy, especially the various types like `MirBorrowckCtxt`, `BorrowckInferCtxt`, `MirTypeckResults`, `MirTypeckRegionConstraints`, `CreateResult`, `TypeChecker`, `TypeVerifier`, `LivenessContext`, `LivenessResults`. This PR does some tidying up, though there's still plenty of mess left afterwards.

A sequel to #132250.

r? `@compiler-errors`
2024-11-19 08:32:27 +00:00
Matthias Krüger
f25fee3349
Rollup merge of #133023 - samestep:hir-stats-total-count, r=nnethercote
Merge `-Zhir-stats` into `-Zinput-stats`

Currently `-Z hir-stats` prints the size and count of various kinds of nodes, and the total size of all the nodes it counted, but not the total count of nodes. So, before this PR:

```
$ git clone https://github.com/BurntSushi/ripgrep
$ cd ripgrep
$ cargo +nightly rustc -- -Z hir-stats
ast-stats-1 PRE EXPANSION AST STATS
ast-stats-1 Name                Accumulated Size         Count     Item Size
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 ...
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 Total                 93_576
ast-stats-1
ast-stats-2 POST EXPANSION AST STATS
ast-stats-2 Name                Accumulated Size         Count     Item Size
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 ...
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 Total              2_430_648
ast-stats-2
hir-stats HIR STATS
hir-stats Name                Accumulated Size         Count     Item Size
hir-stats ----------------------------------------------------------------
hir-stats ...
hir-stats ----------------------------------------------------------------
hir-stats Total              3_678_512
hir-stats
```

For consistency, this PR adds a total for the count as well:

```
$ cargo +stage1 rustc -- -Z hir-stats
ast-stats-1 PRE EXPANSION AST STATS
ast-stats-1 Name                Accumulated Size         Count     Item Size
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 ...
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 Total                 93_576                 1_877
ast-stats-1
ast-stats-2 POST EXPANSION AST STATS
ast-stats-2 Name                Accumulated Size         Count     Item Size
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 ...
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 Total              2_430_648                48_625
ast-stats-2
hir-stats HIR STATS
hir-stats Name                Accumulated Size         Count     Item Size
hir-stats ----------------------------------------------------------------
hir-stats ...
hir-stats ----------------------------------------------------------------
hir-stats Total              3_678_512                73_418
hir-stats
```

I wasn't sure if I was supposed to update `tests/ui/stats/hir-stats.stderr` to reflect this. I ran it locally, thinking it would fail, but it didn't:

```
$ ./x test tests/ui/stats
...

running 2 tests
i.

test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 17949 filtered out
```

Also: is there a reason `-Z hir-stats` and `-Z input-stats` both exist? The former seems like it should completely supercede the latter. But strangely, the two give very different numbers for node counts:

```
$ cargo +nightly rustc -- -Z input-stats
...
Lines of code:             483
Pre-expansion node count:  2386
Post-expansion node count: 63844
```

That's a 30% difference in this case. Is it intentional that these numbers are so different? I see comments for both saying that they are merely approximations and should not be expected to be correct:

bd0826a452/compiler/rustc_ast_passes/src/node_count.rs (L1)

bd0826a452/compiler/rustc_passes/src/hir_stats.rs (L1-L3)
2024-11-19 09:19:20 +01:00
Matthias Krüger
47200547f3
Rollup merge of #132577 - Urgau:check-cfg-report-extern-macro, r=petrochenkov
Report the `unexpected_cfgs` lint in external macros

This PR marks the `unexpected_cfgs` lint as being reportable in external macros, as it's probably not the intention of the macro author to leave ineffective cfgs in the users code.

Fixes #132572

try-job: aarch64-gnu-debug
2024-11-19 09:19:19 +01:00
Matthias Krüger
5f586efd3e
Rollup merge of #131081 - camelid:const-path-it-all, r=BoxyUwU
Use `ConstArgKind::Path` for all single-segment paths, not just params under `min_generic_const_args`

r? `@BoxyUwU`

edit by `@BoxyUwU:`

This PR introduces a `min_generic_const_args` feature gate and implements some preliminary work for it, representing all const arguments that are single segment paths as `ConstArg::Path` instead of only those that resolve to a const generic parameter. There are a few bits of follow up work after this lands:
- Figure out how to represent `Foo<{ STATIC }>`
- Figure out how to evaluate `Foo<{ EnumVariantConstructor }>`
- Make param env normalization handle non-anon-consts
- Move `try_from_lit` and `from_anon_const` to hir ty lowering too
2024-11-19 09:19:17 +01:00
Nicholas Nethercote
e9a0c3c98c Remove TokenKind::InvalidPrefix.
It was added in #123752 to handle some cases involving emoji, but it
isn't necessary because it's always treated the same as
`TokenKind::InvalidIdent`. This commit removes it, which makes things a
little simpler.
2024-11-19 18:06:22 +11:00
Nicholas Nethercote
2c7c3697db Improve TokenKind comments.
- Improve wording.
- Use backticks consistently for examples.
2024-11-19 18:04:01 +11:00
Nicholas Nethercote
df29f9b0c3 Improve fake_ident_or_unknown_prefix.
- Rename it as `invalid_ident_or_prefix`, which matches the possible
  outputs (`InvalidIdent` or `InvalidPrefix`).
- Use the local wrapper for `is_xid_continue`, for consistency.
- Make it clear what `\u{200d}` means.
2024-11-19 18:01:43 +11:00
Boxy
473b5d5290 Fix broken intra-doc link 2024-11-19 06:06:47 +00:00
Noah Lev
59e339f766 Introduce min_generic_const_args and directly represent paths
Co-authored-by: Boxy UwU <rust@boxyuwu.dev>
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-11-19 05:07:43 +00:00
bors
5926e82dd1 Auto merge of #124780 - Mark-Simulacrum:lockless-cache, r=lcnr
Improve VecCache under parallel frontend

This replaces the single Vec allocation with a series of progressively larger buckets. With the cfg for parallel enabled but with -Zthreads=1, this looks like a slight regression in i-count and cycle counts (~1%).

With the parallel frontend at -Zthreads=4, this is an improvement (-5% wall-time from 5.788 to 5.4688 on libcore) than our current Lock-based approach, likely due to reducing the bouncing of the cache line holding the lock. At -Zthreads=32 it's a huge improvement (-46%: 8.829 -> 4.7319 seconds).

try-job: i686-gnu-nopt
try-job: dist-x86_64-linux
2024-11-19 02:07:48 +00:00
Nicholas Nethercote
75108b6067 Pass flow_inits by value.
It's simpler that way, and we don't need the explicit `drop`.
2024-11-19 11:46:33 +11:00