Deshim VirtualExecutor in folly
[hiphop-php.git] / hphp / hhbbc / type-builtins.cpp
blob6415ca528c050ad1f3cd0c600626fbcfd28e1cd4
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #include "hphp/hhbbc/type-builtins.h"
18 #include "hphp/runtime/base/type-string.h"
19 #include "hphp/runtime/vm/native.h"
20 #include "hphp/hhbbc/representation.h"
22 namespace HPHP::HHBBC {
24 //////////////////////////////////////////////////////////////////////
26 Type native_function_return_type(const php::Func* f) {
27 assertx(f->isNative);
29 // Infer the type from the HNI declaration
30 auto t = [&]{
31 auto const hni = f->retTypeConstraint.asSystemlibType();
32 return hni ? from_DataType(*hni) : TInitCell;
33 }();
35 // Non-simple types (ones that are represented by pointers) can always
36 // possibly be null.
37 if (t.subtypeOf(BStr | BArrLike | BObj | BRes)) {
38 t = opt(std::move(t));
39 } else {
40 // Otherwise it should be a simple type or possibly everything.
41 assertx(t == TInitCell || t.subtypeOf(BBool | BInt | BDbl | BNull));
44 t = remove_uninit(std::move(t));
45 if (!f->hasInOutArgs) return t;
47 std::vector<Type> types;
48 types.emplace_back(std::move(t));
50 for (auto const& p : f->params) {
51 if (!p.inout) continue;
52 auto const dt =
53 Native::builtinOutType(p.typeConstraint, p.userAttributes);
54 if (!dt) {
55 types.emplace_back(TInitCell);
56 continue;
58 auto t = from_DataType(*dt);
59 if (p.typeConstraint.isNullable()) t = opt(std::move(t));
60 types.emplace_back(remove_uninit(std::move(t)));
62 std::reverse(types.begin()+1, types.end());
64 return vec(std::move(types));