Skip to content

Commit 5406131

Browse files
committed
[move-only] Emit a nice error if a move only type is imported into a module that does not have experimental-move-only enabled.
This just prevents user confusion when they forget to do this since weird behavior /could/ result. rdar://102062737
1 parent 938036b commit 5406131

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6528,6 +6528,11 @@ ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
65286528
none, "Can not use feature when experimental move only is disabled! Pass"
65296529
" the frontend flag -enable-experimental-move-only to swift to enable "
65306530
"the usage of this language feature", ())
6531+
ERROR(experimental_moveonly_feature_can_only_be_imported_when_enabled,
6532+
none, "Can not import module %0 that uses move only features when "
6533+
"experimental move only is disabled! Pass the frontend flag "
6534+
"-enable-experimental-move-only to swift to enable the usage of this "
6535+
"language feature", (Identifier))
65316536
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
65326537
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
65336538
ERROR(noimplicitcopy_attr_invalid_in_generic_context,

lib/Serialization/Deserialization.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "ModuleFormat.h"
1717
#include "swift/AST/ASTContext.h"
1818
#include "swift/AST/Attr.h"
19+
#include "swift/AST/AttrKind.h"
1920
#include "swift/AST/AutoDiff.h"
2021
#include "swift/AST/DiagnosticsSema.h"
2122
#include "swift/AST/Expr.h"
@@ -24,18 +25,18 @@
2425
#include "swift/AST/GenericEnvironment.h"
2526
#include "swift/AST/Initializer.h"
2627
#include "swift/AST/NameLookupRequests.h"
27-
#include "swift/AST/Pattern.h"
2828
#include "swift/AST/ParameterList.h"
29+
#include "swift/AST/Pattern.h"
2930
#include "swift/AST/PrettyStackTrace.h"
3031
#include "swift/AST/PropertyWrappers.h"
3132
#include "swift/AST/ProtocolConformance.h"
3233
#include "swift/AST/TypeCheckRequests.h"
34+
#include "swift/Basic/Defer.h"
35+
#include "swift/Basic/Statistic.h"
3336
#include "swift/ClangImporter/ClangImporter.h"
3437
#include "swift/ClangImporter/ClangModule.h"
3538
#include "swift/ClangImporter/SwiftAbstractBasicReader.h"
3639
#include "swift/Serialization/SerializedModuleLoader.h"
37-
#include "swift/Basic/Defer.h"
38-
#include "swift/Basic/Statistic.h"
3940
#include "clang/AST/DeclTemplate.h"
4041
#include "llvm/ADT/Statistic.h"
4142
#include "llvm/Support/Compiler.h"
@@ -5131,6 +5132,17 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
51315132
MF.fatal(llvm::make_error<InvalidRecordKindError>(recordID));
51325133
}
51335134

5135+
// Do a quick check to see if this attribute is a move only attribute. If
5136+
// so, emit a nice error if we don't have experimental move only enabled.
5137+
if (Attr->getKind() == DeclAttrKind::DAK_MoveOnly &&
5138+
!MF.getContext().LangOpts.Features.contains(Feature::MoveOnly)) {
5139+
MF.getContext().Diags.diagnose(
5140+
SourceLoc(),
5141+
diag::
5142+
experimental_moveonly_feature_can_only_be_imported_when_enabled,
5143+
MF.getAssociatedModule()->getName());
5144+
}
5145+
51345146
if (!skipAttr) {
51355147
if (!Attr)
51365148
return llvm::Error::success();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
@_moveOnly
3+
public class Klass {}

test/Serialization/moveonly.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t/Library.swiftmodule -module-name Library %S/Inputs/moveonly_klass.swift -enable-experimental-move-only
3+
// RUN: not %target-swift-frontend -I %t %s -emit-sil -o /dev/null 2>&1 | %FileCheck %s
4+
5+
// This test makes sure that if we import a move only type and do not set the
6+
// experimental move only flag, we get a nice error.
7+
8+
import Library
9+
10+
// CHECK: error: Can not import module 'Library' that uses move only features when experimental move only is disabled! Pass the frontend flag -enable-experimental-move-only to swift to enable the usage of this language feature
11+
12+
func f(_ k: Klass) {
13+
}

0 commit comments

Comments
 (0)