Commit cba475a
authored
Clean up native parser follow-ups (#394)
## 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:
```bash
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:
```php
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:
```php
$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
```bash
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`.1 parent c43113d commit cba475a
9 files changed
Lines changed: 152 additions & 222 deletions
File tree
- .github/workflows
- packages
- mysql-on-sqlite
- src/sqlite
- tests
- mysql/native
- tools
- php-ext-wp-mysql-parser
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 170 | + | |
199 | 171 | | |
200 | 172 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | 173 | | |
254 | 174 | | |
255 | 175 | | |
| |||
Lines changed: 28 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
118 | 136 | | |
119 | 137 | | |
120 | | - | |
121 | | - | |
| 138 | + | |
122 | 139 | | |
123 | 140 | | |
124 | 141 | | |
125 | 142 | | |
126 | 143 | | |
127 | 144 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 145 | + | |
139 | 146 | | |
140 | 147 | | |
141 | 148 | | |
142 | | - | |
143 | | - | |
| 149 | + | |
144 | 150 | | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 154 | + | |
159 | 155 | | |
160 | 156 | | |
161 | 157 | | |
162 | 158 | | |
163 | | - | |
164 | | - | |
| 159 | + | |
165 | 160 | | |
166 | 161 | | |
167 | 162 | | |
168 | 163 | | |
169 | | - | |
170 | | - | |
| 164 | + | |
171 | 165 | | |
172 | 166 | | |
173 | 167 | | |
174 | 168 | | |
175 | | - | |
176 | | - | |
| 169 | + | |
177 | 170 | | |
178 | 171 | | |
179 | 172 | | |
180 | | - | |
181 | | - | |
| 173 | + | |
182 | 174 | | |
183 | 175 | | |
184 | 176 | | |
185 | 177 | | |
186 | 178 | | |
187 | 179 | | |
188 | | - | |
189 | | - | |
| 180 | + | |
190 | 181 | | |
191 | 182 | | |
192 | 183 | | |
| |||
197 | 188 | | |
198 | 189 | | |
199 | 190 | | |
200 | | - | |
| 191 | + | |
201 | 192 | | |
202 | 193 | | |
203 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
| 5 | + | |
| 6 | + | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
Lines changed: 4 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1160 | 1160 | | |
1161 | 1161 | | |
1162 | 1162 | | |
1163 | | - | |
| 1163 | + | |
1164 | 1164 | | |
1165 | 1165 | | |
1166 | 1166 | | |
1167 | 1167 | | |
1168 | | - | |
1169 | | - | |
1170 | | - | |
1171 | | - | |
1172 | | - | |
1173 | | - | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
1174 | 1171 | | |
1175 | 1172 | | |
1176 | 1173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 13 | + | |
89 | 14 | | |
90 | 15 | | |
91 | 16 | | |
| |||
Lines changed: 9 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
104 | 102 | | |
105 | 103 | | |
106 | 104 | | |
| |||
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
0 commit comments