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/LocalArchetypeRequirementCollector.h"
2526#include " swift/AST/Module.h"
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"
@@ -3041,8 +3043,6 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30413043 AbstractionPattern origType,
30423044 CanType substType,
30433045 TypeExpansionContext forExpansion) {
3044- if (!Context.LangOpts .hasFeature (Feature::BitwiseCopyable))
3045- return ;
30463046 auto *bitwiseCopyableProtocol =
30473047 Context.getProtocol (KnownProtocolKind::BitwiseCopyable);
30483048 if (!bitwiseCopyableProtocol)
@@ -3057,10 +3057,20 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30573057
30583058 if (auto *nominal = substType.getAnyNominal ()) {
30593059 auto *module = nominal->getModuleContext ();
3060- if (module && module ->isBuiltFromInterface ()) {
3061- // Don't verify for types in modules built from interfaces; the feature
3062- // may not have been enabled in them.
3063- return ;
3060+ if (module ) {
3061+ if (module ->isBuiltFromInterface ()) {
3062+ // Don't verify for types in modules built from interfaces; the feature
3063+ // may not have been enabled in them.
3064+ return ;
3065+ }
3066+ auto *file = dyn_cast_or_null<FileUnit>(module ->getModuleScopeContext ());
3067+ if (file && file->getKind () == FileUnitKind::Source) {
3068+ auto sourceFile = nominal->getParentSourceFile ();
3069+ if (sourceFile && sourceFile->Kind == SourceFileKind::SIL) {
3070+ // Don't verify for types in SIL files.
3071+ return ;
3072+ }
3073+ }
30643074 }
30653075 }
30663076
@@ -3086,6 +3096,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30863096 // unconditionally but does in this case
30873097 // (8) being or containing the error type
30883098 // (9) explicitly suppressing conformance
3099+ // (10) a layout constrained archetype
30893100 bool hasNoNonconformingNode = visitAggregateLeaves (
30903101 origType, substType, forExpansion,
30913102 /* isLeafAggregate=*/
@@ -3155,7 +3166,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31553166
31563167 // ModuleTypes are trivial but don't warrant being given a
31573168 // conformance to BitwiseCopyable (case (3)).
3158- if (isa<ModuleType, SILTokenType>(ty)) {
3169+ if (isa<ModuleType>(ty) || isa< SILTokenType>(ty)) {
31593170 // These types should never appear within aggregates.
31603171 assert (isTopLevel && " aggregate containing marker type!?" );
31613172 // If they did, though, they would not justify the aggregate's
@@ -3174,13 +3185,21 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31743185 return !isTopLevel;
31753186 }
31763187
3188+ // Case (10): a layout-constrained archetype.
3189+ if (auto archetype = dyn_cast<ArchetypeType>(ty)) {
3190+ auto constraint = archetype->getLayoutConstraint ();
3191+ if (constraint && constraint->isTrivial ()) {
3192+ return false ;
3193+ }
3194+ }
3195+
31773196 auto *nominal = ty.getAnyNominal ();
31783197
31793198 // Non-nominal types (besides case (3) handled above) are trivial iff
31803199 // conforming.
31813200 if (!nominal) {
31823201 llvm::errs ()
3183- << " Non-nominal type without conformance to _BitwiseCopyable :\n "
3202+ << " Non-nominal type without conformance to BitwiseCopyable :\n "
31843203 << ty << " \n "
31853204 << " within " << substType << " \n "
31863205 << " of " << origType << " \n " ;
@@ -3291,7 +3310,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
32913310 return true ;
32923311 });
32933312 if (hasNoConformingArchetypeNode) {
3294- llvm::errs () << " Non-trivial type with _BitwiseCopyable conformance!?:\n "
3313+ llvm::errs () << " Non-trivial type with BitwiseCopyable conformance!?:\n "
32953314 << substType << " \n " ;
32963315 conformance.print (llvm::errs ());
32973316 llvm::errs () << " \n "
0 commit comments