Skip to content

Commit 863f3a1

Browse files
committed
Rename @effects to @_effects
@effects is too low a level, and not meant for general usage outside the standard library. Therefore it deserves to be underscored like other such attributes.
1 parent 1ffc687 commit 863f3a1

29 files changed

+95
-95
lines changed

Diff for: docs/HighLevelSILOptimizations.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,19 @@ Dictionary
313313
~~~~~~~~~~
314314
TBD.
315315

316-
@effects attribute
316+
@_effects attribute
317317
~~~~~~~~~~~~~~~~~~~~~~~~~~~
318318

319-
The @effects attribute describes how a function affects "the state of the world".
319+
The @_effects attribute describes how a function affects "the state of the world".
320320
More practically how the optimizer can modify the program based on information
321321
that is provided by the attribute.
322322

323323
Usage:
324324

325-
@effects(readonly) func foo() { .. }
325+
@_effects(readonly) func foo() { .. }
326326

327327

328-
The @effects attribute supports the following tags:
328+
The @_effects attribute supports the following tags:
329329

330330
readnone
331331

@@ -363,13 +363,13 @@ releasenone
363363
}
364364
}
365365

366-
@effects(releasenone)
366+
@_effects(releasenone)
367367
func validReleaseNoneFunction(x: Int) -> Int {
368368
global.x = 5
369369
return x + 2
370370
}
371371

