Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-omarov committed Sep 13, 2024
2 parents 4efbde7 + 3ce70ae commit fa4fe66
Show file tree
Hide file tree
Showing 986 changed files with 11,274 additions and 4,734 deletions.
6 changes: 6 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CompileFlags:
CompilationDatabase: build/ # Search build/ directory for compile_commands.json

Diagnostics:
Suppress: cppcoreguidelines-avoid-do-while

7 changes: 5 additions & 2 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ jobs:
- name: Build and save docker image
if: steps.docker-image-cache.outputs.cache-hit != 'true'
run: |
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
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}}
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
docker tag kphp-build-img-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
docker save kphp-build-img-${{matrix.os}}-cache -o kphp-build-env-${{matrix.os}}.tar
- name: Load docker image from cache
if: steps.docker-image-cache.outputs.cache-hit == 'true'
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,20 @@ jobs:
- name: Build and save docker image
if: steps.docker-image-cache.outputs.cache-hit != 'true'
run: |
docker build -f $GITHUB_WORKSPACE/.github/workflows/Dockerfile.${{matrix.os}} $GITHUB_WORKSPACE -t kphp-build-img-${{matrix.os}}
docker save --output kphp-build-env-${{matrix.os}}.tar kphp-build-img-${{matrix.os}}
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
docker tag kphp-build-img-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
docker save kphp-build-img-${{matrix.os}}-cache -o kphp-build-env-${{matrix.os}}.tar
- name: Load docker image from cache
if: steps.docker-image-cache.outputs.cache-hit == 'true'
run: docker load --input kphp-build-env-${{matrix.os}}.tar

- name: Start docker container
run: docker run -dt --name kphp-build-container-${{matrix.os}} --volume $GITHUB_WORKSPACE:${{env.kphp_root_dir}} kphp-build-img-${{matrix.os}}
run: |
docker run -dt --name kphp-build-container-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
docker cp $GITHUB_WORKSPACE/. kphp-build-container-${{matrix.os}}:${{env.kphp_root_dir}}
- name: Change repo rights
run: docker exec kphp-build-container-${{matrix.os}} bash -c
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ jobs:
- name: Build and save docker image
if: steps.docker-image-cache.outputs.cache-hit != 'true'
run: |
docker build -f $GITHUB_WORKSPACE/.github/workflows/Dockerfile.${{matrix.os}} $GITHUB_WORKSPACE -t kphp-build-img-${{matrix.os}}
docker save --output kphp-build-env-${{matrix.os}}.tar kphp-build-img-${{matrix.os}}
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
docker tag kphp-build-img-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
docker save kphp-build-img-${{matrix.os}}-cache -o kphp-build-env-${{matrix.os}}.tar
- name: Load docker image from cache
if: steps.docker-image-cache.outputs.cache-hit == 'true'
run: docker load --input kphp-build-env-${{matrix.os}}.tar

- name: Start docker container
run: docker run -dt --name kphp-build-container-${{matrix.os}} --volume $GITHUB_WORKSPACE:${{env.kphp_root_dir}} kphp-build-img-${{matrix.os}}
run: |
docker run -dt --name kphp-build-container-${{matrix.os}} kphp-build-img-${{matrix.os}}-cache
docker cp $GITHUB_WORKSPACE/. kphp-build-container-${{matrix.os}}:${{env.kphp_root_dir}}
- name: Change repo rights
run: docker exec kphp-build-container-${{matrix.os}} bash -c
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

.idea
.vscode
.cache
build
*.iml
/cmake-build-*
Expand Down
7 changes: 6 additions & 1 deletion builtin-functions/kphp-full/_functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,8 @@ function rtrim ($s ::: string, $what ::: string = " \n\r\t\v\0") ::: string;
function xor_strings ($s ::: string, $t ::: string) ::: string;
function similar_text ($first ::: string, $second ::: string, float &$percent = TODO) ::: int;

function str_getcsv($str ::: string, string $delimiter ::: string = ",", string $enclosure ::: string = "\"", string $escape ::: string = "\\") ::: mixed[] | false;

function extension_loaded(string $extension): bool;

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

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

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

function getenv(string $varname = '', bool $local_only = false): mixed;

