Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rust: Refactor type inference to use newTypeItem 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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
paldepind wants to merge2 commits intogithub:main
base:main
Choose a base branch
Loading
frompaldepind:rust/type-inference-use-type-item

Conversation

@paldepind
Copy link
Contributor

@paldepindpaldepind commentedDec 18, 2025
edited
Loading

Just a quick go at getting some mileage out of the newTypeItem class in the type inference implementation.

@github-actionsgithub-actionsbot added the RustPull requests that update Rust code labelDec 18, 2025
@paldepindpaldepind added the no-change-note-requiredThis PR does not need a change note labelDec 18, 2025
@paldepindpaldepindforce-pushed therust/type-inference-use-type-item branch frombfc43d5 tofce7247CompareDecember 18, 2025 14:52
@paldepindpaldepindforce-pushed therust/type-inference-use-type-item branch fromfce7247 todde845eCompareDecember 18, 2025 15:08
@paldepindpaldepind marked this pull request as ready for reviewDecember 18, 2025 16:14
@paldepindpaldepind requested a review froma team as acode ownerDecember 18, 2025 16:14
CopilotAI review requested due to automatic review settingsDecember 18, 2025 16:14
Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull request overview

This PR refactors the type inference implementation in Rust QL to use a new unifiedTypeItem class, consolidating the handling of structs, enums, and unions under a common abstraction.

  • Introduces a newDataType class that replaces separateTStruct,TEnum, andTUnion type constructors with a singleTDataType(TypeItem) constructor
  • Replaces specific getter methods (getStruct(),getEnum(),getUnion()) with a unifiedgetTypeItem() method across the codebase
  • RefactorsTupleLikeConstructor andDeclaration classes to use the new abstraction, reducing code duplication

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
FileDescription
rust/ql/lib/codeql/rust/internal/Type.qllIntroducesDataType class and makesStructType,EnumType, andUnionType subclasses; consolidates type constructors fromTStruct,TEnum,TUnion toTDataType
rust/ql/lib/codeql/rust/internal/TypeInference.qllUpdates all type references to useTDataType constructor; refactorsTupleLikeConstructor andDeclaration classes to usegetTypeItem() method and eliminate duplicate logic
rust/ql/lib/codeql/rust/internal/TypeMention.qllSimplifiesresolveRootType() by consolidating three separate type resolution cases into a singleTDataType case
rust/ql/lib/codeql/rust/security/Barriers.qllUpdates barrier classes to usegetTypeItem() instead ofgetStruct() orgetEnum()
rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qllUpdates algorithm name extraction to usegetTypeItem() instead ofgetStruct()

💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.

Copy link
Contributor

@hvitvedhvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice refactor; some minor comments. I have also started a DCA run.

paldepind reacted with thumbs up emoji
EnumType(){this=TEnum(enum)}
/** A struct type. */
classStructTypeextendsDataType{
StructType(){super.getTypeItem()instanceofStruct}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
StructType(){super.getTypeItem()instanceofStruct}
privateStructstruct;
StructType(){struct=super.getTypeItem()}

/** Gets the enum that this enum type represents. */
EnumgetEnum(){result=enum}
/** Gets the struct that this struct type represents. */
overrideStructgetTypeItem(){result=super.getTypeItem()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
overrideStructgetTypeItem(){result=super.getTypeItem()}
overrideStructgetTypeItem(){result=struct}

}
/** An enum type. */
classEnumTypeextendsDataType{
EnumType(){super.getTypeItem()instanceofEnum}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
EnumType(){super.getTypeItem()instanceofEnum}
privateEnumenum;
EnumType(){enum=super.getTypeItem()}

result=enum.getGenericParamList().getTypeParam(i).getDefaultType()
}
/** Gets the enum that this enum type represents. */
overrideEnumgetTypeItem(){result=super.getTypeItem()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
overrideEnumgetTypeItem(){result=super.getTypeItem()}
overrideEnumgetTypeItem(){result=enum}

overridestringtoString(){result=enum.getName().getText()}
/** A union type. */
classUnionTypeextendsDataType{
UnionType(){super.getTypeItem()instanceofUnion}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
UnionType(){super.getTypeItem()instanceofUnion}
privateUnionunion;
UnionType(){union=super.getTypeItem()}


overrideLocationgetLocation(){result=enum.getLocation()}
/** Gets the union that this union type represents. */
overrideUniongetTypeItem(){result=super.getTypeItem()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
overrideUniongetTypeItem(){result=super.getTypeItem()}
overrideUniongetTypeItem(){result=union}

result=this.getTypeParameter(_)and
path= TypePath::singleton(result)
or
// type of the struct itself
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Needs to be updated

paldepind reacted with thumbs up emoji
}
overrideTypeItemgetTypeItem(){result=this}

overrideTupleFieldgetTupleField(inti){result=this.(Struct).getTupleField(i)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
overrideTupleFieldgetTupleField(inti){result=this.(Struct).getTupleField(i)}
overrideTupleFieldgetTupleField(inti){result=Struct.super.getTupleField(i)}

path= TypePath::singleton(result)
)
}
overrideTupleFieldgetTupleField(inti){result=this.(Variant).getTupleField(i)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
overrideTupleFieldgetTupleField(inti){result=this.(Variant).getTupleField(i)}
overrideTupleFieldgetTupleField(inti){result=Variant.super.getTupleField(i)}

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@hvitvedhvitvedhvitved approved these changes

Assignees

No one assigned

Labels

no-change-note-requiredThis PR does not need a change noteRustPull requests that update Rust code

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@paldepind@hvitved

[8]ページ先頭

©2009-2025 Movatter.jp