Skip to content

Commit eb23d3b

Browse files
authored
Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2 parents bafd04d + ca737d3 commit eb23d3b

File tree

62 files changed

+816
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+816
-401
lines changed

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,12 +1117,6 @@ if it is never explicitly bound using a typed pointer method like
11171117
bound, it must only be used with compatible typed memory accesses for as long
11181118
as the binding is active.
11191119

1120-
## `@_section("section_name")`
1121-
1122-
Places a global variable or a top-level function into a section of the object
1123-
file with the given name. It's the equivalent of clang's
1124-
`__attribute__((section))`.
1125-
11261120
## `@_semantics("uniquely.recognized.id")`
11271121

11281122
Allows the optimizer to make use of some key invariants in performance critical
@@ -1320,12 +1314,6 @@ for more details.
13201314

13211315
This `async` function uses the pre-SE-0338 semantics of unsafely inheriting the caller's executor. This is an underscored feature because the right way of inheriting an executor is to pass in the required executor and switch to it. Unfortunately, there are functions in the standard library which need to inherit their caller's executor but cannot change their ABI because they were not defined as `@_alwaysEmitIntoClient` in the initial release.
13221316

1323-
## `@_used`
1324-
1325-
Marks a global variable or a top-level function as "used externally" even if it
1326-
does not have visible users in the compilation unit. It's the equivalent of
1327-
clang's `__attribute__((used))`.
1328-
13291317
## `@_weakLinked`
13301318

13311319
Allows a declaration to be weakly-referenced, i.e., any references emitted by

include/swift/AST/Attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ class SILGenNameAttr : public DeclAttribute {
714714
}
715715
};
716716

717-
/// Defines the @_section attribute.
717+
/// Defines the @section attribute.
718718
class SectionAttr : public DeclAttribute {
719719
public:
720720
SectionAttr(StringRef Name, SourceLoc AtLoc, SourceRange Range, bool Implicit)

include/swift/AST/DeclAttr.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,12 +753,12 @@ DECL_ATTR(attached, MacroRole,
753753
142)
754754
DECL_ATTR_ALIAS(freestanding, MacroRole)
755755

756-
SIMPLE_DECL_ATTR(_used, Used,
756+
SIMPLE_DECL_ATTR(used, Used,
757757
OnAbstractFunction | OnVar,
758758
UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove | ForbiddenInABIAttr,
759759
143)
760760

761-
DECL_ATTR(_section, Section,
761+
DECL_ATTR(section, Section,
762762
OnAbstractFunction | OnVar,
763763
UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove | ForbiddenInABIAttr,
764764
144)

include/swift/AST/DiagnosticsSema.def

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -826,29 +826,29 @@ ERROR(expect_compile_time_literal,none,
826826
"expect a compile-time constant literal", ())
827827

828828
ERROR(const_unsupported_enum_associated_value,none,
829-
"enums with associated values not supported in a '@const' expression", ())
829+
"enums with associated values not supported in a constant expression", ())
830830
ERROR(const_unsupported_operator,none,
831-
"unsupported operator in a '@const' expression", ())
831+
"unsupported operator in a constant expression", ())
832832
ERROR(const_unsupported_type,none,
833-
"unsupported type in a '@const' expression", ())
833+
"unsupported type in a constant expression", ())
834834
ERROR(const_unsupported_type_expr,none,
835-
"type expressions not supported in a '@const' expression", ())
835+
"type expressions not supported in a constant expression", ())
836836
ERROR(const_unsupported_closure,none,
837-
"closures not supported in a '@const' expression", ())
837+
"closures not supported in a constant expression", ())
838838
ERROR(const_unsupported_keypath,none,
839-
"keypaths not supported in a '@const' expression", ())
839+
"keypaths not supported in a constant expression", ())
840840
ERROR(const_opaque_decl_ref,none,
841-
"unable to resolve variable reference in a '@const' expression", ())
841+
"unable to resolve variable reference in a constant expression", ())
842842
ERROR(const_opaque_func_decl_ref,none,
843-
"unable to resolve function reference in a '@const' expression", ())
843+
"unable to resolve function reference in a constant expression", ())
844844
ERROR(const_non_convention_c_conversion,none,
845-
"only 'convention(c)' function values are supported in a '@const' expression", ())
845+
"only 'convention(c)' function values are supported in a constant expression", ())
846846
ERROR(const_opaque_callee,none,
847-
"unable to resolve callee in a '@const' expression", ())
847+
"unable to resolve callee in a constant expression", ())
848848
ERROR(const_non_const_param,none,
849-
"reference to a non-'@const' parameter in a '@const' expression", ())
849+
"reference to a non-'@const' parameter in a constant expression", ())
850850
ERROR(const_unknown_default,none,
851-
"not supported in a '@const' expression", ())
851+
"not supported in a constant expression", ())
852852

853853
//------------------------------------------------------------------------------
854854
// MARK: Import Resolution
@@ -2097,11 +2097,9 @@ ERROR(cdecl_feature_required,none,
20972097
"'@c' requires '-enable-experimental-feature CDecl'",
20982098
())
20992099

2100-
// @_used and @_section
2101-
ERROR(section_linkage_markers_disabled,none,
2102-
"attribute requires '-enable-experimental-feature SymbolLinkageMarkers'", ())
2100+
// @used and @section
21032101
ERROR(section_empty_name,none,
2104-
"'@_section' section name cannot be empty", ())
2102+
"'@section' section name cannot be empty", ())
21052103

