Skip to content

Commit fa4fe66

Browse files
author
Marat Omarov
committed
Merge master
2 parents 4efbde7 + 3ce70ae commit fa4fe66

986 files changed

Lines changed: 11274 additions & 4734 deletions

File tree

Some content is hidden

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

.clangd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CompileFlags:
2+
CompilationDatabase: build/ # Search build/ directory for compile_commands.json
3+
4+
Diagnostics:
5+
Suppress: cppcoreguidelines-avoid-do-while
6+

.github/workflows/Build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ jobs:
7676
- name: Build and save docker image
7777
if: steps.docker-image-cache.outputs.cache-hit != 'true'
7878
run: |
79-
docker build -f $GITHUB_WORKSPACE/.github/workflows/Dockerfile.${{matrix.os}} $GITHUB_WORKSPACE -t kphp-build-img-${{matrix.os}} --cache-from=type=local,src=kphp-build-img-${{matrix.os}}-cache
80-
docker tag kphp-build-img-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache && mkdir -p /tmp/docker-save-${{matrix.os}} && docker save kphp-build-img-${{matrix.os}}-cache -o /tmp/docker-save-${{matrix.os}}/kphp-build-env-${{matrix.os}}.tar && ls -lh /tmp/docker-save-${{matrix.os}}
79+
docker build -f $GITHUB_WORKSPACE/.github/workflows/Dockerfile.${{matrix.os}} $GITHUB_WORKSPACE \
80+
-t kphp-build-img-${{matrix.os}} \
81+
--cache-from=type=local,src=kphp-build-img-${{matrix.os}}-cache
82+
docker tag kphp-build-img-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
83+
docker save kphp-build-img-${{matrix.os}}-cache -o kphp-build-env-${{matrix.os}}.tar
8184
8285
- name: Load docker image from cache
8386
if: steps.docker-image-cache.outputs.cache-hit == 'true'

.github/workflows/debian.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,20 @@ jobs:
4343
- name: Build and save docker image
4444
if: steps.docker-image-cache.outputs.cache-hit != 'true'
4545
run: |
46-
docker build -f $GITHUB_WORKSPACE/.github/workflows/Dockerfile.${{matrix.os}} $GITHUB_WORKSPACE -t kphp-build-img-${{matrix.os}}
47-
docker save --output kphp-build-env-${{matrix.os}}.tar kphp-build-img-${{matrix.os}}
46+
docker build -f $GITHUB_WORKSPACE/.github/workflows/Dockerfile.${{matrix.os}} $GITHUB_WORKSPACE \
47+
-t kphp-build-img-${{matrix.os}} \
48+
--cache-from=type=local,src=kphp-build-img-${{matrix.os}}-cache
49+
docker tag kphp-build-img-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
50+
docker save kphp-build-img-${{matrix.os}}-cache -o kphp-build-env-${{matrix.os}}.tar
4851
4952
- name: Load docker image from cache
5053
if: steps.docker-image-cache.outputs.cache-hit == 'true'
5154
run: docker load --input kphp-build-env-${{matrix.os}}.tar
5255

5356
- name: Start docker container
54-
run: docker run -dt --name kphp-build-container-${{matrix.os}} --volume $GITHUB_WORKSPACE:${{env.kphp_root_dir}} kphp-build-img-${{matrix.os}}
57+
run: |
58+
docker run -dt --name kphp-build-container-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
59+
docker cp $GITHUB_WORKSPACE/. kphp-build-container-${{matrix.os}}:${{env.kphp_root_dir}}
5560
5661
- name: Change repo rights
5762
run: docker exec kphp-build-container-${{matrix.os}} bash -c

.github/workflows/ubuntu.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,20 @@ jobs:
5353
- name: Build and save docker image
5454
if: steps.docker-image-cache.outputs.cache-hit != 'true'
5555
run: |
56-
docker build -f $GITHUB_WORKSPACE/.github/workflows/Dockerfile.${{matrix.os}} $GITHUB_WORKSPACE -t kphp-build-img-${{matrix.os}}
57-
docker save --output kphp-build-env-${{matrix.os}}.tar kphp-build-img-${{matrix.os}}
56+
docker build -f $GITHUB_WORKSPACE/.github/workflows/Dockerfile.${{matrix.os}} $GITHUB_WORKSPACE \
57+
-t kphp-build-img-${{matrix.os}} \
58+
--cache-from=type=local,src=kphp-build-img-${{matrix.os}}-cache
59+
docker tag kphp-build-img-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
60+
docker save kphp-build-img-${{matrix.os}}-cache -o kphp-build-env-${{matrix.os}}.tar
5861
5962
- name: Load docker image from cache
6063
if: steps.docker-image-cache.outputs.cache-hit == 'true'
6164
run: docker load --input kphp-build-env-${{matrix.os}}.tar
6265

