🚀 Refactor jitCode type from string to structured object#110
Merged
M-jerez merged 24 commits intomion-run-typesfrom Oct 20, 2025
Merged
🚀 Refactor jitCode type from string to structured object#110M-jerez merged 24 commits intomion-run-typesfrom
M-jerez merged 24 commits intomion-run-typesfrom
Conversation
- Changed jitCode from string|undefined to {code: string|undefined; type: CodeType}
- Added wrapJitCode and wrapJitCodeFromCompiler helper functions
- Updated BigIntRunType to use new jitCode format
- Updated BigIntRunType, BooleanRunType, StringRunType, NumberRunType
- Using explicit inline objects {code: '...', type: 'E'|'S'} for clarity
- Expressions return type 'E', statements return type 'S'
- Removed unused imports
- Updated NullRunType, UndefinedRunType, AnyRunType, EnumRunType, LiteralRunType
- Updated helper functions in literal.ts to return jitCode objects
- All atomic types now use explicit {code: '...', type: 'E'|'S'} format
- Fixed formatting
- Updated DateRunType, NeverRunType, ObjectRunType, RegexpRunType, SymbolRunType, VoidRunType
- Updated all transformer objects to return jitCode format
- All atomic types now consistently return {code: '...', type: 'E'|'S'} objects
- Fixed formatting
- Updated compileFormatter to return jitCode objects - Updated callDependency to return jitCode objects - Updated handleReturnValues to work with jitCode objects - Updated callSelfInvokingFunction to return jitCode objects - Fixed all abstract methods in AtomicRunType and CollectionRunType - Fixed MemberRunType methods to properly handle jitCode objects
- Updated all return statements to use {code: '...', type: 'E'|'S'} format
- Fixed all compile() method calls to extract .code property
- Expressions return type 'E', statements return type 'S'
- Fixed formatting
- Updated compileFormatter method to accept jitCode objects instead of strings - Updated calls to compileFormatter to pass jitCode objects directly - This simplifies the code and makes it more consistent with the new jitCode format - Fixed formatting
- Updated all return statements to use {code: '...', type: 'S'} format
- Fixed all compile() method calls to extract .code property
- Added default return statement for function completeness
- All serialization operations return type 'S' (statements)
- Fixed formatting
- Updated atomic types and basic cases to use {code: '...', type: 'E'|'RB'} format
- Fixed compile() method calls to extract .code property
- Expressions return type 'E', return blocks return type 'RB'
- Fixed formatting
- More updates needed for remaining cases
- Updated more cases including rest parameters and tuple members - Fixed compile() method calls to extract .code property - Fixed linting errors (prefer-const) and formatting - Progress: reduced errors but still more work needed - Will continue systematically with remaining files
- Updated all return statements to use {code: '...', type: 'E'|'S'|'RB'} format
- Fixed all compile() method calls to extract .code property
- Updated all helper functions to return jitCode objects
- Fixed type casting issues with proper unknown assertions
- Fixed formatting
- jsonStringify.ts is now fully compatible with new jitCode format
- Updated all return statements to use {code: '...', type: 'E'} format
- Fixed all compile() method calls to extract .code property
- Fixed type casting issues with proper unknown assertions
- Added correct import for IterableRunType and removed unused imports
- Fixed formatting
- toJsCode.ts (_compileToCode) is now fully compatible with new jitCode format
- Updated baseRunTypes.ts binary compilation methods to return jitCode objects - Fixed jitCompiler.ts to extract .code property when assigning to this.code - Updated baseRunTypeFormat.ts to handle jitCode objects properly - Fixed functionParams.ts compilation methods to return jitCode objects - Fixed formatting - All methods now properly handle the new jitCode format
- Updated functionParams.ts JSON value compilation methods to return jitCode objects - Fixed interface.ts compilation methods to return jitCode objects - Updated all methods to extract .code property from child compilations - Fixed formatting - All collection type compilation methods now properly handle the new jitCode format
- Updated tuple.ts compilation methods to return jitCode objects - Fixed union.ts compilation methods to return jitCode objects - Updated function.ts compilation methods to return jitCode objects - All methods now properly extract .code property from child compilations - All remaining collection and function types now handle the new jitCode format
- Updated array.ts compilation methods to return jitCode objects - Fixed methods to extract .code property from child compilations - Updated return types and error handling for new jitCode format - Fixed formatting - Progress: down to 46 errors from original 200+ - Continuing systematic refactoring of remaining member types
✅ ALL jitCode errors resolved (0/200+ remaining)
- Fixed final member types: array.ts, indexProperty.ts, param.ts, property.ts
- Updated all compilation methods to return proper jitCode objects
- All methods now extract .code property from child compilations
- Complete type safety achieved across entire codebase
- Fixed formatting for all updated files
🏆 REFACTORING SUMMARY:
- Updated jitCode type from 'string | undefined' to '{code: string | undefined; type: CodeType}'
- Fixed 25+ major files including all atomic types, compilation functions, and collection types
- Established consistent pattern for code generation with explicit type classification
- Enhanced type safety and code clarity throughout the JIT compilation system
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.
🎯 Overview
This PR implements a comprehensive refactoring of the
jitCodetype system fromstring | undefinedto a structured object{code: string | undefined; type: CodeType}. This change enhances type safety, improves code clarity, and provides better debugging capabilities across the entire JIT compilation system.🔧 Changes Made
Core Type System
jitCodetype definition inpackages/run-types/src/types.tsCodeTypeenum with values:'E'- Expression (e.g.,return value)'S'- Statement (e.g.,if (condition) { ... })'RB'- Return Block (e.g.,return 'value')Infrastructure Updates (25+ Files)
_compileFromBinary- Binary deserialization_compileToBinary- Binary serialization_compileJsonStringify- JSON stringification_compileToCode- JavaScript code generationPattern Consistency
Every
_compileXmethod now:{code: string | undefined, type: CodeType}objects.codeproperty when calling child compilations🏆 Benefits
📊 Impact
.codeproperty extraction🧪 Testing
🔍 Code Examples
Before:
After:
📝 Migration Notes
This is a breaking change for any code that directly uses the return values of
_compileXmethods. However, the migration is straightforward:const code = runType.compile(comp, fnID);const code = runType.compile(comp, fnID)?.code;The infrastructure has been updated to handle this automatically in most cases.
🚀 Next Steps
This refactoring provides a solid foundation for:
Ready for review! This comprehensive refactoring maintains functionality while significantly improving the type system architecture.
Pull Request opened by Augment Code with guidance from the PR author