-
Notifications
You must be signed in to change notification settings - Fork 2k
Rust: Avoid unnecessary constraint satisfaction #21172
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 2 commits
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||
| private import rust | ||||||
| private import codeql.rust.elements.internal.generated.Raw | ||||||
| private import codeql.rust.elements.internal.generated.Synth | ||||||
| private import Type | ||||||
|
|
||||||
| /** | ||||||
| * A type abstraction. I.e., a place in the program where type variables are | ||||||
| * introduced. | ||||||
| * | ||||||
| * Example: | ||||||
| * ```rust | ||||||
| * impl<A, B> Foo<A, B> { } | ||||||
| * // ^^^^^^ a type abstraction | ||||||
| * ``` | ||||||
| */ | ||||||
| abstract class TypeAbstraction extends AstNode { | ||||||
| abstract TypeParameter getATypeParameter(); | ||||||
| } | ||||||
|
|
||||||
| final class ImplTypeAbstraction extends TypeAbstraction, Impl { | ||||||
| override TypeParamTypeParameter getATypeParameter() { | ||||||
| result.getTypeParam() = this.getGenericParamList().getATypeParam() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private predicate idDynTraitTypeRepr(Raw::DynTraitTypeRepr x, Raw::DynTraitTypeRepr y) { x = y } | ||||||
|
|
||||||
| private predicate idOfDynTraitTypeRepr(Raw::DynTraitTypeRepr x, int y) = | ||||||
| equivalenceRelation(idDynTraitTypeRepr/2)(x, y) | ||||||
|
|
||||||
| private int idOfDynTraitTypeRepr(DynTraitTypeRepr node) { | ||||||
| idOfDynTraitTypeRepr(Synth::convertAstNodeToRaw(node), result) | ||||||
| } | ||||||
|
|
||||||
| /** Holds if `dt` is the (arbitrarily chosen) canonical dyn trait type abstraction for `trait`. */ | ||||||
| private predicate canonicalDynTraitTypeAbstraction(DynTraitTypeRepr dt, Trait trait) { | ||||||
| dt = min(DynTraitTypeRepr d | d.getTrait() = trait | d order by idOfDynTraitTypeRepr(d)) | ||||||
| } | ||||||
|
|
||||||
| final class DynTypeAbstraction extends TypeAbstraction, DynTraitTypeRepr { | ||||||
| DynTypeAbstraction() { | ||||||
| // We pick a "canonical" `dyn Trait` in order to avoid including multiple | ||||||
| // entries in `conditionSatisfiesConstraint` with the exact same effect when | ||||||
| // `dyn Trait` occurs multiple times for the same trait. | ||||||
| canonicalDynTraitTypeAbstraction(this, this.getTrait()) | ||||||
| } | ||||||
|
|
||||||
| override TypeParameter getATypeParameter() { | ||||||
| result = any(DynTraitTypeParameter tp | tp.getTrait() = this.getTrait()).getTraitTypeParameter() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| final class TraitTypeAbstraction extends TypeAbstraction, Trait { | ||||||
| override TypeParameter getATypeParameter() { | ||||||
| result.(TypeParamTypeParameter).getTypeParam() = this.getGenericParamList().getATypeParam() | ||||||
| or | ||||||
| result.(AssociatedTypeTypeParameter).getTrait() = this | ||||||
| or | ||||||
| result.(SelfTypeParameter).getTrait() = this | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| final class TypeBoundTypeAbstraction extends TypeAbstraction, TypeBound { | ||||||
| override TypeParameter getATypeParameter() { none() } | ||||||
| } | ||||||
|
|
||||||
| final class SelfTypeBoundTypeAbstraction extends TypeAbstraction, Name { | ||||||
| SelfTypeBoundTypeAbstraction() { any(TraitTypeAbstraction trait).getName() = this } | ||||||
|
|
||||||
| override TypeParameter getATypeParameter() { none() } | ||||||
| } | ||||||
|
|
||||||
| final class ImplTraitTypeReprAbstraction extends TypeAbstraction, ImplTraitTypeRepr { | ||||||
| override TypeParamTypeParameter getATypeParameter() { | ||||||
| exists(TImplTraitTypeParameter(this, result.getTypeParam())) | ||||||
|
||||||
| exists(TImplTraitTypeParameter(this, result.getTypeParam())) | |
| exists(TImplTraitTypeParameter(this, result.(TypeParamTypeParameter).getTypeParam())) |
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.
Suggested change makes zero difference. This was mostly to avoid using implTraitTypeParam which is private inside Type.qll.
Uh oh!
There was an error while loading. Please reload this page.