Skip to content

refactor: ARCH-001 internal packages + 12/18 coverage ≥80% + 13 panics→errors#72

Merged
kolkov merged 26 commits into
mainfrom
refactor/arch-001-msl-internal
May 7, 2026
Merged

refactor: ARCH-001 internal packages + 12/18 coverage ≥80% + 13 panics→errors#72
kolkov merged 26 commits into
mainfrom
refactor/arch-001-msl-internal

Conversation

@kolkov

@kolkov kolkov commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

ARCH-001: Enterprise internal packages refactoring + test coverage + error handling.

Architecture (DXIL pattern applied to all backends)

  • glsl/internal/codegen/ (9 files)
  • msl/internal/codegen/ (10 files)
  • hlsl/internal/codegen/ + shared namer in internal/backend/
  • spirv/internal/codegen/ (5 files)
  • wgsl/internal/parser/ + internal/lower/
  • ir/internal/registry/ extracted
  • internal/textutil/ — shared IndentWriter (DRY 3×)
  • Public API: real types, not aliases. go doc shows full struct definitions.

Test coverage (12/18 packages ≥80%)

| 100% | textutil, dxil/module |
| 83-97% | backend, mem2reg, dce, parser, bitcode, viewid, sroa, ir, container, glsl |

Error handling

  • 13 panics → error returns (glsl, hlsl, spirv)
  • 2 nilerr fixes (spirv — silently swallowed errors)
  • Unsupported stage validation (mesh/task → clear error)
  • 11 dead functions removed, 929 LOC deleted

Metrics (unchanged)

  • TestDxilValSummary: 161/170
  • TestDxilValGGProduction: 61/61 (100%)
  • TestRustReference: 100%
  • golangci-lint: 0 unused/unparam/nilerr issues

Test plan

  • go build ./...
  • All backend tests pass
  • TestRustReference — 100%
  • TestDxilValGGProduction — 61/61
  • golangci-lint — clean (nestif pre-existing)
  • CI green

kolkov added 24 commits May 7, 2026 14:57
…n (ARCH-001)

All codegen moved to glsl/internal/codegen/ via git mv. Thin public
wrapper at glsl/glsl.go with type aliases (zero overhead). Public API
unchanged: Compile, Options, DefaultOptions, TranslationInfo, BindingMapKey.
Writer and Features types now internal. 0 lint issues, all tests pass.
… (ARCH-001)

All codegen moved to msl/internal/codegen/ via git mv. Thin public
wrapper at msl/msl.go with type aliases (zero overhead). Public API
unchanged: Compile, CompileWithPipeline, Options, DefaultOptions,
BoundsCheckPolicies, VertexFormat constants. 0 lint issues, all tests pass.
…n (ARCH-001)

All codegen moved to hlsl/internal/codegen/ via git mv. Shared namer
logic (NeedsTrailingUnderscore, keyword maps) moved to internal/backend/
to avoid circular imports — both hlsl/internal/codegen and dxil/internal/emit
import from shared location. Public API unchanged via type aliases.
0 lint issues, all tests pass including DXIL.
…rn (ARCH-001)

All codegen moved to spirv/internal/codegen/ via git mv. Thin public
wrapper at spirv/spirv.go with type aliases. Public API unchanged:
Backend, Options, DefaultOptions, ModuleBuilder, capabilities, opcodes.
SPIR-V val 172/172 (100%). 0 lint issues, all tests pass.
…/msl (ARCH-001 Phase 0)

internal/textutil/textutil.go with IndentWriter (WriteLine, WriteIndent,
PushIndent, PopIndent). Embedded in all 3 text backend Writers. Eliminates
3× duplication of indent/output methods. 5 unit tests. 0 lint issues.
…attern (ARCH-001)

glsl: 8/8 aliases → real types + toCodegenOptions/fromCodegenTranslationInfo
msl: 22/22 aliases → real types + conversion functions
hlsl: 15/16 aliases → real types (Writer stays alias — implementation type)
spirv: 4/30 aliases → real types (implementation types stay — tightly coupled)
go doc now shows full struct definitions. 0 lint issues, all tests pass.
…rn (ARCH-001 Phase 2a)

parser/ contains lexer, token, parser, ast, deporder, errors.
lower/ contains the 16K LOC lowerer (imports parser for AST types).
Public API: REAL types (Module, Lexer, Tokens, Parser, ParseError, Span).
No type aliases. go doc shows full struct definitions.
0 lint issues, all tests pass.
Registry moved to module-level internal/registry/ (not ir/internal/)
because wgsl/internal/lower/ needs access and Go internal visibility
restricts ir/internal/ to ir/ subtree only. compact.go and validate.go
stay in ir/ — circular import prevents moving. 0 lint issues.
5 test files, 5139 LOC. Covers: compile integration (100 tests),
statements (22), writer utils (24), features (33), types (28).
Table-driven, named subtests, real WGSL→GLSL output verification.
1341 LOC. Covers: Version.Less, BoundsCheckPolicies, blockEndsWithReturn,
builtinInputAttribute (19 builtins), resolveInterpolation, compile
integration (workgroup init, dual-source blend, storage buffers, etc.).
writeHelperFunctions 12%→100%, resolveTypeInner 18%→tested,
scanBlockForStages 16%→91%, tryConstEvalUnary 23%→100%,
writeUniformBlock 28%→improved, plus writeCallResult, writeAtomicResult,
formatConstResult, computeBlockNames, expandBoolVectorOp all from 0%.
…OV-001)

