Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split create_def and lowering of lifetimes for opaque types and bare async fns #99867

Merged
merged 56 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5c23a2e
Remove old docs on lower_async_fn_ret_ty
spastorino Jul 15, 2022
b14c957
Make lower_generic_bound_predicate receive AST bounds instead of HIR …
spastorino Jul 19, 2022
0f11a0c
Add captures flag to capture or not while lowering
spastorino Jul 20, 2022
84a24a1
Unroll while_capturing_lifetimes into lower_opaque_impl_trait
spastorino Jul 20, 2022
cda2c04
Explicitly gather lifetimes and definitions in RPIT
spastorino Jul 20, 2022
399609e
Add debug! calls
spastorino Jul 26, 2022
fac7631
Remove NEW_COLLECT_LIFETIMES env var
spastorino Jul 26, 2022
25825cd
Extract create_and_capture_lifetime_defs function
spastorino Jul 26, 2022
19dcbd1
Explicitly gather lifetimes and definitions for bare async fns
spastorino Jul 26, 2022
5a184ac
There's no need to check binders_to_ignore using the old code anymore
spastorino Jul 26, 2022
9c0d9ba
Do not execute captures code for async fns
spastorino Jul 26, 2022
20c88a2
Do not execute captures code when lowering lifetimes as GenericArg
spastorino Jul 26, 2022
9f77688
Completely remove captures flag
spastorino Jul 26, 2022
4f334f2
Move LifetimeCollectVisitor to rustc_ast_lowering
spastorino Jul 30, 2022
05b989e
Skip lifetimes in binders when visiting
spastorino Aug 1, 2022
81c4d23
Restructure visit_ty in a more clear way
spastorino Aug 2, 2022
1802d45
Record RPITs elided lifetimes in path segments
spastorino Aug 2, 2022
c390bda
Record RPITs elided lifetimes in Rptr Tys
spastorino Aug 2, 2022
14ea178
Fail if LifetimeRes is Infer when creating def ids for lifetimes copies
spastorino Aug 2, 2022
3030ab3
new_named_lifetime_with_res's LifetimeRes::Param should have created …
spastorino Aug 2, 2022
d9e6364
new_named_lifetime_with_res's LifetimeRes::Fresh should have created …
spastorino Aug 2, 2022
6041ed0
No need to check binders to ignore on new_named_lifetime_with_res's L…
spastorino Aug 2, 2022
552f6b0
No need to check binders to ignore on new_named_lifetime_with_res's L…
spastorino Aug 2, 2022
95158fd
No need to store parent_def_id in LifetimeCaptureContext
spastorino Aug 2, 2022
6c6a81e
Remove binders_to_ignore from LifetimeCaptureContext
spastorino Aug 2, 2022
f6b4dd1
Create new_mapping local structure and avoid checking def_ids on capt…
spastorino Aug 2, 2022
2d826e2
Capture things as Lifetime object to simplify things
spastorino Aug 2, 2022
f0db1d6
Remove local_def_id from captured_lifetimes
spastorino Aug 3, 2022
1d6cebf
Implement def_id based remapping
spastorino Aug 2, 2022
1380062
Remove captured_lifetimes and LifetimeCaptureContext and make create_…
spastorino Aug 2, 2022
cd3c388
create_and_capture_lifetime_defs -> create_lifetime_defs
spastorino Aug 2, 2022
40bcbed
Avoid explicitly handling res when is not needed
spastorino Aug 3, 2022
7858509
Add comments about lifetime collect and create lifetime defs for RPITs
spastorino Aug 3, 2022
966269a
Document generics_def_id_map field and record/get methods on it
spastorino Aug 3, 2022
c946cdc
Document opt_local_def_id
spastorino Aug 3, 2022
11e00f5
Add comments on with_remapping
spastorino Aug 3, 2022
6289d0e
with_lifetime_binder is now lower_lifetime_binder and doesn't need a …
spastorino Aug 3, 2022
d85720a
Document lower_opaque_impl_trait
spastorino Aug 3, 2022
76b518f
Document what collected_lifetimes vec containts
spastorino Aug 3, 2022
4b9b583
Move lifetimes_in_bounds call to outside with_hir_id_owner block in l…
spastorino Aug 4, 2022
12fa339
Move lifetimes_in_bounds call to outside with_hir_id_owner block in l…
spastorino Aug 4, 2022
3f7db37
captures -> collected_lifetimes
spastorino Aug 4, 2022
9c7de6f
Move hir_bounds after lifetime_defs
spastorino Aug 4, 2022
a3bfdc7
Add documentation about lifetime_defs
spastorino Aug 4, 2022
cab6740
Add documentation about lifetime args
spastorino Aug 4, 2022
2f353d1
Add more debug calls
spastorino Aug 4, 2022
1ece866
Add documentation for create_lifetime_defs
spastorino Aug 4, 2022
9f10f58
Move new_remapping inside with_hir_id_owner
spastorino Aug 4, 2022
f8b1b2b
Extract record_elided_anchor
spastorino Aug 4, 2022
5e71659
Add docs to record_elided_anchor
spastorino Aug 4, 2022
c0923c8
Add docs to generics_def_id_map
spastorino Aug 4, 2022
45991f9
Use span_bug instead of panic
spastorino Aug 4, 2022
ece5245
Do not collect lifetimes with Infer resolution
spastorino Aug 4, 2022
bf1c7da
Improve record_def_id_remap docs
spastorino Aug 4, 2022
065e497
Improve opt_local_def_id docs
spastorino Aug 4, 2022
4170d73
Fix typo
spastorino Aug 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl fmt::Debug for Label {

/// A "Lifetime" is an annotation of the scope in which variable
/// can be used, e.g. `'a` in `&'a i32`.
#[derive(Clone, Encodable, Decodable, Copy)]
#[derive(Clone, Encodable, Decodable, Copy, PartialEq, Eq)]
pub struct Lifetime {
pub id: NodeId,
pub ident: Ident,
Expand Down
63 changes: 31 additions & 32 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,22 +864,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
(body_id, generator_option)
});

