1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-12 11:12:16 +00:00
ton/tolk
tolk-vm 799e2d1265
[Tolk] Rewrite the type system from Hindley-Milner to static typing
FunC's (and Tolk's before this PR) type system is based on Hindley-Milner.
This is a common approach for functional languages, where
types are inferred from usage through unification.
As a result, type declarations are not necessary:
() f(a,b) { return a+b; } // a and b now int, since `+` (int, int)

While this approach works for now, problems arise with the introduction
of new types like bool, where `!x` must handle both int and bool.
It will also become incompatible with int32 and other strict integers.
This will clash with structure methods, struggle with proper generics,
and become entirely impractical for union types.

This PR completely rewrites the type system targeting the future.
1) type of any expression is inferred and never changed
2) this is available because dependent expressions already inferred
3) forall completely removed, generic functions introduced
   (they work like template functions actually, instantiated while inferring)
4) instantiation `<...>` syntax, example: `t.tupleAt<int>(0)`
5) `as` keyword, for example `t.tupleAt(0) as int`
6) methods binding is done along with type inferring, not before
   ("before", as worked previously, was always a wrong approach)
2025-01-15 15:38:43 +03:00
..
abscode.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
analyzer.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
asmops.cpp [Tolk] AST-based semantic analysis, get rid of Expr 2025-01-13 20:28:44 +07:00
ast-from-tokens.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
ast-from-tokens.h [Tolk] AST-based semantic analysis, get rid of Expr 2025-01-13 20:28:44 +07:00
ast-replacer.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
ast-replicator.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
ast-stringifier.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
ast-visitor.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
ast.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
ast.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
builtins.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
CMakeLists.txt [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
codegen.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
compiler-state.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
compiler-state.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
constant-evaluator.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
constant-evaluator.h [Tolk] AST-based semantic analysis, get rid of Expr 2025-01-13 20:28:44 +07:00
fwd-declarations.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
generics-helpers.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
generics-helpers.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
lexer.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
lexer.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
optimize.cpp [Tolk] Embedded stdlib.tolk, CompilerState, strict includes 2024-11-02 01:33:08 +04:00
pipe-ast-to-legacy.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-calc-rvalue-lvalue.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-check-pure-impure.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-check-rvalue-lvalue.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-constant-folding.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-detect-unreachable.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-discover-parse-sources.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-find-unused-symbols.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-generate-fif-output.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-infer-types-and-calls.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-refine-lvalue-for-mutate.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-register-symbols.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipe-resolve-identifiers.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
pipeline.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
platform-utils.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
src-file.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
src-file.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
stack-transform.cpp [Tolk] Initial commit of TOLK Language: fork all sources from FunC 2024-11-02 01:33:08 +04:00
symtable.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
symtable.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
tolk-main.cpp [Tolk] Completely rework stdlib: multiple files and renaming 2024-11-02 03:44:13 +04:00
tolk-version.h [Tolk] v0.6 syntax: fun, import, var, types on the right, etc. 2024-11-02 03:44:13 +04:00
tolk-wasm.cpp [Tolk] Completely rework stdlib: multiple files and renaming 2024-11-02 03:44:13 +04:00
tolk.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
tolk.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
type-system.cpp [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00
type-system.h [Tolk] Rewrite the type system from Hindley-Milner to static typing 2025-01-15 15:38:43 +03:00