-
Notifications
You must be signed in to change notification settings - Fork 2k
Rust: Improve performance of type inference #19534
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -181,18 +181,29 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |||||||||||||||||||||
| /** Holds if this type path is empty. */ | ||||||||||||||||||||||
| predicate isEmpty() { this = "" } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** Gets the length of this path, assuming the length is at least 2. */ | ||||||||||||||||||||||
| bindingset[this] | ||||||||||||||||||||||
| pragma[inline_late] | ||||||||||||||||||||||
| private int length2() { | ||||||||||||||||||||||
|
||||||||||||||||||||||
| // Same as | ||||||||||||||||||||||
| // `result = strictcount(this.indexOf(".")) + 1` | ||||||||||||||||||||||
| // but performs better because it doesn't use an aggregate | ||||||||||||||||||||||
| result = this.regexpReplaceAll("[0-9]+", "").length() + 1 | ||||||||||||||||||||||
paldepind marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** Gets the length of this path. */ | ||||||||||||||||||||||
| bindingset[this] | ||||||||||||||||||||||
| pragma[inline_late] | ||||||||||||||||||||||
| int length() { | ||||||||||||||||||||||
| this.isEmpty() and result = 0 | ||||||||||||||||||||||
| or | ||||||||||||||||||||||
| result = strictcount(this.indexOf(".")) + 1 | ||||||||||||||||||||||
| if this.isEmpty() | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't depth lead to the misconception that it is a tree instead of a list?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe? To me it feel natural to say that the depth of |
||||||||||||||||||||||
| then result = 0 | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| if exists(TypeParameter::decode(this)) | ||||||||||||||||||||||
| then result = 1 | ||||||||||||||||||||||
| else result = this.length2() | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** Gets the path obtained by appending `suffix` onto this path. */ | ||||||||||||||||||||||
| bindingset[suffix, result] | ||||||||||||||||||||||
| bindingset[this, result] | ||||||||||||||||||||||
| bindingset[this, suffix] | ||||||||||||||||||||||
| TypePath append(TypePath suffix) { | ||||||||||||||||||||||
| if this.isEmpty() | ||||||||||||||||||||||
|
|
@@ -202,22 +213,37 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |||||||||||||||||||||
| then result = this | ||||||||||||||||||||||
| else ( | ||||||||||||||||||||||
| result = this + "." + suffix and | ||||||||||||||||||||||
| not result.length() > getTypePathLimit() | ||||||||||||||||||||||
| ( | ||||||||||||||||||||||
| not exists(getTypePathLimit()) | ||||||||||||||||||||||
paldepind marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
| or | ||||||||||||||||||||||
| result.length2() <= getTypePathLimit() | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Gets the path obtained by appending `suffix` onto this path. | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * Unlike `append`, this predicate has `result` in the binding set, | ||||||||||||||||||||||
| * so there is no need to check the length of `result`. | ||||||||||||||||||||||
|
Comment on lines
+225
to
+228
|
||||||||||||||||||||||
| * Gets the path obtained by appending `suffix` onto this path. | |
| * | |
| * Unlike `append`, this predicate has `result` in the binding set, | |
| * so there is no need to check the length of `result`. | |
| * Deconstructs a full path `result` into `this` and `suffix`. | |
| * | |
| * This predicate performs the inverse operation of `append`. It holds if | |
| * `result` is a path that can be split into `this` as the prefix and | |
| * `suffix` as the remainder. For example, if `result` is "a.b.c" and | |
| * `this` is "a.b", then `suffix` would be "c". |
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.
A variant of this where the result is the output could be:
bindingset[this, prefix]
TypePath stripPrefix(TypePath prefix) { this = prefix.appendInverse(result) }Similar to my comment for consInverse I find that more natural. However, unlike for isCons this variant is less convenient in all the places where appendInverse is used. But perhaps we could introduce stripPrefix, define appendInverse in terms of stripPrefix, and use stripPrefix in the (few if any) cases where it's not inconvenient?
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.
consInverse is equivalent to isCons but with a different parameter order.
I find isCons easer to read as it's the result that is the output and since the name is easier to understand. Looking at the places where consInverse is used there's only one spot where it's not trivial to use isCons instead. Given that, I think it would make sense to remove consInverse and use isCons instead.
Uh oh!
There was an error while loading. Please reload this page.