Skip to content

Commit 71a0fe7

Browse files
authored
add forbid stubs option in compiler (#1250)
1 parent 4143ac7 commit 71a0fe7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+886
-751
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
// ===== SUPPORTED =====
4+
5+
/** @var mixed $_SERVER */
6+
global $_SERVER;
7+
/** @var mixed $_GET */
8+
global $_GET;
9+
/** @var mixed $_POST */
10+
global $_POST;
11+
/** @var mixed $_FILES */
12+
global $_FILES;
13+
/** @var mixed $_COOKIE */
14+
global $_COOKIE;
15+
/** @var mixed $_REQUEST */
16+
global $_REQUEST;
17+
/** @var mixed $_ENV */
18+
global $_ENV;
19+
/** @var mixed $argc */
20+
global $argc;
21+
/** @var mixed $argv */
22+
global $argv;
23+
24+
define('PHP_INT_MAX', 9223372036854775807);
25+
define('PHP_INT_MIN', -9223372036854775808);
26+
define('PHP_INT_SIZE', 8);
27+
define('PHP_EOL', "\n");
28+
29+
function empty ($val ::: any) ::: bool;
30+
function count ($val ::: any) ::: int;
31+
function sizeof ($val ::: any) ::: int;
32+
function gettype ($v ::: any) ::: string;
33+
function is_scalar ($v ::: any) ::: bool;
34+
function is_numeric ($v ::: mixed) ::: bool;
35+
function is_null ($v ::: any) ::: bool;
36+
function is_bool ($v ::: mixed) ::: bool;
37+
function is_int ($v ::: mixed) ::: bool;
38+
function is_integer ($v ::: mixed) ::: bool;
39+
function is_long ($v ::: mixed) ::: bool;
40+
function is_float ($v ::: mixed) ::: bool;
41+
function is_double ($v ::: mixed) ::: bool;
42+
function is_real ($v ::: mixed) ::: bool;
43+
function is_string ($v ::: mixed) ::: bool;
44+
function is_array ($v ::: any) ::: bool;
45+
function is_object ($v ::: any) ::: bool;
46+
function get_class ($v ::: any) ::: string;
47+
function get_hash_of_class (object $klass) ::: int;
48+
49+
50+
/** defined in runtime-core.h **/
51+
function likely ($x ::: bool) ::: bool;
52+
function unlikely ($x ::: bool) ::: bool;
53+
54+
function boolval ($v ::: any) ::: bool;
55+
function intval ($v ::: mixed) ::: int;
56+
function floatval ($v ::: mixed) ::: float;
57+
function strval ($v ::: mixed) ::: string;
58+
59+
/** @kphp-extern-func-info cpp_template_call */
60+
function instance_cast(any $instance, $to_type ::: string) ::: instance<^2>;
61+
62+
function make_clone ($x ::: any) ::: ^1;
63+
64+
function warning($message ::: string) ::: void;
65+
/** @kphp-no-return */
66+
function critical_error($message ::: string) ::: void;
67+
68+
// builtin that allows to store objects inside a mixed
69+
function to_mixed(object $instance) ::: mixed;
70+
71+
/** @kphp-required */
72+
interface ArrayAccess {
73+
public function offsetExists(mixed $offset): bool;
74+
public function offsetGet(mixed $offset): mixed;
75+
public function offsetSet(mixed $offset, mixed $value);
76+
public function offsetUnset(mixed $offset);
77+
}

builtin-functions/kphp-light/kphp_internal.txt renamed to builtin-functions/kphp-light/core/kphp_internal.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,26 @@ function _exception_set_location($e, string $filename, int $line): ^1;
4343
// ===== UNSUPPORTED =====
4444

4545
// `new $c(...)` => `_by_name_construct($c, ...)`
46+
/** @kphp-extern-func-info stub */
4647
function _by_name_construct(string $class_name, ...$args) ::: instance<^1>;
4748
// `$c::method()` => `_by_name_call_method($c, 'method')`
49+
/** @kphp-extern-func-info stub */
4850
function _by_name_call_method(string $class_name, string $method_name, ...$args);
4951
// `$c::CONST` => `_by_name_get_const($c, 'CONST')`
52+
/** @kphp-extern-func-info stub */
5053
function _by_name_get_const(string $class_name, string $constant);
5154
// `$c::$field` => `_by_name_get_field($c, 'field')`
55+
/** @kphp-extern-func-info stub */
5256
function _by_name_get_field(string $class_name, string $field);
5357

5458
/**
5559
* @kphp-internal-param-readonly $str
60+
* @kphp-extern-func-info stub
5661
*/
5762
function _tmp_substr($str ::: string, $start ::: int, $length ::: int = PHP_INT_MAX): _tmp_string;
5863

5964
/**
6065
* @kphp-internal-param-readonly $str
66+
* @kphp-extern-func-info stub
6167
*/
6268
function _tmp_trim($str ::: string, $what ::: string = " \n\r\t\v\0"): _tmp_string;
Lines changed: 29 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -1,185 +1,38 @@
11
<?php
22

3-
require_once __DIR__ . '/array.txt';
4-
require_once __DIR__ . '/confdata.txt';
5-
require_once __DIR__ . '/crypto.txt';
6-
require_once __DIR__ . '/error.txt';
7-
require_once __DIR__ . '/file.txt';
8-
require_once __DIR__ . '/hash.txt';
9-
require_once __DIR__ . '/job-workers.txt';
10-
require_once __DIR__ . '/rpc.txt';
11-
require_once __DIR__ . '/serialize.txt';
12-
require_once __DIR__ . '/string.txt';
13-
require_once __DIR__ . '/server.txt';
14-
require_once __DIR__ . '/system.txt';
15-
require_once __DIR__ . '/kphp-toggles.txt';
16-
require_once __DIR__ . '/kphp_internal.txt';
17-
require_once __DIR__ . '/math.txt';
18-
require_once __DIR__ . '/time.txt';
19-
require_once __DIR__ . '/regex.txt';
20-
require_once __DIR__ . '/vkext.txt';
21-
22-
/** defined in runtime-core.h **/
23-
function likely ($x ::: bool) ::: bool;
24-
function unlikely ($x ::: bool) ::: bool;
25-
263
define('TODO', -1);
274
define('TODO_OVERLOAD', -1);
285

29-
define('PHP_INT_MAX', 9223372036854775807);
30-
define('PHP_INT_MIN', -9223372036854775808);
31-
define('PHP_INT_SIZE', 8);
32-
define('PHP_EOL', "\n");
6+
require_once __DIR__ . '/core/core-functions.txt';
7+
require_once __DIR__ . '/core/kphp_internal.txt';
8+
require_once __DIR__ . '/stdlib/array-functions.txt';
9+
require_once __DIR__ . '/stdlib/component-functions.txt';
10+
require_once __DIR__ . '/stdlib/confdata-functions.txt';
11+
require_once __DIR__ . '/stdlib/crypto-functions.txt';
12+
require_once __DIR__ . '/stdlib/curl-functions.txt';
13+
require_once __DIR__ . '/stdlib/diagnostic.txt';
14+
require_once __DIR__ . '/stdlib/error.txt';
15+
require_once __DIR__ . '/stdlib/file-functions.txt';
16+
require_once __DIR__ . '/stdlib/fork-functions.txt';
17+
require_once __DIR__ . '/stdlib/job-workers.txt';
18+
require_once __DIR__ . '/stdlib/kml-functions.txt';
19+
require_once __DIR__ . '/stdlib/kphp-toggles.txt';
20+
require_once __DIR__ . '/stdlib/kphp-tracing.txt';
21+
require_once __DIR__ . '/stdlib/math-functions.txt';
22+
require_once __DIR__ . '/stdlib/memcache.txt';
23+
require_once __DIR__ . '/stdlib/output-functions.txt';
24+
require_once __DIR__ . '/stdlib/regex-functions.txt';
25+
require_once __DIR__ . '/stdlib/rpc.txt';
26+
require_once __DIR__ . '/stdlib/serialize-functions.txt';
27+
require_once __DIR__ . '/stdlib/server-functions.txt';
28+
require_once __DIR__ . '/stdlib/spl.txt';
29+
require_once __DIR__ . '/stdlib/string-functions.txt';
30+
require_once __DIR__ . '/stdlib/system-functions.txt';
31+
require_once __DIR__ . '/stdlib/time-functions.txt';
32+
require_once __DIR__ . '/stdlib/uberh3.txt';
33+
require_once __DIR__ . '/stdlib/vkext-functions.txt';
34+
require_once __DIR__ . '/stdlib/zlib-functions.txt';
3335

3436
if (0) {
3537
define('PHP_SAPI', php_sapi_name());//"Defined in source code"
3638
}
37-
38-
/** @var mixed $_SERVER */
39-
global $_SERVER;
40-
/** @var mixed $_GET */
41-
global $_GET;
42-
/** @var mixed $_POST */
43-
global $_POST;
44-
/** @var mixed $_FILES */
45-
global $_FILES;
46-
/** @var mixed $_COOKIE */
47-
global $_COOKIE;
48-
/** @var mixed $_REQUEST */
49-
global $_REQUEST;
50-
/** @var mixed $_ENV */
51-
global $_ENV;
52-
/** @var mixed $argc */
53-
global $argc;
54-
/** @var mixed $argv */
55-
global $argv;
56-
57-
function boolval ($v ::: any) ::: bool;
58-
function intval ($v ::: mixed) ::: int;
59-
function floatval ($v ::: mixed) ::: float;
60-
function strval ($v ::: mixed) ::: string;
61-
62-
/**
63-
* @kphp-no-return
64-
* @kphp-extern-func-info interruptible
65-
*/
66-
function exit($code = 0) ::: void;
67-
68-
/**
69-
* @kphp-no-return
70-
* @kphp-extern-func-info interruptible
71-
*/
72-
function die($code = 0) ::: void;
73-
74-
function ob_clean() ::: void;
75-
function ob_end_clean() ::: bool;
76-
function ob_get_clean() ::: string | false;
77-
function ob_get_contents() ::: string;
78-
function ob_start ($x ::: string = "") ::: void;
79-
function ob_flush () ::: void;
80-
function ob_end_flush () ::: bool;
81-
function ob_get_flush () ::: string | false;
82-
function ob_get_length () ::: int | false;
83-
function ob_get_level () ::: int;
84-
85-
function print_r ($v ::: any, $buffered ::: bool = false) ::: string;
86-
function var_export ($v ::: any, $buffered ::: bool = false) ::: string;
87-
function print ($v ::: string) ::: int;
88-
function echo ($v ::: string) ::: void;
89-
function dbg_echo ($v ::: string) ::: void;
90-
function var_dump ($v ::: any) ::: void;
91-
92-
function empty ($val ::: any) ::: bool;
93-
function count ($val ::: any) ::: int;
94-
function sizeof ($val ::: any) ::: int;
95-
function gettype ($v ::: any) ::: string;
96-
function is_scalar ($v ::: any) ::: bool;
97-
function is_numeric ($v ::: mixed) ::: bool;
98-
function is_null ($v ::: any) ::: bool;
99-
function is_bool ($v ::: mixed) ::: bool;
100-
function is_int ($v ::: mixed) ::: bool;
101-
function is_integer ($v ::: mixed) ::: bool;
102-
function is_long ($v ::: mixed) ::: bool;
103-
function is_float ($v ::: mixed) ::: bool;
104-
function is_double ($v ::: mixed) ::: bool;
105-
function is_real ($v ::: mixed) ::: bool;
106-
function is_string ($v ::: mixed) ::: bool;
107-
function is_array ($v ::: any) ::: bool;
108-
function is_object ($v ::: any) ::: bool;
109-
function get_class ($v ::: any) ::: string;
110-
function get_hash_of_class (object $klass) ::: int;
111-
112-
function strlen ($str ::: string) ::: int;
113-
114-
// === Future =====================================================================================
115-
116-
function get_running_fork_id() ::: future <void>;
117-
118-
/** @kphp-extern-func-info can_throw interruptible cpp_template_call */
119-
function wait(future<any> | false $id, float $timeout = -1.0) ::: ^1[*] | null;
120-
121-
/** @kphp-extern-func-info interruptible */
122-
function wait_concurrently ($id ::: future<any>): bool;
123-
124-
/** @kphp-extern-func-info interruptible can_throw cpp_template_call */
125-
function wait_multi (future<any>[] $resumables) ::: (^1[*][*] | null)[];
126-
127-
// === Fork =======================================================================================
128-
129-
/** @kphp-extern-func-info interruptible */
130-
function sched_yield() ::: void;
131-
132-
/** @kphp-extern-func-info interruptible */
133-
function sched_yield_sleep($duration ::: float) ::: void;
134-
135-
// === Component ==================================================================================
136-
137-
final class ComponentQuery {
138-
private function __construct() ::: \ComponentQuery;
139-
}
140-
141-
/** @kphp-extern-func-info interruptible */
142-
function component_client_send_request($name ::: string, $message ::: string) ::: ComponentQuery;
143-
144-
/** @kphp-extern-func-info interruptible */
145-
function component_client_fetch_response($query ::: ComponentQuery) ::: string;
146-
147-
/** @kphp-extern-func-info interruptible */
148-
function component_server_accept_query() ::: ComponentQuery;
149-
150-
/** @kphp-extern-func-info interruptible */
151-
function component_server_fetch_request($query ::: ComponentQuery) ::: string;
152-
153-
/** @kphp-extern-func-info interruptible */
154-
function component_server_send_response($query ::: ComponentQuery, $message ::: string) ::: void;
155-
156-
// === Misc =======================================================================================
157-
158-
/** @kphp-extern-func-info cpp_template_call */
159-
function instance_cast(any $instance, $to_type ::: string) ::: instance<^2>;
160-
161-
function make_clone ($x ::: any) ::: ^1;
162-
163-
function check_shutdown() ::: void;
164-
165-
function warning($message ::: string) ::: void;
166-
/** @kphp-no-return */
167-
function critical_error($message ::: string) ::: void;
168-
169-
/** @kphp-extern-func-info interruptible */
170-
function set_timer(int $timeout, callable():void $callback) ::: void;
171-
172-
// builtin that allows to store objects inside a mixed
173-
function to_mixed(object $instance) ::: mixed;
174-
175-
// === Unsupported =======================================================================================
176-
177-
require_once __DIR__ . '/unsupported-functions.txt';
178-
179-
/** @kphp-required */
180-
interface ArrayAccess {
181-
public function offsetExists(mixed $offset): bool;
182-
public function offsetGet(mixed $offset): mixed;
183-
public function offsetSet(mixed $offset, mixed $value);
184-
public function offsetUnset(mixed $offset);
185-
}

builtin-functions/kphp-light/server.txt

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)