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
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::prelude::*;
use c = metadata::common;
use cstore = metadata::cstore;
use driver::session::Session;
use e = metadata::encoder;
use metadata::decoder;
use metadata::encoder;
use metadata::tydecode;
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter};
use metadata::tyencode;
use middle::freevars::freevar_entry;
use middle::typeck::{method_origin, method_map_entry};
use middle::{ty, typeck, moves};
use middle;
use util::ppaux::ty_to_str;
use std::ebml::reader;
use std::ebml;
use std::serialize;
use std::serialize::{Encoder, Encodable, EncoderHelpers, DecoderHelpers};
use std::serialize::{Decoder, Decodable};
use syntax::ast;
use syntax::ast_map;
use syntax::ast_util::inlined_item_utils;
use syntax::ast_util;
use syntax::codemap::span;
use syntax::codemap;
use syntax::fold::*;
use syntax::fold;
use syntax;
use writer = std::ebml::writer;
#[cfg(test)] use syntax::parse;
#[cfg(test)] use syntax::print::pprust;
// Auxiliary maps of things to be encoded
pub struct Maps {
mutbl_map: middle::borrowck::mutbl_map,
root_map: middle::borrowck::root_map,
last_use_map: middle::liveness::last_use_map,
method_map: middle::typeck::method_map,
vtable_map: middle::typeck::vtable_map,
write_guard_map: middle::borrowck::write_guard_map,
moves_map: middle::moves::MovesMap,
capture_map: middle::moves::CaptureMap,
}
struct DecodeContext {
cdata: @cstore::crate_metadata,
tcx: ty::ctxt,
maps: Maps
}
struct ExtendedDecodeContext {
dcx: @DecodeContext,
from_id_range: ast_util::id_range,
to_id_range: ast_util::id_range
}
trait tr {
fn tr(&self, xcx: @ExtendedDecodeContext) -> Self;
}
trait tr_intern {
fn tr_intern(&self, xcx: @ExtendedDecodeContext) -> ast::def_id;
}
// ______________________________________________________________________
// Top-level methods.
pub fn encode_inlined_item(ecx: @e::EncodeContext,
ebml_w: writer::Encoder,
path: &[ast_map::path_elt],
ii: ast::inlined_item,
maps: Maps) {
debug!("> Encoding inlined item: %s::%s (%u)",
ast_map::path_to_str(path, ecx.tcx.sess.parse_sess.interner),
*ecx.tcx.sess.str_of(ii.ident()),
ebml_w.writer.tell());
let id_range = ast_util::compute_id_range_for_inlined_item(ii);
do ebml_w.wr_tag(c::tag_ast as uint) {
id_range.encode(&ebml_w);
encode_ast(ebml_w, simplify_ast(ii));
encode_side_tables_for_ii(ecx, maps, ebml_w, ii);
}
debug!("< Encoded inlined fn: %s::%s (%u)",
ast_map::path_to_str(path, ecx.tcx.sess.parse_sess.interner),
*ecx.tcx.sess.str_of(ii.ident()),
ebml_w.writer.tell());
}
pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
tcx: ty::ctxt,
maps: Maps,
+path: ast_map::path,
par_doc: ebml::Doc)
-> Option<ast::inlined_item> {
let dcx = @DecodeContext {
cdata: cdata,
tcx: tcx,
maps: maps
};
match par_doc.opt_child(c::tag_ast) {
None => None,
Some(ast_doc) => {
debug!("> Decoding inlined fn: %s::?",
ast_map::path_to_str(path, tcx.sess.parse_sess.interner));
let ast_dsr = &reader::Decoder(ast_doc);
let from_id_range = Decodable::decode(ast_dsr);
let to_id_range = reserve_id_range(dcx.tcx.sess, from_id_range);
let xcx = @ExtendedDecodeContext {
dcx: dcx,
from_id_range: from_id_range,
to_id_range: to_id_range
};
let raw_ii = decode_ast(ast_doc);
let ii = renumber_ast(xcx, raw_ii);
debug!("Fn named: %s", *tcx.sess.str_of(ii.ident()));
debug!("< Decoded inlined fn: %s::%s",
ast_map::path_to_str(path, tcx.sess.parse_sess.interner),
*tcx.sess.str_of(ii.ident()));
ast_map::map_decoded_item(tcx.sess.diagnostic(),
dcx.tcx.items, path, ii);
decode_side_tables(xcx, ast_doc);
match ii {
ast::ii_item(i) => {
debug!(">>> DECODED ITEM >>>\n%s\n<<< DECODED ITEM <<<",
syntax::print::pprust::item_to_str(i, tcx.sess.intr()));
}
_ => { }
}
Some(ii)
}
}
}
// ______________________________________________________________________
// Enumerating the IDs which appear in an AST
fn reserve_id_range(sess: Session,
from_id_range: ast_util::id_range) -> ast_util::id_range {
// Handle the case of an empty range:
if ast_util::empty(from_id_range) { return from_id_range; }
let cnt = from_id_range.max - from_id_range.min;
let to_id_min = sess.parse_sess.next_id;
let to_id_max = sess.parse_sess.next_id + cnt;
sess.parse_sess.next_id = to_id_max;
ast_util::id_range { min: to_id_min, max: to_id_min }
}
pub impl ExtendedDecodeContext {
fn tr_id(&self, id: ast::node_id) -> ast::node_id {
/*!
*
* Translates an internal id, meaning a node id that is known
* to refer to some part of the item currently being inlined,
* such as a local variable or argument. All naked node-ids
* that appear in types have this property, since if something
* might refer to an external item we would use a def-id to
* allow for the possibility that the item resides in another
* crate.
*/
// from_id_range should be non-empty
assert!(!ast_util::empty(self.from_id_range));
(id - self.from_id_range.min + self.to_id_range.min)
}
fn tr_def_id(&self, did: ast::def_id) -> ast::def_id {
/*!
*
* Translates an EXTERNAL def-id, converting the crate number
* from the one used in the encoded data to the current crate
* numbers.. By external, I mean that it be translated to a
* reference to the item in its original crate, as opposed to
* being translated to a reference to the inlined version of
* the item. This is typically, but not always, what you
* want, because most def-ids refer to external things like
* types or other fns that may or may not be inlined. Note
* that even when the inlined function is referencing itself
* recursively, we would want `tr_def_id` for that
* reference--- conceptually the function calls the original,
* non-inlined version, and trans deals with linking that
* recursive call to the inlined copy.
*
* However, there are a *few* cases where def-ids are used but
* we know that the thing being referenced is in fact *internal*
* to the item being inlined. In those cases, you should use
* `tr_intern_def_id()` below.
*/
decoder::translate_def_id(self.dcx.cdata, did)
}
fn tr_intern_def_id(&self, did: ast::def_id) -> ast::def_id {
/*!
*
* Translates an INTERNAL def-id, meaning a def-id that is
* known to refer to some part of the item currently being
* inlined. In that case, we want to convert the def-id to
* refer to the current crate and to the new, inlined node-id.
*/
assert!(did.crate == ast::local_crate);
ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) }
}
fn tr_span(&self, _span: span) -> span {
codemap::dummy_sp() // FIXME (#1972): handle span properly
}
}
impl tr_intern for ast::def_id {
fn tr_intern(&self, xcx: @ExtendedDecodeContext) -> ast::def_id {
xcx.tr_intern_def_id(*self)
}
}
impl tr for ast::def_id {
fn tr(&self, xcx: @ExtendedDecodeContext) -> ast::def_id {
xcx.tr_def_id(*self)
}
}
impl tr for span {
fn tr(&self, xcx: @ExtendedDecodeContext) -> span {
xcx.tr_span(*self)
}
}
trait def_id_encoder_helpers {
fn emit_def_id(&self, did: ast::def_id);
}
impl<S:serialize::Encoder> def_id_encoder_helpers for S {
fn emit_def_id(&self, did: ast::def_id) {
did.encode(self)
}
}
trait def_id_decoder_helpers {
fn read_def_id(&self, xcx: @ExtendedDecodeContext) -> ast::def_id;
}
impl<D:serialize::Decoder> def_id_decoder_helpers for D {
fn read_def_id(&self, xcx: @ExtendedDecodeContext) -> ast::def_id {
let did: ast::def_id = Decodable::decode(self);
did.tr(xcx)
}
}
// ______________________________________________________________________
// Encoding and decoding the AST itself
//
// The hard work is done by an autogenerated module astencode_gen. To
// regenerate astencode_gen, run src/etc/gen-astencode. It will
// replace astencode_gen with a dummy file and regenerate its
// contents. If you get compile errors, the dummy file
// remains---resolve the errors and then rerun astencode_gen.
// Annoying, I know, but hopefully only temporary.
//
// When decoding, we have to renumber the AST so that the node ids that
// appear within are disjoint from the node ids in our existing ASTs.
// We also have to adjust the spans: for now we just insert a dummy span,
// but eventually we should add entries to the local codemap as required.
fn encode_ast(ebml_w: writer::Encoder, item: ast::inlined_item) {
do ebml_w.wr_tag(c::tag_tree as uint) {
item.encode(&ebml_w)
}
}
// Produces a simplified copy of the AST which does not include things
// that we do not need to or do not want to export. For example, we
// do not include any nested items: if these nested items are to be
// inlined, their AST will be exported separately (this only makes
// sense because, in Rust, nested items are independent except for
// their visibility).
//
// As it happens, trans relies on the fact that we do not export
// nested items, as otherwise it would get confused when translating
// inlined items.
fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
fn drop_nested_items(blk: &ast::blk_, fld: @fold::ast_fold) -> ast::blk_ {
let stmts_sans_items = do blk.stmts.filtered |stmt| {
match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_),
span: _}, _) => true,
ast::stmt_decl(@codemap::spanned { node: ast::decl_item(_),
span: _}, _) => false,
ast::stmt_mac(*) => fail!(~"unexpanded macro in astencode")
}
};
let blk_sans_items = ast::blk_ {
view_items: ~[], // I don't know if we need the view_items here,
// but it doesn't break tests!
stmts: stmts_sans_items,
expr: blk.expr,
id: blk.id,
rules: blk.rules
};
fold::noop_fold_block(&blk_sans_items, fld)
}
let fld = fold::make_fold(@fold::AstFoldFns {
fold_block: fold::wrap(drop_nested_items),
.. *fold::default_ast_fold()
});
match ii {
ast::ii_item(i) => {
ast::ii_item(fld.fold_item(i).get()) //hack: we're not dropping items
}
ast::ii_method(d, m) => {
ast::ii_method(d, fld.fold_method(m))
}
ast::ii_foreign(i) => {
ast::ii_foreign(fld.fold_foreign_item(i))
}
ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => {
let dtor_body = fld.fold_block(&dtor.node.body);
ast::ii_dtor(
codemap::spanned {
node: ast::struct_dtor_ { body: dtor_body,
.. /*bad*/copy (*dtor).node },
.. (/*bad*/copy *dtor) },
nm, /*bad*/copy *tps, parent_id)
}
}
}
fn decode_ast(par_doc: ebml::Doc) -> ast::inlined_item {
let chi_doc = par_doc.get(c::tag_tree as uint);
let d = &reader::Decoder(chi_doc);
Decodable::decode(d)
}
fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item)
-> ast::inlined_item {
let fld = fold::make_fold(@fold::AstFoldFns{
new_id: |a| xcx.tr_id(a),
new_span: |a| xcx.tr_span(a),
.. *fold::default_ast_fold()
});
match ii {
ast::ii_item(i) => {
ast::ii_item(fld.fold_item(i).get())
}
ast::ii_method(d, m) => {
ast::ii_method(xcx.tr_def_id(d), fld.fold_method(m))
}
ast::ii_foreign(i) => {
ast::ii_foreign(fld.fold_foreign_item(i))
}
ast::ii_dtor(ref dtor, nm, ref generics, parent_id) => {
let dtor_body = fld.fold_block(&dtor.node.body);
let dtor_attrs = fld.fold_attributes(/*bad*/copy (*dtor).node.attrs);
let new_generics = fold::fold_generics(generics, fld);
let dtor_id = fld.new_id((*dtor).node.id);
let new_parent = xcx.tr_def_id(parent_id);
let new_self = fld.new_id((*dtor).node.self_id);
ast::ii_dtor(
codemap::spanned {
node: ast::struct_dtor_ { id: dtor_id,
attrs: dtor_attrs,
self_id: new_self,
body: dtor_body },
.. (/*bad*/copy *dtor)
},
nm, new_generics, new_parent)
}
}
}
// ______________________________________________________________________
// Encoding and decoding of ast::def
fn encode_def(ebml_w: writer::Encoder, def: ast::def) {
def.encode(&ebml_w)
}
fn decode_def(xcx: @ExtendedDecodeContext, doc: ebml::Doc) -> ast::def {
let dsr = &reader::Decoder(doc);
let def: ast::def = Decodable::decode(dsr);
def.tr(xcx)
}
impl tr for ast::def {
fn tr(&self, xcx: @ExtendedDecodeContext) -> ast::def {
match *self {
ast::def_fn(did, p) => { ast::def_fn(did.tr(xcx), p) }
ast::def_static_method(did, did2_opt, p) => {
ast::def_static_method(did.tr(xcx),
did2_opt.map(|did2| did2.tr(xcx)),
p)
}
ast::def_self_ty(nid) => { ast::def_self_ty(xcx.tr_id(nid)) }
ast::def_self(nid, i) => { ast::def_self(xcx.tr_id(nid), i) }
ast::def_mod(did) => { ast::def_mod(did.tr(xcx)) }
ast::def_foreign_mod(did) => { ast::def_foreign_mod(did.tr(xcx)) }
ast::def_const(did) => { ast::def_const(did.tr(xcx)) }
ast::def_arg(nid, m, b) => { ast::def_arg(xcx.tr_id(nid), m, b) }
ast::def_local(nid, b) => { ast::def_local(xcx.tr_id(nid), b) }
ast::def_variant(e_did, v_did) => {
ast::def_variant(e_did.tr(xcx), v_did.tr(xcx))
}
ast::def_ty(did) => ast::def_ty(did.tr(xcx)),
ast::def_prim_ty(p) => ast::def_prim_ty(p),
ast::def_ty_param(did, v) => ast::def_ty_param(did.tr(xcx), v),
ast::def_binding(nid, bm) => ast::def_binding(xcx.tr_id(nid), bm),
ast::def_use(did) => ast::def_use(did.tr(xcx)),
ast::def_upvar(nid1, def, nid2, nid3) => {
ast::def_upvar(xcx.tr_id(nid1),
@(*def).tr(xcx),
xcx.tr_id(nid2),
xcx.tr_id(nid3))
}
ast::def_struct(did) => {
ast::def_struct(did.tr(xcx))
}
ast::def_region(nid) => ast::def_region(xcx.tr_id(nid)),
ast::def_typaram_binder(nid) => {
ast::def_typaram_binder(xcx.tr_id(nid))
}
ast::def_label(nid) => ast::def_label(xcx.tr_id(nid))
}
}
}
// ______________________________________________________________________
// Encoding and decoding of adjustment information
impl tr for ty::AutoAdjustment {
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::AutoAdjustment {
match self {
&ty::AutoAddEnv(r, s) => {
ty::AutoAddEnv(r.tr(xcx), s)
}
&ty::AutoDerefRef(ref adr) => {
ty::AutoDerefRef(ty::AutoDerefRef {
autoderefs: adr.autoderefs,
autoref: adr.autoref.map(|ar| ar.tr(xcx)),
})
}
}
}
}
impl tr for ty::AutoRef {
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::AutoRef {
ty::AutoRef {
kind: self.kind,
region: self.region.tr(xcx),
mutbl: self.mutbl,
}
}
}
impl tr for ty::Region {
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::Region {
match *self {
ty::re_bound(br) => ty::re_bound(br.tr(xcx)),
ty::re_free(id, br) => ty::re_free(xcx.tr_id(id), br.tr(xcx)),
ty::re_scope(id) => ty::re_scope(xcx.tr_id(id)),
ty::re_static | ty::re_infer(*) => *self,
}
}
}
impl tr for ty::bound_region {
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::bound_region {
match *self {
ty::br_anon(_) | ty::br_named(_) | ty::br_self |
ty::br_fresh(_) => *self,
ty::br_cap_avoid(id, br) => ty::br_cap_avoid(xcx.tr_id(id),
@br.tr(xcx))
}
}
}
// ______________________________________________________________________
// Encoding and decoding of freevar information
fn encode_freevar_entry(ebml_w: writer::Encoder, fv: @freevar_entry) {
(*fv).encode(&ebml_w)
}
trait ebml_decoder_helper {
fn read_freevar_entry(&self, xcx: @ExtendedDecodeContext)
-> freevar_entry;
}
impl ebml_decoder_helper for reader::Decoder {
fn read_freevar_entry(&self, xcx: @ExtendedDecodeContext)
-> freevar_entry {
let fv: freevar_entry = Decodable::decode(self);
fv.tr(xcx)
}
}
impl tr for freevar_entry {
fn tr(&self, xcx: @ExtendedDecodeContext) -> freevar_entry {
freevar_entry {
def: self.def.tr(xcx),
span: self.span.tr(xcx),
}
}
}
// ______________________________________________________________________
// Encoding and decoding of CaptureVar information
trait capture_var_helper {
fn read_capture_var(&self, xcx: @ExtendedDecodeContext)
-> moves::CaptureVar;
}
impl capture_var_helper for reader::Decoder {
fn read_capture_var(&self, xcx: @ExtendedDecodeContext)
-> moves::CaptureVar {
let cvar: moves::CaptureVar = Decodable::decode(self);
cvar.tr(xcx)
}
}
impl tr for moves::CaptureVar {
fn tr(&self, xcx: @ExtendedDecodeContext) -> moves::CaptureVar {
moves::CaptureVar {
def: self.def.tr(xcx),
span: self.span.tr(xcx),
mode: self.mode
}
}
}
// ______________________________________________________________________
// Encoding and decoding of method_map_entry
trait read_method_map_entry_helper {
fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
-> method_map_entry;
}
fn encode_method_map_entry(ecx: @e::EncodeContext,
ebml_w: writer::Encoder,
mme: method_map_entry) {
do ebml_w.emit_struct("method_map_entry", 3) {
do ebml_w.emit_field(~"self_arg", 0u) {
ebml_w.emit_arg(ecx, mme.self_arg);
}
do ebml_w.emit_field(~"explicit_self", 2u) {
mme.explicit_self.encode(&ebml_w);
}
do ebml_w.emit_field(~"origin", 1u) {
mme.origin.encode(&ebml_w);
}
}
}
impl read_method_map_entry_helper for reader::Decoder {
fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
-> method_map_entry {
do self.read_struct("method_map_entry", 3) {
method_map_entry {
self_arg: self.read_field(~"self_arg", 0u, || {
self.read_arg(xcx)
}),
explicit_self: self.read_field(~"explicit_self", 2u, || {
let self_type: ast::self_ty_ = Decodable::decode(self);
self_type
}),
origin: self.read_field(~"origin", 1u, || {
let method_origin: method_origin =
Decodable::decode(self);
method_origin.tr(xcx)
}),
}
}
}
}
impl tr for method_origin {
fn tr(&self, xcx: @ExtendedDecodeContext) -> method_origin {
match *self {
typeck::method_static(did) => {
typeck::method_static(did.tr(xcx))
}
typeck::method_param(ref mp) => {
typeck::method_param(
typeck::method_param {
trait_id: mp.trait_id.tr(xcx),
.. *mp
}
)
}
typeck::method_trait(did, m, vstore) => {
typeck::method_trait(did.tr(xcx), m, vstore)
}
typeck::method_self(did, m) => {
typeck::method_self(did.tr(xcx), m)
}
typeck::method_super(trait_did, m) => {
typeck::method_super(trait_did.tr(xcx), m)
}
}
}
}
// ______________________________________________________________________
// Encoding and decoding vtable_res
fn encode_vtable_res(ecx: @e::EncodeContext,
ebml_w: writer::Encoder,
dr: typeck::vtable_res) {
// can't autogenerate this code because automatic code of
// ty::t doesn't work, and there is no way (atm) to have
// hand-written encoding routines combine with auto-generated
// ones. perhaps we should fix this.
do ebml_w.emit_from_vec(*dr) |vtable_origin| {
encode_vtable_origin(ecx, ebml_w, *vtable_origin)
}
}
fn encode_vtable_origin(ecx: @e::EncodeContext,
ebml_w: writer::Encoder,
vtable_origin: typeck::vtable_origin) {
do ebml_w.emit_enum(~"vtable_origin") {
match vtable_origin {
typeck::vtable_static(def_id, ref tys, vtable_res) => {
do ebml_w.emit_enum_variant(~"vtable_static", 0u, 3u) {
do ebml_w.emit_enum_variant_arg(0u) {
ebml_w.emit_def_id(def_id)
}
do ebml_w.emit_enum_variant_arg(1u) {
ebml_w.emit_tys(ecx, /*bad*/copy *tys);
}
do ebml_w.emit_enum_variant_arg(2u) {
encode_vtable_res(ecx, ebml_w, vtable_res);
}
}
}
typeck::vtable_param(pn, bn) => {
do ebml_w.emit_enum_variant(~"vtable_param", 1u, 2u) {
do ebml_w.emit_enum_variant_arg(0u) {
ebml_w.emit_uint(pn);
}
do ebml_w.emit_enum_variant_arg(1u) {
ebml_w.emit_uint(bn);
}
}
}
}
}
}
trait vtable_decoder_helpers {
fn read_vtable_res(&self, xcx: @ExtendedDecodeContext)
-> typeck::vtable_res;
fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
-> typeck::vtable_origin;
}
impl vtable_decoder_helpers for reader::Decoder {
fn read_vtable_res(&self, xcx: @ExtendedDecodeContext)
-> typeck::vtable_res {
@self.read_to_vec(|| self.read_vtable_origin(xcx) )
}
fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
-> typeck::vtable_origin {
do self.read_enum("vtable_origin") {
do self.read_enum_variant(["vtable_static", "vtable_param"]) |i| {
match i {
0 => {
typeck::vtable_static(
do self.read_enum_variant_arg(0u) {
self.read_def_id(xcx)
},
do self.read_enum_variant_arg(1u) {
self.read_tys(xcx)
},
do self.read_enum_variant_arg(2u) {
self.read_vtable_res(xcx)
}
)
}
1 => {
typeck::vtable_param(
do self.read_enum_variant_arg(0u) {
self.read_uint()
},
do self.read_enum_variant_arg(1u) {
self.read_uint()
}
)
}
// hard to avoid - user input
_ => fail!(~"bad enum variant")
}
}
}
}
}
// ______________________________________________________________________
// Encoding and decoding the side tables
trait get_ty_str_ctxt {
fn ty_str_ctxt(@self) -> @tyencode::ctxt;
}
impl get_ty_str_ctxt for e::EncodeContext {
// IMPLICIT SELF WARNING: fix this!
fn ty_str_ctxt(@self) -> @tyencode::ctxt {
@tyencode::ctxt {diag: self.tcx.sess.diagnostic(),
ds: e::def_to_str,
tcx: self.tcx,
reachable: |a| encoder::reachable(self, a),
abbrevs: tyencode::ac_use_abbrevs(self.type_abbrevs)}
}
}
trait ebml_writer_helpers {
fn emit_arg(&self, ecx: @e::EncodeContext, arg: ty::arg);
fn emit_ty(&self, ecx: @e::EncodeContext, ty: ty::t);
fn emit_vstore(&self, ecx: @e::EncodeContext, vstore: ty::vstore);
fn emit_tys(&self, ecx: @e::EncodeContext, tys: ~[ty::t]);
fn emit_bounds(&self, ecx: @e::EncodeContext, bs: ty::param_bounds);
fn emit_tpbt(&self, ecx: @e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty);
}
impl ebml_writer_helpers for writer::Encoder {
fn emit_ty(&self, ecx: @e::EncodeContext, ty: ty::t) {
do self.emit_opaque {
e::write_type(ecx, *self, ty)
}
}
fn emit_vstore(&self, ecx: @e::EncodeContext, vstore: ty::vstore) {
do self.emit_opaque {
e::write_vstore(ecx, *self, vstore)
}
}
fn emit_arg(&self, ecx: @e::EncodeContext, arg: ty::arg) {
do self.emit_opaque {
tyencode::enc_arg(self.writer, ecx.ty_str_ctxt(), arg);
}
}
fn emit_tys(&self, ecx: @e::EncodeContext, tys: ~[ty::t]) {
do self.emit_from_vec(tys) |ty| {
self.emit_ty(ecx, *ty)
}
}
fn emit_bounds(&self, ecx: @e::EncodeContext, bs: ty::param_bounds) {
do self.emit_opaque {
tyencode::enc_bounds(self.writer, ecx.ty_str_ctxt(), bs)
}
}
fn emit_tpbt(&self, ecx: @e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty) {
do self.emit_struct("ty_param_bounds_and_ty", 3) {
do self.emit_field(~"bounds", 0) {
do self.emit_from_vec(*tpbt.bounds) |bs| {
self.emit_bounds(ecx, *bs);
}
}
do self.emit_field(~"region_param", 1u) {
tpbt.region_param.encode(self);
}
do self.emit_field(~"ty", 2u) {
self.emit_ty(ecx, tpbt.ty);
}
}
}
}
trait write_tag_and_id {
fn tag(&self, tag_id: c::astencode_tag, f: &fn());
fn id(&self, id: ast::node_id);
}
impl write_tag_and_id for writer::Encoder {
fn tag(&self, tag_id: c::astencode_tag, f: &fn()) {
do self.wr_tag(tag_id as uint) { f() }
}
fn id(&self, id: ast::node_id) {
self.wr_tagged_u64(c::tag_table_id as uint, id as u64)
}
}
fn encode_side_tables_for_ii(ecx: @e::EncodeContext,
maps: Maps,
ebml_w: writer::Encoder,
ii: ast::inlined_item) {
do ebml_w.wr_tag(c::tag_table as uint) {
let ebml_w = copy ebml_w;
ast_util::visit_ids_for_inlined_item(
ii,
|id: ast::node_id| {
// Note: this will cause a copy of ebml_w, which is bad as
// it has mut fields. But I believe it's harmless since
// we generate balanced EBML.
encode_side_tables_for_id(ecx, maps, ebml_w, id)
});
}
}
fn encode_side_tables_for_id(ecx: @e::EncodeContext,
maps: Maps,
ebml_w: writer::Encoder,
id: ast::node_id) {
let tcx = ecx.tcx;
debug!("Encoding side tables for id %d", id);
for tcx.def_map.find(&id).each |def| {
do ebml_w.tag(c::tag_table_def) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
(*def).encode(&ebml_w)
}
}
}
for tcx.node_types.find(&(id as uint)).each |&ty| {
do ebml_w.tag(c::tag_table_node_type) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
ebml_w.emit_ty(ecx, *ty);
}
}
}
for tcx.node_type_substs.find(&id).each |tys| {
do ebml_w.tag(c::tag_table_node_type_subst) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
// FIXME(#5562): removing this copy causes a segfault
// before stage2
ebml_w.emit_tys(ecx, /*bad*/copy **tys)
}
}
}
for tcx.freevars.find(&id).each |&fv| {
do ebml_w.tag(c::tag_table_freevars) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
do ebml_w.emit_from_vec(**fv) |fv_entry| {
encode_freevar_entry(ebml_w, *fv_entry)
}
}
}
}
let lid = ast::def_id { crate: ast::local_crate, node: id };
for tcx.tcache.find(&lid).each |&tpbt| {
do ebml_w.tag(c::tag_table_tcache) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
ebml_w.emit_tpbt(ecx, *tpbt);
}
}
}
for tcx.ty_param_bounds.find(&id).each |&pbs| {
do ebml_w.tag(c::tag_table_param_bounds) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
ebml_w.emit_bounds(ecx, *pbs)
}
}
}
// I believe it is not necessary to encode this information. The
// ids will appear in the AST but in the *type* information, which
// is what we actually use in trans, all modes will have been
// resolved.
//
//for tcx.inferred_modes.find(&id).each |m| {
// ebml_w.tag(c::tag_table_inferred_modes) {||
// ebml_w.id(id);
// ebml_w.tag(c::tag_table_val) {||
// tyencode::enc_mode(ebml_w.writer, ty_str_ctxt(), m);
// }
// }
//}
if maps.mutbl_map.contains(&id) {
do ebml_w.tag(c::tag_table_mutbl) {
ebml_w.id(id);
}
}
for maps.last_use_map.find(&id).each |&m| {
do ebml_w.tag(c::tag_table_last_use) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
do ebml_w.emit_from_vec(/*bad*/ copy **m) |id| {
id.encode(&ebml_w);
}
}
}
}
for maps.method_map.find(&id).each |&mme| {
do ebml_w.tag(c::tag_table_method_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
encode_method_map_entry(ecx, ebml_w, *mme)
}
}
}
for maps.vtable_map.find(&id).each |&dr| {
do ebml_w.tag(c::tag_table_vtable_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
encode_vtable_res(ecx, ebml_w, *dr);
}
}
}
for tcx.adjustments.find(&id).each |adj| {
do ebml_w.tag(c::tag_table_adjustments) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
(**adj).encode(&ebml_w)
}
}
}
if maps.moves_map.contains(&id) {
do ebml_w.tag(c::tag_table_moves_map) {
ebml_w.id(id);
}
}
for maps.capture_map.find(&id).each |&cap_vars| {
do ebml_w.tag(c::tag_table_capture_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
do ebml_w.emit_from_vec(*cap_vars) |cap_var| {
cap_var.encode(&ebml_w);
}
}
}
}
}
trait doc_decoder_helpers {
fn as_int(&self) -> int;
fn opt_child(&self, tag: c::astencode_tag) -> Option<ebml::Doc>;
}
impl doc_decoder_helpers for ebml::Doc {
fn as_int(&self) -> int { reader::doc_as_u64(*self) as int }
fn opt_child(&self, tag: c::astencode_tag) -> Option<ebml::Doc> {
reader::maybe_get_doc(*self, tag as uint)
}
}
trait ebml_decoder_decoder_helpers {
fn read_arg(&self, xcx: @ExtendedDecodeContext) -> ty::arg;
fn read_ty(&self, xcx: @ExtendedDecodeContext) -> ty::t;
fn read_tys(&self, xcx: @ExtendedDecodeContext) -> ~[ty::t];
fn read_bounds(&self, xcx: @ExtendedDecodeContext) -> @~[ty::param_bound];
fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty;
fn convert_def_id(&self, xcx: @ExtendedDecodeContext,
source: DefIdSource,
did: ast::def_id) -> ast::def_id;
}
impl ebml_decoder_decoder_helpers for reader::Decoder {
fn read_arg(&self, xcx: @ExtendedDecodeContext) -> ty::arg {
do self.read_opaque |doc| {
tydecode::parse_arg_data(
doc.data, xcx.dcx.cdata.cnum, doc.start, xcx.dcx.tcx,
|s, a| self.convert_def_id(xcx, s, a))
}
}
fn read_ty(&self, xcx: @ExtendedDecodeContext) -> ty::t {
// Note: regions types embed local node ids. In principle, we
// should translate these node ids into the new decode
// context. However, we do not bother, because region types
// are not used during trans.
return do self.read_opaque |doc| {
let ty = tydecode::parse_ty_data(
doc.data, xcx.dcx.cdata.cnum, doc.start, xcx.dcx.tcx,
|s, a| self.convert_def_id(xcx, s, a));
debug!("read_ty(%s) = %s",
type_string(doc), ty_to_str(xcx.dcx.tcx, ty));
ty
};
fn type_string(doc: ebml::Doc) -> ~str {
let mut str = ~"";
for uint::range(doc.start, doc.end) |i| {
str::push_char(&mut str, doc.data[i] as char);
}
str
}
}
fn read_tys(&self, xcx: @ExtendedDecodeContext) -> ~[ty::t] {
self.read_to_vec(|| self.read_ty(xcx) )
}
fn read_bounds(&self, xcx: @ExtendedDecodeContext)
-> @~[ty::param_bound] {
do self.read_opaque |doc| {
tydecode::parse_bounds_data(
doc.data, doc.start, xcx.dcx.cdata.cnum, xcx.dcx.tcx,
|s, a| self.convert_def_id(xcx, s, a))
}
}
fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty
{
do self.read_struct("ty_param_bounds_and_ty", 3) {
ty::ty_param_bounds_and_ty {
bounds: self.read_field(~"bounds", 0u, || {
@self.read_to_vec(|| self.read_bounds(xcx) )
}),
region_param: self.read_field(~"region_param", 1u, || {
Decodable::decode(self)
}),
ty: self.read_field(~"ty", 2u, || {
self.read_ty(xcx)
})
}
}
}
fn convert_def_id(&self, xcx: @ExtendedDecodeContext,
source: tydecode::DefIdSource,
did: ast::def_id) -> ast::def_id {
/*!
*
* Converts a def-id that appears in a type. The correct
* translation will depend on what kind of def-id this is.
* This is a subtle point: type definitions are not
* inlined into the current crate, so if the def-id names
* a nominal type or type alias, then it should be
* translated to refer to the source crate.
*
* However, *type parameters* are cloned along with the function
* they are attached to. So we should translate those def-ids
* to refer to the new, cloned copy of the type parameter.
*/
let r = match source {
NominalType | TypeWithId => xcx.tr_def_id(did),
TypeParameter => xcx.tr_intern_def_id(did)
};
debug!("convert_def_id(source=%?, did=%?)=%?", source, did, r);
return r;
}
}
fn decode_side_tables(xcx: @ExtendedDecodeContext,
ast_doc: ebml::Doc) {
let dcx = xcx.dcx;
let tbl_doc = ast_doc.get(c::tag_table as uint);
for reader::docs(tbl_doc) |tag, entry_doc| {
let id0 = entry_doc.get(c::tag_table_id as uint).as_int();
let id = xcx.tr_id(id0);
debug!(">> Side table document with tag 0x%x \
found for id %d (orig %d)",
tag, id, id0);
if tag == (c::tag_table_mutbl as uint) {
dcx.maps.mutbl_map.insert(id);
} else if tag == (c::tag_table_moves_map as uint) {
dcx.maps.moves_map.insert(id);
} else {
let val_doc = entry_doc.get(c::tag_table_val as uint);
let val_dsr = &reader::Decoder(val_doc);
if tag == (c::tag_table_def as uint) {
let def = decode_def(xcx, val_doc);
dcx.tcx.def_map.insert(id, def);
} else if tag == (c::tag_table_node_type as uint) {
let ty = val_dsr.read_ty(xcx);
debug!("inserting ty for node %?: %s",
id, ty_to_str(dcx.tcx, ty));
dcx.tcx.node_types.insert(id as uint, ty);
} else if tag == (c::tag_table_node_type_subst as uint) {
let tys = val_dsr.read_tys(xcx);
dcx.tcx.node_type_substs.insert(id, tys);
} else if tag == (c::tag_table_freevars as uint) {
let fv_info = @val_dsr.read_to_vec(|| {
@val_dsr.read_freevar_entry(xcx)
});
dcx.tcx.freevars.insert(id, fv_info);
} else if tag == (c::tag_table_tcache as uint) {
let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx);
let lid = ast::def_id { crate: ast::local_crate, node: id };
dcx.tcx.tcache.insert(lid, tpbt);
} else if tag == (c::tag_table_param_bounds as uint) {
let bounds = val_dsr.read_bounds(xcx);
dcx.tcx.ty_param_bounds.insert(id, bounds);
} else if tag == (c::tag_table_last_use as uint) {
let ids = val_dsr.read_to_vec(|| {
xcx.tr_id(val_dsr.read_int())
});
dcx.maps.last_use_map.insert(id, @mut ids);
} else if tag == (c::tag_table_method_map as uint) {
dcx.maps.method_map.insert(
id,
val_dsr.read_method_map_entry(xcx));
} else if tag == (c::tag_table_vtable_map as uint) {
dcx.maps.vtable_map.insert(id,
val_dsr.read_vtable_res(xcx));
} else if tag == (c::tag_table_adjustments as uint) {
let adj: @ty::AutoAdjustment = @Decodable::decode(val_dsr);
adj.tr(xcx);
dcx.tcx.adjustments.insert(id, adj);
} else if tag == (c::tag_table_capture_map as uint) {
let cvars =
at_vec::from_owned(
val_dsr.read_to_vec(
|| val_dsr.read_capture_var(xcx)));
dcx.maps.capture_map.insert(id, cvars);
} else {
xcx.dcx.tcx.sess.bug(
fmt!("unknown tag found in side tables: %x", tag));
}
}
debug!(">< Side table doc loaded");
}
}
// ______________________________________________________________________
// Testing of astencode_gen
#[cfg(test)]
fn encode_item_ast(ebml_w: writer::Encoder, item: @ast::item) {
do ebml_w.wr_tag(c::tag_tree as uint) {
(*item).encode(&ebml_w)
}
}
#[cfg(test)]
fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
let chi_doc = par_doc.get(c::tag_tree as uint);
let d = &reader::Decoder(chi_doc);
@Decodable::decode(d)
}
#[cfg(test)]
trait fake_ext_ctxt {
fn cfg(&self) -> ast::crate_cfg;
fn parse_sess(&self) -> @mut parse::ParseSess;
fn call_site(&self) -> span;
fn ident_of(&self, +st: ~str) -> ast::ident;
}
#[cfg(test)]
type fake_session = @mut parse::ParseSess;
#[cfg(test)]
impl fake_ext_ctxt for fake_session {
fn cfg(&self) -> ast::crate_cfg { ~[] }
fn parse_sess(&self) -> @mut parse::ParseSess { *self }
fn call_site(&self) -> span {
codemap::span {
lo: codemap::BytePos(0),
hi: codemap::BytePos(0),
expn_info: None
}
}
fn ident_of(&self, +st: ~str) -> ast::ident {
self.interner.intern(@st)
}
}
#[cfg(test)]
fn mk_ctxt() -> @fake_ext_ctxt {
@parse::new_parse_sess(None) as @fake_ext_ctxt
}
#[cfg(test)]
fn roundtrip(in_item: Option<@ast::item>) {
use core::io;
let in_item = in_item.get();
let bytes = do io::with_bytes_writer |wr| {
let ebml_w = writer::Encoder(wr);
encode_item_ast(ebml_w, in_item);
};
let ebml_doc = reader::Doc(@bytes);
let out_item = decode_item_ast(ebml_doc);
assert_eq!(in_item, out_item);
}
#[test]
fn test_basic() {
let ext_cx = mk_ctxt();
roundtrip(quote_item!(
fn foo() {}
));
}
#[test]
fn test_smalltalk() {
let ext_cx = mk_ctxt();
roundtrip(quote_item!(
fn foo() -> int { 3 + 4 } // first smalltalk program ever executed.
));
}
#[test]
fn test_more() {
let ext_cx = mk_ctxt();
roundtrip(quote_item!(
fn foo(x: uint, y: uint) -> uint {
let z = x + y;
return z;
}
));
}
#[test]
fn test_simplification() {
let ext_cx = mk_ctxt();
let item_in = ast::ii_item(quote_item!(
fn new_int_alist<B:Copy>() -> alist<int, B> {
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
return alist {eq_fn: eq_int, data: ~[]};
}
).get());
let item_out = simplify_ast(item_in);
let item_exp = ast::ii_item(quote_item!(
fn new_int_alist<B:Copy>() -> alist<int, B> {
return alist {eq_fn: eq_int, data: ~[]};
}
).get());
match (item_out, item_exp) {
(ast::ii_item(item_out), ast::ii_item(item_exp)) => {
assert!(pprust::item_to_str(item_out,
ext_cx.parse_sess().interner)
== pprust::item_to_str(item_exp,
ext_cx.parse_sess().interner));
}
_ => fail!()
}
}
|