6366
- name: Start docker container
64-
run: docker run -dt --name kphp-build-container-${{matrix.os}} --volume $GITHUB_WORKSPACE:${{env.kphp_root_dir}} kphp-build-img-${{matrix.os}}
67+
run: |
68+
docker run -dt --name kphp-build-container-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
69+
docker cp $GITHUB_WORKSPACE/. kphp-build-container-${{matrix.os}}:${{env.kphp_root_dir}}
6570
6671
- name: Change repo rights
6772
run: docker exec kphp-build-container-${{matrix.os}} bash -c

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
.idea
1111
.vscode
12+
.cache
1213
build
1314
*.iml
1415
/cmake-build-*

builtin-functions/kphp-full/_functions.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ function rtrim ($s ::: string, $what ::: string = " \n\r\t\v\0") ::: string;
741741
function xor_strings ($s ::: string, $t ::: string) ::: string;
742742
function similar_text ($first ::: string, $second ::: string, float &$percent = TODO) ::: int;
743743

744+
function str_getcsv($str ::: string, string $delimiter ::: string = ",", string $enclosure ::: string = "\"", string $escape ::: string = "\\") ::: mixed[] | false;
745+
744746
function extension_loaded(string $extension): bool;
745747

746748
function ctype_alnum(mixed $text): bool;
@@ -1395,7 +1397,7 @@ function raise_sigsegv () ::: void;
13951397
function make_clone ($x ::: any) ::: ^1;
13961398

13971399
/** @kphp-extern-func-info cpp_template_call */
1398-
function instance_cast(object $instance, $to_type ::: string) ::: instance<^2>;
1400+
function instance_cast(any $instance, $to_type ::: string) ::: instance<^2>;
13991401

14001402
function instance_to_array(object $instance, $with_class_names ::: bool = false) ::: mixed[];
14011403
function to_array_debug(any $instance, bool $with_class_names = false) ::: mixed[];
@@ -1695,3 +1697,6 @@ class DateTimeImmutable implements DateTimeInterface {
16951697
}
16961698

16971699
function getenv(string $varname = '', bool $local_only = false): mixed;
1700+
1701+
// builtin that allows to store objects inside a mixed
1702+
function to_mixed(object $instance) ::: mixed;

builtin-functions/kphp-light/functions.txt

Lines changed: 43 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
<?php
22

3+
require_once __DIR__ . '/job-workers.txt';
4+
5+
define('TODO', -1);
6+
define('TODO_OVERLOAD', -1);
7+
8+
define('PHP_INT_MAX', 9223372036854775807);
39
define('PHP_INT_MIN', -9223372036854775808);
410
define('PHP_INT_SIZE', 8);
511
define('PHP_EOL', "\n");
612

13+
714
/** @var mixed $_SERVER */
815
global $_SERVER;
916
/** @var mixed $_GET */
@@ -31,6 +38,7 @@ function strval ($v ::: mixed) ::: string;
3138
/** @kphp-extern-func-info interruptible */
3239
function exit($code = 0) ::: void;
3340

41+
/** @kphp-extern-func-info interruptible */
3442
function die($code = 0) ::: void;
3543

3644
function ob_clean() ::: void;
@@ -62,9 +70,6 @@ function is_bool ($v ::: mixed) ::: bool;
6270
function is_int ($v ::: mixed) ::: bool;
6371
function is_integer ($v ::: mixed) ::: bool;
6472
function is_long ($v ::: mixed) ::: bool;
65-
function is_finite ($v ::: float) ::: bool;
66-
function is_infinite ($v ::: float) ::: bool;
67-
function is_nan ($v ::: float) ::: bool;
6873
function is_float ($v ::: mixed) ::: bool;
6974
function is_double ($v ::: mixed) ::: bool;
7075
function is_real ($v ::: mixed) ::: bool;
@@ -76,6 +81,21 @@ function get_hash_of_class (object $klass) ::: int;
7681

7782
function strlen ($str ::: string) ::: int;
7883

84+
// === Future =====================================================================================
85+
86+
function get_running_fork_id() ::: future <void>;
87+
88+
/** @kphp-extern-func-info interruptible cpp_template_call */
89+
function wait(future<any> | false $id, float $timeout = -1.0) ::: ^1[*] | null;
90+
91+
// === Fork =======================================================================================
92+
93+
/** @kphp-extern-func-info interruptible */
94+
function sched_yield() ::: void;
95+
96+
/** @kphp-extern-func-info interruptible */
97+
function sched_yield_sleep($duration ::: float) ::: void;
98+
7999
// === Rpc ========================================================================================
80100

