Skip to content

Commit

Permalink
Replace "existential" by "opaque"
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Aug 2, 2019
1 parent fc48541 commit c28ce3e
Show file tree
Hide file tree
Showing 175 changed files with 1,018 additions and 418 deletions.
6 changes: 3 additions & 3 deletions src/librustc/hir/check_attr.rs
Expand Up @@ -27,7 +27,7 @@ pub(crate) enum Target {
ForeignMod,
GlobalAsm,
Ty,
Existential,
OpaqueTy,
Enum,
Struct,
Union,
Expand All @@ -51,7 +51,7 @@ impl Display for Target {
Target::ForeignMod => "foreign module",
Target::GlobalAsm => "global asm",
Target::Ty => "type alias",
Target::Existential => "existential type",
Target::OpaqueTy => "opaque type",
Target::Enum => "enum",
Target::Struct => "struct",
Target::Union => "union",
Expand All @@ -76,7 +76,7 @@ impl Target {
hir::ItemKind::ForeignMod(..) => Target::ForeignMod,
hir::ItemKind::GlobalAsm(..) => Target::GlobalAsm,
hir::ItemKind::Ty(..) => Target::Ty,
hir::ItemKind::Existential(..) => Target::Existential,
hir::ItemKind::OpaqueTy(..) => Target::OpaqueTy,
hir::ItemKind::Enum(..) => Target::Enum,
hir::ItemKind::Struct(..) => Target::Struct,
hir::ItemKind::Union(..) => Target::Union,
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/hir/def.rs
Expand Up @@ -55,15 +55,15 @@ pub enum DefKind {
/// Refers to the variant itself, `DefKind::Ctor` refers to its constructor if it exists.
Variant,
Trait,
/// `existential type Foo: Bar;`
Existential,
/// `type Foo = impl Bar;`
OpaqueTy,
/// `type Foo = Bar;`
TyAlias,
ForeignTy,
TraitAlias,
AssocTy,
/// `existential type Foo: Bar;`
AssocExistential,
/// `type Foo = impl Bar;`
AssocOpaqueTy,
TyParam,

// Value namespace
Expand Down Expand Up @@ -96,11 +96,11 @@ impl DefKind {
DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct",
DefKind::Ctor(CtorOf::Struct, CtorKind::Fictive) =>
bug!("impossible struct constructor"),
DefKind::Existential => "existential type",
DefKind::OpaqueTy => "opaque type",
DefKind::TyAlias => "type alias",
DefKind::TraitAlias => "trait alias",
DefKind::AssocTy => "associated type",
DefKind::AssocExistential => "associated existential type",
DefKind::AssocOpaqueTy => "associated opaque type",
DefKind::Union => "union",
DefKind::Trait => "trait",
DefKind::ForeignTy => "foreign type",
Expand All @@ -118,9 +118,9 @@ impl DefKind {
match *self {
DefKind::AssocTy
| DefKind::AssocConst
| DefKind::AssocExistential
| DefKind::AssocOpaqueTy
| DefKind::Enum
| DefKind::Existential => "an",
| DefKind::OpaqueTy => "an",
DefKind::Macro(macro_kind) => macro_kind.article(),
_ => "a",
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/intravisit.rs
Expand Up @@ -505,7 +505,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
visitor.visit_ty(ty);
visitor.visit_generics(generics)
}
ItemKind::Existential(ExistTy {
ItemKind::OpaqueTy(ExistTy {
ref generics,
ref bounds,
..
Expand Down Expand Up @@ -930,7 +930,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
visitor.visit_id(impl_item.hir_id);
visitor.visit_ty(ty);
}
ImplItemKind::Existential(ref bounds) => {
ImplItemKind::OpaqueTy(ref bounds) => {
visitor.visit_id(impl_item.hir_id);
walk_list!(visitor, visit_param_bound, bounds);
}
Expand Down
80 changes: 40 additions & 40 deletions src/librustc/hir/lowering.rs
Expand Up @@ -189,14 +189,14 @@ enum ImplTraitContext<'a> {
/// Newly generated parameters should be inserted into the given `Vec`.
Universal(&'a mut Vec<hir::GenericParam>),

/// Treat `impl Trait` as shorthand for a new existential parameter.
/// Treat `impl Trait` as shorthand for a new opaque type.
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
/// equivalent to a fresh existential parameter like `existential type T; fn foo() -> T`.
/// equivalent to a new opaque type like `type T = impl Debug; fn foo() -> T`.
///
/// We optionally store a `DefId` for the parent item here so we can look up necessary
/// information later. It is `None` when no information about the context should be stored
/// (e.g., for consts and statics).
Existential(Option<DefId> /* fn def-ID */),
OpaqueTy(Option<DefId> /* fn def-ID */),

/// `impl Trait` is not accepted in this position.
Disallowed(ImplTraitPosition),
Expand All @@ -222,7 +222,7 @@ impl<'a> ImplTraitContext<'a> {
use self::ImplTraitContext::*;
match self {
Universal(params) => Universal(params),
Existential(fn_def_id) => Existential(*fn_def_id),
OpaqueTy(fn_def_id) => OpaqueTy(*fn_def_id),
Disallowed(pos) => Disallowed(*pos),
}
}
Expand Down Expand Up @@ -487,7 +487,7 @@ impl<'a> LoweringContext<'a> {
| ItemKind::Union(_, ref generics)
| ItemKind::Enum(_, ref generics)
| ItemKind::Ty(_, ref generics)
| ItemKind::Existential(_, ref generics)
| ItemKind::OpaqueTy(_, ref generics)
| ItemKind::Trait(_, _, ref generics, ..) => {
let def_id = self.lctx.resolver.definitions().local_def_id(item.id);
let count = generics
Expand Down Expand Up @@ -1422,7 +1422,7 @@ impl<'a> LoweringContext<'a> {
// so desugar to
//
// fn foo() -> impl Iterator<Item = impl Debug>
ImplTraitContext::Existential(_) => (true, itctx),
ImplTraitContext::OpaqueTy(_) => (true, itctx),

// We are in the argument position, but within a dyn type:
//
Expand All @@ -1436,11 +1436,11 @@ impl<'a> LoweringContext<'a> {
// In `type Foo = dyn Iterator<Item: Debug>` we desugar to
// `type Foo = dyn Iterator<Item = impl Debug>` but we have to override the
// "impl trait context" to permit `impl Debug` in this position (it desugars
// then to an existential type).
// then to an opaque type).
//
// FIXME: this is only needed until `impl Trait` is allowed in type aliases.
ImplTraitContext::Disallowed(_) if self.is_in_dyn_type =>
(true, ImplTraitContext::Existential(None)),
(true, ImplTraitContext::OpaqueTy(None)),

// We are in the argument position, but not within a dyn type:
//
Expand Down Expand Up @@ -1634,8 +1634,8 @@ impl<'a> LoweringContext<'a> {
TyKind::ImplTrait(def_node_id, ref bounds) => {
let span = t.span;
match itctx {
ImplTraitContext::Existential(fn_def_id) => {
self.lower_existential_impl_trait(
ImplTraitContext::OpaqueTy(fn_def_id) => {
self.lower_opaque_impl_trait(
span, fn_def_id, def_node_id,
|this| this.lower_param_bounds(bounds, itctx),
)
Expand Down Expand Up @@ -1717,7 +1717,7 @@ impl<'a> LoweringContext<'a> {
}
}

fn lower_existential_impl_trait(
fn lower_opaque_impl_trait(
&mut self,
span: Span,
fn_def_id: Option<DefId>,
Expand All @@ -1730,7 +1730,7 @@ impl<'a> LoweringContext<'a> {
// Not tracking it makes lints in rustc and clippy very fragile, as
// frequently opened issues show.
let exist_ty_span = self.mark_span_with_reason(
DesugaringKind::ExistentialType,
DesugaringKind::OpaqueTy,
span,
None,
);
Expand Down Expand Up @@ -1763,11 +1763,11 @@ impl<'a> LoweringContext<'a> {
},
bounds: hir_bounds,
impl_trait_fn: fn_def_id,
origin: hir::ExistTyOrigin::ReturnImplTrait,
origin: hir::OpaqueTyOrigin::ReturnImplTrait,
};

trace!("exist ty from impl trait def-index: {:#?}", exist_ty_def_index);
let exist_ty_id = lctx.generate_existential_type(
let exist_ty_id = lctx.generate_opaque_type(
exist_ty_node_id,
exist_ty_item,
span,
Expand All @@ -1779,19 +1779,19 @@ impl<'a> LoweringContext<'a> {
})
}

/// Registers a new existential type with the proper `NodeId`s and
/// returns the lowered node-ID for the existential type.
fn generate_existential_type(
/// Registers a new opaque type with the proper `NodeId`s and
/// returns the lowered node-ID for the opaque type.
fn generate_opaque_type(
&mut self,
exist_ty_node_id: NodeId,
exist_ty_item: hir::ExistTy,
span: Span,
exist_ty_span: Span,
) -> hir::HirId {
let exist_ty_item_kind = hir::ItemKind::Existential(exist_ty_item);
let exist_ty_item_kind = hir::ItemKind::OpaqueTy(exist_ty_item);
let exist_ty_id = self.lower_node_id(exist_ty_node_id);
// Generate an `existential type Foo: Trait;` declaration.
trace!("registering existential type with id {:#?}", exist_ty_id);
// Generate an `type Foo = impl Trait;` declaration.
trace!("registering opaque type with id {:#?}", exist_ty_id);
let exist_ty_item = hir::Item {
hir_id: exist_ty_id,
ident: Ident::invalid(),
Expand All @@ -1802,7 +1802,7 @@ impl<'a> LoweringContext<'a> {
};

// Insert the item into the global item list. This usually happens
// automatically for all AST items. But this existential type item
// automatically for all AST items. But this opaque type item
// does not actually exist in the AST.
self.insert_item(exist_ty_item);
exist_ty_id
Expand Down Expand Up @@ -2439,7 +2439,7 @@ impl<'a> LoweringContext<'a> {
.as_ref()
.map(|t| self.lower_ty(t,
if self.sess.features_untracked().impl_trait_in_bindings {
ImplTraitContext::Existential(Some(parent_def_id))
ImplTraitContext::OpaqueTy(Some(parent_def_id))
} else {
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
}
Expand Down Expand Up @@ -2500,7 +2500,7 @@ impl<'a> LoweringContext<'a> {
let lt_mode = if make_ret_async.is_some() {
// In `async fn`, argument-position elided lifetimes
// must be transformed into fresh generic parameters so that
// they can be applied to the existential return type.
// they can be applied to the opaque `impl Trait` return type.
AnonymousLifetimeMode::CreateParameter
} else {
self.anonymous_lifetime_mode
Expand Down Expand Up @@ -2539,7 +2539,7 @@ impl<'a> LoweringContext<'a> {
FunctionRetTy::Ty(ref ty) => match in_band_ty_params {
Some((def_id, _)) if impl_trait_return_allow => {
hir::Return(self.lower_ty(ty,
ImplTraitContext::Existential(Some(def_id))
ImplTraitContext::OpaqueTy(Some(def_id))
))
}
_ => {
Expand Down Expand Up @@ -2585,12 +2585,12 @@ impl<'a> LoweringContext<'a> {
// Transforms `-> T` for `async fn` into `-> ExistTy { .. }`
// combined with the following definition of `ExistTy`:
//
// existential type ExistTy<generics_from_parent_fn>: Future<Output = T>;
// type ExistTy<generics_from_parent_fn> = impl Future<Output = T>;
//
// `inputs`: lowered types of arguments to the function (used to collect lifetimes)
// `output`: unlowered output type (`T` in `-> T`)
// `fn_def_id`: `DefId` of the parent function (used to create child impl trait definition)
// `exist_ty_node_id`: `NodeId` of the existential type that should be created
// `exist_ty_node_id`: `NodeId` of the opaque `impl Trait` type that should be created
// `elided_lt_replacement`: replacement for elided lifetimes in the return type
fn lower_async_fn_ret_ty(
&mut self,
Expand Down Expand Up @@ -2626,7 +2626,7 @@ impl<'a> LoweringContext<'a> {
);

// Calculate all the lifetimes that should be captured
// by the existential type. This should include all in-scope
// by the opaque type. This should include all in-scope
// lifetime parameters, including those defined in-band.
//
// Note: this must be done after lowering the output type,
Expand Down Expand Up @@ -2657,11 +2657,11 @@ impl<'a> LoweringContext<'a> {
},
bounds: hir_vec![future_bound],
impl_trait_fn: Some(fn_def_id),
origin: hir::ExistTyOrigin::AsyncFn,
origin: hir::OpaqueTyOrigin::AsyncFn,
};

trace!("exist ty from async fn def index: {:#?}", exist_ty_def_index);
let exist_ty_id = this.generate_existential_type(
let exist_ty_id = this.generate_opaque_type(
exist_ty_node_id,
exist_ty_item,
span,
Expand Down Expand Up @@ -2702,7 +2702,7 @@ impl<'a> LoweringContext<'a> {
// Compute the `T` in `Future<Output = T>` from the return type.
let output_ty = match output {
FunctionRetTy::Ty(ty) => {
self.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id)))
self.lower_ty(ty, ImplTraitContext::OpaqueTy(Some(fn_def_id)))
}
FunctionRetTy::Default(ret_ty_span) => {
P(hir::Ty {
Expand Down Expand Up @@ -2905,7 +2905,7 @@ impl<'a> LoweringContext<'a> {

let kind = hir::GenericParamKind::Type {
default: default.as_ref().map(|x| {
self.lower_ty(x, ImplTraitContext::Existential(None))
self.lower_ty(x, ImplTraitContext::OpaqueTy(None))
}),
synthetic: param.attrs.iter()
.filter(|attr| attr.check_name(sym::rustc_synthetic))
Expand Down Expand Up @@ -3384,7 +3384,7 @@ impl<'a> LoweringContext<'a> {
self.lower_ty(
t,
if self.sess.features_untracked().impl_trait_in_bindings {
ImplTraitContext::Existential(None)
ImplTraitContext::OpaqueTy(None)
} else {
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
}
Expand All @@ -3398,7 +3398,7 @@ impl<'a> LoweringContext<'a> {
self.lower_ty(
t,
if self.sess.features_untracked().impl_trait_in_bindings {
ImplTraitContext::Existential(None)
ImplTraitContext::OpaqueTy(None)
} else {
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
}
Expand Down Expand Up @@ -3444,14 +3444,14 @@ impl<'a> LoweringContext<'a> {
self.lower_ty(t, ImplTraitContext::disallowed()),
self.lower_generics(generics, ImplTraitContext::disallowed()),
),
ItemKind::Existential(ref b, ref generics) => hir::ItemKind::Existential(
ItemKind::OpaqueTy(ref b, ref generics) => hir::ItemKind::OpaqueTy(
hir::ExistTy {
generics: self.lower_generics(generics,
ImplTraitContext::Existential(None)),
ImplTraitContext::OpaqueTy(None)),
bounds: self.lower_param_bounds(b,
ImplTraitContext::Existential(None)),
ImplTraitContext::OpaqueTy(None)),
impl_trait_fn: None,
origin: hir::ExistTyOrigin::ExistentialType,
origin: hir::OpaqueTyOrigin::TraitAliasImplTrait,
},
),
ItemKind::Enum(ref enum_definition, ref generics) => {
Expand Down Expand Up @@ -3918,9 +3918,9 @@ impl<'a> LoweringContext<'a> {
self.lower_generics(&i.generics, ImplTraitContext::disallowed()),
hir::ImplItemKind::Type(self.lower_ty(ty, ImplTraitContext::disallowed())),
),
ImplItemKind::Existential(ref bounds) => (
ImplItemKind::OpaqueTy(ref bounds) => (
self.lower_generics(&i.generics, ImplTraitContext::disallowed()),
hir::ImplItemKind::Existential(
hir::ImplItemKind::OpaqueTy(
self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
),
),
Expand Down Expand Up @@ -3951,7 +3951,7 @@ impl<'a> LoweringContext<'a> {
kind: match i.node {
ImplItemKind::Const(..) => hir::AssocItemKind::Const,
ImplItemKind::Type(..) => hir::AssocItemKind::Type,
ImplItemKind::Existential(..) => hir::AssocItemKind::Existential,
ImplItemKind::OpaqueTy(..) => hir::AssocItemKind::OpaqueTy,
ImplItemKind::Method(ref sig, _) => hir::AssocItemKind::Method {
has_self: sig.decl.has_self(),
},
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/def_collector.rs
Expand Up @@ -92,7 +92,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
}
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
ItemKind::Existential(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
ItemKind::OpaqueTy(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
ItemKind::Ty(..) => DefPathData::TypeNs(i.ident.as_interned_str()),
ItemKind::Fn(
ref decl,
Expand Down Expand Up @@ -223,7 +223,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
DefPathData::ValueNs(ii.ident.as_interned_str()),
ImplItemKind::Type(..) |
ImplItemKind::Existential(..) => {
ImplItemKind::OpaqueTy(..) => {
DefPathData::TypeNs(ii.ident.as_interned_str())
},
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
Expand Down

0 comments on commit c28ce3e

Please sign in to comment.