Merge pull request #279 from aeternity/optimize_calldata_generation
Improve call data encoding times by 35%
This commit is contained in:
commit
1fee306daa
@ -157,14 +157,16 @@ string_to_code(ContractString, Options) ->
|
|||||||
aevm ->
|
aevm ->
|
||||||
Icode = ast_to_icode(TypedAst, Options),
|
Icode = ast_to_icode(TypedAst, Options),
|
||||||
pp_icode(Icode, Options),
|
pp_icode(Icode, Options),
|
||||||
#{ icode => Icode,
|
#{ icode => Icode
|
||||||
typed_ast => TypedAst,
|
, typed_ast => TypedAst
|
||||||
type_env => TypeEnv};
|
, type_env => TypeEnv
|
||||||
|
, ast => Ast };
|
||||||
fate ->
|
fate ->
|
||||||
Fcode = aeso_ast_to_fcode:ast_to_fcode(TypedAst, Options),
|
Fcode = aeso_ast_to_fcode:ast_to_fcode(TypedAst, Options),
|
||||||
#{ fcode => Fcode,
|
#{ fcode => Fcode
|
||||||
typed_ast => TypedAst,
|
, typed_ast => TypedAst
|
||||||
type_env => TypeEnv}
|
, type_env => TypeEnv
|
||||||
|
, ast => Ast }
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-define(CALL_NAME, "__call").
|
-define(CALL_NAME, "__call").
|
||||||
@ -199,8 +201,8 @@ check_call1(ContractString0, FunName, Args, Options) ->
|
|||||||
case proplists:get_value(backend, Options, aevm) of
|
case proplists:get_value(backend, Options, aevm) of
|
||||||
aevm ->
|
aevm ->
|
||||||
%% First check the contract without the __call function
|
%% First check the contract without the __call function
|
||||||
#{} = string_to_code(ContractString0, Options),
|
#{ast := Ast} = string_to_code(ContractString0, Options),
|
||||||
ContractString = insert_call_function(ContractString0, ?CALL_NAME, FunName, Args, Options),
|
ContractString = insert_call_function(Ast, ContractString0, ?CALL_NAME, FunName, Args),
|
||||||
#{typed_ast := TypedAst,
|
#{typed_ast := TypedAst,
|
||||||
icode := Icode} = string_to_code(ContractString, Options),
|
icode := Icode} = string_to_code(ContractString, Options),
|
||||||
{ok, {FunName, {fun_t, _, _, ArgTypes, RetType}}} = get_call_type(TypedAst),
|
{ok, {FunName, {fun_t, _, _, ArgTypes, RetType}}} = get_call_type(TypedAst),
|
||||||
@ -221,13 +223,14 @@ check_call1(ContractString0, FunName, Args, Options) ->
|
|||||||
{ok, FunName, {ArgVMTypes, RetVMType1}, ArgTerms};
|
{ok, FunName, {ArgVMTypes, RetVMType1}, ArgTerms};
|
||||||
fate ->
|
fate ->
|
||||||
%% First check the contract without the __call function
|
%% First check the contract without the __call function
|
||||||
#{fcode := OrgFcode} = string_to_code(ContractString0, Options),
|
#{ fcode := OrgFcode
|
||||||
|
, ast := Ast } = string_to_code(ContractString0, Options),
|
||||||
FateCode = aeso_fcode_to_fate:compile(OrgFcode, []),
|
FateCode = aeso_fcode_to_fate:compile(OrgFcode, []),
|
||||||
%% collect all hashes and compute the first name without hash collision to
|
%% collect all hashes and compute the first name without hash collision to
|
||||||
SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)),
|
SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)),
|
||||||
CallName = first_none_match(?CALL_NAME, SymbolHashes,
|
CallName = first_none_match(?CALL_NAME, SymbolHashes,
|
||||||
lists:seq($1, $9) ++ lists:seq($A, $Z) ++ lists:seq($a, $z)),
|
lists:seq($1, $9) ++ lists:seq($A, $Z) ++ lists:seq($a, $z)),
|
||||||
ContractString = insert_call_function(ContractString0, CallName, FunName, Args, Options),
|
ContractString = insert_call_function(Ast, ContractString0, CallName, FunName, Args),
|
||||||
#{fcode := Fcode} = string_to_code(ContractString, Options),
|
#{fcode := Fcode} = string_to_code(ContractString, Options),
|
||||||
CallArgs = arguments_of_body(CallName, FunName, Fcode),
|
CallArgs = arguments_of_body(CallName, FunName, Fcode),
|
||||||
{ok, FunName, CallArgs}
|
{ok, FunName, CallArgs}
|
||||||
@ -253,9 +256,8 @@ first_none_match(CallName, Hashes, [Char|Chars]) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
%% Add the __call function to a contract.
|
%% Add the __call function to a contract.
|
||||||
-spec insert_call_function(string(), string(), string(), [string()], options()) -> string().
|
-spec insert_call_function(aeso_syntax:ast(), string(), string(), string(), [string()]) -> string().
|
||||||
insert_call_function(Code, Call, FunName, Args, Options) ->
|
insert_call_function(Ast, Code, Call, FunName, Args) ->
|
||||||
Ast = parse(Code, Options),
|
|
||||||
Ind = last_contract_indent(Ast),
|
Ind = last_contract_indent(Ast),
|
||||||
lists:flatten(
|
lists:flatten(
|
||||||
[ Code,
|
[ Code,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user