Skip to content

Commit 9ca6b9a

Browse files
committed
[Test] Print to stdout.
In the C++ sources it is slightly more convenient to dump to stderr than to print to stdout, but it is rather more unsightly to print to stderr from the Swift sources. Switch to stdout. Also allows the dump functions to be marked debug only.
1 parent 2eb90c3 commit 9ca6b9a

19 files changed

+71
-79
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/Test.swift

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ private func functionTestThunk(
164164
let invocation = castToInvocation(fromOpaquePointer: erasedInvocation)
165165
let context = FunctionPassContext(_bridged: BridgedPassContext(invocation: passInvocation.invocation))
166166
invocation(function.function, arguments.native, context)
167+
fflush(stdout)
167168
}
168169

169170
/// Bitcast a thin test closure to void *.
@@ -202,46 +203,36 @@ private func castToInvocation(fromOpaquePointer erasedInvocation: UnsafeMutableR
202203
// - something to identify the instance (mostly this means calling dump)
203204
let parseTestSpecificationTest =
204205
FunctionTest(name: "test_specification_parsing") { function, arguments, context in
205-
struct _Stderr : TextOutputStream {
206-
public init() {}
207-
208-
public mutating func write(_ string: String) {
209-
for c in string.utf8 {
210-
writeCharToStderr(CInt(c))
211-
}
212-
}
213-
}
214-
var stderr = _Stderr()
215206
let expectedFields = arguments.takeString()
216207
for expectedField in expectedFields.string {
217208
switch expectedField {
218209
case "A":
219210
let argument = arguments.takeArgument()
220-
print("argument:\n\(argument)", to: &stderr)
211+
print("argument:\n\(argument)")
221212
case "F":
222213
let function = arguments.takeFunction()
223-
print("function: \(function.name)", to: &stderr)
214+
print("function: \(function.name)")
224215
case "B":
225216
let block = arguments.takeBlock()
226-
print("block:\n\(block)", to: &stderr)
217+
print("block:\n\(block)")
227218
case "I":
228219
let instruction = arguments.takeInstruction()
229-
print("instruction: \(instruction)", to: &stderr)
220+
print("instruction: \(instruction)")
230221
case "V":
231222
let value = arguments.takeValue()
232-
print("value: \(value)", to: &stderr)
223+
print("value: \(value)")
233224
case "O":
234225
let operand = arguments.takeOperand()
235-
print("operand: \(operand)", to: &stderr)
226+
print("operand: \(operand)")
236227
case "u":
237228
let u = arguments.takeInt()
238-
print("uint: \(u)", to: &stderr)
229+
print("uint: \(u)")
239230
case "b":
240231
let b = arguments.takeBool()
241-
print("bool: \(b)", to: &stderr)
232+
print("bool: \(b)")
242233
case "s":
243234
let s = arguments.takeString()
244-
print("string: \(s)", to: &stderr)
235+
print("string: \(s)")
245236
default:
246237
fatalError("unknown field type was expected?!");
247238
}

lib/SIL/IR/SILValue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ static FunctionTest IsLexicalTest("is-lexical", [](auto &function,
166166
auto &test) {
167167
auto value = arguments.takeValue();
168168
auto isLexical = value->isLexical();
169-
value->dump();
169+
value->print(llvm::outs());
170170
auto *boolString = isLexical ? "true" : "false";
171-
llvm::errs() << boolString << "\n";
171+
llvm::outs() << boolString << "\n";
172172
});
173173
} // end namespace swift::test
174174

lib/SIL/IR/TypeLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ static FunctionTest PrintTypeLowering("print-type-lowering", [](auto &function,
27582758
auto &test) {
27592759
auto value = arguments.takeValue();
27602760
auto ty = value->getType();
2761-
function.getModule().Types.getTypeLowering(ty, function).print(llvm::dbgs());
2761+
function.getModule().Types.getTypeLowering(ty, function).print(llvm::outs());
27622762
});
27632763
} // end namespace swift::test
27642764

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,12 +1024,12 @@ static FunctionTest FieldSensitiveMultiDefUseLiveRangeTest(
10241024
TypeTreeLeafTypeRange range(begin, end);
10251025
liveness.updateForUse(inst, range, lifetimeEnding);
10261026
}
1027-
liveness.print(llvm::errs());
1027+
liveness.print(llvm::outs());
10281028

10291029
FieldSensitivePrunedLivenessBoundary boundary(
10301030
liveness.getNumSubElements());
10311031
liveness.computeBoundary(boundary);
1032-
boundary.print(llvm::errs());
1032+
boundary.print(llvm::outs());
10331033
});
10341034
} // end namespace swift::test
10351035

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ static FunctionTest
375375
GetTypedAccessAddress("get_typed_access_address",
376376
[](auto &function, auto &arguments, auto &test) {
377377
auto address = arguments.takeValue();
378-
function.dump();
379-
llvm::dbgs() << "Address: " << address;
378+
function.print(llvm::outs());
379+
llvm::outs() << "Address: " << address;
380380
auto access = getTypedAccessAddress(address);
381-
llvm::dbgs() << "Access: " << access;
381+
llvm::outs() << "Access: " << access;
382382
});
383383
} // end namespace swift::test
384384