self.with_lifetime_binder(closure_id, generic_params, |this, bound_generic_params| {
// Lower outside new scope to preserve `is_in_loop_condition`.
let fn_decl = this.lower_fn_decl(decl, None, FnDeclKind::Closure, None);

let c = self.arena.alloc(hir::Closure {
binder: binder_clause,
capture_clause,
bound_generic_params,
fn_decl,
body: body_id,
fn_decl_span: this.lower_span(fn_decl_span),
movability: generator_option,
});
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
// Lower outside new scope to preserve `is_in_loop_condition`.
let fn_decl = self.lower_fn_decl(decl, None, FnDeclKind::Closure, None);

let c = self.arena.alloc(hir::Closure {
binder: binder_clause,
capture_clause,
bound_generic_params,
fn_decl,
body: body_id,
fn_decl_span: self.lower_span(fn_decl_span),
movability: generator_option,
});

hir::ExprKind::Closure(c)
})
hir::ExprKind::Closure(c)
}

fn generator_movability_for_fn(
Expand Down Expand Up @@ -991,23 +990,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
body_id
});

self.with_lifetime_binder(closure_id, generic_params, |this, bound_generic_params| {
// We need to lower the declaration outside the new scope, because we
// have to conserve the state of being inside a loop condition for the
// closure argument types.
let fn_decl = this.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None);

let c = self.arena.alloc(hir::Closure {
binder: binder_clause,
capture_clause,
bound_generic_params,
fn_decl,
body,
fn_decl_span: this.lower_span(fn_decl_span),
movability: None,
});
hir::ExprKind::Closure(c)
})
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);

// We need to lower the declaration outside the new scope, because we
// have to conserve the state of being inside a loop condition for the
// closure argument types.
let fn_decl = self.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None);

let c = self.arena.alloc(hir::Closure {
binder: binder_clause,
capture_clause,
bound_generic_params,
fn_decl,
body,
fn_decl_span: self.lower_span(fn_decl_span),
movability: None,
});
hir::ExprKind::Closure(c)
}

/// Destructure the LHS of complex assignments.
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
generator_kind: None,
task_context: None,
current_item: None,
captured_lifetimes: None,
impl_trait_defs: Vec::new(),
impl_trait_bounds: Vec::new(),
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
Expand Down Expand Up @@ -1350,12 +1349,12 @@ impl<'hir> LoweringContext<'_, 'hir> {

let mut predicates: SmallVec<[hir::WherePredicate<'hir>; 4]> = SmallVec::new();
predicates.extend(generics.params.iter().filter_map(|param| {
let bounds = self.lower_param_bounds(&param.bounds, itctx);
self.lower_generic_bound_predicate(
param.ident,
param.id,
&param.kind,
bounds,
&param.bounds,
itctx,
PredicateOrigin::GenericParam,
)
}));
Expand Down Expand Up @@ -1403,13 +1402,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
ident: Ident,
id: NodeId,
kind: &GenericParamKind,
bounds: &'hir [hir::GenericBound<'hir>],
bounds: &[GenericBound],
itctx: ImplTraitContext,
origin: PredicateOrigin,
) -> Option<hir::WherePredicate<'hir>> {
// Do not create a clause if we do not have anything inside it.
if bounds.is_empty() {
return None;
}

let bounds = self.lower_param_bounds(bounds, itctx);

let ident = self.lower_ident(ident);
let param_span = ident.span;
let span = bounds
Expand Down Expand Up @@ -1450,11 +1453,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
GenericParamKind::Lifetime => {
let ident_span = self.lower_span(ident.span);
let ident = self.lower_ident(ident);
let res = self.resolver.get_lifetime_res(id).unwrap_or_else(|| {
panic!("Missing resolution for lifetime {:?} at {:?}", id, ident.span)
});
let lt_id = self.next_node_id();
let lifetime = self.new_named_lifetime_with_res(lt_id, ident_span, ident, res);
let lifetime = self.new_named_lifetime(id, lt_id, ident_span, ident);
Some(hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
lifetime,
span,
Expand Down
Loading