summary refs log tree commit diff
path: root/compiler/rustc_ty_utils/src
AgeCommit message (Collapse)AuthorLines
2024-06-05ty::Expr reviewsBoxy-1/+1
2024-06-05Add `Ty` to `ConstKind::Value`Boxy-4/+1
2024-06-05Basic removal of `Ty` from places (boring)Boxy-25/+16
2024-06-04Downsize `ty::Expr`Boxy-8/+25
2024-06-01Uplift TypeRelation and RelateMichael Goulet-1/+2
2024-05-31Auto merge of #124662 - zetanumbers:needs_async_drop, r=oli-obkbors-21/+19
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-30Auto merge of #125711 - oli-obk:const_block_ice2, r=Nadrierilbors-1/+1
Make `body_owned_by` return the `Body` instead of just the `BodyId` fixes #125677 Almost all `body_owned_by` callers immediately called `body`, too, so just return `Body` directly. This makes the inline-const query feeding more robust, as all calls to `body_owned_by` will now yield a body for inline consts, too. I have not yet figured out a good way to make `tcx.hir().body()` return an inline-const body, but that can be done as a follow-up
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-1/+1
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29Optimize async drop glue for some old typesDaria Sukhonina-2/+3
2024-05-29Start implementing needs_async_drop and relatedDaria Sukhonina-20/+17
2024-05-29Auto merge of #125695 - RalfJung:fn_arg_sanity_check, r=jieyouxubors-1/+2
fn_arg_sanity_check: fix panic message The `\n` inside a raw string doesn't actually make a newline...
2024-05-29fn_arg_sanity_check: fix panic messageRalf Jung-1/+2
also update csky comment in abi/compatibility test
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-1/+1
2024-05-27Rollup merge of #125597 - compiler-errors:early-binder, r=jackh726Guillaume Gomez-5/+5
Uplift `EarlyBinder` into `rustc_type_ir` We also need to give `EarlyBinder` a `'tcx` param, so that we can carry the `Interner` in the `EarlyBinder` too. This is necessary because otherwise we have an unconstrained `I: Interner` parameter in many of the `EarlyBinder`'s inherent impls. I also generally think that this is desirable to have, in case we later want to track some state in the `EarlyBinder`. r? lcnr
2024-05-26Give EarlyBinder a tcx parameterMichael Goulet-5/+5
We are gonna need it to uplift EarlyBinder
2024-05-24Remove `DefId` from `EarlyParamRegion` (tedium/diagnostics)Boxy-5/+1
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_ty_utils`.Nicholas Nethercote-3/+8
2024-05-20Rollup merge of #125173 - scottmcm:never-checked, r=davidtwcoMatthias Krüger-3/+3
Remove `Rvalue::CheckedBinaryOp` Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/intrinsics.20vs.20binop.2Funop/near/438729996> cc `@RalfJung` While it's a draft, r? ghost
2024-05-18Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726bors-5/+5
Rename Unsafe to Safety Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks. This leaves us today with: ```rust enum ast::Safety { Unsafe(Span), Default, // Safe (going to be added for unsafe extern blocks) } enum hir::Safety { Unsafe, Safe, } ``` We would convert from `ast::Safety::Default` into the right Safety level according the context.
2024-05-17Remove `Rvalue::CheckedBinaryOp`Scott McMurray-3/+3
2024-05-17Rename Unsafe to SafetySantiago Pastorino-5/+5
2024-05-16Rename ToPredicate for UpcastMichael Goulet-2/+2
2024-05-13Auto merge of #125076 - compiler-errors:alias-term, r=lcnrbors-1/+1
Split out `ty::AliasTerm` from `ty::AliasTy` Splitting out `AliasTerm` (for use in project and normalizes goals) and `AliasTy` (for use in `ty::Alias`) r? lcnr
2024-05-13split out AliasTy -> AliasTermMichael Goulet-1/+1
2024-05-13Remove `extern crate rustc_middle` from `rustc_ty_utils`.Nicholas Nethercote-2/+12
2024-05-10Rollup merge of #124797 - beetrees:primitive-float, r=davidtwcoMatthias Krüger-7/+2
Refactor float `Primitive`s to a separate `Float` type Now there are 4 of them, it makes sense to refactor `F16`, `F32`, `F64` and `F128` out of `Primitive` and into a separate `Float` type (like integers already are). This allows patterns like `F16 | F32 | F64 | F128` to be simplified into `Float(_)`, and is consistent with `ty::FloatTy`. As a side effect, this PR also makes the `Ty::primitive_size` method work with `f16` and `f128`. Tracking issue: #116909 `@rustbot` label +F-f16_and_f128
2024-05-09Rename Generics::params to Generics::own_paramsMichael Goulet-7/+8
2024-05-06Refactor float `Primitive`s to a separate `Float` typebeetrees-7/+2
2024-05-02Inline & delete `Ty::new_unit`, since it's just a field accessWaffle Lapkin-1/+1
2024-04-30Give items related to issue 33140 a more meaningful nameLeón Orell Valerian Liehr-15/+17
2024-04-25Don't ICE when codegen_select returns ambiguity in new solverMichael Goulet-12/+5
2024-04-23Auto merge of #121801 - zetanumbers:async_drop_glue, r=oli-obkbors-1/+42
Add simple async drop glue generation This is a prototype of the async drop glue generation for some simple types. Async drop glue is intended to behave very similar to the regular drop glue except for being asynchronous. Currently it does not execute synchronous drops but only calls user implementations of `AsyncDrop::async_drop` associative function and awaits the returned future. It is not complete as it only recurses into arrays, slices, tuples, and structs and does not have same sensible restrictions as the old `Drop` trait implementation like having the same bounds as the type definition, while code assumes their existence (requires a future work). This current design uses a workaround as it does not create any custom async destructor state machine types for ADTs, but instead uses types defined in the std library called future combinators (deferred_async_drop, chain, ready_unit). Also I recommend reading my [explainer](https://zetanumbers.github.io/book/async-drop-design.html). This is a part of the [MCP: Low level components for async drop](https://github.com/rust-lang/compiler-team/issues/727) work. Feature completeness: - [x] `AsyncDrop` trait - [ ] `async_drop_in_place_raw`/async drop glue generation support for - [x] Trivially destructible types (integers, bools, floats, string slices, pointers, references, etc.) - [x] Arrays and slices (array pointer is unsized into slice pointer) - [x] ADTs (enums, structs, unions) - [x] tuple-like types (tuples, closures) - [ ] Dynamic types (`dyn Trait`, see explainer's [proposed design](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#async-drop-glue-for-dyn-trait)) - [ ] coroutines (https://github.com/rust-lang/rust/pull/123948) - [x] Async drop glue includes sync drop glue code - [x] Cleanup branch generation for `async_drop_in_place_raw` - [ ] Union rejects non-trivially async destructible fields - [ ] `AsyncDrop` implementation requires same bounds as type definition - [ ] Skip trivially destructible fields (optimization) - [ ] New [`TyKind::AdtAsyncDestructor`](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#adt-async-destructor-types) and get rid of combinators - [ ] [Synchronously undroppable types](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#exclusively-async-drop) - [ ] Automatic async drop at the end of the scope in async context
2024-04-19Stop taking ParamTy/ParamConst/EarlyParamRegion/AliasTy by refMichael Goulet-3/+3
2024-04-19Auto merge of #117919 - daxpedda:wasm-c-abi, r=wesleywiserbors-1/+1
Introduce perma-unstable `wasm-c-abi` flag Now that `wasm-bindgen` v0.2.88 supports the spec-compliant C ABI, the idea is to switch to that in a future version of Rust. In the meantime it would be good to let people test and play around with it. This PR introduces a new perma-unstable `-Zwasm-c-abi` compiler flag, which switches to the new spec-compliant C ABI when targeting `wasm32-unknown-unknown`. Alternatively, we could also stabilize this and then deprecate it when we switch. I will leave this to the Rust maintainers to decide. This is a companion PR to #117918, but they could be merged independently. MCP: https://github.com/rust-lang/compiler-team/issues/703 Tracking issue: https://github.com/rust-lang/rust/issues/122532
2024-04-18Fix disabling the export of noop async_drop_in_place_rawDaria Sukhonina-1/+1
2024-04-17Use non-exhaustive matches for TyKindDaria Sukhonina-36/+17
Also no longer export noop async_drop_in_place_raw
2024-04-16Add simple async drop glue generationzetanumbers-1/+61
Explainer: https://zetanumbers.github.io/book/async-drop-design.html https://github.com/rust-lang/rust/pull/121801
2024-04-16Fail candidate assembly for erroneous typesGurinder Singh-2/+2
Trait predicates for types which have errors may still evaluate to OK leading to downstream ICEs. Now we return a selection error for such types in candidate assembly and thereby prevent such issues
2024-04-09Handle const generic pattern typesSantiago Pastorino-2/+6
2024-04-08Actually create ranged int types in the type system.Oli Scherer-0/+36
2024-04-04Rollup merge of #123464 - fmease:rn-has-proj-to-has-aliases, r=compiler-errorsJacob Pratt-2/+2
Cleanup: Rename `HAS_PROJECTIONS` to `HAS_ALIASES` etc. The name of the bitflag `HAS_PROJECTIONS` and of its corresponding method `has_projections` is quite historical dating back to a time when projections were the only kind of alias type. I think it's time to update it to clear up any potential confusion for newcomers and to reduce unnecessary friction during contributor onboarding. r? types
2024-04-04Rename HAS_PROJECTIONS to HAS_ALIASES etc.León Orell Valerian Liehr-2/+2
2024-04-04Auto merge of #123377 - oli-obk:private_projection, r=compiler-errorsbors-5/+6
Only inspect user-written predicates for privacy concerns fixes #123288 Previously we looked at the elaborated predicates, which, due to adding various bounds on fields, end up requiring trivially true bounds. But these bounds can contain private types, which the privacy visitor then found and errored about.
2024-04-04Only inspect user-written predicates for privacy concernsOli Scherer-5/+6
2024-04-04Rollup merge of #121546 - gurry:121473-ice-sizeof-mir-op, r=oli-obkMatthias Krüger-1/+37
Error out of layout calculation if a non-last struct field is unsized Fixes #121473 Fixes #123152
2024-04-04Error out of layout calculation if a non-last struct field is unsizedGurinder Singh-1/+37
Fixes an ICE that occurs when a struct with an unsized field at a non-last position is const evaluated.
2024-04-04Auto merge of #123240 - compiler-errors:assert-args-compat, r=fmeasebors-2/+1
Assert that args are actually compatible with their generics, rather than just their count Right now we just check that the number of args is right, rather than actually checking the kinds. Uplift a helper fn that I wrote from trait selection to do just that. Found a couple bugs along the way. r? `@lcnr` or `@fmease` (or anyone really lol)
2024-04-03rustc_index: Add a `ZERO` constant to index typesVadim Petrochenkov-1/+1
It is commonly used.
2024-04-03Uplift and start using check_args_compatible more liberallyMichael Goulet-2/+1
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-1/+1
Add `Ord::cmp` for primitives as a `BinOp` in MIR Update: most of this OP was written months ago. See https://github.com/rust-lang/rust/pull/118310#issuecomment-2016940014 below for where we got to recently that made it ready for review. --- There are dozens of reasonable ways to implement `Ord::cmp` for integers using comparison, bit-ops, and branches. Those differences are irrelevant at the rust level, however, so we can make things better by adding `BinOp::Cmp` at the MIR level: 1. Exactly how to implement it is left up to the backends, so LLVM can use whatever pattern its optimizer best recognizes and cranelift can use whichever pattern codegens the fastest. 2. By not inlining those details for every use of `cmp`, we drastically reduce the amount of MIR generated for `derive`d `PartialOrd`, while also making it more amenable to MIR-level optimizations. Having extremely careful `if` ordering to μoptimize resource usage on broadwell (#63767) is great, but it really feels to me like libcore is the wrong place to put that logic. Similarly, using subtraction [tricks](https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign) (#105840) is arguably even nicer, but depends on the optimizer understanding it (https://github.com/llvm/llvm-project/issues/73417) to be practical. Or maybe [bitor is better than add](https://discourse.llvm.org/t/representing-in-ir/67369/2?u=scottmcm)? But maybe only on a future version that [has `or disjoint` support](https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036?u=scottmcm)? And just because one of those forms happens to be good for LLVM, there's no guarantee that it'd be the same form that GCC or Cranelift would rather see -- especially given their very different optimizers. Not to mention that if LLVM gets a spaceship intrinsic -- [which it should](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Suboptimal.20inlining.20in.20std.20function.20.60binary_search.60/near/404250586) -- we'll need at least a rustc intrinsic to be able to call it. As for simplifying it in Rust, we now regularly inline `{integer}::partial_cmp`, but it's quite a large amount of IR. The best way to see that is with https://github.com/rust-lang/rust/commit/8811efa88b25b5e41d63850e6047e8257c677858#diff-d134c32d028fbe2bf835fef2df9aca9d13332dd82284ff21ee7ebf717bfa4765R113 -- I added a new pre-codegen MIR test for a simple 3-tuple struct, and this PR change it from 36 locals and 26 basic blocks down to 24 locals and 8 basic blocks. Even better, as soon as the construct-`Some`-then-match-it-in-same-BB noise is cleaned up, this'll expose the `Cmp == 0` branches clearly in MIR, so that an InstCombine (#105808) can simplify that to just a `BinOp::Eq` and thus fix some of our generated code perf issues. (Tracking that through today's `if a < b { Less } else if a == b { Equal } else { Greater }` would be *much* harder.) --- r? `@ghost` But first I should check that perf is ok with this ~~...and my true nemesis, tidy.~~