Skip to content

Implement Type System#8

Open
singlerr wants to merge 9 commits intomasterfrom
ts
Open

Implement Type System#8
singlerr wants to merge 9 commits intomasterfrom
ts

Conversation

@singlerr
Copy link
Copy Markdown
Owner

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

@singlerr singlerr added this to the Implement Type System milestone Feb 23, 2026
@singlerr singlerr self-assigned this Feb 23, 2026
Copilot AI review requested due to automatic review settings February 23, 2026 03:18
@singlerr singlerr added the enhancement New feature or request label Feb 23, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Luxque Luxque requested review from Luxque and removed request for Luxque February 26, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants