Skip to content

Commit 52035c1

Browse files
authored
Merge pull request #27081 from ismetanin/SR-7165
SR-7165. Excise <iostream> from reflection
2 parents e3f934a + b906348 commit 52035c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1212
-1236
lines changed

include/swift/Demangling/Demangler.h

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323

2424
//#define NODE_FACTORY_DEBUGGING
2525

26-
#ifdef NODE_FACTORY_DEBUGGING
27-
#include <iostream>
28-
#endif
29-
30-
3126
using namespace swift::Demangle;
3227
using llvm::StringRef;
3328

@@ -86,7 +81,7 @@ class NodeFactory {
8681

8782
NodeFactory() {
8883
#ifdef NODE_FACTORY_DEBUGGING
89-
std::cerr << indent() << "## New NodeFactory\n";
84+
fprintf(stderr, "%s## New NodeFactory\n", indent().c_str());
9085
nestingLevel++;
9186
#endif
9287
}
@@ -96,8 +91,7 @@ class NodeFactory {
9691
/// Only if this memory overflows, the factory begins to malloc.
9792
void providePreallocatedMemory(char *Memory, size_t Size) {
9893
#ifdef NODE_FACTORY_DEBUGGING
99-
std::cerr << indent() << "++ provide preallocated memory, size = "
100-
<< Size << '\n';
94+
fprintf(stderr, "%s++ provide preallocated memory, size = %zu\n", indent().c_str(), Size);
10195
#endif
10296
assert(!CurPtr && !End && !CurrentSlab);
10397
CurPtr = Memory;
@@ -116,17 +110,15 @@ class NodeFactory {
116110
CurPtr = BorrowFrom.CurPtr;
117111
End = BorrowFrom.End;
118112
#ifdef NODE_FACTORY_DEBUGGING
119-
std::cerr << indent() << "++ borrow memory, size = "
120-
<< (End - CurPtr) << '\n';
113+
fprintf(stderr, "%s++ borrow memory, size = %zu\n", indent().c_str(), (End - CurPtr));
121114
#endif
122115
}
123116

124117
virtual ~NodeFactory() {
125118
freeSlabs(CurrentSlab);
126119
#ifdef NODE_FACTORY_DEBUGGING
127120
nestingLevel--;
128-
std::cerr << indent() << "## Delete NodeFactory: allocated memory = "
129-
<< allocatedMemory << '\n';
121+
fprintf(stderr, "%s## Delete NodeFactory: allocated memory = %zu\n", indent().c_str(), allocatedMemory)
130122
#endif
131123
if (BorrowedFrom) {
132124
BorrowedFrom->isBorrowed = false;
@@ -141,8 +133,7 @@ class NodeFactory {
141133
size_t ObjectSize = NumObjects * sizeof(T);
142134
CurPtr = align(CurPtr, alignof(T));
143135
#ifdef NODE_FACTORY_DEBUGGING
144-
std::cerr << indent() << "alloc " << ObjectSize << ", CurPtr = "
145-
<< (void *)CurPtr << "\n";
136+
fprintf(stderr, "%salloc %zu, CurPtr = %p\n", indent().c_str(), ObjectSize, (void *)CurPtr)
146137
allocatedMemory += ObjectSize;
147138
#endif
148139

@@ -163,9 +154,8 @@ class NodeFactory {
163154
End = (char *)newSlab + AllocSize;
164155
assert(CurPtr + ObjectSize <= End);
165156
#ifdef NODE_FACTORY_DEBUGGING
166-
std::cerr << indent() << "** new slab " << newSlab << ", allocsize = "
167-
<< AllocSize << ", CurPtr = " << (void *)CurPtr
168-
<< ", End = " << (void *)End << "\n";
157+
fprintf(stderr, "%s** new slab %p, allocsize = %zu, CurPtr = %p, End = %p\n",
158+
indent().c_str(), newSlab, AllocSize, (void *)CurPtr, (void *)End);
169159
#endif
170160
}
171161
T *AllocatedObj = (T *)CurPtr;
@@ -189,9 +179,8 @@ class NodeFactory {
189179
size_t AdditionalAlloc = MinGrowth * sizeof(T);
190180

191181
#ifdef NODE_FACTORY_DEBUGGING
192-
std::cerr << indent() << "realloc: capacity = " << Capacity
193-
<< " (size = " << OldAllocSize << "), growth = " << MinGrowth
194-
<< " (size = " << AdditionalAlloc << ")\n";
182+
fprintf(stderr, "%srealloc: capacity = %d (size = %zu), growth = %zu (size = %zu)\n",
183+
indent().c_str(), Capacity, OldAllocSize, MinGrowth, AdditionalAlloc);
195184
#endif
196185
if ((char *)Objects + OldAllocSize == CurPtr
197186
&& CurPtr + AdditionalAlloc <= End) {
@@ -200,7 +189,7 @@ class NodeFactory {
200189
CurPtr += AdditionalAlloc;
201190
Capacity += MinGrowth;
202191
#ifdef NODE_FACTORY_DEBUGGING
203-
std::cerr << indent() << "** can grow: " << (void *)CurPtr << '\n';
192+
fprintf(stderr, "%s** can grow: %p\n", indent().c_str(), (void *)CurPtr);
204193
allocatedMemory += AdditionalAlloc;
205194
#endif
206195
return;

include/swift/Reflection/MetadataSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class MetadataSource {
177177
}
178178

179179
void dump() const;
180-
void dump(std::ostream &OS, unsigned Indent = 0) const;
180+
void dump(FILE *file, unsigned Indent = 0) const;
181181
template <typename Allocator>
182182
static const MetadataSource *decode(Allocator &A, const std::string &str) {
183183
auto begin = str.begin();

include/swift/Reflection/ReflectionContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "swift/Reflection/TypeRefBuilder.h"
3232
#include "swift/Runtime/Unreachable.h"
3333

34-
#include <iostream>
3534
#include <set>
3635
#include <vector>
3736
#include <unordered_map>

include/swift/Reflection/TypeLowering.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "llvm/Support/Casting.h"
2424
#include "swift/Remote/MetadataReader.h"
2525

26-
#include <iostream>
2726
#include <memory>
2827

2928
namespace swift {
@@ -134,7 +133,7 @@ class TypeInfo {
134133
bool isBitwiseTakable() const { return BitwiseTakable; }
135134

136135
void dump() const;
137-
void dump(std::ostream &OS, unsigned Indent = 0) const;
136+
void dump(FILE *file, unsigned Indent = 0) const;
138137
};
139138

140139
struct FieldInfo {

include/swift/Reflection/TypeRef.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include "swift/Remote/MetadataReader.h"
2525
#include "swift/Runtime/Unreachable.h"
2626

27-
#include <iostream>
28-
2927
namespace swift {
3028
namespace reflection {
3129

@@ -150,7 +148,7 @@ class alignas(void *) TypeRef {
150148
}
151149

152150
void dump() const;
153-
void dump(std::ostream &OS, unsigned Indent = 0) const;
151+
void dump(FILE *file, unsigned Indent = 0) const;
154152

155153
bool isConcrete() const;
156154
bool isConcreteAfterSubstitutions(const GenericArgumentMap &Subs) const;

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/Reflection/TypeRef.h"
2626
#include "llvm/ADT/Optional.h"
2727

28-
#include <iostream>
2928
#include <vector>
3029
#include <unordered_map>
3130

@@ -211,7 +210,7 @@ struct ClosureContextInfo {
211210
unsigned NumBindings = 0;
212211

213212
void dump() const;
214-
void dump(std::ostream &OS) const;
213+
void dump(FILE *file) const;
215214
};
216215

217216
struct FieldTypeInfo {
@@ -653,13 +652,13 @@ class TypeRefBuilder {
653652
/// Dumping typerefs, field declarations, associated types
654653
///
655654

656-
void dumpTypeRef(RemoteRef<char> mangledName,
657-
std::ostream &OS, bool printTypeName = false);
658-
void dumpFieldSection(std::ostream &OS);
659-
void dumpAssociatedTypeSection(std::ostream &OS);
660-
void dumpBuiltinTypeSection(std::ostream &OS);
661-
void dumpCaptureSection(std::ostream &OS);
662-
void dumpAllSections(std::ostream &OS);
655+
void dumpTypeRef(RemoteRef<char> MangledName,
656+
FILE *file, bool printTypeName = false);
657+
void dumpFieldSection(FILE *file);
658+
void dumpAssociatedTypeSection(FILE *file);
659+
void dumpBuiltinTypeSection(FILE *file);
660+
void dumpCaptureSection(FILE *file);
661+
void dumpAllSections(FILE *file);
663662
};
664663

665664

lib/Demangling/Demangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void NodeFactory::clear() {
412412
assert(!isBorrowed);
413413
if (CurrentSlab) {
414414
#ifdef NODE_FACTORY_DEBUGGING
415-
std::cerr << indent() << "## clear: allocated memory = " << allocatedMemory << "\n";
415+
fprintf(stderr, "%s## clear: allocated memory = %zu\n", indent().c_str(), allocatedMemory);
416416
#endif
417417

418418
freeSlabs(CurrentSlab->Previous);

stdlib/public/Reflection/MetadataSource.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,69 @@ using namespace reflection;
1919

2020
class PrintMetadataSource
2121
: public MetadataSourceVisitor<PrintMetadataSource, void> {
22-
std::ostream &OS;
22+
FILE *file;
2323
unsigned Indent;
2424

25-
std::ostream &indent(unsigned Amount) {
25+
FILE * indent(unsigned Amount) {
2626
for (unsigned i = 0; i < Amount; ++i)
27-
OS << ' ';
28-
return OS;
27+
fprintf(file, " ");
28+
return file;
2929
}
3030

31-
std::ostream &printHeader(std::string Name) {
32-
indent(Indent) << '(' << Name;
33-
return OS;
31+
FILE * printHeader(std::string Name) {
32+
fprintf(indent(Indent), "(%s", Name.c_str());
33+
return file;
3434
}
3535

36-
template<typename T>
37-
std::ostream &printField(std::string name, const T &value) {
36+
FILE * printField(std::string name, std::string value) {
3837
if (!name.empty())
39-
OS << " " << name << "=" << value;
38+
fprintf(file, " %s=%s", name.c_str(), value.c_str());
4039
else
41-
OS << " " << value;
42-
return OS;
40+
fprintf(file, " %s", value.c_str());
41+
return file;
4342
}
4443

4544
void printRec(const MetadataSource *MS) {
46-
OS << "\n";
45+
fprintf(file, "\n");
4746

4847
Indent += 2;
4948
visit(MS);
5049
Indent -= 2;
5150
}
5251

5352
void closeForm() {
54-
OS << ')';
53+
fprintf(file, ")");
5554
}
5655

5756
public:
58-
PrintMetadataSource(std::ostream &OS, unsigned Indent)
59-
: OS(OS), Indent(Indent) {}
57+
PrintMetadataSource(FILE *file, unsigned Indent)
58+
: file(file), Indent(Indent) {}
6059

6160
void
6261
visitClosureBindingMetadataSource(const ClosureBindingMetadataSource *CB) {
6362
printHeader("closure_binding");
64-
printField("index", CB->getIndex());
63+
printField("index", std::to_string(CB->getIndex()));
6564
closeForm();
6665
}
6766

6867
void
6968
visitReferenceCaptureMetadataSource(const ReferenceCaptureMetadataSource *RC){
7069
printHeader("reference_capture");
71-
printField("index", RC->getIndex());
70+
printField("index", std::to_string(RC->getIndex()));
7271
closeForm();
7372
}
7473

7574
void
7675
visitMetadataCaptureMetadataSource(const MetadataCaptureMetadataSource *MC){
7776
printHeader("metadata_capture");
78-
printField("index", MC->getIndex());
77+
printField("index", std::to_string(MC->getIndex()));
7978
closeForm();
8079
}
8180

8281
void
8382
visitGenericArgumentMetadataSource(const GenericArgumentMetadataSource *GA) {
8483
printHeader("generic_argument");
85-
printField("index", GA->getIndex());
84+
printField("index", std::to_string(GA->getIndex()));
8685
printRec(GA->getSource());
8786
closeForm();
8887
}
@@ -100,10 +99,10 @@ class PrintMetadataSource
10099
};
101100

102101
void MetadataSource::dump() const {
103-
dump(std::cerr, 0);
102+
dump(stderr, 0);
104103
}
105104

106-
void MetadataSource::dump(std::ostream &OS, unsigned Indent) const {
107-
PrintMetadataSource(OS, Indent).visit(this);
108-
OS << '\n';
105+
void MetadataSource::dump(FILE *file, unsigned Indent) const {
106+
PrintMetadataSource(file, Indent).visit(this);
107+
fprintf(file, "\n");
109108
}

0 commit comments

Comments
 (0)