about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2024-06-13Fix some TODOsMichael Goulet-0/+8
2024-06-13Finish uplifting all of structural_traitsMichael Goulet-2/+30
2024-06-13Rework most of structural_traits to be Interner-agnosticMichael Goulet-3/+75
2024-06-13Method resolution constrains hidden types instead of rejecting method candidatesOli Scherer-1/+1
2024-06-12Stop passing traitref/traitpredicate by refMichael Goulet-2/+2
2024-06-12Use Variance glob import everywhereMichael Goulet-2/+1
2024-06-12Rollup merge of #126075 - compiler-errors:remove-debugwithinfcx, r=lcnrGuillaume Gomez-98/+16
Remove `DebugWithInfcx` machinery This PR removes `DebugWithInfcx` after having a lot of second thoughts about it due to recent type system uplifting work. We could add it back later if we want, but I don't think the amount of boilerplate in the complier and the existence of (kindof) hacks like `NoInfcx` currently justify the existence of `DebugWithInfcx`, especially since it's not even being used anywhere in the compiler currently. The motivation for `DebugWithInfcx` is that we want to be able to print infcx-aware information, such as universe information[^1] (though if there are other usages that I'm overlooking, please let me know). I think there are probably more tailored solutions that can specifically be employed in places where this infcx-aware printing is necessary. For example, one way of achieving this is by implementing a custom `FmtPrinter` which overloads `ty_infer_name` (perhaps also extending it to have overrideable stubs for printing placeholders too) to print the `?u.i` name for an infer var. This will necessitate uplifting `Print` from `rustc_middle::ty::print`, but this seems a bit more extensible and reusable than `DebugWithInfcx`. One of the problems w/ `DebugWithInfcx` is its opt-in-ness. Even if a compiler dev adds a new `debug!(ty)` in a context where there is an `infcx` we can access, they have to *opt-in* to using `DebugWithInfcx` with something like `debug!(infcx.with(ty))`. This feels to me like it risks a lot of boilerplate, and very easy to just forget adding it at all, especially in cases like `#[instrument]`. A second problem is the `NoInfcx` type itself. It's necessary to have this dummy infcx implementation since we often want to print types outside of the scope of a valid `Infcx`. Right now, `NoInfcx` is only *partially* a valid implementation of `InferCtxtLike`, except for the methods that we specifically need for `DebugWithInfcx`. As I work on uplifting the trait solver, I actually want to add a lot more methods to `InferCtxtLike` and having to add `unreachable!("this should never be called")` stubs for uplifted methods like `next_ty_var` is quite annoying. In reality, I actually only *really* care about the second problem -- we could, perhaps, instead just try to get rid of `NoInfcx` and just just duplicate `Debug` and `DebugWithInfcx` for most types. If we're okay with duplicating all these implementations (though most of them would just be trivial `#[derive(Debug, DebugWithInfcx)]`), I'd be okay with that too 🤔 r? `@BoxyUwU` `@lcnr` would like to know your thoughts -- happy to discuss this further, mainly trying to bring this problem up [^1]: Which in my experience is only really necessary when we're debugging things like generalizer bugs.
2024-06-12Require any function with a tait in its signature to actually constrain a ↵Oli Scherer-70/+81
hidden type
2024-06-11Remove DebugWithInfcxMichael Goulet-98/+16
2024-06-11Rollup merge of #126265 - RalfJung:interpret-cast-validity, r=oli-obk许杰友 Jieyou Xu (Joe)-10/+5
interpret: ensure we check bool/char for validity when they are used in a cast In general, `Scalar::to_bits` is a bit dangerous as it bypasses all type information. We should usually prefer matching on the type and acting according to that. So I also refactored `unary_op` handling of integers to do that. The remaining `to_bits` uses are operations that just fundamentally don't care about the sign (and only work on integers). invalid_char_cast.rs is the key new test, the others already passed before this PR. r? `@oli-obk`
2024-06-11interpret: ensure we check bool/char for validity when they are used in a castRalf Jung-10/+5
2024-06-11Auto merge of #126139 - compiler-errors:specializes, r=lcnrbors-0/+5
Only compute `specializes` query if (min)specialization is enabled in the crate of the specializing impl Fixes (after backport) https://github.com/rust-lang/rust/issues/125197 ### What https://github.com/rust-lang/rust/pull/122791 makes it so that inductive cycles are no longer hard errors. That means that when we are testing, for example, whether these impls overlap: ```rust impl PartialEq<Self> for AnyId { fn eq(&self, _: &Self) -> bool { todo!() } } impl<T: Identifier> PartialEq<T> for AnyId { fn eq(&self, _: &T) -> bool { todo!() } } ``` ...given... ```rust pub trait Identifier: Display + 'static {} impl<T> Identifier for T where T: PartialEq + Display + 'static {} ``` Then we try to see if the second impl holds given `T = AnyId`. That requires `AnyId: Identifier`, which requires that `AnyId: PartialEq`, which is satisfied by these two impl candidates... The `PartialEq<T>` impl is a cycle, and we used to winnow it when we used to treat inductive cycles as errors. However, now that we don't winnow it, this means that we *now* try calling `candidate_should_be_dropped_in_favor_of`, which tries to check whether one of the impls specializes the other: the `specializes` query. In that query, we currently bail early if the impl is local. However, in a foreign crate, we try to compute if the two impls specialize each other by doing trait solving. This may itself lead to the same situation where we call `specializes`, which will lead to a query cycle. ### How does this fix the problem We now record whether specialization is enabled in foreign crates, and extend this early-return behavior to foreign impls too. This means that we can only encounter these cycles if we truly have a specializing impl from a crate with specialization enabled. ----- r? `@oli-obk` or `@lcnr`
2024-06-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-163/+129
2024-06-09Auto merge of #126150 - RalfJung:offset_of_slice, r=compiler-errorsbors-0/+34
offset_of: allow (unstably) taking the offset of slice tail fields Fields of type `[T]` have a statically known offset, so there is no reason to forbid them in `offset_of!`. This PR adds the `offset_of_slice` feature to allow them. I created a tracking issue: https://github.com/rust-lang/rust/issues/126151.
2024-06-08offset_of: allow (unstably) taking the offset of slice tail fieldsRalf Jung-0/+34
2024-06-08add missing Scalar::from_i128Ralf Jung-0/+5
2024-06-08StorageLive: refresh storage (instead of UB) when local is already liveRalf Jung-4/+7
2024-06-07Only compute specializes query if specialization is enabled in the crate of ↵Michael Goulet-0/+5
the specialized impl
2024-06-07Auto merge of #125918 - oli-obk:const_block_ice, r=compiler-errorsbors-36/+12
Revert: create const block bodies in typeck via query feeding as per the discussion in https://github.com/rust-lang/rust/pull/125806#discussion_r1622563948 It was a mistake to try to shoehorn const blocks and some specific anon consts into the same box and feed them during typeck. It turned out not simplifying anything (my hope was that we could feed `type_of` to start avoiding the huge HIR matcher, but that didn't work out), but instead making a few things more fragile. reverts the const-block-specific parts of https://github.com/rust-lang/rust/pull/124650 `@bors` rollup=never had a small perf impact previously fixes https://github.com/rust-lang/rust/issues/125846 r? `@compiler-errors`
2024-06-07Revert "Create const block DefIds in typeck instead of ast lowering"Oli Scherer-35/+12
This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42.
2024-06-07Revert "Cache whether a body has inline consts"Oli Scherer-1/+0
This reverts commit eae5031ecbda434e92966099e0dc93917de03eff.
2024-06-07Auto merge of #126108 - workingjubilee:rollup-g7m92b6, r=workingjubileebors-1039/+292
Rollup of 7 pull requests Successful merges: - #125606 (Size optimize int formatting) - #125724 (Uplift `Relate`/`TypeRelation` into `rustc_next_trait_solver`) - #126040 (Don't warn on fields in the `unreachable_pub` lint ) - #126098 (Remove `same-lib-two-locations-no-panic` run-make test) - #126099 (Crate loader cleanups) - #126101 (Revert "Disallow ambiguous attributes on expressions" on nightly) - #126103 (Improve Docs for `hir::Impl` and `hir::ImplItem`) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-06Rollup merge of #125724 - compiler-errors:uplift-relate, r=lcnrJubilee-1039/+292
Uplift `Relate`/`TypeRelation` into `rustc_next_trait_solver` For use in the new solver. This doesn't yet uplift `ObligationEmittingRelation`. r? lcnr
2024-06-07Auto merge of #125928 - michaelwoerister:fix-cgu-hashstable, r=oli-obkbors-30/+21
Stabilize order of MonoItems in CGUs and disallow query_instability lint for rustc_monomorphize The HashStable impl for `CodegenUnit` was incorrect as described in [MCP 533](https://github.com/rust-lang/compiler-team/issues/533). This PR removes any indeterminism from the way codegen units are built. The changes are pretty straightforward. Part of https://github.com/rust-lang/rust/issues/84447 and [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).
2024-06-06Auto merge of #126068 - lqd:revert-124976, r=petrochenkovbors-20/+11
Revert "use `tcx.used_crates(())` more" before it reaches beta There are more open issues caused by #124976 than will be fixed by #125493 alone. The beta cut is soon, so let's revert it and buy some time to analyze and fix these issues in our own time. fixes https://github.com/rust-lang/rust/issues/125474 fixes https://github.com/rust-lang/rust/issues/125484 fixes https://github.com/rust-lang/rust/issues/125646 fixes https://github.com/rust-lang/rust/issues/125707 fixes #126066 fixes #125934 fixes https://github.com/rust-lang/rust/issues/126021 r? `@petrochenkov` `@bors` p=1
2024-06-06Uplift TypeRelation and RelateMichael Goulet-864/+247
2024-06-06Uplift TypeErrorMichael Goulet-170/+40
2024-06-06Make middle not rely on next_trait_solverMichael Goulet-5/+5
2024-06-06Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk"Rémy Rakic-20/+11
This reverts commit eda4a35f365535af72118118a3597edf5a13c12d, reversing changes made to eb6b35b5bcb3c2a594cb29cd478aeb2893f49d30.
2024-06-06Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obkbors-5/+7
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484 This is better reviewed commit by commit.
2024-06-06Auto merge of #125958 - BoxyUwU:remove_const_ty, r=lcnrbors-283/+249
Remove the `ty` field from type system `Const`s Fixes #125556 Fixes #122908 Part of the work on `adt_const_params`/`generic_const_param_types`/`min_generic_const_exprs`/generally making the compiler nicer. cc rust-lang/project-const-generics#44 Please review commit-by-commit otherwise I wasted a lot of time not just squashing this into a giant mess (and also it'll be SO much nicer because theres a lot of fluff changes mixed in with other more careful changes if looking via File Changes --- Why do this? - The `ty` field keeps causing ICEs and weird behaviour due to it either being treated as "part of the const" or it being forgotten about leading to ICEs. - As we move forward with `adt_const_params` and a potential `min_generic_const_exprs` it's going to become more complex to actually lower the correct `Ty<'tcx>` - It muddles the idea behind how we check `Const` arguments have the correct type. By having the `ty` field it may seem like we ought to be relating it when we relate two types, or that its generally important information about the `Const`. - Brings the compiler more in line with `a-mir-formality` as that also tracks the type of type system `Const`s via `ConstArgHasType` bounds in the env instead of on the `Const` itself. - A lot of stuff is a lot nicer when you dont have to pass around the type of a const lol. Everywhere we construct `Const` is now significantly nicer :sweat_smile: See #125671's description for some more information about the `ty` field --- General summary of changes in this PR: - Add `Ty` to `ConstKind::Value` as otherwise there is no way to implement `ConstArgHasType` to ensure that const arguments are correctly typed for the parameter when we stop creating anon consts for all const args. It's also just incredibly difficult/annoying to thread the correct `Ty` around to a bunch of ctfe functions otherwise. - Fully implement `ConstArgHasType` in both the old and new solver. Since it now has no reliance on the `ty` field it serves its originally intended purpose of being able to act as a double check that trait vs impls have correctly typed const parameters. It also will now be able to be responsible for checking types of const arguments to parameters under `min_generic_const_exprs`. - Add `Ty` to `mir::Const::Ty`. I dont have a great understanding of why mir constants are setup like this to be honest. Regardless they need to be able to determine the type of the const and the easiest way to make this happen was to simply store the `Ty` along side the `ty::Const`. Maybe we can do better here in the future but I'd have to spend way more time looking at everywhere we use `mir::Const`. - rustdoc has its own `Const` which also has a `ty` field. It was relatively easy to remove this. --- r? `@lcnr` `@compiler-errors`
2024-06-06Auto merge of #122505 - oli-obk:visit_nested_body2, r=tmiaskobors-3/+23
Don't walk the bodies of free constants for reachability. follow-up to #122371 cc #119214 This avoids codegening items (e.g. functions) that are only used during const eval, but do not reach their final constant value (e.g. via function pointers). r? `@tmiasko`
2024-06-05ty::Expr reviewsBoxy-6/+10
2024-06-05Misc fixes (pattern type lowering, cfi, pretty printing)Boxy-18/+1
2024-06-05Add `Ty` to `mir::Const::Ty`Boxy-16/+25
2024-06-05Fully implement `ConstArgHasType`Boxy-0/+48
2024-06-05Add `Ty` to `ConstKind::Value`Boxy-71/+72
2024-06-05Basic removal of `Ty` from places (boring)Boxy-211/+132
2024-06-05Rollup merge of #125505 - aDotInTheVoid:middle-idl, r=pnkfelixMatthias Krüger-5/+6
Add intra-doc-links to rustc_middle crate-level docs. Makes it slightly faster to find these modules, as you don't need to hunt for them in the big list.
2024-06-05Don't walk the bodies of free constants for reachability.Oli Scherer-3/+23
2024-06-05Rollup merge of #123168 - joshtriplett:size-of-prelude, r=AmanieuJubilee-1/+1
Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude (Note: need to update the PR to add `align_of` and `align_of_val`, and remove the second commit with the myriad changes to appease the lint.) Many, many projects use `size_of` to get the size of a type. However, it's also often equally easy to hardcode a size (e.g. `8` instead of `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps ensure that people use it and make code more self-documenting. The name `size_of` is unambiguous: the name alone, without any prefix or path, is self-explanatory and unmistakeable for any other functionality. Adding it to the prelude cannot produce any name conflicts, as any local definition will silently shadow the one from the prelude. Thus, we don't need to wait for a new edition prelude to add it.
2024-06-04Add safe/unsafe to static inside extern blocksSantiago Pastorino-3/+5
2024-06-04Handle safety keyword for extern block inner itemsSantiago Pastorino-2/+2
2024-06-04Auto merge of #123536 - compiler-errors:simplify-int-float, r=lcnrbors-36/+2
Simplify `IntVarValue`/`FloatVarValue` r? `@ghost`
2024-06-04Rollup merge of #125968 - BoxyUwU:shrink_ty_expr, r=oli-obkMichael Goulet-155/+208
Store the types of `ty::Expr` arguments in the `ty::Expr` Part of #125958 In attempting to remove the `ty` field on `Const` it will become necessary to store the `Ty<'tcx>` inside of `Expr<'tcx>`. In order to do this without blowing up the size of `ConstKind`, we start storing the type/const args as `GenericArgs` r? `@oli-obk`
2024-06-04Downsize `ty::Expr`Boxy-155/+208
2024-06-04Rollup merge of #125750 - compiler-errors:expect, r=lcnr许杰友 Jieyou Xu (Joe)-5/+13
Align `Term` methods with `GenericArg` methods, add `Term::expect_*` * `Term::ty` -> `Term::as_type`. * `Term::ct` -> `Term::as_const`. * Adds `Term::expect_type` and `Term::expect_const`, and uses them in favor of `.ty().unwrap()`, etc. I could also shorten these to `as_ty` and then do `GenericArg::as_ty` as well, but I do think the `as_` is important to signal that this is a conversion method, and not a getter, like `Const::ty` is. r? types
2024-06-03Align Term methods with GenericArg methodsMichael Goulet-5/+13
2024-06-03Stabilize order of MonoItems in CGUs and disallow query_instability lint for ↵Michael Woerister-30/+21
rustc_monomorphize
2024-06-03check_is_object_safe -> is_object_safeMichael Goulet-1/+1