// builtin that allows to store objects inside a mixed
function to_mixed(object $instance) ::: mixed;
101 changes: 43 additions & 58 deletions builtin-functions/kphp-light/functions.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<?php

require_once __DIR__ . '/job-workers.txt';

define('TODO', -1);
define('TODO_OVERLOAD', -1);

define('PHP_INT_MAX', 9223372036854775807);
define('PHP_INT_MIN', -9223372036854775808);
define('PHP_INT_SIZE', 8);
define('PHP_EOL', "\n");


/** @var mixed $_SERVER */
global $_SERVER;
/** @var mixed $_GET */
Expand Down Expand Up @@ -31,6 +38,7 @@ function strval ($v ::: mixed) ::: string;
/** @kphp-extern-func-info interruptible */
function exit($code = 0) ::: void;

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

function ob_clean() ::: void;
Expand Down Expand Up @@ -62,9 +70,6 @@ function is_bool ($v ::: mixed) ::: bool;
function is_int ($v ::: mixed) ::: bool;
function is_integer ($v ::: mixed) ::: bool;
function is_long ($v ::: mixed) ::: bool;
function is_finite ($v ::: float) ::: bool;
function is_infinite ($v ::: float) ::: bool;
function is_nan ($v ::: float) ::: bool;
function is_float ($v ::: mixed) ::: bool;
function is_double ($v ::: mixed) ::: bool;
function is_real ($v ::: mixed) ::: bool;
Expand All @@ -76,6 +81,21 @@ function get_hash_of_class (object $klass) ::: int;

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

// === Future =====================================================================================

function get_running_fork_id() ::: future <void>;

/** @kphp-extern-func-info interruptible cpp_template_call */
function wait(future<any> | false $id, float $timeout = -1.0) ::: ^1[*] | null;

// === Fork =======================================================================================

/** @kphp-extern-func-info interruptible */
function sched_yield() ::: void;

/** @kphp-extern-func-info interruptible */
function sched_yield_sleep($duration ::: float) ::: void;

// === Rpc ========================================================================================

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


// === Component ==================================================================================

class ComponentQuery {
private function __construct() ::: \ComponentQuery;
}

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

/** @kphp-extern-func-info interruptible */
function component_client_send_query($name ::: string, $message ::: string) ::: ComponentQuery;
/** @kphp-extern-func-info interruptible */
function component_client_get_result($query ::: ComponentQuery) ::: string;
function component_client_fetch_response($query ::: ComponentQuery) ::: string;

/** @kphp-extern-func-info interruptible */
function component_server_get_query() ::: string;
/** @kphp-extern-func-info interruptible */
function component_server_send_result($message ::: string) ::: void;

class ComponentStream {
private function __construct() ::: \ComponentStream;
function component_server_accept_query() ::: ComponentQuery;

public function is_read_closed() ::: bool;
public function is_write_closed() ::: bool;
public function is_please_shutdown_write() ::: bool;

public function shutdown_write() ::: void;
public function please_shutdown_write() ::: void;
}

function component_open_stream($name ::: string) ::: ComponentStream;
/** @kphp-extern-func-info interruptible */
function component_accept_stream() ::: ComponentStream;
function component_server_fetch_request($query ::: ComponentQuery) ::: string;

function component_stream_write_nonblock($stream ::: ComponentStream, $message ::: string) ::: int;
function component_stream_read_nonblock($stream ::: ComponentStream) ::: string;
/** @kphp-extern-func-info interruptible */
function component_stream_write_exact($stream ::: ComponentStream, $message ::: string) ::: int;
/** @kphp-extern-func-info interruptible */
function component_stream_read_exact($stream ::: ComponentStream, $len ::: int) ::: string;

function component_close_stream($stream ::: ComponentStream) ::: void;
function component_finish_stream_processing($stream ::: ComponentStream) ::: void;
function component_server_send_response($query ::: ComponentQuery, $message ::: string) ::: void;

// === Json =======================================================================================

