about summary refs log tree commit diff
path: root/compiler/rustc_ty_utils/src
AgeCommit message (Collapse)AuthorLines
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.~~
2024-03-27Rollup merge of #123021 - compiler-errors:coroutine-layout-lol, r=oli-obkGuillaume Gomez-2/+2
Make `TyCtxt::coroutine_layout` take coroutine's kind parameter For coroutines that come from coroutine-closures (i.e. async closures), we may have two kinds of bodies stored in the coroutine; one that takes the closure's captures by reference, and one that takes the captures by move. These currently have identical layouts, but if we do any optimization for these layouts that are related to the upvars, then they will diverge -- e.g. https://github.com/rust-lang/rust/pull/120168#discussion_r1536943728. This PR relaxes the assertion I added in #121122, and instead make the `TyCtxt::coroutine_layout` method take the `coroutine_kind_ty` argument from the coroutine, which will allow us to differentiate these by-move and by-ref bodies.
2024-03-26In ConstructCoroutineInClosureShim, pass receiver by ref, not pointerMichael Goulet-2/+6
2024-03-24Require coroutine kind type to be passed to TyCtxt::coroutine_layoutMichael Goulet-2/+2
2024-03-24Always use tcx.coroutine_layout over calling optimized_mir directlyMichael Goulet-1/+1
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-1/+1
2024-03-22-Zprint-type-sizes: print the types of awaitees and unnamed coroutine locals.Kevin Reid-1/+9
This should assist comprehending the size of coroutines. In particular, whenever a future is suspended while awaiting another future, the latter is given the special name `__awaitee`, and now the type of the awaited future will be printed, allowing identifying caller/callee — er, I mean, poller/pollee — relationships. It would be possible to include the type name in more cases, but I thought that that might be overly verbose (`print-type-sizes` is already a lot of text) and ordinary named fields or variables are easier for readers to discover the types of.
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-2/+2
2024-03-19Fix ABI for FnMut/Fn impls for async closuresMichael Goulet-4/+13
2024-03-19Only split by-ref/by-move futures for async closuresMichael Goulet-29/+22
2024-03-19Ensure nested statics have a HIR node to prevent various queries from ICEingOli Scherer-25/+4
2024-03-19The AssocOpaqueTy HIR node is not actually needed to differentiate from ↵Oli Scherer-5/+3
other hir nodes that were fed
2024-03-19Auto merge of #122493 - lukas-code:sized-constraint, r=lcnrbors-74/+68
clean up `Sized` checking This PR cleans up `sized_constraint` and related functions to make them simpler and faster. This should not make more or less code compile, but it can change error output in some rare cases. ## enums and unions are `Sized`, even if they are not WF The previous code has some special handling for enums, which made them sized if and only if the last field of each variant is sized. For example given this definition (which is not WF) ```rust enum E<T1: ?Sized, T2: ?Sized, U1: ?Sized, U2: ?Sized> { A(T1, T2), B(U1, U2), } ``` the enum was sized if and only if `T2` and `U2` are sized, while `T1` and `T2` were ignored for `Sized` checking. After this PR this enum will always be sized. Unsized enums are not a thing in Rust and removing this special case allows us to return an `Option<Ty>` from `sized_constraint`, rather than a `List<Ty>`. Similarly, the old code made an union defined like this ```rust union Union<T: ?Sized, U: ?Sized> { head: T, tail: U, } ``` sized if and only if `U` is sized, completely ignoring `T`. This just makes no sense at all and now this union is always sized. ## apply the "perf hack" to all (non-error) types, instead of just type parameters This "perf hack" skips evaluating `sized_constraint(adt): Sized` if `sized_constraint(adt): Sized` exactly matches a predicate defined on `adt`, for example: ```rust // `Foo<T>: Sized` iff `T: Sized`, but we know `T: Sized` from a predicate of `Foo` struct Foo<T /*: Sized */>(T); ``` Previously this was only applied to type parameters and now it is applied to every type. This means that for example this type is now always sized: ```rust // Note that this definition is WF, but the type `S<T>` not WF in the global/empty ParamEnv struct S<T>([T]) where [T]: Sized; ``` I don't anticipate this to affect compile time of any real-world program, but it makes the code a bit nicer and it also makes error messages a bit more consistent if someone does write such a cursed type. ## tuples are sized if the last type is sized The old solver already has this behavior and this PR also implements it for the new solver and `is_trivially_sized`. This makes it so that tuples work more like a struct defined like this: ```rust struct TupleN<T1, T2, /* ... */ Tn: ?Sized>(T1, T2, /* ... */ Tn); ``` This might improve the compile time of programs with large tuples a little, but is mostly also a consistency fix. ## `is_trivially_sized` for more types This function is used post-typeck code (borrowck, const eval, codegen) to skip evaluating `T: Sized` in some cases. It will now return `true` in more cases, most notably `UnsafeCell<T>` and `ManuallyDrop<T>` where `T.is_trivially_sized`. I'm anticipating that this change will improve compile time for some real world programs.
2024-03-18address nitsLukas Markeffsky-7/+4
2024-03-15Rollup merge of #122513 - petrochenkov:somehir4, r=fmeaseGuillaume Gomez-5/+1
hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id` Also replace a few `hir_node()` calls with `hir_node_by_def_id()`. Follow up to https://github.com/rust-lang/rust/pull/120943.
2024-03-14Fill in HIR hash for associated opaque typesVadim Petrochenkov-3/+9
2024-03-14clean up ADT sized constraint computationLukas Markeffsky-70/+67
2024-03-14make `Representability::Infinite` carry `ErrorGuaranteed`Lukas Markeffsky-3/+3
2024-03-14hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id`Vadim Petrochenkov-5/+1
Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
2024-03-13Create some minimal HIR for associated opaque typesVadim Petrochenkov-8/+21
2024-03-12Rollup merge of #122366 - oli-obk:opaques_defined_by_overflow, r=lcnrJubilee-0/+4
Fix stack overflow with recursive associated types fixes #122364
2024-03-12Fix stack overflow with recursive associated typesOli Scherer-0/+4
2024-03-12Manual rustfmtOli Scherer-2/+2
2024-03-12Change `DefKind::Static` to a struct variantOli Scherer-3/+3
2024-03-11update comment for RPITIT projectionslcnr-15/+22
2024-03-11Make `DefiningAnchor::Bind` only store the opaque types that may be ↵Oli Scherer-1/+25
constrained, instead of the current infcx root item. This makes `Bind` almost always be empty, so we can start forwarding it to queries, allowing us to remove `Bubble` entirely
2024-03-10Introduce perma-unstable `wasm-c-abi` flagdaxpedda-1/+1
2024-03-09Rollup merge of #122237 - fee1-dead-contrib:rmord, r=compiler-errorsMatthias Krüger-17/+20
Remove `Ord` from `ClosureKind` Using `Ord` to accomplish a meaning of subset relationship can be hard to read. The existing uses for that are easily replaced with a `match`, and in my opinion, more readable without needing to resorting to comments to explain the intention. cc `@compiler-errors`
2024-03-09Remove `Ord` from `ClosureKind`Deadbeef-17/+20
Using `Ord` to accomplish a meaning of subset relationship can be hard to read. The existing uses for that are easily replaced with a `match`, and in my opinion, more readable without needing to resorting to comments to explain the intention.
2024-03-08Rename some functions to represent their generalized behaviorMichael Goulet-1/+1
2024-03-08Make TAITs capture all higher-ranked lifetimes in scopeMichael Goulet-1/+1