Implement PHP7 null coalesce operator
commitfcf8d4dea785cdbcba02baa7a0d94020d14a9a10
authorRick Lavoie <rlavoie@fb.com>
Wed, 11 Nov 2015 18:42:50 +0000 (11 10:42 -0800)
committerhhvm-bot <hhvm-bot@fb.com>
Wed, 11 Nov 2015 19:00:43 +0000 (11 11:00 -0800)
tree380b3ce86fd8172aed79f75896c858ffb0f8377b
parent4f6f375440c73759e6b8e20e4cbf69ba4d5e2734
Implement PHP7 null coalesce operator

Summary: Implement the PHP7 null coalesce operator. This operator, '??', behaves
similarily to the '?:' operator, except if the left hand side does not exist, no
warning is issued.

To implement the required semantics, three new bytecodes had to be
added. 'CGetQuietL', 'CGetQuietN', and 'CGetQuietG', which behave like the
non-quiet versions, but never warn. Two other approaches were considered. The
first was adding flags to the CGet bytecodes to indicate whether to warn or
not. This became quite intrusive as these bytecodes are used everywhere. The
second approach was to lower the coalesce operator into an Isset followed by the
appropriate CGet. This generated very messy bytecode, however, and would require
at least one new bytecode anyways (to duplicate multiple values off the top of
the eval stack).

Reviewed By: swtaarrs

Differential Revision: D2592125

fb-gh-sync-id: 1e6b9c67657938e28f4c0e1b8dd1b2657fbea213
25 files changed:
hphp/compiler/analysis/emitter.cpp
hphp/compiler/analysis/emitter.h
hphp/compiler/construct.h
hphp/compiler/expression/list_assignment.cpp
hphp/compiler/expression/null_coalesce_expression.cpp [new file with mode: 0644]
hphp/compiler/expression/null_coalesce_expression.h [new file with mode: 0644]
hphp/compiler/parser/parser.cpp
hphp/compiler/parser/parser.h
hphp/doc/bytecode.specification
hphp/hhbbc/interp.cpp
hphp/parser/hphp.5.tab.cpp
hphp/parser/hphp.7.tab.cpp
hphp/parser/hphp.ll
hphp/parser/hphp.tab.hpp
hphp/parser/hphp.y
hphp/parser/lex.yy.cpp
hphp/runtime/ext/std/ext_std_misc.cpp
hphp/runtime/vm/bytecode.cpp
hphp/runtime/vm/hhbc.h
hphp/runtime/vm/jit/irgen-basic.cpp
hphp/runtime/vm/jit/irgen-interpone.cpp
hphp/runtime/vm/jit/irgen-sprop-global.cpp
hphp/runtime/vm/jit/translator.cpp
hphp/test/slow/php7_backported/coalesce.php [new file with mode: 0644]
hphp/test/slow/php7_backported/coalesce.php.expectf [new file with mode: 0644]