Commit graph

44199 commits

Author SHA1 Message Date
Jacob Pratt
6aa015ae9d
Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb
Allow `IndexSlice` to be indexed by ranges.

This comes with some annoyances as the index type can no longer inferred from indexing expressions. The biggest offender for this is `IndexVec::from_fn_n(|idx| ..., n)` where the index type won't be inferred from the call site or any index expressions inside the closure.

My main use case for this is mapping a `Place` to `Range<Idx>` for value tracking where the range represents all the values the place contains.
2025-02-24 02:11:32 -05:00
bors
e0be1a0262 Auto merge of #137271 - nikic:gep-nuw-2, r=scottmcm
Emit getelementptr inbounds nuw for pointer::add()

Lower pointer::add (via intrinsic::offset with unsigned offset) to getelementptr inbounds nuw on LLVM versions that support it. This lets LLVM make use of the pre-condition that the offset addition does not wrap in an unsigned sense. Together with inbounds, this also implies that the offset is non-negative.

Fixes https://github.com/rust-lang/rust/issues/137217.
2025-02-24 03:06:16 +00:00
Trevor Gross
18ffee2126
Rollup merge of #137483 - bend-n:😅, r=Noratrieb
rename sub_ptr to offset_from_unsigned

i also made `byte_sub_ptr` `byte_offset_from_unsigned`

fixes #137121
tracking issue #95892
2025-02-23 14:30:28 -05:00
Trevor Gross
781203dd87
Rollup merge of #137451 - compiler-errors:synm, r=Noratrieb
FIx `sym` -> `syn` typo in tail-expr-drop-order type opt-out

The #131326 PR attempts to reduce some false positives for the `tail_expr_drop_order` lint by hard-coding some common ecosystem crate names. Specifically, I believe it attempts to opt out the drop impls from `syn` which only exist as optimizations.

However, this was typo'd like "sym", which is a crate that has been [yanked](https://crates.io/crates/sym) (lol). This PR fixes that.

cc `@dingxiangfei2009` `@nikomatsakis` -- did I mistake this? Was this meant to be a different crate?

`@bors` rollup
2025-02-23 14:30:27 -05:00
Trevor Gross
fb54acd700
Rollup merge of #137297 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.147

Removes an ABI hack that used `<2 x i64>` to return `i128` in `xmm0` on Windows [1].

[1]: https://github.com/rust-lang/compiler-builtins/pull/759
Link: https://github.com/rust-lang/rust/issues/116558
Link: https://github.com/rust-lang/compiler-builtins/issues/758

try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
2025-02-23 14:30:27 -05:00
Trevor Gross
2c6fa32bdc
Rollup merge of #136637 - Pyr0de:binary-format, r=Noratrieb
Add binary_format to rustc target specs

Added binary format field to `TargetOptions`

Fixes #135724

r? `@Noratrieb`
2025-02-23 14:30:26 -05:00
Trevor Gross
a2bb4d748d
Rollup merge of #136543 - RalfJung:round-ties-even, r=tgross35
intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic

LLVM has three intrinsics here that all do the same thing (when used in the default FP environment). There's no reason Rust needs to copy that historically-grown mess -- let's just have one intrinsic and leave it up to the LLVM backend to decide how to lower that.

Suggested by `@hanna-kruppe` in https://github.com/rust-lang/rust/issues/136459; Cc `@tgross35`

try-job: test-various
2025-02-23 14:30:25 -05:00
Trevor Gross
31719b59c8
Rollup merge of #136439 - yotamofek:pr/codegen-ssa-no-indexing, r=Noratrieb
Misc. `rustc_codegen_ssa` cleanups 🧹

