Commit Graph

508 Commits

Author SHA1 Message Date
bors
42b384ec0d Auto merge of #147055 - beepster4096:subtype_is_not_a_projection, r=lcnr
Turn ProjectionElem::Subtype into CastKind::Subtype

I noticed that drop elaboration can't, in general, handle `ProjectionElem::SubType`. It creates a disjoint move path that overlaps with other move paths. (`Subslice` does too, and I'm working on a different PR to make that special case less fragile.) If its skipped and treated as the same move path as its parent then `MovePath.place` has multiple possible projections. (It would probably make sense to remove all `Subtype` projections for the canonical place but it doesn't make sense to have this special case for a problem that doesn't actually occur in real MIR.)

The only reason this doesn't break is that `Subtype` is always the sole projection of the local its applied to. For the same reason, it works fine as a `CastKind` so I figured that makes more sense than documenting and validating this hidden invariant.

cc rust-lang/rust#112651, rust-lang/rust#133258

r? Icnr (bc you've been the main person dealing with `Subtype` it looks like)
2025-10-02 01:54:48 +00:00
Stuart Cook
1ef1d3bc28 Rollup merge of #147122 - Zalathar:crash-directives, r=cjgillot
Fix some crash-test directives

- 120175 fails to crash for non-ELF targets; presumably this wasn't noticed because the CI jobs don't enable rustc assertions for non-ELF hosts.
- 34127, 125722, and 131292 have `only-x86_64`, which is overly specific.
  - Unnecessary x86 directives cause friction for contributors using aarch64, especially now that many PR CI jobs also use aarch64.

r? ghost
2025-09-29 11:56:44 +10:00
Stuart Cook
01b172ef33 Rollup merge of #147092 - cjgillot:late-validate-mir, r=compiler-errors
Do not compute optimized MIR if code does not type-check.

Since https://github.com/rust-lang/rust/pull/128612, we compute optimized MIR when `-Zvalidate-mir` is present.

This is done as part of required analyses, even if type-checking fails. This causes ICEs, as most of the mir-opt pipeline expects well-formed code.

Fixes rust-lang/rust#129095
Fixes rust-lang/rust#134174
Fixes rust-lang/rust#134654
Fixes rust-lang/rust#135570
Fixes rust-lang/rust#136381
Fixes rust-lang/rust#137468
Fixes rust-lang/rust#144491
Fixes rust-lang/rust#147011

This does not fix issue rust-lang/rust#137190, as it ICEs without `-Zvalidate-mir`.

r? ``@compiler-errors``
2025-09-29 11:56:42 +10:00
Zalathar
b71c469040 Fix some crash-test directives 2025-09-29 11:04:50 +10:00
Camille Gillot
7a7cb05f11 Do not validate MIR if code does not type-check. 2025-09-28 15:59:21 +00:00
Mads Marquart
07ed247d3c Ignore crash test that doesn't crash on Apple platforms
This wasn't caught by CI, because debug assertions aren't enabled there.
2025-09-27 14:41:09 +02:00
beepster4096
413f095a85 this ice now requires -Zvalidate-mir
also slightly minimized the test
2025-09-26 15:37:19 -07:00
lcnr
32d24f9efa allow bound regions in writeback 2025-09-24 13:08:25 +02:00
bors
7e4b8d702f Auto merge of #146659 - cjgillot:impossible-taint, r=oli-obk
Consider errors in MIR as impossible predicates to empty the body.

The ICEs come from elaborating drops or performing state transform in MIR bodies that fail typeck or borrowck.

If the body is tainted, replace it with `unreachable`.

Fixes https://github.com/rust-lang/rust/issues/122630
Fixes https://github.com/rust-lang/rust/issues/122904
Fixes https://github.com/rust-lang/rust/issues/125185
Fixes https://github.com/rust-lang/rust/issues/139556
2025-09-21 16:28:12 +00:00
Camille Gillot
3934fc9eb2 Consider errors in MIR as impossible predicates. 2025-09-21 03:26:21 +00:00
Folkert de Vries
8b752cb37d fix issue with cmse-nonsecure-entry ABI being both async and c-variadic 2025-09-16 10:23:07 +02:00
jullang
f6e7c81061 Add compiler error when trying to use concat metavar expr in repetitions
Replace unimplemented()! with a more helpful compiler error.
2025-09-01 08:27:30 +02:00
Jonathan Brouwer
7db1840569 Changes to the uitests
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-27 20:25:18 +02:00
Matthias Krüger
bd90013b39 Rollup merge of #145905 - TaKO8Ki:fix-137580, r=nnethercote
Stop calling unwrap when format foreign has trailing dollar

Fixes rust-lang/rust#137580
2025-08-27 11:26:52 +02:00
Takayuki Maeda
2c361f8267 remove old crash test 2025-08-27 14:39:33 +09:00
bors
269d5b56bc Auto merge of #144841 - cjgillot:typeck-no-attrs, r=davidtwco
Access less HIR attributes from typeck

Typeck relies on attributes to modify its own behaviour. This is a problem, as this means that `typeck(some function)` may depend on the span and doc-comments of many other functions.

This PR attempts to reduce such accesses to attributes. This yields to a sizeable perf improvement: https://github.com/rust-lang/rust/pull/144841#issuecomment-3153339771

Fixes https://github.com/rust-lang/rust/issues/124352
2025-08-27 01:11:24 +00:00
Shoyu Vanilla
2218ff1940 fix: Reject async assoc fns of const traits/impls in ast_passes 2025-08-15 16:31:10 +09:00
Jonathan Brouwer
4bb7bf64e0 Update uitests
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-14 18:18:42 +02:00
Stuart Cook
e5b98a9c21 Rollup merge of #143093 - lqd:polonius-pre-alpha, r=jackh726
Simplify polonius location-sensitive analysis

This PR reworks the location-sensitive analysis into what we think is a worthwhile subset of the datalog analysis. A sort of polonius alpha analysis that handles NLL problem case 3 and more, but is still using the faster "reachability as an approximation of liveness", as well as the same loans-in-scope computation as NLLs -- and thus doesn't handle full flow-sensitivity like the datalog implementation.

In the last few months, we've identified this subset as being actionable:
- we believe we can make a stabilizable version of this analysis
- it is an improvement over the status quo
- it can also be modeled in a-mir-formality, or some other formalism, for assurances about soundness, and I believe ````````@nikomatsakis```````` is interested in looking into this during H2.
- and we've identified the areas of work we wish to explore later to gradually expand the supported cases: the differences between reachability and liveness, support of kills, and considerations of time-traveling, for example.

The approach in this PR is to try less to have the graph only represent live paths, by checking whether we reach a live region during traversal and recording the loan as live there, instead of equating traversal with liveness like today because it has subtleties with the typeck edges in statements (that could forward loans to the successor point without ensuring their liveness). We can then also simplify these typeck stmt edges. And we also can simplify traversal by removing looking at kills, because that's enough to handle a bunch of NLL problem 3 cases -- and we can gradually support them more and more in traversal in the future, to reduce the approximation of liveness.

There's still some in-progress pieces of work w/r/t opaque types that I'm expecting [lcnr's opaque types rework](https://github.com/rust-lang/rust/pull/139587), and [amanda's SCCs rework](https://github.com/rust-lang/rust/pull/130227) to handle. That didn't seem to show up in tests until I rebased today (and shows lack of test coverage once again) when https://github.com/rust-lang/rust/pull/142255 introduced a couple of test failures with the new captures rules from edition 2024. It's not unexpected since we know more work is needed with member constraints (and we're not even using SCCs in this prototype yet)

I'll look into these anyways, both for future work, and checking how these other 2 PRs would change things.

---

I'm not sure the following means a lot until we have some formalism in-place, but:
- I've changed the polonius compare-mode to use this analysis: the tests pass with it, except 2 cases with minor diagnostics differences, and the 2 edition 2024 opaque types one I mentioned above and need to investigate
- things that are expected to work still do work: it bootstraps, can run our rustc-perf benchmarks (and the results are not even that bad), and a crater run didn't find any regressions (forgetting that crater currently fails to test around a quarter of all crates 👼)
- I've added tests with improvements, like the NLL problem case 3 and others, as well as some that behave the same as NLLs today and are thus worse than the datalog implementation

r? ````````@jackh726````````

(no rush I know you're deep in phd work and "implmentating" the new trait solver for r-a :p <3)

This also fixes rust-lang/rust#135646, a diagnostics ICE from the previous implementation.
2025-08-10 19:45:46 +10:00
lcnr
4eee55691a borrowck: defer opaque type errors 2025-08-08 19:24:53 +02:00
Rémy Rakic
13308988b0 new impl fixes crash test 2025-08-08 15:14:51 +00:00
ash
916fb6a464 explicit tail call tests with indirect operands in LLVM, small test for indexing into a function table as described by RFC 3407 2025-08-06 18:13:56 -06:00
Camille GILLOT
6b7f8fbcc5 Promote crash test. 2025-08-05 01:55:20 +00:00
bors
32e7a4b92b Auto merge of #144405 - lcnr:hir-typeck-uniquify, r=BoxyUwU
uniquify root goals during HIR typeck

We need to rely on region identity to deal with hangs such as https://github.com/rust-lang/trait-system-refactor-initiative/issues/210 and to keep the current behavior of `fn try_merge_responses`.

This is a problem as borrowck starts by replacing each *occurrence* of a region with a unique inference variable. This frequently splits a single region during HIR typeck into multiple distinct regions. As we assume goals to always succeed during borrowck, relying on two occurances of a region being identical during HIR typeck causes ICE. See the now fixed examples in https://github.com/rust-lang/trait-system-refactor-initiative/issues/27 and rust-lang/rust#139409.

We've previously tried to avoid this issue by always *uniquifying* regions when canonicalizing goals. This prevents caching subtrees during canonicalization which resulted in hangs for very large types. People rely on such types in practice, which caused us to revert our attempt to reinstate `#[type_length_limit]` in https://github.com/rust-lang/rust/pull/127670. The complete list of changes here:
- rust-lang/rust#107981
- rust-lang/rust#110180
- rust-lang/rust#114117
- rust-lang/rust#130821

After more consideration, all occurrences of such large types need to happen outside of typeck/borrowck. We know this as we already walk over all types in the MIR body when replacing their regions with nll vars.

This PR therefore enables us to rely on region identity inside of the trait solver by exclusively **uniquifying root goals during HIR typeck**. These are the only goals we assume to hold during borrowck. This is insufficient as type inference variables may "hide" regions we later uniquify. Because of this, we now stash proven goals which depend on inference variables in HIR typeck and reprove them after writeback. This closes https://github.com/rust-lang/trait-system-refactor-initiative/issues/127.

This was originally part of rust-lang/rust#144258 but I've moved it into a separate PR. While I believe we need to rely on region identity to fix the performance issues in some way, I don't know whether rust-lang/rust#144258 is the best approach to actually do so. Regardless of how we deal with the hangs however, this change is necessary and desirable regardless.

r? `@compiler-errors` or `@BoxyUwU`
2025-07-31 00:32:55 +00:00
lcnr
0b323eacd4 uniquify root goals during HIR typeck 2025-07-25 12:40:01 +00:00
Camille GILLOT
832207862a Check static is sized when building MIR. 2025-07-25 02:31:59 +00:00
Camille GILLOT
6b4181f1e3 Do not assert layout in KnownPanicsLint. 2025-07-25 02:27:30 +00:00
Camille GILLOT
e70d213275 Add crash tests. 2025-07-25 02:18:27 +00:00
bors
b56aaec52b Auto merge of #144389 - scottmcm:no-more-mir-cast-assume, r=davidtwco
MIR-build: No longer emit assumes in enum-as casting

This just uses the `valid_range` from the backend, so it's duplicating the range metadata that now we include on parameters and loads, and thus no longer seems to be useful -- notably there's no codegen test failures from removing it.

(Because it's using data from the same source as the backend annotations, it doesn't do anything to mitigate things like rust-lang/rust#144388 where the range in the layout is more permissive than the actual possible discriminants.  A variant of this that actually checked the discriminants more specifically might be useful, so could potentially be added in future, but I don't think the *current* checks are actually providing value.)

r? mir

Randomly turns out that this
Fixes https://github.com/rust-lang/rust/issues/121097
2025-07-24 20:38:53 +00:00
Scott McMurray
01524abb05 MIR-build: No longer emit assumes in enum-as casting
This just uses the `valid_range` from the backend, so it's duplicating the range metadata that now we include on parameters and loads.
2025-07-24 10:18:37 -07:00
Camille GILLOT
538b0004bc Also bail out if predicates contain errors. 2025-07-20 23:15:24 +00:00
Camille GILLOT
1987471d05 Consider parent predicates in ImpossiblePredicates pass. 2025-07-20 22:45:07 +00:00
Matthias Krüger
b252014673 Rollup merge of #143271 - cjgillot:gvn-types, r=oli-obk
Store the type of each GVN value

MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities.

This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code.

Fixes rust-lang/rust#128094
Fixes rust-lang/rust#135128

r? ``````@ghost`````` for perf
2025-07-18 04:27:50 +02:00
Deadbeef
69326878ee parse const trait Trait 2025-07-17 18:06:26 +08:00
León Orell Valerian Liehr
7ea74358c8 Rollup merge of #143895 - compiler-errors:trait-wc-item-bound-host-eff, r=oli-obk
Dont collect assoc ty item bounds from trait where clause for host effect predicates

For background, we uplift `where Self::Assoc: Trait` bounds in a trait's where clauses into *item bounds* on `type Assoc;`. This is because before we *had* syntactical item bounds, users would express their item bounds like so.

Let's opt out of doing this same behavior for `HostEffect` predicates like `where Self::Assoc: [const] Trait`. I left a comment in the code:

```rust
// FIXME(const_trait_impl): We *could* uplift the
// `where Self::Assoc: [const] Trait` bounds from the parent trait
// here too, but we'd need to split `const_conditions` into two
// queries (like we do for `trait_explicit_predicates_and_bounds`)
// since we need to also filter the predicates *out* of the const
// conditions or they lead to cycles in the trait solver when
// utilizing these bounds. For now, let's do nothing.
```

As an aside, this was an ICE that was only triggerable when building libraries and not binaries because we never were calling `tcx.ensure_ok().explicit_implied_const_bounds(def_id);` on associated types like we should have been. I adjusted the calls to `ensure_ok` to make sure this happens, so we catch bugs like this in the future more easily.

As another aside, I fixed the bound uplifting logic for *always const* predicates, since those act like normal clauses and have no notion of conditional constness.

r? ```@oli-obk``` ```@fee1-dead``` or anyone really

Fixes rust-lang/rust#133275
2025-07-17 03:58:34 +02:00
Ralf Jung
8f854d9cb2 const heap: fix ICE on forgotten make_global 2025-07-16 15:29:52 +02:00
Michael Goulet
549a5d8b28 Dont collect assoc ty item bounds from trait where clause for host effect predicates 2025-07-13 16:31:59 +00:00
Camille GILLOT
4a95b16527 Move crashes tests. 2025-07-02 10:51:40 +00:00
Michael Goulet
2516c33982 Remove support for dyn* 2025-07-01 19:00:21 +00:00
Michael Goulet
ed16ae851b Do not freshen ReError 2025-06-28 20:48:58 +00:00
Yotam Ofek
0e32036deb gce: don't ICE on non-local const 2025-06-27 18:07:07 +00:00
bors
e61dd437f3 Auto merge of #143074 - compiler-errors:rollup-cv64hdh, r=compiler-errors
Rollup of 18 pull requests

Successful merges:

 - rust-lang/rust#137843 (make RefCell unstably const)
 - rust-lang/rust#140942 (const-eval: allow constants to refer to mutable/external memory, but reject such constants as patterns)
 - rust-lang/rust#142549 (small iter.intersperse.fold() optimization)
 - rust-lang/rust#142637 (Remove some glob imports from the type system)
 - rust-lang/rust#142647 ([perf] Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation)
 - rust-lang/rust#142700 (Remove incorrect comments in `Weak`)
 - rust-lang/rust#142927 (Add note to `find_const_ty_from_env`)
 - rust-lang/rust#142967 (Fix RwLock::try_write documentation for WouldBlock condition)
 - rust-lang/rust#142986 (Port `#[export_name]` to the new attribute parsing infrastructure)
 - rust-lang/rust#143001 (Rename run always )
 - rust-lang/rust#143010 (Update `browser-ui-test` version to `0.20.7`)
 - rust-lang/rust#143015 (Add `sym::macro_pin` diagnostic item for `core::pin::pin!()`)
 - rust-lang/rust#143033 (Expand const-stabilized API links in relnotes)
 - rust-lang/rust#143041 (Remove cache for citool)
 - rust-lang/rust#143056 (Move an ACE test out of the GCI directory)
 - rust-lang/rust#143059 (Fix 1.88 relnotes)
 - rust-lang/rust#143067 (Tracking issue number for `iter_macro`)
 - rust-lang/rust#143073 (Fix some fixmes that were waiting for let chains)

Failed merges:

 - rust-lang/rust#143020 (codegen_fn_attrs: make comment more precise)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-27 00:44:20 +00:00
Michael Goulet
25e239c193 Rollup merge of #142647 - compiler-errors:less-work-in-coherence, r=lcnr
[perf] Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation

First compute hard errors without diagnostics, then ambiguities with diagnostics since we need to know if any of them overflowed.
2025-06-26 20:15:20 -04:00
Matthias Krüger
a05f2cc44d Rollup merge of #142393 - compiler-errors:nofield, r=petrochenkov
Don't  give APITs names with macro expansion placeholder fragments in it

The `DefCollector` previously called `pprust::ty_to_string` to construct a name for APITs (arg-position impl traits). The `ast::Ty` that was being formatted however has already had its macro calls replaced with "placeholder fragments", which end up rendering like `!()` (or ICEing, in the case of rust-lang/rust#140333, since it led to a placeholder struct field with no name).

Instead, collect the name of the APIT *before* we visit its macros and replace them with placeholders in the macro expander. This makes the implementation a bit more involved, but AFAICT there's no better way to do this since we can't do a reverse mapping from placeholder fragment -> original macro call AST.

Fixes rust-lang/rust#140333
2025-06-26 15:47:20 +02:00
Jana Dönszelmann
da42289cd7 Rollup merge of #142976 - compiler-errors:coerce-ice, r=fee1-dead
Check CoerceUnsized impl validity before coercing

Self-explanatory from the title.

Fixes rust-lang/rust#126982
Fixes rust-lang/rust#131048
Fixes rust-lang/rust#134217
Fixes rust-lang/rust#126269
Fixes rust-lang/rust#138265
2025-06-25 22:14:56 +02:00
Michael Goulet
8cd3fa04e2 Don't give APITs names with macro expansion placeholder fragments in it 2025-06-25 15:42:11 +00:00
Michael Goulet
8304435793 Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation 2025-06-25 15:32:08 +00:00
Jubilee Young
1400e2d9f5 tests: s/C-cmse/cmse/ 2025-06-25 00:52:10 -07:00
Michael Goulet
1c9f7955d4 Check CoerceUnsized impl validity before coercing 2025-06-24 17:48:09 +00:00
Jubilee Young
7632fab668 tests: Adopt ABI transmute tests from crashtests 2025-06-23 09:40:00 -07:00