Skip to content

Commit 4e484df

Browse files
committed
---
yaml --- r: 323325 b: refs/heads/tensorflow-next c: 9ddff82 h: refs/heads/master i: 323323: 6566d2c
1 parent 82ed36a commit 4e484df

File tree

12 files changed

+427
-147
lines changed

12 files changed

+427
-147
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,4 +1461,4 @@ refs/heads/master-rebranch: 86e95c23aa0d37f24ec138b7853146c1cead2e40
14611461
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14621462
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14631463
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec
1464-
refs/heads/tensorflow-next: e619e5f1f695781c718f9f7259ed3c0fb6b43025
1464+
refs/heads/tensorflow-next: 9ddff82d83e3a926b8a19e292627ec30c5639897

branches/tensorflow-next/include/swift/ABI/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ struct External {
124124

125125
template <typename T, bool Nullable = false>
126126
using RelativeIndirectablePointer = int32_t;
127-
127+
128128
template <typename T, bool Nullable = true>
129-
using RelativeDirectPointer = int32_t;
129+
using RelativeDirectPointer = RelativeDirectPointer<T, Nullable>;
130130
};
131131

132132
/// Template for branching on native pointer types versus external ones

branches/tensorflow-next/include/swift/Reflection/MetadataSourceBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#define SWIFT_REFLECTION_METADATASOURCEBUILDER_H
1919

2020
#include "swift/Reflection/MetadataSource.h"
21+
#include <memory>
22+
#include <vector>
2123

