Skip to content

Commit 79b3d2d

Browse files
Add underscore prefix to extern attribute
It's already guarded by a feature flag, but it would be nice to signal users that it's not stable yet by adding an underscore prefix.
1 parent 031f112 commit 79b3d2d

27 files changed

+120
-122
lines changed

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,19 @@ the export name.
437437

438438
It's the equivalent of clang's `__attribute__((export_name))`.
439439

440-
## `@extern(<language>)`
440+
## `@_extern(<language>)`
441441

442442
Indicates that a particular declaration should be imported
443443
from the external environment.
444444

445-
### `@extern(wasm, module: <"moduleName">, name: <"fieldName">)`
445+
### `@_extern(wasm, module: <"moduleName">, name: <"fieldName">)`
446446

447447
Indicates that a particular declaration should be imported
448448
through WebAssembly's import interface.
449449

450450
It's the equivalent of clang's `__attribute__((import_module("module"), import_name("field")))`.
451451

452-
### `@extern(c, [, <"cName">])`
452+
### `@_extern(c, [, <"cName">])`
453453

454454
Indicates that a particular declaration should refer to a
455455
C declaration with the given name. If the optional "cName"
@@ -462,7 +462,7 @@ C declarations from Swift, while `@_cdecl` is used to define
462462
Swift functions that can be referenced from C.
463463

464464
Also similar to `@_silgen_name`, but a function declared with
465-
`@extern(c)` is assumed to use the C ABI, while `@_silgen_name`
465+
`@_extern(c)` is assumed to use the C ABI, while `@_silgen_name`
466466
assumes the Swift ABI.
467467

