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

Misc lowering cleanups #51654

Closed
wants to merge 20 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4093d37
Use `PathParameters` even if just the `lifetimes` field is used
oli-obk Jun 18, 2018
5181218
Cleanup in preparation of generic extraction
oli-obk Jun 18, 2018
dea4d5b
Generate the `NodeId` for `existential type` in the AST
oli-obk Jun 18, 2018
2b7f86a
Reduce repetition around `lower_method_sig`
oli-obk Jun 19, 2018
0dcb45e
Deduplicate code in `lower_lifetime`
oli-obk Jun 19, 2018
98d4500
Remove some global state from the lowering pass
oli-obk Jun 19, 2018
3ae2e31
Pass generics through to existential impl Trait lowering
oli-obk Jun 19, 2018
3dbe348
Don't generate a new NodeId for universal impl Trait
oli-obk Jun 20, 2018
90a54c1
Generate `DefId`s for impl Trait in the def_collector
oli-obk Jun 20, 2018
2fdb64c
Update ui tests
oli-obk Jun 20, 2018
19f5e5e
While we don't have full existential types yet, there is some duplica…
oli-obk Jun 20, 2018
a83733f
Flatten some occurrences of `[P<T>]` to `[T]`
oli-obk Jun 20, 2018
47732a4
Prevent lowering item ids from behaving differently than lowering items
oli-obk Jun 21, 2018
057cf0f
Update rustdoc
oli-obk Jun 21, 2018
1bf351d
We now have proper locations for the `existential type` items.
oli-obk Jun 22, 2018
356d683
Also place method impl trait into the surrounding module
oli-obk Jun 22, 2018
398a5f8
Ignore existential type items during collection for now
oli-obk Jun 22, 2018
9859a52
Don't try to do impl Trait lowering for `impl Trait for Type` items
oli-obk Jun 22, 2018
a152770
Generics Unification rebase fallout
oli-obk Jun 25, 2018
922249c
Update tests
oli-obk Jun 25, 2018
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
Prev Previous commit
Next Next commit
Generics Unification rebase fallout
oli-obk committed Jun 25, 2018
commit a1527702c31452c7d7d6edb13acc87fed8134cb9
51 changes: 25 additions & 26 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
@@ -174,7 +174,7 @@ enum ImplTraitContext<'a> {
/// We store a DefId here so we can look up necessary information later
///
/// Newly generated parameters should be inserted into the given `Vec`
Universal(DefId, &'a mut Vec<hir::TyParam>),
Universal(DefId, &'a mut Vec<hir::GenericParam>),

/// Treat `impl Trait` as shorthand for a new universal existential parameter.
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
@@ -183,7 +183,7 @@ enum ImplTraitContext<'a> {
/// We store a DefId here so we can look up necessary information later
///
/// All generics of the surrounding function must go into the generated existential type
Existential(DefId, &'a [hir::TyParam], &'a hir::Generics),
Existential(DefId, &'a [hir::GenericParam], &'a hir::Generics),

/// `impl Trait` is not accepted in this position.
Disallowed,
@@ -656,7 +656,7 @@ impl<'a> LoweringContext<'a> {
f: F,
) -> (Vec<hir::GenericParam>, T)
where
F: FnOnce(&mut LoweringContext) -> (Vec<hir::TyParam>, T),
F: FnOnce(&mut LoweringContext) -> (Vec<hir::GenericParam>, T),
{
assert!(!self.is_collecting_in_band_lifetimes);
assert!(self.lifetimes_to_define.is_empty());
@@ -804,7 +804,7 @@ impl<'a> LoweringContext<'a> {
f: F,
) -> (hir::Generics, T)
where
F: FnOnce(&mut LoweringContext, &mut Vec<hir::TyParam>, &hir::Generics) -> T,
F: FnOnce(&mut LoweringContext, &mut Vec<hir::GenericParam>, &hir::Generics) -> T,
{
let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs(
&generics.params,
@@ -1045,7 +1045,7 @@ impl<'a> LoweringContext<'a> {
-> hir::GenericArg {
match arg {
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(&lt)),
ast::GenericArg::Type(ty) => GenericArg::Type(self.lower_ty(&ty, itctx)),
ast::GenericArg::Type(ty) => GenericArg::Type(self.lower_ty_direct(&ty, itctx)),
}
}

@@ -1175,7 +1175,7 @@ impl<'a> LoweringContext<'a> {
lctx.lower_param_bounds(bounds, itctx)
});

let (path_params, params) = self.generics_from_impl_trait_bounds(
let (params, lifetimes) = self.generics_from_impl_trait_bounds(
def_node_id,
exist_ty_def_index,
&hir_bounds,
@@ -1222,7 +1222,7 @@ impl<'a> LoweringContext<'a> {
id: exist_ty_id.node_id
},
DefId::local(exist_ty_def_index),
path_params.lifetimes,
lifetimes,
)
})
}
@@ -1241,7 +1241,7 @@ impl<'a> LoweringContext<'a> {
);
// Set the name to `impl Bound1 + Bound2`
let name = Symbol::intern(&pprust::ty_to_string(t));
self.in_band_ty_params.push(hir::GenericParam {
in_band_ty_params.push(hir::GenericParam {
id: def_node_id,
name: ParamName::Plain(name),
span,
@@ -1292,7 +1292,7 @@ impl<'a> LoweringContext<'a> {
exist_ty_id: NodeId,
parent_index: DefIndex,
bounds: &hir::GenericBounds,
) -> (hir::PathParameters, HirVec<hir::GenericParam>) {
) -> (HirVec<hir::GenericParam>, HirVec<hir::Lifetime>) {
// This visitor walks over impl trait bounds and creates defs for all lifetimes which
// appear in the bounds, excluding lifetimes that are created within the bounds.
// e.g. 'a, 'b, but not 'c in `impl for<'c> SomeTrait<'a, 'b, 'c>`
@@ -1408,23 +1408,23 @@ impl<'a> LoweringContext<'a> {
lifetime.span,
);

let name = match name {
let (in_band, name) = match name {
hir::LifetimeName::Underscore => {
hir::ParamName::Plain(keywords::UnderscoreLifetime.name())
(true, hir::ParamName::Plain(keywords::UnderscoreLifetime.name()))
}
hir::LifetimeName::Param(param_name) => param_name,
hir::LifetimeName::Param(param_name) => (false, param_name),
_ => bug!("expected LifetimeName::Param or ParamName::Plain"),
};

self.output_lifetime_params.push(hir::GenericParam {
self.output_params.push(hir::GenericParam {
id: def_node_id,
name,
span: lifetime.span,
pure_wrt_drop: false,
attrs: hir_vec![],
bounds: hir_vec![],
kind: hir::GenericParamKind::Lifetime {
in_band: false,
in_band,
}
});
}
@@ -1447,13 +1447,8 @@ impl<'a> LoweringContext<'a> {
}

(
hir::PathParameters {
lifetimes: lifetime_collector.output_lifetimes.into(),
types: HirVec::new(),
bindings: HirVec::new(),
parenthesized: false,
},
lifetime_collector.output_params.into(),
lifetime_collector.output_lifetimes.into(),
)
}

@@ -1844,7 +1839,7 @@ impl<'a> LoweringContext<'a> {
fn lower_fn_decl(
&mut self,
decl: &FnDecl,
mut in_band_ty_params: Option<(DefId, &mut Vec<hir::TyParam>, &hir::Generics)>,
mut in_band_ty_params: Option<(DefId, &mut Vec<hir::GenericParam>, &hir::Generics)>,
impl_trait_return_allow: bool,
) -> P<hir::FnDecl> {
// NOTE: The two last parameters here have to do with impl Trait. If fn_def_id is Some,
@@ -1943,15 +1938,19 @@ impl<'a> LoweringContext<'a> {
add_bounds: &NodeMap<Vec<GenericBound>>,
mut itctx: ImplTraitContext,
) -> hir::HirVec<hir::GenericParam> {
params.iter().map(|param| self.lower_generic_param(param, add_bounds, itctx)).collect()
params.iter().map(|param| self.lower_generic_param(
param,
add_bounds,
itctx.reborrow(),
)).collect()
}

fn lower_generic_param(&mut self,
param: &GenericParam,
add_bounds: &NodeMap<Vec<GenericBound>>,
itctx: ImplTraitContext)
mut itctx: ImplTraitContext)
-> hir::GenericParam {
let mut bounds = self.lower_param_bounds(&param.bounds, itctx);
let mut bounds = self.lower_param_bounds(&param.bounds, itctx.reborrow());
match param.kind {
GenericParamKind::Lifetime => {
let was_collecting_in_band = self.is_collecting_in_band_lifetimes;
@@ -2809,8 +2808,8 @@ impl<'a> LoweringContext<'a> {
path_span: Span,
path_segment: &'v PathSegment,
) {
if let Some(ref p) = path_segment.parameters {
if let PathParameters::Parenthesized(..) = **p {
if let Some(ref p) = path_segment.args {
if let GenericArgs::Parenthesized(..) = **p {
return;
}
}
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
@@ -383,7 +383,7 @@ impl PathSegment {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum GenericArg {
Lifetime(Lifetime),
Type(P<Ty>),
Type(Ty),
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]