Skip to content

Commit 6135791

Browse files
Merge pull request #73282 from nate-chandler/cherrypick/release/6.0/bitwise-copyable/enable
6.0: [BitwiseCopyable] Promote to feature.
2 parents 5c3ec6b + a8e8ab0 commit 6135791

File tree

53 files changed

+264
-297
lines changed

Some content is hidden

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

53 files changed

+264
-297
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7694,7 +7694,7 @@ ERROR(non_bitwise_copyable_type_cxx_nontrivial,none,
76947694
ERROR(non_bitwise_copyable_c_type_nontrivial,none,
76957695
"type with unrepresentable fields cannot derive conformance to 'BitwiseCopyable'", ())
76967696
NOTE(note_non_bitwise_copyable_c_type_add_attr,none,
7697-
"annotate the type __attribute__((__swift_attr__(\"_BitwiseCopyable\")))",())
7697+
"annotate the type __attribute__((__swift_attr__(\"BitwiseCopyable\")))",())
76987698
ERROR(non_bitwise_copyable_type_member,none,
76997699
"%select{stored property %2|associated value %2}1 of "
77007700
"'BitwiseCopyable'-conforming %kind3 has non-bitwise-copyable type %0",

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ PROTOCOL(FloatingPoint)
150150
INVERTIBLE_PROTOCOL_WITH_NAME(Name, #Name)
151151
#include "swift/ABI/InvertibleProtocols.def"
152152

153-
REPRESSIBLE_PROTOCOL_(BitwiseCopyable)
153+
REPRESSIBLE_PROTOCOL(BitwiseCopyable)
154154

155155
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByArrayLiteral, "Array", false)
156156
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByBooleanLiteral, "BooleanLiteralType", true)

include/swift/Basic/Features.def

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ LANGUAGE_FEATURE(BuiltinStoreRaw, 0, "Builtin.storeRaw")
176176
LANGUAGE_FEATURE(BuiltinCreateTask, 0, "Builtin.createTask and Builtin.createDiscardingTask")
177177
SUPPRESSIBLE_LANGUAGE_FEATURE(AssociatedTypeImplements, 0, "@_implements on associated types")
178178
LANGUAGE_FEATURE(MoveOnlyPartialConsumption, 429, "Partial consumption of noncopyable values")
179+
/// Enable bitwise-copyable feature.
180+
LANGUAGE_FEATURE(BitwiseCopyable, 426, "BitwiseCopyable protocol")
181+
SUPPRESSIBLE_LANGUAGE_FEATURE(ConformanceSuppression, 426, "Suppressible inferred conformances")
179182

180183
// Swift 6
181184
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -339,12 +342,6 @@ EXPERIMENTAL_FEATURE(StaticExclusiveOnly, true)
339342
/// Enable the @extractConstantsFromMembers attribute.
340343
EXPERIMENTAL_FEATURE(ExtractConstantsFromMembers, false)
341344

342-
/// Enable bitwise-copyable feature.
343-
EXPERIMENTAL_FEATURE(BitwiseCopyable, true)
344-
345-
/// Enable the suppression of inferred, non-invertible, protocols via ~.
346-
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ConformanceSuppression, true)
347-
348345
/// Enables the FixedArray data type.
349346
EXPERIMENTAL_FEATURE(FixedArrays, true)
350347

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,10 +1284,7 @@ static SmallVector<ProtocolConformance *, 2> findSynthesizedConformances(
12841284
for (auto ip : InvertibleProtocolSet::allKnown())
12851285
trySynthesize(getKnownProtocolKind(ip));
12861286

1287-
if (nominal->getASTContext().LangOpts.hasFeature(
1288-
Feature::BitwiseCopyable)) {
1289-
trySynthesize(KnownProtocolKind::BitwiseCopyable);
1290-
}
1287+
trySynthesize(KnownProtocolKind::BitwiseCopyable);
12911288
}
12921289

12931290
/// Distributed actors can synthesize Encodable/Decodable, so look for those

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8020,9 +8020,7 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
80208020
continue;
80218021
}
80228022