21062104
// @_silgen_name and friends
21072105
WARNING(reserved_runtime_symbol_name,none,

include/swift/Basic/Features.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,6 @@ EXPERIMENTAL_FEATURE(FullTypedThrows, false)
323323
EXPERIMENTAL_FEATURE(SameElementRequirements, false)
324324
EXPERIMENTAL_FEATURE(KeyPathWithMethodMembers, false)
325325

326-
// Whether to enable @_used and @_section attributes
327-
EXPERIMENTAL_FEATURE(SymbolLinkageMarkers, true)
328-
329326
// Whether to emit an Embedded Swift module with "deferred" code generation,
330327
// meaning that the only code that will be emitted into the object file is
331328
// code that was marked as "never emit into client". For everything else,

include/swift/IRGen/Linking.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ class LinkEntity {
18501850
///
18511851
/// This applies only in the Embedded Swift linkage model, and is used for
18521852
/// any symbols that have not been explicitly requested to have unique
1853-
/// definitions (e.g., with @_used).
1853+
/// definitions (e.g., with @used).
18541854
bool hasNonUniqueDefinition() const;
18551855

18561856
#undef LINKENTITY_GET_FIELD

include/swift/SIL/SILFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class SILFunction
325325
/// If empty, use the SIL function's name directly.
326326
StringRef AsmName;
327327

328-
/// Name of a section if @_section attribute was used, otherwise empty.
328+
/// Name of a section if @section attribute was used, otherwise empty.
329329
StringRef Section;
330330

331331
/// Name of a Wasm export if @_expose(wasm) attribute was used, otherwise
@@ -396,7 +396,7 @@ class SILFunction
396396
/// would indicate.
397397
unsigned HasCReferences : 1;
398398

399-
/// Whether attribute @_used was present
399+
/// Whether attribute @used was present
400400
unsigned MarkedAsUsed : 1;
401401

402402
/// Whether cross-module references to this function should always use weak
@@ -1424,15 +1424,15 @@ class SILFunction
14241424
return V && V->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>();
14251425
}
14261426

1427-
/// Return whether this function has attribute @_used on it
1427+
/// Return whether this function has attribute @used on it
14281428
bool markedAsUsed() const { return MarkedAsUsed; }
14291429
void setMarkedAsUsed(bool value) { MarkedAsUsed = value; }
14301430

14311431
/// Return custom assembler name, otherwise empty.
14321432
StringRef asmName() const { return AsmName; }
14331433
void setAsmName(StringRef value) { AsmName = value; }
14341434

1435-
/// Return custom section name if @_section was used, otherwise empty
1435+
/// Return custom section name if @section was used, otherwise empty
14361436
StringRef section() const { return Section; }
14371437
void setSection(StringRef value) { Section = value; }
14381438

include/swift/SIL/SILGlobalVariable.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class SILGlobalVariable
6464
/// the mangled name of the variable will be used instead.
6565
StringRef AsmName;
6666

67-
/// Name of a section if @_section attribute was used, otherwise empty.
67+
/// Name of a section if @section attribute was used, otherwise empty.
6868
StringRef Section;
6969

7070
/// The lowered type of the variable.
@@ -86,7 +86,7 @@ class SILGlobalVariable
8686
/// once (either in its declaration, or once later), making it immutable.
8787
unsigned IsLet : 1;
8888

89-
/// Whether this declaration was marked `@_used`, meaning that it should be
89+
/// Whether this declaration was marked `@used`, meaning that it should be
9090
/// added to the llvm.used list.
9191
unsigned IsUsed : 1;
9292

@@ -162,7 +162,7 @@ class SILGlobalVariable
162162
StringRef asmName() const { return AsmName; }
163163
void setAsmName(StringRef value) { AsmName = value; }
164164

165-
/// Return custom section name if @_section was used, otherwise empty
165+
/// Return custom section name if @section was used, otherwise empty
166166
StringRef section() const { return Section; }
167167
void setSection(StringRef value) { Section = value; }
168168

@@ -242,7 +242,7 @@ class SILGlobalVariable
242242
StaticInitializerBlock.eraseAllInstructions(Module);
243243
}
244244

245-
/// Returns true if this global variable has `@_used` attribute.
245+
/// Returns true if this global variable has `@used` attribute.
246246
bool markedAsUsed() const { return IsUsed; }
247247

248248
void setMarkedAsUsed(bool used) { IsUsed = used; }

lib/AST/Attr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
13231323
}
13241324

13251325
case DeclAttrKind::Section:
1326-
Printer.printAttrName("@_section");
1326+
Printer.printAttrName("@section");
13271327
Printer << "(\"" << cast<SectionAttr>(this)->Name << "\")";
13281328
break;
13291329

@@ -1977,7 +1977,7 @@ StringRef DeclAttribute::getAttrName() const {
19771977
case DeclAttrKind::Expose:
19781978
return "_expose";
19791979
case DeclAttrKind::Section:
1980-
return "_section";
1980+
return "section";
19811981
case DeclAttrKind::Documentation:
19821982
return "_documentation";
19831983
case DeclAttrKind::Nonisolated:

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ bool AbstractStorageDecl::isCompileTimeLiteral() const {
13421342
}
13431343

13441344
bool AbstractStorageDecl::isConstValue() const {
1345-
return getAttrs().hasAttribute<ConstValAttr>();
1345+
return getAttrs().hasAttribute<ConstValAttr>() || getAttrs().hasAttribute<SectionAttr>();
13461346
}
13471347

13481348
bool AbstractStorageDecl::isTransparent() const {

0 commit comments

Comments
 (0)