Integration tests via compileWGSL: math functions, expressions, control
flow, textures, atomics, pipeline constants, vertex pulling, bounds
checking. 3919 LOC new tests. Remaining gap: ray queries, subgroups,
external textures — specialized WGSL extensions.
…packing

hlsl_namer_test: EndsWithDigit, IsASCIIAlphanumeric, NeedsTrailingUnderscore (44 cases).
interface_order_test: MemberInterfaceLess, SortedArgIndices, SortFlatBindings.
sig_pack_binding_test: componentDimensions, SigElementInfoForBinding (13 cases),
PackStructMembers, PackSignatureElements edge cases.
…n, float16

60+ tests: type system dedup, instruction constructors, aggregate/undef
constants, global variables, float32ToF16Bits (12 cases), full
serialization coverage (all instruction kinds, branches, phi, atomics,
GEP, value symtab, function decls). Enterprise quality.
analysis_test: scalarSet, componentTaint, giveUp fallback, expandTaint.
expressions_test: computeTaint for 15+ expression kinds, merge ops.
walker_test: walkStatement (if/switch/loop/block), handleStore,
rootLocalVar, resolveFlatRange. All tests verify actual scalar dataflow.
process_overrides: literalToFloat, evalBinary/Unary, cloneModule,
filterEmitsInBlock, overrideRemapExprHandles (18 kinds). resolve:
Load/Access/Splay/Swizzle type resolution, modf/frexp struct finding,
atomicResult, workGroupUniformLoad. inline: blockContainsReturn,
shouldAliasArgType. Core: StorageFormat, TypeSize, Validate errors.
DCE: 27 tests — dead loop, side-effect roots, visitExprHandles (14 kinds),
stmtHasSideEffects (22 types), shared consumer tracking.
mem2reg: 17 tests — Phase B phi, loop disqualification, collectStores,
classifyStatements, promoteBlocks recursion, isBoolLocal.
SROA: 19 tests — nested stores, resolveStructLocal, allMembersDecomposable,
classify with control flow recursion, Compose-store.
Integration: entry points, math, textures, storage buffers, derivatives.
Unit: binaryOpStr, scalarKindToHLSL, continueCtx, mathFunction dispatch.
Types: hlslTypeSize, isDynamicallySized, struct padding, matCx2.
Advanced: 8 storage texture formats, interpolation, force loop bounding.
Remaining gap: ray tracing, subgroups, external textures — specialized IR.
Parser: overrides, bitcast, increment/decrement, 11 assign ops, all type
specs (atomic, sampler, 16 textures), DependencyOrder (12 cases), error
recovery, Token.String, SourceError formatting, AST Pos() (33 nodes).
Lower: overrides, globals, control flow, 30+ texture ops, atomics (10),
barriers, constant folding (40+ math builtins), type constructors,
abstract concretization, entry points, error cases, interpolation.
StorageFormatToImageFormat (36 formats), float32ToF16Bits edge cases,
ModuleBuilder methods (12), atomicOpcode (12 ops), 50+ WGSL compilation
tests with SPIR-V binary assertions (OpSelect, OpKill, derivatives,
pack/unpack polyfills, interpolation, barriers, textures, builtins).
Remaining gap: subgroups, ray queries — WGSL extensions not supported.
GLSL: exitLoop/exitSwitch return error instead of panic. writeEntryPoint
rejects StageMesh/StageTask with clear error. 6 unsupported feature tests
with hand-crafted IR (ray query, mesh/task shader, binding array).
MSL: writeEntryPoint rejects unsupported stages. 2 unsupported tests.
HLSL: exitLoop/exitSwitch return error instead of panic (2 panics).
SPIR-V: emitScalarType, addressSpaceToStorageClass, emitScalarConstant,
resolveScalarType, findTypeHandleByID, resolveTypeResolution,
emitInlineType + cascading caller updates (~200 sites). 8 error-path
tests. 0 panics remaining in hlsl, 4 remaining in spirv ray_query
(deep signature cascade, separate task).
…2 swallowed errors fixed

Removed 11 unused functions from wgsl/internal/lower/lower.go.
Fixed 5 unused params (prefix _). Fixed 3 unused returns.
Fixed 2 nilerr in spirv/backend.go (silently swallowing errors).
0 unused/unparam/nilerr lint issues.
@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

kolkov added 2 commits May 7, 2026 21:36
Exclusion paths updated after git mv: wgsl/parser.go → wgsl/internal/parser/,
wgsl/lower.go → wgsl/internal/lower/, msl/ → msl/internal/codegen/,
hlsl/ → hlsl/internal/codegen/, etc. Added internal/registry and
internal/backend/hlsl_keywords exclusions. 0 lint issues.
@kolkov kolkov merged commit bca2392 into main May 7, 2026
11 checks passed
@kolkov kolkov deleted the refactor/arch-001-msl-internal branch May 8, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant