packages/deriver/tests/Unit/Deriver/Evaluator/Execution/Demand/DiscoveryTest.php
1<?php
2
3declare (strict_types=1);
4
5namespace Tests\Unit\Deriver\Evaluator\Execution\Demand;
6
7use Deriver\Deriver\Contributions;
8use Deriver\Deriver\DeriverConfig;
9use Deriver\Deriver\Evaluator\Call\BoundInstruction;
10use Deriver\Deriver\Evaluator\Call\Evaluators;
11use Deriver\Deriver\Evaluator\Call\Extensions;
12use Deriver\Deriver\Evaluator\Call\Registrations;
13use Deriver\Deriver\Evaluator\Call\StateRegistry;
14use Deriver\Deriver\Evaluator\EvaluatorConfig;
15use Deriver\Deriver\Evaluator\Evidence\Frontier;
16use Deriver\Deriver\Evaluator\Execution\Context;
17use Deriver\Deriver\Evaluator\Execution\Demand\Discovery;
18use Deriver\Deriver\Evaluator\Execution\EvaluatorConfig as ExecutionEvaluatorConfig;
19use Deriver\Deriver\Evaluator\Request\Budget;
20use Deriver\Deriver\Evaluator\Request\Query;
21use Deriver\Deriver\Evaluator\Request\QueryScope;
22use Deriver\Deriver\Evaluator\Request\ReturnQuery;
23use Deriver\Deriver\Evaluator\Request\StateQuery;
24use Deriver\Deriver\Evaluator\Request\TupleQuery;
25use Deriver\Deriver\Evaluator\Request\ValueQuery;
26use Deriver\Deriver\Evaluator\TargetProfile;
27use Deriver\Deriver\Evaluator\Term;
28use Deriver\Deriver\Execution\QueryExecution;
29use Deriver\Deriver\Lowerer\CallLowering;
30use Deriver\Deriver\Lowerer\Declaration\CallableIdentity;
31use Deriver\Deriver\Lowerer\Declaration\CallableSource;
32use Deriver\Deriver\Lowerer\Declaration\Index;
33use Deriver\Deriver\Lowerer\Declaration\Indexer;
34use Deriver\Deriver\Lowerer\Declaration\Traits\Composition;
35use Deriver\Deriver\Lowerer\ExpressionLowering;
36use Deriver\Deriver\Lowerer\Graph\Argument;
37use Deriver\Deriver\Lowerer\Graph\BasicBlock;
38use Deriver\Deriver\Lowerer\Graph\CallableGraph;
39use Deriver\Deriver\Lowerer\Graph\ExpressionRef;
40use Deriver\Deriver\Lowerer\Graph\Instruction;
41use Deriver\Deriver\Lowerer\Graph\ObservationPhase;
42use Deriver\Deriver\Lowerer\Graph\PointRef;
43use Deriver\Deriver\Lowerer\Graph\Terminator;
44use Deriver\Deriver\Lowerer\Graph\TerminatorKind;
45use Deriver\Deriver\Lowerer\InstructionEmitter;
46use Deriver\Deriver\Lowerer\Lowerer;
47use Deriver\Deriver\Lowerer\LoweringScope;
48use Deriver\Deriver\Lowerer\StatementLowering;
49use Deriver\Deriver\MicroEvaluatorConversion;
50use Deriver\Deriver\Parser\Node\File;
51use Deriver\Deriver\Parser\Parser;
52use Deriver\Deriver\Parser\ParserConfig;
53use Deriver\Deriver\Parser\TargetSyntax;
54use Deriver\Deriver\Providers\ProviderExpansion;
55use Deriver\Deriver\Resolver\AssignmentPatterns;
56use Deriver\Deriver\Resolver\ClassScope;
57use Deriver\Deriver\Resolver\ExpressionValidation;
58use Deriver\Deriver\Resolver\MagicContext;
59use Deriver\Deriver\Resolver\Resolver;
60use Deriver\Deriver\SnapshotIdentity;
61use Deriver\Deriver\Sources\LineMap;
62use Deriver\Deriver\Sources\Path;
63use Deriver\Deriver\Sources\Source;
64use Deriver\Deriver\Sources\SourceRef;
65use Deriver\Deriver\Sources\Sources;
66use Deriver\Exception\ParserException;
67use Deriver\Exception\ResolutionException;
68use PHPUnit\Framework\Attributes\CoversClass;
69use PHPUnit\Framework\Attributes\DataProvider;
70use PHPUnit\Framework\Attributes\Small;
71use PHPUnit\Framework\Attributes\UsesClass;
72use PHPUnit\Framework\TestCase;
73
74/**
75 * @covers \Deriver\Deriver\Evaluator\Execution\Demand\Discovery
76 */
77#[UsesClass(Resolver::class)]
78#[UsesClass(ExpressionValidation::class)]
79#[UsesClass(ResolutionException::class)]
80#[UsesClass(ParserConfig::class)]
81#[UsesClass(ParserException::class)]
82#[CoversClass(Discovery::class)]
83#[UsesClass(Argument::class)]
84#[UsesClass(BasicBlock::class)]
85#[UsesClass(CallableGraph::class)]
86#[UsesClass(CallableIdentity::class)]
87#[UsesClass(Instruction::class)]
88#[UsesClass(Terminator::class)]
89#[UsesClass(Context::class)]
90#[UsesClass(Extensions::class)]
91#[UsesClass(Evaluators::class)]
92#[UsesClass(StateRegistry::class)]
93#[UsesClass(DeriverConfig::class)]
94#[UsesClass(Sources::class)]
95#[UsesClass(Path::class)]
96#[UsesClass(Source::class)]
97#[UsesClass(TargetProfile::class)]
98#[UsesClass(Budget::class)]
99#[UsesClass(QueryScope::class)]
100#[UsesClass(ReturnQuery::class)]
101#[UsesClass(StateQuery::class)]
102#[UsesClass(TupleQuery::class)]
103#[UsesClass(ValueQuery::class)]
104#[UsesClass(SourceRef::class)]
105#[UsesClass(Frontier::class)]
106#[UsesClass(Parser::class)]
107#[UsesClass(File::class)]
108#[UsesClass(CallLowering::class)]
109#[UsesClass(Lowerer::class)]
110#[UsesClass(ExpressionLowering::class)]
111#[UsesClass(InstructionEmitter::class)]
112#[UsesClass(LoweringScope::class)]
113#[UsesClass(StatementLowering::class)]
114#[UsesClass(CallableSource::class)]
115#[UsesClass(Indexer::class)]
116#[UsesClass(Index::class)]
117#[UsesClass(Composition::class)]
118#[UsesClass(LineMap::class)]
119#[UsesClass(MagicContext::class)]
120#[UsesClass(AssignmentPatterns::class)]
121#[UsesClass(ClassScope::class)]
122#[UsesClass(TargetSyntax::class)]
123#[UsesClass(Term::class)]
124#[Small]
125final class DiscoveryTest extends TestCase
126{
127 public function testInstructionsRetainsAnUnusedCallButOmitsAnUnusedLiteral(): void
128 {
129 $source = '<?php function target(){999; sideEffect(); return 1;}';
130 $budget = new Budget();
131 $configuration = new DeriverConfig();
132 $contributions = new Contributions();
133 $input = new Sources([new Source('fixture.php', $source)]);
134 $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
135 $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
136 $contributions1 = $providers->contributions;
137 $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
138 $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
139 $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
140 $snapshotId = $identity->id;
141 $input1 = $providers->input;
142 $parser = new Parser(new ParserConfig($target->version));
143 $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(Path::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
144 $program1 = new Index($snapshotId, $trees);
145 $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
146 $snapshotId1 = 'test';
147 $input2 = new Sources([new Source('fixture.php', $source)]);
148 $profile = $execution->configuration->target;
149 $parser1 = new Parser(new ParserConfig($profile->version));
150 $trees1 = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser1->parse(new Source(Path::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input2, false));
151 $program = new Index($snapshotId1, $trees1);
152 $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
153 $body = $context->program->callable('target');
154 self::assertNotNull($body);
155 $instructions = (new Discovery($context))->instructions($body);
156 self::assertArrayNotHasKey($body->blocks[0]->instructions[0]->id, $instructions);
157 self::assertArrayHasKey($body->blocks[0]->instructions[2]->id, $instructions);
158 self::assertArrayHasKey($body->blocks[0]->instructions[3]->id, $instructions);
159 }
160 public function testRootRetainsThrowingOperatorsWithoutAResultUse(): void
161 {
162 $source = '<?php function target(){return 1;}';
163 $budget = new Budget();
164 $configuration = new DeriverConfig();
165 $contributions = new Contributions();
166 $input = new Sources([new Source('fixture.php', $source)]);
167 $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
168 $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
169 $contributions1 = $providers->contributions;
170 $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
171 $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
172 $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
173 $snapshotId = $identity->id;
174 $input1 = $providers->input;
175 $parser = new Parser(new ParserConfig($target->version));
176 $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(Path::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
177 $program1 = new Index($snapshotId, $trees);
178 $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
179 $snapshotId1 = 'test';
180 $input2 = new Sources([new Source('fixture.php', $source)]);
181 $profile = $execution->configuration->target;
182 $parser1 = new Parser(new ParserConfig($profile->version));
183 $trees1 = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser1->parse(new Source(Path::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input2, false));
184 $program = new Index($snapshotId1, $trees1);
185 $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
186 $body = $context->program->callable('target');
187 self::assertNotNull($body);
188 $instruction = new BoundInstruction('division', 'binary', $body->source, 'unused', name: '/');
189 self::assertTrue((new Discovery($context))->root($body, $instruction));
190 }
191 #[DataProvider('providerObservationRoots')]
192 public function testRootSelectsOnlyTheRequestedPureObservation(Query $query, string $symbol, bool $expected): void
193 {
194 $source1 = '<?php function target(){return 1;}';
195 $budget = new Budget();
196 $configuration = new DeriverConfig();
197 $contributions = new Contributions();
198 $input = new Sources([new Source('fixture.php', $source1)]);
199 $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
200 $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
201 $contributions1 = $providers->contributions;
202 $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
203 $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
204 $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
205 $snapshotId = $identity->id;
206 $input1 = $providers->input;
207 $parser = new Parser(new ParserConfig($target->version));
208 $trees = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser->parse(new Source(Path::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input1, false));
209 $program1 = new Index($snapshotId, $trees);
210 $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
211 $snapshotId1 = 'test';
212 $input2 = new Sources([new Source('fixture.php', $source1)]);
213 $profile = $execution->configuration->target;
214 $parser1 = new Parser(new ParserConfig($profile->version));
215 $trees1 = array_map(static fn (Source $source3): File => (new Resolver())->resolve($parser1->parse(new Source(Path::normalize($source3->path), $source3->contents, $source3->declarationsOnly))), iterator_to_array($input2, false));
216 $program = new Index($snapshotId1, $trees1);
217 $fixture = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
218 $context = new Context($fixture->program, $query, $fixture->configuration, $fixture->evaluators);
219 $source = new SourceRef('test', 'fixture.php', 0, 1);
220 $body = new CallableGraph($symbol, [], [], $source);
221 $instruction = new BoundInstruction('selected', 'constant', $source, 'value');
222 self::assertSame($expected, (new Discovery($context))->root($body, $instruction));
223 }
224 /**
225 * @return iterable<string,array{Query,string,bool}>
226 */
227 public static function providerObservationRoots(): iterable
228 {
229 $source = new SourceRef('test', 'fixture.php', 0, 1);
230 $expression = new ExpressionRef($source, '\N\TARGET', 'value');
231 $point = new PointRef($source, '\N\TARGET', 'selected', ObservationPhase::After);
232 $elsewhere = new PointRef($source, '\N\TARGET', 'elsewhere', ObservationPhase::After);
233 yield 'return does not force unused literals' => [new ReturnQuery('N\target'), 'N\target', false];
234 yield 'value owner and register' => [new ValueQuery($expression), 'N\target', true];
235 yield 'value other owner' => [new ValueQuery($expression), 'N\other', false];
236 yield 'value other register' => [new ValueQuery(new ExpressionRef($source, 'N\target', 'other')), 'N\target', false];
237 yield 'state observation instruction' => [new StateQuery($point, 'x'), 'N\target', true];
238 yield 'state other owner' => [new StateQuery($point, 'x'), 'N\other', false];
239 yield 'state other instruction' => [new StateQuery($elsewhere, 'x'), 'N\target', false];
240 yield 'tuple instruction' => [new TupleQuery($point, []), 'N\target', true];
241 yield 'tuple demanded register' => [new TupleQuery($elsewhere, ['one' => $expression]), 'N\target', true];
242 yield 'tuple unrelated register' => [new TupleQuery($elsewhere, ['one' => new ExpressionRef($source, 'N\target', 'other')]), 'N\target', false];
243 yield 'tuple unrelated owner' => [new TupleQuery($elsewhere, ['one' => $expression]), 'N\other', false];
244 yield 'case-sensitive script' => [new ValueQuery(new ExpressionRef($source, 'script:A.php', 'value')), 'script:a.php', false];
245 }
246 public function testInstructionsFollowsArgumentsAndReferenceLocationsThroughRepeatedDependencies(): void
247 {
248 $source1 = '<?php function target(){return 1;}';
249 $budget = new Budget();
250 $configuration = new DeriverConfig();
251 $contributions = new Contributions();
252 $input = new Sources([new Source('fixture.php', $source1)]);
253 $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
254 $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
255 $contributions1 = $providers->contributions;
256 $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
257 $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
258 $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
259 $snapshotId = $identity->id;
260 $input1 = $providers->input;
261 $parser = new Parser(new ParserConfig($target->version));
262 $trees = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser->parse(new Source(Path::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input1, false));
263 $program1 = new Index($snapshotId, $trees);
264 $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
265 $snapshotId1 = 'test';
266 $input2 = new Sources([new Source('fixture.php', $source1)]);
267 $profile = $execution->configuration->target;
268 $parser1 = new Parser(new ParserConfig($profile->version));
269 $trees1 = array_map(static fn (Source $source3): File => (new Resolver())->resolve($parser1->parse(new Source(Path::normalize($source3->path), $source3->contents, $source3->declarationsOnly))), iterator_to_array($input2, false));
270 $program = new Index($snapshotId1, $trees1);
271 $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
272 $source = new SourceRef('test', 'fixture.php', 0, 1);
273 $instructions = [new BoundInstruction('argument-definition', 'constant', $source, 'argument'), new BoundInstruction('location-definition', 'constant', $source, 'address'), new BoundInstruction('receiver-definition', 'constant', $source, 'receiver'), new BoundInstruction('discarded', 'constant', $source, 'unused'), new BoundInstruction('effect', 'invoke', $source, 'result', ['receiver', 'receiver'], arguments: [new Argument('argument', location: 'address'), new Argument('argument')])];
274 $body = new CallableGraph('target', [], [new BasicBlock(0, $instructions, new Terminator(TerminatorKind::Return, 'result'))], $source);
275 $needed = (new Discovery($context))->instructions($body);
276 ksort($needed);
277 self::assertSame(['argument-definition' => true, 'effect' => true, 'location-definition' => true, 'receiver-definition' => true], $needed);
278 self::assertFalse($context->sealed);
279 self::assertSame([], $context->frontiers);
280 }
281 #[DataProvider('providerDiscoveryBudgets')]
282 public function testInstructionsStopsOnlyAfterExceedingTheNodeBudget(int $budget, int $count, bool $sealed): void
283 {
284 $source1 = '<?php function target(){return 1;}';
285 $budget1 = new Budget(nodes: $budget);
286 $configuration = new DeriverConfig();
287 $contributions = new Contributions();
288 $input = new Sources([new Source('fixture.php', $source1)]);
289 $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
290 $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
291 $contributions1 = $providers->contributions;
292 $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
293 $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
294 $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
295 $snapshotId = $identity->id;
296 $input1 = $providers->input;
297 $parser = new Parser(new ParserConfig($target->version));
298 $trees = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser->parse(new Source(Path::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input1, false));
299 $program1 = new Index($snapshotId, $trees);
300 $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
301 $snapshotId1 = 'test';
302 $input2 = new Sources([new Source('fixture.php', $source1)]);
303 $profile = $execution->configuration->target;
304 $parser1 = new Parser(new ParserConfig($profile->version));
305 $trees1 = array_map(static fn (Source $source3): File => (new Resolver())->resolve($parser1->parse(new Source(Path::normalize($source3->path), $source3->contents, $source3->declarationsOnly))), iterator_to_array($input2, false));
306 $program = new Index($snapshotId1, $trees1);
307 $context = new Context($program, new ReturnQuery('target', budget: $budget1), $execution->configuration, $execution->evaluators);
308 $source = new SourceRef('test', 'fixture.php', 0, 1);
309 $instructions = [new BoundInstruction('first', 'invoke', $source, 'one'), new BoundInstruction('second', 'invoke', $source, 'two'), new BoundInstruction('third', 'invoke', $source, 'three')];
310 $body = new CallableGraph('target', [], [new BasicBlock(0, $instructions, new Terminator(TerminatorKind::Return, 'three'))], $source);
311 $needed = (new Discovery($context))->instructions($body);
312 self::assertCount($count, $needed);
313 self::assertSame($sealed, $context->sealed);
314 self::assertSame($sealed, $context->frontiers !== []);
315 }
316 /**
317 * @return iterable<string,array{int,int,bool}>
318 */
319 public static function providerDiscoveryBudgets(): iterable
320 {
321 yield 'exact fit' => [3, 3, false];
322 yield 'last node exceeds limit' => [2, 3, true];
323 yield 'stop before all roots' => [1, 2, true];
324 }
325 public function testObservationDemandsOnlyTheRequestedPureRegister(): void
326 {
327 $source = '<?php function target(){return 1;}';
328 $budget = new Budget();
329 $configuration = new DeriverConfig();
330 $contributions = new Contributions();
331 $input = new Sources([new Source('fixture.php', $source)]);
332 $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
333 $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
334 $contributions1 = $providers->contributions;
335 $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
336 $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
337 $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
338 $snapshotId = $identity->id;
339 $input1 = $providers->input;
340 $parser = new Parser(new ParserConfig($target->version));
341 $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(Path::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
342 $program1 = new Index($snapshotId, $trees);
343 $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
344 $snapshotId1 = 'test';
345 $input2 = new Sources([new Source('fixture.php', $source)]);
346 $profile = $execution->configuration->target;
347 $parser1 = new Parser(new ParserConfig($profile->version));
348 $trees1 = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser1->parse(new Source(Path::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input2, false));
349 $program = new Index($snapshotId1, $trees1);
350 $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
351 $body = $context->program->callable('target');
352 self::assertNotNull($body);
353 $instruction = $body->blocks[0]->instructions[0];
354 $query = new ValueQuery(new ExpressionRef($instruction->source, $body->symbol, $instruction->result));
355 self::assertTrue((new Discovery($context))->observation($query, $body, $instruction));
356 self::assertFalse((new Discovery($context))->observation(new ReturnQuery('target'), $body, $instruction));
357 }
358}
359