-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathModuleFormat.h
2653 lines (2321 loc) · 81 KB
/
ModuleFormat.h
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
//===--- ModuleFormat.h - The internals of serialized modules ---*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Contains various constants and helper types to deal with serialized
/// modules.
///
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SERIALIZATION_MODULEFORMAT_H
#define SWIFT_SERIALIZATION_MODULEFORMAT_H
#include "swift/AST/Decl.h"
#include "swift/AST/FineGrainedDependencyFormat.h"
#include "swift/AST/Types.h"
#include "llvm/ADT/PointerEmbeddedInt.h"
#include "llvm/Bitcode/BitcodeConvenience.h"
#include "llvm/Bitstream/BitCodes.h"
namespace swift {
class ModuleFile;
class TypeDeserializer;
namespace serialization {
using llvm::PointerEmbeddedInt;
using llvm::BCArray;
using llvm::BCBlob;
using llvm::BCFixed;
using llvm::BCGenericRecordLayout;
using llvm::BCRecordLayout;
using llvm::BCVBR;
/// Magic number for serialized module files.
const unsigned char SWIFTMODULE_SIGNATURE[] = { 0xE2, 0x9C, 0xA8, 0x0E };
/// Alignment of each serialized modules inside a .swift_ast section.
const unsigned char SWIFTMODULE_ALIGNMENT = 4;
/// Serialized module format major version number.
///
/// Always 0 for Swift 1.x - 4.x.
const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// Serialized module format minor version number.
///
/// When the format changes IN ANY WAY, this number should be incremented.
/// To ensure that two separate changes don't silently get merged into one
/// in source control, you should also update the comment to briefly
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 863; // @sil_transferring
/// A standard hash seed used for all string hashes in a serialized module.
///
/// This is the same as the default used by llvm::djbHash, just provided
/// explicitly here to note that it's part of the format.
const uint32_t SWIFTMODULE_HASH_SEED = 5381;
using DeclIDField = BCFixed<31>;
// TypeID must be the same as DeclID because it is stored in the same way.
using TypeID = DeclID;
using TypeIDField = DeclIDField;
using TypeIDWithBitField = BCFixed<32>;
// ClangTypeID must be the same as DeclID because it is stored in the same way.
using ClangTypeID = TypeID;
using ClangTypeIDField = TypeIDField;
// IdentifierID must be the same as DeclID because it is stored in the same way.
using IdentifierID = DeclID;
using IdentifierIDField = DeclIDField;
// LocalDeclContextID must be the same as DeclID because it is stored in the
// same way.
using LocalDeclContextID = DeclID;
using LocalDeclContextIDField = DeclIDField;
/// Stores either a DeclID or a LocalDeclContextID, using 32 bits.
class DeclContextID {
int32_t rawValue;
explicit DeclContextID(int32_t rawValue) : rawValue(rawValue) {}
public:
DeclContextID() : DeclContextID(0) {}
static DeclContextID forDecl(DeclID value) {
assert(value && "should encode null using DeclContextID()");
assert(llvm::isUInt<31>(value) && "too many DeclIDs");
return DeclContextID(static_cast<int32_t>(value));
}
static DeclContextID forLocalDeclContext(LocalDeclContextID value) {
assert(value && "should encode null using DeclContextID()");
assert(llvm::isUInt<31>(value) && "too many LocalDeclContextIDs");
return DeclContextID(-static_cast<int32_t>(value));
}
explicit operator bool() const {
return rawValue != 0;
}
std::optional<DeclID> getAsDeclID() const {
if (rawValue > 0)
return DeclID(rawValue);
return std::nullopt;
}
std::optional<LocalDeclContextID> getAsLocalDeclContextID() const {
if (rawValue < 0)
return LocalDeclContextID(-rawValue);
return std::nullopt;
}
static DeclContextID getFromOpaqueValue(uint32_t opaqueValue) {
return DeclContextID(opaqueValue);
}
uint32_t getOpaqueValue() const { return rawValue; }
};
class DeclContextIDField : public BCFixed<32> {
public:
static DeclContextID convert(uint64_t rawValue) {
assert(llvm::isUInt<32>(rawValue));
return DeclContextID::getFromOpaqueValue(rawValue);
}
};
// ProtocolConformanceID must be the same as DeclID because it is stored
// in the same way.
using ProtocolConformanceID = DeclID;
using ProtocolConformanceIDField = DeclIDField;
// The low two bits of the ProtocolConformanceID determine the kind:
// 00 -- abstract conformance
// 01 -- concrete conformance
// 10 -- pack conformance
struct SerializedProtocolConformanceKind {
enum {
Abstract = 0,
Concrete = 1,
Pack = 2,
Shift = 2,
Mask = 3
};
};
// GenericSignatureID must be the same as DeclID because it is stored in the
// same way.
using GenericSignatureID = DeclID;
using GenericSignatureIDField = DeclIDField;
using GenericEnvironmentID = unsigned;
using GenericEnvironmentIDField = BCFixed<32>;
// SubstitutionMapID must be the same as DeclID because it is stored in the
// same way.
using SubstitutionMapID = DeclID;
using SubstitutionMapIDField = DeclIDField;
// ModuleID must be the same as IdentifierID because it is stored the same way.
using ModuleID = IdentifierID;
using ModuleIDField = IdentifierIDField;
// SILLayoutID must be the same as DeclID because it is stored in the same way.
using SILLayoutID = DeclID;
using SILLayoutIDField = DeclIDField;
using BitOffset = PointerEmbeddedInt<unsigned, 31>;
using BitOffsetField = BCFixed<31>;
// CharOffset must be the same as BitOffset because it is stored in the
// same way.
using CharOffset = BitOffset;
using CharOffsetField = BitOffsetField;
using FileSizeField = BCVBR<16>;
using FileModTimeOrContentHashField = BCVBR<16>;
using FileHashField = BCVBR<16>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class OpaqueReadOwnership : uint8_t {
Owned,
Borrowed,
OwnedOrBorrowed,
};
using OpaqueReadOwnershipField = BCFixed<2>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class ReadImplKind : uint8_t {
Stored = 0,
Get,
Inherited,
Address,
Read,
};
using ReadImplKindField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class WriteImplKind : uint8_t {
Immutable = 0,
Stored,
StoredWithObservers,
InheritedWithObservers,
Set,
MutableAddress,
Modify,
};
using WriteImplKindField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class ReadWriteImplKind : uint8_t {
Immutable = 0,
Stored,
MutableAddress,
MaterializeToTemporary,
Modify,
StoredWithDidSet,
InheritedWithDidSet,
};
using ReadWriteImplKindField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class StaticSpellingKind : uint8_t {
None = 0,
KeywordStatic,
KeywordClass,
};
using StaticSpellingKindField = BCFixed<2>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class FunctionTypeRepresentation : uint8_t {
Swift = 0,
Block,
Thin,
CFunctionPointer,
};
using FunctionTypeRepresentationField = BCFixed<4>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class DifferentiabilityKind : uint8_t {
NonDifferentiable = 0,
Forward,
Reverse,
Normal,
Linear,
};
using DifferentiabilityKindField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing the
// module version.
enum class AutoDiffDerivativeFunctionKind : uint8_t {
JVP = 0,
VJP
};
using AutoDiffDerivativeFunctionKindField = BCFixed<1>;
enum class ForeignErrorConventionKind : uint8_t {
ZeroResult,
NonZeroResult,
ZeroPreservedResult,
NilResult,
NonNilError,
};
using ForeignErrorConventionKindField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class SILFunctionTypeRepresentation : uint8_t {
Thick = 0,
Block,
Thin,
CFunctionPointer,
FirstSIL = 8,
Method = FirstSIL,
ObjCMethod,
WitnessMethod,
Closure,
CXXMethod,
KeyPathAccessorGetter,
KeyPathAccessorSetter,
KeyPathAccessorEquals,
KeyPathAccessorHash,
};
using SILFunctionTypeRepresentationField = BCFixed<5>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class SILCoroutineKind : uint8_t {
None = 0,
YieldOnce = 1,
YieldMany = 2,
};
using SILCoroutineKindField = BCFixed<2>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum OperatorKind : uint8_t {
Infix = 0,
Prefix,
Postfix,
PrecedenceGroup, // only for cross references
};
// This is currently required to have the same width as AccessorKindField.
using OperatorKindField = BCFixed<4>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum AccessorKind : uint8_t {
Get = 0,
Set,
WillSet,
DidSet,
Address,
MutableAddress,
Read,
Modify,
Init,
};
using AccessorKindField = BCFixed<4>;
using AccessorCountField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum CtorInitializerKind : uint8_t {
Designated = 0,
Convenience = 1,
Factory = 2,
ConvenienceFactory = 3,
};
using CtorInitializerKindField = BCFixed<2>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class ParamDeclSpecifier : uint8_t {
Default = 0,
InOut = 1,
Borrowing = 2,
Consuming = 3,
LegacyShared = 4,
LegacyOwned = 5,
ImplicitlyCopyableConsuming = 6,
};
using ParamDeclSpecifierField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class VarDeclIntroducer : uint8_t {
Let = 0,
Var = 1,
InOut = 2,
Borrowing = 3,
};
using VarDeclIntroducerField = BCFixed<2>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class ParameterConvention : uint8_t {
Indirect_In,
Indirect_Inout,
Indirect_InoutAliasable,
Direct_Owned,
Direct_Unowned,
Direct_Guaranteed,
Indirect_In_Guaranteed,
Indirect_In_Constant,
Pack_Owned,
Pack_Inout,
Pack_Guaranteed,
};
using ParameterConventionField = BCFixed<4>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class SILParameterDifferentiability : uint8_t {
DifferentiableOrNotApplicable = 0,
NotDifferentiable,
};
/// These IDs must \em not be renumbered or reordered without incrementing the
/// module version.
enum class SILParameterInfoFlags : uint8_t {
NotDifferentiable = 0x1,
Isolated = 0x2,
Transferring = 0x4,
};
using SILParameterInfoOptions = OptionSet<SILParameterInfoFlags>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class ResultConvention : uint8_t {
Indirect,
Owned,
Unowned,
UnownedInnerPointer,
Autoreleased,
Pack,
};
using ResultConventionField = BCFixed<3>;
/// These IDs must \em not be renumbered or reordered without incrementing the
/// module version.
enum class SILResultInfoFlags : uint8_t {
NotDifferentiable = 0x1,
IsTransferring = 0x2,
};
using SILResultInfoOptions = OptionSet<SILResultInfoFlags>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum MetatypeRepresentation : uint8_t {
MR_None, MR_Thin, MR_Thick, MR_ObjC
};
using MetatypeRepresentationField = BCFixed<2>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class SelfAccessKind : uint8_t {
NonMutating = 0,
Mutating,
LegacyConsuming,
Consuming,
Borrowing,
};
using SelfAccessKindField = BCFixed<3>;
/// Translates an operator decl fixity to a Serialization fixity, whose values
/// are guaranteed to be stable.
static inline OperatorKind getStableFixity(OperatorFixity fixity) {
switch (fixity) {
case OperatorFixity::Prefix:
return Prefix;
case OperatorFixity::Postfix:
return Postfix;
case OperatorFixity::Infix:
return Infix;
}
llvm_unreachable("Unhandled case in switch");
}
/// Translates a stable Serialization fixity back to an AST operator fixity.
static inline OperatorFixity getASTOperatorFixity(OperatorKind fixity) {
switch (fixity) {
case Prefix:
return OperatorFixity::Prefix;
case Postfix:
return OperatorFixity::Postfix;
case Infix:
return OperatorFixity::Infix;
case PrecedenceGroup:
llvm_unreachable("Not an operator kind");
}
llvm_unreachable("Unhandled case in switch");
}
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum GenericRequirementKind : uint8_t {
SameShape = 0,
Conformance = 1,
SameType = 2,
Superclass = 3,
Layout = 4,
};
using GenericRequirementKindField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum LayoutRequirementKind : uint8_t {
UnknownLayout = 0,
TrivialOfExactSize = 1,
TrivialOfAtMostSize = 2,
Trivial = 3,
RefCountedObject = 4,
NativeRefCountedObject = 5,
Class = 6,
NativeClass = 7,
BridgeObject = 8,
TrivialStride = 9,
};
using LayoutRequirementKindField = BCFixed<4>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum Associativity : uint8_t {
NonAssociative = 0,
LeftAssociative,
RightAssociative
};
using AssociativityField = BCFixed<2>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum ReferenceOwnership : uint8_t {
Strong = 0,
Weak,
Unowned,
Unmanaged,
};
using ReferenceOwnershipField = BCFixed<2>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class DefaultArgumentKind : uint8_t {
None = 0,
Normal,
FileID,
FileIDSpelledAsFile,
FilePath,
FilePathSpelledAsFile,
Line,
Column,
Function,
Inherited,
DSOHandle,
NilLiteral,
EmptyArray,
EmptyDictionary,
StoredProperty,
ExpressionMacro,
};
using DefaultArgumentField = BCFixed<4>;
/// These IDs must \em not be renumbered or reordered without incrementing
/// the module version.
enum class ActorIsolation : uint8_t {
Unspecified = 0,
ActorInstance,
Nonisolated,
NonisolatedUnsafe,
GlobalActor,
GlobalActorUnsafe,
Erased,
};
using ActorIsolationField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum LibraryKind : uint8_t {
Library = 0,
Framework
};
using LibraryKindField = BCFixed<1>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class AccessLevel : uint8_t {
Private = 0,
FilePrivate,
Internal,
Package,
Public,
Open,
};
using AccessLevelField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class DeclNameKind: uint8_t {
Normal,
Subscript,
Constructor,
Destructor
};
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum SpecialIdentifierID : uint8_t {
/// Special IdentifierID value for the Builtin module.
BUILTIN_MODULE_ID = 0,
/// Special IdentifierID value for the current module.
CURRENT_MODULE_ID,
/// Special value for the module for imported Objective-C headers.
OBJC_HEADER_MODULE_ID,
/// Special value for the special subscript name
SUBSCRIPT_ID,
/// Special value for the special constructor name
CONSTRUCTOR_ID,
/// Special value for the special destructor name
DESTRUCTOR_ID,
/// The number of special Identifier IDs. This value should never be encoded;
/// it should only be used to count the number of names above. As such, it
/// is correct and necessary to add new values above this one.
NUM_SPECIAL_IDS
};
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class EnumElementRawValueKind : uint8_t {
/// No raw value serialized.
None = 0,
/// Integer literal.
IntegerLiteral,
/// TODO: Float, string, char, etc.
};
using EnumElementRawValueKindField = BCFixed<4>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class ResilienceExpansion : uint8_t {
Minimal = 0,
Maximal,
};
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class ImportControl : uint8_t {
/// `import FooKit`
Normal = 0,
/// `@_exported import FooKit`
Exported,
/// `@_implementationOnly import FooKit`
ImplementationOnly,
/// `internal import FooKit` or more restrictive.
InternalOrBelow,
/// `package import FooKit`
PackageOnly,
};
using ImportControlField = BCFixed<3>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class ClangDeclPathComponentKind : uint8_t {
Record = 0,
Enum,
Namespace,
Typedef,
TypedefAnonDecl,
ObjCInterface,
ObjCProtocol,
};
enum class GenericEnvironmentKind : uint8_t {
OpenedExistential,
OpenedElement
};
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class MacroRole : uint8_t {
#define MACRO_ROLE(Name, Description) Name,
#include "swift/Basic/MacroRoles.def"
};
using MacroRoleField = BCFixed<4>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class MacroIntroducedDeclNameKind : uint8_t {
Named = 0,
Overloaded,
Accessors,
Prefixed,
Suffixed,
Arbitrary,
};
using MacroIntroducedDeclNameKindField = BCFixed<4>;
// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class PluginSearchOptionKind : uint8_t {
PluginPath,
ExternalPluginPath,
LoadPluginLibrary,
LoadPluginExecutable,
};
using PluginSearchOptionKindField = BCFixed<3>;
enum class FunctionTypeIsolation : uint8_t {
NonIsolated,
Parameter,
Erased,
GlobalActorOffset, // Add this to the global actor type ID
};
using FunctionTypeIsolationField = TypeIDField;
// Encodes a VersionTuple:
//
// Major
// Minor
// Subminor
// HasMinor
// HasSubminor
#define BC_AVAIL_TUPLE\
BCVBR<5>,\
BCVBR<5>,\
BCVBR<4>,\
BCFixed<1>,\
BCFixed<1>
#define LIST_VER_TUPLE_PIECES(X)\
X##_Major, X##_Minor, X##_Subminor, X##_HasMinor, X##_HasSubminor
#define DEF_VER_TUPLE_PIECES(X) unsigned LIST_VER_TUPLE_PIECES(X)
#define DECODE_VER_TUPLE(X)\
if (X##_HasMinor) {\
if (X##_HasSubminor)\
X = llvm::VersionTuple(X##_Major, X##_Minor, X##_Subminor);\
else\
X = llvm::VersionTuple(X##_Major, X##_Minor);\
}\
else X = llvm::VersionTuple(X##_Major);
#define ENCODE_VER_TUPLE(X, X_Expr)\
unsigned X##_Major = 0, X##_Minor = 0, X##_Subminor = 0,\
X##_HasMinor = 0, X##_HasSubminor = 0;\
const auto &X##_Val = X_Expr;\
if (X##_Val.has_value()) {\
const auto &Y = X##_Val.value();\
X##_Major = Y.getMajor();\
X##_Minor = Y.getMinor().value_or(0);\
X##_Subminor = Y.getSubminor().value_or(0);\
X##_HasMinor = Y.getMinor().has_value();\
X##_HasSubminor = Y.getSubminor().has_value();\
}
/// The various types of blocks that can occur within a serialized Swift
/// module.
///
/// Some of these are shared with the swiftdoc format, which is a stable format.
/// Be very very careful when renumbering them.
enum BlockID {
/// The module block, which contains all of the other blocks (and in theory
/// allows a single file to contain multiple modules).
MODULE_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID,
/// The control block, which contains all of the information that needs to
/// be validated prior to committing to loading the serialized module.
///
/// This is part of a stable format and must not be renumbered!
///
/// \sa control_block
CONTROL_BLOCK_ID,
/// The input block, which contains all the files this module depends on.
///
/// \sa input_block
INPUT_BLOCK_ID,
/// The "decls-and-types" block, which contains all of the declarations that
/// come from this module.
///
/// Types are also stored here, so that types that just wrap a Decl don't need
/// a separate entry in the file.
///
/// \sa decls_block
DECLS_AND_TYPES_BLOCK_ID,
/// The identifier block, which contains all of the strings used in
/// identifiers in the module.
///
/// Unlike other blocks in the file, all data within this block is completely
/// opaque. Offsets into this block should point directly into the blob at a
/// null-terminated UTF-8 string.
IDENTIFIER_DATA_BLOCK_ID,
/// The index block, which contains cross-referencing information for the
/// module.
///
/// \sa index_block
INDEX_BLOCK_ID,
/// The block for SIL functions.
///
/// \sa sil_block
SIL_BLOCK_ID,
/// The index block for SIL functions.
///
/// \sa sil_index_block
SIL_INDEX_BLOCK_ID,
/// A sub-block of the control block that contains configuration options
/// needed to successfully load this module.
///
/// \sa options_block
OPTIONS_BLOCK_ID,
/// The declaration member-tables index block, a sub-block of the index block.
///
/// \sa decl_member_tables_block
DECL_MEMBER_TABLES_BLOCK_ID,
/// The module documentation container block, which contains all other
/// documentation blocks.
///
/// This is part of a stable format and must not be renumbered!
MODULE_DOC_BLOCK_ID = 96,
/// The comment block, which contains documentation comments.
///
/// This is part of a stable format and must not be renumbered!
///
/// \sa comment_block
COMMENT_BLOCK_ID,
/// The module source location container block, which contains all other
/// source location blocks.
///
/// This is part of a stable format and should not be renumbered.
///
/// Though we strive to keep the format stable, breaking the format of
/// .swiftsourceinfo doesn't have consequences as serious as breaking the
/// format of .swiftdoc because .swiftsourceinfo file is for local development
/// use only.
MODULE_SOURCEINFO_BLOCK_ID = 192,
/// The source location block, which contains decl locations.
///
/// This is part of a stable format and should not be renumbered.
///
/// Though we strive to keep the format stable, breaking the format of
/// .swiftsourceinfo doesn't have consequences as serious as breaking the
/// format
/// of .swiftdoc because .swiftsourceinfo file is for local development use
/// only.
///
/// \sa decl_locs_block
DECL_LOCS_BLOCK_ID,
/// The incremental dependency information block.
///
/// This is part of a stable format and should not be renumbered.
INCREMENTAL_INFORMATION_BLOCK_ID =
fine_grained_dependencies::INCREMENTAL_INFORMATION_BLOCK_ID,
};
/// The record types within the control block.
///
/// Be VERY VERY careful when changing this block; it is also used by the
/// swiftdoc format, which \e must \e remain \e stable. Adding new records is
/// okay---they will be ignored---but modifying existing ones must be done
/// carefully. You may need to update the swiftdoc version in DocFormat.h.
///
/// \sa CONTROL_BLOCK_ID
namespace control_block {
enum {
METADATA = 1,
MODULE_NAME,
TARGET,
SDK_NAME,
REVISION,
CHANNEL,
IS_OSSA,
ALLOWABLE_CLIENT_NAME,
HAS_NONCOPYABLE_GENERICS,
};
using MetadataLayout = BCRecordLayout<
METADATA, // ID
BCFixed<16>, // Module format major version
BCFixed<16>, // Module format minor version
BCVBR<8>, // length of "short version string" in the blob
BCVBR<8>, // length of "short compatibility version string" in the blob
BCVBR<17>, // User module format major version
BCVBR<17>, // User module format minor version
BCVBR<17>, // User module format sub-minor version
BCVBR<17>, // User module format build version
BCBlob // misc. version information
>;
using ModuleNameLayout = BCRecordLayout<
MODULE_NAME,
BCBlob
>;
using TargetLayout = BCRecordLayout<
TARGET,
BCBlob // LLVM triple
>;
using SDKNameLayout = BCRecordLayout<
SDK_NAME,
BCBlob
>;
using RevisionLayout = BCRecordLayout<
REVISION,
BCBlob
>;
using ChannelLayout = BCRecordLayout<
CHANNEL,
BCBlob
>;
using IsOSSALayout = BCRecordLayout<
IS_OSSA,
BCFixed<1>
>;
using AllowableClientLayout = BCRecordLayout<
ALLOWABLE_CLIENT_NAME,
BCBlob
>;
using HasNoncopyableGenerics = BCRecordLayout<
HAS_NONCOPYABLE_GENERICS,
BCFixed<1>
>;
}
/// The record types within the options block (a sub-block of the control
/// block).
///
/// \sa OPTIONS_BLOCK_ID
namespace options_block {
enum {
SDK_PATH = 1,
XCC,
IS_SIB,
IS_STATIC_LIBRARY,
HAS_HERMETIC_SEAL_AT_LINK,
IS_EMBEDDED_SWIFT_MODULE,
IS_TESTABLE,
RESILIENCE_STRATEGY,
ARE_PRIVATE_IMPORTS_ENABLED,
IS_IMPLICIT_DYNAMIC_ENABLED,
IS_BUILT_FROM_INTERFACE,
IS_ALLOW_MODULE_WITH_COMPILER_ERRORS_ENABLED,
MODULE_ABI_NAME,
IS_CONCURRENCY_CHECKED,
MODULE_PACKAGE_NAME,
MODULE_EXPORT_AS_NAME,
PLUGIN_SEARCH_OPTION,
HAS_CXX_INTEROPERABILITY_ENABLED,
ALLOW_NON_RESILIENT_ACCESS,
};
using SDKPathLayout = BCRecordLayout<
SDK_PATH,
BCBlob // path
>;
using XCCLayout = BCRecordLayout<
XCC,
BCBlob // -Xcc flag, as string
>;
using PluginSearchOptionLayout = BCRecordLayout<
PLUGIN_SEARCH_OPTION,
PluginSearchOptionKindField, // kind
BCBlob // option value string
>;
using IsSIBLayout = BCRecordLayout<
IS_SIB,
BCFixed<1> // Is this an intermediate file?
>;
using IsStaticLibraryLayout = BCRecordLayout<
IS_STATIC_LIBRARY
>;
using HasHermeticSealAtLinkLayout = BCRecordLayout<
HAS_HERMETIC_SEAL_AT_LINK
>;
using IsEmbeddedSwiftModuleLayout = BCRecordLayout<
IS_EMBEDDED_SWIFT_MODULE
>;
using IsTestableLayout = BCRecordLayout<
IS_TESTABLE
>;
using ArePrivateImportsEnabledLayout = BCRecordLayout<
ARE_PRIVATE_IMPORTS_ENABLED
>;
using IsImplicitDynamicEnabledLayout = BCRecordLayout<
IS_IMPLICIT_DYNAMIC_ENABLED
>;
using ResilienceStrategyLayout = BCRecordLayout<
RESILIENCE_STRATEGY,
BCFixed<2>
>;