-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: extract crate graph #18228
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
Rust: extract crate graph #18228
Conversation
48783f3
to
e0ecf47
Compare
9f083b9
to
7419e77
Compare
4c9e103
to
83111f3
Compare
4782bc1
to
b3ed09d
Compare
c651fee
to
ed57708
Compare
private import codeql.rust.elements.internal.generated.Raw | ||
import codeql.rust.elements.Crate | ||
import codeql.rust.elements.internal.ElementImpl::Impl as ElementImpl | ||
import codeql.rust.elements.Module |
Check warning
Code scanning / CodeQL
Redundant import Warning generated
codeql.rust.elements.Crate
95cbd9b
to
7d08551
Compare
394bc66
to
bbe51cb
Compare
…ion checks These elements depend on the version of the standard libraries and platform, and in addition no location information is extracted for them at the moment. f
bbe51cb
to
9814aef
Compare
@@ -1,4 +1,5 @@ | |||
import rust | |||
|
|||
from Function f | |||
where exists(f.getLocation().getFile().getRelativePath()) |
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.
How about adding
/** Holds if this element is from source code. */
predicate fromSource() { exists(this.getFile().getRelativePath()) }
to the class Locatable
inside LocatableImpl.qll
, and then replace all these calls with simply fromSource
?
@@ -55,7 +55,8 @@ class File extends Container, Impl::File { | |||
| | |||
node.getFile() = this and | |||
line = [/*loc.getStartLine(), */ loc.getEndLine()] and // ignore start locations for now as we're getting them wrong for things with a comment attached | |||
not loc instanceof EmptyLocation | |||
not loc instanceof EmptyLocation and | |||
line > 0 |
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.
Why can't line 0
contain code?
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.
Lines start at 1
. A location with a 0
line is pointing to a whole file .
override string toString() { | ||
result = "Crate(" + this.getName() + "@" + concat(this.getVersion()) + ")" | ||
} |
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.
override string toString() { | |
result = "Crate(" + this.getName() + "@" + concat(this.getVersion()) + ")" | |
} | |
override string toString() { | |
result = strictconcat(int i | | this.toStringPart(i), " " order by i) | |
} | |
private string toStringPart(int i) { | |
i = 0 and result = "Crate(" | |
or | |
i = 1 and result = this.getName() | |
or | |
i = 2 and result = "@" | |
or | |
i = 3 and result = this.getVersion() | |
or | |
i = 4 and result = ")" | |
} |
@@ -24,7 +24,9 @@ query predicate multipleLocations(Locatable e) { strictcount(e.getLocation()) > | |||
/** | |||
* Holds if `e` does not have a `Location`. | |||
*/ | |||
query predicate noLocation(Locatable e) { not exists(e.getLocation()) } | |||
query predicate noLocation(Locatable e) { | |||
not exists(e.getLocation()) and not e.(AstNode).getParentNode*() = any(Crate c).getModule() |
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.
Does this mean we only have crate information for entities that are not in the source code?
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.
No, we have crate information for things in source code, but the crate information has no locations.
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.
Just to double check: This is because for things in source code, we will now extract two entities, one as before, and a new one with crate information (for which we do not want to report missing locations)?
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.
Yes, that's right. For items in source code, you'd have signatures without bodies and without locations.
766a338
to
3991dc3
Compare
As discussed offline, re-exports like this are not currently extracted, so we should do that follow-up. |
This pull request changes the Rust extractor to emit information about the crate graph, and the public modules, types, traits and function signatures contained in each crate. This should give our analyses information about names and types provided by the dependencies of a project. The information in the crate graph is represented as AST nodes without macro calls; type paths should be fully qualified and methods/functions have no bodies.
This PR currently does not extract generic type arguments ,
where
clauses, and associated types and aliases. These should be added in a follow-up pull request.