VKCOM/kphp

tl2php не генерирует RpcResponse.

byteduck-exploit opened this issue · 1 comments

Столкнулся с проблемой, tl2php попросту не генерирует класс RpcResponse.
Соответственно, при сборке kPHP не может его найти:

<redacted>@MacBook-Pro--<redacted> <redacted> % kphp src/Server.php --include-dir src/generated -T tl/schema.tlo -v 3
Version: kphp2cpp compiled at Feb  8 2024 18:02:40 CET by gcc Apple LLVM 14.0.3 (clang-1403.0.22.14.1) 64-bit after commit 8e1bad64f68ebd71450245fcf79db85261bd322c 
<main-file>: /Users/<redacted>/src/Server.php

KPHP_VERBOSITY: [3]
KPHP_PATH: [/Users/<redacted>/kphp/]
KPHP_FUNCTIONS: [/Users/<redacted>/kphp/builtin-functions/_functions.txt]
KPHP_RUNTIME_SHA256: [/Users/<redacted>/kphp/objs/php_lib_version.sha256]
KPHP_MODE: [server]
KPHP_LINK_FILE: [/Users/<redacted>/kphp/objs/libkphp-full-runtime.a]
KPHP_INCLUDE_DIR: [/Users/<redacted>/src/generated/]
KPHP_DEST_DIR: [/Users/<redacted>/kphp_out/]
KPHP_USER_BINARY_PATH: []
KPHP_OUT_LIB_DIR: []
KPHP_FORCE_MAKE: [false]
KPHP_NO_MAKE: [false]
KPHP_JOBS_COUNT: [8]
KPHP_THREADS_COUNT: [8]
KPHP_GLOBALS_SPLIT_COUNT: [1024]
KPHP_TL_SCHEMA: [tl/schema.tlo]
KPHP_GEN_TL_INTERNALS: [false]
KPHP_ERROR_ON_WARNINGS: [false]
KPHP_WARNINGS_FILE: []
KPHP_WARNINGS_LEVEL: [0]
KPHP_SHOW_ALL_TYPE_ERRORS: [false]
KPHP_COLORS: [auto]
KPHP_STATS_FILE: []
KPHP_COMPILATION_METRICS_FILE: []
KPHP_VERSION_OVERRIDE: []
KPHP_PHP_CODE_VERSION: [unknown]
KPHP_CXX: [clang++]
KPHP_CXX_TOOLCHAIN_DIR: []
KPHP_EXTRA_CXXFLAGS: [-O2 -ggdb -fsigned-char]
KPHP_EXTRA_LDFLAGS: [-L/Users/<redacted>/kphp//objs/flex -ggdb -fno-lto]
KPHP_DEBUG_LEVEL: []
KPHP_ARCHIVE_CREATOR: [ar]
KPHP_DYNAMIC_INCREMENTAL_LINKAGE: [false]
KPHP_PROFILER: [0]
KPHP_ENABLE_GLOBAL_VARS_MEMORY_STATS: [false]
KPHP_ENABLE_FULL_PERFORMANCE_ANALYZE: [false]
KPHP_PRINT_RESUMABLE_GRAPH: [false]
KPHP_NO_PCH: [false]
KPHP_NO_INDEX_FILE: [false]
KPHP_SHOW_PROGRESS: [false]
KPHP_COMPOSER_ROOT: []
KPHP_COMPOSER_AUTOLOAD_DEV: [false]
KPHP_REQUIRE_FUNCTIONS_TYPING: [false]
KPHP_REQUIRE_CLASS_TYPING: [false]

Linker flags: [-L/Users/<redacted>/kphp//objs/flex -ggdb -fno-lto -lcurl -liconv -lepoll-shim -L/Users/<redacted>/kphp/build/_deps/epoll-build/src -L/opt/homebrew/lib -undefined dynamic_lookup -L/opt/homebrew/opt/openssl/lib -L/Users/<redacted>/kphp/build/_deps/kphp-timelib-src/objs -L/Users/<redacted>/kphp/build/_deps/h3-build/lib -lpcre -lre2 -lyaml-cpp -lh3 -lz -lzstd -lnghttp2 -lkphp-timelib -lssl -lcrypto /Users/<redacted>/kphp/objs/flex/libvk-flex-data.a -lpthread -lm -ldl -rdynamic]
Incremental linker flags: [-r -nostdlib]
Base directory: [/Users/<redacted>/src/]
CPP destination directory: [/Users/<redacted>/kphp_out/kphp/]
Objs destination directory: [/Users/<redacted>/kphp_out/objs/]
Binary path: [/Users/<redacted>/kphp_out/server]
Static lib name: []
Runtime SHA256: [d9bedc177936567a54d850abaa01c61152e94dd2c1db65cc2a3ddcedb52db48d]
Runtime headers: [runtime-headers.h]
C++ compiler flags default: [-Wall -O2 -ggdb -fsigned-char -iquote/Users/<redacted>/kphp/ -iquote /Users/<redacted>/kphp/objs/generated/auto/runtime -fwrapv -Wno-parentheses -Wno-trigraphs -fno-strict-aliasing -fno-omit-frame-pointer -march=armv8.2-a+crypto -Winvalid-pch -fpch-preprocess -Wno-invalid-source-encoding -std=c++17 -I/opt/homebrew/include -I/opt/homebrew/opt/openssl/include -iquote/Users/<redacted>/kphp_out/kphp/]
C++ compiler flags default SHA256: [23403d865c05bfefcb2eed948e26484d9d6afc6de24ce4650637d3ff24124084]
C++ compiler flags with debug: [-Wall -O2 -ggdb -fsigned-char -iquote/Users/<redacted>/kphp/ -iquote /Users/<redacted>/kphp/objs/generated/auto/runtime -fwrapv -Wno-parentheses -Wno-trigraphs -fno-strict-aliasing -fno-omit-frame-pointer -march=armv8.2-a+crypto -Winvalid-pch -fpch-preprocess -Wno-invalid-source-encoding -std=c++17 -I/opt/homebrew/include -I/opt/homebrew/opt/openssl/include -iquote/Users/<redacted>/kphp_out/kphp/]
C++ compiler flags with debug SHA256: [23403d865c05bfefcb2eed948e26484d9d6afc6de24ce4650637d3ff24124084]
TL namespace prefix: [VK\TL\]
TL classname prefix: [C$VK$TL$]
Generated runtime path: [/Users/<redacted>/kphp/objs/generated/auto/runtime/]
Performance report path: [/Users/<redacted>/kphp_out/performance_issues.json]
C++ compiler toolchain option: []

Starting php to cpp transpiling...
FFI parser: allocated 14 objects (9 collected as garbage)
FFI parser: allocated 14 objects (9 collected as garbage)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation error at stage: Check tl classes, gen by check-tl-classes.cpp:50
  _functions_txt:-1

Can't find tl-class 'VK\TL\RpcResponse' in schema

Compilation terminated due to errors

Собирал TL схему через:

tl-compiler -e tl/schema.tlo tl/schema.tl; 
tl2php -f -d src/generated tl/schema.tlo;

Вывод:

Generating PHP classes
  schema file: 'tl/schema.tlo'
  destination directory: 'src/generated'
  total functions: 1
  total types: 6
  anonymous types: 0
  unused and flatted types: 2
Generated 9 PHP classes

Содержимое src/generated:

<redacted>@MacBook-Pro--<redacted> generated % tree             
.
└── VK
    └── TL
        ├── RpcFunction.php
        ├── _common
        │   └── Types
        │       ├── Response.php
        │       ├── deployStatus.php
        │       └── error.php
        ├── components
        │   └── Types
        │       ├── components_DeployComponent.php
        │       └── components_web.php
        └── deployments
            └── Functions
                └── deployments_deployComponent.php

9 directories, 7 files

При этом в deployments/Functions/deployments_deployComponent.php присутствуют упоминания VK\TL\RpcResponse:

  /**
   * @kphp-inline
   *
   * @param TL\RpcResponse $response
   * @return TL\_common\Types\Response
   */
  public static function result(TL\RpcResponse $response) {
    return self::functionReturnValue($response->getResult());
  }

Попробовал собрать код из документации с небольшими изменениями(типы + @read аттрибут):

<redacted>@MacBook-Pro--<redacted> tltest % vim schema.tl                      
<redacted>@MacBook-Pro--<redacted> tltest % tl-compiler -e schema.tlo schema.tl
<redacted>@MacBook-Pro--<redacted> tltest % cat schema.tl
string ?= String;

---types---
memcache.not_found = memcache.Value;
memcache.str_value value:string = memcache.Value;

---functions---
@read memcache.get key:string = memcache.Value;
<redacted>@MacBook-Pro--<redacted> tltest % tl-compiler -e schema.tlo schema.tl
<redacted>@MacBook-Pro--<redacted> tltest % ls
schema.tl	schema.tlo
<redacted>@MacBook-Pro--<redacted> tltest % tl2php schema.tlo
Generating PHP classes
  schema file: 'schema.tlo'
  destination directory: '.'
  total functions: 1
  total types: 4
  anonymous types: 0
  unused and flatted types: 2
Generated 7 PHP classes
<redacted>@MacBook-Pro--<redacted> tltest % ls
VK		schema.tl	schema.tlo
<redacted>@MacBook-Pro--<redacted> tltest % tree VK 
VK
└── TL
    ├── RpcFunction.php
    └── memcache
        ├── Functions
        │   └── memcache_get.php
        └── Types
            ├── memcache_Value.php
            ├── memcache_not_found.php
            └── memcache_str_value.php

5 directories, 5 files
<redacted>@MacBook-Pro--<redacted> tltest % 

И даже тут его нет.
Также попробовал собрать этот же пример, только с аттрибутом @kphp:

<redacted>@MacBook-Pro--<redacted> tltest % vim schema.tl                      
<redacted>@MacBook-Pro--<redacted> tltest % tl-compiler -e schema.tlo schema.tl
<redacted>@MacBook-Pro--<redacted> tltest % cat schema.tl
string ?= String;

---types---
memcache.not_found = memcache.Value;
memcache.str_value value:string = memcache.Value;

---functions---
@kphp memcache.get key:string = memcache.Value;
<redacted>@MacBook-Pro--<redacted> tltest % tl-compiler -e schema.tlo schema.tl
<redacted>@MacBook-Pro--<redacted> tltest % ls
schema.tl	schema.tlo
<redacted>@MacBook-Pro--<redacted> tltest % tl2php schema.tlo
Generating PHP classes
  schema file: 'schema.tlo'
  destination directory: '.'
  total functions: 1
  total types: 4
  anonymous types: 0
  unused and flatted types: 2
Generated 7 PHP classes
<redacted>@MacBook-Pro--<redacted> tltest % ls
VK		schema.tl	schema.tlo
<redacted>@MacBook-Pro--<redacted> tltest % tree VK 
VK
└── TL
    ├── RpcFunction.php
    └── memcache
        ├── Functions
        │   └── memcache_get.php
        └── Types
            ├── memcache_Value.php
            ├── memcache_not_found.php
            └── memcache_str_value.php

5 directories, 5 files
<redacted>@MacBook-Pro--<redacted> tltest % 

Решил добавлением этого файла в начало своей TL схемы и перегенерацией всего.
Сначала сгенерировал всё:

/bin/zsh -c "tl-compiler -e tl/schema.tlo tl/schema.tl; tl2php -f -d src/generated tl/schema.tlo;"
Generating PHP classes
  schema file: 'tl/schema.tlo'
  destination directory: 'src/generated'
  total functions: 18
  total types: 31
  anonymous types: 0
  unused and flatted types: 12
Generated 46 PHP classes

И собрал через:

<redacted>@MacBook-Pro--<redacted> <redacted> % kphp src/Server.php --include-dir src/generated -T tl/schema.tlo --gen-tl-internals 
Starting php to cpp transpiling...

Starting make...
objs cnt = 19
objs cnt = 13
Compiling stage started...
Linking stage started...

Благодарю @okhttp за помощь в решении.