468468
## `@_fixed_layout`

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ DECL_ATTR(_section, Section,
421421
DECL_ATTR(_rawLayout, RawLayout,
422422
OnStruct | UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
423423
146)
424-
DECL_ATTR(extern, Extern,
424+
DECL_ATTR(_extern, Extern,
425425
OnFunc | AllowMultipleAttributes | ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
426426
147)
427427
SIMPLE_DECL_ATTR(_nonEscapable, NonEscapable,

include/swift/AST/Attr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ class ExposeAttr : public DeclAttribute {
23432343
}
23442344
};
23452345

2346-
/// Define the `@extern` attribute, used to import external declarations in
2346+
/// Define the `@_extern` attribute, used to import external declarations in
23472347
/// the specified way to interoperate with Swift.
23482348
class ExternAttr : public DeclAttribute {
23492349
SourceLoc LParenLoc, RParenLoc;
@@ -2368,7 +2368,7 @@ class ExternAttr : public DeclAttribute {
23682368
const llvm::Optional<StringRef> ModuleName;
23692369

23702370
/// The declaration name to import
2371-
/// std::nullopt if the declaration name is not specified with @extern(c)
2371+
/// std::nullopt if the declaration name is not specified with @_extern(c)
23722372
const llvm::Optional<StringRef> Name;
23732373

23742374
SourceLoc getLParenLoc() const { return LParenLoc; }

include/swift/AST/AttrKind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ enum class ExposureKind: uint8_t {
112112
enum : unsigned { NumExposureKindBits =
113113
countBitsUsed(static_cast<unsigned>(ExposureKind::Last_ExposureKind)) };
114114

115-
/// This enum represents the possible values of the @extern attribute.
115+
/// This enum represents the possible values of the @_extern attribute.
116116
enum class ExternKind: uint8_t {
117117
/// Reference an externally defined C function.
118118
/// The imported function has C function pointer representation,

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ ERROR(attr_rawlayout_expected_params,none,
18691869
"expected %1 argument after %0 argument in @_rawLayout attribute", (StringRef, StringRef))
18701870

18711871
ERROR(attr_extern_expected_label,none,
1872-
"expected %0 argument to @extern attribute", (StringRef))
1872+
"expected %0 argument to @_extern attribute", (StringRef))
18731873
//------------------------------------------------------------------------------
18741874
// MARK: Generics parsing diagnostics
18751875
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,17 +1900,17 @@ ERROR(section_not_at_top_level,none,
19001900
ERROR(section_empty_name,none,
19011901
"@_section section name cannot be empty", ())
19021902

1903-
// @extern
1903+
// @_extern
19041904
ERROR(attr_extern_experimental,none,
1905-
"@extern requires '-enable-experimental-feature Extern'", ())
1905+
"@_extern requires '-enable-experimental-feature Extern'", ())
19061906
ERROR(extern_not_at_top_level_func,none,
1907-
"@extern attribute can only be applied to global functions", ())
1907+
"@_extern attribute can only be applied to global functions", ())
19081908
ERROR(extern_empty_c_name,none,
1909-
"expected non-empty C name in @extern attribute", ())
1909+
"expected non-empty C name in @_extern attribute", ())
19101910
ERROR(extern_only_non_other_attr,none,
1911-
"@extern attribute cannot be applied to an '@%0' declaration", (StringRef))
1911+
"@_extern attribute cannot be applied to an '@%0' declaration", (StringRef))
19121912
WARNING(extern_c_maybe_invalid_name, none,
1913-
"C name '%0' may be invalid; explicitly specify the name in @extern(c) to suppress this warning",
1913+
"C name '%0' may be invalid; explicitly specify the name in @_extern(c) to suppress this warning",
19141914
(StringRef))
19151915

19161916
ERROR(c_func_variadic, none,

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
257257
/// lifetime-dependent results.
258258
EXPERIMENTAL_FEATURE(NonEscapableTypes, false)
259259

260-
/// Enable the `@extern` attribute.
260+
/// Enable the `@_extern` attribute.
261261
EXPERIMENTAL_FEATURE(Extern, true)
262262

263263
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE

include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ class Parser {
10951095
ParserResult<DifferentiableAttr> parseDifferentiableAttribute(SourceLoc AtLoc,
10961096
SourceLoc Loc);
10971097

1098-
/// Parse the @extern attribute.
1098+
/// Parse the @_extern attribute.
10991099
bool parseExternAttribute(DeclAttributes &Attributes, bool &DiscardAttribute,
11001100
StringRef AttrName, SourceLoc AtLoc, SourceLoc Loc);
11011101

include/swift/SIL/SILFunction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class SILFunction
303303
/// empty.
304304
StringRef WasmExportName;
305305

306-
/// Name of a Wasm import module and field if @extern(wasm) attribute
306+
/// Name of a Wasm import module and field if @_extern(wasm) attribute
307307
llvm::Optional<std::pair<StringRef, StringRef>> WasmImportModuleAndField;
308308

309309
/// Has value if there's a profile for this function
@@ -1288,14 +1288,14 @@ class SILFunction
12881288
StringRef wasmExportName() const { return WasmExportName; }
12891289
void setWasmExportName(StringRef value) { WasmExportName = value; }
12901290

1291-
/// Return Wasm import module name if @extern(wasm) was used otherwise empty
1291+
/// Return Wasm import module name if @_extern(wasm) was used otherwise empty
12921292
StringRef wasmImportModuleName() const {
12931293
if (WasmImportModuleAndField)
12941294
return WasmImportModuleAndField->first;
12951295
return StringRef();
12961296
}
12971297

1298-
/// Return Wasm import field name if @extern(wasm) was used otherwise empty
1298+
/// Return Wasm import field name if @_extern(wasm) was used otherwise empty
12991299
StringRef wasmImportFieldName() const {
13001300
if (WasmImportModuleAndField)
13011301
return WasmImportModuleAndField->second;

lib/AST/Attr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
11441144

11451145
case DAK_Extern: {
11461146
auto *Attr = cast<ExternAttr>(this);
1147-
Printer.printAttrName("@extern");
1147+
Printer.printAttrName("@_extern");
11481148
Printer << "(";
11491149
switch (Attr->getExternKind()) {
11501150
case ExternKind::C:
@@ -1155,7 +1155,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
11551155
break;
11561156
case ExternKind::Wasm:
11571157
Printer << "wasm";
1158-
// @extern(wasm) always has names.
1158+
// @_extern(wasm) always has names.
11591159
Printer << ", module: \"" << *Attr->ModuleName << "\"";
11601160
Printer << ", name: \"" << *Attr->Name << "\"";
11611161
break;
@@ -1749,7 +1749,7 @@ StringRef DeclAttribute::getAttrName() const {
17491749
case DAK_RawLayout:
17501750
return "_rawLayout";
17511751
case DAK_Extern:
1752-
return "extern";
1752+
return "_extern";
17531753
}
17541754
llvm_unreachable("bad DeclAttrKind");
17551755
}

0 commit comments

Comments
 (0)