Skip to content

Commit 772fdda

Browse files
committed
Remove unpacking
1 parent 7bb7533 commit 772fdda

File tree

6 files changed

+45
-22
lines changed

6 files changed

+45
-22
lines changed

src/TL_filerefs.tl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Root
22
fileReferenceOrigins ctxs:Vector<Origin> = FileReferenceOrigins;
33

4-
origin flags:# predicate:string is_constructor:flags.0?true action:flags.1?ActionOp noop:flags.2?string = origin;
4+
origin flags:# predicate:string is_constructor:flags.0?true action:flags.1?ActionOp noop:flags.2?string needs_parent:flags.3?string parent_is_constructor:flags.4?true = origin;
55

66
// For string => TypedOp dictionaries
77
typedOpArg key:string value:TypedOp = TypedOpArg;
@@ -11,7 +11,7 @@ callOp method:string args:Vector<TypedOpArg> = ActionOp;
1111
getMessageOp flags:# peer:TypedOp id:TypedOp from_scheduled:flags.0?TypedOp = ActionOp;
1212

1313
// Field extraction path
14-
pathPart flags:# constructor:string param:string flag_abort_if_empty:flags.0?true flag_fallback_if_empty:flags.1?TypedOp flag_passthrough:flags.2?true unpack_vector:flags.3?true = PathPart;
14+
pathPart flags:# constructor:string param:string flag_abort_if_empty:flags.0?true flag_fallback_if_empty:flags.1?TypedOp flag_passthrough:flags.2?true = PathPart;
1515

1616
path parts:Vector<PathPart> = Path;
1717

@@ -21,6 +21,7 @@ path parts:Vector<PathPart> = Path;
2121
typedOp type:string op:TypedOpOp = TypedOp;
2222

2323
copyOp path:Path = TypedOpOp;
24+
copyFromParentOp path:Path = TypedOpOp;
2425

2526
getInputChannelByIdOp path:Path = TypedOpOp;
2627
getInputUserByIdOp path:Path = TypedOpOp;

src/file_ref_map.dat

-972 Bytes
Binary file not shown.

tools/FileRefExtractor/BuildMode/Ast.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ final class Ast implements BuildMode
3434
private ?string $needsParent = null;
3535

3636
public function __construct(
37-
private readonly bool $allowBackrefs,
37+
public readonly bool $allowBackrefs,
38+
public readonly bool $allowUnpacking,
3839
) {
3940
}
4041

@@ -58,8 +59,11 @@ public function addNode(TLContext $ctx, ?array $action = null, ?string $why = nu
5859
'_' => 'origin',
5960
'predicate' => $ctx->position,
6061
'is_constructor' => $ctx->isConstructor,
61-
//'needsParent' => $this->needsParent,
6262
];
63+
if ($this->needsParent !== null) {
64+
$out['needs_parent'] = $this->needsParent;
65+
$out['parent_is_constructor'] = $ctx->tl->isConstructor($this->needsParent);
66+
}
6367
if ($action !== null) {
6468
$out['action'] = $action;
6569
Assert::null($why);

tools/FileRefExtractor/FieldExtractorOp.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace danog\MadelineProto\FileRefExtractor;
2020

2121
use AssertionError;
22+
use danog\MadelineProto\FileRefExtractor\BuildMode\Ast;
2223
use danog\MadelineProto\FileRefExtractor\Ops\CopyOp;
2324
use Webmozart\Assert\Assert;
2425

@@ -67,6 +68,9 @@ final protected function buildPath(TLContext $tl): array
6768
$newPart['flag_fallback_if_empty'] = $part[2]->build($tl);
6869
} elseif (\is_int($part[2])) {
6970
if ($part[2] & self::FLAG_UNPACK_ARRAY) {
71+
if ($tl->buildMode instanceof Ast && !$tl->buildMode->allowUnpacking) {
72+
throw new AssertionError('Cannot use unpack_array flag in Ast mode with backrefs enabled');
73+
}
7074
$newPart['unpack_vector'] = true;
7175
}
7276
if ($part[2] & self::FLAG_IF_ABSENT_ABORT) {

tools/FileRefExtractor/Ops/ExtractFromParentOp.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ public function build(TLContext $tl): array
6262
$tl->buildMode->setNeedsParent($this->path[0][0]);
6363
}
6464
return [
65-
'_' => 'extractFromParentConstructor',
65+
'_' => 'typedOp',
6666
'type' => $this->getType($tl),
67-
'path' => $this->buildPath($tl),
67+
'op' => [
68+
'_' => 'copyFromParentOp',
69+
'path' => $this->buildPath($tl),
70+
],
6871
];
6972
}
7073
}

tools/gen_filerefmap.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
}
4141

4242
$storyMethods = [];
43-
/*foreach (['stories.StoryViewsList', 'stories.Stories', 'stories.PeerStories', 'stories.StoryReactionsList'] as $t) {
43+
//foreach (['stories.StoryViewsList', 'stories.Stories', 'stories.PeerStories', 'stories.StoryReactionsList'] as $t) {
44+
foreach (['stories.Stories'] as $t) {
4445
foreach ($TL->getMethodsOfType($t) as $method => $_) {
4546
$storyMethods[$method] = true;
4647
$locations['storyItem'][] = new CallOp(
@@ -51,7 +52,8 @@
5152
]
5253
);
5354
}
54-
}*/
55+
}
56+
/*
5557
foreach (['stories.Stories'] as $t) {
5658
foreach ($TL->getMethodsOfType($t) as $method => $_) {
5759
$storyMethods[$method] = true;
@@ -67,7 +69,7 @@
6769
]
6870
);
6971
}
70-
}
72+
}*/
7173

7274
$locations['storyViewPublicRepost'][] = new CallOp(
7375
'stories.getStoriesByID',
@@ -84,12 +86,20 @@
8486
]
8587
);
8688

87-
$locations['peerStories'][] = new CallOp(
89+
/*$locations['peerStories'][] = new CallOp(
8890
'stories.getStoriesByID',
8991
[
9092
'id' => new ArrayOp(new CopyOp([['peerStories', 'stories', CopyOp::FLAG_UNPACK_ARRAY], ['storyItem', 'id']])),
9193
'peer' => new GetInputPeerOp(new CopyOp([['peerStories', 'peer']])),
9294
]
95+
);*/
96+
97+
$locations['storyItem'][] = new CallOp(
98+
'stories.getStoriesByID',
99+
[
100+
'id' => new ArrayOp(new CopyOp([['storyItem', 'id']])),
101+
'peer' => new GetInputPeerOp(new ExtractFromParentOp([['peerStories', 'peer']])),
102+
]
93103
);
94104

95105
foreach (['foundStory', 'publicForwardStory', 'webPageAttributeStory', 'messageMediaStory'] as $c) {
@@ -123,7 +133,7 @@
123133
'peer' => new GetInputPeerOp(new CopyOp([['storyItem', 'from_id', CopyOp::FLAG_IF_ABSENT_ABORT]])),
124134
]);
125135
$locations['messages.getSponsoredMessages'][] = new CopyMethodCallOp('messages.getSponsoredMessages');
126-
/*$locations['channelAdminLogEvent'][] = new CallOp(
136+
$locations['channelAdminLogEvent'][] = new CallOp(
127137
'channels.getAdminLog',
128138
[
129139
'channel' => new GetInputChannelOp(new ExtractFromParentOp([['channels.getAdminLog', 'channel']])),
@@ -132,8 +142,9 @@
132142
'limit' => new PrimitiveLiteralOp('int', 1),
133143
'q' => new PrimitiveLiteralOp('string', ''),
134144
]
135-
);*/
145+
);
136146

147+
/*
137148
$locations['channels.getAdminLog'][] = new CallOp(
138149
'channels.getAdminLog',
139150
[
@@ -151,7 +162,7 @@
151162
'limit' => new PrimitiveLiteralOp('int', 1),
152163
'q' => new PrimitiveLiteralOp('string', ''),
153164
]
154-
);
165+
);*/
155166

156167
$locations['bots.getPreviewMedias'][] = new CopyMethodCallOp('bots.getPreviewMedias');
157168
$locations['bots.getPreviewInfo'][] = new CopyMethodCallOp('bots.getPreviewInfo');
@@ -194,7 +205,7 @@
194205
$starMethods = [];
195206
foreach ($TL->getMethodsOfType('payments.StarsStatus') as $method => $_) {
196207
$starMethods[$method] = true;
197-
/*$locations['starsTransaction'][] = new CallOp(
208+
$locations['starsTransaction'][] = new CallOp(
198209
'payments.getStarsTransactionsByID',
199210
[
200211
'peer' => new ExtractFromParentOp([[$method, 'peer']]),
@@ -207,7 +218,7 @@
207218
]
208219
)),
209220
]
210-
);*/
221+
);/*
211222
$locations[$method][] = new CallOp(
212223
'payments.getStarsTransactionsByID',
213224
[
@@ -229,7 +240,7 @@
229240
]
230241
)),
231242
]
232-
);
243+
);*/
233244
}
234245
$locations['attachMenuBot'][] = new CallOp(
235246
'messages.getAttachMenuBot',
@@ -307,16 +318,16 @@
307318
['hash' => new PrimitiveLiteralOp('int', 0)],
308319
);
309320

310-
/*$locations['photo'][] = new CallOp(
321+
$locations['photo'][] = new CallOp(
311322
'photos.getUserPhotos',
312323
[
313324
'user_id' => new ExtractFromParentOp([['photos.getUserPhotos', 'user_id']]),
314325
'offset' => new PrimitiveLiteralOp('int', -1),
315326
'max_id' => new CopyOp([['photo', 'id']]),
316327
'limit' => new PrimitiveLiteralOp('int', 1),
317328
]
318-
);*/
319-
329+
);
330+
/*
320331
$locations['photos.getUserPhotos'][] = new CallOp(
321332
'photos.getUserPhotos',
322333
[
@@ -329,7 +340,7 @@
329340
]),
330341
'limit' => new PrimitiveLiteralOp('int', 1),
331342
]
332-
);
343+
);*/
333344

334345
foreach (['photos.updateProfilePhoto', 'photos.uploadProfilePhoto'] as $method) {
335346
$locations[$method][] = new CallOp(
@@ -445,7 +456,7 @@
445456

446457
$validated = [];
447458

448-
$tmp = new Ast(allowBackrefs: false);
459+
$tmp = new Ast(allowBackrefs: true, allowUnpacking: true);
449460
foreach (['Document' => 'document', 'Photo' => 'photo'] as $type => $constructor) {
450461
$stack = [[$constructor, 'file_reference']];
451462
$stackTypes = [$type => 1];
@@ -533,7 +544,7 @@ static function (array $stack) use ($locations, $TL, $tmp, &$validated, $storyMe
533544
throw new AssertionError("Leftover ops!");
534545
}
535546

536-
$output = new Ast(allowBackrefs: false);
547+
$output = new Ast(allowBackrefs: true, allowUnpacking: false);
537548
foreach ($locations as $constructor => $ops) {
538549
foreach ($ops as $idx => $op) {
539550
$op->build(new TLContext($TL, $output, $constructor, $TL->isConstructor($constructor)));

0 commit comments

Comments
 (0)