Skip to content

Commit a6045c3

Browse files
committed
Finalize
1 parent 2c6ad09 commit a6045c3

6 files changed

Lines changed: 114 additions & 86 deletions

File tree

src/TL_file_ref_map_schema.json

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,59 @@
5959
],
6060
"type": "FileReferenceMap"
6161
},
62+
{
63+
"id": "-1861181580",
64+
"predicate": "traverseParam",
65+
"params": [
66+
{
67+
"name": "flags",
68+
"type": "#"
69+
},
70+
{
71+
"name": "name",
72+
"type": "string"
73+
},
74+
{
75+
"name": "is_flag",
76+
"type": "flags.0?true"
77+
},
78+
{
79+
"name": "is_vector",
80+
"type": "flags.1?true"
81+
}
82+
],
83+
"type": "TraverseParam"
84+
},
85+
{
86+
"id": "-612602635",
87+
"predicate": "traverseConstructor",
88+
"params": [
89+
{
90+
"name": "predicate",
91+
"type": "string"
92+
},
93+
{
94+
"name": "params",
95+
"type": "Vector<TraverseParam>"
96+
}
97+
],
98+
"type": "TraversePart"
99+
},
100+
{
101+
"id": "-1816492855",
102+
"predicate": "traverseMethod",
103+
"params": [
104+
{
105+
"name": "predicate",
106+
"type": "string"
107+
},
108+
{
109+
"name": "params",
110+
"type": "Vector<TraverseParam>"
111+
}
112+
],
113+
"type": "TraversePart"
114+
},
62115
{
63116
"id": "-1637001781",
64117
"predicate": "locationIncoming",
@@ -222,37 +275,6 @@
222275
],
223276
"type": "PathPart"
224277
},
225-
{
226-
"id": "1422205210",
227-
"predicate": "traversePart",
228-
"params": [
229-
{
230-
"name": "flags",
231-
"type": "#"
232-
},
233-
{
234-
"name": "constructor",
235-
"type": "string"
236-
},
237-
{
238-
"name": "param",
239-
"type": "string"
240-
},
241-
{
242-
"name": "is_method",
243-
"type": "flags.0?true"
244-
},
245-
{
246-
"name": "is_flag",
247-
"type": "flags.1?true"
248-
},
249-
{
250-
"name": "is_vector",
251-
"type": "flags.2?true"
252-
}
253-
],
254-
"type": "TraversePart"
255-
},
256278
{
257279
"id": "204834466",
258280
"predicate": "path",

src/TL_file_ref_map_schema.tl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ vector#1cb5c415 {t:Type} # [ t ] = Vector t;
77
// Root
88
fileReferenceMap#28834873 layer:int db_schema:string db_schema_json:string locations:Vector<Location> sources:Vector<Source> skipped:Vector<SkippedSource> actions:Vector<Action> = FileReferenceMap;
99

10+
traverseParam#91109f74 flags:# name:string is_flag:flags.0?true is_vector:flags.1?true = TraverseParam;
11+
12+
traverseConstructor#db7c6cf5 predicate:string params:Vector<TraverseParam> = TraversePart;
13+
traverseMethod#93ba84c9 predicate:string params:Vector<TraverseParam> = TraversePart;
14+
1015
locationIncoming#9e6d55cb predicate:string stored_constructor:string traverse:Vector<TraversePart> = Location;
1116
locationOutgoing#53d26b0e predicate:string stored_constructor:string traverse:Vector<TraversePart> = Location;
1217

@@ -24,8 +29,6 @@ paramIsFlagPassthrough#1dc6e17d = ParamFlag;
2429

2530
pathPart#8dc6ff46 constructor:string param:string flag:ParamFlag = PathPart;
2631

27-
traversePart#54c5211a flags:# constructor:string param:string is_method:flags.0?true is_flag:flags.1?true is_vector:flags.2?true = TraversePart;
28-
2932
path#0c3586a2 parts:Vector<PathPart> = Path;
3033
pathParent#58f13684 parts:Vector<PathPart> = Path;
3134

src/file_ref_map.dat

-16 KB
Binary file not shown.

src/file_ref_map.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tools/FileRefExtractor/FileRefGenerator.php

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,10 @@ public static function generate(int $layer, string $inputSchema, string $outputF
491491
$stack[$pos][2] = $oldFlag | Path::FLAG_UNPACK_ARRAY;
492492
}
493493
if ($isMethod) {
494-
$stack[$pos][3] = true;
495494
if (!$incoming) {
496495
$onStackEnd($stack);
497496
}
498497
} else {
499-
$stack[$pos][3] = false;
500498
$recurse($onStackEnd, $t, $stack, $stackTypes, $incoming);
501499
}
502500
unset($stack[$pos]);
@@ -508,11 +506,11 @@ public static function generate(int $layer, string $inputSchema, string $outputF
508506

509507
if ($incoming) {
510508
foreach ($TL->getMethodsOfType($type, true) as $method => $data) {
511-
$stack[$pos] = [$method, '', 0, true];
509+
$stack[$pos] = [$method, '', 0];
512510
$onStackEnd($stack);
513511
}
514512
foreach ($TL->getMethodsOfType("Vector<$type>", true) as $method => $data) {
515-
$stack[$pos] = [$method, '', Path::FLAG_UNPACK_ARRAY, true];
513+
$stack[$pos] = [$method, '', Path::FLAG_UNPACK_ARRAY];
516514
$onStackEnd($stack);
517515
}
518516
}
@@ -591,7 +589,7 @@ public static function generate(int $layer, string $inputSchema, string $outputF
591589
continue;
592590
}
593591
$type = $TL->tl->getConstructors()->findByPredicate($constructor)['type'];
594-
$stack = [[$constructor, 'file_reference', 0, false]];
592+
$stack = [[$constructor, 'file_reference', 0]];
595593
$stackTypes = [$type => 1];
596594

597595
$outgoingTraversalPairs = [];
@@ -601,20 +599,14 @@ static function (array $stack) use (&$outgoingTraversalPairs): void {
601599
if ($pair[1] === 'file_reference') {
602600
continue;
603601
}
604-
$pairTraverse = Path::arrayPathToTraversePath($pair);
605-
$encoded = json_encode($pairTraverse);
606-
if (!isset($outgoingTraversalPairs[$encoded])) {
607-
$outgoingTraversalPairs[$encoded] = $pairTraverse;
608-
}
602+
$outgoingTraversalPairs[$pair[0]][$pair[1]] = $pair;
609603
}
610604
},
611605
$type,
612606
$stack,
613607
$stackTypes,
614608
false,
615609
);
616-
ksort($outgoingTraversalPairs);
617-
$outgoingTraversalPairs = array_values($outgoingTraversalPairs);
618610
$outgoingTraversalPairsByCons[$constructor] = $outgoingTraversalPairs;
619611
}
620612
unset($outgoingTraversalPairs);
@@ -623,7 +615,7 @@ static function (array $stack) use (&$outgoingTraversalPairs): void {
623615
$tmp = new Ast(blacklistedPredicates: $blacklistedPredicates, allowUnpacking: true, outputSchema: $pre);
624616
foreach ($incomingCons as $constructor => $_) {
625617
$type = ucfirst($constructor);
626-
$stack = [[$constructor, 'file_reference', 0, false]];
618+
$stack = [[$constructor, 'file_reference', 0]];
627619
$stackTypes = [$type => 1];
628620

629621
$incomingTraversalPairs = [];
@@ -640,11 +632,7 @@ static function (array $stack) use ($locations, $TL, $tmp, &$incomingTraversalPa
640632
$pair = $stack[$x];
641633

642634
if ($pair[1] !== 'file_reference') {
643-
$pairTraverse = Path::arrayPathToTraversePath($pair);
644-
$encoded = json_encode($pairTraverse);
645-
if (!isset($tmpPairs[$encoded])) {
646-
$tmpPairs[$encoded] = $pairTraverse;
647-
}
635+
$tmpPairs[$pair[0]][$pair[1]] = $pair;
648636
}
649637

650638
foreach ($locations[$pair[0]] ?? [] as $op) {
@@ -669,7 +657,10 @@ static function (array $stack) use ($locations, $TL, $tmp, &$incomingTraversalPa
669657
$slice[] = $pair;
670658
}
671659
if ($hadAnyNotNoop) {
672-
$incomingTraversalPairs += $tmpPairs;
660+
foreach ($tmpPairs as $cons => $fields) {
661+
$incomingTraversalPairs[$pair[0]] ??= [];
662+
$incomingTraversalPairs[$pair[0]] += $fields;
663+
}
673664
}
674665
if (!$hadAny) {
675666
throw new AssertionError("Uncovered path: " . json_encode($stack));
@@ -718,9 +709,6 @@ static function (array $stack) use ($locations, $TL, $tmp, &$incomingTraversalPa
718709
$stackTypes,
719710
true,
720711
);
721-
722-
ksort($incomingTraversalPairs);
723-
$incomingTraversalPairs = array_values($incomingTraversalPairs);
724712
$incomingTraversalPairsByCons[$constructor] = $incomingTraversalPairs;
725713
}
726714
unset($incomingTraversalPairs);
@@ -752,12 +740,54 @@ static function (array $stack) use ($locations, $TL, $tmp, &$incomingTraversalPa
752740
$layer,
753741
array_filter($outgoingCons),
754742
$incomingCons,
755-
$incomingTraversalPairsByCons,
756-
$outgoingTraversalPairsByCons,
743+
self::fixupTraversalPairs($TL, $incomingTraversalPairsByCons),
744+
self::fixupTraversalPairs($TL, $outgoingTraversalPairsByCons),
757745
$outputFile,
758746
$outputFileJson
759747
);
760748

761749
echo("OK $layer!\n".PHP_EOL);
762750
}
751+
752+
public static function fixupTraversalPairs(TLWrapper $TL, array $pairsByCons): array
753+
{
754+
$fixed = [];
755+
foreach ($pairsByCons as $parentCons => $pairs) {
756+
foreach ($pairs as $cons => $fields) {
757+
$newFields = [];
758+
foreach ($fields as $field => $part) {
759+
$newPart = [
760+
'_' => 'traverseParam',
761+
'name' => $field,
762+
'is_vector' => false,
763+
'is_flag' => false,
764+
];
765+
if (isset($part[2])) {
766+
if ($part[2] instanceof TypedOp) {
767+
throw new \InvalidArgumentException('Cannot use TypedOp in traverse path');
768+
} elseif (\is_int($part[2])) {
769+
if ($part[2] & Path::FLAG_UNPACK_ARRAY) {
770+
$newPart['is_vector'] = true;
771+
}
772+
if ($part[2] & Path::FLAG_IF_ABSENT_ABORT) {
773+
$newPart['is_flag'] = true;
774+
}
775+
if ($part[2] & Path::FLAG_PASSTHROUGH) {
776+
$newPart['is_flag'] = true;
777+
}
778+
}
779+
}
780+
$newFields[] = $newPart;
781+
}
782+
Assert::notEmpty($newFields);
783+
784+
$fixed[$parentCons][] = [
785+
'_' => $TL->isConstructor($cons) ? 'traverseConstructor' : 'traverseMethod',
786+
'predicate' => $cons,
787+
'params' => $newFields,
788+
];
789+
}
790+
}
791+
return $fixed;
792+
}
763793
}

tools/FileRefExtractor/Path.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
private ?string $customName = null,
3636
) {
3737
foreach ($path as $k => $elem) {
38-
if (\count($elem) !== 2 && \count($elem) !== 3 && \count($elem) !== 4) {
38+
if (\count($elem) !== 2 && \count($elem) !== 3) {
3939
throw new \InvalidArgumentException('Invalid path part: ' . json_encode($path));
4040
}
4141
if (isset($elem[2])) {
@@ -87,33 +87,6 @@ public function normalize(array $stack, string $current, bool $ignoreFlag): ?sel
8787
);
8888
}
8989

90-
public static function arrayPathToTraversePath(array $part): array
91-
{
92-
$newPart = [
93-
'_' => 'traversePart',
94-
'constructor' => $part[0],
95-
'is_method' => $part[3] ?? false,
96-
'is_vector' => false,
97-
'is_flag' => false,
98-
'param' => $part[1],
99-
];
100-
if (isset($part[2])) {
101-
if ($part[2] instanceof TypedOp) {
102-
throw new \InvalidArgumentException('Cannot use TypedOp in traverse path');
103-
} elseif (\is_int($part[2])) {
104-
if ($part[2] & self::FLAG_UNPACK_ARRAY) {
105-
$newPart['is_vector'] = true;
106-
}
107-
if ($part[2] & self::FLAG_IF_ABSENT_ABORT) {
108-
$newPart['is_flag'] = true;
109-
}
110-
if ($part[2] & self::FLAG_PASSTHROUGH) {
111-
$newPart['is_flag'] = true;
112-
}
113-
}
114-
}
115-
return $newPart;
116-
}
11790
public function buildPath(TLContext $tl, string $extractor): string
11891
{
11992
$new = [];

0 commit comments

Comments
 (0)