abstract constants: preclass/class emission [2/2]
commit7900db75f735d352f63cc827bab78bc017e8ce93
authorEugene Letuchy <eletuchy@fb.com>
Thu, 20 Nov 2014 04:19:11 +0000 (19 20:19 -0800)
committerhhvm-bot <hhvm-bot@fb.com>
Tue, 2 Dec 2014 03:00:39 +0000 (1 19:00 -0800)
tree97cc9e06bfca22e6817cc8daabc485a725fb1705
parent8cab8cda7c2f385072a4c3d661a13f9274d398cf
abstract constants: preclass/class emission [2/2]

Summary: `abstract const` in a class has the same general purpose as an
 abstract method: prevent a class from being 'concrete' unless it
 defines that constant. Trying to reference a value of an abstract
 constant remains a fatal (as if it were not defined at all).

 PHP5 doesn't allow interface constants to be redefined in any
 implementing class. In contrast, this diff allows interface/abstract
 class constants to be defined as `abstract` in a addition to regular
 definitions. This allows (and for non-abstract children, forces)
 extending classes to provide concrete definitions for those
 constants. This diff does not touch the prohibition on constants in
 traits.

 Between preclass emitter, preclass, class, and hhbbc, we have an
 impressive number of structs that represent constants. In all of
 these, the ## val ## of a const is changed from being a TypedValue to
 a ##folly::optional<TypedValue>##, with ##folly::none## representing
 an abstract constant definition. For constant values,
 ##KindOfUninit## is already taken as the representation values
 requiring runtime calculations (e.g. 'const X = self::Y;').

 Note: all this diff does for runtime reflection support is actively
 hide the abstract constant definitions.

Reviewed By: @jdelong

Differential Revision: D1693734

Signature: t1:1693734:1416989210:8f15fa8069018553973f0b285315f02330096323
34 files changed:
hphp/compiler/analysis/emitter.cpp
hphp/hhbbc/emit.cpp
hphp/hhbbc/index.cpp
hphp/hhbbc/parse.cpp
hphp/hhbbc/representation.h
hphp/runtime/base/enum-cache.cpp
hphp/runtime/base/typed-value.h
hphp/runtime/ext/reflection/ext_reflection.cpp
hphp/runtime/ext/std/ext_std_classobj.cpp
hphp/runtime/test/blob-helper-test.cpp
hphp/runtime/vm/blob-helper.h
hphp/runtime/vm/class-inl.h
hphp/runtime/vm/class.cpp
hphp/runtime/vm/class.h
hphp/runtime/vm/disas.cpp
hphp/runtime/vm/preclass-emitter.cpp
hphp/runtime/vm/preclass-emitter.h
hphp/runtime/vm/preclass-inl.h
hphp/runtime/vm/preclass.cpp
hphp/runtime/vm/preclass.h
hphp/system/php/spl/iterators/FilesystemIterator.php
hphp/test/slow/class_constant/abstract_const1.php [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const1.php.expectf [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const3.php [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const3.php.expectf [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const4.php [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const4.php.expectf [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const5.php [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const5.php.expectf [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const6.php [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const6.php.expectf [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const7.php [new file with mode: 0644]
hphp/test/slow/class_constant/abstract_const7.php.expectf [new file with mode: 0644]
hphp/test/slow/types/default_parameter.inc