2224
namespace swift {
2325
namespace reflection {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//===--- ProtocolConformance.h --------------------------------*- C++ -*---===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_REFLECTION_PROTOCOLCONFORMANCE_H
14+
#define SWIFT_REFLECTION_PROTOCOLCONFORMANCE_H
15+
16+
#if !defined(__APPLE__) || !defined(__MACH__)
17+
// TODO: Implement this.
18+
#error "Only supported on Darwin now. Do not include this otherwise!"
19+
#endif
20+
21+
#include "swift/ABI/Metadata.h"
22+
#include "swift/Basic/LLVM.h"
23+
#include "swift/Reflection/ReflectionInfo.h"
24+
25+
namespace swift {
26+
namespace reflection {
27+
28+
template <typename Runtime>
29+
class ProtocolDescriptorIterator
30+
: public std::iterator<std::forward_iterator_tag,
31+
TargetProtocolDescriptor<Runtime>> {
32+
// The protocol descriptor section is filled with relative direct
33+
// pointers to protocol descriptors.
34+
using PointerType = RelativeDirectPointer<TargetProtocolDescriptor<Runtime>>;
35+
36+
public:
37+
using ProtocolDescriptor = TargetProtocolDescriptor<Runtime>;
38+
39+
const void *Cur;
40+
const void *const End;
41+
42+
ProtocolDescriptorIterator(const ReflectionInfo &reflectionInfo)
43+
: Cur(reflectionInfo.Protocol.Metadata.getStartAddress()),
44+
End(reflectionInfo.Protocol.Metadata.getEndAddress()) {}
45+
46+
const ProtocolDescriptor &operator*() const { return *curAsPointer(); }
47+
48+
const ProtocolDescriptor *operator->() const { return curAsPointer(); }
49+
50+
bool hasNext() const { return Cur < End; }
51+
52+
ProtocolDescriptorIterator &operator++() {
53+
assert(hasNext());
54+
const void *Next =
55+
reinterpret_cast<const char *>(Cur) + sizeof(PointerType);
56+
Cur = Next;
57+
return *this;
58+
}
59+
60+
bool operator==(ProtocolDescriptorIterator const &other) const {
61+
return Cur == other.Cur && End == other.End;
62+
}
63+
64+
bool operator!=(ProtocolDescriptorIterator const &other) const {
65+
return !(*this == other);
66+
}
67+
68+
const ProtocolDescriptor *curAsPointer() const {
69+
return static_cast<const PointerType *>(Cur)->get();
70+
}
71+
};
72+
73+
} // namespace reflection
74+
} // namespace swift
75+
76+
#endif

branches/tensorflow-next/include/swift/Reflection/Records.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
#ifndef SWIFT_REFLECTION_RECORDS_H
1818
#define SWIFT_REFLECTION_RECORDS_H
1919

20+
#include "swift/Basic/LLVM.h"
2021
#include "swift/Basic/RelativePointer.h"
2122
#include "swift/Demangling/Demangle.h"
2223
#include "llvm/ADT/ArrayRef.h"
24+
#include "llvm/ADT/StringRef.h"
2325

2426
namespace swift {
2527

branches/tensorflow-next/include/swift/Reflection/ReflectionContext.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,26 @@ class ReflectionContext
224224
auto CaptureSec = findMachOSectionByName("__swift5_capture");
225225
auto TypeRefMdSec = findMachOSectionByName("__swift5_typeref");
226226
auto ReflStrMdSec = findMachOSectionByName("__swift5_reflstr");
227+
auto ProtocolSec = findMachOSectionByName("__swift5_protos");
227228

228-
if (FieldMdSec.first == nullptr &&
229-
AssocTySec.first == nullptr &&
230-
BuiltinTySec.first == nullptr &&
231-
CaptureSec.first == nullptr &&
232-
TypeRefMdSec.first == nullptr &&
233-
ReflStrMdSec.first == nullptr)
229+
if (FieldMdSec.first == nullptr && AssocTySec.first == nullptr &&
230+
BuiltinTySec.first == nullptr && CaptureSec.first == nullptr &&
231+
TypeRefMdSec.first == nullptr && ReflStrMdSec.first == nullptr &&
232+
ProtocolSec.first == nullptr)
234233
return false;
235234

236235
auto LocalStartAddress = reinterpret_cast<uint64_t>(SectBuf.get());
237236
auto RemoteStartAddress = static_cast<uint64_t>(RangeStart);
238237

239-
ReflectionInfo info = {
240-
{{FieldMdSec.first, FieldMdSec.second}, 0},
241-
{{AssocTySec.first, AssocTySec.second}, 0},
242-
{{BuiltinTySec.first, BuiltinTySec.second}, 0},
243-
{{CaptureSec.first, CaptureSec.second}, 0},
244-
{{TypeRefMdSec.first, TypeRefMdSec.second}, 0},
245-
{{ReflStrMdSec.first, ReflStrMdSec.second}, 0},
246-
LocalStartAddress,
247-
RemoteStartAddress};
238+
ReflectionInfo info = {{{FieldMdSec.first, FieldMdSec.second}, 0},
239+
{{AssocTySec.first, AssocTySec.second}, 0},
240+
{{BuiltinTySec.first, BuiltinTySec.second}, 0},
241+
{{CaptureSec.first, CaptureSec.second}, 0},
242+
{{TypeRefMdSec.first, TypeRefMdSec.second}, 0},
243+
{{ReflStrMdSec.first, ReflStrMdSec.second}, 0},
244+
{{ProtocolSec.first, ProtocolSec.second}, 0},
245+
LocalStartAddress,
246+
RemoteStartAddress};
248247

249248
this->addReflectionInfo(info);
250249

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
//===--- ReflectionInfo.h --------------------------------*- C++ -*--------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_REFLECTION_REFLECTIONINFO_H
14+
#define SWIFT_REFLECTION_REFLECTIONINFO_H
15+
16+
#include "swift/Reflection/MetadataSource.h"
17+
#include "swift/Reflection/Records.h"
18+
#include "swift/Reflection/TypeRef.h"
19+
#include "swift/Remote/MetadataReader.h"
20+
21+
namespace swift {
22+
namespace reflection {
23+
24+
template <typename IteratorTy> class ReflectionSection {
25+
using const_iterator = IteratorTy;
26+
uintptr_t startAddress;
27+
uintptr_t endAddress;
28+
29+
public:
30+
ReflectionSection(const void *startAddress, const void *endAddress)
31+
: startAddress(uintptr_t(startAddress)),
32+
endAddress(uintptr_t(endAddress)) {}
33+
34+
ReflectionSection(uintptr_t startAddress, uintptr_t endAddress)
35+
: startAddress(startAddress), endAddress(endAddress) {}
36+
37+
void *getStartAddress() { return reinterpret_cast<void *>(startAddress); }
38+
39+
const void *getStartAddress() const {
40+
return reinterpret_cast<const void *>(startAddress);
41+
}
42+
43+
const void *getEndAddress() const {
44+
return reinterpret_cast<const void *>(endAddress);
45+
}
46+
47+
const_iterator begin() const {
48+
return const_iterator(getStartAddress(), getEndAddress());
49+
}
50+
51+
const_iterator end() const {
52+
return const_iterator(getEndAddress(), getEndAddress());
53+
}
54+
55+
size_t size() const { return endAddress - startAddress; }
56+
};
57+
58+
/// A section of packed void * pointers.
59+
using GenericSection = ReflectionSection<const void *>;
60+
61+
template <typename Runtime> class ReflectionContext;
62+
63+
using FieldSection = ReflectionSection<FieldDescriptorIterator>;
64+
using AssociatedTypeSection = ReflectionSection<AssociatedTypeIterator>;
65+
using BuiltinTypeSection = ReflectionSection<BuiltinTypeDescriptorIterator>;
66+
using CaptureSection = ReflectionSection<CaptureDescriptorIterator>;
67+
68+
struct ReflectionInfo {
69+
struct {
70+
FieldSection Metadata;
71+
uint64_t SectionOffset;
72+
} Field;
73+
74+
struct {
75+
AssociatedTypeSection Metadata;
76+
uint64_t SectionOffset;
77+
} AssociatedType;
78+
79+
struct {
80+
BuiltinTypeSection Metadata;
81+
uint64_t SectionOffset;
82+
} Builtin;
83+
84+
struct {
85+
CaptureSection Metadata;
86+
uint64_t SectionOffset;
87+
} Capture;
88+
89+
struct {
90+
GenericSection Metadata;
91+
uint64_t SectionOffset;
92+
} TypeReference;
93+
94+
struct {
95+
GenericSection Metadata;
96+
uint64_t SectionOffset;
97+
} ReflectionString;
98+
99+
#if defined(__APPLE__) && defined(__MACH__)
100+
struct {
101+
GenericSection Metadata;
102+
uint64_t SectionOffset;
103+
} Protocol;
104+
#endif
105+
106+
uint64_t LocalStartAddress;
107+
uint64_t RemoteStartAddress;
108+
};
109+
110+
struct ClosureContextInfo {
111+
std::vector<const TypeRef *> CaptureTypes;
112+
std::vector<std::pair<const TypeRef *, const MetadataSource *>>
113+
MetadataSources;
114+
unsigned NumBindings = 0;
115+
116+
void dump() const;
117+
void dump(std::ostream &OS) const;
118+
};
119+
120+
struct FieldTypeInfo {
121+
std::string Name;
122+
const TypeRef *TR;
123+
bool Indirect;
124+
125+
FieldTypeInfo() : Name(""), TR(nullptr), Indirect(false) {}
126+
FieldTypeInfo(const std::string &Name, const TypeRef *TR, bool Indirect)
127+
: Name(Name), TR(TR), Indirect(Indirect) {}
128+
129+
static FieldTypeInfo forEmptyCase(std::string Name) {
130+
return FieldTypeInfo(Name, nullptr, false);
131+
}
132+
133+
static FieldTypeInfo forIndirectCase(std::string Name, const TypeRef *TR) {
134+
return FieldTypeInfo(Name, TR, true);
135+
}
136+
137+
static FieldTypeInfo forField(std::string Name, const TypeRef *TR) {
138+
return FieldTypeInfo(Name, TR, false);
139+
}
140+
};
141+
142+
} // namespace reflection
143+
} // namespace swift
144+
145+
#endif

0 commit comments

Comments
 (0)