class JsonEncoder {
const rename_policy = 'none';
const visibility_policy = 'all';
const skip_if_default = false;
const float_precision = 0;

private function __construct();

public static function encode(object $instance, int $flags = 0, array $more = []) : string;
public static function decode(string $json, string $class_name) : instance<^2>;
public static function getLastError() : string;
function json_encode ($v ::: mixed, $options ::: int = 0) ::: string | false;

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

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

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

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

// === Misc =======================================================================================

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

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

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

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

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

function byte_to_int($str ::: string) ::: ?int;
function int_to_byte($v ::: int) ::: ?string;
// builtin that allows to store objects inside a mixed
function to_mixed(object $instance) ::: mixed;

function set_timer(int $timeout, callable():void $callback) ::: void;
// === Unsupported =======================================================================================

require_once __DIR__ . '/unsupported-functions.txt';
49 changes: 49 additions & 0 deletions builtin-functions/kphp-light/job-workers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

// === Job Worker =================================================================================

/** @kphp-immutable-class */
interface KphpJobWorkerSharedMemoryPiece {}

interface KphpJobWorkerRequest {}
interface KphpJobWorkerResponse {}

class KphpJobWorkerResponseError implements KphpJobWorkerResponse {
// Job script execution errors:
const JOB_MEMORY_LIMIT_ERROR = -101;
const JOB_TIMEOUT_ERROR = -102;
const JOB_EXCEPTION_ERROR = -103;
const JOB_STACK_OVERFLOW_ERROR = -104;
const JOB_PHP_ASSERT_ERROR = -105;

const JOB_CLIENT_MEMORY_LIMIT_ERROR = -1001; // client doesn't have enough memory to accept job response
const JOB_NOTHING_REPLIED_ERROR = -2001; // kphp_job_worker_store_response() was not succeeded

const JOB_STORE_RESPONSE_INCORRECT_CALL_ERROR = -3000;
const JOB_STORE_RESPONSE_NOT_ENOUGH_SHARED_MESSAGES_ERROR = -3001;
const JOB_STORE_RESPONSE_TOO_BIG_ERROR = -3002;
const JOB_STORE_RESPONSE_CANT_SEND_ERROR = -3003;

public function getError() ::: string;
public function getErrorCode() ::: int; // returns one of listed above error codes
}

/** @kphp-extern-func-info interruptible */
function kphp_job_worker_start(string $request, float $timeout): future<string> | false;

/** @kphp-extern-func-info interruptible */
function kphp_job_worker_start_no_reply(string $request, float $timeout): bool;

/** @kphp-extern-func-info interruptible */
function kphp_job_worker_start_multi(string[] $request, float $timeout): (future<string> | false)[];

/** @kphp-extern-func-info interruptible */
function kphp_job_worker_fetch_request(): string;

/** @kphp-extern-func-info interruptible */
function kphp_job_worker_store_response(string $response): int;

function is_kphp_job_workers_enabled(): bool;

function get_job_workers_number(): int;

23 changes: 23 additions & 0 deletions builtin-functions/kphp-light/unsupported-functions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require_once __DIR__ . '/unsupported/arrays.txt';
require_once __DIR__ . '/unsupported/crypto.txt';
require_once __DIR__ . '/unsupported/curl.txt';
require_once __DIR__ . '/unsupported/error.txt';
require_once __DIR__ . '/unsupported/file.txt';
require_once __DIR__ . '/unsupported/fork.txt';
require_once __DIR__ . '/unsupported/hash.txt';
require_once __DIR__ . '/unsupported/kml.txt';
require_once __DIR__ . '/unsupported/kphp-toggles.txt';
require_once __DIR__ . '/unsupported/kphp-tracing.txt';
require_once __DIR__ . '/unsupported/kphp_internal.txt';
require_once __DIR__ . '/unsupported/math.txt';
require_once __DIR__ . '/unsupported/misc.txt';
require_once __DIR__ . '/unsupported/regex.txt';
require_once __DIR__ . '/unsupported/rpc.txt';
require_once __DIR__ . '/unsupported/serialize.txt';
require_once __DIR__ . '/unsupported/server.txt';
require_once __DIR__ . '/unsupported/string.txt';
require_once __DIR__ . '/unsupported/time.txt';
require_once __DIR__ . '/unsupported/uberh3.txt';
require_once __DIR__ . '/unsupported/vkext.txt';
Loading

0 comments on commit fa4fe66

Please sign in to comment.