372-
@effects(releasenone)
372+
@_effects(releasenone)
373373
func validReleaseNoneFunction(x: Int) -> Int {
374374
var notExternallyVisibleObject = SomeObject()
375375
return x + notExternallyVisibleObject.x

Diff for: docs/proposals/OptimizerEffects.rst

+11-11
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ don't have a more general term for "release", which refers to any
9696
release_value operation.
9797

9898
When referring to unspecified state, I will use the syntax
99-
``@effects(no<effectname>)``. When referring to state reachable via an
99+
``@_effects(no<effectname>)``. When referring to state reachable via an
100100
argument, ``@no<effectname> arg``.
101101

102102
Naturally, we also need a syntax for associating effects with
@@ -110,7 +110,7 @@ effects at a call site. For now, we assume the predicate only applies
110110
to unspecified state and that the bridged object is always self. That
111111
way we can denote predicated effects as @nonbridged_effects.
112112

113-
In examples, @effects(argonly) means that there are no effects on
113+
In examples, @_effects(argonly) means that there are no effects on
114114
unspecified state.
115115

116116
CoW Optimization Requirements
@@ -167,7 +167,7 @@ state.
167167

168168
Note: In terms of low-level SIL attributes such a method will be marked:::
169169

170-
@effects(argonly)
170+
@_effects(argonly)
171171
@selfeffects(make_unique)
172172
func makeUnique() {}
173173

@@ -230,7 +230,7 @@ state.
230230

231231
Note: In terms of low-level SIL attributes such a method will be marked:::
232232

233-
@effects(argonly)
233+
@_effects(argonly)
234234
@selfeffects(preserve_unique, nowrite, nocapture, norelease,
235235
projects_subobject)
236236
func getElement(_ index: Int) -> T {}
@@ -297,7 +297,7 @@ state.
297297

298298
Note: In terms of low-level SIL attributes such a method will be marked:::
299299

300-
@effects(argonly)
300+
@_effects(argonly)
301301
@selfeffects(preserve_unique, nowrite, nocapture, norelease,
302302
projects_subobject_addr)
303303
func getElementAddr(_ index: Int) -> T {}
@@ -320,7 +320,7 @@ state.
320320

321321
Note: In terms of low-level SIL attributes such a method will be marked:::
322322

323-
@effects(argonly)
323+
@_effects(argonly)
324324
@selfeffects(preserve_unique, nocapture, norelease)
325325
func appendElementAssumingUnique(@norelease @nowrite elt: T) {}
326326

@@ -356,7 +356,7 @@ state.
356356

357357
Note: In terms of low-level SIL attributes such a method will be marked:::
358358

359-
@effects(argonly, T.release)
359+
@_effects(argonly, T.release)
360360
@selfeffects(preserve_unique, nocapture)
361361
func setElement(@nowrite e: T, index: Int) {
362362
}
@@ -536,15 +536,15 @@ Mostly TBD.
536536

537537
The optimizer can only take advantage of user-specified effects before
538538
they have been inlined. Consequently, the optimizer initially preserves
539-
calls to annotated @effects() functions. After optimizing for effects
539+
calls to annotated @_effects() functions. After optimizing for effects
540540
these functions can be inlined, dropping the effects information.
541541

542542
Without special syntax, specifying a pure function would require::
543543

544-
@effects(argonly)
544+
@_effects(argonly)
545545
func foo(@noread @nowrite arg)
546546

547-
A shorthand, such as @effects(none) could easily be
547+
A shorthand, such as @_effects(none) could easily be
548548
introduced. Typically, this shouldn't be needed because the purity of
549549
a function can probably be deduced from its argument types given that
550550
it has no effect on unspecified state. i.e. If the function does not
@@ -576,7 +576,7 @@ example. But there are two situations to be concerned about:
576576
Solving this requires a system for polymorphic effects. Language
577577
support for polymorphic effects might look something like this::
578578

579-
@effects(T.release)
579+
@_effects(T.release)
580580
func foo<T>(t: T) { ... }
581581

582582
This would mean that foo's unspecified effects are bounded by the

Diff for: include/swift/AST/Attr.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ CONTEXTUAL_DECL_ATTR(weak, ReferenceOwnership,
269269
DeclModifier |
270270
NotSerialized, 49)
271271
CONTEXTUAL_DECL_ATTR_ALIAS(unowned, ReferenceOwnership)
272-
DECL_ATTR(effects, Effects,
272+
DECL_ATTR(_effects, Effects,
273273
OnAbstractFunction |
274274
UserInaccessible,
275275
50)

Diff for: include/swift/AST/AttrKind.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ enum class InlineKind : uint8_t {
7272
enum : unsigned { NumInlineKindBits =
7373
countBitsUsed(static_cast<unsigned>(InlineKind::Last_InlineKind)) };
7474

75-
/// This enum represents the possible values of the @effects attribute.
75+
/// This enum represents the possible values of the @_effects attribute.
7676
/// These values are ordered from the strongest guarantee to the weakest,
7777
/// so please do not reorder existing values.
7878
enum class EffectsKind : uint8_t {

Diff for: include/swift/SIL/SILFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ class SILFunction
587587
/// \return the function side effects information.
588588
EffectsKind getEffectsKind() const { return EffectsKindAttr; }
589589

590-
/// \return True if the function is annotated with the @effects attribute.
590+
/// \return True if the function is annotated with the @_effects attribute.
591591
bool hasEffectsKind() const {
592592
return EffectsKindAttr != EffectsKind::Unspecified;
593593
}

Diff for: include/swift/SILOptimizer/Analysis/SideEffectAnalysis.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ class FunctionSideEffects {
406406
}
407407

408408
protected:
409-
/// Set the side-effects of a function, which has an @effects attribute.
410-
/// Returns true if \a F has an @effects attribute which could be handled.
409+
/// Set the side-effects of a function, which has an @_effects attribute.
410+
/// Returns true if \a F has an @_effects attribute which could be handled.
411411
bool setDefinedEffects(SILFunction *F);
412412

413413
/// Set the side-effects of a semantic call.

Diff for: lib/IRGen/GenDecl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
22222222
}
22232223

22242224
/// Return True if the function \p f is a 'readonly' function. Checking
2225-
/// for the SIL @effects(readonly) attribute is not enough because this
2225+
/// for the SIL @_effects(readonly) attribute is not enough because this
22262226
/// definition does not match the definition of the LLVM readonly function
22272227
/// attribute. In this function we do the actual check.
22282228
static bool isReadOnlyFunction(SILFunction *f) {
@@ -2235,11 +2235,11 @@ static bool isReadOnlyFunction(SILFunction *f) {
22352235
auto Eff = f->getEffectsKind();
22362236

22372237
// Swift's readonly does not automatically match LLVM's readonly.
2238-
// Swift SIL optimizer relies on @effects(readonly) to remove e.g.
2238+
// Swift SIL optimizer relies on @_effects(readonly) to remove e.g.
22392239
// dead code remaining from initializers of strings or dictionaries
22402240
// of variables that are not used. But those initializers are often
22412241
// not really readonly in terms of LLVM IR. For example, the
2242-
// Dictionary.init() is marked as @effects(readonly) in Swift, but
2242+
// Dictionary.init() is marked as @_effects(readonly) in Swift, but
22432243
// it does invoke reference-counting operations.
22442244
if (Eff == EffectsKind::ReadOnly || Eff == EffectsKind::ReadNone) {
22452245
// TODO: Analyze the body of function f and return true if it is

Diff for: lib/SILOptimizer/Analysis/SideEffectAnalysis.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bool FunctionSideEffects::setDefinedEffects(SILFunction *F) {
334334
case EffectsKind::ReadNone:
335335
return true;
336336
case EffectsKind::ReadOnly:
337-
// @effects(readonly) is worthless if we have owned parameters, because
337+
// @_effects(readonly) is worthless if we have owned parameters, because
338338
// the release inside the callee may call a deinit, which itself can do
339339
// anything.
340340
if (!F->hasOwnedParameters()) {
@@ -356,7 +356,7 @@ bool FunctionSideEffects::summarizeFunction(SILFunction *F) {
356356
if (!F->empty())
357357
ParamEffects.resize(F->getArguments().size());
358358

359-
// Handle @effects attributes
359+
// Handle @_effects attributes
360360
if (setDefinedEffects(F)) {
361361
DEBUG(llvm::dbgs() << " -- has defined effects " << F->getName() << '\n');
362362
return true;
@@ -463,7 +463,7 @@ bool FunctionSideEffects::summarizeCall(FullApplySite fullApply) {
463463
}
464464

465465
if (SILFunction *SingleCallee = fullApply.getReferencedFunction()) {
466-
// Does the function have any @effects?
466+
// Does the function have any @_effects?
467467
if (setDefinedEffects(SingleCallee))
468468
return true;
469469
}

Diff for: lib/SILOptimizer/Transforms/PerformanceInliner.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ class SILPerformanceInlinerPass : public SILFunctionTransform {
924924
} // end anonymous namespace
925925

926926
/// Create an inliner pass that does not inline functions that are marked with
927-
/// the @_semantics, @effects or global_init attributes.
927+
/// the @_semantics, @_effects or global_init attributes.
928928
SILTransform *swift::createEarlyInliner() {
929929
return new SILPerformanceInlinerPass(
930930
InlineSelection::NoSemanticsAndGlobalInit, "Early");
@@ -937,7 +937,7 @@ SILTransform *swift::createPerfInliner() {
937937
}
938938

939939
/// Create an inliner pass that inlines all functions that are marked with
940-
/// the @_semantics, @effects or global_init attributes.
940+
/// the @_semantics, @_effects or global_init attributes.
941941
SILTransform *swift::createLateInliner() {
942942
return new SILPerformanceInlinerPass(InlineSelection::Everything, "Late");
943943
}

Diff for: lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI,
669669
auto ModuleName = Callee->getModule().getSwiftModule()->getName().str();
670670
bool IsInStdlib = (ModuleName == STDLIB_NAME || ModuleName == SWIFT_ONONE_SUPPORT);
671671

672-
// Don't inline functions that are marked with the @_semantics or @effects
672+
// Don't inline functions that are marked with the @_semantics or @_effects
673673
// attribute if the inliner is asked not to inline them.
674674
if (Callee->hasSemanticsAttrs() || Callee->hasEffectsKind()) {
675675
if (WhatToInline == InlineSelection::NoSemanticsAndGlobalInit) {

Diff for: stdlib/public/core/Character.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ extension Character
130130
}
131131

132132
@inlinable // FIXME(sil-serialize-all)
133-
@effects(readonly)
133+
@_effects(readonly)
134134
public init(_builtinUnicodeScalarLiteral value: Builtin.Int32) {
135135
self.init(Unicode.Scalar(_builtinUnicodeScalarLiteral: value))
136136
}
@@ -139,7 +139,7 @@ extension Character
139139
// integer constant in case of small character literals.
140140
@inlinable // FIXME(sil-serialize-all)
141141
@inline(__always)
142-
@effects(readonly)
142+
@_effects(readonly)
143143
public init(
144144
_builtinExtendedGraphemeClusterLiteral start: Builtin.RawPointer,
145145
utf8CodeUnitCount: Builtin.Word,
@@ -194,7 +194,7 @@ extension Character
194194
// integer constant in case of small character literals.
195195
@inlinable // FIXME(sil-serialize-all)
196196
@inline(__always)
197-
@effects(readonly)
197+
@_effects(readonly)
198198
public init(
199199
_builtinExtendedGraphemeClusterLiteral start: Builtin.RawPointer,
200200
utf16CodeUnitCount: Builtin.Word
@@ -483,7 +483,7 @@ extension Character: Hashable {
483483
///
484484
/// - Parameter hasher: The hasher to use when combining the components
485485
/// of this instance.
486-
@effects(releasenone)
486+
@_effects(releasenone)
487487
public func hash(into hasher: inout Hasher) {
488488
// FIXME(performance): constructing a temporary string is extremely
489489
// wasteful and inefficient.

Diff for: stdlib/public/core/Dictionary.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ extension Dictionary: ExpressibleByDictionaryLiteral {
798798
/// - Parameter elements: The key-value pairs that will make up the new
799799
/// dictionary. Each key in `elements` must be unique.
800800
@inlinable // FIXME(sil-serialize-all)
801-
@effects(readonly)
801+
@_effects(readonly)
802802
public init(dictionaryLiteral elements: (Key, Value)...) {
803803
self.init(_nativeBuffer: _NativeDictionaryBuffer.fromArray(elements))
804804
}

0 commit comments

Comments
 (0)