81101
/** @kphp-tl-class */
@@ -120,95 +140,60 @@ function rpc_tl_query_result($query_ids ::: array) ::: mixed[][];
120140
/** @kphp-extern-func-info interruptible */
121141
function typed_rpc_tl_query_result(int[] $query_ids) ::: @tl\RpcResponse[];
122142

123-
124143
// === Component ==================================================================================
125144

126145
class ComponentQuery {
127146
private function __construct() ::: \ComponentQuery;
128147
}
129148

130149
/** @kphp-extern-func-info interruptible */
131-
function component_get_http_query() ::: void;
150+
function component_client_send_request($name ::: string, $message ::: string) ::: ComponentQuery;
132151

133152
/** @kphp-extern-func-info interruptible */
134-
function component_client_send_query($name ::: string, $message ::: string) ::: ComponentQuery;
135-
/** @kphp-extern-func-info interruptible */
136-
function component_client_get_result($query ::: ComponentQuery) ::: string;
153+
function component_client_fetch_response($query ::: ComponentQuery) ::: string;
137154

138155
/** @kphp-extern-func-info interruptible */
139-
function component_server_get_query() ::: string;
140-
/** @kphp-extern-func-info interruptible */
141-
function component_server_send_result($message ::: string) ::: void;
142-
143-
class ComponentStream {
144-
private function __construct() ::: \ComponentStream;
156+
function component_server_accept_query() ::: ComponentQuery;
145157

146-
public function is_read_closed() ::: bool;
147-
public function is_write_closed() ::: bool;
148-
public function is_please_shutdown_write() ::: bool;
149-
150-
public function shutdown_write() ::: void;
151-
public function please_shutdown_write() ::: void;
152-
}
153-
154-
function component_open_stream($name ::: string) ::: ComponentStream;
155158
/** @kphp-extern-func-info interruptible */
156-
function component_accept_stream() ::: ComponentStream;
159+
function component_server_fetch_request($query ::: ComponentQuery) ::: string;
157160

158-
function component_stream_write_nonblock($stream ::: ComponentStream, $message ::: string) ::: int;
159-
function component_stream_read_nonblock($stream ::: ComponentStream) ::: string;
160-
/** @kphp-extern-func-info interruptible */
161-
function component_stream_write_exact($stream ::: ComponentStream, $message ::: string) ::: int;
162161
/** @kphp-extern-func-info interruptible */
163-
function component_stream_read_exact($stream ::: ComponentStream, $len ::: int) ::: string;
164-
165-
function component_close_stream($stream ::: ComponentStream) ::: void;
166-
function component_finish_stream_processing($stream ::: ComponentStream) ::: void;
162+
function component_server_send_response($query ::: ComponentQuery, $message ::: string) ::: void;
167163

168164
// === Json =======================================================================================
169165

170-
class JsonEncoder {
171-
const rename_policy = 'none';
172-
const visibility_policy = 'all';
173-
const skip_if_default = false;
174-
const float_precision = 0;
175-
176-
private function __construct();
177-
178-
public static function encode(object $instance, int $flags = 0, array $more = []) : string;
179-
public static function decode(string $json, string $class_name) : instance<^2>;
180-
public static function getLastError() : string;
166+
function json_encode ($v ::: mixed, $options ::: int = 0) ::: string | false;
181167

182-
// JsonEncoderOrChild::encode(...) is actually replaced by JsonEncoder::to_json_impl('JsonEncoderOrChild', ...)
183-
static function to_json_impl(string $encoder_tag, object $instance, int $flags = 0, array $more = []) ::: string;
168+
function json_decode ($v ::: string, $assoc ::: bool = false) ::: mixed;
184169

185-
// JsonEncoderOrChild::decode(...) is actually replaced by JsonEncoder::from_json_impl('JsonEncoderOrChild', ...)
186-
/** @kphp-extern-func-info cpp_template_call */
187-
static function from_json_impl(string $encoder_tag, string $json, string $class_name) ::: instance<^3>;
188-
}
170+
// === Crypto======================================================================================
189171

190-
function json_encode ($v ::: mixed, $options ::: int = 0) ::: string | false;
172+
/** @kphp-extern-func-info interruptible */
173+
function openssl_random_pseudo_bytes ($length ::: int) ::: string | false;
191174

192-
function json_decode ($v ::: string, $assoc ::: bool = false) ::: mixed;
175+
/** @kphp-extern-func-info interruptible */
176+
function openssl_x509_parse ($x509cert ::: string, $shortnames ::: bool = true) ::: mixed[] | false;
193177

194178
// === Misc =======================================================================================
195179

196180
/** @kphp-extern-func-info cpp_template_call */
197-
function instance_cast(object $instance, $to_type ::: string) ::: instance<^2>;
181+
function instance_cast(any $instance, $to_type ::: string) ::: instance<^2>;
198182

199183
function make_clone ($x ::: any) ::: ^1;
200184

