Skip to content

Commit 72161a2

Browse files
committed
More fixes
1 parent 7fcb416 commit 72161a2

6 files changed

Lines changed: 53 additions & 20 deletions

File tree

docs

Submodule docs updated 796 files

tools/FileRefExtractor/BuildMode/Ast.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ final class Ast implements BuildMode
3232
{
3333
/** @var array<string, array{name: string, type: string}> */
3434
public array $stored = [];
35-
/** @var array<string, true> */
35+
/** @var array<string, string> */
3636
public array $storedNames = [];
3737
public int $storedFlags = 0;
3838

3939
public ?string $curKey = null;
4040

4141
private array $output = [];
42-
private array $outputSchema = [];
4342
private ?string $needsParent = null;
4443

4544
public function __construct(
4645
public readonly bool $allowBackrefs,
4746
public readonly bool $allowUnpacking,
47+
private array $outputSchema = []
4848
) {
4949
}
5050

@@ -62,6 +62,15 @@ public function getOutput(): string
6262
return $serialized;
6363
}
6464

65+
private static function stringifySchema(string $constructor, array $params): string
66+
{
67+
$paramsStr = "$constructor ";
68+
foreach ($params as $name => $type) {
69+
$paramsStr .= "$name:$type ";
70+
}
71+
$paramsStr .= '= FileSource;';
72+
return $paramsStr;
73+
}
6574
public function addNode(TLContext $ctx, ?array $action = null, ?string $why = null): void
6675
{
6776
$out = [
@@ -80,24 +89,38 @@ public function addNode(TLContext $ctx, ?array $action = null, ?string $why = nu
8089

8190
$constructor = $action['stored_constructor'];
8291

83-
$paramsStr = $this->storedFlags ? "$constructor flags:# " : "$constructor ";
84-
foreach ($this->stored as $param) {
85-
$paramsStr .= "{$param['name']}:{$param['type']} ";
92+
$names = $this->storedNames;
93+
if ($this->storedFlags) {
94+
$names['flags'] = '#';
8695
}
87-
$paramsStr .= '= FileSource;';
88-
89-
$this->storedFlags = 0;
90-
$this->stored = [];
91-
$this->storedNames = [];
9296

9397
if (isset($this->outputSchema[$constructor])) {
94-
if ($this->outputSchema[$constructor] !== $paramsStr) {
95-
echo("Existing schema for $constructor ({$this->outputSchema[$constructor]}) does not match newly generated schema $paramsStr\n");
98+
foreach ($this->outputSchema[$constructor] as $name => $type) {
99+
if (isset($names[$name])) {
100+
if ($names[$name] === $type) {
101+
unset($names[$name]);
102+
} else {
103+
throw new AssertionError("Type mismatch for $constructor.$name: have {$names[$name]}, need $type");
104+
}
105+
} else if (str_starts_with($type, 'flags.')) {
106+
if ($this->storedFlags) {
107+
throw new AssertionError("Have conflicting flag $constructor.$name:$type; new schema is ".self::stringifySchema($constructor, $names));
108+
}
109+
} elseif ($name !== 'flags') {
110+
throw new AssertionError("Missing pre-existing parameter $constructor.$name for $constructor");
111+
}
112+
}
113+
foreach ($names as $name => $type) {
114+
throw new AssertionError("Leftover parameter $constructor.$name:$type for $constructor");
96115
}
97116
} else {
98-
$this->outputSchema[$constructor] = $paramsStr;
117+
$this->outputSchema[$constructor] = $names;
99118
}
100119

120+
121+
$this->storedFlags = 0;
122+
$this->stored = [];
123+
$this->storedNames = [];
101124
Assert::null($why);
102125
} elseif ($why !== null) {
103126
$out['action'] = ['_' => 'noOp', 'why' => $why];

tools/FileRefExtractor/Ops/GetMessageOp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getType(TLContext $tl): string
5858

5959
public function build(TLContext $tl): void
6060
{
61-
Assert::eq($this->peer->getType($tl), 'Peer');
61+
Assert::eq($this->peer->getType($tl), 'InputPeer');
6262
Assert::eq($this->id->getType($tl), 'int');
6363
if ($this->fromScheduled !== null) {
6464
Assert::eq($this->fromScheduled->getType($tl), 'true');

tools/FileRefExtractor/Path.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function buildPath(TLContext $tl, string $extractor): array
160160
if (isset($tl->buildMode->storedNames[$name])) {
161161
throw new AssertionError("Need custom name (already have $name) for ".json_encode($this->path));
162162
}
163-
$tl->buildMode->storedNames[$name] = true;
163+
$tl->buildMode->storedNames[$name] = $type;
164164
$tl->buildMode->stored[$serialized] = [
165165
'name' => $name,
166166
'type' => $type,

tools/gen_filerefmap.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
continue;
4444
}
4545
$locations[$constructor][] = new GetMessageOp(
46-
new CopyOp([[$constructor, 'peer_id']]),
46+
new GetInputPeerOp(new Path([[$constructor, 'peer_id']])),
4747
new CopyOp([[$constructor, 'id']]),
4848
$constructor === 'message' ? new CopyOp([[$constructor, 'from_scheduled', Path::FLAG_PASSTHROUGH]]) : null,
4949
'fileSourceMessage',
@@ -493,9 +493,19 @@
493493
unset($stack[$pos]);
494494
};
495495

496+
497+
$pre = [
498+
'fileSourceMessage' => [
499+
'flags' => '#',
500+
'from_scheduled' => 'flags.0?true',
501+
'peer' => 'long',
502+
'id' => 'int'
503+
]
504+
];
505+
496506
$validated = [];
497507

498-
$tmp = new Ast(allowBackrefs: true, allowUnpacking: true);
508+
$tmp = new Ast(allowBackrefs: true, allowUnpacking: true, outputSchema: $pre);
499509
foreach (['Document' => 'document', 'Photo' => 'photo'] as $type => $constructor) {
500510
$stack = [[$constructor, 'file_reference']];
501511
$stackTypes = [$type => 1];
@@ -583,7 +593,7 @@ static function (array $stack) use ($locations, $TL, $tmp, &$validated, $storyMe
583593
throw new AssertionError("Leftover ops!");
584594
}
585595

586-
$output = new Ast(allowBackrefs: true, allowUnpacking: false);
596+
$output = new Ast(allowBackrefs: true, allowUnpacking: false, outputSchema: $pre);
587597
foreach ($locations as $constructor => $ops) {
588598
foreach ($ops as $idx => $op) {
589599
$op->build(new TLContext($TL, $output, $constructor, $TL->isConstructor($constructor)));

0 commit comments

Comments
 (0)