about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty
AgeCommit message (Collapse)AuthorLines
2024-08-31interpret, codegen: tweak some comments and checks regarding Box with custom ↵Ralf Jung-1/+4
allocator
2024-08-31Rollup merge of #129725 - compiler-errors:predicates-of, r=fmeaseMatthias Krüger-4/+2
Stop using `ty::GenericPredicates` for non-predicates_of queries `GenericPredicates` is a struct of several parts: A list of of an item's own predicates, and a parent def id (and some effects related stuff, but ignore that since it's kinda irrelevant). When instantiating these generic predicates, it calls `predicates_of` on the parent and instantiates its predicates, and appends the item's own instantiated predicates too: https://github.com/rust-lang/rust/blob/acb4e8b6251f1d8da36f08e7a70fa23fc581839e/compiler/rustc_middle/src/ty/generics.rs#L407-L413 Notice how this should result in a recursive set of calls to `predicates_of`... However, `GenericPredicates` is *also* misused by a bunch of *other* queries as a convenient way of passing around a list of predicates. For these queries, we don't ever set the parent def id of the `GenericPredicates`, but if we did, then this would be very easy to mistakenly call `predicates_of` instead of some other intended parent query. Given that footgun, and the fact that we don't ever even *use* the parent def id in the `GenericPredicates` returned from queries like `explicit_super_predicates_of`, It really has no benefit over just returning `&'tcx [(Clause<'tcx>, Span)]`. This PR additionally opts to wrap the results of `EarlyBinder`, as we've tended to use that in the return type of these kinds of queries to properly convey that the user has params to deal with, and it also gives a convenient way of iterating over a slice of things after instantiating.
2024-08-31Rollup merge of #129527 - compiler-errors:lint-nit, r=NadrierilMatthias Krüger-1/+1
Don't use `TyKind` in a lint Allows us to remove an inherent method from `TyKind` from the type ir crate.
2024-08-29Add `warn(unreachable_pub)` to `rustc_middle`.Nicholas Nethercote-1/+1
I am surprised the diff is so small for this enormous crate.
2024-08-29Stop using ty::GenericPredicates for non-predicates_of queriesMichael Goulet-4/+2
2024-08-28Auto merge of #127537 - veluca93:struct_tf, r=BoxyUwUbors-0/+1
Implement a first version of RFC 3525: struct target features This PR is an attempt at implementing https://github.com/rust-lang/rfcs/pull/3525, behind a feature gate `struct_target_features`. There's obviously a few tasks that ought to be done before this is merged; in no particular order: - add proper error messages - add tests - create a tracking issue for the RFC - properly serialize/deserialize the new target_features field in `rmeta` (assuming I even understood that correctly :-)) That said, as I am definitely not a `rustc` expert, I'd like to get some early feedback on the overall approach before fixing those things (and perhaps some pointers for `rmeta`...), hence this early PR :-) Here's an example piece of code that I have been using for testing - with the new code, the calls to intrinsics get correctly inlined: ```rust #![feature(struct_target_features)] use std::arch::x86_64::*; /* // fails to compile #[target_feature(enable = "avx")] struct Invalid(u32); */ #[target_feature(enable = "avx")] struct Avx {} #[target_feature(enable = "sse")] struct Sse(); /* // fails to compile extern "C" fn bad_fun(_: Avx) {} */ /* // fails to compile #[inline(always)] fn inline_fun(_: Avx) {} */ trait Simd { fn do_something(&self); } impl Simd for Avx { fn do_something(&self) { unsafe { println!("{:?}", _mm256_setzero_ps()); } } } impl Simd for Sse { fn do_something(&self) { unsafe { println!("{:?}", _mm_setzero_ps()); } } } struct WithAvx { #[allow(dead_code)] avx: Avx, } impl Simd for WithAvx { fn do_something(&self) { unsafe { println!("{:?}", _mm256_setzero_ps()); } } } #[inline(never)] fn dosomething<S: Simd>(simd: &S) { simd.do_something(); } fn main() { /* // fails to compile Avx {}; */ if is_x86_feature_detected!("avx") { let avx = unsafe { Avx {} }; dosomething(&avx); dosomething(&WithAvx { avx }); } if is_x86_feature_detected!("sse") { dosomething(&unsafe { Sse {} }) } } ``` Tracking: - https://github.com/rust-lang/rust/issues/129107
2024-08-28coverage: `CodeRegion` is never stored in an arenaZalathar-1/+0
This might have been left over when coverage regions were stored in individual MIR statements, instead of a separate table attached to the MIR body.
2024-08-28Implement RFC 3525.Luca Versari-0/+1
2024-08-27Auto merge of #128506 - compiler-errors:by-move-body, r=cjgillotbors-15/+23
Stop storing a special inner body for the coroutine by-move body for async closures ...and instead, just synthesize an item which is treated mostly normally by the MIR pipeline. This PR does a few things: * We synthesize a new `DefId` for the by-move body of a closure, which has its `mir_built` fed with the output of the `ByMoveBody` MIR transformation, and some other relevant queries. * This has the `DefKind::ByMoveBody`, which we use to distinguish it from "real" bodies (that come from HIR) which need to be borrowck'd. Introduce `TyCtxt::is_synthetic_mir` to skip over `mir_borrowck` which is called by `mir_promoted`; borrowck isn't really possible to make work ATM since it heavily relies being called on a body generated from HIR, and is redundant by the construction of the by-move-body. * Remove the special `PassManager` hacks for handling the inner `by_move_body` stored within the coroutine's mir body. Instead, this body is fed like a regular MIR body, so it's goes through all of the `tcx.*_mir` stages normally (build -> promoted -> ...etc... -> optimized) ✨. * Remove the `InstanceKind::ByMoveBody` shim, since now we have a "regular" def id, we can just use `InstanceKind::Item`. This also allows us to remove the corresponding hacks from codegen, such as in `fn_sig_for_fn_abi` ✨. Notable remarks: * ~~I know it's kind of weird to be using `DefKind::Closure` here, since it's not a distinct closure but just a new MIR body. I don't believe it really matters, but I could also use a different `DefKind`... maybe one that we could use for synthetic MIR bodies in general?~~ edit: We're doing this now.
2024-08-26Use unsafe extern blocks throughout the compilerMichael Goulet-1/+1
2024-08-26Stop using a special inner body for the coroutine by-move body for async ↵Michael Goulet-15/+23
closures
2024-08-25Avoid taking reference of &TyKindMichael Goulet-2/+2
2024-08-24Don't use TyKind in lintMichael Goulet-1/+1
2024-08-24Rollup merge of #129510 - GrigorenkoPV:fix-elided-named-lifetimes, r=cjgillotMatthias Krüger-1/+1
Fix `elided_named_lifetimes` in code https://github.com/rust-lang/rust/pull/129207#issuecomment-2308428671 r? cjgillot
2024-08-24Rollup merge of #129246 - BoxyUwU:feature_gate_const_arg_path, r=cjgillotMatthias Krüger-10/+22
Retroactively feature gate `ConstArgKind::Path` This puts the lowering introduced by #125915 under a feature gate until we fix the regressions introduced by it. Alternative to whole sale reverting the PR since it didn't seem like a very clean revert and I think this is generally a step in the right direction and don't want to get stuck landing and reverting the PR over and over :) cc #129137 ``@camelid,`` tests taken from there. beta is branching soon so I think it makes sense to not try and rush that fix through since it wont have much time to bake and if it has issues we can't simply revert it on beta. Fixes #128016
2024-08-24Fix `elided_named_lifetimes` in codePavel Grigorenko-1/+1
2024-08-23Rollup merge of #129386 - cjgillot:local-resolved-arg, r=compiler-errorsMatthias Krüger-9/+9
Use a LocalDefId in ResolvedArg.
2024-08-22Rollup merge of #129395 - fmease:pp-dyn-w-gat, r=compiler-errorsMatthias Krüger-1/+4
Pretty-print own args of existential projections (dyn-Trait w/ GAT constraints) Previously we would just drop them. This bug isn't that significant as it can only be triggered by user code that constrains GATs inside trait object types which is currently gated under the interim feature `generic_associated_types_extended` (whose future is questionable) or on stable if the GATs are 'disabled' in dyn-Trait via `where Self: Sized` (in which case the assoc type bindings get ignored anyway (and trigger the warn-by-default lint `unused_associated_type_bounds`)), so yeah. Affects diagnostic output and output of `std::any::type_name{_of_val}`.
2024-08-22Pretty-print own args of existential projectionsLeón Orell Valerian Liehr-1/+4
2024-08-22Use a LocalDefId in ResolvedArg.Camille GILLOT-9/+9
2024-08-21Use bool in favor of Option<()> for diagnosticsMichael Goulet-2/+2
2024-08-19Retroactively feature gate `ConstArgKind::Path`Boxy-10/+22
2024-08-17Use cnum for extern crate dataMichael Goulet-6/+4
2024-08-16Rollup merge of #129042 - Jaic1:fix-116308, r=BoxyUwUMatthias Krüger-0/+4
Special-case alias ty during the delayed bug emission in `try_from_lit` This PR tries to fix #116308. A delayed bug in `try_from_lit` will not be emitted so that the compiler will not ICE when it sees the pair `(ast::LitKind::Int, ty::TyKind::Alias)` in `lit_to_const` (called from `try_from_lit`). This PR is related to an unstable feature `adt_const_params` (#95174). r? ``@BoxyUwU``
2024-08-16Special-case alias ty in `try_from_lit`Jaic1-0/+4
2024-08-15Add a comment explaining the return type of `Ty::kind`.Nicholas Nethercote-0/+4
2024-08-14Rollup merge of #128828 - lcnr:search-graph-11, r=compiler-errors许杰友 Jieyou Xu (Joe)-9/+0
`-Znext-solver` caching This PR has two major changes while also fixing multiple issues found via fuzzing. The main optimization is the ability to not discard provisional cache entries when popping the highest cycle head the entry depends on. This fixes the hang in Fuchsia with `-Znext-solver=coherence`. It also bails if the result of a fixpoint iteration is ambiguous, even without reaching a fixpoint. This is necessary to avoid exponential blowup if a coinductive cycle results in ambiguity, e.g. due to unknowable candidates in coherence. Updating stack entries pretty much exclusively happens lazily now, so `fn check_invariants` ended up being mostly useless and I've removed it. See https://gist.github.com/lcnr/8de338fdb2685581e17727bbfab0622a for the invariants we would be able to assert with it. For a general overview, see the in-process update of the relevant rustc-dev-guide chapter: https://hackmd.io/1ALkSjKlSCyQG-dVb_PUHw r? ```@compiler-errors```
2024-08-14Auto merge of #129076 - matthiaskrgr:rollup-rg8mi2x, r=matthiaskrgrbors-7/+9
Rollup of 6 pull requests Successful merges: - #128410 (Migrate `remap-path-prefix-dwarf` `run-make` test to rmake) - #128759 (alloc: add ToString specialization for `&&str`) - #128873 (Add windows-targets crate to std's sysroot) - #129001 (chore(lib): Enhance documentation for core::fmt::Formatter's write_fm…) - #129061 (Use `is_lang_item` more) - #129062 (Remove a no-longer-true assert) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-14Rollup merge of #129061 - compiler-errors:lang-item, r=UrgauMatthias Krüger-7/+9
Use `is_lang_item` more Few places that I missed since introducing `TyCtxt::is_lang_item`.
2024-08-14Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errorsbors-38/+44
Shrink `TyKind::FnPtr`. By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI. r? `@compiler-errors`
2024-08-13Use is_lang_item moreMichael Goulet-7/+9
2024-08-13Auto merge of #128742 - RalfJung:miri-vtable-uniqueness, r=saethlinbors-5/+10
miri: make vtable addresses not globally unique Miri currently gives vtables a unique global address. That's not actually matching reality though. So this PR enables Miri to generate different addresses for the same type-trait pair. To avoid generating an unbounded number of `AllocId` (and consuming unbounded amounts of memory), we use the "salt" technique that we also already use for giving constants non-unique addresses: the cache is keyed on a "salt" value n top of the actually relevant key, and Miri picks a random salt (currently in the range `0..16`) each time it needs to choose an `AllocId` for one of these globals -- that means we'll get up to 16 different addresses for each vtable. The salt scheme is integrated into the global allocation deduplication logic in `tcx`, and also used for functions and string literals. (So this also fixes the problem that casting the same function to a fn ptr over and over will consume unbounded memory.) r? `@saethlin` Fixes https://github.com/rust-lang/miri/issues/3737
2024-08-12Rollup merge of #128912 - compiler-errors:do-not-recommend-impl, r=lcnrMatthias Krüger-0/+7
Store `do_not_recommend`-ness in impl header Alternative to #128674 It's less flexible, but also less invasive. Hopefully it's also performant. I'd recommend we think separately about the design for how to gate arbitrary diagnostic attributes moving forward.
2024-08-12Rollup merge of #128712 - compiler-errors:normalize-borrowck, r=lcnrMatthias Krüger-18/+12
Normalize struct tail properly for `dyn` ptr-to-ptr casting in new solver Realized that the new solver didn't handle ptr-to-ptr casting correctly. r? lcnr Built on #128694
2024-08-12Rollup merge of #128978 - compiler-errors:assert-matches, r=jieyouxuGuillaume Gomez-4/+6
Use `assert_matches` around the compiler more It's a useful assertion, especially since it actually prints out the LHS.
2024-08-12do not use the global solver cache for proof treeslcnr-9/+0
doing so requires overwriting global cache entries and generally adds significant complexity to the solver. This is also only ever done for root goals, so it feels easier to wrap the `evaluate_canonical_goal` in an ordinary query if necessary.
2024-08-12Streamline some inputs/output traversals.Nicholas Nethercote-6/+3
2024-08-12Avoid a `FnPtr` deconstruct-and-recreate.Nicholas Nethercote-4/+5
2024-08-11Remove struct_tail_no_normalizationMichael Goulet-8/+0
2024-08-11Rename normalization functions to rawMichael Goulet-11/+13
2024-08-11Use assert_matches around the compilerMichael Goulet-4/+6
2024-08-10Rollup merge of #128910 - estebank:assoc-fn, r=compiler-errorsGuillaume Gomez-0/+9
Differentiate between methods and associated functions in diagnostics Accurately refer to assoc fn without receiver as assoc fn instead of methods. Add `AssocItem::descr` method to centralize where we call methods and associated functions.
2024-08-10Auto merge of #128740 - compiler-errors:generic-preds, r=estebankbors-6/+6
Stop unnecessarily taking GenericPredicates by `&self` This results in overcapturing in edition 2024, and is unnecessary since `GenericPredicates: Copy`.
2024-08-09Store do_not_recommend-ness in impl headerMichael Goulet-0/+7
2024-08-10Differentiate between methods and associated functionsEsteban Küber-0/+9
Accurately refer to assoc fn without receiver as assoc fn instead of methods. Add `AssocItem::descr` method to centralize where we call methods and associated functions.
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-33/+38
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-08-09Split `split_inputs_and_output` in two.Nicholas Nethercote-3/+6
I think it's a little clearer and nicer that way.
2024-08-08Rename struct_tail_erasing_lifetimes to struct_tail_for_codegenMichael Goulet-11/+7
2024-08-06miri: make vtable addresses not globally uniqueRalf Jung-5/+10
2024-08-06Stop unnecessarily taking GenericPredicates by &selfMichael Goulet-6/+6