Just a bunch of stuff I found while reading the crate's code.
Each commit can stand on its own.
Maybe r? `@Noratrieb` because I saw you did some similar cleanups on these files a while ago? (feel free to re-assign, I'm just guessing)
2025-02-23 14:30:24 -05:00
bendn
c813d8f3e4
rename sub_ptr 😅 2025-02-23 23:11:00 +07:00
bors
b522e7c5ea Auto merge of #137225 - RalfJung:vectorcall, r=nnethercote
vectorcall ABI: require SSE2

According to the official docs at https://learn.microsoft.com/en-us/cpp/cpp/vectorcall, SSE2 is required for this ABI. Add a check that enforces this.

I put this together with the other checks ensuring the target features required for a function are present... however, since the ABI is known pre-monomorphization, it would be possible to do this check earlier, which would have the advantage of checking even in `cargo check`. It would have the disadvantage of spreading this code in yet more places.

The first commit just does a little refactoring of the mono-time ABI check to make it easier to add the new check.

Cc `@workingjubilee`

try-job: dist-i586-gnu-i586-i686-musl
2025-02-23 14:12:38 +00:00
bors
b880760977 Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrum
Master bootstrap update

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday

r? `@Mark-Simulacrum`
2025-02-23 11:12:56 +00:00
Jacob Pratt
d41520052e
Rollup merge of #137458 - compiler-errors:render-fn, r=fmease
Fix missing self subst when rendering `impl Fn*<T>` with no output type

r? `@fmease` or reassign

Fixes #133597
cc #137456
2025-02-23 02:44:20 -05:00
Jacob Pratt
f5c6287d76
Rollup merge of #137448 - compiler-errors:control-flow-oops, r=scottmcm
Fix bugs due to unhandled `ControlFlow` in compiler

Well, one bug and one nit.
2025-02-23 02:44:20 -05:00
Jacob Pratt
da493c91d6
Rollup merge of #137435 - estebank:match-arm-2, r=compiler-errors
Fix "missing match arm body" suggestion involving `!`

Include the match arm guard in the gated span, so that the suggestion to add a body is correct instead of inserting the body before the guard.

Make the suggestion verbose.

```
error: `match` arm with no body
  --> $DIR/feature-gate-never_patterns.rs:43:9
   |
LL |         Some(_) if false,
   |         ^^^^^^^^^^^^^^^^
   |
help: add a body after the pattern
   |
LL |         Some(_) if false => { todo!() },
   |                          ++++++++++++++
```

r? `@compiler-errors`
2025-02-23 02:44:19 -05:00
Jacob Pratt
4bed9eca0e
Rollup merge of #137423 - Urgau:imprv-pretty-hir, r=compiler-errors
Improve a bit HIR pretty printer

This PR improve (a bit) the HIR pretty printer.

It does so by:
 - Not printing elided lifetimes (those are not expressible in surface Rust anyway)
 - And by rendering implicit self with the shorthand syntax

I also tried fixing some indentation and other things but gave up for now.

Best reviewed commit by commit.
2025-02-23 02:44:19 -05:00
Jacob Pratt
7f14d2eba4
Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross
Greatly simplify lifetime captures in edition 2024

Remove most of the `+ Captures` and `+ '_` from the compiler, since they are now unnecessary with the new edition 2021 lifetime capture rules. Use some `+ 'tcx` and `+ 'static` rather than being overly verbose with precise capturing syntax.
2025-02-23 02:44:18 -05:00
Trevor Gross
08f1086bf0 Update compiler-builtins to 0.1.147
Removes an ABI hack that used `<2 x i64>` to return `i128` in `xmm0` on
Windows [1].

[1]: https://github.com/rust-lang/compiler-builtins/pull/759
Link: https://github.com/rust-lang/rust/issues/116558
Link: https://github.com/rust-lang/compiler-builtins/issues/758
2025-02-23 06:13:09 +00:00
Michael Goulet
431b9aa38f Fix missing self subst when rendering Fn* trait with no output type 2025-02-23 04:46:51 +00:00
Michael Goulet
506532aad2 The sym crate is not a thing 2025-02-23 03:02:46 +00:00
Michael Goulet
04c453c4bc Fix bugs due to unhandled ControlFlow 2025-02-22 23:56:14 +00:00
Matthias Krüger
e780b89959
Rollup merge of #137415 - chenyukang:yukang-fix-137345-invalid-sugg, r=estebank
Remove invalid suggestion of into_iter for extern macro

Fixes #137345

#109082 is closed due to performance issue, do we have any other solution for this kind of issue?
2025-02-23 00:16:21 +01:00
Matthias Krüger
86008eaeac
Rollup merge of #137256 - workingjubilee:untangle-vector-abi-assumptions, r=bjorn3,RalfJung
compiler: untangle SIMD alignment assumptions

There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
2025-02-23 00:16:19 +01:00
Matthias Krüger
4115f51d15
Rollup merge of #137180 - compiler-errors:sym-regions, r=oli-obk
Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes

There are a few intertwined problems with `sym fn` operands in both inline and global asm macros.

Specifically, unlike other anon consts, they may evaluate to a type with free regions in them without actually having an item-level type annotation to give them a "proper" type. This is in contrast to named constants, which always have an item-level type annotation, or unnamed constants which are constrained by their position (e.g. a const arg in a turbofish, or a const array length).

Today, we infer the type of the operand by looking at the HIR typeck results; however, those results are region-erased, so during borrowck we ICE since we don't expect to encounter erased regions. We can't just fill this type with something like `'static`, since we may want to use real (free) regions:

```rust
fn foo<'a>() {
  asm!("/* ... */", sym bar::<&'a ()>);
}
```

The first idea may be to represent `sym fn` operands using *inline* consts instead of anon consts. This makes sense, since inline consts can reference regions from the parent body (like the `'a` in the example above). However, this introduces a problem with `global_asm!`, which doesn't *have* a parent body; inline consts *must* be associated with a parent body since they are not a body owner of their own. In #116087, I attempted to fix this by using two separate `sym` operands for global and inline asm. However, this led to a lot of confusion and also some unattractive code duplication.

In this PR, I adjust the lowering of `global_asm!` so that it's lowered in a "fake" HIR body. This body contains a single expression which is `ExprKind::InlineAsm`; we don't *use* this HIR body, but it's used in typeck and borrowck so that we can properly infer and validate the the lifetimes of `sym fn` operands.

I then adjust the lowering of `sym fn` to instead be represented with a HIR expression. This is both because it's no longer necessary to represent this operand as an anon const, since it's *just* a path expression, and also more importantly to sidestep yet another ICE (https://github.com/rust-lang/rust/issues/137179), which has to do with the existing code breaking an invariant of def-id creation and anon consts. Specifically, we are not allowed to synthesize a def-id for an anon const when that anon const contains expressions with def-ids whose parent is *not* that anon const. This is somewhat related to https://github.com/rust-lang/rust/pull/130443#issuecomment-2445678945, which is also a place in the compiler where synthesizing anon consts leads to def-id parenting issue.

As a side-effect, this consolidates the type checking for inline and global asm, so it allows us to simplify `InlineAsmCtxt` a bit. It also allows us to delete a bit of hacky code from anon const `type_of` which was there to detect `sym fn` operands specifically. This also could be generalized to support `const` asm operands with types with lifetimes in them. Since we specifically reject these consts today, I'm not going to change the representation of those consts (but they'd just be turned into inline consts).

r? oli-obk -- mostly b/c you're patient and also understand the breadth of the code that this touches, please reassign if you don't want to review this.

Fixes #111709
Fixes #96304
Fixes #137179
2025-02-23 00:16:19 +01:00
Matthias Krüger
929423a4f0
Rollup merge of #137121 - bend-n:master, r=Noratrieb
stabilize `(const_)ptr_sub_ptr`

Tracking issue: #95892
Closes #95892
FCP Completed: https://github.com/rust-lang/rust/issues/95892#issuecomment-2561139730

r? ````@Noratrieb````
2025-02-23 00:16:18 +01:00
Matthias Krüger
1610bfb6af
Rollup merge of #135501 - tgross35:stdlib-dependencies-private, r=bjorn3
Inject `compiler_builtins` during postprocessing and ensure it is made private

Follow up of https://github.com/rust-lang/rust/pull/135278

Do the following:

* Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST
* Do not make dependencies of `std` private by default (this was added in #135278)
* Make sure sysroot crates correctly mark their dependencies private/public
* Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified
* Do the `compiler_builtins` update that has been blocked on this

There is more detail in the commit messages. This includes the changes I was working on in https://github.com/rust-lang/rust/pull/136226.

try-job: test-various
try-job: x86_64-msvc-1
try-job: x86_64-msvc-2
try-job: i686-mingw-1
try-job: i686-mingw-2
2025-02-23 00:16:18 +01:00
Michael Goulet
12e3911d81 Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
Esteban Küber
a8f8b8de66 Fix "missing match arm body" suggestion involving !
Include the match arm guard in the gated span, so that the suggestion to add a body is correct instead of inserting the body before the guard.

Make the suggestion verbose.

```
error: `match` arm with no body
  --> $DIR/feature-gate-never_patterns.rs:43:9
   |
LL |         Some(_) if false,
   |         ^^^^^^^^^^^^^^^^
   |
help: add a body after the pattern
   |
LL |         Some(_) if false => { todo!() },
   |                          ++++++++++++++
```
2025-02-22 18:30:14 +00:00
Urgau
d0e7bfd205 Render implicit self with their shorthand syntax in HIR pretty printing 2025-02-22 17:12:19 +01:00
Urgau
46154c9b09 Filter elided lifetimes in HIR pretty printing 2025-02-22 17:12:19 +01:00
bors
15469f8f8a Auto merge of #137420 - matthiaskrgr:rollup-rr0q37f, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #136910 (Implement feature `isolate_most_least_significant_one` for integer types)
 - #137183 (Prune dead regionck code)
 - #137333 (Use `edition = "2024"` in the compiler (redux))
 - #137356 (Ferris 🦀 Identifier naming conventions)
 - #137362 (Add build step log for `run-make-support`)
 - #137377 (Always allow reusing cratenum in CrateLoader::load)
 - #137388 (Fix(lib/fs/tests): Disable rename POSIX semantics FS tests under Windows 7)
 - #137410 (Use StableHasher + Hash64 for dep_tracking_hash)
 - #137413 (jubilee cleared out the review queue)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-22 13:32:44 +00:00
Ralf Jung
d1b34acb3b make the new intrinsics safe 2025-02-22 14:12:55 +01:00
Matthias Krüger
1066af5b1a
Rollup merge of #137410 - saethlin:stable-dep-tracking-hash, r=workingjubilee
Use StableHasher + Hash64 for dep_tracking_hash

This is similar to https://github.com/rust-lang/rust/pull/137095. We currently have a +/- 1 byte jitter in the size of dep graphs reported on perf.rust-lang.org. I think this fixes that jitter.

When I introduced `Hash64`, I wired it through most of the compiler by making it an output of `StableHasher::finalize` then fixing the compile errors. I missed this case because the `u64` hash in this function is being produced by `DefaultHasher` instead. That seems pretty sketchy because the code seems confident that the hash needs to be stable, and we have a mechanism for stable hashing that we weren't using here.
2025-02-22 11:36:46 +01:00
Matthias Krüger
f13feb34dc
Rollup merge of #137377 - bjorn3:crate_loader_cleanup, r=compiler-errors
Always allow reusing cratenum in CrateLoader::load

The only case where can_reuse_cratenum could have been false in the past are rustc plugins, support for which has been removed over a year ago now. Nowadays the only case where locator.tuple is not target_triple is when loading a proc macro, in which case we also set can_reuse_cratenum to true. As such it is always true and we can remove some dead code.
2025-02-22 11:36:45 +01:00
Matthias Krüger
72e41e5d65
Rollup merge of #137356 - nik-rev:FERRIS, r=compiler-errors
Ferris 🦀 Identifier naming conventions

You cannot use Ferris as an identifier in Rust, this code will suggest to correct the  🦀 to `ferris`:

```rs
fn main() {
  let  🦀 = 4;
}
```

But it also suggests to correct to `ferris` in these cases, too:

```rs
struct  🦀 {}
fn main() {}
```

^ suggests: `ferris`
~ with this PR: `Ferris`

```rs
static 🦀: &str = "ferris!";
fn main() {}
```

^ suggests: `ferris`
~ with this PR: `FERRIS`

This is my first pull requests here!
2025-02-22 11:36:44 +01:00
Matthias Krüger
37e0d138cf
Rollup merge of #137333 - compiler-errors:edition-2024-fresh, r=Nadrieril
Use `edition = "2024"` in the compiler (redux)

Most of this is binding mode changes, which I fixed by running `x.py fix`.

Also adds some miscellaneous `unsafe` blocks for new unsafe standard library functions (the setenv ones), and a missing `unsafe extern` block in some enzyme codegen code, and fixes some precise capturing lifetime changes (but only when they led to errors).

cc ``@ehuss`` ``@traviscross``
2025-02-22 11:36:43 +01:00
Matthias Krüger
72535fec55
Rollup merge of #137183 - compiler-errors:dead-regionck-code, r=lcnr
Prune dead regionck code

We never encounter `ObligationCauseCode`s that correspond to region obligations that originate from "within" a body, since we don't do HIR regionck anymore on bodies. So prune some dead code.
2025-02-22 11:36:42 +01:00
bors
8dac72bb1d Auto merge of #136428 - EnzymeAD:enable-autodiff, r=oli-obk
test building enzyme in CI

1) This PR fixes a significant compile-time regression, by only running the expensive autodiff pipeline, if the users pass the newly introduced Enable value to the `-Zautodiff=` flag. It updates the test(s) accordingly. It gives a nice error if users forget that.
2) It fixes macos support by explicitly linking against the Enzyme build folder. This doesn't cover CI macos yet.
3) It fixes the issue that setting ENZYME_RUNPASS was ignored by enzyme and in fact did not schedule enzyme's opt pass.
4) It also re-enables support for various other values for the autodiff flag, which were ignored since the refactor.
5) I merged some improvements to Enzyme core, which means we do not longer depend on LLVM being build with the Plugin Interface enabled.
6) Unrelated to other fixes, this changes `rustc_autodiff` to `EncodeCrossCrate::Yes`. It is not enough on it's own to enable usage of Enzyme in libraries, but it is for sure a piece of the fixes needed to get this to work.

