-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Refactor type inference to use new TypeItem class
#21067
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,10 +32,8 @@ private predicate dynTraitTypeParameter(Trait trait, AstNode n) { | |||||||
|
|
||||||||
| cached | ||||||||
| newtype TType = | ||||||||
| TStruct(Struct s) { Stages::TypeInferenceStage::ref() } or | ||||||||
| TEnum(Enum e) or | ||||||||
| TDataType(TypeItem ti) { Stages::TypeInferenceStage::ref() } or | ||||||||
| TTrait(Trait t) or | ||||||||
| TUnion(Union u) or | ||||||||
| TImplTraitType(ImplTraitTypeRepr impl) or | ||||||||
| TDynTraitType(Trait t) { t = any(DynTraitTypeRepr dt).getTrait() } or | ||||||||
| TNeverType() or | ||||||||
|
|
@@ -92,7 +90,7 @@ abstract class Type extends TType { | |||||||
| class TupleType extends StructType { | ||||||||
| private int arity; | ||||||||
|
|
||||||||
| TupleType() { arity = this.getStruct().(Builtins::TupleType).getArity() } | ||||||||
| TupleType() { arity = this.getTypeItem().(Builtins::TupleType).getArity() } | ||||||||
|
|
||||||||
| /** Gets the arity of this tuple type. */ | ||||||||
| int getArity() { result = arity } | ||||||||
|
|
@@ -112,48 +110,49 @@ class UnitType extends TupleType { | |||||||
| override string toString() { result = "()" } | ||||||||
| } | ||||||||
|
|
||||||||
| /** A struct type. */ | ||||||||
| class StructType extends Type, TStruct { | ||||||||
| private Struct struct; | ||||||||
| class DataType extends Type, TDataType { | ||||||||
| private TypeItem typeItem; | ||||||||
|
|
||||||||
| StructType() { this = TStruct(struct) } | ||||||||
| DataType() { this = TDataType(typeItem) } | ||||||||
|
|
||||||||
| /** Gets the struct that this struct type represents. */ | ||||||||
| Struct getStruct() { result = struct } | ||||||||
| /** Gets the type item that this data type represents. */ | ||||||||
| TypeItem getTypeItem() { result = typeItem } | ||||||||
|
|
||||||||
| override TypeParameter getPositionalTypeParameter(int i) { | ||||||||
| result = TTypeParamTypeParameter(struct.getGenericParamList().getTypeParam(i)) | ||||||||
| result = TTypeParamTypeParameter(typeItem.getGenericParamList().getTypeParam(i)) | ||||||||
| } | ||||||||
|
|
||||||||
| override TypeMention getTypeParameterDefault(int i) { | ||||||||
| result = struct.getGenericParamList().getTypeParam(i).getDefaultType() | ||||||||
| result = typeItem.getGenericParamList().getTypeParam(i).getDefaultType() | ||||||||
| } | ||||||||
|
|
||||||||
| override string toString() { result = struct.getName().getText() } | ||||||||
| override string toString() { result = typeItem.getName().getText() } | ||||||||
|
|
||||||||
| override Location getLocation() { result = struct.getLocation() } | ||||||||
| override Location getLocation() { result = typeItem.getLocation() } | ||||||||
| } | ||||||||
|
|
||||||||
| /** An enum type. */ | ||||||||
| class EnumType extends Type, TEnum { | ||||||||
| private Enum enum; | ||||||||
|
|
||||||||
| EnumType() { this = TEnum(enum) } | ||||||||
| /** A struct type. */ | ||||||||
| class StructType extends DataType { | ||||||||
| StructType() { super.getTypeItem() instanceof Struct } | ||||||||
|
|
||||||||
| /** Gets the enum that this enum type represents. */ | ||||||||
| Enum getEnum() { result = enum } | ||||||||
| /** Gets the struct that this struct type represents. */ | ||||||||
| override Struct getTypeItem() { result = super.getTypeItem() } | ||||||||
|
||||||||
| override Struct getTypeItem() { result = super.getTypeItem() } | |
| override Struct getTypeItem() { result = struct } |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| EnumType() { super.getTypeItem() instanceof Enum } | |
| private Enum enum; | |
| EnumType() { enum = super.getTypeItem() } |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| override Enum getTypeItem() { result = super.getTypeItem() } | |
| override Enum getTypeItem() { result = enum } |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| UnionType() { super.getTypeItem() instanceof Union } | |
| private Union union; | |
| UnionType() { union = super.getTypeItem() } |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| override Union getTypeItem() { result = super.getTypeItem() } | |
| override Union getTypeItem() { result = union } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.