mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Merge pull request #18228 from github/aibaars/crate-graph
Rust: extract crate graph
This commit is contained in:
@@ -14,6 +14,7 @@ ra_ap_base_db = "0.0.266"
|
||||
ra_ap_hir = "0.0.266"
|
||||
ra_ap_hir_def = "0.0.266"
|
||||
ra_ap_ide_db = "0.0.266"
|
||||
ra_ap_hir_ty = "0.0.266"
|
||||
ra_ap_hir_expand = "0.0.266"
|
||||
ra_ap_load-cargo = "0.0.266"
|
||||
ra_ap_paths = "0.0.266"
|
||||
@@ -39,3 +40,4 @@ toml = "0.8.20"
|
||||
tracing = "0.1.41"
|
||||
tracing-flame = "0.2.0"
|
||||
tracing-subscriber = "0.3.19"
|
||||
chalk-ir = "0.99.0"
|
||||
|
||||
1311
rust/extractor/src/crate_graph.rs
Normal file
1311
rust/extractor/src/crate_graph.rs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -83,6 +83,7 @@ pub enum ExtractionStepKind {
|
||||
LoadSource,
|
||||
Parse,
|
||||
Extract,
|
||||
CrateGraph,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
@@ -128,6 +129,10 @@ impl ExtractionStep {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn crate_graph(start: Instant) -> Self {
|
||||
Self::new(start, ExtractionStepKind::CrateGraph, None)
|
||||
}
|
||||
|
||||
pub fn load_source(start: Instant, target: &Path) -> Self {
|
||||
Self::new(
|
||||
start,
|
||||
|
||||
2
rust/extractor/src/generated/.generated.list
generated
2
rust/extractor/src/generated/.generated.list
generated
@@ -1,2 +1,2 @@
|
||||
mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7
|
||||
top.rs da0f43b99d3a173520048275597e2b052a7351f6fcb2ad5fc912257976742bb7 da0f43b99d3a173520048275597e2b052a7351f6fcb2ad5fc912257976742bb7
|
||||
top.rs 4b7dee6ebdbb2f8bd2f387cbb71e0481475de0a94c0baaac4699f19551256d65 4b7dee6ebdbb2f8bd2f387cbb71e0481475de0a94c0baaac4699f19551256d65
|
||||
|
||||
48
rust/extractor/src/generated/top.rs
generated
48
rust/extractor/src/generated/top.rs
generated
@@ -22,6 +22,54 @@ impl trap::TrapClass for Element {
|
||||
fn class_name() -> &'static str { "Element" }
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Crate {
|
||||
pub id: trap::TrapId<Crate>,
|
||||
pub name: Option<String>,
|
||||
pub version: Option<String>,
|
||||
pub module: Option<trap::Label<Module>>,
|
||||
pub cfg_options: Vec<String>,
|
||||
pub dependencies: Vec<trap::Label<Crate>>,
|
||||
}
|
||||
|
||||
impl trap::TrapEntry for Crate {
|
||||
fn extract_id(&mut self) -> trap::TrapId<Self> {
|
||||
std::mem::replace(&mut self.id, trap::TrapId::Star)
|
||||
}
|
||||
|
||||
fn emit(self, id: trap::Label<Self>, out: &mut trap::Writer) {
|
||||
out.add_tuple("crates", vec![id.into()]);
|
||||
if let Some(v) = self.name {
|
||||
out.add_tuple("crate_names", vec![id.into(), v.into()]);
|
||||
}
|
||||
if let Some(v) = self.version {
|
||||
out.add_tuple("crate_versions", vec![id.into(), v.into()]);
|
||||
}
|
||||
if let Some(v) = self.module {
|
||||
out.add_tuple("crate_modules", vec![id.into(), v.into()]);
|
||||
}
|
||||
for (i, v) in self.cfg_options.into_iter().enumerate() {
|
||||
out.add_tuple("crate_cfg_options", vec![id.into(), i.into(), v.into()]);
|
||||
}
|
||||
for (i, v) in self.dependencies.into_iter().enumerate() {
|
||||
out.add_tuple("crate_dependencies", vec![id.into(), i.into(), v.into()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl trap::TrapClass for Crate {
|
||||
fn class_name() -> &'static str { "Crate" }
|
||||
}
|
||||
|
||||
impl From<trap::Label<Crate>> for trap::Label<Element> {
|
||||
fn from(value: trap::Label<Crate>) -> Self {
|
||||
// SAFETY: this is safe because in the dbscheme Crate is a subclass of Element
|
||||
unsafe {
|
||||
Self::from_untyped(value.as_untyped())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ExtractorStep {
|
||||
pub id: trap::TrapId<ExtractorStep>,
|
||||
|
||||
@@ -23,6 +23,7 @@ use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
mod archive;
|
||||
mod config;
|
||||
mod crate_graph;
|
||||
mod diagnostics;
|
||||
pub mod generated;
|
||||
mod qltest;
|
||||
@@ -255,6 +256,11 @@ fn main() -> anyhow::Result<()> {
|
||||
if let Some((ref db, ref vfs)) =
|
||||
extractor.load_manifest(manifest, &cargo_config, &load_cargo_config)
|
||||
{
|
||||
let before_crate_graph = Instant::now();
|
||||
crate_graph::extract_crate_graph(extractor.traps, db, vfs);
|
||||
extractor
|
||||
.steps
|
||||
.push(ExtractionStep::crate_graph(before_crate_graph));
|
||||
let semantics = Semantics::new(db);
|
||||
for file in files {
|
||||
match extractor.load_source(file, &semantics, vfs) {
|
||||
|
||||
@@ -74,7 +74,7 @@ macro_rules! trap_key {
|
||||
$(
|
||||
key.push_str(&$x.as_key_part());
|
||||
)*
|
||||
$crate::TrapId::Key(key)
|
||||
trap::TrapId::Key(key)
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ impl<T: TrapClass> From<Label<T>> for trap::Arg {
|
||||
}
|
||||
|
||||
pub struct TrapFile {
|
||||
path: PathBuf,
|
||||
pub path: PathBuf,
|
||||
pub writer: Writer,
|
||||
compression: Compression,
|
||||
}
|
||||
@@ -171,6 +171,26 @@ impl TrapFile {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn emit_file_only_location<E: TrapClass>(
|
||||
&mut self,
|
||||
file_label: Label<generated::File>,
|
||||
entity_label: Label<E>,
|
||||
) {
|
||||
let location_label = extractor::location_label(
|
||||
&mut self.writer,
|
||||
trap::Location {
|
||||
file_label: file_label.as_untyped(),
|
||||
start_line: 0,
|
||||
start_column: 0,
|
||||
end_line: 0,
|
||||
end_column: 0,
|
||||
},
|
||||
);
|
||||
self.writer.add_tuple(
|
||||
"locatable_locations",
|
||||
vec![entity_label.into(), location_label.into()],
|
||||
);
|
||||
}
|
||||
pub fn emit_diagnostic(
|
||||
&mut self,
|
||||
severity: DiagnosticSeverity,
|
||||
|
||||
Reference in New Issue
Block a user