Skip to content

Commit dfd833d

Browse files
committed
refine graph builder and hir APIs
1 parent 1c9ea42 commit dfd833d

19 files changed

Lines changed: 453 additions & 445 deletions

File tree

crates/llmcc-cli/src/runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use tracing::info;
77

88
use llmcc_core::context::{BuildMetrics, FileOrder};
99
use llmcc_core::graph::ProjectGraph;
10-
use llmcc_core::graph_builder::{GraphBuildOption, build_llmcc_graph};
1110
use llmcc_core::lang_def::Language as CoreLanguage;
1211
use llmcc_core::{CompileCtxt, Error, ResolveOptions, Result, print_llmcc_graph};
12+
use llmcc_core::{GraphBuildOptions, build_graphs};
1313
use llmcc_cpp::LangCpp;
1414
use llmcc_dot::{RenderOptions, render_graph_with_options};
1515
use llmcc_resolver::{bind_symbols_with, build_and_collect_symbols};
@@ -85,7 +85,7 @@ impl Runner {
8585

8686
let graph_start = Instant::now();
8787
let mut project_graph = ProjectGraph::new(&cc);
88-
let unit_graphs = build_llmcc_graph::<L>(&cc, GraphBuildOption::new())?;
88+
let unit_graphs = build_graphs::<L>(&cc, GraphBuildOptions::new())?;
8989
project_graph.add_children(unit_graphs);
9090
info!(
9191
"Graph building: {:.2}s",

crates/llmcc-collect/src/collect.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ pub fn collect_nodes(project: &ProjectGraph) -> Vec<RenderNode> {
5151
}
5252

5353
// Get symbol info for visibility check
54-
let symbol_opt = block
55-
.node()
56-
.as_scope()
57-
.and_then(|scope_node| scope_node.try_scope())
58-
.and_then(|scope| scope.try_symbol());
54+
let symbol_opt = block.node().try_scope_symbol();
5955

6056
let sym_kind = symbol_opt.map(|s| s.kind());
6157

crates/llmcc-core/src/block.rs

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ pub enum BlockKind {
5555
Alias,
5656
}
5757

58+
impl BlockKind {
59+
/// Return true when this kind has a concrete [`BasicBlock`] representation.
60+
pub fn is_graph_block(self) -> bool {
61+
matches!(
62+
self,
63+
BlockKind::Root
64+
| BlockKind::Module
65+
| BlockKind::Func
66+
| BlockKind::Method
67+
| BlockKind::Call
68+
| BlockKind::Class
69+
| BlockKind::Trait
70+
| BlockKind::Interface
71+
| BlockKind::Enum
72+
| BlockKind::Const
73+
| BlockKind::Impl
74+
| BlockKind::Field
75+
| BlockKind::Parameter
76+
| BlockKind::Return
77+
| BlockKind::Alias
78+
)
79+
}
80+
}
81+
5882
/// Concrete block stored in the block graph.
5983
///
6084
/// Each variant wraps a block-specific payload, but every variant has a
@@ -460,10 +484,10 @@ impl<'blk> BlockRoot<'blk> {
460484
children: Vec<BlockId>,
461485
file_name: Option<String>,
462486
) -> Self {
463-
Self::new_with_symbol(id, node, parent, children, file_name, None)
487+
Self::new_with(id, node, parent, children, file_name, None)
464488
}
465489

466-
pub fn new_with_symbol(
490+
pub fn new_with(
467491
id: BlockId,
468492
node: HirNode<'blk>,
469493
parent: Option<BlockId>,
@@ -549,10 +573,10 @@ impl<'blk> BlockModule<'blk> {
549573
name: String,
550574
is_inline: bool,
551575
) -> Self {
552-
Self::new_with_symbol(id, node, parent, children, name, is_inline, None)
576+
Self::new_with(id, node, parent, children, name, is_inline, None)
553577
}
554578

555-
pub fn new_with_symbol(
579+
pub fn new_with(
556580
id: BlockId,
557581
node: HirNode<'blk>,
558582
parent: Option<BlockId>,
@@ -603,10 +627,10 @@ impl<'blk> BlockFunc<'blk> {
603627
parent: Option<BlockId>,
604628
children: Vec<BlockId>,
605629
) -> Self {
606-
Self::new_with_symbol(id, node, kind, parent, children, None)
630+
Self::new_with(id, node, kind, parent, children, None)
607631
}
608632

609-
pub fn new_with_symbol(
633+
pub fn new_with(
610634
id: BlockId,
611635
node: HirNode<'blk>,
612636
kind: BlockKind,
@@ -718,10 +742,10 @@ impl<'blk> BlockCall<'blk> {
718742
parent: Option<BlockId>,
719743
children: Vec<BlockId>,
720744
) -> Self {
721-
Self::new_with_symbol(id, node, parent, children, None)
745+
Self::new_with(id, node, parent, children, None)
722746
}
723747

724-
pub fn new_with_symbol(
748+
pub fn new_with(
725749
id: BlockId,
726750
node: HirNode<'blk>,
727751
parent: Option<BlockId>,
@@ -777,10 +801,10 @@ impl<'blk> BlockClass<'blk> {
777801
parent: Option<BlockId>,
778802
children: Vec<BlockId>,
779803
) -> Self {
780-
Self::new_with_symbol(id, node, parent, children, None)
804+
Self::new_with(id, node, parent, children, None)
781805
}
782806

783-
pub fn new_with_symbol(
807+
pub fn new_with(
784808
id: BlockId,
785809
node: HirNode<'blk>,
786810
parent: Option<BlockId>,
@@ -888,10 +912,10 @@ impl<'blk> BlockTrait<'blk> {
888912
parent: Option<BlockId>,
889913
children: Vec<BlockId>,
890914
) -> Self {
891-
Self::new_with_symbol(id, node, parent, children, None)
915+
Self::new_with(id, node, parent, children, None)
892916
}
893917

894-
pub fn new_with_symbol(
918+
pub fn new_with(
895919
id: BlockId,
896920
node: HirNode<'blk>,
897921
parent: Option<BlockId>,
@@ -944,10 +968,10 @@ impl<'blk> BlockInterface<'blk> {
944968
parent: Option<BlockId>,
945969
children: Vec<BlockId>,
946970
) -> Self {
947-
Self::new_with_symbol(id, node, parent, children, None)
971+
Self::new_with(id, node, parent, children, None)
948972
}
949973

950-
pub fn new_with_symbol(
974+
pub fn new_with(
951975
id: BlockId,
952976
node: HirNode<'blk>,
953977
parent: Option<BlockId>,
@@ -1046,10 +1070,10 @@ impl<'blk> BlockImpl<'blk> {
10461070
parent: Option<BlockId>,
10471071
children: Vec<BlockId>,
10481072
) -> Self {
1049-
Self::new_with_symbol(id, node, parent, children, None)
1073+
Self::new_with(id, node, parent, children, None)
10501074
}
10511075

1052-
pub fn new_with_symbol(
1076+
pub fn new_with(
10531077
id: BlockId,
10541078
node: HirNode<'blk>,
10551079
parent: Option<BlockId>,
@@ -1137,10 +1161,10 @@ impl<'blk> BlockEnum<'blk> {
11371161
parent: Option<BlockId>,
11381162
children: Vec<BlockId>,
11391163
) -> Self {
1140-
Self::new_with_symbol(id, node, parent, children, None)
1164+
Self::new_with(id, node, parent, children, None)
11411165
}
11421166

1143-
pub fn new_with_symbol(
1167+
pub fn new_with(
11441168
id: BlockId,
11451169
node: HirNode<'blk>,
11461170
parent: Option<BlockId>,
@@ -1192,20 +1216,20 @@ impl<'blk> BlockConst<'blk> {
11921216
parent: Option<BlockId>,
11931217
children: Vec<BlockId>,
11941218
) -> Self {
1195-
Self::new_with_symbol(id, node, parent, children, None)
1219+
Self::new_with(id, node, parent, children, None)
11961220
}
11971221

1198-
pub fn new_with_symbol(
1222+
pub fn new_with(
11991223
id: BlockId,
12001224
node: HirNode<'blk>,
12011225
parent: Option<BlockId>,
12021226
children: Vec<BlockId>,
12031227
symbol: Option<&'blk Symbol>,
12041228
) -> Self {
1205-
Self::new_with_name_and_symbol(id, node, parent, children, None, symbol)
1229+
Self::new_with_name(id, node, parent, children, None, symbol)
12061230
}
12071231

1208-
pub(crate) fn new_with_name_and_symbol(
1232+
pub(crate) fn new_with_name(
12091233
id: BlockId,
12101234
node: HirNode<'blk>,
12111235
parent: Option<BlockId>,
@@ -1274,20 +1298,20 @@ impl<'blk> BlockField<'blk> {
12741298
parent: Option<BlockId>,
12751299
children: Vec<BlockId>,
12761300
) -> Self {
1277-
Self::new_with_symbol(id, node, parent, children, None)
1301+
Self::new_with(id, node, parent, children, None)
12781302
}
12791303

1280-
pub fn new_with_symbol(
1304+
pub fn new_with(
12811305
id: BlockId,
12821306
node: HirNode<'blk>,
12831307
parent: Option<BlockId>,
12841308
children: Vec<BlockId>,
12851309
symbol: Option<&'blk Symbol>,
12861310
) -> Self {
1287-
Self::new_with_name_and_symbol(id, node, parent, children, None, symbol)
1311+
Self::new_with_name(id, node, parent, children, None, symbol)
12881312
}
12891313

1290-
pub(crate) fn new_with_name_and_symbol(
1314+
pub(crate) fn new_with_name(
12911315
id: BlockId,
12921316
node: HirNode<'blk>,
12931317
parent: Option<BlockId>,
@@ -1359,20 +1383,20 @@ impl<'blk> BlockParameter<'blk> {
13591383
parent: Option<BlockId>,
13601384
children: Vec<BlockId>,
13611385
) -> Self {
1362-
Self::new_with_symbol(id, node, parent, children, None)
1386+
Self::new_with(id, node, parent, children, None)
13631387
}
13641388

1365-
pub fn new_with_symbol(
1389+
pub fn new_with(
13661390
id: BlockId,
13671391
node: HirNode<'blk>,
13681392
parent: Option<BlockId>,
13691393
children: Vec<BlockId>,
13701394
symbol: Option<&'blk Symbol>,
13711395
) -> Self {
1372-
Self::new_with_name_and_symbol(id, node, parent, children, None, symbol)
1396+
Self::new_with_name(id, node, parent, children, None, symbol)
13731397
}
13741398

1375-
pub(crate) fn new_with_name_and_symbol(
1399+
pub(crate) fn new_with_name(
13761400
id: BlockId,
13771401
node: HirNode<'blk>,
13781402
parent: Option<BlockId>,
@@ -1441,10 +1465,10 @@ impl<'blk> BlockReturn<'blk> {
14411465
parent: Option<BlockId>,
14421466
children: Vec<BlockId>,
14431467
) -> Self {
1444-
Self::new_with_symbol(id, node, parent, children, None)
1468+
Self::new_with(id, node, parent, children, None)
14451469
}
14461470

1447-
pub fn new_with_symbol(
1471+
pub fn new_with(
14481472
id: BlockId,
14491473
node: HirNode<'blk>,
14501474
parent: Option<BlockId>,
@@ -1502,20 +1526,20 @@ impl<'blk> BlockAlias<'blk> {
15021526
parent: Option<BlockId>,
15031527
children: Vec<BlockId>,
15041528
) -> Self {
1505-
Self::new_with_symbol(id, node, parent, children, None)
1529+
Self::new_with(id, node, parent, children, None)
15061530
}
15071531

1508-
pub fn new_with_symbol(
1532+
pub fn new_with(
15091533
id: BlockId,
15101534
node: HirNode<'blk>,
15111535
parent: Option<BlockId>,
15121536
children: Vec<BlockId>,
15131537
symbol: Option<&'blk Symbol>,
15141538
) -> Self {
1515-
Self::new_with_name_and_symbol(id, node, parent, children, None, symbol)
1539+
Self::new_with_name(id, node, parent, children, None, symbol)
15161540
}
15171541

1518-
pub(crate) fn new_with_name_and_symbol(
1542+
pub(crate) fn new_with_name(
15191543
id: BlockId,
15201544
node: HirNode<'blk>,
15211545
parent: Option<BlockId>,

0 commit comments

Comments
 (0)