Skip to content

Commit 290cf5a

Browse files
committed
Track 'release/5.5' to resolve merge conflicts.
Conflicts were just @Availability marker changes.
2 parents 6167d0d + 0912fa2 commit 290cf5a

File tree

121 files changed

+2099
-653
lines changed

Some content is hidden

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

121 files changed

+2099
-653
lines changed

include/swift/AST/ASTContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ class ASTContext final {
880880
/// If there is no Clang module loader, returns a null pointer.
881881
/// The loader is owned by the AST context.
882882
ClangModuleLoader *getDWARFModuleLoader() const;
883+
884+
/// Check whether the module with a given name can be imported without
885+
/// importing it.
886+
///
887+
/// Note that even if this check succeeds, errors may still occur if the
888+
/// module is loaded in full.
889+
bool canImportModuleImpl(ImportPath::Element ModulePath) const;
883890
public:
884891
namelookup::ImportCache &getImportCache() const;
885892

@@ -909,6 +916,7 @@ class ASTContext final {
909916
/// Note that even if this check succeeds, errors may still occur if the
910917
/// module is loaded in full.
911918
bool canImportModule(ImportPath::Element ModulePath);
919+
bool canImportModule(ImportPath::Element ModulePath) const;
912920

913921
/// \returns a module with a given name that was already loaded. If the
914922
/// module was not loaded, returns nullptr.

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ ERROR(cannot_emit_ir_skipping_function_bodies,none,
136136
WARNING(emit_reference_dependencies_without_primary_file,none,
137137
"ignoring -emit-reference-dependencies (requires -primary-file)", ())
138138

139+
WARNING(warn_implicit_concurrency_import_failed,none,
140+
"unable to perform implicit import of \"_Concurrency\" module: no such module found", ())
141+
139142
ERROR(error_module_name_required,none, "-module-name is required", ())
140143
ERROR(error_bad_module_name,none,
141144
"module name \"%0\" is not a valid identifier"

include/swift/AST/DiagnosticsRefactoring.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ ERROR(unknown_callback_conditions, none, "cannot refactor complex if conditions"
6262

6363
ERROR(mixed_callback_conditions, none, "cannot refactor mixed nil and not-nil conditions", ())
6464

65-
ERROR(callback_multiple_bound_names, none, "cannot refactor when multiple names bound to single declaration, had '%0' and found '%1'", (StringRef, StringRef))
66-
6765
ERROR(callback_with_fallthrough, none, "cannot refactor switch with fallthrough", ())
6866

6967
ERROR(callback_with_default, none, "cannot refactor switch with default case", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ FIXIT(insert_closure_return_type_placeholder,
279279
"%select{| () }0-> <#Result#> %select{|in }0",
280280
(bool))
281281

282+
NOTE(use_of_anon_closure_param,none,
283+
"anonymous closure parameter %0 is used here", (Identifier))
284+
282285
ERROR(incorrect_explicit_closure_result,none,
283286
"declared closure result %0 is incompatible with contextual type %1",
284287
(Type, Type))

include/swift/AST/TypeRefinementContext.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,21 @@ class TypeRefinementContext {
154154

155155
SourceRange SrcRange;
156156

157+
/// A canonical availiability info for this context, computed top-down from the root
158+
/// context (compilation deployment target).
157159
AvailabilityContext AvailabilityInfo;
158160

161+
/// If this context was annotated with an availability attribute, this property captures that.
162+
/// It differs from the above `AvailabilityInfo` by being independent of the deployment target,
163+
/// and is used for providing availability attribute redundancy warning diagnostics.
164+
AvailabilityContext ExplicitAvailabilityInfo;
165+
159166
std::vector<TypeRefinementContext *> Children;
160167

161168
TypeRefinementContext(ASTContext &Ctx, IntroNode Node,
162169
TypeRefinementContext *Parent, SourceRange SrcRange,
163-
const AvailabilityContext &Info);
170+
const AvailabilityContext &Info,
171+
const AvailabilityContext &ExplicitInfo);
164172

165173
public:
166174

@@ -172,6 +180,7 @@ class TypeRefinementContext {
172180
static TypeRefinementContext *createForDecl(ASTContext &Ctx, Decl *D,
173181
TypeRefinementContext *Parent,
174182
const AvailabilityContext &Info,
183+
const AvailabilityContext &ExplicitInfo,
175184
SourceRange SrcRange);
176185

177186
/// Create a refinement context for the Then branch of the given IfStmt.
@@ -245,6 +254,12 @@ class TypeRefinementContext {
245254
return AvailabilityInfo;
246255
}
247256

257+
/// Returns the information on what availability was specified by the programmer
258+
/// on this context (if any).
259+
const AvailabilityContext &getExplicitAvailabilityInfo() const {
260+
return ExplicitAvailabilityInfo;
261+
}
262+
248263
/// Adds a child refinement context.
249264
void addChild(TypeRefinementContext *Child) {
250265
assert(Child->getSourceRange().isValid());

include/swift/Frontend/Frontend.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,14 @@ class CompilerInstance {
529529
return getMainModule()->getPrimarySourceFiles();
530530
}
531531

532+
/// Verify that if an implicit import of the `Concurrency` module if expected,
533+
/// it can actually be imported. Emit a warning, otherwise.
534+
void verifyImplicitConcurrencyImport();
535+
536+
/// Whether the Swift Concurrency support library can be imported
537+
/// i.e. if it can be found.
538+
bool canImportSwiftConcurrency() const;
539+
532540
/// Gets the SourceFile which is the primary input for this CompilerInstance.
533541
/// \returns the primary SourceFile, or nullptr if there is no primary input;
534542
/// if there are _multiple_ primary inputs, fails with an assertion.

lib/AST/ASTContext.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ bool ASTContext::shouldPerformTypoCorrection() {
19381938
return NumTypoCorrections <= LangOpts.TypoCorrectionLimit;
19391939
}
19401940

1941-
bool ASTContext::canImportModule(ImportPath::Element ModuleName) {
1941+
bool ASTContext::canImportModuleImpl(ImportPath::Element ModuleName) const {
19421942
// If this module has already been successfully imported, it is importable.
19431943
if (getLoadedModule(ImportPath::Module::Builder(ModuleName).get()) != nullptr)
19441944
return true;
@@ -1954,10 +1954,22 @@ bool ASTContext::canImportModule(ImportPath::Element ModuleName) {
19541954
}
19551955
}
19561956

1957-
FailedModuleImportNames.insert(ModuleName.Item);
19581957
return false;
19591958
}
19601959

1960+
bool ASTContext::canImportModule(ImportPath::Element ModuleName) {
1961+
if (canImportModuleImpl(ModuleName)) {
1962+
return true;
1963+
} else {
1964+
FailedModuleImportNames.insert(ModuleName.Item);
1965+
return false;
1966+
}
1967+
}
1968+
1969+
bool ASTContext::canImportModule(ImportPath::Element ModuleName) const {
1970+
return canImportModuleImpl(ModuleName);
1971+
}
1972+
19611973
ModuleDecl *
19621974
ASTContext::getModule(ImportPath::Module ModulePath) {
19631975
assert(!ModulePath.empty());

lib/AST/TypeRefinementContext.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ using namespace swift;
2828
TypeRefinementContext::TypeRefinementContext(ASTContext &Ctx, IntroNode Node,
2929
TypeRefinementContext *Parent,
3030
SourceRange SrcRange,
31-
const AvailabilityContext &Info)
32-
: Node(Node), SrcRange(SrcRange), AvailabilityInfo(Info) {
31+
const AvailabilityContext &Info,
32+
const AvailabilityContext &ExplicitInfo)
33+
: Node(Node), SrcRange(SrcRange),
34+
AvailabilityInfo(Info), ExplicitAvailabilityInfo(ExplicitInfo) {
3335
if (Parent) {
3436
assert(SrcRange.isValid());
3537
Parent->addChild(this);
@@ -46,18 +48,20 @@ TypeRefinementContext::createRoot(SourceFile *SF,
4648
ASTContext &Ctx = SF->getASTContext();
4749
return new (Ctx)
4850
TypeRefinementContext(Ctx, SF,
49-
/*Parent=*/nullptr, SourceRange(), Info);
51+
/*Parent=*/nullptr, SourceRange(),
52+
Info, AvailabilityContext::alwaysAvailable());
5053
}
5154

5255
TypeRefinementContext *
5356
TypeRefinementContext::createForDecl(ASTContext &Ctx, Decl *D,
5457
TypeRefinementContext *Parent,
5558
const AvailabilityContext &Info,
59+
const AvailabilityContext &ExplicitInfo,
5660
SourceRange SrcRange) {
5761
assert(D);
5862
assert(Parent);
5963
return new (Ctx)
60-
TypeRefinementContext(Ctx, D, Parent, SrcRange, Info);
64+
TypeRefinementContext(Ctx, D, Parent, SrcRange, Info, ExplicitInfo);
6165
}
6266

6367
TypeRefinementContext *
@@ -68,7 +72,8 @@ TypeRefinementContext::createForIfStmtThen(ASTContext &Ctx, IfStmt *S,
6872
assert(Parent);
6973
return new (Ctx)
7074
TypeRefinementContext(Ctx, IntroNode(S, /*IsThen=*/true), Parent,
71-
S->getThenStmt()->getSourceRange(), Info);
75+
S->getThenStmt()->getSourceRange(),
76+
Info, /* ExplicitInfo */Info);
7277
}
7378

7479
TypeRefinementContext *
@@ -79,7 +84,8 @@ TypeRefinementContext::createForIfStmtElse(ASTContext &Ctx, IfStmt *S,
7984
assert(Parent);
8085
return new (Ctx)
8186
TypeRefinementContext(Ctx, IntroNode(S, /*IsThen=*/false), Parent,
82-
S->getElseStmt()->getSourceRange(), Info);
87+
S->getElseStmt()->getSourceRange(),
88+
Info, /* ExplicitInfo */Info);
8389
}
8490

8591
TypeRefinementContext *
@@ -92,7 +98,7 @@ TypeRefinementContext::createForConditionFollowingQuery(ASTContext &Ctx,
9298
assert(Parent);
9399
SourceRange Range(PAI->getEndLoc(), LastElement.getEndLoc());
94100
return new (Ctx) TypeRefinementContext(Ctx, PAI, Parent, Range,
95-
Info);
101+
Info, /* ExplicitInfo */Info);
96102
}
97103

98104
TypeRefinementContext *
@@ -107,7 +113,7 @@ TypeRefinementContext::createForGuardStmtFallthrough(ASTContext &Ctx,
107113
SourceRange Range(RS->getEndLoc(), ContainingBraceStmt->getEndLoc());
108114
return new (Ctx) TypeRefinementContext(Ctx,
109115
IntroNode(RS, /*IsFallthrough=*/true),
110-
Parent, Range, Info);
116+
Parent, Range, Info, /* ExplicitInfo */Info);
111117
}
112118

113119
TypeRefinementContext *
@@ -118,7 +124,7 @@ TypeRefinementContext::createForGuardStmtElse(ASTContext &Ctx, GuardStmt *RS,
118124
assert(Parent);
119125
return new (Ctx)
120126
TypeRefinementContext(Ctx, IntroNode(RS, /*IsFallthrough=*/false), Parent,
121-
RS->getBody()->getSourceRange(), Info);
127+
RS->getBody()->getSourceRange(), Info, /* ExplicitInfo */Info);
122128
}
123129

124130
TypeRefinementContext *
@@ -128,7 +134,7 @@ TypeRefinementContext::createForWhileStmtBody(ASTContext &Ctx, WhileStmt *S,
128134
assert(S);
129135
assert(Parent);
130136
return new (Ctx) TypeRefinementContext(
131-
Ctx, S, Parent, S->getBody()->getSourceRange(), Info);
137+
Ctx, S, Parent, S->getBody()->getSourceRange(), Info, /* ExplicitInfo */Info);
132138
}
133139

134140
// Only allow allocation of TypeRefinementContext using the allocator in

lib/Frontend/Frontend.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,19 @@ bool CompilerInvocation::shouldImportSwiftONoneSupport() const {
800800
FrontendOptions::doesActionGenerateSIL(options.RequestedAction);
801801
}
802802

803+
void CompilerInstance::verifyImplicitConcurrencyImport() {
804+
if (Invocation.shouldImportSwiftConcurrency() &&
805+
!canImportSwiftConcurrency()) {
806+
Diagnostics.diagnose(SourceLoc(),
807+
diag::warn_implicit_concurrency_import_failed);
808+
}
809+
}
810+
811+
bool CompilerInstance::canImportSwiftConcurrency() const {
812+
return getASTContext().canImportModule(
813+
{getASTContext().getIdentifier(SWIFT_CONCURRENCY_NAME), SourceLoc()});
814+
}
815+
803816
ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
804817
auto &frontendOpts = Invocation.getFrontendOptions();
805818

@@ -824,14 +837,18 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
824837
pushImport(SWIFT_ONONE_SUPPORT);
825838
}
826839

840+
// FIXME: The canImport check is required for compatibility
841+
// with older SDKs. Longer term solution is to have the driver make
842+
// the decision on the implicit import: rdar://76996377
827843
if (Invocation.shouldImportSwiftConcurrency()) {
828844
switch (imports.StdlibKind) {
829845
case ImplicitStdlibKind::Builtin:
830846
case ImplicitStdlibKind::None:
831847
break;
832848

833849
case ImplicitStdlibKind::Stdlib:
834-
pushImport(SWIFT_CONCURRENCY_NAME);
850+
if (canImportSwiftConcurrency())
851+
pushImport(SWIFT_CONCURRENCY_NAME);
835852
break;
836853
}
837854
}
@@ -1043,6 +1060,8 @@ bool CompilerInstance::loadStdlibIfNeeded() {
10431060
return true;
10441061
}
10451062

1063+
verifyImplicitConcurrencyImport();
1064+
10461065
// If we failed to load, we should have already diagnosed.
10471066
if (M->failedToLoad()) {
10481067
assert(Diagnostics.hadAnyError() &&

0 commit comments

Comments
 (0)