mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
[Tolk] throw interrupts control flow; never type
In FunC (and in Tolk before) throwing an exception is just
calling a built-in function:
> throw 123; // actually, __throw(123)
Since it's a regular function, the compiler was not aware
that execution will stop, and all following code is unreachable.
For instance, `throw` in the end on function needed to be
followed by `return` statement.
Now, `throw` interrupts control flow, all statements after
it are considered unreachable. At IR level, code Ops are
also not produced.
This works because a built-in __throw() now has `never` type.
It can also be applied to custom functions:
> fun alwaysThrow(): never { throw 123; }
The code after alwaysThrow() call will also be unreachable.
This commit is contained in:
parent
7bcb8b895f
commit
ef0328837f
10 changed files with 227 additions and 25 deletions
|
|
@ -1088,6 +1088,7 @@ void define_builtins() {
|
|||
TypePtr Slice = TypeDataSlice::create();
|
||||
TypePtr Builder = TypeDataBuilder::create();
|
||||
TypePtr Tuple = TypeDataTuple::create();
|
||||
TypePtr Never = TypeDataNever::create();
|
||||
|
||||
std::vector<GenericsDeclaration::GenericsItem> itemsT;
|
||||
itemsT.emplace_back("T");
|
||||
|
|
@ -1201,10 +1202,10 @@ void define_builtins() {
|
|||
define_builtin_func("__isNull", {typeT}, Bool, declGenericT,
|
||||
compile_is_null,
|
||||
FunctionData::flagMarkedAsPure);
|
||||
define_builtin_func("__throw", ParamsInt1, Unit, nullptr,
|
||||
define_builtin_func("__throw", ParamsInt1, Never, nullptr,
|
||||
compile_throw,
|
||||
0);
|
||||
define_builtin_func("__throw_arg", {typeT, Int}, Unit, declGenericT,
|
||||
define_builtin_func("__throw_arg", {typeT, Int}, Never, declGenericT,
|
||||
compile_throw_arg,
|
||||
0);
|
||||
define_builtin_func("__throw_if_unless", ParamsInt3, Unit, nullptr,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue