Skip to content

Commit 2ca448b

Browse files
committed
Address review comments
* add namespace * fix block comment style * SEMA_ATTR -> SEMANTICS_ATTR * error when SEMANTICS_ATTR isn't defined
1 parent 9c1a614 commit 2ca448b

File tree

12 files changed

+84
-77
lines changed

12 files changed

+84
-77
lines changed

include/swift/AST/SemanticAttrs.def

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,65 +15,69 @@
1515
// NAME: the global name used in the compiler
1616
// C_STR: the raw value used in swift
1717
//
18-
// SEMA_ATTR(NAME, C_STR)
18+
// SEMANTICS_ATTR(NAME, C_STR)
1919
//
2020
//===----------------------------------------------------------------------===//
2121

22-
SEMA_ATTR(STRING_EQUALS, "string.equals")
23-
SEMA_ATTR(STRING_MAKE_UTF8, "string.makeUTF8")
24-
SEMA_ATTR(STRING_ESCAPE_PERCENT_GET, "string.escapePercent.get")
25-
SEMA_ATTR(STRING_CONCAT, "string.concat")
26-
SEMA_ATTR(STRING_APPEND, "string.append")
27-
SEMA_ATTR(STRING_INIT_EMPTY, "string.init_empty")
28-
SEMA_ATTR(STRING_PLUS_EQUALS, "string.plusequals")
29-
SEMA_ATTR(FIND_STRING_SWITCH_CASE, "findStringSwitchCase")
30-
SEMA_ATTR(FIND_STRING_SWITCH_CASE_WITH_CACHE, "findStringSwitchCaseWithCache")
22+
#ifndef SEMANTICS_ATTR
23+
#error SEMANTICS_ATTR not defined.
24+
#endif
3125

32-
SEMA_ATTR(SWIFT_CONCURRENT_ASYNC, "swift.concurrent.async")
33-
SEMA_ATTR(SWIFT_CONCURRENT_SAFE, "swift.concurrent.safe")
34-
SEMA_ATTR(SWIFT_CONCURRENT, "swift.concurrent")
26+
SEMANTICS_ATTR(STRING_EQUALS, "string.equals")
27+
SEMANTICS_ATTR(STRING_MAKE_UTF8, "string.makeUTF8")
28+
SEMANTICS_ATTR(STRING_ESCAPE_PERCENT_GET, "string.escapePercent.get")
29+
SEMANTICS_ATTR(STRING_CONCAT, "string.concat")
30+
SEMANTICS_ATTR(STRING_APPEND, "string.append")
31+
SEMANTICS_ATTR(STRING_INIT_EMPTY, "string.init_empty")
32+
SEMANTICS_ATTR(STRING_PLUS_EQUALS, "string.plusequals")
33+
SEMANTICS_ATTR(FIND_STRING_SWITCH_CASE, "findStringSwitchCase")
34+
SEMANTICS_ATTR(FIND_STRING_SWITCH_CASE_WITH_CACHE, "findStringSwitchCaseWithCache")
3535

36-
SEMA_ATTR(ARRAY_APPEND_CONTENTS_OF, "array.append_contentsOf")
37-
SEMA_ATTR(ARRAY_APPEND_ELEMENT, "array.append_element")
38-
SEMA_ATTR(ARRAY_CHECK_INDEX, "array.check_index")
39-
SEMA_ATTR(ARRAY_CHECK_SUBSCRIPT, "array.check_subscript")
40-
SEMA_ATTR(ARRAY_GET_CAPACITY, "array.get_capacity")
41-
SEMA_ATTR(ARRAY_GET_COUNT, "array.get_count")
42-
SEMA_ATTR(ARRAY_GET_ELEMENT, "array.get_element")
43-
SEMA_ATTR(ARRAY_GET_ELEMENT_ADDRESS, "array.get_element_address")
44-
SEMA_ATTR(ARRAY_INIT, "array.init")
45-
SEMA_ATTR(ARRAY_INIT_EMPTY, "array.init.empty")
46-
SEMA_ATTR(ARRAY_MAKE_MUTABLE, "array.make_mutable")
47-
SEMA_ATTR(ARRAY_MUTATE_UNKNOWN, "array.mutate_unknown")
48-
SEMA_ATTR(ARRAY_PROPS_IS_NATIVE_TYPE_CHECKED, "array.props.isNativeTypeChecked")
49-
SEMA_ATTR(ARRAY_RESERVE_CAPACITY_FOR_APPEND, "array.reserve_capacity_for_append")
50-
SEMA_ATTR(ARRAY_UNINITIALIZED, "array.uninitialized")
51-
SEMA_ATTR(ARRAY_WITH_UNSAFE_MUTABLE_BUFFER_POINTER, "array.withUnsafeMutableBufferPointer")
52-
SEMA_ATTR(ARRAY_COUNT, "array.count")
53-
SEMA_ATTR(ARRAY_DEALLOC_UNINITIALIZED, "array.dealloc_uninitialized")
54-
SEMA_ATTR(ARRAY_UNINITIALIZED_INTRINSIC, "array.uninitialized_intrinsic")
36+
SEMANTICS_ATTR(SWIFT_CONCURRENT_ASYNC, "swift.concurrent.async")
37+
SEMANTICS_ATTR(SWIFT_CONCURRENT_SAFE, "swift.concurrent.safe")
38+
SEMANTICS_ATTR(SWIFT_CONCURRENT, "swift.concurrent")
5539

56-
SEMA_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_NEVER, "optimize.sil.specialize.generic.never")
57-
SEMA_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_PARTIAL_NEVER,
40+
SEMANTICS_ATTR(ARRAY_APPEND_CONTENTS_OF, "array.append_contentsOf")
41+
SEMANTICS_ATTR(ARRAY_APPEND_ELEMENT, "array.append_element")
42+
SEMANTICS_ATTR(ARRAY_CHECK_INDEX, "array.check_index")
43+
SEMANTICS_ATTR(ARRAY_CHECK_SUBSCRIPT, "array.check_subscript")
44+
SEMANTICS_ATTR(ARRAY_GET_CAPACITY, "array.get_capacity")
45+
SEMANTICS_ATTR(ARRAY_GET_COUNT, "array.get_count")
46+
SEMANTICS_ATTR(ARRAY_GET_ELEMENT, "array.get_element")
47+
SEMANTICS_ATTR(ARRAY_GET_ELEMENT_ADDRESS, "array.get_element_address")
48+
SEMANTICS_ATTR(ARRAY_INIT, "array.init")
49+
SEMANTICS_ATTR(ARRAY_INIT_EMPTY, "array.init.empty")
50+
SEMANTICS_ATTR(ARRAY_MAKE_MUTABLE, "array.make_mutable")
51+
SEMANTICS_ATTR(ARRAY_MUTATE_UNKNOWN, "array.mutate_unknown")
52+
SEMANTICS_ATTR(ARRAY_PROPS_IS_NATIVE_TYPE_CHECKED, "array.props.isNativeTypeChecked")
53+
SEMANTICS_ATTR(ARRAY_RESERVE_CAPACITY_FOR_APPEND, "array.reserve_capacity_for_append")
54+
SEMANTICS_ATTR(ARRAY_UNINITIALIZED, "array.uninitialized")
55+
SEMANTICS_ATTR(ARRAY_WITH_UNSAFE_MUTABLE_BUFFER_POINTER, "array.withUnsafeMutableBufferPointer")
56+
SEMANTICS_ATTR(ARRAY_COUNT, "array.count")
57+
SEMANTICS_ATTR(ARRAY_DEALLOC_UNINITIALIZED, "array.dealloc_uninitialized")
58+
SEMANTICS_ATTR(ARRAY_UNINITIALIZED_INTRINSIC, "array.uninitialized_intrinsic")
59+
60+
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_NEVER, "optimize.sil.specialize.generic.never")
61+
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_PARTIAL_NEVER,
5862
"optimize.sil.specialize.generic.partial.never")
59-
SEMA_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER, "optimize.sil.specialize.generic.size.never")
63+
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER, "optimize.sil.specialize.generic.size.never")
6064

61-
SEMA_ATTR(OSLOG_INTERPOLATION_INIT, "oslog.interpolation.init")
62-
SEMA_ATTR(OSLOG_MESSAGE_INIT_INTERPOLATION, "oslog.message.init_interpolation")
63-
SEMA_ATTR(OSLOG_MESSAGE_INIT_STRING_LITERAL, "oslog.message.init_stringliteral")
65+
SEMANTICS_ATTR(OSLOG_INTERPOLATION_INIT, "oslog.interpolation.init")
66+
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_INTERPOLATION, "oslog.message.init_interpolation")
67+
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_STRING_LITERAL, "oslog.message.init_stringliteral")
6468