@@ -404,10 +404,10 @@ static FunctionTest GetAccessBaseTest("get_access_base",
404404
[](auto &function, auto &arguments,
405405
auto &test) {
406406
auto address = arguments.takeValue();
407-
function.dump();
408-
llvm::dbgs() << "Address: " << address;
407+
function.print(llvm::outs());
408+
llvm::outs() << "Address: " << address;
409409
auto base = getAccessBase(address);
410-
llvm::dbgs() << "Base: " << base;
410+
llvm::outs() << "Base: " << base;
411411
});
412412
} // end namespace swift::test
413413

@@ -1196,10 +1196,10 @@ static FunctionTest ComputeAccessStorage("compute_access_storage",
11961196
[](auto &function, auto &arguments,
11971197
auto &test) {
11981198
auto address = arguments.takeValue();
1199-
function.dump();
1200-
llvm::dbgs() << "Address: " << address;
1199+
function.print(llvm::outs());
1200+
llvm::outs() << "Address: " << address;
12011201
auto accessStorage = AccessStorage::compute(address);
1202-
accessStorage.dump();
1202+
accessStorage.print(llvm::outs());
12031203
});
12041204
} // end namespace swift::test
12051205

@@ -2070,7 +2070,7 @@ static FunctionTest AccessPathBaseTest("accesspath-base", [](auto &function,
20702070
auto &arguments,
20712071
auto &test) {
20722072
auto value = arguments.takeValue();
2073-
function.dump();
2073+
function.print(llvm::outs());
20742074
llvm::outs() << "Access path base: " << value;
20752075
auto accessPathWithBase = AccessPathWithBase::compute(value);
20762076
AccessUseTestVisitor visitor;

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ static FunctionTest OSSALifetimeCompletionTest(
364364
"ossa-lifetime-completion",
365365
[](auto &function, auto &arguments, auto &test) {
366366
SILValue value = arguments.takeValue();
367-
llvm::dbgs() << "OSSA lifetime completion: " << value;
367+
llvm::outs() << "OSSA lifetime completion: " << value;
368368
OSSALifetimeCompletion completion(&function, /*domInfo*/ nullptr);
369369
completion.completeOSSALifetime(value);
370-
function.dump();
370+
function.print(llvm::outs());
371371
});
372372
} // end namespace swift::test
373373

lib/SIL/Utils/OwnershipLiveness.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ static FunctionTest LinearLivenessTest("linear-liveness", [](auto &function,
378378
auto &arguments,
379379
auto &test) {
380380
SILValue value = arguments.takeValue();
381-
function.dump();
382-
llvm::dbgs() << "Linear liveness: " << value;
381+
function.print(llvm::outs());
382+
llvm::outs() << "Linear liveness: " << value;
383383
LinearLiveness liveness(value);
384384
liveness.compute();
385385
liveness.print(llvm::outs());
@@ -399,8 +399,8 @@ static FunctionTest
399399
InteriorLivenessTest("interior-liveness",
400400
[](auto &function, auto &arguments, auto &test) {
401401
SILValue value = arguments.takeValue();
402-
function.dump();
403-
llvm::dbgs() << "Interior liveness: " << value;
402+
function.print(llvm::outs());
403+
llvm::outs() << "Interior liveness: " << value;
404404
auto *domTree = test.getDominanceInfo();
405405
InteriorLiveness liveness(value);
406406
auto handleInnerScope = [](SILValue innerBorrow) {
@@ -423,8 +423,8 @@ static FunctionTest
423423
static FunctionTest ExtendedLinearLivenessTest(
424424
"extended-liveness", [](auto &function, auto &arguments, auto &test) {
425425
SILValue value = arguments.takeValue();
426-
function.dump();
427-
llvm::dbgs() << "Extended liveness: " << value;
426+
function.print(llvm::outs());
427+
llvm::outs() << "Extended liveness: " << value;
428428
ExtendedLinearLiveness liveness(value);
429429
liveness.compute();
430430
liveness.print(llvm::outs());

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ static FunctionTest OwnershipUtilsHasPointerEscape(
105105
"has-pointer-escape", [](auto &function, auto &arguments, auto &test) {
106106
auto value = arguments.takeValue();
107107
auto has = findPointerEscape(value);
108-
value->print(llvm::errs());
108+
value->print(llvm::outs());
109109
auto *boolString = has ? "true" : "false";
110-
llvm::errs() << boolString << "\n";
110+
llvm::outs() << boolString << "\n";
111111
});
112112
} // end namespace swift::test
113113

@@ -2057,10 +2057,10 @@ namespace swift::test {
20572057
// - the enclosing defs
20582058
static FunctionTest FindEnclosingDefsTest(
20592059
"find-enclosing-defs", [](auto &function, auto &arguments, auto &test) {
2060-
function.dump();
2061-
llvm::dbgs() << "Enclosing Defs:\n";
2060+
function.print(llvm::outs());
2061+
llvm::outs() << "Enclosing Defs:\n";
20622062
visitEnclosingDefs(arguments.takeValue(), [](SILValue def) {
2063-
def->dump();
2063+
def->print(llvm::outs());
20642064
return true;
20652065
});
20662066
});
@@ -2082,10 +2082,10 @@ namespace swift::test {
20822082
// - the borrow introducers
20832083
static FunctionTest FindBorrowIntroducers(
20842084
"find-borrow-introducers", [](auto &function, auto &arguments, auto &test) {
2085-
function.dump();
2086-
llvm::dbgs() << "Introducers:\n";
2085+
function.print(llvm::outs());
2086+
llvm::outs() << "Introducers:\n";
20872087
visitBorrowIntroducers(arguments.takeValue(), [](SILValue def) {
2088-
def->dump();
2088+
def->print(llvm::outs());
20892089
return true;
20902090
});
20912091
});
@@ -2202,10 +2202,10 @@ namespace swift::test {
22022202
static FunctionTest VisitInnerAdjacentPhisTest(
22032203
"visit-inner-adjacent-phis",
22042204
[](auto &function, auto &arguments, auto &test) {
2205-
function.dump();
2205+
function.print(llvm::outs());
22062206
visitInnerAdjacentPhis(cast<SILPhiArgument>(arguments.takeValue()),
22072207
[](auto *argument) -> bool {
2208-
argument->dump();
2208+
argument->print(llvm::outs());
22092209
return true;
22102210
});
22112211
});

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ static FunctionTest
182182
while (arguments.hasUntaken()) {
183183
boundary.lastUsers.push_back(arguments.takeInstruction());
184184
}
185-
boundary.visitInsertionPoints(
186-
[](SILBasicBlock::iterator point) { point->dump(); });
185+
boundary.visitInsertionPoints([](SILBasicBlock::iterator point) {
186+
point->print(llvm::outs());
187+
});
187188
});
188189
} // end namespace swift::test
189190

lib/SIL/Utils/Test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void FunctionTest::run(SILFunction &function, Arguments &arguments,
9797
auto fn = invocation.get<Invocation>();
9898
fn(function, arguments, *this);
9999
} else {
100+
llvm::outs().flush();
100101
auto *fn = invocation.get<NativeSwiftInvocation>();
101102
Registry::get().getFunctionTestThunk()(fn, {&function}, {&arguments},
102103
{getInvocation()});

0 commit comments

Comments
 (0)