-
Notifications
You must be signed in to change notification settings - Fork 2k
Shared, type inference: Add inference for type parameters with constraints (base type mentions) #19102
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
Merged
Merged
Shared, type inference: Add inference for type parameters with constraints (base type mentions) #19102
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ba9edf8
Shared: Refactor type inference
paldepind 831413b
Rust: Expand on type parameter bounds type inference test
paldepind 06c8963
Shared: Infer types for type parameters with contraints
paldepind 54e7bb7
Rust: Fix a bad join by adding bindingset to resolveTypeMentionRoot
paldepind efcffc5
Merge branch 'main' into rust-ti-refactor
paldepind 520e27c
Shared: Fix typos in qldoc
paldepind 623bc23
Rust: Address PR comments
paldepind 989c144
Rust: Minor doc tweaks based on PR comments
paldepind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,11 +287,11 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| * - `T3` is mentioned at `T2.T1` for immediate base type mention `Base<C<T3>>` | ||
| * of `Mid`, | ||
| * - ``C`1`` is mentioned at `T3` for immediate base type mention `Mid<C<T4>>` | ||
| * of `Sub`, and | ||
| * of `Sub`, | ||
| * - `T4` is mentioned at `T3.T1` for immediate base type mention `Mid<C<T4>>` | ||
| * of `Sub`, and | ||
| * of `Sub`, | ||
| * - ``C`1`` is mentioned at `T2` and implicitly at `T2.T1` for transitive base type | ||
| * mention `Base<C<T3>>` of `Sub`. | ||
| * mention `Base<C<T3>>` of `Sub`, and | ||
| * - `T4` is mentioned implicitly at `T2.T1.T1` for transitive base type mention | ||
| * `Base<C<T3>>` of `Sub`. | ||
| */ | ||
|
|
@@ -307,8 +307,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| or | ||
| // transitive base class | ||
| exists(Type immediateBase | immediateBase = resolveTypeMentionRoot(immediateBaseMention) | | ||
| not t = immediateBase.getATypeParameter() and | ||
| baseTypeMentionHasTypeAt(immediateBase, baseMention, path, t) | ||
| baseTypeMentionHasNonTypeParameterAt(immediateBase, baseMention, path, t) | ||
| or | ||
| exists(TypePath path0, TypePath prefix, TypePath suffix, TypeParameter tp | | ||
| /* | ||
|
|
@@ -336,15 +335,29 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| * ``` | ||
| */ | ||
|
|
||
| baseTypeMentionHasTypeAt(immediateBase, baseMention, prefix, tp) and | ||
| tp = immediateBase.getATypeParameter() and | ||
| baseTypeMentionHasTypeParameterAt(immediateBase, baseMention, prefix, tp) and | ||
| t = immediateBaseMention.resolveTypeAt(path0) and | ||
| path0.isCons(tp, suffix) and | ||
| path = prefix.append(suffix) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| /** Similar to `baseTypeMentionHasTypeAt` but FIXME: */ | ||
| pragma[inline] | ||
| predicate baseTypeMentionHasNonTypeParameterAt( | ||
| Type sub, TypeMention baseMention, TypePath path, Type t | ||
| ) { | ||
| not t = sub.getATypeParameter() and baseTypeMentionHasTypeAt(sub, baseMention, path, t) | ||
| } | ||
|
|
||
| pragma[inline] | ||
| predicate baseTypeMentionHasTypeParameterAt( | ||
| Type sub, TypeMention baseMention, TypePath path, TypeParameter tp | ||
| ) { | ||
| tp = sub.getATypeParameter() and baseTypeMentionHasTypeAt(sub, baseMention, path, tp) | ||
| } | ||
| } | ||
|
|
||
| private import BaseTypes | ||
|
|
@@ -514,7 +527,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| private module AccessBaseType { | ||
| /** | ||
| * Holds if inferring types at `a` might depend on the type at `path` of | ||
| * `apos` having `baseMention` as a transitive base type mention. | ||
| * `apos` having `base` as a transitive base type mention. | ||
|
||
| */ | ||
| private predicate relevantAccess(Access a, AccessPosition apos, TypePath path, Type base) { | ||
| exists(Declaration target, DeclarationPosition dpos | | ||
|
|
@@ -557,8 +570,9 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| * // ^^^^^^^^^^^^^^^^^^^^^^^^^ `a` | ||
| * ``` | ||
| * | ||
| * where the method call is an access and `new Sub<int>()` is at an | ||
| * access position, which is the receiver of a method call, we have: | ||
| * where the method call is an access, `new Sub<int>()` is at the access | ||
| * position which is the receiver of a method call, and `pathToSub` is | ||
| * `""` we have: | ||
| * | ||
| * `baseMention` | `path` | `t` | ||
| * ------------- | ------------ | --- | ||
|
|
@@ -575,12 +589,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| ) { | ||
| relevantAccess(a, apos, pathToSub, resolveTypeMentionRoot(baseMention)) and | ||
| exists(Type sub | sub = a.getInferredType(apos, pathToSub) | | ||
| not t = sub.getATypeParameter() and | ||
| baseTypeMentionHasTypeAt(sub, baseMention, path, t) | ||
| baseTypeMentionHasNonTypeParameterAt(sub, baseMention, path, t) | ||
| or | ||
| exists(TypePath prefix, TypePath suffix, TypeParameter tp | | ||
| tp = sub.getATypeParameter() and | ||
| baseTypeMentionHasTypeAt(sub, baseMention, prefix, tp) and | ||
| baseTypeMentionHasTypeParameterAt(sub, baseMention, prefix, tp) and | ||
| t = inferTypeAt(a, apos, pathToSub, tp, suffix) and | ||
| path = prefix.append(suffix) | ||
| ) | ||
|
|
@@ -681,15 +693,15 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| * For this example | ||
| * ```csharp | ||
| * interface IFoo<A> { } | ||
| * void M<T1, T2>(T2 item) where T2 : IFoo<T1> { } | ||
| * T1 M<T1, T2>(T2 item) where T2 : IFoo<T1> { } | ||
| * ``` | ||
| * with the method declaration being the target and the for the first | ||
| * parameter position, we have the following | ||
| * - `path1 = ""`, | ||
| * - `tp1 = T2`, | ||
| * - `constraint = IFoo`, | ||
| * - `path2 = "A"`, | ||
| * - `tp2 = T1` | ||
| * - `path2 = "A"`, and | ||
| * - `tp2 = T1`. | ||
| */ | ||
| pragma[nomagic] | ||
| private predicate typeParameterConstraintHasTypeParameter( | ||
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should be fixed ;-)
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.
Fine to simply the remove the QL doc.
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.
Oops 😅