65-
SEMA_ATTR(TYPE_CHECKER_OPEN_EXISTENTIAL, "typechecker._openExistential(_:do:)")
66-
SEMA_ATTR(TYPE_CHECKER_TYPE, "typechecker.type(of:)")
67-
SEMA_ATTR(TYPE_CHECKER_WITHOUT_ACTUALLY_ESCAPING, "typechecker.withoutActuallyEscaping(_:do:)")
69+
SEMANTICS_ATTR(TYPE_CHECKER_OPEN_EXISTENTIAL, "typechecker._openExistential(_:do:)")
70+
SEMANTICS_ATTR(TYPE_CHECKER_TYPE, "typechecker.type(of:)")
71+
SEMANTICS_ATTR(TYPE_CHECKER_WITHOUT_ACTUALLY_ESCAPING, "typechecker.withoutActuallyEscaping(_:do:)")
6872

69-
SEMA_ATTR(AVAILABILITY_OSVERSION, "availability.osversion")
73+
SEMANTICS_ATTR(AVAILABILITY_OSVERSION, "availability.osversion")
7074

71-
SEMA_ATTR(CONSTANT_EVALUABLE, "constant_evaluable")
72-
SEMA_ATTR(EXIT, "exit")
73-
SEMA_ATTR(FASTPATH, "fastpath")
74-
SEMA_ATTR(SLOWPATH, "slowpath")
75-
SEMA_ATTR(PROGRAMTERMINATION_POINT, "programtermination_point")
76-
SEMA_ATTR(CONVERT_TO_OBJECTIVE_C, "convertToObjectiveC")
75+
SEMANTICS_ATTR(CONSTANT_EVALUABLE, "constant_evaluable")
76+
SEMANTICS_ATTR(EXIT, "exit")
77+
SEMANTICS_ATTR(FASTPATH, "fastpath")
78+
SEMANTICS_ATTR(SLOWPATH, "slowpath")
79+
SEMANTICS_ATTR(PROGRAMTERMINATION_POINT, "programtermination_point")
80+
SEMANTICS_ATTR(CONVERT_TO_OBJECTIVE_C, "convertToObjectiveC")
7781

78-
#undef SEMA_ATTR
82+
#undef SEMANTICS_ATTR
7983

include/swift/AST/SemanticAttrs.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
//
13-
// Implementation of the matching definition file.
14-
// This file holds all semantics attributes as constant string literals.
15-
//
12+
///
13+
/// \file
14+
/// Implementation of the matching definition file.
15+
/// This file holds all semantics attributes as constant string literals.
16+
///
1617
//===----------------------------------------------------------------------===//
1718

1819
#ifndef SWIFT_SEMANTICS_H
@@ -21,8 +22,10 @@
2122
#include "llvm/ADT/StringRef.h"
2223

2324
namespace swift {
24-
#define SEMA_ATTR(NAME, C_STR) constexpr static const StringLiteral NAME = #C_STR;
25+
namespace semantics {
26+
#define SEMANTICS_ATTR(NAME, C_STR) constexpr static const StringLiteral NAME = #C_STR;
2527
#include "SemanticAttrs.def"
2628
}
29+
}
2730

2831
#endif

