Skip to content

Commit d68dc5a

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents ceb4559 + 28daeae commit d68dc5a

File tree

8 files changed

+68
-10
lines changed

8 files changed

+68
-10
lines changed

include/swift/AST/SemanticAttrs.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER,
7575
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_OWNED2GUARANTEE_NEVER,
7676
"optimize.sil.specialize.owned2guarantee.never")
7777

78+
SEMANTICS_ATTR(OSLOG_MESSAGE_TYPE, "oslog.message.type")
7879
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_INTERPOLATION, "oslog.message.init_interpolation")
7980
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_STRING_LITERAL, "oslog.message.init_stringliteral")
8081
SEMANTICS_ATTR(OSLOG_REQUIRES_CONSTANT_ARGUMENTS, "oslog.requires_constant_arguments")

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ PASS(Outliner, "outliner",
308308
"Function Outlining Optimization")
309309
PASS(OwnershipModelEliminator, "ownership-model-eliminator",
310310
"Eliminate Ownership Annotation of SIL")
311+
PASS(ModulePrinter, "module-printer",
312+
"Print the module")
311313
PASS(NestedSemanticFunctionCheck, "nested-semantic-function-check",
312314
"Diagnose improperly nested '@_semantics' functions")
313315
PASS(NonTransparentFunctionOwnershipModelEliminator,

lib/SILOptimizer/Mandatory/OSLogOptimization.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,8 +1510,8 @@ static ApplyInst *getAsOSLogMessageInit(SILInstruction *inst) {
15101510
}
15111511

15121512
/// Return true iff the SIL function \c fun is a method of the \c OSLogMessage
1513-
/// type.
1514-
bool isMethodOfOSLogMessage(SILFunction &fun) {
1513+
/// type or a type that has the @_semantics("oslog.message.type") annotation.
1514+
static bool isMethodOfOSLogMessage(SILFunction &fun) {
15151515
DeclContext *declContext = fun.getDeclContext();
15161516
if (!declContext)
15171517
return false;
@@ -1527,7 +1527,8 @@ bool isMethodOfOSLogMessage(SILFunction &fun) {
15271527
NominalTypeDecl *typeDecl = parentContext->getSelfNominalTypeDecl();
15281528
if (!typeDecl)
15291529
return false;
1530-
return typeDecl->getName() == fun.getASTContext().Id_OSLogMessage;
1530+
return typeDecl->getName() == fun.getASTContext().Id_OSLogMessage
1531+
|| typeDecl->hasSemanticsAttr(semantics::OSLOG_MESSAGE_TYPE);
15311532
}
15321533

15331534
class OSLogOptimization : public SILFunctionTransform {

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ static llvm::cl::opt<bool>
4343
SILViewCFG("sil-view-cfg", llvm::cl::init(false),
4444
llvm::cl::desc("Enable the sil cfg viewer pass"));
4545

46-
static llvm::cl::opt<bool> SILViewGuaranteedCFG(
47-
"sil-view-guaranteed-cfg", llvm::cl::init(false),
46+
static llvm::cl::opt<bool> SILViewCanonicalCFG(
47+
"sil-view-canonical-cfg", llvm::cl::init(false),
4848
llvm::cl::desc("Enable the sil cfg viewer pass after diagnostics"));
4949

50+
static llvm::cl::opt<bool> SILPrintCanonicalModule(
51+
"sil-print-canonical-module", llvm::cl::init(false),
52+
llvm::cl::desc("Print the textual SIL module after diagnostics"));
53+
5054
static llvm::cl::opt<bool> SILViewSILGenCFG(
5155
"sil-view-silgen-cfg", llvm::cl::init(false),
5256
llvm::cl::desc("Enable the sil cfg viewer pass before diagnostics"));
@@ -64,6 +68,12 @@ static void addCFGPrinterPipeline(SILPassPipelinePlan &P, StringRef Name) {
6468
P.addCFGPrinter();
6569
}
6670

71+
static void addModulePrinterPipeline(SILPassPipelinePlan &plan,
72+
StringRef name) {
73+
plan.startPipeline(name);
74+
plan.addModulePrinter();
75+
}
76+
6777
static void addMandatoryDebugSerialization(SILPassPipelinePlan &P) {
6878
P.startPipeline("Mandatory Debug Serialization");
6979
P.addOwnershipModelEliminator();
@@ -187,8 +197,11 @@ SILPassPipelinePlan::getDiagnosticPassPipeline(const SILOptions &Options) {
187197
// Otherwise run the rest of diagnostics.
188198
addMandatoryDiagnosticOptPipeline(P);
189199

190-
if (SILViewGuaranteedCFG) {
191-
addCFGPrinterPipeline(P, "SIL View Guaranteed CFG");
200+
if (SILViewCanonicalCFG) {
201+
addCFGPrinterPipeline(P, "SIL View Canonical CFG");
202+
}
203+
if (SILPrintCanonicalModule) {
204+
addModulePrinterPipeline(P, "SIL Print Canonical Module");
192205
}
193206
return P;
194207
}

lib/SILOptimizer/UtilityPasses/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ target_sources(swiftSILOptimizer PRIVATE
2525
LoopInfoPrinter.cpp
2626
LoopRegionPrinter.cpp
2727
MemBehaviorDumper.cpp
28+
ModulePrinter.cpp
2829
RCIdentityDumper.cpp
2930
SerializeSILPass.cpp
3031
SILDebugInfoGenerator.cpp
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===--- ModulePrinter.cpp - Module printer pass --------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2021 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+
// A utility module pass to print the module as textual SIL.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#include "swift/SIL/SILPrintContext.h"
18+
#include "swift/SILOptimizer/PassManager/Passes.h"
19+
#include "swift/SILOptimizer/PassManager/Transforms.h"
20+
21+
using namespace swift;
22+
23+
namespace {
24+
25+
class SILModulePrinter : public SILModuleTransform {
26+
27+
/// The entry point.
28+
void run() override {
29+
auto *module = getModule();
30+
SILPrintContext context(llvm::outs(), /*Verbose*/ true, /*SortedSIL*/ true,
31+
/*PrintFullConvention*/ true);
32+
module->print(context);
33+
}
34+
};
35+
36+
} // end anonymous namespace
37+
38+
SILTransform *swift::createModulePrinter() { return new SILModulePrinter(); }

lib/Sema/ConstantnessSemaDiagnostics.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ static void diagnoseError(Expr *errorExpr, const ASTContext &astContext,
284284
}
285285
// If this is OSLogMessage, it should be a string-interpolation literal.
286286
Identifier declName = nominalDecl->getName();
287-
if (declName == astContext.Id_OSLogMessage) {
287+
if (declName == astContext.Id_OSLogMessage ||
288+
nominalDecl->hasSemanticsAttr(semantics::OSLOG_MESSAGE_TYPE)) {
288289
diags.diagnose(errorLoc, diag::oslog_message_must_be_string_interpolation);
289290
return;
290291
}

stdlib/private/OSLog/OSLogTestHelper.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ internal func _os_log_impl_test(
121121
/// on the special case of animation begin signposts.
122122
@_transparent
123123
public func _osSignpostAnimationBeginTestHelper(
124-
_ format: AnimationFormatString.OSLogMessage,
124+
_ format: AnimationFormatString.MyLogMessage,
125125
_ arguments: CVarArg...
126126
) {
127127
_animationBeginSignpostHelper(formatStringPointer: format.formatStringPointer,
@@ -149,7 +149,8 @@ public enum AnimationFormatString {
149149
}
150150

151151
@frozen
152-
public struct OSLogMessage : ExpressibleByStringLiteral {
152+
@_semantics("oslog.message.type")
153+
public struct MyLogMessage : ExpressibleByStringLiteral {
153154
@usableFromInline
154155
var formatStringPointer: UnsafePointer<CChar>
155156

0 commit comments

Comments
 (0)