File size: 19,241 Bytes
919fd68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | """Declarative NoNE language-expert catalog.
These rows are capability identities and page-training objectives, not claims
that a language expert has already been trained. A family becomes promotable
only after the normal NoNE route, gradient, held-out, retention, and cold-reload
proofs pass.
"""
from __future__ import annotations
import hashlib
from typing import Final
from resynthesis.language_catalog import (
BROAD_LANGUAGE_PACK_IDS,
BROAD_LANGUAGE_PACK_IDS_SHA256,
LANGUAGE_ABILITY_AXIS_IDS,
LANGUAGE_ABILITY_IDS_BY_SOURCE_TYPE,
LINGUIST_LANGUAGE_SOURCE_PACK_RECORDS,
NATIVE_LANGUAGE_PACK_PREFIX_IDS,
)
NONE_LANGUAGE_EXPERT_CATALOG_SCHEMA: Final = (
"nnf.resynthesis.none_language_expert_catalog.v4"
)
_LANGUAGE_EXPERT_SPECS: Final[
tuple[tuple[str, str, str, tuple[str, ...]], ...]
] = (
(
"language_python",
"Python",
"CPython, typing, asyncio, packaging, data, and scientific computing",
("python", "py", "python_source"),
),
(
"language_go",
"Go",
"modules, interfaces, goroutines, channels, services, and tooling",
("go", "golang", "go_source"),
),
(
"language_java",
"Java",
"JVM behavior, generics, concurrency, Maven, Gradle, and services",
("java", "jvm_java", "java_source"),
),
(
"language_ruby",
"Ruby",
"MRI behavior, gems, metaprogramming, Rails, and services",
("ruby", "ruby_source", "rails"),
),
(
"language_php",
"PHP",
"Composer, PHP runtimes, Laravel, Symfony, and web applications",
("php", "php_source", "composer_php"),
),
(
"language_dotnet",
".NET",
"CLR semantics, assemblies, NuGet, MSBuild, ASP.NET, and interop",
("dotnet", "clr", "msbuild", "nuget"),
),
(
"language_native",
"Native systems",
"ABIs, linking, FFI, ownership, concurrency, and platform toolchains",
("native", "native_code", "abi", "system_programming"),
),
(
"language_c",
"C",
"standards, pointers, layouts, preprocessors, compilers, and embedded code",
("c", "c_source", "iso_c"),
),
(
"language_cpp",
"C++",
"templates, RAII, modern standards, CMake, ABI, and performance",
("cpp", "c++", "cplusplus", "cpp_source"),
),
(
"language_rust",
"Rust",
"ownership, lifetimes, traits, Cargo, async, unsafe code, and FFI",
("rust", "rust_source", "cargo"),
),
(
"language_csharp",
"C#",
"CLR types, LINQ, async, Roslyn, .NET libraries, and applications",
("csharp", "c#", "c_sharp"),
),
(
"language_fsharp",
"F#",
"functional .NET, algebraic types, computation expressions, and interop",
("fsharp", "f#", "f_sharp"),
),
(
"language_visual_basic",
"Visual Basic",
"VB.NET, legacy Visual Basic, COM, forms, and .NET interop",
("visual_basic", "vb", "vbnet"),
),
(
"language_javascript",
"JavaScript",
"ECMAScript, browser and Node runtimes, events, modules, and services",
("javascript", "js", "ecmascript", "nodejs"),
),
(
"language_typescript",
"TypeScript",
"structural typing, compiler configuration, declarations, and JS interop",
("typescript", "ts", "typescript_source"),
),
(
"language_swift",
"Swift",
"value semantics, protocols, concurrency, SwiftPM, Apple, and servers",
("swift", "swift_source", "swiftpm"),
),
(
"language_objective_c",
"Objective-C",
"runtime messaging, ARC, Cocoa, C interop, and mixed Apple codebases",
("objective_c", "objective-c", "objc"),
),
(
"language_kotlin",
"Kotlin",
"JVM and native targets, coroutines, Gradle, Android, and multiplatform",
("kotlin", "kotlin_source", "kotlin_multiplatform"),
),
(
"language_scala",
"Scala",
"JVM functional and object models, implicits, sbt, and data systems",
("scala", "scala_source", "sbt"),
),
(
"language_dart",
"Dart",
"sound typing, async execution, packages, Flutter, web, and native",
("dart", "dart_source", "flutter"),
),
(
"language_lua",
"Lua",
"tables, metatables, coroutines, embedding, LuaJIT, and scripting",
("lua", "lua_source", "luajit"),
),
(
"language_perl",
"Perl",
"references, regex processing, CPAN, automation, and legacy services",
("perl", "perl_source", "cpan"),
),
(
"language_r",
"R",
"vectors, statistical modeling, packages, data frames, and visualization",
("r", "r_source", "rstats"),
),
(
"language_julia",
"Julia",
"multiple dispatch, numerical computing, environments, and performance",
("julia", "julia_source", "julia_language"),
),
(
"language_matlab",
"MATLAB",
"matrix computing, toolboxes, Simulink, and numerical workflows",
("matlab", "matlab_source", "simulink"),
),
(
"language_sas",
"SAS",
"DATA steps, procedures, macros, analytics, and clinical workflows",
("sas", "sas_source", "sas_macro"),
),
(
"language_sql",
"SQL",
"relational schemas, queries, transactions, tuning, and dialect interop",
("sql", "sql_source", "relational_query"),
),
(
"language_html",
"HTML",
"semantic markup, accessibility, forms, parsing, and templates",
("html", "html_source", "web_markup"),
),
(
"language_css",
"CSS",
"cascade, layout, responsive design, animation, and browser behavior",
("css", "css_source", "stylesheets"),
),
(
"language_graphql",
"GraphQL",
"schemas, queries, resolvers, federation, clients, and API evolution",
("graphql", "graphql_source", "graphql_schema"),
),
(
"language_bash",
"Bash and POSIX shell",
"expansion, pipelines, process control, portability, and automation",
("bash", "shell", "posix_shell", "shell_script"),
),
(
"language_powershell",
"PowerShell",
"object pipelines, modules, remoting, administration, and automation",
("powershell", "pwsh", "powershell_source"),
),
(
"language_haskell",
"Haskell",
"lazy evaluation, type classes, monads, effects, Cabal, and Stack",
("haskell", "haskell_source", "cabal"),
),
(
"language_ocaml",
"OCaml",
"modules, algebraic types, pattern matching, effects, and dune",
("ocaml", "ocaml_source", "dune_ocaml"),
),
(
"language_clojure",
"Clojure",
"persistent data, macros, sequences, concurrency, and JVM interop",
("clojure", "clojure_source", "clj"),
),
(
"language_elixir",
"Elixir",
"BEAM processes, OTP, supervision, Mix, Phoenix, and distribution",
("elixir", "elixir_source", "mix_elixir"),
),
(
"language_erlang",
"Erlang",
"BEAM semantics, OTP behaviors, supervision, messaging, and resilience",
("erlang", "erlang_source", "beam_erlang"),
),
(
"language_scheme",
"Scheme",
"lexical scope, continuations, macros, interpreters, and reasoning",
("scheme", "scheme_source", "r7rs"),
),
(
"language_common_lisp",
"Common Lisp",
"CLOS, macros, conditions, packages, interactive work, and compilation",
("common_lisp", "common-lisp", "lisp"),
),
(
"language_prolog",
"Prolog",
"unification, backtracking, constraints, logic programs, and symbols",
("prolog", "prolog_source", "logic_programming"),
),
(
"language_groovy",
"Groovy",
"dynamic JVM semantics, closures, Gradle DSLs, tests, and Java interop",
("groovy", "groovy_source", "gradle_groovy"),
),
(
"language_fortran",
"Fortran",
"arrays, modules, numerical kernels, interoperability, and HPC",
("fortran", "fortran_source", "modern_fortran"),
),
(
"language_assembly",
"Assembly",
"instructions, calling conventions, registers, linking, and debugging",
("assembly", "asm", "machine_assembly"),
),
(
"language_cuda",
"CUDA",
"kernels, memory hierarchy, synchronization, streams, and profiling",
("cuda", "cuda_source", "cuda_kernel"),
),
(
"language_opencl",
"OpenCL",
"portable kernels, devices, memory spaces, synchronization, and interop",
("opencl", "opencl_source", "opencl_kernel"),
),
(
"language_webassembly",
"WebAssembly",
"modules, linear memory, WASI, components, toolchains, and embedding",
("webassembly", "wasm", "wasi"),
),
(
"language_zig",
"Zig",
"comptime, explicit allocation, build tooling, C interop, and systems",
("zig", "zig_source", "ziglang"),
),
(
"language_nim",
"Nim",
"macros, generics, memory management, native compilation, and C interop",
("nim", "nim_source", "nim_lang"),
),
(
"language_apex",
"Apex",
"Salesforce data, triggers, limits, testing, and deployment",
("apex", "salesforce_apex", "apex_source"),
),
(
"language_verilog",
"Verilog",
"RTL, simulation, synthesis, testbenches, timing, and interfaces",
("verilog", "verilog_source", "rtl_verilog"),
),
(
"language_systemverilog",
"SystemVerilog",
"RTL, assertions, interfaces, UVM, simulation, and synthesis",
("systemverilog", "system_verilog", "uvm"),
),
(
"language_vhdl",
"VHDL",
"typed RTL, simulation, synthesis, testbenches, and hardware packages",
("vhdl", "vhdl_source", "rtl_vhdl"),
),
(
"language_cobol",
"COBOL",
"divisions, records, files, transactions, mainframes, and modernization",
("cobol", "cobol_source", "mainframe_cobol"),
),
(
"language_ada",
"Ada",
"typing, contracts, tasks, packages, safety-critical systems, and SPARK",
("ada", "ada_source", "spark_ada"),
),
(
"language_pascal",
"Pascal and Object Pascal",
"structured programs, units, classes, Delphi, and native applications",
("pascal", "object_pascal", "delphi"),
),
(
"language_tcl",
"Tcl",
"commands, substitutions, event loops, Tk, embedding, and EDA",
("tcl", "tcl_source", "tcl_tk"),
),
(
"language_solidity",
"Solidity",
"EVM semantics, contracts, storage, testing, security, and upgrades",
("solidity", "solidity_source", "evm"),
),
(
"language_move",
"Move",
"resources, modules, bytecode, verification, and blockchain applications",
("move", "move_source", "move_language"),
),
(
"language_hcl",
"HashiCorp Configuration Language",
"infrastructure, expressions, modules, Terraform, and provider schemas",
("hcl", "terraform_hcl", "terraform"),
),
(
"language_nix",
"Nix",
"pure expressions, derivations, flakes, reproducible builds, and systems",
("nix", "nix_language", "nix_flakes"),
),
)
def _build_curated_language_expert_families(
specs: tuple[tuple[str, str, str, tuple[str, ...]], ...],
) -> tuple[tuple[str, str, frozenset[str]], ...]:
"""Validate and materialize the inherited curated prefix once."""
family_ids = tuple(spec[0] for spec in specs)
if len(family_ids) < 60 or len(set(family_ids)) != len(family_ids):
raise RuntimeError("language expert catalog is incomplete or duplicated")
if any(not family_id.startswith("language_") for family_id in family_ids):
raise RuntimeError("language expert family IDs require language_ prefix")
return tuple(
(
family_id,
(
f"{display_name} syntax and semantics, idioms, build/test/debug "
f"workflows, interoperability, security, performance, and {focus}"
),
frozenset((family_id, *aliases)),
)
for family_id, display_name, focus, aliases in specs
)
_CURATED_LANGUAGE_EXPERT_FAMILIES: Final = _build_curated_language_expert_families(
_LANGUAGE_EXPERT_SPECS
)
_CURATED_LANGUAGE_EXPERT_IDS: Final = tuple(
family_id
for family_id, _description, _claims in _CURATED_LANGUAGE_EXPERT_FAMILIES
)
NONE_LANGUAGE_EXPERT_INHERITED_CATALOG_SCHEMA: Final = (
"nnf.resynthesis.none_language_expert_catalog.v1"
)
NONE_LANGUAGE_EXPERT_INHERITED_PREFIX_COUNT: Final = len(
_CURATED_LANGUAGE_EXPERT_IDS
)
NONE_LANGUAGE_EXPERT_INHERITED_PREFIX_IDS_SHA256: Final = hashlib.sha256(
"\n".join(_CURATED_LANGUAGE_EXPERT_IDS).encode("utf-8")
).hexdigest()
if (
_CURATED_LANGUAGE_EXPERT_IDS
!= NATIVE_LANGUAGE_PACK_PREFIX_IDS[: len(_CURATED_LANGUAGE_EXPERT_IDS)]
):
raise RuntimeError("curated language experts are not the native catalog prefix")
_LINGUIST_METADATA_BY_FAMILY_ID: Final = {
family_id: (source_name, source_type)
for family_id, source_name, source_type in reversed(
LINGUIST_LANGUAGE_SOURCE_PACK_RECORDS
)
}
_ABILITY_IDS_BY_SOURCE_TYPE: Final = dict(
LANGUAGE_ABILITY_IDS_BY_SOURCE_TYPE
)
_NATIVE_PREFIX_ORDINAL_BY_ID: Final = {
family_id: ordinal
for ordinal, family_id in enumerate(NATIVE_LANGUAGE_PACK_PREFIX_IDS)
}
def _native_domain_ability_ids(family_id: str) -> frozenset[str]:
"""Return additive ability objectives for the frozen native graph row."""
ordinal = _NATIVE_PREFIX_ORDINAL_BY_ID.get(family_id)
if ordinal is None:
return frozenset()
if 173 <= ordinal < 197:
return frozenset(
{
"serialization_exchange",
"numerical_stability_units",
"chemical_structure_reaction_validation",
"scientific_data_mesh_geometry",
"simulation_boundary_conditions",
}
)
if 197 <= ordinal < 221:
return frozenset(
{
"serialization_exchange",
"systems_biology_simulation",
"clinical_regulatory_validation",
"workflow_provenance_orchestration",
}
)
if 221 <= ordinal < 245:
return frozenset(
{
"numerical_stability_units",
"probabilistic_inference_optimization",
"scientific_data_mesh_geometry",
"simulation_boundary_conditions",
"data_visualization_reporting",
}
)
if 245 <= ordinal < 269:
return frozenset(
{
"numerical_stability_units",
"probabilistic_inference_optimization",
"accelerator_parallel_lowering",
"hardware_hdl_verification",
"quantum_circuit_pulse_validation",
}
)
if 269 <= ordinal < 279:
return frozenset({"formal_proof_model_check"})
if 279 <= ordinal < 289:
return frozenset(
{
"workflow_provenance_orchestration",
"laboratory_robotics_control",
}
)
if 289 <= ordinal:
return frozenset(
{
"serialization_exchange",
"numerical_stability_units",
"laboratory_robotics_control",
"scientific_data_mesh_geometry",
"simulation_boundary_conditions",
}
)
return frozenset()
def _language_ability_ids(
family_id: str,
source_type: str,
) -> tuple[str, ...]:
ability_ids = frozenset(
_ABILITY_IDS_BY_SOURCE_TYPE.get(
source_type,
_ABILITY_IDS_BY_SOURCE_TYPE["programming"],
)
).union(_native_domain_ability_ids(family_id))
return tuple(
ability_id
for ability_id in LANGUAGE_ABILITY_AXIS_IDS
if ability_id in ability_ids
)
def _recovered_language_family(
family_id: str,
) -> tuple[str, str, frozenset[str]]:
metadata = _LINGUIST_METADATA_BY_FAMILY_ID.get(family_id)
if metadata is None:
source_name = family_id.removeprefix("language_").replace("_", " ")
source_type = "programming"
provenance = "the immutable native Resynthesis language graph"
else:
source_name, source_type = metadata
provenance = "the pinned GitHub Linguist source snapshot"
ability_ids = _language_ability_ids(family_id, source_type)
return (
family_id,
(
f"{source_name} {source_type} syntax and semantics, parsing, "
"verification, implementation, interoperability, migration, "
f"and production operation; identity recovered from {provenance}"
),
frozenset((family_id, *ability_ids)),
)
_CURATED_LANGUAGE_FAMILY_BY_ID: Final = {
family_id: (family_id, description, claims)
for family_id, description, claims in _CURATED_LANGUAGE_EXPERT_FAMILIES
}
NONE_LANGUAGE_EXPERT_FAMILIES: Final = tuple(
_CURATED_LANGUAGE_FAMILY_BY_ID.get(
family_id,
_recovered_language_family(family_id),
)
for family_id in BROAD_LANGUAGE_PACK_IDS
)
NONE_LANGUAGE_EXPERT_ABILITY_ASSIGNMENTS: Final = tuple(
(
family_id,
_language_ability_ids(
family_id,
_LINGUIST_METADATA_BY_FAMILY_ID.get(
family_id,
("", "programming"),
)[1],
),
)
for family_id in BROAD_LANGUAGE_PACK_IDS
)
NONE_LANGUAGE_EXPERT_IDS_SHA256: Final = hashlib.sha256(
"\n".join(
family_id
for family_id, _description, _claims in NONE_LANGUAGE_EXPERT_FAMILIES
).encode("utf-8")
).hexdigest()
NONE_LANGUAGE_EXPERT_ABILITY_ASSIGNMENTS_SHA256: Final = hashlib.sha256(
"\n".join(
f"{family_id}:{','.join(ability_ids)}"
for family_id, ability_ids in NONE_LANGUAGE_EXPERT_ABILITY_ASSIGNMENTS
).encode("utf-8")
).hexdigest()
if (
len(NONE_LANGUAGE_EXPERT_FAMILIES) != 936
or NONE_LANGUAGE_EXPERT_IDS_SHA256 != BROAD_LANGUAGE_PACK_IDS_SHA256
or len({row[0] for row in NONE_LANGUAGE_EXPERT_FAMILIES})
!= len(NONE_LANGUAGE_EXPERT_FAMILIES)
or NONE_LANGUAGE_EXPERT_FAMILIES[: len(_CURATED_LANGUAGE_EXPERT_FAMILIES)]
!= _CURATED_LANGUAGE_EXPERT_FAMILIES
or tuple(row[0] for row in NONE_LANGUAGE_EXPERT_ABILITY_ASSIGNMENTS)
!= BROAD_LANGUAGE_PACK_IDS
):
raise RuntimeError("broad language expert catalog identity is invalid")
|