Skip to content

Commit 4f5c4a2

Browse files
committed
Merge native AST identity work into Rust parser branch
2 parents 2faa18b + b47b748 commit 4f5c4a2

9 files changed

Lines changed: 667 additions & 448 deletions

File tree

.github/workflows/mysql-parser-extension-tests.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,31 @@ jobs:
144144
$parser = $driver->create_parser( "SELECT 1" );
145145
$parser->next_query();
146146
$ast = $parser->get_query_ast();
147-
$property = ( new ReflectionClass( $ast ) )->getProperty( "native_ast" );
148-
$property->setAccessible( true );
149-
$native_ast = $property->getValue( $ast );
150-
if ( ! is_object( $native_ast ) || "WP_MySQL_Native_Ast" !== get_class( $native_ast ) ) {
147+
if ( ! ( $ast instanceof WP_MySQL_Native_Parser_Node ) ) {
151148
fwrite( STDERR, "SQLite driver did not return a native-backed AST.\n" );
152149
exit( 1 );
153150
}
151+
$reflection = new ReflectionObject( $ast );
152+
if ( $reflection->hasProperty( "native_ast" ) || $reflection->hasProperty( "native_node_index" ) ) {
153+
fwrite( STDERR, "Native wrapper still stores Rust AST handle properties.\n" );
154+
exit( 1 );
155+
}
156+
$first = $ast->get_first_child_node();
157+
if ( ! ( $first instanceof WP_MySQL_Native_Parser_Node ) ) {
158+
fwrite( STDERR, "Native wrapper did not return a native-backed child node.\n" );
159+
exit( 1 );
160+
}
161+
if ( $first !== $ast->get_first_child_node() ) {
162+
fwrite( STDERR, "Native wrapper identity is not stable across reads.\n" );
163+
exit( 1 );
164+
}
165+
$synthetic = new WP_Parser_Node( 0, "synthetic" );
166+
$first->append_child( $synthetic );
167+
$same_first = $ast->get_first_child_node();
168+
if ( $same_first !== $first || ! in_array( $synthetic, $same_first->get_children(), true ) ) {
169+
fwrite( STDERR, "Materialized native wrapper was lost from the parent cache.\n" );
170+
exit( 1 );
171+
}
154172
'
155173
156174
- name: Run PHPUnit tests with SQLite driver using parser extension

.github/workflows/phpunit-tests-run.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,31 @@ jobs:
3838
else
3939
TAG="version-${VERSION}"
4040
fi
41-
wget -O sqlite.tar.gz "https://sqlite.org/src/tarball/sqlite.tar.gz?r=${TAG}"
41+
SQLITE_SOURCE="https://sqlite.org/src/tarball/sqlite.tar.gz?r=${TAG}"
42+
SQLITE_MIRROR="https://github.com/sqlite/sqlite/archive/refs/tags/${TAG}.tar.gz"
43+
DOWNLOADED=0
44+
for url in "$SQLITE_SOURCE" "$SQLITE_MIRROR"; do
45+
for attempt in 1 2 3 4 5; do
46+
if wget -O sqlite.tar.gz "$url"; then
47+
DOWNLOADED=1
48+
break 2
49+
fi
50+
if [ "$attempt" -lt 5 ]; then
51+
sleep $(( attempt * 10 ))
52+
fi
53+
done
54+
done
55+
if [ "$DOWNLOADED" -ne 1 ]; then
56+
exit 1
57+
fi
4258
tar xzf sqlite.tar.gz
59+
if [ ! -d sqlite ]; then
60+
SQLITE_DIR=$(find . -maxdepth 1 -type d -name 'sqlite-*' | head -n 1)
61+
if [ -z "$SQLITE_DIR" ]; then
62+
exit 1
63+
fi
64+
mv "$SQLITE_DIR" sqlite
65+
fi
4366
cd sqlite
4467
./configure --prefix=/usr/local CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS5 -DSQLITE_USE_URI -DSQLITE_ENABLE_JSON1" LDFLAGS="-lm"
4568
make -j$(nproc)

.github/workflows/wp-tests-phpunit-native-extension-setup.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,36 @@ $driver = new WP_PDO_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=wp;'
125125
$parser = $driver->create_parser( 'SELECT 1' );
126126
$parser->next_query();
127127
$ast = $parser->get_query_ast();
128-
$property = ( new ReflectionClass( $ast ) )->getProperty( 'native_ast' );
129-
$property->setAccessible( true );
130-
$native_ast = $property->getValue( $ast );
131128
132-
if ( ! is_object( $native_ast ) || 'WP_MySQL_Native_Ast' !== get_class( $native_ast ) ) {
129+
if ( ! ( $ast instanceof WP_MySQL_Native_Parser_Node ) ) {
133130
fwrite( STDERR, "WordPress PHP test container did not select the native-backed AST.\n" );
134131
exit( 1 );
135132
}
133+
134+
$reflection = new ReflectionObject( $ast );
135+
if ( $reflection->hasProperty( 'native_ast' ) || $reflection->hasProperty( 'native_node_index' ) ) {
136+
fwrite( STDERR, "Native wrapper still stores Rust AST handle properties.\n" );
137+
exit( 1 );
138+
}
139+
140+
$first = $ast->get_first_child_node();
141+
if ( ! ( $first instanceof WP_MySQL_Native_Parser_Node ) ) {
142+
fwrite( STDERR, "Native wrapper did not return a native-backed child node.\n" );
143+
exit( 1 );
144+
}
145+
146+
if ( $first !== $ast->get_first_child_node() ) {
147+
fwrite( STDERR, "Native wrapper identity is not stable across reads.\n" );
148+
exit( 1 );
149+
}
150+
151+
$synthetic = new WP_Parser_Node( 0, 'synthetic' );
152+
$first->append_child( $synthetic );
153+
$same_first = $ast->get_first_child_node();
154+
if ( $same_first !== $first || ! in_array( $synthetic, $same_first->get_children(), true ) ) {
155+
fwrite( STDERR, "Materialized native wrapper was lost from the parent cache.\n" );
156+
exit( 1 );
157+
}
136158
EOF
137159

138160
node tools/local-env/scripts/docker.js run --rm php php -m | grep -qx 'wp_mysql_parser'

packages/mysql-on-sqlite/src/load.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
if ( class_exists( 'WP_MySQL_Native_Parser', false ) ) {
2929
require_once __DIR__ . '/mysql/native/mysql-rust-bridge.php';
30-
require_once __DIR__ . '/mysql/native/class-wp-mysql-native-ast-cache.php';
3130
require_once __DIR__ . '/mysql/native/class-wp-mysql-native-parser-node.php';
3231
require_once __DIR__ . '/mysql/native/class-wp-mysql-parser.php';
3332
} else {

packages/mysql-on-sqlite/src/mysql/native/class-wp-mysql-native-ast-cache.php

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

0 commit comments

Comments
 (0)