about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/closure.rs
AgeCommit message (Collapse)AuthorLines
2023-12-12Uplift ClosureKindMichael Goulet-70/+3
2023-11-26Auto merge of #118316 - Mark-Simulacrum:delete-copy-to-upvars, r=cjgillotbors-0/+7
Remove borrowck Upvar duplication This cuts out an extra allocation and copying over from the already cached closure capture information.
2023-11-26Remove Upvar duplicationMark Rousskov-0/+7
This cuts out an extra allocation and copying over from the already cached closure capture information.
2023-11-26rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` ↵Vadim Petrochenkov-1/+1
cleanup
2023-08-07Migrate a trait selection error to use diagnostic translationDeadbeef-2/+17
2023-08-04Rollup merge of #114022 - oli-obk:tait_ice_alias_field_projection, r=cjgillotMatthias Krüger-0/+2
Perform OpaqueCast field projection on HIR, too. fixes #105819 This is necessary for closure captures in 2021 edition, as they capture individual fields, not the full mentioned variables. So it may try to capture a field of an opaque (because the hidden type is known to be something with a field). See https://github.com/rust-lang/rust/pull/99806 for when and why we added OpaqueCast to MIR.
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-1/+1
2023-07-24Perform OpaqueCast field projection on HIR, too.Oli Scherer-0/+2
This is necessary for closure captures in 2021 edition, as they capture individual fields, not the full mentioned variables. So it may try to capture a field of an opaque (because the hidden type is known to be something with a field).
2023-07-14Enable potential_query_instability lint in rustc_hir_typeck.Michael Woerister-5/+3
Fix linting errors by using FxIndex(Map|Set) and Unord(Map|Set) as appropriate.
2023-06-20address most easy commentsZiru Niu-0/+2
2023-05-15Move expansion of query macros in rustc_middle to rustc_middle::queryJohn Kåre Alsaker-2/+3
2023-03-30Update `ty::VariantDef` to use `IndexVec<FieldIdx, FieldDef>`Scott McMurray-4/+4
And while doing the updates for that, also uses `FieldIdx` in `ProjectionKind::Field` and `TypeckResults::field_indices`. There's more places that could use it (like `rustc_const_eval` and `LayoutS`), but I tried to keep this PR from exploding to *even more* places. Part 2/? of https://github.com/rust-lang/compiler-team/issues/606
2023-02-26Wrap more into into closure_typeinfo query.Camille GILLOT-8/+32
2023-02-26Access upvars through a query.Camille GILLOT-18/+18
2022-12-20rustc: Remove needless lifetimesJeremy Stucki-4/+1
2022-11-28Rollup merge of #104732 - WaffleLapkin:from_def_idn't, r=compiler-errorsDylan DPC-31/+14
Refactor `ty::ClosureKind` related stuff I've tried to fix all duplication and weirdness, but if I missed something do tell :p r? `@compiler-errors`
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-3/+3
2022-11-27micro doc fixesMaybe Waffle-11/+11
2022-11-27Simplify `ty::ClosureKind::extends`Maybe Waffle-9/+1
This is valid per the comment of the `ClosureKind` defition
2022-11-27Remove `ty::ClosureKind::from_def_id`Maybe Waffle-12/+3
…in favour of `TyCtxt::fn_trait_kind_from_def_id`
2022-11-22Fix `ClosureKind::to_def_id`Maybe Waffle-5/+9
2022-07-30Use LocalDefId for closures moreCameron Steffen-2/+2
2022-07-18Use span_bug for unexpected field projection typeJordan McQueen-1/+5
Improves the compiler error backtrace information, as shown in #99363, by using `span_bug` instead of `bug`. New output: ``` build/aarch64-apple-darwin/stage1/bin/rustc /tmp/test.rs --edition=2021 error: internal compiler error: compiler/rustc_middle/src/ty/closure.rs:185:25: Unexpected type Opaque(DefId(0:5 ~ test[db0f]::main::T::{opaque#0}), []) for `Field` projection --> /tmp/test.rs:11:27 | 11 | let Foo((a, b)) = foo; | ^^^ thread 'rustc' panicked at 'Box<dyn Any>', /Users/jmq/src/forked/rust/compiler/rustc_errors/src/lib.rs:1331:9 stack backtrace: ``` (Remainder of output truncated.)
2022-07-14Point out custom Fn-family trait implMichael Goulet-0/+8
2022-07-05Add #[derive(TypeVisitable)]Alan Egerton-17/+12
2022-05-02fix most compiler/ doctestsElliot Roberts-11/+14
2022-03-23Better suggestions for Fn trait selection errorsMichael Goulet-3/+15
2022-03-12Auto merge of #94733 - nnethercote:fix-AdtDef-interning, r=fee1-deadbors-2/+2
Improve `AdtDef` interning. This commit makes `AdtDef` use `Interned`. Much of the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`. r? `@fee1-dead`
2022-03-11Improve `AdtDef` interning.Nicholas Nethercote-2/+2
This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`.
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-1/+1
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-02-15Overhaul `TyS` and `Ty`.Nicholas Nethercote-1/+1
Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable.
2022-01-13Auto merge of #89861 - nbdd0121:closure, r=wesleywiserbors-24/+10
Closure capture cleanup & refactor Follow up of #89648 Each commit is self-contained and the rationale/changes are documented in the commit message, so it's advisable to review commit by commit. The code is significantly cleaner (at least IMO), but that could have some perf implication, so I'd suggest a perf run. r? `@wesleywiser` cc `@arora-aman`
2022-01-11Store a `Symbol` instead of an `Ident` in `VariantDef`/`FieldDef`Aaron Hill-2/+2
The field is also renamed from `ident` to `name. In most cases, we don't actually need the `Span`. A new `ident` method is added to `VariantDef` and `FieldDef`, which constructs the full `Ident` using `tcx.def_ident_span()`. This method is used in the cases where we actually need an `Ident`. This makes incremental compilation properly track changes to the `Span`, without all of the invalidations caused by storing a `Span` directly via an `Ident`.
2022-01-07Remove region from UpvarCapture and move it to CapturedPlaceGary Guo-17/+9
Region info is completely unnecessary for upvar capture kind computation and is only needed to create the final upvar tuple ty. Doing so makes creation of UpvarCapture very cheap and expose further cleanup opportunity.
2022-01-07Remove span from UpvarCapture::ByValueGary Guo-7/+1
This span is unused and is superseded by capture_kind_expr_id in CaptureInfo
2021-12-15Remove `in_band_lifetimes` from `rustc_middle`Aaron Hill-2/+2
See #91867 This was mostly straightforward. In several places, I take advantage of the fact that lifetimes are non-hygenic: a macro declares the 'tcx' lifetime, which is then used in types passed in as macro arguments.
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-08-14Auto merge of #85020 - lrh2000:named-upvars, r=tmandrybors-1/+53
Name the captured upvars for closures/generators in debuginfo Previously, debuggers print closures as something like ``` y::main::closure-0 (0x7fffffffdd34) ``` The pointer actually references to an upvar. It is not very obvious, especially for beginners. It's because upvars don't have names before, as they are packed into a tuple. This PR names the upvars, so we can expect to see something like ``` y::main::closure-0 {_captured_ref__b: 0x[...]} ``` r? `@tmandry` Discussed at https://github.com/rust-lang/rust/pull/84752#issuecomment-831639489 .
2021-07-17rustc_middle: remove redundant cloneMatthias Krüger-3/+2
found while looking through some clippy lint warnings
2021-07-10Add a query for `CapturedPlace::to_symbol`lrh2000-1/+14
2021-07-09Store names of captured variables in `optimized_mir`lrh2000-22/+13
- Closures in external crates may get compiled in because of monomorphization. We should store names of captured variables in `optimized_mir`, so that they are written into the metadata file and we can use them to generate debuginfo. - If there are breakpoints inside closures, the names of captured variables stored in `optimized_mir` can be used to print them. Now the name is more precise when disjoint fields are captured.
2021-07-09Name the captured upvars for closures/generators in debuginfolrh2000-0/+48
Previously, debuggers print closures as something like ``` y::main::closure-0 (0x7fffffffdd34) ``` The pointer actually references to an upvar. It is not very obvious, especially for beginners. It's because upvars don't have names before, as they are packed into a tuple. This commit names the upvars, so we can expect to see something like ``` y::main::closure-0 {_captured_ref__b: 0x[...]} ```
2021-07-04Fix comments about unique borrowsLeSeulArtichaut-1/+1
2021-05-23Replace Local::new(1) with CAPTURE_STRUCT_LOCALPaul Trojahn-1/+5
2021-05-01Closure capture borrow diagnostics for disjoint capturesChris Pardy-0/+20
2021-04-19fix few typosklensy-1/+1
2021-03-27Remove (lots of) dead codeJoshua Nelson-17/+0
Found with https://github.com/est31/warnalyzer. Dubious changes: - Is anyone else using rustc_apfloat? I feel weird completely deleting x87 support. - Maybe some of the dead code in rustc_data_structures, in case someone wants to use it in the future? - Don't change rustc_serialize I plan to scrap most of the json module in the near future (see https://github.com/rust-lang/compiler-team/issues/418) and fixing the tests needed more work than I expected. TODO: check if any of the comments on the deleted code should be kept.
2021-03-18Replace closures_captures and upvar_capture with closure_min_capturesJennifer Wills-0/+50
make changes to liveness to use closure_min_captures use different span borrow check uses new structures rename to CapturedPlace stop using upvar_capture in regionck remove the bridge cleanup from rebase + remove the upvar_capture reference from mutability_errors.rs remove line from livenes test make our unused var checking more consistent update tests adding more warnings to the tests move is_ancestor_or_same_capture to rustc_middle/ty update names to reflect the closures add FIXME check that all captures are immutable borrows before returning add surrounding if statement like the original move var out of the loop and rename Co-authored-by: Logan Mosier <logmosier@gmail.com> Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2021-03-10Moved more of the capture related types into closure.rsNicholas-Baron-2/+173
2021-03-10Moved more types into upvar.rs (now named closure.rs)Nicholas-Baron-0/+167