aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/core_parse.yrl
diff options
context:
space:
mode:
authorMichał Muskała <[email protected]>2018-02-25 14:19:48 +0100
committerMichał Muskała <[email protected]>2018-03-26 12:07:10 +0200
commit63e1c58d27ab695a19897423fc75e607f69ff51b (patch)
tree5965bba7175e8cb29596d3cdabb2db8cd86d6cd3 /lib/compiler/src/core_parse.yrl
parent0217dbfee505ed8c88164c7a4ea5e1834e6ce8cd (diff)
downloadotp-63e1c58d27ab695a19897423fc75e607f69ff51b.tar.gz
otp-63e1c58d27ab695a19897423fc75e607f69ff51b.tar.bz2
otp-63e1c58d27ab695a19897423fc75e607f69ff51b.zip
Compile external fun expressions to literals
The expressions fun M:F/A, when all elements are literals are also treated as a literal. Since they have consistent representation and don't depend on the code currently loaded in the VM, this is safe. This can provide significant performance improvements in code using such functions extensively - a full function call to erlang:make_fun/3 is replaced by a single move instruction and no register shuffling or saving registers to stack is necessary. Additionally, compound data types that contain such external functions as elements can be treated as literals too. The commit also changes the representation of external funs to be a valid Erlang syntax and adds support for literal external funs to core Erlang.
Diffstat (limited to 'lib/compiler/src/core_parse.yrl')
-rw-r--r--lib/compiler/src/core_parse.yrl6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/compiler/src/core_parse.yrl b/lib/compiler/src/core_parse.yrl
index 79a7cccd98..f828b3ed56 100644
--- a/lib/compiler/src/core_parse.yrl
+++ b/lib/compiler/src/core_parse.yrl
@@ -36,7 +36,7 @@ other_pattern atomic_pattern tuple_pattern cons_pattern tail_pattern
binary_pattern segment_patterns segment_pattern
expression single_expression
-literal literals atomic_literal tuple_literal cons_literal tail_literal
+literal literals atomic_literal tuple_literal cons_literal tail_literal fun_literal
nil tuple cons tail
binary segments segment
@@ -267,6 +267,7 @@ single_expression -> cons : '$1'.
single_expression -> binary : '$1'.
single_expression -> variable : '$1'.
single_expression -> function_name : '$1'.
+single_expression -> fun_literal : '$1'.
single_expression -> fun_expr : '$1'.
single_expression -> let_expr : '$1'.
single_expression -> letrec_expr : '$1'.
@@ -303,6 +304,9 @@ tail_literal -> ']' : #c_literal{val=[]}.
tail_literal -> '|' literal ']' : '$2'.
tail_literal -> ',' literal tail_literal : c_cons('$2', '$3').
+fun_literal -> 'fun' atom ':' atom '/' integer :
+ #c_literal{val = erlang:make_fun(tok_val('$2'), tok_val('$4'), tok_val('$6'))}.
+
tuple -> '{' '}' : c_tuple([]).
tuple -> '{' anno_expressions '}' : c_tuple('$2').