Skip to content

Add diagnostics system and improve type-based mapping detection#57

Merged
sudo-owen merged 1 commit intomainfrom
claude/analyze-transpiler-flow-63vi9
Feb 6, 2026
Merged

Add diagnostics system and improve type-based mapping detection#57
sudo-owen merged 1 commit intomainfrom
claude/analyze-transpiler-flow-63vi9

Conversation

@sudo-owen
Copy link
Collaborator

Summary

This PR introduces a comprehensive diagnostics/warning system for the transpiler and improves type information usage throughout code generation. The changes help developers understand simulation fidelity gaps by reporting unsupported Solidity constructs that were skipped or degraded during transpilation.

Key Changes

Diagnostics System (New)

  • New module: transpiler/codegen/diagnostics.py with TranspilerDiagnostics, Diagnostic, and DiagnosticSeverity classes
  • Collects warnings about unsupported constructs (modifiers, try/catch, receive/fallback, function pointers, Yul parse errors)
  • Provides structured diagnostic reporting with severity levels (WARNING, INFO)
  • Generates summary reports grouped by construct type
  • Integrated into CodeGenerationContext and Sol2Ts transpiler

Type-Based Mapping Detection

  • statement.py: Replaced name-based heuristics with type registry lookups for mapping detection
    • Now checks var_types and current_state_vars to determine if a variable is a mapping
    • More accurate handling of struct field access with known mapping types
  • expression.py: Improved struct field mapping detection using known_struct_fields registry
    • Resolves parent struct types and checks field information
    • Properly distinguishes between arrays and mappings

Interface Type Handling

  • type_converter.py: Interface types now generate as their actual names instead of collapsing to any
    • Tracks interface references in contracts_referenced for import generation
  • type_system/registry.py: Added interface_methods tracking to record method signatures
    • Enables proper TypeScript interface generation with method signatures

ABI Type Inference Refactoring

  • expression.py: Delegated ABI type conversion to new AbiTypeInferer class
    • Cleaner separation of concerns
    • Rebuilds inferer per function to reflect current context state

Yul Transpiler Enhancements

  • Significantly expanded transpiler/codegen/yul.py with improved parsing and code generation
  • Better handling of storage operations, arithmetic, bitwise, and comparison operations
  • Support for control flow (if, for, switch/case)
  • Comprehensive test coverage added

Testing

  • Added 60+ new test cases covering:
    • Yul transpiler functionality (tokenizer, parser, code generation)
    • Interface type generation and method tracking
    • Mapping detection from type information
    • Diagnostics collection and reporting
    • Struct default values
    • Operator precedence and type casts

Notable Implementation Details

  1. Lazy Diagnostics Initialization: CodeGenerationContext.diagnostics property creates a TranspilerDiagnostics instance on first access
  2. AST Scanning: Sol2Ts._emit_ast_diagnostics() scans the AST to detect and report unsupported constructs before code generation
  3. Type Registry Integration: Mapping detection now leverages the type registry's var_types and known_struct_fields for accurate type information
  4. Grouped Reporting: Diagnostics summary groups warnings by construct type for better readability

Backward Compatibility

All changes are additive or improve existing behavior without breaking changes. The diagnostics system is optional and non-blocking.

https://claude.ai/code/session_01GtZHJWCpU7GiocausVWvax

Major changes:
- Replace regex-based Yul transpiler with proper recursive descent parser
  (tokenizer + parser + AST-based code generation) supporting nested
  if/for/switch, arbitrary expression nesting, and all arithmetic/bitwise ops
- Generate TypeScript interfaces from Solidity interfaces instead of collapsing
  to `any`, with method signatures preserved
- Replace hard-coded field name sets in expression.py with type-registry-driven
  inference for numeric key mapping detection
- Replace variable name heuristic for mapping detection with var_types lookups
- Add diagnostic/warning system that reports skipped constructs (modifiers,
  try/catch, receive/fallback) with source locations
- Extract ABI type inference delegation from ExpressionGenerator to AbiTypeInferer
- Add 43 new unit tests covering Yul tokenizer/parser/transpiler, interface
  generation, mapping detection, diagnostics, struct defaults, operator
  precedence, and type casts (51 total, up from 8)

https://claude.ai/code/session_01GtZHJWCpU7GiocausVWvax
@sudo-owen sudo-owen merged commit 7e2487d into main Feb 6, 2026
1 check passed
@sudo-owen sudo-owen deleted the claude/analyze-transpiler-flow-63vi9 branch February 6, 2026 18:07
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.

2 participants