Skip to content

Commit 1dfbbd9

Browse files
committed
Add full macro route regeneration pipeline
1 parent 0ddf1a2 commit 1dfbbd9

32 files changed

Lines changed: 5647 additions & 239 deletions

cppmega_mlx/config/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class StructureConfig:
136136

137137
active_components: str = "core"
138138
bottleneck_dim: int = 64
139-
num_categories: int = 9
139+
num_categories: int = 12
140140
max_dep_level: int = 16
141141
max_ast_depth: int = 64
142142
max_sibling_index: int = 64

cppmega_mlx/data/domain_schema.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ class DomainEdgeKind(IntEnum):
8181
TYPE = 3
8282
DEF_USE = 4
8383
INCLUDE = 5
84+
MACRO_PARAM_USE = 6
85+
MACRO_INVOCATION = 7
86+
MACRO_CONDITION = 8
87+
MACRO_REDEFINITION = 9
88+
MACRO_INCLUDE_ORDER = 10
89+
MACRO_EXPANSION_CONDITION = 11
90+
MACRO_EXPANSION_REDEFINITION = 12
91+
MACRO_EXPANSION_INCLUDE_ORDER = 13
8492
BUILD_TARGET_DEP = 20
8593
BUILD_TARGET_SOURCE = 21
8694
BUILD_RULE_COMMAND = 22
@@ -118,10 +126,16 @@ class ParseConfidence(IntEnum):
118126
DomainKind.MAKE: ("MAKE_START", "MAKE_END"),
119127
DomainKind.NINJA: ("NINJA_START", "NINJA_END"),
120128
DomainKind.BAZEL: ("BAZEL_START", "BAZEL_END"),
121-
# Autotools/Automake are Make-family text, but remain distinct in
122-
# token_domain_ids so the model does not collapse them semantically.
123-
DomainKind.AUTOCONF: ("MAKE_START", "MAKE_END"),
124-
DomainKind.AUTOMAKE: ("MAKE_START", "MAKE_END"),
129+
DomainKind.AUTOCONF: ("AUTOCONF_START", "AUTOCONF_END"),
130+
DomainKind.AUTOMAKE: ("AUTOMAKE_START", "AUTOMAKE_END"),
131+
DomainKind.MESON: ("MESON_START", "MESON_END"),
132+
DomainKind.GN: ("GN_START", "GN_END"),
133+
DomainKind.SCONS: ("SCONS_START", "SCONS_END"),
134+
DomainKind.XMAKE: ("XMAKE_START", "XMAKE_END"),
135+
DomainKind.COMPILE_COMMANDS: (
136+
"COMPILE_COMMANDS_START",
137+
"COMPILE_COMMANDS_END",
138+
),
125139
DomainKind.BASH: ("BASH_START", "BASH_END"),
126140
DomainKind.ZSH: ("ZSH_START", "ZSH_END"),
127141
DomainKind.SH: ("SH_START", "SH_END"),

cppmega_mlx/data/nanochat_pipeline/build_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ def read_text(name: str) -> str | None:
878878
path = compile_commands_path
879879
else:
880880
path = os.path.join(repo_dir, name)
881-
if not os.path.exists(path):
881+
if not os.path.isfile(path):
882882
return None
883883
with open(path, "r", encoding="utf-8", errors="replace") as f:
884884
return f.read()

cppmega_mlx/data/nanochat_pipeline/packed_rows_schema.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
SOURCE_HAS_PR_DISCUSSIONS_COLUMN = "source_has_pr_discussions"
8282
SOURCE_PR_DISCUSSION_CHARS_COLUMN = "source_pr_discussion_chars"
8383
SOURCE_PR_DISCUSSION_LINES_COLUMN = "source_pr_discussion_lines"
84+
SOURCE_DOC_TYPES_COLUMN = "source_doc_types"
85+
SOURCE_HEADER_FRAGMENT_KINDS_COLUMN = "source_header_fragment_kinds"
8486
PACKED_REPO_COLUMN = REPO_COLUMN
8587
PACKED_FILEPATH_COLUMN = FILEPATH_COLUMN
8688
PACKED_COMMIT_HASH_COLUMN = COMMIT_HASH_COLUMN
@@ -212,6 +214,8 @@
212214
SOURCE_HAS_PR_DISCUSSIONS_COLUMN,
213215
SOURCE_PR_DISCUSSION_CHARS_COLUMN,
214216
SOURCE_PR_DISCUSSION_LINES_COLUMN,
217+
SOURCE_DOC_TYPES_COLUMN,
218+
SOURCE_HEADER_FRAGMENT_KINDS_COLUMN,
215219
ROW_PLATFORM_IDS_COLUMN,
216220
PACKED_REPO_COLUMN,
217221
PACKED_FILEPATH_COLUMN,
@@ -371,6 +375,8 @@ def resolve_packed_row_valid_token_count(
371375
"SOURCE_HAS_PR_DISCUSSIONS_COLUMN",
372376
"SOURCE_PR_DISCUSSION_CHARS_COLUMN",
373377
"SOURCE_PR_DISCUSSION_LINES_COLUMN",
378+
"SOURCE_DOC_TYPES_COLUMN",
379+
"SOURCE_HEADER_FRAGMENT_KINDS_COLUMN",
374380
"PLATFORM_IDS_COLUMN",
375381
"ROW_PLATFORM_IDS_COLUMN",
376382
"PACKED_REPO_COLUMN",

cppmega_mlx/data/nanochat_pipeline/tokenized_enriched.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,12 @@ def _insert_domain_delimiters(
458458
domain: DomainKind,
459459
insert_at: int = 1,
460460
) -> None:
461+
if DomainKind(domain) == DomainKind.UNKNOWN:
462+
return
461463
try:
462464
start_id, end_id = delimiter_token_ids(domain)
463-
except KeyError:
464-
return
465+
except KeyError as exc:
466+
raise ValueError(f"missing delimiter token contract for domain {domain!r}") from exc
465467
token_ids = list(row[TOKEN_IDS_COLUMN])
466468
if insert_at > len(token_ids):
467469
insert_at = len(token_ids)

cppmega_mlx/data/nanochat_pipeline/tokenized_enriched_schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def _extract_span_bounds(span: object) -> tuple[int, int] | None:
9696
HUNK_ID_PER_TOKEN_COLUMN = "hunk_id_per_token"
9797
EDIT_OP_PER_TOKEN_COLUMN = "edit_op_per_token"
9898

99+
DOC_TYPE_COLUMN = "doc_type"
100+
HEADER_FRAGMENT_KIND_COLUMN = "header_fragment_kind"
101+
99102
REPO_COLUMN = "repo"
100103
FILEPATH_COLUMN = "filepath"
101104
COMMIT_HASH_COLUMN = "commit_hash"
@@ -351,6 +354,8 @@ def has_materialized_token_metadata(
351354
"CHANGED_CHUNK_SPANS_COLUMN",
352355
"HUNK_ID_PER_TOKEN_COLUMN",
353356
"EDIT_OP_PER_TOKEN_COLUMN",
357+
"DOC_TYPE_COLUMN",
358+
"HEADER_FRAGMENT_KIND_COLUMN",
354359
"REPO_COLUMN",
355360
"FILEPATH_COLUMN",
356361
"COMMIT_HASH_COLUMN",

cppmega_mlx/data/tokenizer_contract.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@
3838
"NINJA_END": 198,
3939
"BAZEL_START": 199,
4040
"BAZEL_END": 200,
41+
"AUTOCONF_START": 223,
42+
"AUTOCONF_END": 224,
43+
"AUTOMAKE_START": 225,
44+
"AUTOMAKE_END": 226,
45+
"MESON_START": 227,
46+
"MESON_END": 228,
47+
"GN_START": 229,
48+
"GN_END": 230,
49+
"SCONS_START": 231,
50+
"SCONS_END": 232,
51+
"XMAKE_START": 233,
52+
"XMAKE_END": 234,
53+
"COMPILE_COMMANDS_START": 235,
54+
"COMPILE_COMMANDS_END": 236,
4155
"BASH_START": 201,
4256
"BASH_END": 202,
4357
"ZSH_START": 203,

cppmega_mlx/models/dense_cpp_lm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class DenseCppLMConfig:
8888
# Side-channel structure embedding (CppMegaStructureEmbedding).
8989
structure_components: str = "all"
9090
structure_bottleneck_dim: int = 128
91-
structure_num_categories: int = 9
91+
structure_num_categories: int = 12
9292
structure_max_dep_level: int = 64
9393
structure_max_ast_depth: int = 128
9494
structure_max_sibling_index: int = 128

cppmega_mlx/models/hybrid_lm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class HybridTinyConfig:
240240
structure_vocab_size: int = 32
241241
structure_components: str = "core"
242242
structure_bottleneck_dim: int = 64
243-
structure_num_categories: int = 9
243+
structure_num_categories: int = 12
244244
structure_max_dep_level: int = 16
245245
structure_max_ast_depth: int = 64
246246
structure_max_sibling_index: int = 64

cppmega_mlx/nn/domain_graph_routes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ def build_domain_block_candidates(
8282
DEFAULT_EDGE_WEIGHTS: dict[int, float] = {
8383
int(DomainEdgeKind.BUILD_TARGET_SOURCE): 1.0,
8484
int(DomainEdgeKind.BUILD_TARGET_DEP): 1.0,
85+
int(DomainEdgeKind.MACRO_PARAM_USE): 1.0,
86+
int(DomainEdgeKind.MACRO_INVOCATION): 1.0,
87+
int(DomainEdgeKind.MACRO_CONDITION): 1.0,
88+
int(DomainEdgeKind.MACRO_REDEFINITION): 1.0,
89+
int(DomainEdgeKind.MACRO_INCLUDE_ORDER): 1.0,
90+
int(DomainEdgeKind.MACRO_EXPANSION_CONDITION): 1.0,
91+
int(DomainEdgeKind.MACRO_EXPANSION_REDEFINITION): 1.0,
92+
int(DomainEdgeKind.MACRO_EXPANSION_INCLUDE_ORDER): 1.0,
8593
int(DomainEdgeKind.SHELL_PIPE): 1.0,
8694
int(DomainEdgeKind.DIAG_PRIMARY_LOCATION): 2.0,
8795
int(DomainEdgeKind.DIAG_FIXIT): 2.0,

0 commit comments

Comments
 (0)