Skip to content

Clean up native parser follow-ups#394

Merged
adamziel merged 2 commits intotrunkfrom
codex/native-parser-followup-cleanups
May 1, 2026
Merged

Clean up native parser follow-ups#394
adamziel merged 2 commits intotrunkfrom
codex/native-parser-followup-cleanups

Conversation

@adamziel
Copy link
Copy Markdown
Collaborator

@adamziel adamziel commented May 1, 2026

What it does

Cleans up the native parser follow-up from #381 so the merged code reads as permanent code, not review scaffolding.

It replaces duplicated inline verifier logic with one tests/tools/verify-native-parser-extension.php entry point for mysql-on-sqlite. The parser-extension workflow and PHPUnit bootstrap both call the same verifier:

php -d extension=../php-ext-wp-mysql-parser/target/debug/libwp_mysql_parser.so \
  tests/tools/verify-native-parser-extension.php

It also collapses WP_PDO_MySQL_On_SQLite::create_parser() to one token selection and one parser reset/create return, and rewrites native parser test comments to describe behavior instead of PR review history.

Rationale

#381 landed functional native parser support, but a few follow-up surfaces still carried review-era wording and copied verifier blocks. That makes future changes harder to read and easier to drift: native parser routing, Rust AST handle storage, wrapper identity, and materialized child behavior were being checked in multiple places.

The verifier now pins that runtime contract from one script: extension loaded, WP_MySQL_Lexer resolves native, WP_MySQL_Parser delegates to WP_MySQL_Native_Parser, the SQLite driver returns a native-backed AST, native wrapper handle properties are absent, child identity is stable, and materialized child mutations survive.

Implementation

Added wp_sqlite_verify_native_parser_extension() with a shared delegate check:

function wp_sqlite_assert_native_parser_delegate( WP_MySQL_Parser $parser, string $context ): void {
    $reflection = new ReflectionObject( $parser );
    if ( ! $reflection->hasProperty( 'native' ) ) {
        wp_sqlite_native_parser_verification_fail( $context );
    }

    $native_property = $reflection->getProperty( 'native' );
    $native_property->setAccessible( true );
    if ( ! ( $native_property->getValue( $parser ) instanceof WP_MySQL_Native_Parser ) ) {
        wp_sqlite_native_parser_verification_fail( $context );
    }
}

WP_SQLITE_REQUIRE_NATIVE_PARSER_EXTENSION=1 in the PHPUnit bootstrap now loads that verifier instead of inlining the same checks.

create_parser() now selects tokens once:

$tokens = $lexer instanceof WP_MySQL_Native_Lexer
    ? $lexer->native_token_stream()
    : $lexer->remaining_tokens();

return $this->reset_or_create_parser( $tokens );

The WordPress PHPUnit extension setup keeps its container-specific verifier, but factors the repeated reflection checks into the same small helper shape.

Testing instructions

cargo fmt --check
bash -n .github/workflows/wp-tests-phpunit-native-extension-setup.sh
node --check .github/workflows/wp-tests-phpunit-run.js
php -l packages/mysql-on-sqlite/tests/tools/verify-native-parser-extension.php
php -l packages/mysql-on-sqlite/tests/bootstrap.php
php ./vendor/bin/phpcs .github/workflows/wp-tests-phpunit-native-extension-setup.sh packages/mysql-on-sqlite/tests/bootstrap.php packages/mysql-on-sqlite/tests/tools/verify-native-parser-extension.php packages/mysql-on-sqlite/src/sqlite/class-wp-pdo-mysql-on-sqlite.php packages/mysql-on-sqlite/tests/mysql/native/WP_MySQL_Native_Parser_Node_Identity_Tests.php packages/mysql-on-sqlite/tests/mysql/native/WP_MySQL_Parser_Instanceof_Tests.php

cd packages/mysql-on-sqlite
php -d extension=../php-ext-wp-mysql-parser/target/debug/libwp_mysql_parser.so tests/tools/verify-native-parser-extension.php
php ./vendor/bin/phpunit -c ./phpunit.xml.dist tests/mysql/native/WP_MySQL_Parser_Instanceof_Tests.php tests/mysql/native/WP_MySQL_Native_Parser_Node_Identity_Tests.php tests/mysql/native/WP_MySQL_Native_Parser_Node_Cycle_Tests.php
WP_SQLITE_REQUIRE_NATIVE_PARSER_EXTENSION=1 php -d extension=../php-ext-wp-mysql-parser/target/debug/libwp_mysql_parser.so ./vendor/bin/phpunit -c ./phpunit.xml.dist --filter 'WP_MySQL_(Native_Parser_Node_(Identity|Cycle)|Parser_Instanceof)_Tests'
php ./vendor/bin/phpunit -c ./phpunit.xml.dist tests/WP_SQLite_Driver_Query_Tests.php
WP_SQLITE_REQUIRE_NATIVE_PARSER_EXTENSION=1 php -d extension=../php-ext-wp-mysql-parser/target/debug/libwp_mysql_parser.so ./vendor/bin/phpunit -c ./phpunit.xml.dist tests/WP_SQLite_Driver_Query_Tests.php

CI is passing on 3f4153f, including the PHP 8.0-8.5 Rust-extension matrix and WordPress PHPUnit Tests / Rust extension.

@adamziel adamziel changed the title [codex] Clean up native parser follow-ups Clean up native parser follow-ups May 1, 2026
@adamziel adamziel marked this pull request as ready for review May 1, 2026 18:39
@adamziel adamziel merged commit cba475a into trunk May 1, 2026
26 of 27 checks passed
@adamziel adamziel deleted the codex/native-parser-followup-cleanups branch May 1, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant