mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
[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)
This commit is contained in:
parent
3540424aa1
commit
799e2d1265
101 changed files with 5402 additions and 2713 deletions
|
@ -25,25 +25,33 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "src-file.h"
|
||||
#include "fwd-declarations.h"
|
||||
#include <string>
|
||||
|
||||
namespace tolk {
|
||||
|
||||
AllSrcFiles pipeline_discover_and_parse_sources(const std::string& stdlib_filename, const std::string& entrypoint_filename);
|
||||
void pipeline_discover_and_parse_sources(const std::string& stdlib_filename, const std::string& entrypoint_filename);
|
||||
|
||||
void pipeline_register_global_symbols(const AllSrcFiles&);
|
||||
void pipeline_resolve_identifiers_and_assign_symbols(const AllSrcFiles&);
|
||||
void pipeline_calculate_rvalue_lvalue(const AllSrcFiles&);
|
||||
void pipeline_detect_unreachable_statements(const AllSrcFiles&);
|
||||
void pipeline_infer_and_check_types(const AllSrcFiles&);
|
||||
void pipeline_refine_lvalue_for_mutate_arguments(const AllSrcFiles&);
|
||||
void pipeline_check_rvalue_lvalue(const AllSrcFiles&);
|
||||
void pipeline_check_pure_impure_operations(const AllSrcFiles&);
|
||||
void pipeline_constant_folding(const AllSrcFiles&);
|
||||
void pipeline_convert_ast_to_legacy_Expr_Op(const AllSrcFiles&);
|
||||
void pipeline_register_global_symbols();
|
||||
void pipeline_resolve_identifiers_and_assign_symbols();
|
||||
void pipeline_calculate_rvalue_lvalue();
|
||||
void pipeline_detect_unreachable_statements();
|
||||
void pipeline_infer_types_and_calls_and_fields();
|
||||
void pipeline_refine_lvalue_for_mutate_arguments();
|
||||
void pipeline_check_rvalue_lvalue();
|
||||
void pipeline_check_pure_impure_operations();
|
||||
void pipeline_constant_folding();
|
||||
void pipeline_convert_ast_to_legacy_Expr_Op();
|
||||
|
||||
void pipeline_find_unused_symbols();
|
||||
void pipeline_generate_fif_output_to_std_cout(const AllSrcFiles&);
|
||||
void pipeline_generate_fif_output_to_std_cout();
|
||||
|
||||
// these pipes also can be called per-function individually
|
||||
// they are called for instantiated generics functions, when `f<T>` is deeply cloned as `f<int>`
|
||||
void pipeline_resolve_identifiers_and_assign_symbols(const FunctionData*);
|
||||
void pipeline_calculate_rvalue_lvalue(const FunctionData*);
|
||||
void pipeline_detect_unreachable_statements(const FunctionData*);
|
||||
void pipeline_infer_types_and_calls_and_fields(const FunctionData*);
|
||||
|
||||
|
||||
} // namespace tolk
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue