Add diagnostics system and improve type-based mapping detection#57
Merged
Add diagnostics system and improve type-based mapping detection#57
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
transpiler/codegen/diagnostics.pywithTranspilerDiagnostics,Diagnostic, andDiagnosticSeverityclassesCodeGenerationContextandSol2TstranspilerType-Based Mapping Detection
statement.py: Replaced name-based heuristics with type registry lookups for mapping detectionvar_typesandcurrent_state_varsto determine if a variable is a mappingexpression.py: Improved struct field mapping detection usingknown_struct_fieldsregistryInterface Type Handling
type_converter.py: Interface types now generate as their actual names instead of collapsing toanycontracts_referencedfor import generationtype_system/registry.py: Addedinterface_methodstracking to record method signaturesABI Type Inference Refactoring
expression.py: Delegated ABI type conversion to newAbiTypeInfererclassYul Transpiler Enhancements
transpiler/codegen/yul.pywith improved parsing and code generationTesting
Notable Implementation Details
CodeGenerationContext.diagnosticsproperty creates aTranspilerDiagnosticsinstance on first accessSol2Ts._emit_ast_diagnostics()scans the AST to detect and report unsupported constructs before code generationvar_typesandknown_struct_fieldsfor accurate type informationBackward 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