Skip to content

SR-7165. Excise <iostream> from reflection #27081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions include/swift/Demangling/Demangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

//#define NODE_FACTORY_DEBUGGING

#ifdef NODE_FACTORY_DEBUGGING
#include <iostream>
#endif


using namespace swift::Demangle;
using llvm::StringRef;

Expand Down Expand Up @@ -86,7 +81,7 @@ class NodeFactory {

NodeFactory() {
#ifdef NODE_FACTORY_DEBUGGING
std::cerr << indent() << "## New NodeFactory\n";
fprintf(stderr, "%s## New NodeFactory\n", indent().c_str());
nestingLevel++;
#endif
}
Expand All @@ -96,8 +91,7 @@ class NodeFactory {
/// Only if this memory overflows, the factory begins to malloc.
void providePreallocatedMemory(char *Memory, size_t Size) {
#ifdef NODE_FACTORY_DEBUGGING
std::cerr << indent() << "++ provide preallocated memory, size = "
<< Size << '\n';
fprintf(stderr, "%s++ provide preallocated memory, size = %zu\n", indent().c_str(), Size);
#endif
assert(!CurPtr && !End && !CurrentSlab);
CurPtr = Memory;
Expand All @@ -116,17 +110,15 @@ class NodeFactory {
CurPtr = BorrowFrom.CurPtr;
End = BorrowFrom.End;
#ifdef NODE_FACTORY_DEBUGGING
std::cerr << indent() << "++ borrow memory, size = "
<< (End - CurPtr) << '\n';
fprintf(stderr, "%s++ borrow memory, size = %zu\n", indent().c_str(), (End - CurPtr));
#endif
}

virtual ~NodeFactory() {
freeSlabs(CurrentSlab);
#ifdef NODE_FACTORY_DEBUGGING
nestingLevel--;
std::cerr << indent() << "## Delete NodeFactory: allocated memory = "
<< allocatedMemory << '\n';
fprintf(stderr, "%s## Delete NodeFactory: allocated memory = %zu\n", indent().c_str(), allocatedMemory)
#endif
if (BorrowedFrom) {
BorrowedFrom->isBorrowed = false;
Expand All @@ -141,8 +133,7 @@ class NodeFactory {
size_t ObjectSize = NumObjects * sizeof(T);
CurPtr = align(CurPtr, alignof(T));
#ifdef NODE_FACTORY_DEBUGGING
std::cerr << indent() << "alloc " << ObjectSize << ", CurPtr = "
<< (void *)CurPtr << "\n";
fprintf(stderr, "%salloc %zu, CurPtr = %p\n", indent().c_str(), ObjectSize, (void *)CurPtr)
allocatedMemory += ObjectSize;
#endif

Expand All @@ -163,9 +154,8 @@ class NodeFactory {
End = (char *)newSlab + AllocSize;
assert(CurPtr + ObjectSize <= End);
#ifdef NODE_FACTORY_DEBUGGING
std::cerr << indent() << "** new slab " << newSlab << ", allocsize = "
<< AllocSize << ", CurPtr = " << (void *)CurPtr
<< ", End = " << (void *)End << "\n";
fprintf(stderr, "%s** new slab %p, allocsize = %zu, CurPtr = %p, End = %p\n",
indent().c_str(), newSlab, AllocSize, (void *)CurPtr, (void *)End);
#endif
}
T *AllocatedObj = (T *)CurPtr;
Expand All @@ -189,9 +179,8 @@ class NodeFactory {
size_t AdditionalAlloc = MinGrowth * sizeof(T);

#ifdef NODE_FACTORY_DEBUGGING
std::cerr << indent() << "realloc: capacity = " << Capacity
<< " (size = " << OldAllocSize << "), growth = " << MinGrowth
<< " (size = " << AdditionalAlloc << ")\n";
fprintf(stderr, "%srealloc: capacity = %d (size = %zu), growth = %zu (size = %zu)\n",
indent().c_str(), Capacity, OldAllocSize, MinGrowth, AdditionalAlloc);
#endif
if ((char *)Objects + OldAllocSize == CurPtr
&& CurPtr + AdditionalAlloc <= End) {
Expand All @@ -200,7 +189,7 @@ class NodeFactory {
CurPtr += AdditionalAlloc;
Capacity += MinGrowth;
#ifdef NODE_FACTORY_DEBUGGING
std::cerr << indent() << "** can grow: " << (void *)CurPtr << '\n';
fprintf(stderr, "%s** can grow: %p\n", indent().c_str(), (void *)CurPtr);
allocatedMemory += AdditionalAlloc;
#endif
return;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Reflection/MetadataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class MetadataSource {
}

void dump() const;
void dump(std::ostream &OS, unsigned Indent = 0) const;
void dump(FILE *file, unsigned Indent = 0) const;
template <typename Allocator>
static const MetadataSource *decode(Allocator &A, const std::string &str) {
auto begin = str.begin();
Expand Down
1 change: 0 additions & 1 deletion include/swift/Reflection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "swift/Reflection/TypeRefBuilder.h"
#include "swift/Runtime/Unreachable.h"

#include <iostream>
#include <set>
#include <vector>
#include <unordered_map>
Expand Down
3 changes: 1 addition & 2 deletions include/swift/Reflection/TypeLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "llvm/Support/Casting.h"
#include "swift/Remote/MetadataReader.h"

#include <iostream>
#include <memory>

namespace swift {
Expand Down Expand Up @@ -134,7 +133,7 @@ class TypeInfo {
bool isBitwiseTakable() const { return BitwiseTakable; }

void dump() const;
void dump(std::ostream &OS, unsigned Indent = 0) const;
void dump(FILE *file, unsigned Indent = 0) const;
};

struct FieldInfo {
Expand Down
4 changes: 1 addition & 3 deletions include/swift/Reflection/TypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include "swift/Remote/MetadataReader.h"
#include "swift/Runtime/Unreachable.h"

#include <iostream>

namespace swift {
namespace reflection {

Expand Down Expand Up @@ -150,7 +148,7 @@ class alignas(void *) TypeRef {
}

void dump() const;
void dump(std::ostream &OS, unsigned Indent = 0) const;
void dump(FILE *file, unsigned Indent = 0) const;

bool isConcrete() const;
bool isConcreteAfterSubstitutions(const GenericArgumentMap &Subs) const;
Expand Down
17 changes: 8 additions & 9 deletions include/swift/Reflection/TypeRefBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "swift/Reflection/TypeRef.h"
#include "llvm/ADT/Optional.h"

#include <iostream>
#include <vector>
#include <unordered_map>

Expand Down Expand Up @@ -211,7 +210,7 @@ struct ClosureContextInfo {
unsigned NumBindings = 0;

void dump() const;
void dump(std::ostream &OS) const;
void dump(FILE *file) const;
};

struct FieldTypeInfo {
Expand Down Expand Up @@ -653,13 +652,13 @@ class TypeRefBuilder {
/// Dumping typerefs, field declarations, associated types
///

void dumpTypeRef(RemoteRef<char> mangledName,
std::ostream &OS, bool printTypeName = false);
void dumpFieldSection(std::ostream &OS);
void dumpAssociatedTypeSection(std::ostream &OS);
void dumpBuiltinTypeSection(std::ostream &OS);
void dumpCaptureSection(std::ostream &OS);
void dumpAllSections(std::ostream &OS);
void dumpTypeRef(RemoteRef<char> MangledName,
FILE *file, bool printTypeName = false);
void dumpFieldSection(FILE *file);
void dumpAssociatedTypeSection(FILE *file);
void dumpBuiltinTypeSection(FILE *file);
void dumpCaptureSection(FILE *file);
void dumpAllSections(FILE *file);
};


Expand Down
2 changes: 1 addition & 1 deletion lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void NodeFactory::clear() {
assert(!isBorrowed);
if (CurrentSlab) {
#ifdef NODE_FACTORY_DEBUGGING
std::cerr << indent() << "## clear: allocated memory = " << allocatedMemory << "\n";
fprintf(stderr, "%s## clear: allocated memory = %zu\n", indent().c_str(), allocatedMemory);
#endif

freeSlabs(CurrentSlab->Previous);
Expand Down
47 changes: 23 additions & 24 deletions stdlib/public/Reflection/MetadataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,70 +19,69 @@ using namespace reflection;

class PrintMetadataSource
: public MetadataSourceVisitor<PrintMetadataSource, void> {
std::ostream &OS;
FILE *file;
unsigned Indent;

std::ostream &indent(unsigned Amount) {
FILE * indent(unsigned Amount) {
for (unsigned i = 0; i < Amount; ++i)
OS << ' ';
return OS;
fprintf(file, " ");
return file;
}

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

template<typename T>
std::ostream &printField(std::string name, const T &value) {
FILE * printField(std::string name, std::string value) {
if (!name.empty())
OS << " " << name << "=" << value;
fprintf(file, " %s=%s", name.c_str(), value.c_str());
else
OS << " " << value;
return OS;
fprintf(file, " %s", value.c_str());
return file;
}

void printRec(const MetadataSource *MS) {
OS << "\n";
fprintf(file, "\n");

Indent += 2;
visit(MS);
Indent -= 2;
}

void closeForm() {
OS << ')';
fprintf(file, ")");
}

public:
PrintMetadataSource(std::ostream &OS, unsigned Indent)
: OS(OS), Indent(Indent) {}
PrintMetadataSource(FILE *file, unsigned Indent)
: file(file), Indent(Indent) {}

void
visitClosureBindingMetadataSource(const ClosureBindingMetadataSource *CB) {
printHeader("closure_binding");
printField("index", CB->getIndex());
printField("index", std::to_string(CB->getIndex()));
closeForm();
}

void
visitReferenceCaptureMetadataSource(const ReferenceCaptureMetadataSource *RC){
printHeader("reference_capture");
printField("index", RC->getIndex());
printField("index", std::to_string(RC->getIndex()));
closeForm();
}

void
visitMetadataCaptureMetadataSource(const MetadataCaptureMetadataSource *MC){
printHeader("metadata_capture");
printField("index", MC->getIndex());
printField("index", std::to_string(MC->getIndex()));
closeForm();
}

void
visitGenericArgumentMetadataSource(const GenericArgumentMetadataSource *GA) {
printHeader("generic_argument");
printField("index", GA->getIndex());
printField("index", std::to_string(GA->getIndex()));
printRec(GA->getSource());
closeForm();
}
Expand All @@ -100,10 +99,10 @@ class PrintMetadataSource
};

void MetadataSource::dump() const {
dump(std::cerr, 0);
dump(stderr, 0);
}

void MetadataSource::dump(std::ostream &OS, unsigned Indent) const {
PrintMetadataSource(OS, Indent).visit(this);
OS << '\n';
void MetadataSource::dump(FILE *file, unsigned Indent) const {
PrintMetadataSource(file, Indent).visit(this);
fprintf(file, "\n");
}
Loading