about summary refs log tree commit diff
path: root/compiler/rustc_middle
AgeCommit message (Collapse)AuthorLines
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
2024-06-03Auto merge of #125778 - estebank:issue-67100, r=compiler-errorsbors-1/+1
Use parenthetical notation for `Fn` traits Always use the `Fn(T) -> R` format when printing closure traits instead of `Fn<(T,), Output = R>`. Address #67100: ``` error[E0277]: expected a `Fn()` closure, found `F` --> file.rs:6:13 | 6 | call_fn(f) | ------- ^ expected an `Fn()` closure, found `F` | | | required by a bound introduced by this call | = note: wrap the `F` in a closure with no arguments: `|| { /* code */ }` note: required by a bound in `call_fn` --> file.rs:1:15 | 1 | fn call_fn<F: Fn() -> ()>(f: &F) { | ^^^^^^^^^^ required by this bound in `call_fn` help: consider further restricting this bound | 5 | fn call_any<F: std::any::Any + Fn()>(f: &F) { | ++++++ ```
2024-06-01Auto merge of #125775 - compiler-errors:uplift-closure-args, r=lcnrbors-730/+126
Uplift `{Closure,Coroutine,CoroutineClosure}Args` and friends to `rustc_type_ir` Part of converting the new solver's `structural_traits.rs` to be interner-agnostic. I decided against aliasing `ClosureArgs<TyCtxt<'tcx>>` to `ClosureArgs<'tcx>` because it seemed so rare. I could do so if desired, though. r? lcnr
2024-06-01Uplift TypeRelation and RelateMichael Goulet-717/+126
2024-06-01Yeet PolyFnSig from InternerMichael Goulet-13/+0
2024-06-01Simplify IntVarValue/FloatVarValueMichael Goulet-36/+2
2024-06-01Deduplicate supertrait_def_ids codeMark Rousskov-12/+10
2024-06-01Increase vtable layout sizeMark Rousskov-18/+71
This improves LLVM's codegen by allowing vtable loads to be hoisted out of loops (as just one example).
2024-05-31Auto merge of #124662 - zetanumbers:needs_async_drop, r=oli-obkbors-132/+245
Implement `needs_async_drop` in rustc and optimize async drop glue This PR expands on #121801 and implements `Ty::needs_async_drop` which works almost exactly the same as `Ty::needs_drop`, which is needed for #123948. Also made compiler's async drop code to look more like compiler's regular drop code, which enabled me to write an optimization where types which do not use `AsyncDrop` can simply forward async drop glue to `drop_in_place`. This made size of the async block from the [async_drop test](https://github.com/zetanumbers/rust/blob/67980dd6fb11917d23d01a19c2cf4cfc3978aac8/tests/ui/async-await/async-drop.rs) to decrease by 12%.
2024-05-31Rollup merge of #125635 - fmease:mv-type-binding-assoc-item-constraint, ↵Matthias Krüger-2/+2
r=compiler-errors Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup Rename `hir::TypeBinding` and `ast::AssocConstraint` to `AssocItemConstraint` and update all items and locals using the old terminology. Motivation: The terminology *type binding* is extremely outdated. "Type bindings" not only include constraints on associated *types* but also on associated *constants* (feature `associated_const_equality`) and on RPITITs of associated *functions* (feature `return_type_notation`). Hence the word *item* in the new name. Furthermore, the word *binding* commonly refers to a mapping from a binder/identifier to a "value" for some definition of "value". Its use in "type binding" made sense when equality constraints (e.g., `AssocTy = Ty`) were the only kind of associated item constraint. Nowadays however, we also have *associated type bounds* (e.g., `AssocTy: Bound`) for which the term *binding* doesn't make sense. --- Old terminology (HIR, rustdoc): ``` `TypeBinding`: (associated) type binding ├── `Constraint`: associated type bound └── `Equality`: (associated) equality constraint (?) ├── `Ty`: (associated) type binding └── `Const`: associated const equality (constraint) ``` Old terminology (AST, abbrev.): ``` `AssocConstraint` ├── `Bound` └── `Equality` ├── `Ty` └── `Const` ``` New terminology (AST, HIR, rustdoc): ``` `AssocItemConstraint`: associated item constraint ├── `Bound`: associated type bound └── `Equality`: associated item equality constraint OR associated item binding (for short) ├── `Ty`: associated type equality constraint OR associated type binding (for short) └── `Const`: associated const equality constraint OR associated const binding (for short) ``` r? compiler-errors
2024-05-30Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanupLeón Orell Valerian Liehr-2/+2
2024-05-30Rollup merge of #125754 - Zalathar:conditions-num, r=lqdMatthias Krüger-4/+4
coverage: Rename MC/DC `conditions_num` to `num_conditions` Updated version of #124571, without the other changes that were split out into #125108 and #125700. This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate. Some of the code touched by this PR could perhaps use some other changes, but I would prefer to keep this PR as a simple renaming and avoid scope creep. `@rustbot` label +A-code-coverage
2024-05-30transmute size check: properly account for alignmentRalf Jung-8/+17
2024-05-30coverage: Rename MC/DC `conditions_num` to `num_conditions`Zalathar-4/+4
This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate.
2024-05-29Use parenthetical notation for `Fn` traitsEsteban Küber-1/+1
Always use the `Fn(T) -> R` format when printing closure traits instead of `Fn<(T,), Output = R>`. Fix #67100: ``` error[E0277]: expected a `Fn()` closure, found `F` --> file.rs:6:13 | 6 | call_fn(f) | ------- ^ expected an `Fn()` closure, found `F` | | | required by a bound introduced by this call | = note: wrap the `F` in a closure with no arguments: `|| { /* code */ }` note: required by a bound in `call_fn` --> file.rs:1:15 | 1 | fn call_fn<F: Fn() -> ()>(f: &F) { | ^^^^^^^^^^ required by this bound in `call_fn` help: consider further restricting this bound | 5 | fn call_any<F: std::any::Any + Fn()>(f: &F) { | ++++++ ```
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-7/+25
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29fix non-existing ToPredicate trait errorDaria Sukhonina-2/+2
2024-05-29Optimize async drop glue for some old typesDaria Sukhonina-79/+112
2024-05-29Start implementing needs_async_drop and relatedDaria Sukhonina-90/+170
2024-05-29Rollup merge of #125633 - RalfJung:miri-no-copy, r=saethlin许杰友 Jieyou Xu (Joe)-22/+21
miri: avoid making a full copy of all new allocations Hopefully fixes https://github.com/rust-lang/miri/issues/3637 r? ``@saethlin``
2024-05-29Rollup merge of #124251 - scottmcm:unop-ptr-metadata, r=oli-obk许杰友 Jieyou Xu (Joe)-1/+34
Add an intrinsic for `ptr::metadata` The follow-up to #123840, so we can remove `PtrComponents` and `PtrRepr` from libcore entirely (well, after a bootstrap update). As discussed in <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/.60ptr_metadata.60.20in.20MIR/near/435637808>, this introduces `UnOp::PtrMetadata` taking a raw pointer and returning the associated metadata value. By no longer going through a `union`, this should also help future PRs better optimize pointer operations. r? ``@oli-obk``
2024-05-28Auto merge of #125665 - matthiaskrgr:rollup-srkx0v1, r=matthiaskrgrbors-0/+7
Rollup of 5 pull requests Successful merges: - #117671 (NVPTX: Avoid PassMode::Direct for args in C abi) - #125573 (Migrate `run-make/allow-warnings-cmdline-stability` to `rmake.rs`) - #125590 (Add a "Setup Python" action for github-hosted runners and remove unnecessary `CUSTOM_MINGW` environment variable) - #125598 (Make `ProofTreeBuilder` actually generic over `Interner`) - #125637 (rustfmt fixes) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-1/+34
2024-05-28Rollup merge of #125598 - compiler-errors:proof-tree-builder, r=lcnrMatthias Krüger-0/+7
Make `ProofTreeBuilder` actually generic over `Interner` Self-explanatory. Also renamed `ecx.tcx()` to `ecx.interner()`. r? lcnr
2024-05-28Auto merge of #122662 - Mark-Simulacrum:optional-drop, r=bjorn3bors-4/+8
Omit non-needs_drop drop_in_place in vtables This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included. This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime. Accepted MCP: https://github.com/rust-lang/compiler-team/issues/730
2024-05-28Make ProofTreeBuilder actually generic over internerMichael Goulet-0/+7
2024-05-28Cache whether a body has inline constsOli Scherer-0/+1
2024-05-28Create const block DefIds in typeck instead of ast loweringOli Scherer-9/+17
2024-05-28eagerly normalize when adding goalslcnr-6/+3
2024-05-27miri: avoid making a full copy of all new allocationsRalf Jung-22/+21