lib/IRGen/AllocStackHoisting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ bool indicatesDynamicAvailabilityCheckUse(SILInstruction *I) {
350350
auto *Apply = dyn_cast<ApplyInst>(I);
351351
if (!Apply)
352352
return false;
353-
if (Apply->hasSemantics(AVAILABILITY_OSVERSION))
353+
if (Apply->hasSemantics(semantics::AVAILABILITY_OSVERSION))
354354
return true;
355355
auto *FunRef = Apply->getReferencedFunctionOrNull();
356356
if (!FunRef)

lib/SILOptimizer/Analysis/ColdBlockInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ ColdBlockInfo::BranchHint ColdBlockInfo::getBranchHint(SILValue Cond,
8484
if (F->hasSemanticsAttrs()) {
8585
// fastpath/slowpath attrs are untested because the inliner luckily
8686
// inlines them before the downstream calls.
87-
if (F->hasSemanticsAttr(SLOWPATH))
87+
if (F->hasSemanticsAttr(semantics::SLOWPATH))
8888
return BranchHint::LikelyFalse;
89-
else if (F->hasSemanticsAttr(FASTPATH))
89+
else if (F->hasSemanticsAttr(semantics::FASTPATH))
9090
return BranchHint::LikelyTrue;
9191
}
9292
}

lib/SILOptimizer/Mandatory/OSLogOptimization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static SILFunction *getStringMakeUTF8Init(SILInstruction *inst) {
120120
return nullptr;
121121

122122
SILFunction *callee = apply->getCalleeFunction();
123-
if (!callee || !callee->hasSemanticsAttr(STRING_MAKE_UTF8))
123+
if (!callee || !callee->hasSemanticsAttr(semantics::STRING_MAKE_UTF8))
124124
return nullptr;
125125
return callee;
126126
}

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ SILInstruction *SILCombiner::visitApplyInst(ApplyInst *AI) {
16491649
return I;
16501650
}
16511651
}
1652-
if (SF->hasSemanticsAttr(ARRAY_UNINITIALIZED)) {
1652+
if (SF->hasSemanticsAttr(semantics::ARRAY_UNINITIALIZED)) {
16531653
UserListTy Users;
16541654
// If the uninitialized array is only written into then it can be removed.
16551655
if (recursivelyCollectARCUsers(Users, AI)) {

lib/SILOptimizer/Transforms/ObjectOutliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ bool ObjectOutliner::isValidUseOfObject(SILInstruction *I, bool isCOWObject,
149149
// There should only be a single call to findStringSwitchCase. But even
150150
// if there are multiple calls, it's not problem - we'll just optimize the
151151
// last one we find.
152-
if (cast<ApplyInst>(I)->hasSemantics(FIND_STRING_SWITCH_CASE))
152+
if (cast<ApplyInst>(I)->hasSemantics(semantics::FIND_STRING_SWITCH_CASE))
153153
*FindStringCall = cast<ApplyInst>(I);
154154
return true;
155155

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ bool SILPerformanceInliner::decideInColdBlock(FullApplySite AI,
645645
static void addWeightCorrection(FullApplySite FAS,
646646
llvm::DenseMap<FullApplySite, int> &WeightCorrections) {
647647
SILFunction *Callee = FAS.getReferencedFunctionOrNull();
648-
if (Callee && Callee->hasSemanticsAttr(ARRAY_UNINITIALIZED)) {
648+
if (Callee && Callee->hasSemanticsAttr(semantics::ARRAY_UNINITIALIZED)) {
649649
// We want to inline the argument to an array.uninitialized call, because
650650
// this argument is most likely a call to a function which contains the
651651
// buffer allocation for the array. It is essential to inline it for stack

lib/SILOptimizer/Utils/ConstExpr.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,24 @@ enum class WellKnownFunction {
6363
};
6464

6565
static llvm::Optional<WellKnownFunction> classifyFunction(SILFunction *fn) {
66-
if (fn->hasSemanticsAttr(ARRAY_INIT_EMPTY))
66+
if (fn->hasSemanticsAttr(semantics::ARRAY_INIT_EMPTY))
6767
return WellKnownFunction::ArrayInitEmpty;
68-
if (fn->hasSemanticsAttr(ARRAY_UNINITIALIZED_INTRINSIC))
68+
if (fn->hasSemanticsAttr(semantics::ARRAY_UNINITIALIZED_INTRINSIC))
6969
return WellKnownFunction::AllocateUninitializedArray;
70-
if (fn->hasSemanticsAttr(ARRAY_APPEND_ELEMENT))
70+
if (fn->hasSemanticsAttr(semantics::ARRAY_APPEND_ELEMENT))
7171
return WellKnownFunction::ArrayAppendElement;
72-
if (fn->hasSemanticsAttr(STRING_INIT_EMPTY))
72+
if (fn->hasSemanticsAttr(semantics::STRING_INIT_EMPTY))
7373
return WellKnownFunction::StringInitEmpty;
7474
// There are two string initializers in the standard library with the
7575
// semantics "string.makeUTF8". They are identical from the perspective of
7676
// the interpreter. One of those functions is probably redundant and not used.
77-
if (fn->hasSemanticsAttr(STRING_MAKE_UTF8))
77+
if (fn->hasSemanticsAttr(semantics::STRING_MAKE_UTF8))
7878
return WellKnownFunction::StringMakeUTF8;
79-
if (fn->hasSemanticsAttr(STRING_APPEND))
79+
if (fn->hasSemanticsAttr(semantics::STRING_APPEND))
8080
return WellKnownFunction::StringAppend;
81-
if (fn->hasSemanticsAttr(STRING_EQUALS))
81+
if (fn->hasSemanticsAttr(semantics::STRING_EQUALS))
8282
return WellKnownFunction::StringEquals;
83-
if (fn->hasSemanticsAttr(STRING_ESCAPE_PERCENT_GET))
83+
if (fn->hasSemanticsAttr(semantics::STRING_ESCAPE_PERCENT_GET))
8484
return WellKnownFunction::StringEscapePercent;
8585
if (fn->hasSemanticsAttrThatStartsWith("programtermination_point"))
8686
return WellKnownFunction::AssertionFailure;

lib/SILOptimizer/Utils/ConstantFolding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ static bool isApplyOfBuiltin(SILInstruction &I, BuiltinValueKind kind) {
14671467
static bool isApplyOfStringConcat(SILInstruction &I) {
14681468
if (auto *AI = dyn_cast<ApplyInst>(&I))
14691469
if (auto *Fn = AI->getReferencedFunctionOrNull())
1470-
if (Fn->hasSemanticsAttr(STRING_CONCAT))
1470+
if (Fn->hasSemanticsAttr(semantics::STRING_CONCAT))
14711471
return true;
14721472
return false;
14731473
}
@@ -1536,7 +1536,7 @@ constantFoldGlobalStringTablePointerBuiltin(BuiltinInst *bi,
15361536
FullApplySite stringInitSite = FullApplySite::isa(builtinOperand);
15371537
if (!stringInitSite || !stringInitSite.getReferencedFunctionOrNull() ||
15381538
!stringInitSite.getReferencedFunctionOrNull()->hasSemanticsAttr(
1539-
STRING_MAKE_UTF8)) {
1539+
semantics::STRING_MAKE_UTF8)) {
15401540
// Emit diagnostics only on non-transparent functions.
15411541
if (enableDiagnostics && !caller->isTransparent()) {
15421542
diagnose(caller->getASTContext(), bi->getLoc().getSourceLoc(),

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,18 +373,18 @@ static bool createsInfiniteSpecializationLoop(ApplySite Apply) {
373373

374374
static bool shouldNotSpecialize(SILFunction *Callee, SILFunction *Caller,
375375
SubstitutionMap Subs = {}) {
376-
if (Callee->hasSemanticsAttr(OPTIMIZE_SIL_SPECIALIZE_GENERIC_NEVER))
376+
if (Callee->hasSemanticsAttr(semantics::OPTIMIZE_SIL_SPECIALIZE_GENERIC_NEVER))
377377
return true;
378378

379379
if (Caller &&
380380
Caller->getEffectiveOptimizationMode() == OptimizationMode::ForSize &&
381-
Callee->hasSemanticsAttr(OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER)) {
381+
Callee->hasSemanticsAttr(semantics::OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER)) {
382382
return true;
383383
}
384384

385385

386386
if (Subs.hasAnySubstitutableParams() &&
387-
Callee->hasSemanticsAttr(OPTIMIZE_SIL_SPECIALIZE_GENERIC_PARTIAL_NEVER))
387+
Callee->hasSemanticsAttr(semantics::OPTIMIZE_SIL_SPECIALIZE_GENERIC_PARTIAL_NEVER))
388388
return true;
389389

390390
return false;

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ bool StringConcatenationOptimizer::extractStringConcatOperands() {
726726
if (!Fn)
727727
return false;
728728

729-
if (ai->getNumArguments() != 3 || !Fn->hasSemanticsAttr(STRING_CONCAT))
729+
if (ai->getNumArguments() != 3 || !Fn->hasSemanticsAttr(semantics::STRING_CONCAT))
730730
return false;
731731

732732
// Left and right operands of a string concatenation operation.
@@ -757,9 +757,9 @@ bool StringConcatenationOptimizer::extractStringConcatOperands() {
757757

758758
// makeUTF8 should have following parameters:
759759
// (start: RawPointer, utf8CodeUnitCount: Word, isASCII: Int1)
760-
if (!((friLeftFun->hasSemanticsAttr(STRING_MAKE_UTF8)
760+
if (!((friLeftFun->hasSemanticsAttr(semantics::STRING_MAKE_UTF8)
761761
&& aiLeftOperandsNum == 5)
762-
|| (friRightFun->hasSemanticsAttr(STRING_MAKE_UTF8)
762+
|| (friRightFun->hasSemanticsAttr(semantics::STRING_MAKE_UTF8)
763763
&& aiRightOperandsNum == 5)))
764764
return false;
765765

0 commit comments

Comments
 (0)