try-job: x86_64-gnu

r? `@oli-obk`

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-02-22 10:30:06 +00:00
bors
b6d3be4948 Auto merge of #133436 - nnethercote:rm-NtVis-NtTy, r=petrochenkov
Remove `NtVis` and `NtTy`

The next part of #124141. The first actual remove of `Nonterminal` variants. `NtVis` is a simple case that doesn't get much use, but `NtTy` is more complex.

r? `@petrochenkov`
2025-02-22 06:09:14 +00:00
yukang
c45463ec8b remove invalid suggestion of into_iter for extern macro 2025-02-22 13:30:41 +08:00
bors
b87eda7fdf Auto merge of #137406 - matthiaskrgr:rollup-9nknrsb, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #136458 (Do not deduplicate list of associated types provided by dyn principal)
 - #136474 ([`compiletest`-related cleanups 3/7] Make the distinction between sources root vs test suite sources root in compiletest less confusing)
 - #136592 (Make sure we don't overrun the stack in canonicalizer)
 - #136787 (Remove `lifetime_capture_rules_2024` feature)
 - #137207 (Add #[track_caller] to Duration Div impl)
 - #137245 (Tweak E0277 when predicate comes indirectly from ?)
 - #137257 (Ignore fake borrows for packed field check)
 - #137399 (fix ICE in layout computation with unnormalizable const)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-22 03:05:26 +00:00
Manuel Drehwald
49e9630641 enable rustc_autodiff cross-crate encoding 2025-02-21 21:53:31 -05:00
Manuel Drehwald
e2d250c3f6 update autodiff flags 2025-02-21 21:51:20 -05:00
Manuel Drehwald
161a4bf6ff update enzyme submodule and users 2025-02-21 21:49:46 -05:00
Manuel Drehwald
f4e2218b13 clean up autodiff code/comments 2025-02-21 21:47:48 -05:00
Manuel Drehwald
fe90883ef7 fix build regressions 2025-02-21 21:45:29 -05:00
Ben Kimock
fd451dc057 Use StableHasher + Hash64 for dep_tracking_hash 2025-02-21 21:36:58 -05:00
Michael Goulet
3d5438accd Fix binding mode problems 2025-02-22 00:13:19 +00:00
Michael Goulet
6ba39f7dc7 Make a fake body to store typeck results for global_asm 2025-02-22 00:12:07 +00:00
Michael Goulet
37060aae13 Initial cleanups of InlineAsmCtxt 2025-02-22 00:05:09 +00:00
Michael Goulet
2a6daaf89a Make asm a named field 2025-02-22 00:05:09 +00:00