diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2017-09-29 16:16:19 -0700 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2017-10-02 11:33:26 -0700 |
commit | 25ce0f658775bc866179c291e2f0c85f797a5b6b (patch) | |
tree | 94202cfcfb47ef9e8fa8341ac0bc16506e55187b /src | |
parent | bd324232ef905a2186cf88510a68c27d55859a30 (diff) |
Make TemplateInstantiation's definition into a TypeId
The definition of a template is always a type, so it should be a TypeId rather
than an ItemId. Template arguments, on the other hand are not guaranteed to be
types. They can be constant values, for example.
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/analysis/derive_copy.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/derive_debug.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/derive_default.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/derive_hash.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/derive_partial_eq_or_partial_ord.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/has_destructor.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/has_float.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/has_type_param_in_array.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/has_vtable.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/template_params.rs | 10 | ||||
-rw-r--r-- | src/ir/context.rs | 4 | ||||
-rw-r--r-- | src/ir/template.rs | 12 | ||||
-rw-r--r-- | src/ir/ty.rs | 4 |
13 files changed, 24 insertions, 24 deletions
diff --git a/src/ir/analysis/derive_copy.rs b/src/ir/analysis/derive_copy.rs index 1a97f3c2..319f67cd 100644 --- a/src/ir/analysis/derive_copy.rs +++ b/src/ir/analysis/derive_copy.rs @@ -307,7 +307,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> { "The early ty.is_opaque check should have handled this case" ); let def_cannot_derive = self.is_not_copy( - template.template_definition(), + template.template_definition().into(), ); if def_cannot_derive { trace!( diff --git a/src/ir/analysis/derive_debug.rs b/src/ir/analysis/derive_debug.rs index 8a83613b..0ca94cd1 100644 --- a/src/ir/analysis/derive_debug.rs +++ b/src/ir/analysis/derive_debug.rs @@ -325,7 +325,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> { "The early ty.is_opaque check should have handled this case" ); let def_cannot_derive = self.is_not_debug( - template.template_definition(), + template.template_definition().into(), ); if def_cannot_derive { trace!( diff --git a/src/ir/analysis/derive_default.rs b/src/ir/analysis/derive_default.rs index 083723c7..aff99681 100644 --- a/src/ir/analysis/derive_default.rs +++ b/src/ir/analysis/derive_default.rs @@ -353,7 +353,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> { "The early ty.is_opaque check should have handled this case" ); let def_cannot_derive = - self.is_not_default(template.template_definition()); + self.is_not_default(template.template_definition().into()); if def_cannot_derive { trace!( " template definition cannot derive Default, so \ diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs index e2aae2f8..6644ad49 100644 --- a/src/ir/analysis/derive_hash.rs +++ b/src/ir/analysis/derive_hash.rs @@ -326,7 +326,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> { "The early ty.is_opaque check should have handled this case" ); let def_cannot_derive = self.cannot_derive_hash.contains( - &template.template_definition(), + &template.template_definition().into(), ); if def_cannot_derive { trace!( diff --git a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs index 9211bb09..14e6cd9b 100644 --- a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs +++ b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs @@ -348,7 +348,7 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> { "The early ty.is_opaque check should have handled this case" ); let def_cannot_derive = self.cannot_derive_partialeq_or_partialord.contains( - &template.template_definition(), + &template.template_definition().into(), ); if def_cannot_derive { trace!( diff --git a/src/ir/analysis/has_destructor.rs b/src/ir/analysis/has_destructor.rs index 4058cd88..2d3bb89f 100644 --- a/src/ir/analysis/has_destructor.rs +++ b/src/ir/analysis/has_destructor.rs @@ -140,7 +140,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> { TypeKind::TemplateInstantiation(ref inst) => { let definition_or_arg_destructor = - self.have_destructor.contains(&inst.template_definition()) + self.have_destructor.contains(&inst.template_definition().into()) || inst.template_arguments().iter().any(|arg| { self.have_destructor.contains(arg) diff --git a/src/ir/analysis/has_float.rs b/src/ir/analysis/has_float.rs index 218572dc..0f0fb385 100644 --- a/src/ir/analysis/has_float.rs +++ b/src/ir/analysis/has_float.rs @@ -205,7 +205,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { } let def_has = self.has_float - .contains(&template.template_definition()); + .contains(&template.template_definition().into()); if def_has { trace!(" template definition has float, so \ insantiation also has"); diff --git a/src/ir/analysis/has_type_param_in_array.rs b/src/ir/analysis/has_type_param_in_array.rs index 6a0e6707..09783037 100644 --- a/src/ir/analysis/has_type_param_in_array.rs +++ b/src/ir/analysis/has_type_param_in_array.rs @@ -217,7 +217,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { } let def_has = self.has_type_parameter_in_array.contains( - &template.template_definition(), + &template.template_definition().into(), ); if def_has { trace!( diff --git a/src/ir/analysis/has_vtable.rs b/src/ir/analysis/has_vtable.rs index 53a647af..3d44dd92 100644 --- a/src/ir/analysis/has_vtable.rs +++ b/src/ir/analysis/has_vtable.rs @@ -120,7 +120,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> { } TypeKind::TemplateInstantiation(ref inst) => { - if self.have_vtable.contains(&inst.template_definition()) { + if self.have_vtable.contains(&inst.template_definition().into()) { self.insert(id) } else { ConstrainResult::Same diff --git a/src/ir/analysis/template_params.rs b/src/ir/analysis/template_params.rs index ea4bd7b8..d7f5ab57 100644 --- a/src/ir/analysis/template_params.rs +++ b/src/ir/analysis/template_params.rs @@ -271,14 +271,14 @@ impl<'ctx> UsedTemplateParameters<'ctx> { ) { trace!(" template instantiation"); - let decl = self.ctx.resolve_type(instantiation.template_definition().as_type_id_unchecked()); + let decl = self.ctx.resolve_type(instantiation.template_definition()); let args = instantiation.template_arguments(); let params = decl.self_template_params(self.ctx).unwrap_or(vec![]); - debug_assert!(this_id != instantiation.template_definition()); + debug_assert!(this_id != instantiation.template_definition().into()); let used_by_def = self.used - .get(&instantiation.template_definition()) + .get(&instantiation.template_definition().into()) .expect("Should have a used entry for instantiation's template definition") .as_ref() .expect("And it should be Some because only this_id's set is None, and an \ @@ -411,7 +411,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // generic template parameters are used. ctx.resolve_item(item).as_type().map(|ty| match ty.kind() { &TypeKind::TemplateInstantiation(ref inst) => { - let decl = ctx.resolve_type(inst.template_definition().as_type_id_unchecked()); + let decl = ctx.resolve_type(inst.template_definition()); let args = inst.template_arguments(); // Although template definitions should always have @@ -520,7 +520,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // template definition uses the corresponding template parameter. Some(&TypeKind::TemplateInstantiation(ref inst)) => { if self.whitelisted_items.contains( - &inst.template_definition(), + &inst.template_definition().into(), ) { self.constrain_instantiation( diff --git a/src/ir/context.rs b/src/ir/context.rs index 79f4012e..2fef35ee 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1509,7 +1509,7 @@ impl BindgenContext { let sub_name = Some(template_decl_cursor.spelling()); let sub_inst = TemplateInstantiation::new( - template_decl_id, + template_decl_id.as_type_id_unchecked(), sub_args, ); let sub_kind = @@ -1578,7 +1578,7 @@ impl BindgenContext { args.reverse(); let type_kind = TypeKind::TemplateInstantiation( - TemplateInstantiation::new(template, args), + TemplateInstantiation::new(template.as_type_id_unchecked(), args), ); let name = ty.spelling(); let name = if name.is_empty() { None } else { Some(name) }; diff --git a/src/ir/template.rs b/src/ir/template.rs index c1650abc..bad3df48 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -27,7 +27,7 @@ //! }; //! ``` -use super::context::{BindgenContext, ItemId}; +use super::context::{BindgenContext, ItemId, TypeId}; use super::item::{IsOpaque, Item, ItemAncestors, ItemCanonicalPath}; use super::traversal::{EdgeKind, Trace, Tracer}; use clang; @@ -206,7 +206,7 @@ pub trait AsTemplateParam { #[derive(Clone, Debug)] pub struct TemplateInstantiation { /// The template definition which this is instantiating. - definition: ItemId, + definition: TypeId, /// The concrete template arguments, which will be substituted in the /// definition for the generic template parameters. args: Vec<ItemId>, @@ -215,7 +215,7 @@ pub struct TemplateInstantiation { impl TemplateInstantiation { /// Construct a new template instantiation from the given parts. pub fn new<I>( - template_definition: ItemId, + template_definition: TypeId, template_args: I, ) -> TemplateInstantiation where @@ -228,7 +228,7 @@ impl TemplateInstantiation { } /// Get the template definition for this instantiation. - pub fn template_definition(&self) -> ItemId { + pub fn template_definition(&self) -> TypeId { self.definition } @@ -305,7 +305,7 @@ impl TemplateInstantiation { Item::from_ty_or_ref(definition.cur_type(), definition, None, ctx); Some(TemplateInstantiation::new( - template_definition, + template_definition.as_type_id_unchecked(), template_args, )) } @@ -353,7 +353,7 @@ impl Trace for TemplateInstantiation { where T: Tracer, { - tracer.visit_kind(self.definition, EdgeKind::TemplateDeclaration); + tracer.visit_kind(self.definition.into(), EdgeKind::TemplateDeclaration); for &item in self.template_arguments() { tracer.visit_kind(item, EdgeKind::TemplateArgument); } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 34146658..1bb2cce7 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -336,7 +336,7 @@ impl Type { ctx.resolve_type(inner).safe_canonical_type(ctx) } TypeKind::TemplateInstantiation(ref inst) => { - ctx.resolve_type(inst.template_definition().as_type_id_unchecked()) + ctx.resolve_type(inst.template_definition()) .safe_canonical_type(ctx) } @@ -710,7 +710,7 @@ impl Type { } TypeKind::TemplateInstantiation(ref inst) => { let definition = inst.template_definition(); - ctx.resolve_type(definition.as_type_id_unchecked()).is_unsized(ctx, &definition) + ctx.resolve_type(definition).is_unsized(ctx, &definition.into()) } TypeKind::TypeParam | TypeKind::Int(..) | |