201-
/** @kphp-extern-func-info interruptible */
202-
function testyield() ::: void;
203185
function check_shutdown() ::: void;
204186

205187
function warning($message ::: string) ::: void;
206188
/** @kphp-no-return */
207189
function critical_error($message ::: string) ::: void;
208190

209-
function debug_print_string($str ::: string) ::: void;
191+
/** @kphp-extern-func-info interruptible */
192+
function set_timer(int $timeout, callable():void $callback) ::: void;
210193

211-
function byte_to_int($str ::: string) ::: ?int;
212-
function int_to_byte($v ::: int) ::: ?string;
194+
// builtin that allows to store objects inside a mixed
195+
function to_mixed(object $instance) ::: mixed;
213196

214-
function set_timer(int $timeout, callable():void $callback) ::: void;
197+
// === Unsupported =======================================================================================
198+
199+
require_once __DIR__ . '/unsupported-functions.txt';
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
// === Job Worker =================================================================================
4+
5+
/** @kphp-immutable-class */
6+
interface KphpJobWorkerSharedMemoryPiece {}
7+
8+
interface KphpJobWorkerRequest {}
9+
interface KphpJobWorkerResponse {}
10+
11+
class KphpJobWorkerResponseError implements KphpJobWorkerResponse {
12+
// Job script execution errors:
13+
const JOB_MEMORY_LIMIT_ERROR = -101;
14+
const JOB_TIMEOUT_ERROR = -102;
15+
const JOB_EXCEPTION_ERROR = -103;
16+
const JOB_STACK_OVERFLOW_ERROR = -104;
17+
const JOB_PHP_ASSERT_ERROR = -105;
18+
19+
const JOB_CLIENT_MEMORY_LIMIT_ERROR = -1001; // client doesn't have enough memory to accept job response
20+
const JOB_NOTHING_REPLIED_ERROR = -2001; // kphp_job_worker_store_response() was not succeeded
21+
22+
const JOB_STORE_RESPONSE_INCORRECT_CALL_ERROR = -3000;
23+
const JOB_STORE_RESPONSE_NOT_ENOUGH_SHARED_MESSAGES_ERROR = -3001;
24+
const JOB_STORE_RESPONSE_TOO_BIG_ERROR = -3002;
25+
const JOB_STORE_RESPONSE_CANT_SEND_ERROR = -3003;
26+
27+
public function getError() ::: string;
28+
public function getErrorCode() ::: int; // returns one of listed above error codes
29+
}
30+
31+
/** @kphp-extern-func-info interruptible */
32+
function kphp_job_worker_start(string $request, float $timeout): future<string> | false;
33+
34+
/** @kphp-extern-func-info interruptible */
35+
function kphp_job_worker_start_no_reply(string $request, float $timeout): bool;
36+
37+
/** @kphp-extern-func-info interruptible */
38+
function kphp_job_worker_start_multi(string[] $request, float $timeout): (future<string> | false)[];
39+
40+
/** @kphp-extern-func-info interruptible */
41+
function kphp_job_worker_fetch_request(): string;
42+
43+
/** @kphp-extern-func-info interruptible */
44+
function kphp_job_worker_store_response(string $response): int;
45+
46+
function is_kphp_job_workers_enabled(): bool;
47+
48+
function get_job_workers_number(): int;
49+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
require_once __DIR__ . '/unsupported/arrays.txt';
4+
require_once __DIR__ . '/unsupported/crypto.txt';
5+
require_once __DIR__ . '/unsupported/curl.txt';
6+
require_once __DIR__ . '/unsupported/error.txt';
7+
require_once __DIR__ . '/unsupported/file.txt';
8+
require_once __DIR__ . '/unsupported/fork.txt';
9+
require_once __DIR__ . '/unsupported/hash.txt';
10+
require_once __DIR__ . '/unsupported/kml.txt';
11+
require_once __DIR__ . '/unsupported/kphp-toggles.txt';
12+
require_once __DIR__ . '/unsupported/kphp-tracing.txt';
13+
require_once __DIR__ . '/unsupported/kphp_internal.txt';
14+
require_once __DIR__ . '/unsupported/math.txt';
15+
require_once __DIR__ . '/unsupported/misc.txt';
16+
require_once __DIR__ . '/unsupported/regex.txt';
17+
require_once __DIR__ . '/unsupported/rpc.txt';
18+
require_once __DIR__ . '/unsupported/serialize.txt';
19+
require_once __DIR__ . '/unsupported/server.txt';
20+
require_once __DIR__ . '/unsupported/string.txt';
21+
require_once __DIR__ . '/unsupported/time.txt';
22+
require_once __DIR__ . '/unsupported/uberh3.txt';
23+
require_once __DIR__ . '/unsupported/vkext.txt';

0 commit comments

Comments
 (0)