Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements a type system for the transpiler by reconstructing the AST model and introducing type inference capabilities using a unification algorithm. The changes replace the existing simplified type system with a more sophisticated approach based on Hindley-Milner type inference.
Changes:
- Introduced new type system infrastructure with type variables, constraints, and unification
- Added efficient-and-flexible array (ENA) data structure implementation for managing type variables
- Integrated supporting data structures (btree, hamt, vec) for type system operations
Reviewed changes
Copilot reviewed 35 out of 38 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/transpiler/type/inference.h | Defines error types for type inference operations |
| src/transpiler/type/base.h | Core type system structures including types, constraints, and inference state |
| src/transpiler/type.h | Removed old simplified type system |
| src/transpiler/type.c | Removed old type system implementation |
| src/transpiler/symrec.h | Updated to reference new common types header and reformatted |
| src/transpiler/symrec.c | Removed symbol table and type management functions |
| src/transpiler/ena/*.{c,h} | Added unification table implementation for type inference |
| src/transpiler/data/vec/*.{c,h} | Added dynamic vector data structure |
| src/transpiler/data/hamt/*.{c,h} | Added hash array-mapped trie implementation |
| src/transpiler/data/btree/*.{c,h} | Added B-tree implementation |
| src/transpiler/data/Makefile | Build configuration for data structures |
| src/transpiler/ast_typing.{h,c} | Removed old type compatibility checking logic |
| src/transpiler/ast_sqz.h | Updated includes and reformatted |
| src/transpiler/ast_sem.h | Updated includes and reformatted |
| src/transpiler/ast.h | Added node_id type and reformatted |
| src/transpiler/Makefile | Updated to include ena and data subdirectories |
Comments suppressed due to low confidence (4)
src/transpiler/type/inference.h:1
- The enum value 'OK' is ambiguous and may conflict with common system macros. Consider renaming to 'TYPE_ERROR_OK' or 'TYPE_OK' for clarity and to avoid potential naming collisions.
src/transpiler/type/base.h:1 - The enum value 'UNEXPECTED_FUN' is duplicated between both 'provenance_tag' (line 54) and 'type_error_tag' (line 104). This creates ambiguity. Consider using unique prefixes like 'PROVENANCE_UNEXPECTED_FUN' and 'TYPE_ERROR_UNEXPECTED_FUN' to distinguish them.
src/transpiler/symrec.c:1 - The file now only contains includes with no function implementations. If all implementations have been removed, consider removing this file entirely rather than leaving an empty implementation file.
src/transpiler/data/hamt/src/uh.c:1 - Corrected spelling of 'importatnt' to 'important'.
#include "uh.h"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Reconstruct AST model
Current AST lacks sufficient information since it tries to cover all syntax. This was mainly caused by limitation of YACC/LEX grammar syntax.
We must transform AST model to be more suitable to type system
#6
Implement Type inference using unification algorithm
See Making a language tutorial