-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 all 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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 lengthAtLeast2() { | ||||||||||||||||||||||
| // Same as | ||||||||||||||||||||||
| // `result = strictcount(this.indexOf(".")) + 1` | ||||||||||||||||||||||
| // but performs better because it doesn't use an aggregate | ||||||||||||||||||||||
| result = this.regexpReplaceAll("[0-9]+", "").length() + 1 | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** 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.lengthAtLeast2() | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** 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,21 +213,40 @@ 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.lengthAtLeast2() <= 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". |
Uh oh!
There was an error while loading. Please reload this page.