8023-
if (swiftAttr->getAttribute() == "_BitwiseCopyable") {
8024-
if (!SwiftContext.LangOpts.hasFeature(Feature::BitwiseCopyable))
8025-
continue;
8023+
if (swiftAttr->getAttribute() == "BitwiseCopyable") {
80268024
auto *protocol =
80278025
SwiftContext.getProtocol(KnownProtocolKind::BitwiseCopyable);
80288026
auto *nominal = dyn_cast<NominalTypeDecl>(MappedDecl);

lib/SIL/IR/TypeLowering.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/DiagnosticEngine.h"
2121
#include "swift/AST/DiagnosticsSIL.h"
2222
#include "swift/AST/Expr.h"
23+
#include "swift/AST/FileUnit.h"
2324
#include "swift/AST/GenericEnvironment.h"
2425
#include "swift/AST/LazyResolver.h"
2526
#include "swift/AST/Module.h"
@@ -28,6 +29,7 @@
2829
#include "swift/AST/Pattern.h"
2930
#include "swift/AST/PrettyStackTrace.h"
3031
#include "swift/AST/PropertyWrappers.h"
32+
#include "swift/AST/SourceFile.h"
3133
#include "swift/AST/TypeDifferenceVisitor.h"
3234
#include "swift/AST/Types.h"
3335
#include "swift/ClangImporter/ClangModule.h"
@@ -3034,8 +3036,6 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30343036
AbstractionPattern origType,
30353037
CanType substType,
30363038
TypeExpansionContext forExpansion) {
3037-
if (!Context.LangOpts.hasFeature(Feature::BitwiseCopyable))
3038-
return;
30393039
auto *bitwiseCopyableProtocol =
30403040
Context.getProtocol(KnownProtocolKind::BitwiseCopyable);
30413041
if (!bitwiseCopyableProtocol)
@@ -3050,10 +3050,20 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30503050

30513051
if (auto *nominal = substType.getAnyNominal()) {
30523052
auto *module = nominal->getModuleContext();
3053-
if (module && module->isBuiltFromInterface()) {
3054-
// Don't verify for types in modules built from interfaces; the feature
3055-
// may not have been enabled in them.
3056-
return;
3053+
if (module) {
3054+
if (module->isBuiltFromInterface()) {
3055+
// Don't verify for types in modules built from interfaces; the feature
3056+
// may not have been enabled in them.
3057+
return;
3058+
}
3059+
auto *file = dyn_cast_or_null<FileUnit>(module->getModuleScopeContext());
3060+
if (file && file->getKind() == FileUnitKind::Source) {
3061+
auto sourceFile = nominal->getParentSourceFile();
3062+
if (sourceFile && sourceFile->Kind == SourceFileKind::SIL) {
3063+
// Don't verify for types in SIL files.
3064+
return;
3065+
}
3066+
}
30573067
}
30583068
}
30593069

@@ -3079,6 +3089,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30793089
// unconditionally but does in this case
30803090
// (8) being or containing the error type
30813091
// (9) explicitly suppressing conformance
3092+
// (10) a layout constrained archetype
30823093
bool hasNoNonconformingNode = visitAggregateLeaves(
30833094
origType, substType, forExpansion,
30843095
/*isLeafAggregate=*/
@@ -3148,7 +3159,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31483159

31493160
// ModuleTypes are trivial but don't warrant being given a
31503161
// conformance to BitwiseCopyable (case (3)).
3151-
if (isa<ModuleType, SILTokenType>(ty)) {
3162+
if (isa<ModuleType>(ty) || isa<SILTokenType>(ty)) {
31523163
// These types should never appear within aggregates.
31533164
assert(isTopLevel && "aggregate containing marker type!?");
31543165
// If they did, though, they would not justify the aggregate's
@@ -3167,13 +3178,21 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31673178
return !isTopLevel;
31683179
}
31693180

3181+
// Case (10): a layout-constrained archetype.
3182+
if (auto archetype = dyn_cast<ArchetypeType>(ty)) {
3183+
auto constraint = archetype->getLayoutConstraint();
3184+
if (constraint && constraint->isTrivial()) {
3185+
return false;
3186+
}
3187+
}
3188+
31703189
auto *nominal = ty.getAnyNominal();
31713190

31723191
// Non-nominal types (besides case (3) handled above) are trivial iff
31733192
// conforming.
31743193
if (!nominal) {
31753194
llvm::errs()
3176-
<< "Non-nominal type without conformance to _BitwiseCopyable:\n"
3195+
<< "Non-nominal type without conformance to BitwiseCopyable:\n"
31773196
<< ty << "\n"
31783197
<< "within " << substType << "\n"
31793198
<< "of " << origType << "\n";
@@ -3284,7 +3303,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
32843303
return true;
32853304
});
32863305
if (hasNoConformingArchetypeNode) {
3287-
llvm::errs() << "Non-trivial type with _BitwiseCopyable conformance!?:\n"
3306+
llvm::errs() << "Non-trivial type with BitwiseCopyable conformance!?:\n"
32883307
<< substType << "\n";
32893308
conformance.print(llvm::errs());
32903309
llvm::errs() << "\n"

lib/Sema/LifetimeDependence.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,12 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd) {
205205
// error.
206206
// TODO: Diagnose ~Escapable types are always non-trivial in SIL.
207207
if (paramType->isEscapable()) {
208-
if (ctx.LangOpts.hasFeature(Feature::BitwiseCopyable)) {
209-
auto *bitwiseCopyableProtocol =
210-
ctx.getProtocol(KnownProtocolKind::BitwiseCopyable);
211-
if (bitwiseCopyableProtocol &&
212-
mod->checkConformance(paramType, bitwiseCopyableProtocol)) {
213-
diags.diagnose(loc, diag::lifetime_dependence_on_bitwise_copyable);
214-
return true;
215-
}
208+
auto *bitwiseCopyableProtocol =
209+
ctx.getProtocol(KnownProtocolKind::BitwiseCopyable);
210+
if (bitwiseCopyableProtocol &&
211+
mod->checkConformance(paramType, bitwiseCopyableProtocol)) {
212+
diags.diagnose(loc, diag::lifetime_dependence_on_bitwise_copyable);
213+
return true;
216214
}
217215
}
218216

@@ -425,16 +423,14 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
425423
if (!cd && afd->hasImplicitSelfDecl()) {
426424
Type selfTypeInContext = dc->getSelfTypeInContext();
427425
if (selfTypeInContext->isEscapable()) {
428-
if (ctx.LangOpts.hasFeature(Feature::BitwiseCopyable)) {
429-
auto *bitwiseCopyableProtocol =
430-
ctx.getProtocol(KnownProtocolKind::BitwiseCopyable);
431-
if (bitwiseCopyableProtocol &&
432-
mod->checkConformance(selfTypeInContext, bitwiseCopyableProtocol)) {
433-
diags.diagnose(
434-
returnLoc,
435-
diag::lifetime_dependence_method_escapable_bitwisecopyable_self);
436-
return std::nullopt;
437-
}
426+
auto *bitwiseCopyableProtocol =
427+
ctx.getProtocol(KnownProtocolKind::BitwiseCopyable);
428+
if (bitwiseCopyableProtocol &&
429+
mod->checkConformance(selfTypeInContext, bitwiseCopyableProtocol)) {
430+
diags.diagnose(
431+
returnLoc,
432+
diag::lifetime_dependence_method_escapable_bitwisecopyable_self);
433+
return std::nullopt;
438434
}
439435
}
440436
auto kind = getLifetimeDependenceKindFromType(selfTypeInContext);

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,9 @@ ExistentialConformsToSelfRequest::evaluate(Evaluator &evaluator,
682682
ProtocolDecl *decl) const {
683683
// Marker protocols always self-conform.
684684
if (decl->isMarkerProtocol()) {
685-
// Except for BitwiseCopyable an existential of which is non-trivial.
686-
if (decl->getASTContext().LangOpts.hasFeature(Feature::BitwiseCopyable) &&
687-
decl->getKnownProtocolKind() == KnownProtocolKind::BitwiseCopyable) {
685+
// Except for BitwiseCopyable an existential of which is not bitwise
686+
// copyable.
687+
if (decl->getKnownProtocolKind() == KnownProtocolKind::BitwiseCopyable) {
688688
return false;
689689
}
690690
return true;

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6117,11 +6117,9 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
61176117
break;
61186118
}
61196119
case KnownProtocolKind::BitwiseCopyable: {
6120-
if (Context.LangOpts.hasFeature(Feature::BitwiseCopyable)) {
6121-
checkBitwiseCopyableConformance(
6122-
conformance, /*isImplicit=*/conformance->getSourceKind() ==
6123-
ConformanceEntryKind::Synthesized);
6124-
}
6120+
checkBitwiseCopyableConformance(
6121+
conformance, /*isImplicit=*/conformance->getSourceKind() ==
6122+
ConformanceEntryKind::Synthesized);
61256123
break;
61266124
}
61276125
default:

stdlib/public/core/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,7 @@ list(APPEND swift_stdlib_compile_flags "-Xfrontend" "-enable-experimental-concis
315315
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "Macros")
316316
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "FreestandingMacros")
317317
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "Extern")
318-
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "BitwiseCopyable")
319318
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "BorrowingSwitch")
320-
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "ConformanceSuppression")
321319

322320
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
323321
set(swift_bin_dir "${CMAKE_BINARY_DIR}/bin")

0 commit comments

Comments
 (0)