forked from ircmaxell/php-compiler
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompile.php
More file actions
executable file
·912 lines (880 loc) · 44.2 KB
/
Copy pathcompile.php
File metadata and controls
executable file
·912 lines (880 loc) · 44.2 KB
1
2
3
4
5
6
7
8
9
10
11
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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
199
200
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
<?php
declare(strict_types=1);
/**
* This file is part of PHP-Compiler, a PHP CFG Compiler for PHP code
*
* @copyright 2015 Anthony Ferrara. All rights reserved
* @license MIT See LICENSE at the root of the project for more info
*/
use PHPCompiler\Runtime;
use PHPCompiler\Web\DeployRoot;
use PHPCompiler\Web\LiteralIncludeDiscovery;
use PHPCompiler\Web\SourceBundler;
use PHPCompiler\Web\Superglobals;
/**
* True when bin/compile.php is building a user/test fixture binary (not bootstrap/self-host spine).
*/
/**
* Self-host spine / inventory emit drivers: do not mega-concat via SourceBundler
* (OOM past 6–24GiB in lib/JIT.php; #8391, #8559, #23970). Native argv drivers
* compile the entry file and fold literal includes incrementally via JIT
* IncludeHelper. compile_driver also needs PHP_COMPILER_HELPER_RUNTIME_O so
* helper ABIs (phpc_str_replace, …) resolve from the prelinked cache.
*/
function phpc_compile_skip_aot_bundle(string $normalized): bool
{
if ('' === $normalized) {
return false;
}
if (str_contains($normalized, 'test/selfhost/compiler_lib_spine_smoke/main.php')) {
return true;
}
// Mini-spine for #29111: must exercise IncludeHelper inherit (not SourceBundler)
// so REMAP=0 Literal collision on CONST_FETCH is covered.
if (str_contains($normalized, 'test/selfhost/issue_29111_const_fetch_spine/')) {
return true;
}
// Inventory compile_driver pulls Runtime's transitive closure through
// LiteralIncludeDiscovery — bundling OOMs through 24GiB (#23970).
return str_contains($normalized, 'test/selfhost/')
&& str_contains($normalized, 'compile_driver.php');
}
/** @deprecated alias for lint call sites */
function phpc_compile_skip_aot_bundle_for_lint(string $normalized): bool
{
return phpc_compile_skip_aot_bundle($normalized);
}
/**
* Content-keyed cache marker path for a self-host bundle lint, or null when
* the repo root / entry are unresolvable (#16508). Key covers the entry, its
* sibling bundle files, every lib/ext/src/bin/patches source, the patched
* vendor tree (mtime:size), and composer.lock — any source change misses.
*/
function phpc_bundle_lint_cache_path(string $filename, string $normalized): ?string
{
$root = \PHPCompiler\Config::getenv('PHP_COMPILER_REPO_ROOT');
if (!is_string($root) || '' === $root || !is_dir($root.'/lib')) {
$root = dirname(__DIR__);
}
if (!is_file($filename) || !is_dir($root.'/lib')) {
return null;
}
$parts = ['entry:'.$normalized, 'entry-sha:'.sha1_file($filename)];
$scanDirs = ['lib', 'ext', 'src', 'bin', 'patches', 'vendor/ircmaxell'];
$bundleDir = dirname($filename);
foreach ($scanDirs as $dir) {
$base = $root.'/'.$dir;
if (!is_dir($base)) {
continue;
}
$rows = [];
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($base, FilesystemIterator::SKIP_DOTS)
);
foreach ($it as $f) {
$p = $f->getPathname();
if (!str_ends_with($p, '.php') && !str_ends_with($p, '.patch')) {
continue;
}
$rows[] = substr($p, strlen($root) + 1).':'.$f->getMTime().':'.$f->getSize();
}
sort($rows, SORT_STRING);
$parts[] = $dir.":\n".implode("\n", $rows);
}
$siblings = glob($bundleDir.'/*.php') ?: [];
sort($siblings, SORT_STRING);
foreach ($siblings as $sibling) {
$parts[] = 'bundle:'.basename($sibling).':'.sha1_file($sibling);
}
$extras = [$root.'/composer.lock', $root.'/script/apply-patches.sh'];
foreach ($extras as $extra) {
$parts[] = basename($extra).':'.(is_file($extra) ? sha1_file($extra) : 'none');
}
$key = substr(hash('sha256', implode("\n", $parts)), 0, 20);
$slug = preg_replace('/[^A-Za-z0-9_.-]+/', '-', basename($bundleDir));
return $root.'/build/lint-cache/bundle-'.$slug.'-'.$key.'.ok';
}
function phpc_compile_is_user_script_aot(string $normalized): bool
{
if ('' === $normalized || '-' === $normalized
|| 'Standard input code' === $normalized
|| 'Command line code' === $normalized) {
return true;
}
if (str_contains($normalized, 'bootstrap-aot/')) {
return false;
}
if (str_contains($normalized, 'selfhost/')) {
return false;
}
if (str_contains($normalized, 'compile_driver.php')) {
return false;
}
if (str_contains($normalized, 'compiler_unit_probe')) {
return false;
}
// Zend rebuild of the production argv driver is self-host seed work, not user-script AOT.
// Treating bin/compile.php as a user script forces SELFHOST_AOT=0 and installs null
// Runtime::parse / compileEmitSmoke stubs — functional smoke then fails (#26756 / re-#23468).
if (str_ends_with($normalized, '/bin/compile.php') || 'bin/compile.php' === $normalized) {
return false;
}
// M5 argv / gen-0 seed rebuild must keep self-host compile-driver real-lowering (#26756).
$m5Host = \PHPCompiler\Config::getenv('PHP_COMPILER_M5_DRIVER_HOST');
if ('1' === $m5Host || 'true' === strtolower((string) $m5Host)) {
return false;
}
return true;
}
function phpc_compile_ensure_repo_root_env(): void
{
$existing = \PHPCompiler\Config::getenv('PHP_COMPILER_REPO_ROOT');
if (is_string($existing) && '' !== $existing && is_readable($existing.'/bin/compile.php')) {
return;
}
global $argv;
/** @var list<string> $candidates */
$candidates = [];
$cwd = getcwd();
if (is_string($cwd) && '' !== $cwd) {
$candidates[] = $cwd;
}
if (isset($argv) && is_array($argv)) {
foreach ($argv as $arg) {
if (!is_string($arg)) {
continue;
}
$norm = str_replace('\\', '/', $arg);
if ('-' === $norm || !str_ends_with($norm, '.php') || !is_readable($arg)) {
continue;
}
$candidates[] = dirname($arg);
}
}
$candidates[] = dirname(__DIR__);
$seen = [];
foreach ($candidates as $start) {
if (!is_string($start) || '' === $start || isset($seen[$start])) {
continue;
}
$seen[$start] = true;
$dir = str_replace('\\', '/', $start);
for ($depth = 0; $depth < 16; ++$depth) {
if (is_readable($dir.'/bin/compile.php') && is_readable($dir.'/lib/JIT.php')) {
$real = realpath($dir);
$root = false !== $real ? $real : $dir;
putenv('PHP_COMPILER_REPO_ROOT='.$root);
return;
}
$parent = dirname($dir);
if ($parent === $dir) {
break;
}
$dir = $parent;
}
}
}
function run(string $filename, string $code, array $options): void
{
phpc_compile_ensure_repo_root_env();
\PHPCompiler\AOT\BuildTiming::boot();
\PHPCompiler\AOT\BuildTiming::mark('boot_setup');
$normalized = '-' !== $filename ? str_replace('\\', '/', $filename) : '';
if ('' !== $normalized
&& '-' !== $filename
&& 'Standard input code' !== $filename
&& 'Command line code' !== $filename
&& !is_file($filename)) {
fwrite(STDERR, "Could not open file {$filename}\n");
exit(1);
}
if (\class_exists(\PHPCompiler\JIT\Progress::class, false)) {
\PHPCompiler\JIT\Progress::notePhase('bin_compile_run_begin');
\PHPCompiler\JIT\Progress::noteEntry($filename);
}
// When executing as a compiled native driver, default to self-host mode. Relying on getenv()
// alone is fragile in early bootstrap contexts, and the native driver is only used for the
// self-host ladder.
if (\function_exists('php_compiler_cli_should_skip_entry_driver')) {
$selfhostAot = \PHPCompiler\Config::getenv('PHP_COMPILER_SELFHOST_AOT');
if (false === $selfhostAot || '' === $selfhostAot) {
putenv('PHP_COMPILER_SELFHOST_AOT=1');
}
// Compiled argv drivers must enable the M3 compile-driver lowering allowlist; otherwise
// key Runtime entrypoints can be stubbed and compilation returns null (#3004).
$m3CompileDriver = \PHPCompiler\Config::getenv('PHP_COMPILER_M3_COMPILE_DRIVER');
if (false === $m3CompileDriver || '' === $m3CompileDriver) {
putenv('PHP_COMPILER_M3_COMPILE_DRIVER=1');
}
$m3CompileDriverMain = \PHPCompiler\Config::getenv('PHP_COMPILER_M3_COMPILE_DRIVER_MAIN');
if (false === $m3CompileDriverMain || '' === $m3CompileDriverMain) {
putenv('PHP_COMPILER_M3_COMPILE_DRIVER_MAIN=1');
}
$m4BinCompile = \PHPCompiler\Config::getenv('PHP_COMPILER_M4_BIN_COMPILE_DRIVER');
if (false === $m4BinCompile || '' === $m4BinCompile) {
putenv('PHP_COMPILER_M4_BIN_COMPILE_DRIVER=1');
}
// Do NOT auto-set PHP_COMPILER_M5_DRIVER_HOST here. Under Zend, src/cli.php also
// defines php_compiler_cli_should_skip_entry_driver, so auto-set poisoned every
// user-script AOT build: phpc_compile_is_user_script_aot returned false (#26756),
// DomDocumentLoadXML was skipped, and loadXML aborted via VmDomInstanceInvoke
// (#27039 / re-#26757). Refresh scripts export M5_DRIVER_HOST=1 explicitly
// (bootstrap-gen0-refresh-argv-driver.sh, bootstrap-selfhost-driver-host-compile.sh).
}
if ('' !== $normalized && str_contains($normalized, 'bootstrap-aot/')) {
// Bootstrap AOT fixtures require real JIT lowering; ignore inherited self-host stub env (#1086).
//
// But: if we're already running under a compiled self-host driver, forcing stub-off
// can crash before we have a chance to fall back (e.g. inventory argv driver compiling
// bootstrap-aot fixtures as part of self-host compile-smoke, #2967).
//
// Use a runtime-native marker instead of getenv(): self-host AOT execution stubs and
// env access can be unreliable precisely in the scenarios we're trying to debug.
if (!\function_exists('php_compiler_cli_should_skip_entry_driver')) {
$bootstrapAotLink = \PHPCompiler\Config::getenv('PHP_COMPILER_BOOTSTRAP_AOT_LINK');
$isBootstrapAotLink = '1' === $bootstrapAotLink || 'true' === strtolower((string) $bootstrapAotLink);
if ($isBootstrapAotLink) {
// bootstrap-aot-link: Runtime spine via self-host stubs; user FUNCDEF bodies stay real (#1492).
putenv('PHP_COMPILER_SELFHOST_AOT=1');
putenv('PHP_COMPILER_M3_COMPILE_DRIVER=1');
// Defer nested-JIT standalone bodies during inventory argv emit init (#14470).
putenv('PHP_COMPILER_M3_INVENTORY_EMIT_DRIVER=1');
putenv('BOOTSTRAP_M3_USE_INVENTORY_EMIT_DRIVER=1');
} else {
putenv('PHP_COMPILER_SELFHOST_AOT=0');
}
}
}
if ('-' !== $filename && str_contains($normalized, 'test/selfhost/')) {
$selfhostAot = \PHPCompiler\Config::getenv('PHP_COMPILER_SELFHOST_AOT');
if (false === $selfhostAot || '' === $selfhostAot) {
putenv('PHP_COMPILER_SELFHOST_AOT=1');
}
}
$bundleLintCacheFile = null;
if (isset($options['-l']) && '' !== $normalized && str_contains($normalized, 'test/selfhost/')
&& '0' !== \PHPCompiler\Config::getenv('PHP_COMPILER_BUNDLE_LINT_CACHE')) {
// Self-host bundle lints compile hundreds-to-thousands of units as one
// Script (21m+ for compiler_minimal; the spine bundle never finished a
// measured run) but are re-run verbatim by ci-fast on every invocation
// (#16508). Cache SUCCESS by content: entry + every lib/ext/src/bin
// source (mtime:size) + vendor identity. Any source change misses.
$bundleLintCacheFile = phpc_bundle_lint_cache_path($filename, $normalized);
if (null !== $bundleLintCacheFile && is_file($bundleLintCacheFile)) {
fwrite(STDERR, 'phpc lint: OK (bundle cache hit '.basename($bundleLintCacheFile).", #16508)\n");
exit(0);
}
}
// Self-host bundles need multi-GB whether we are LINTING or COMPILING them; the
// 1536M default OOMs deep inside php-cfg Traverser with no hint that the cap is
// the cause (#16508). The bump used to sit inside the `-l` branch above, so
// `bin/compile.php -o OUT test/selfhost/.../main.php` still died at 1536M.
// Inventory compile_driver emit-helper links OOM through 6G–10G when
// PHP_COMPILER_MEMORY_LIMIT is already set by ci_apply_llvm_memory_env (#23970).
if ('' !== $normalized && str_contains($normalized, 'test/selfhost/')) {
// Warm libc `_exit` before LLVM so post-emit fast-exit cannot hang on cdef (#31726).
if (\class_exists(\PHPCompiler\AOT\AotEmitFastExit::class, true)) {
\PHPCompiler\AOT\AotEmitFastExit::warmup();
}
$bundleLimit = \PHPCompiler\Config::getenv('PHP_COMPILER_MEMORY_LIMIT');
$isCompileDriver = str_contains($normalized, 'compile_driver.php');
$limitMib = static function ($limit): int {
if (false === $limit || '' === $limit || !is_string($limit)) {
return 0;
}
if (1 !== preg_match('/^(\d+)\s*([KMG])?$/i', trim($limit), $m)) {
return 0;
}
$n = (int) $m[1];
$u = strtoupper($m[2] ?? 'M');
return match ($u) {
'G' => $n * 1024,
'K' => intdiv($n, 1024),
default => $n,
};
};
// Non-driver selfhost bundles: 10G floor (compiler_minimal OOMs through
// 6G in VM/Optimizer/AssignOp since the bundle grew past ~110 units).
// Inventory compile_driver emit: 16G floor with skip-bundle (#23970).
$floorMib = $isCompileDriver ? 16384 : 10240;
$curMib = $limitMib($bundleLimit);
if ($curMib < $floorMib) {
$floor = $isCompileDriver ? '16384M' : '10G';
ini_set('memory_limit', $floor);
putenv('PHP_COMPILER_MEMORY_LIMIT='.$floor);
$_ENV['PHP_COMPILER_MEMORY_LIMIT'] = $floor;
$_SERVER['PHP_COMPILER_MEMORY_LIMIT'] = $floor;
}
}
if ('' !== $normalized && str_contains($normalized, 'selfhost/') && str_contains($normalized, 'compile_driver.php') && !isset($options['-l'])) {
putenv('PHP_COMPILER_SELFHOST_AOT=1');
putenv('PHP_COMPILER_M3_COMPILE_DRIVER=1');
putenv('PHP_COMPILER_M3_COMPILE_DRIVER_MAIN=1');
// Skip-bundle compile_driver needs split helper objects or ABIs like
// phpc_str_replace fail lookup during IncludeHelper lowering (#23970).
if (false === \PHPCompiler\Config::getenv('PHP_COMPILER_HELPER_RUNTIME_O') || '' === (string) \PHPCompiler\Config::getenv('PHP_COMPILER_HELPER_RUNTIME_O')) {
putenv('PHP_COMPILER_HELPER_RUNTIME_O=1');
$_ENV['PHP_COMPILER_HELPER_RUNTIME_O'] = '1';
$_SERVER['PHP_COMPILER_HELPER_RUNTIME_O'] = '1';
}
if (str_contains($normalized, 'compiler_helloworld_smoke/compile_driver.php')
|| str_contains($normalized, 'bootstrap_loop_smoke/compile_driver.php')) {
putenv('PHP_COMPILER_M3_EMIT_LOG_PREFIX=helloworld_compile_smoke');
} elseif (str_contains($normalized, 'runtime_compile_smoke/compile_driver.php')) {
putenv('PHP_COMPILER_M3_EMIT_LOG_PREFIX=runtime_compile_smoke_m3_emit');
putenv('PHP_COMPILER_M3_EMIT_HELPER_SPINE=1');
} elseif (str_contains($normalized, 'jit_unit_probe/compile_driver.php')) {
putenv('PHP_COMPILER_M3_EMIT_LOG_PREFIX=jit_unit_probe_m3_emit');
} elseif (str_contains($normalized, 'compile_driver.php')) {
putenv('PHP_COMPILER_M3_EMIT_LOG_PREFIX=compile_smoke_m3_emit');
}
$inventoryEmit = getenv('BOOTSTRAP_M3_USE_INVENTORY_EMIT_DRIVER') ?: \PHPCompiler\Config::getenv('PHP_COMPILER_M3_INVENTORY_EMIT_DRIVER');
if ('1' === $inventoryEmit || 'true' === strtolower((string) $inventoryEmit)) {
putenv('PHP_COMPILER_M3_INVENTORY_EMIT_DRIVER=1');
// Runtime: do not force emit-helper TU/minimal mode here.
// The inventory driver is expected to compile arbitrary sources; forcing emit-helper
// mode can route Runtime::parseAndCompile through minimal sentinel stubs and recurse (#2967).
}
}
if ('' !== $normalized && str_contains($normalized, 'jit_result_stub.php')) {
putenv('PHP_COMPILER_SELFHOST_AOT=1');
}
if ('' !== $normalized && str_contains($normalized, 'bootstrap-vendor-prelink/generated/')) {
$vendorPrelink = \PHPCompiler\Config::getenv('PHP_COMPILER_VENDOR_PRELINK');
if ('1' === $vendorPrelink || 'true' === strtolower((string) $vendorPrelink)) {
// Real-lower parse/compile for vendor bundles; avoid M3 emit-TU sidecar host-compile (#3028, #3036).
putenv('PHP_COMPILER_M3_EMIT_HELPER_SPINE=1');
putenv('PHP_COMPILER_KEEP_OBJECT_FILE=1');
}
}
$includes = $options['--include'] ?? [];
if (!is_array($includes)) {
$includes = [] === $includes || '' === $includes ? [] : [$includes];
}
/** @var list<string> $includes */
$skipBundle = phpc_compile_skip_aot_bundle($normalized);
// Latch user-script / helper-runtime env before any Runtime so CompileCache fingerprint
// and early artifact restore see the same ABI key as standalone emit (#36387).
$prevUserScriptAot = \PHPCompiler\Config::getenv('PHP_COMPILER_AOT_USER_SCRIPT');
$prevHelperRuntimeO = \PHPCompiler\Config::getenv('PHP_COMPILER_HELPER_RUNTIME_O');
$prevLanguageProfile = \PHPCompiler\Config::getenv('PHP_COMPILER_PROFILE');
$setUserScriptAot = phpc_compile_is_user_script_aot($normalized);
$inventoryArgvSeed = (str_ends_with($normalized, '/bin/compile.php') || 'bin/compile.php' === $normalized)
&& (('1' === (string) (\PHPCompiler\Config::getenv('PHP_COMPILER_M4_BIN_COMPILE_DRIVER') ?: ''))
|| 'true' === strtolower((string) (\PHPCompiler\Config::getenv('PHP_COMPILER_M4_BIN_COMPILE_DRIVER') ?: ''))
|| '1' === (string) (\PHPCompiler\Config::getenv('PHP_COMPILER_M3_INVENTORY_EMIT_DRIVER') ?: '')
|| 'true' === strtolower((string) (\PHPCompiler\Config::getenv('PHP_COMPILER_M3_INVENTORY_EMIT_DRIVER') ?: ''))
|| '1' === (string) (getenv('BOOTSTRAP_M3_USE_INVENTORY_EMIT_DRIVER') ?: '')
|| 'true' === strtolower((string) (getenv('BOOTSTRAP_M3_USE_INVENTORY_EMIT_DRIVER') ?: '')));
$needHelperRuntimeO = $setUserScriptAot
|| ($skipBundle && str_contains($normalized, 'compile_driver.php'))
|| $inventoryArgvSeed;
if ($setUserScriptAot && \function_exists('putenv')) {
putenv('PHP_COMPILER_AOT_USER_SCRIPT=1');
$_ENV['PHP_COMPILER_AOT_USER_SCRIPT'] = '1';
$_SERVER['PHP_COMPILER_AOT_USER_SCRIPT'] = '1';
\PHPCompiler\JIT\UserScriptAotEnv::latchUserScript();
// cli.php may have defaulted SELFHOST_AOT=1 for native drivers; that disables
// CompileCache::isEnabled() and blocks early artifact restore (#36387 / #26756).
$m5DriverHost = \PHPCompiler\Config::getenv('PHP_COMPILER_M5_DRIVER_HOST');
$keepSelfHostForM5 = '1' === $m5DriverHost || 'true' === strtolower((string) $m5DriverHost);
if (!$keepSelfHostForM5) {
putenv('PHP_COMPILER_SELFHOST_AOT=0');
$_ENV['PHP_COMPILER_SELFHOST_AOT'] = '0';
$_SERVER['PHP_COMPILER_SELFHOST_AOT'] = '0';
}
}
if ($needHelperRuntimeO && \function_exists('putenv')) {
$helperCache = \PHPCompiler\Config::getenv('PHP_COMPILER_HELPER_RUNTIME_O');
if (false === $helperCache || '' === (string) $helperCache) {
putenv('PHP_COMPILER_HELPER_RUNTIME_O=1');
$_ENV['PHP_COMPILER_HELPER_RUNTIME_O'] = '1';
$_SERVER['PHP_COMPILER_HELPER_RUNTIME_O'] = '1';
}
}
$clearedLanguageProfile = false;
if ($setUserScriptAot && false !== $prevLanguageProfile && '' !== (string) $prevLanguageProfile && \function_exists('putenv')) {
putenv('PHP_COMPILER_AOT_COMPILE_PROFILE='.$prevLanguageProfile);
$_ENV['PHP_COMPILER_AOT_COMPILE_PROFILE'] = $prevLanguageProfile;
$_SERVER['PHP_COMPILER_AOT_COMPILE_PROFILE'] = $prevLanguageProfile;
putenv('PHP_COMPILER_PROFILE=');
unset($_ENV['PHP_COMPILER_PROFILE'], $_SERVER['PHP_COMPILER_PROFILE']);
$clearedLanguageProfile = true;
}
$restoreUserScriptEnv = static function () use (
$setUserScriptAot,
$prevUserScriptAot,
$prevHelperRuntimeO,
$clearedLanguageProfile,
$prevLanguageProfile
): void {
if (!$setUserScriptAot || !\function_exists('putenv')) {
return;
}
if (false === $prevUserScriptAot || null === $prevUserScriptAot) {
putenv('PHP_COMPILER_AOT_USER_SCRIPT=');
unset($_ENV['PHP_COMPILER_AOT_USER_SCRIPT'], $_SERVER['PHP_COMPILER_AOT_USER_SCRIPT']);
} else {
putenv('PHP_COMPILER_AOT_USER_SCRIPT='.$prevUserScriptAot);
$_ENV['PHP_COMPILER_AOT_USER_SCRIPT'] = $prevUserScriptAot;
$_SERVER['PHP_COMPILER_AOT_USER_SCRIPT'] = $prevUserScriptAot;
}
if (false === $prevHelperRuntimeO || null === $prevHelperRuntimeO) {
putenv('PHP_COMPILER_HELPER_RUNTIME_O=');
unset($_ENV['PHP_COMPILER_HELPER_RUNTIME_O'], $_SERVER['PHP_COMPILER_HELPER_RUNTIME_O']);
} else {
putenv('PHP_COMPILER_HELPER_RUNTIME_O='.$prevHelperRuntimeO);
$_ENV['PHP_COMPILER_HELPER_RUNTIME_O'] = $prevHelperRuntimeO;
$_SERVER['PHP_COMPILER_HELPER_RUNTIME_O'] = $prevHelperRuntimeO;
}
if ($clearedLanguageProfile) {
putenv('PHP_COMPILER_PROFILE='.$prevLanguageProfile);
$_ENV['PHP_COMPILER_PROFILE'] = $prevLanguageProfile;
$_SERVER['PHP_COMPILER_PROFILE'] = $prevLanguageProfile;
putenv('PHP_COMPILER_AOT_COMPILE_PROFILE=');
unset($_ENV['PHP_COMPILER_AOT_COMPILE_PROFILE'], $_SERVER['PHP_COMPILER_AOT_COMPILE_PROFILE']);
}
};
$tryArtifactRestore = static function (string $srcPath, string $srcCode, array $opts) use ($setUserScriptAot): bool {
if (!$setUserScriptAot || isset($opts['-l']) || isset($opts['-y']) || isset($opts['--debug-symbols'])) {
return false;
}
if (!isset($opts['-o']) || true === $opts['-o'] || '' === $srcCode) {
return false;
}
if (!\PHPCompiler\JIT\CompileCache::isEnabled()) {
return false;
}
$out = (string) $opts['-o'];
$key = \PHPCompiler\JIT\CompileCache::computeKey($srcPath, $srcCode);
if (\PHPCompiler\JIT\CompileCache::tryRestoreArtifact($key, $out, $srcPath, $srcCode)) {
\PHPCompiler\AOT\Linker::assertNonEmptyRequestedOutput($out);
\PHPCompiler\AOT\BuildTiming::note('artifact_cache_hit', 1.0);
\PHPCompiler\AOT\BuildTiming::finish($out);
return true;
}
// Mid-tier: link cached aot.o when aot.bin is absent (#36387).
if (\PHPCompiler\JIT\CompileCache::tryRestoreObjectAndLink($key, $out, $srcPath, $srcCode)) {
\PHPCompiler\AOT\Linker::assertNonEmptyRequestedOutput($out);
\PHPCompiler\AOT\BuildTiming::note('object_cache_hit', 1.0);
\PHPCompiler\AOT\BuildTiming::finish($out);
return true;
}
return false;
};
// Fast warm path for single-file scripts: restore before include discovery / Runtime (#36387).
// Multi-file projects (prior entry→members map with >1 path) must not restore from entry
// bytes alone — a require()'d unit can change while the entry is unchanged (#36382 /
// IncludeHelper Composer graphs). Those hits go through project-index member hashes below.
$allowEarlyEntryArtifactRestore = true;
if (
\PHPCompiler\JIT\CompileCache::isEnabled()
&& '-' !== $filename
&& is_file($filename)
) {
$priorMembers = \PHPCompiler\JIT\CompileCache::lookupEntryMembers($filename);
if (\is_array($priorMembers) && \count($priorMembers) > 1) {
$allowEarlyEntryArtifactRestore = false;
}
}
if (
$allowEarlyEntryArtifactRestore
&& '' === $code
&& '-' !== $filename
&& is_file($filename)
&& [] === $includes
&& !$skipBundle
) {
$codeProbe = (string) file_get_contents($filename);
if ($tryArtifactRestore($filename, $codeProbe, $options)) {
$restoreUserScriptEnv();
return;
}
}
$runtime = null;
\PHPCompiler\AOT\BuildTiming::end('boot_setup');
\PHPCompiler\AOT\BuildTiming::mark('boot_bundle');
if ([] === $includes && '-' !== $filename && is_file($filename) && !$skipBundle) {
// Skip ~200ms Runtime construct when a prior build recorded members for this
// entry and the entry bytes are unchanged (config/lib edits) (#36387).
$cachedMembers = \PHPCompiler\JIT\CompileCache::isEnabled()
? \PHPCompiler\JIT\CompileCache::lookupEntryMembers($filename)
: null;
if (null !== $cachedMembers) {
$entryResolved = realpath($filename) ?: $filename;
foreach ($cachedMembers as $member) {
if ($member !== $entryResolved) {
$includes[] = $member;
}
}
\PHPCompiler\AOT\BuildTiming::note('entry_members_cache_hit', 1.0);
} else {
$runtime = new Runtime(Runtime::MODE_AOT);
$includes = LiteralIncludeDiscovery::discoverDirectAbsolutePaths($runtime, $filename);
}
}
if ([] !== $includes || ('-' !== $filename && is_file($filename))) {
$includes = \PHPCompiler\AOT\ComposerVendorMap::expandIncludesForAutoload($filename, $includes);
}
// Project member index for edit-scaffold reuse (per-file hashes → prior module.bc) (#36387).
if ('-' !== $filename && is_file($filename)) {
$memberPaths = array_values(array_unique(array_merge(
[realpath($filename) ?: $filename],
$includes
)));
\PHPCompiler\JIT\CompileCache::setProjectMembers($memberPaths);
// Warm hit from project index: skip SourceBundler when every member hash matches (#36387).
if (
!isset($options['-l'])
&& !isset($options['-y'])
&& !isset($options['--debug-symbols'])
&& isset($options['-o'])
&& true !== $options['-o']
&& \PHPCompiler\JIT\CompileCache::isEnabled()
) {
$projectId = \PHPCompiler\JIT\CompileCache::projectId($memberPaths);
$hashes = \PHPCompiler\JIT\CompileCache::memberHashes($memberPaths);
$idxFile = \PHPCompiler\JIT\CompileCache::projectIndexPath($projectId);
if (is_file($idxFile)) {
$idx = json_decode((string) file_get_contents($idxFile), true);
if (
is_array($idx)
&& ($idx['members'] ?? null) === $hashes
&& is_string($idx['key'] ?? null)
&& \PHPCompiler\JIT\CompileCache::tryRestoreArtifactByKey($idx['key'], (string) $options['-o'])
) {
\PHPCompiler\AOT\Linker::assertNonEmptyRequestedOutput((string) $options['-o']);
\PHPCompiler\AOT\BuildTiming::note('project_index_cache_hit', 1.0);
\PHPCompiler\AOT\BuildTiming::finish((string) $options['-o']);
$restoreUserScriptEnv();
return;
}
}
$scaffoldKey = \PHPCompiler\JIT\CompileCache::findEditScaffoldKey($projectId, $hashes);
if (
is_string($scaffoldKey)
&& \PHPCompiler\JIT\CompileCache::canUseEditScaffold($scaffoldKey)
) {
$prevMembers = [];
$idxReload = null;
if (isset($idx) && is_array($idx) && is_array($idx['members'] ?? null)) {
$prevMembers = $idx['members'];
} elseif (is_file($idxFile)) {
$idxReload = json_decode((string) file_get_contents($idxFile), true);
if (is_array($idxReload) && is_array($idxReload['members'] ?? null)) {
$prevMembers = $idxReload['members'];
}
}
$prevSemantic = null;
if (isset($idx) && is_array($idx) && is_array($idx['semantic_members'] ?? null)) {
$prevSemantic = $idx['semantic_members'];
} elseif (is_array($idxReload) && is_array($idxReload['semantic_members'] ?? null)) {
$prevSemantic = $idxReload['semantic_members'];
}
$currSemantic = \PHPCompiler\JIT\CompileCache::memberSemanticHashes($memberPaths);
$stripMembers = \PHPCompiler\JIT\CompileCache::diffMembersForStrip(
$prevMembers,
$hashes,
is_array($prevSemantic) ? $prevSemantic : null,
$currSemantic
);
\PHPCompiler\JIT\CompileCache::setEditChangedMembers($stripMembers);
$prevParts = null;
if (isset($idx) && is_array($idx) && is_array($idx['semantic_parts'] ?? null)) {
$prevParts = $idx['semantic_parts'];
} elseif (is_array($idxReload) && is_array($idxReload['semantic_parts'] ?? null)) {
$prevParts = $idxReload['semantic_parts'];
}
$currParts = \PHPCompiler\JIT\CompileCache::memberSemanticParts($memberPaths);
$prevFuncs = is_array($prevParts['functions'] ?? null) ? $prevParts['functions'] : null;
$prevGlue = is_array($prevParts['glue'] ?? null) ? $prevParts['glue'] : null;
\PHPCompiler\JIT\CompileCache::setEditChangedFunctions(
\PHPCompiler\JIT\CompileCache::diffFunctionsForStrip(
$prevFuncs,
$currParts['functions'],
$prevGlue,
$currParts['glue'],
$stripMembers
)
);
\PHPCompiler\JIT\CompileCache::armEditScaffold($scaffoldKey);
}
}
}
$eagerThinPregHelpers = false;
$eagerUriComposerHelpers = false;
if ([] !== $includes && !$skipBundle) {
$projectRoot = DeployRoot::findProjectRootForPath($filename);
// Large Composer graphs (Slim ~99 units): mega-concat OOMs on 8g hosts. Emit
// require_once literals and let IncludeHelper fold one file at a time (#36382).
if (SourceBundler::shouldUseIncrementalRequires($includes)) {
$unitCount = \count($includes);
$code = SourceBundler::entryWithIncrementalRequires($filename, $includes);
// Nyholm Uri::withUserInfo uses UriRawurlencodeReplaceJitHelper (no PregAotFastPath).
// Eager NestedJIT of thin preg here fattens the module before IncludeHelper, so every
// later method (and Uri itself after parse_url) stalls for minutes on LLVM (#36382).
// Instead NestedJIT Uri + ParseUrl helpers while the entry is still only require_once.
// Only for Composer-sized graphs (≥ threshold). Env-forced incremental on small apps
// (Parsedown, #36380) must not pull Uri helpers into an unrelated module.
$eagerThinPregHelpers = false;
$eagerUriComposerHelpers = $unitCount >= SourceBundler::INCREMENTAL_REQUIRES_UNIT_THRESHOLD;
fwrite(
STDERR,
'phpc build: incremental IncludeHelper requires for '.$unitCount
." units (skip SourceBundler mega-concat, #36382)\n"
);
// 1536M CI default OOMs mid-php-llvm Type.php on Slim-sized graphs; raise to
// LLVM budget before IncludeHelper lowers ~100 units into one module (#36382).
$raised = SourceBundler::ensureIncrementalProjectMemoryFloor($unitCount);
if (is_string($raised)) {
fwrite(
STDERR,
"phpc build: raised memory_limit to {$raised} for {$unitCount}-unit incremental project (#36382)\n"
);
}
} else {
[$code, $filename] = SourceBundler::bundleForAot($filename, $includes, $projectRoot);
}
if (is_string($code) && '' !== $code) {
\PHPCompiler\JIT\CompileCache::setBundledSource($code);
}
} elseif ('' === $code && '-' !== $filename && is_file($filename)) {
$code = (string) file_get_contents($filename);
}
// Bundled multi-file projects: restore after SourceBundler rewrote $code (#36387).
// Unchanged multi-member projects already returned via project-index member hashes.
// Reaching here with >1 members means a unit changed (or scaffold armed) — do not
// restore from entry/incremental-require text alone (#36382 IncludeHelper graphs:
// require_once entry bytes stay fixed while vendor units change).
if (
\count(\PHPCompiler\JIT\CompileCache::projectMembers()) <= 1
&& $tryArtifactRestore($filename, $code, $options)
) {
$restoreUserScriptEnv();
return;
}
\PHPCompiler\AOT\BuildTiming::end('boot_bundle');
\PHPCompiler\AOT\BuildTiming::mark('boot_runtime');
// Reuse discovery Runtime when present — avoid a second MODE_AOT construct (#36387).
if (!$runtime instanceof Runtime) {
$runtime = new Runtime(Runtime::MODE_AOT);
}
if ($eagerThinPregHelpers) {
$runtime->eagerThinPregHelpers = true;
fwrite(STDERR, "phpc build: eager thin preg NestedJIT before IncludeHelper graph (#36382)\n");
}
if ($eagerUriComposerHelpers) {
$runtime->eagerUriComposerHelpers = true;
fwrite(STDERR, "phpc build: eager Uri/ParseUrl NestedJIT before IncludeHelper graph (#36382)\n");
}
\PHPCompiler\AOT\BuildTiming::end('boot_runtime');
$allowlistEnv = getenv('PHP_COMPILER_AOT_INCLUDE_ALLOWLIST');
if (is_string($allowlistEnv) && '' !== $allowlistEnv) {
$allow = [];
foreach (preg_split('/\r\n|\n|\r/', $allowlistEnv) ?: [] as $line) {
$line = trim($line);
if ('' === $line) {
continue;
}
$key = realpath($line) ?: $line;
$allow[$key] = true;
$allow[$line] = true;
}
if ([] !== $allow) {
$runtime->aotIncludeAllowlist = $allow;
}
}
$queryString = $options['-q'] ?? null;
if (!is_string($queryString) || '' === $queryString) {
$fromEnv = getenv('QUERY_STRING');
if (is_string($fromEnv) && '' !== $fromEnv) {
$queryString = $fromEnv;
}
}
$postBody = $options['-p'] ?? null;
if (!is_string($postBody) || '' === $postBody) {
$bodyEnv = getenv('REQUEST_BODY');
if (is_string($bodyEnv) && '' !== $bodyEnv) {
$postBody = $bodyEnv;
}
}
$scriptFilename = null;
if (\function_exists('php_compiler_cli_is_virtual_code_filename')
? !php_compiler_cli_is_virtual_code_filename($filename)
: ('-' !== $filename && 'Standard input code' !== $filename && 'Command line code' !== $filename)) {
$resolved = realpath($filename);
if (false !== $resolved) {
$scriptFilename = $resolved;
}
}
$scriptName = \function_exists('php_compiler_cli_server_script_name')
? php_compiler_cli_server_script_name($filename, $options)
: null;
Superglobals::populateFromEnvironment(
$runtime->vmContext,
is_string($queryString) ? $queryString : null,
is_string($postBody) ? $postBody : null,
$scriptFilename,
$scriptName
);
// Warm helper-unit cache once per core fingerprint so subsequent builds skip nested helper lowering (#15889).
\PHPCompiler\AOT\BuildTiming::mark('boot_warm');
\PHPCompiler\AOT\HelperRuntimeCache::warmForUserAotBuild();
\PHPCompiler\AOT\BuildTiming::end('boot_warm');
\PHPCompiler\AOT\BuildTiming::end('boot');
\PHPCompiler\AOT\BuildTiming::mark('parse');
$block = $runtime->parseAndCompile($code, $filename);
\PHPCompiler\AOT\BuildTiming::end('parse');
if (null === $block) {
if (! isset($options['-l'])) {
$diag = \PHPCompiler\Runtime::getLastParseFailure();
if (null === $diag || '' === $diag) {
$diag = $runtime->formatParseAndCompileNullDetail(null);
}
$suffix = null !== $diag && '' !== $diag ? ' — '.$diag : '';
fwrite(STDERR, 'compile.php: parseAndCompile returned null for '.$filename.$suffix."\n");
exit(2);
}
fwrite(STDERR, "phpc lint: failed to compile {$filename}\n");
exit(1);
}
if (! isset($options['-l'])) {
if (! isset($options['-o']) || $options['-o'] === true) {
$options['-o'] = str_replace('.php', '', $filename);
}
if (isset($options['-y'])) {
$debugFile = true === $options['-y'] ? $options['-o'] : $options['-y'];
$runtime->setDebug($debugFile);
}
if (isset($options['--debug-symbols'])) {
$runtime->setAotDebugSymbols(true);
}
// Literal path for self-host AOT/JIT include folding (#54, #1492).
require_once 'lib/AOT/LinkerProcessPolyfill.php';
if (!\function_exists('phpc_run_command')) {
/**
* @param array<string, string>|null $env
*
* @return array{code:int,stdout:string,stderr:string}|null
*/
function phpc_run_command(string $command, ?array $env = null): ?array
{
return \PHPCompiler\AOT\LinkerProcessPolyfill::run($command, $env);
}
}
$prevSelfHostAot = \PHPCompiler\Config::getenv('PHP_COMPILER_SELFHOST_AOT');
$bootstrapAotFixture = '' !== $normalized && str_contains($normalized, 'bootstrap-aot/');
$bootstrapAotLink = \PHPCompiler\Config::getenv('PHP_COMPILER_BOOTSTRAP_AOT_LINK');
$isBootstrapAotLink = '1' === $bootstrapAotLink || 'true' === strtolower((string) $bootstrapAotLink);
// parseAndCompile uses real lowering (SELFHOST_AOT=0) for bootstrap-aot fixtures (#1086); standalone
// LLVM emit still needs self-host Runtime stubs when the env is explicitly `0` (#1492 bootstrap gate).
// bootstrap-aot-link sets PHP_COMPILER_BOOTSTRAP_AOT_LINK=1 to keep real lowering for user FUNCDEF bodies.
$setSelfHostAotForCompile = \function_exists('putenv') && (
false === $prevSelfHostAot
|| '' === (string) $prevSelfHostAot
|| ($bootstrapAotFixture && '0' === (string) $prevSelfHostAot && !$isBootstrapAotLink)
);
if ($setSelfHostAotForCompile && !$setUserScriptAot) {
// Keep LLVM 9 stable during AOT compilation; some lowering paths are still sensitive (#2600).
// User-script AOT (examples/*) needs real refresh helpers — skip stubs (#15624).
putenv('PHP_COMPILER_SELFHOST_AOT=1');
$_ENV['PHP_COMPILER_SELFHOST_AOT'] = '1';
$_SERVER['PHP_COMPILER_SELFHOST_AOT'] = '1';
}
if ($setUserScriptAot && \function_exists('putenv')) {
putenv('PHP_COMPILER_AOT_USER_SCRIPT=1');
$_ENV['PHP_COMPILER_AOT_USER_SCRIPT'] = '1';
$_SERVER['PHP_COMPILER_AOT_USER_SCRIPT'] = '1';
// Real CGI refresh helpers (multipart $_FILES) must not use self-host stubs (#15624).
// Never clear SELFHOST_AOT under M5 argv / gen-0 seed rebuild (#26756).
$m5DriverHost = \PHPCompiler\Config::getenv('PHP_COMPILER_M5_DRIVER_HOST');
$keepSelfHostForM5 = '1' === $m5DriverHost || 'true' === strtolower((string) $m5DriverHost);
if (!$keepSelfHostForM5) {
putenv('PHP_COMPILER_SELFHOST_AOT=0');
$_ENV['PHP_COMPILER_SELFHOST_AOT'] = '0';
$_SERVER['PHP_COMPILER_SELFHOST_AOT'] = '0';
}
// MCJIT bitcode cache is keyed on source + helper-runtime digest (#36199, #15624).
}
$prevBootstrapAotLink = \PHPCompiler\Config::getenv('PHP_COMPILER_BOOTSTRAP_AOT_LINK');
$setBootstrapAotLink = $bootstrapAotFixture && !$isBootstrapAotLink && \function_exists('putenv');
if ($setBootstrapAotLink) {
putenv('PHP_COMPILER_BOOTSTRAP_AOT_LINK=1');
$_ENV['PHP_COMPILER_BOOTSTRAP_AOT_LINK'] = '1';
$_SERVER['PHP_COMPILER_BOOTSTRAP_AOT_LINK'] = '1';
}
$aotEmitOk = false;
try {
$runtime->standalone($block, $options['-o'], $code, $filename);
\PHPCompiler\AOT\Linker::assertNonEmptyRequestedOutput((string) $options['-o']);
$aotEmitOk = true;
\PHPCompiler\AOT\BuildTiming::finish((string) $options['-o']);
} catch (\LogicException $e) {
fwrite(STDERR, $e->getMessage()."\n");
exit(2);
} finally {
if ($setUserScriptAot && \function_exists('putenv')) {
if (false === $prevUserScriptAot || null === $prevUserScriptAot) {
putenv('PHP_COMPILER_AOT_USER_SCRIPT=');
unset($_ENV['PHP_COMPILER_AOT_USER_SCRIPT'], $_SERVER['PHP_COMPILER_AOT_USER_SCRIPT']);
} else {
putenv('PHP_COMPILER_AOT_USER_SCRIPT='.$prevUserScriptAot);
$_ENV['PHP_COMPILER_AOT_USER_SCRIPT'] = $prevUserScriptAot;
$_SERVER['PHP_COMPILER_AOT_USER_SCRIPT'] = $prevUserScriptAot;
}
}
if ($setSelfHostAotForCompile) {
if (false === $prevSelfHostAot || '' === (string) $prevSelfHostAot) {
putenv('PHP_COMPILER_SELFHOST_AOT=');
unset($_ENV['PHP_COMPILER_SELFHOST_AOT'], $_SERVER['PHP_COMPILER_SELFHOST_AOT']);
} else {
putenv('PHP_COMPILER_SELFHOST_AOT='.$prevSelfHostAot);
$_ENV['PHP_COMPILER_SELFHOST_AOT'] = $prevSelfHostAot;
$_SERVER['PHP_COMPILER_SELFHOST_AOT'] = $prevSelfHostAot;
}
}
if ($setBootstrapAotLink) {
if (false === $prevBootstrapAotLink || null === $prevBootstrapAotLink) {
putenv('PHP_COMPILER_BOOTSTRAP_AOT_LINK=');
unset($_ENV['PHP_COMPILER_BOOTSTRAP_AOT_LINK'], $_SERVER['PHP_COMPILER_BOOTSTRAP_AOT_LINK']);
} else {
putenv('PHP_COMPILER_BOOTSTRAP_AOT_LINK='.$prevBootstrapAotLink);
$_ENV['PHP_COMPILER_BOOTSTRAP_AOT_LINK'] = $prevBootstrapAotLink;
$_SERVER['PHP_COMPILER_BOOTSTRAP_AOT_LINK'] = $prevBootstrapAotLink;
}
}
}
// Self-host bundle AOT: ExecutionEngine takes module ownership; PHP request
// shutdown then tears down LLVM builders/module in an order that aborts with
// `free(): invalid pointer` (exit 134) or spins after a successful link
// (#21925, #31726). Prefer Runtime::standalone() fast-exit (before $context
// dtor); this is belt-and-suspenders if that return is reached.
if ($aotEmitOk && '' !== $normalized && (
str_contains($normalized, 'test/selfhost/')
|| \PHPCompiler\AOT\ExternalMethodBind::spineChunkMode()
)) {
\PHPCompiler\AOT\AotEmitFastExit::exitAfterSuccessfulSelfhostEmit($filename, (string) $options['-o']);
}
}
if (isset($options['-l']) && null !== $bundleLintCacheFile) {
// Reached only when parseAndCompile returned a Block (lint success).
@mkdir(dirname($bundleLintCacheFile), 0755, true);
@file_put_contents(
$bundleLintCacheFile,
$normalized."\nlinted-ok " . date('c') . "\n"
);
}
$restoreUserScriptEnv();
}
if (
!(defined('PHP_COMPILER_LIB_SPINE_SMOKE') && PHP_COMPILER_LIB_SPINE_SMOKE)
&& !(\function_exists('php_compiler_cli_should_skip_entry_driver') && php_compiler_cli_should_skip_entry_driver())
) {
// Use literal require paths so self-host AOT/JIT can fold includes (#54, #1492).
require_once __DIR__.'/../src/cli.php';
php_compiler_cli_note_invocation_cwd();
chdir(__DIR__.'/..');
require_once 'src/cli.php';
require_once 'src/cli_driver.php';
php_compiler_cli_dispatch();
}