about summary refs log tree commit diff
path: root/compiler/rustc_ty_utils/src
AgeCommit message (Collapse)AuthorLines
2025-03-06Prefer a two value enum over boolOli Scherer-2/+3
2025-03-05Rollup merge of #138028 - workingjubilee:is-rustic-abi, r=compiler-errors许杰友 Jieyou Xu (Joe)-5/+2
compiler: add `ExternAbi::is_rustic_abi` Various parts of the compiler were hand-rolling this extremely simple check that is nonetheless easy to get wrong as the compiler evolves over time. Discourage them from being so "original" again by replacing it with a single implementation on the type that represents these ABIs. This simplifies a surprising amount of code as a result. Also fixes #132981, an ICE that emerged due to other checks being made stricter.
2025-03-05Rollup merge of #137728 - Darksonn:no-tuple-unsize, r=oli-obk许杰友 Jieyou Xu (Joe)-2/+1
Remove unsizing coercions for tuples See https://github.com/rust-lang/rust/issues/42877#issuecomment-2686010847 and below comments for justification. Tracking issue: #42877 Fixes: #135217
2025-03-04compiler: use `is_rustic_abi` in ty_utilsJubilee Young-5/+2
expands some conditionals to include different "rustic" ABIs, so that we actually handle passing args through all "rustic" ABIs
2025-03-02Remove layouting dead code for non-array SIMD types.Moulins-76/+19
These aren't supported anymore, and are already rejected in type checking.
2025-03-01Rollup merge of #137804 - RalfJung:backend-repr-simd-vector, r=workingjubileeMatthias Krüger-3/+3
rename BackendRepr::Vector → SimdVector For many Rustaceans, "vector" does not imply "SIMD", so let's be more clear in this type that is used pervasively in the compiler. r? `@workingjubilee`
2025-02-28rename BackendRepr::Vector → SimdVectorRalf Jung-3/+3
2025-02-28Rollup merge of #137770 - compiler-errors:unsafe-binder-sized-crit, r=oli-obk许杰友 Jieyou Xu (Joe)-3/+6
Fix sized constraint for unsafe binder Fixes #137705 r? oli-obk
2025-02-28Fix sized constraint for unsafe binderMichael Goulet-3/+6
2025-02-27Delete tuple unsizingAlice Ryhl-2/+1
2025-02-27Don't infer unwinding of virtual calls based on the function attributesDianQK-6/+13
2025-02-27Don't infer attributes of virtual calls based on the function bodyDianQK-34/+29
2025-02-23Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, ↵Jacob Pratt-4/+4
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-23Rollup merge of #137256 - workingjubilee:untangle-vector-abi-assumptions, ↵Matthias Krüger-26/+34
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-22Greatly simplify lifetime captures in edition 2024Michael Goulet-4/+4
2025-02-22Rollup merge of #137399 - lukas-code:oopsie-woopsie, r=compiler-errorsMatthias Krüger-1/+15
fix ICE in layout computation with unnormalizable const The first commit reverts half of 7a667d206c45b96676c260030a4e3d9be1cc8495, where I removed a case from `layout_of` for handling non-generic unevaluated consts in array length, that I incorrectly assumed to be unreachable. This can actually happen with the combination of `feature(generic_const_exprs)` and `feature(trivial_bounds)`, because GCE makes anon consts inherit their parent's predicates and with an impossible predicate like `u8: A` it's possible to have an array whose length is an associated const like `<u8 as A>::B` that is not generic, but also can't be normalized: ```rust #![feature(generic_const_exprs)] #![feature(trivial_bounds)] trait A { const B: usize; } // With GCE + trivial bounds this definition is not a compile error. // Computing the layout of this type shouldn't ICE. struct S([u8; <u8 as A>::B]) where u8: A; ``` --- The first commit also incidentally fixes https://github.com/rust-lang/rust/issues/137308, which also managed to get an unnormalizable assoc const into an array length: ```rust trait A { const B: usize; } impl<C: ?Sized> A for u8 { //~ ERROR: the type parameter `C` is not constrained const B: usize = 42; } // Computing the layout of this type shouldn't ICE, even with the compile error above. struct S([u8; <u8 as A>::B]); ``` This happens, because we bail out from `codegen_select_candidate` with an error if the selected impl has unconstrained params to avoid leaking infer vars out of a query. `Instance::try_resolve` will then return `Ok(None)`, which for assoc consts roughly means "this const can't be evaluated in a generic context" and is treated as such: https://github.com/rust-lang/rust/blob/71e06b9c59d6af50fdc55aed75620493d29baf98/compiler/rustc_middle/src/mir/interpret/queries.rs#L84 (and this can ICE if the const isn't generic: https://github.com/rust-lang/rust/issues/135617). However, here `<u8 as A>::B` is definitely not "too generic" and also not unresolvable due to an unsatisfiable `u8: A` bound, so I've included the second commit to change the result of `Instance::try_resolve` from `Ok(None)` to `Err(ErrorGuaranteed)` when resolving an assoc item to an impl with unconstrained generic params. This has the effect that `<u8 as A>::B` will now be normalized to `ConstKind::Error` in the example above. This properly fixes https://github.com/rust-lang/rust/issues/137308, by no longer treating `<u8 as A>::B` as unresolvable even though it clearly has a unique impl that it resolves to. It also has the effect of changing the layout error from `Unknown` ("the type may be valid but has no sensible layout") to `ReferencesError` ("a non-layout error is reported elsewhere") which seems more appropriate. r? ```@compiler-errors```
2025-02-21don't leave assoc const unnormalized due to unconstrained paramsLukas Markeffsky-0/+1
2025-02-21layout_of: put back not-so-unreachable caseLukas Markeffsky-1/+14
2025-02-21Rollup merge of #137350 - nnethercote:remove-Map-3, r=ZalatharMatthias Krüger-3/+3
Move methods from Map to TyCtxt, part 3. A follow-up to #137162. r? `@Zalathar`
2025-02-20compiler: split vector_align into cabi and llvmlikeJubilee Young-2/+5
Introduce a pair of functions that actually describe what they do, because it wasn't clear the alignment is sometimes a forgery.
2025-02-20compiler: `BackendRepr::inherent_{size,align} -> scalar_{size,align}`Jubilee Young-23/+28
This pair of fn was introduced to perform invariant checks for scalars. Their current behavior doesn't mesh as well with checking SIMD types, so change the name of the fn to reflect their actual use-case and refactor the corresponding checks. Also simplify the returns from Option<AbiAndPrefAlign> to Option<Align>, because every site was mapping away the "preferred" alignment anyways.
2025-02-20compiler: Align::max_for_offset -> Align::max_aligned_factorJubilee Young-1/+1
No functional changes.
2025-02-21Move methods from Map to TyCtxt, part 3.Nicholas Nethercote-3/+3
Continuing the work from #137162. Every method gains a `hir_` prefix.
2025-02-20Update check to reflect that non-ZST uninhabited types should not be ↵Zachary S-1/+1
PassMode::Ignore.
2025-02-20Remove `BackendRepr::Uninhabited`, replaced with an `uninhabited: bool` ↵Zachary S-21/+19
field in `LayoutData`. Also update comments that refered to BackendRepr::Uninhabited.
2025-02-20Turn order dependent trait objects future incompat warning into a hard errorOli Scherer-56/+2
2025-02-19Make fewer crates depend on rustc_ast_irMichael Goulet-2/+1
2025-02-18cosmetic changesLukas Markeffsky-18/+22
- change function parameter order to `cx, ty, ...` to match the other functions in this file - use `ct` identifier for `ty::Const` to match the majority of the compiler codebase - remove useless return - bring match arms in a more natural order
2025-02-18remove useless parameterLukas Markeffsky-36/+10
Remove the `repr` parameter from the wrappers around `calc.univariant`, because it's always defaulted. Only ADTs can have a repr and those call `calc.layout_of_struct_or_enum` and not `calc.univariant`.
2025-02-18remove redundant codeLukas Markeffsky-11/+9
- we normalize before calling `layout_of_uncached`, so we don't need to normalize again later - we check for type/const errors at the top of `layout_of_uncached`, so we don't need to check again later
2025-02-18remove unreachable casesLukas Markeffsky-15/+8
`ty::Placeholder` is used by the trait solver and computing its layout was necessary, because the `PointerLike` trait used to be automatically implemented for all types with pointer-like layout. Nowadays, `PointerLike` requires user-written impls and the trait solver no longer computes any layouts, so this can be removed. Unevaluated constants that aren't generic should have caused a const eval error earlier during normalization.
2025-02-18Move methods from `Map` to `TyCtxt`, part 2.Nicholas Nethercote-1/+1
Continuing the work started in #136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that.
2025-02-17Auto merge of #137164 - matthiaskrgr:rollup-dj5826k, r=matthiaskrgrbors-5/+8
Rollup of 7 pull requests Successful merges: - #137095 (Replace some u64 hashes with Hash64) - #137100 (HIR analysis: Remove unnecessary abstraction over list of clauses) - #137105 (Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str.) - #137120 (Enable `relative-path-include-bytes-132203` rustdoc-ui test on Windows) - #137125 (Re-add missing empty lines in the releases notes) - #137145 (use add-core-stubs / minicore for a few more tests) - #137149 (Remove SSE ABI from i586-pc-windows-msvc) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-1/+1
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.
2025-02-16Move hashes from rustc_data_structure to rustc_hashes so they can be shared ↵Ben Kimock-1/+1
with rust-analyzer
2025-02-15Replace some u64 hashes with Hash64Ben Kimock-5/+8
2025-02-13Auto merge of #136593 - lukas-code:ty-value-perf, r=oli-obkbors-9/+3
valtree performance tuning Summary: This PR makes type checking of code with many type-level constants faster. After https://github.com/rust-lang/rust/pull/136180 was merged, we observed a small perf regression (https://github.com/rust-lang/rust/pull/136318#issuecomment-2635562821). This happened because that PR introduced additional copies in the fast reject code path for consts, which is very hot for certain crates: https://github.com/rust-lang/rust/blob/6c1d960d88dd3755548b3818630acb63fa98187e/compiler/rustc_type_ir/src/fast_reject.rs#L486-L487 This PR improves the performance again by properly interning the valtrees so that copying and comparing them becomes faster. This will become especially useful with `feature(adt_const_params)`, so the fast reject code doesn't have to do a deep compare of the valtrees. Note that we can't just compare the interned consts themselves in the fast reject, because sometimes `'static` lifetimes in the type are be replaced with inference variables (due to canonicalization) on one side but not the other. A less invasive alternative that I considered is simply avoiding copies introduced by https://github.com/rust-lang/rust/pull/136180 and comparing the valtrees it in-place (see commit: https://github.com/rust-lang/rust/commit/9e91e50ac5920f0b9b4a3b1e0880c85336ba5c64 / perf results: https://github.com/rust-lang/rust/pull/136593#issuecomment-2642303245), however that was still measurably slower than interning. There are some minor regressions in secondary benchmarks: These happen due to changes in memory allocations and seem acceptable to me. The crates that make heavy use of valtrees show no significant changes in memory usage.
2025-02-13Auto merge of #136954 - jhpratt:rollup-koefsot, r=jhprattbors-1/+1
Rollup of 12 pull requests Successful merges: - #134090 (Stabilize target_feature_11) - #135025 (Cast allocas to default address space) - #135841 (Reject `?Trait` bounds in various places where we unconditionally warned since 1.0) - #136217 (Mark condition/carry bit as clobbered in C-SKY inline assembly) - #136699 (std: replace the `FromInner` implementation for addresses with private conversion functions) - #136806 (Fix cycle when debug-printing opaque types from RPITIT) - #136807 (compiler: internally merge `PtxKernel` into `GpuKernel`) - #136818 (Implement `read*_exact` for `std:io::repeat`) - #136927 (Correctly escape hashtags when running `invalid_rust_codeblocks` lint) - #136937 (Update books) - #136945 (Add diagnostic item for `std::io::BufRead`) - #136947 (Reinstate nnethercote in the review rotation.) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-12Rollup merge of #136807 - ↵Jacob Pratt-1/+1
workingjubilee:merge-gpus-to-get-the-arcradeongeforce, r=bjorn3 compiler: internally merge `PtxKernel` into `GpuKernel` r? ``@bjorn3`` for review
2025-02-13intern valtreesLukas Markeffsky-9/+3
2025-02-12Auto merge of #135994 - 1c3t3a:rename-unsafe-ptr, r=oli-obkbors-2/+2
Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptr The wording unsafe pointer is less common and not mentioned in a lot of places, instead this is usually called a "raw pointer". For the sake of uniformity, we rename this method. This came up during the review of https://github.com/rust-lang/rust/pull/134424. r? `@Noratrieb`
2025-02-10compiler: die immediately instead of handling unknown target codegenJubilee Young-8/+4
We cannot produce anything useful if asked to compile unknown targets. We should handle the error immediately at the point of discovery instead of propagating it upward, and preferably in the simplest way: Die. This allows cleaning up our "error-handling" spread across 5 crates.
2025-02-10Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptrBastian Kersting-2/+2
The wording unsafe pointer is less common and not mentioned in a lot of places, instead this is usually called a "raw pointer". For the sake of uniformity, we rename this method. This came up during the review of https://github.com/rust-lang/rust/pull/134424.
2025-02-09compiler: internally merge `Conv::PtxKernel` into `GpuKernel`Jubilee Young-1/+1
It is speculated that these two can be conceptually merged, and it can start by ripping out rustc's notion of the PtxKernel call convention. Leave the ExternAbi for now, but the nvptx target now should see it as just a different way to spell Conv::GpuKernel.
2025-02-08Rustfmtbjorn3-24/+39
2025-02-06Rollup merge of #136435 - Zalathar:thir-pat-stuff, r=NadrierilMatthias Krüger-1/+2
Simplify some code for lowering THIR patterns I've been playing around with some radically different ways of storing THIR patterns, and while those experiments haven't yet produced a clear win, I have noticed various smaller things in the existing code that can be made a bit nicer. Some of the more significant changes: - With a little bit of extra effort (and thoughtful use of Arc), we can completely remove an entire layer of `'pat` lifetimes from the intermediate data structures used for match lowering. - In several places, lists of THIR patterns were being double-boxed for no apparent reason.
2025-02-05Rollup merge of #133932 - bjorn3:fix_ptx_kernel_abi, r=wesleywiserJubilee-8/+3
Avoid using make_direct_deprecated() in extern "ptx-kernel" This method will be removed in the future as it produces a broken ABI that depends on cg_llvm implementation details. After this PR wasm32-unknown-unknown is the only remaining user of make_direct_deprecated(). Fixes https://github.com/rust-lang/rust/issues/117271 Blocks https://github.com/rust-lang/rust/issues/38788
2025-02-03Remove `'pat` lifetime from some match-lowering data structuresZalathar-1/+2
By storing `PatRange` in an Arc, and copying a few fields out of `Pat`, we can greatly simplify the lifetimes involved in match lowering.
2025-02-02Rollup merge of #136279 - Zalathar:ensure-ok, r=oli-obkMatthias Krüger-1/+1
Rename `tcx.ensure()` to `tcx.ensure_ok()`, and improve the associated docs This is all based on my archaeology for https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.60TyCtxtEnsure.60. The main renamings are: - `tcx.ensure()` → `tcx.ensure_ok()` - `tcx.ensure_with_value()` → `tcx.ensure_done()` - Query modifier `ensure_forwards_result_if_red` → `return_result_from_ensure_ok` Hopefully these new names are a better fit for the *actual* function and purpose of these query call modes.
2025-02-01Rename `tcx.ensure()` to `tcx.ensure_ok()`Zalathar-1/+1