Skip to content

Commit fabfcd8

Browse files
committed
Merge branch 'main' of github.com:apple/swift into maxd/main-merge
# Conflicts: # stdlib/private/StdlibUnittest/CMakeLists.txt
2 parents bc0604a + 14d8c19 commit fabfcd8

File tree

76 files changed

+2330
-948
lines changed

Some content is hidden

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

76 files changed

+2330
-948
lines changed

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,10 @@ function(swift_benchmark_compile)
708708
cmake_parse_arguments(SWIFT_BENCHMARK_COMPILE "" "PLATFORM" "" ${ARGN})
709709

710710
if(NOT SWIFT_BENCHMARK_BUILT_STANDALONE)
711-
set(stdlib_dependencies "swift-frontend")
711+
set(stdlib_dependencies "swift-frontend" "swiftCore-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
712+
if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
713+
list(APPEND stdlib_dependencies "swiftDarwin-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
714+
endif()
712715
foreach(stdlib_dependency ${UNIVERSAL_LIBRARY_NAMES_${SWIFT_BENCHMARK_COMPILE_PLATFORM}})
713716
string(FIND "${stdlib_dependency}" "Unittest" find_output)
714717
if("${find_output}" STREQUAL "-1")

cmake/modules/AddSwift.cmake

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -802,16 +802,6 @@ macro(add_swift_lib_subdirectory name)
802802
add_llvm_subdirectory(SWIFT LIB ${name})
803803
endmacro()
804804
805-
function(_link_built_compatibility_libs executable)
806-
set(platform ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR})
807-
target_link_directories(${executable} PRIVATE
808-
${SWIFTLIB_DIR}/${platform})
809-
add_dependencies(${executable}
810-
"swiftCompatibility50-${platform}"
811-
"swiftCompatibility51-${platform}"
812-
"swiftCompatibilityDynamicReplacements-${platform}")
813-
endfunction()
814-
815805
function(add_swift_host_tool executable)
816806
set(options HAS_LIBSWIFT)
817807
set(single_parameter_options SWIFT_COMPONENT BOOTSTRAPPING)
@@ -910,24 +900,26 @@ function(add_swift_host_tool executable)
910900
list(APPEND RPATH_LIST "/usr/lib/swift")
911901
912902
elseif(LIBSWIFT_BUILD_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
913-
# Pick up the built libswiftCompatibility<n>.a libraries
914-
_link_built_compatibility_libs(${executable})
915-
916903
# Add the SDK directory for the host platform.
917904
target_link_directories(${executable} PRIVATE "${sdk_dir}")
918905
906+
# A backup in case the toolchain doesn't have one of the compatibility libraries.
907+
target_link_directories(${executable} PRIVATE
908+
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
909+
919910
# Include the abi stable system stdlib in our rpath.
920911
list(APPEND RPATH_LIST "/usr/lib/swift")
921912
922913
elseif(LIBSWIFT_BUILD_MODE STREQUAL "BOOTSTRAPPING")
923-
# Pick up the built libswiftCompatibility<n>.a libraries
924-
_link_built_compatibility_libs(${executable})
925-
926914
# At build time link against the built swift libraries from the
927915
# previous bootstrapping stage.
928916
get_bootstrapping_swift_lib_dir(bs_lib_dir "${ASHT_BOOTSTRAPPING}")
929917
target_link_directories(${executable} PRIVATE ${bs_lib_dir})
930918
919+
# Required to pick up the built libswiftCompatibility<n>.a libraries
920+
target_link_directories(${executable} PRIVATE
921+
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
922+
931923
# At runtime link against the built swift libraries from the current
932924
# bootstrapping stage.
933925
list(APPEND RPATH_LIST "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")

cmake/modules/StandaloneOverlay.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ set(SWIFT_DARWIN_MODULE_ARCHS "" CACHE STRING
8585
targets on Darwin platforms. These targets are in addition to the full \
8686
library targets.")
8787

88+
option(SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS
89+
"Build stdlib with fast-path context descriptor lookups based on well-known short manglings."
90+
TRUE)
8891

8992
# -----------------------------------------------------------------------------
9093
# Constants

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ enum class AssociatedValueCheck {
207207
/// Diagnostic printing of \c StaticSpellingKind.
208208
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, StaticSpellingKind SSK);
209209

210+
/// Diagnostic printing of \c ReferenceOwnership.
211+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, ReferenceOwnership RO);
212+
210213
/// Encapsulation of the overload signature of a given declaration,
211214
/// which is used to determine uniqueness of a declaration within a
212215
/// given context.

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,22 +398,12 @@ NOTE(generic_parameter_inferred_from_result_context,none,
398398
ERROR(cannot_pass_type_to_non_ephemeral,none,
399399
"cannot pass %0 to parameter; argument %1 must be a pointer that "
400400
"outlives the call%select{| to %3}2", (Type, StringRef, bool, DeclName))
401-
WARNING(cannot_pass_type_to_non_ephemeral_warning,none,
402-
"passing %0 to parameter, but argument %1 should be a pointer that "
403-
"outlives the call%select{| to %3}2", (Type, StringRef, bool, DeclName))
404401
ERROR(cannot_use_inout_non_ephemeral,none,
405402
"cannot use inout expression here; argument %0 must be a pointer that "
406403
"outlives the call%select{| to %2}1", (StringRef, bool, DeclName))
407-
WARNING(cannot_use_inout_non_ephemeral_warning,none,
408-
"inout expression creates a temporary pointer, but argument %0 should "
409-
"be a pointer that outlives the call%select{| to %2}1",
410-
(StringRef, bool, DeclName))
411404
ERROR(cannot_construct_dangling_pointer,none,
412405
"initialization of %0 results in a dangling %select{|buffer }1pointer",
413406
(Type, unsigned))
414-
WARNING(cannot_construct_dangling_pointer_warning,none,
415-
"initialization of %0 results in a dangling %select{|buffer }1pointer",
416-
(Type, unsigned))
417407
NOTE(ephemeral_pointer_argument_conversion_note,none,
418408
"implicit argument conversion from %0 to %1 produces a pointer valid only "
419409
"for the duration of the call%select{| to %3}2",
@@ -1881,9 +1871,6 @@ WARNING(spi_attribute_on_import_of_public_module,none,
18811871
(DeclName, StringRef))
18821872

18831873
// Opaque return types
1884-
ERROR(structural_opaque_types_are_experimental,none,
1885-
"'opaque' types cannot be nested inside other types; "
1886-
"structural 'opaque' types are an experimental feature", ())
18871874
ERROR(opaque_type_invalid_constraint,none,
18881875
"an 'opaque' type must specify only 'Any', 'AnyObject', protocols, "
18891876
"and/or a base class", ())
@@ -4878,6 +4865,10 @@ ERROR(opaque_type_unsupported_pattern,none,
48784865
ERROR(opaque_type_in_protocol_requirement,none,
48794866
"'some' type cannot be the return type of a protocol requirement; did you mean to add an associated type?",
48804867
())
4868+
ERROR(opaque_type_in_parameter,none,
4869+
"'some' cannot appear in parameter position in result "
4870+
"type %0",
4871+
(Type))
48814872

48824873
// Function differentiability
48834874
ERROR(attr_only_on_parameters_of_differentiable,none,

include/swift/AST/EducationalNotes.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,9 @@ EDUCATIONAL_NOTES(could_not_use_member_on_existential,
2525
"existential-member-access-limitations.md")
2626

2727
EDUCATIONAL_NOTES(cannot_pass_type_to_non_ephemeral, "temporary-pointers.md")
28-
EDUCATIONAL_NOTES(cannot_pass_type_to_non_ephemeral_warning,
29-
"temporary-pointers.md")
3028
EDUCATIONAL_NOTES(cannot_use_inout_non_ephemeral,
3129
"temporary-pointers.md")
32-
EDUCATIONAL_NOTES(cannot_use_inout_non_ephemeral_warning,
33-
"temporary-pointers.md")
3430
EDUCATIONAL_NOTES(cannot_construct_dangling_pointer, "temporary-pointers.md")
35-
EDUCATIONAL_NOTES(cannot_construct_dangling_pointer_warning,
36-
"temporary-pointers.md")
37-
38-
3931

4032
EDUCATIONAL_NOTES(non_nominal_no_initializers, "nominal-types.md")
4133
EDUCATIONAL_NOTES(non_nominal_extension, "nominal-types.md")

include/swift/AST/LayoutConstraintKind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#include "llvm/Support/DataTypes.h"
17+
#include <cstdint>
1818

1919
#ifndef SWIFT_LAYOUT_CONSTRAINTKIND_H
2020
#define SWIFT_LAYOUT_CONSTRAINTKIND_H

include/swift/AST/Ownership.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "llvm/ADT/StringRef.h"
2424
#include "llvm/Support/Compiler.h"
2525
#include "llvm/Support/ErrorHandling.h"
26-
#include "llvm/Support/raw_ostream.h"
2726
#include <assert.h>
2827
#include <limits.h>
2928
#include <stdint.h>
@@ -118,9 +117,6 @@ optionalityOf(ReferenceOwnership ownership) {
118117
llvm_unreachable("impossible");
119118
}
120119

121-
/// Diagnostic printing of \c StaticSpellingKind.
122-
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, ReferenceOwnership RO);
123-
124120
/// Different kinds of value ownership supported by Swift.
125121
enum class ValueOwnership : uint8_t {
126122
/// the context-dependent default ownership (sometimes shared,

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,6 @@ namespace swift {
310310
/// `func f() -> <T> T`.
311311
bool EnableExperimentalNamedOpaqueTypes = false;
312312

313-
/// Enable experimental support for structural opaque result types, e.g.
314-
/// `func f() -> (some P)?`.
315-
bool EnableExperimentalStructuralOpaqueTypes = false;
316-
317313
/// Enable experimental flow-sensitive concurrent captures.
318314
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;
319315

include/swift/SIL/DebugUtils.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,34 @@ struct DebugVarCarryingInst {
327327
}
328328
};
329329

330+
/// Attempt to discover a StringRef varName for the value \p value. If we fail,
331+
/// we return the name "unknown".
332+
inline StringRef getDebugVarName(SILValue value) {
333+
if (auto *asi = dyn_cast<AllocStackInst>(value)) {
334+
DebugVarCarryingInst debugVar(asi);
335+
if (auto varInfo = debugVar.getVarInfo()) {
336+
return varInfo->Name;
337+
} else {
338+
if (auto *decl = debugVar.getDecl()) {
339+
return decl->getBaseName().userFacingName();
340+
}
341+
}
342+
}
343+
344+
StringRef varName = "unknown";
345+
if (auto *use = getSingleDebugUse(value)) {
346+
DebugVarCarryingInst debugVar(use->getUser());
347+
if (auto varInfo = debugVar.getVarInfo()) {
348+
varName = varInfo->Name;
349+
} else {
350+
if (auto *decl = debugVar.getDecl()) {
351+
varName = decl->getBaseName().userFacingName();
352+
}
353+
}
354+
}
355+
return varName;
356+
}
357+
330358
} // end namespace swift
331359

332360
#endif // SWIFT_SIL_DEBUGUTILS_H

include/swift/Sema/CSFix.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,9 @@ class ContextualMismatch : public ConstraintFix {
650650
Type LHS, RHS;
651651

652652
ContextualMismatch(ConstraintSystem &cs, Type lhs, Type rhs,
653-
ConstraintLocator *locator)
654-
: ConstraintFix(cs, FixKind::ContextualMismatch, locator), LHS(lhs),
655-
RHS(rhs) {}
653+
ConstraintLocator *locator, bool warning)
654+
: ConstraintFix(cs, FixKind::ContextualMismatch, locator, warning),
655+
LHS(lhs), RHS(rhs) {}
656656

657657
protected:
658658
ContextualMismatch(ConstraintSystem &cs, FixKind kind, Type lhs, Type rhs,
@@ -741,9 +741,9 @@ class MarkExplicitlyEscaping final : public ContextualMismatch {
741741
/// Mark function type as being part of a global actor.
742742
class MarkGlobalActorFunction final : public ContextualMismatch {
743743
MarkGlobalActorFunction(ConstraintSystem &cs, Type lhs, Type rhs,
744-
ConstraintLocator *locator)
744+
ConstraintLocator *locator, bool warning)
745745
: ContextualMismatch(cs, FixKind::MarkGlobalActorFunction, lhs, rhs,
746-
locator) {
746+
locator, warning) {
747747
}
748748

749749
public:
@@ -752,7 +752,8 @@ class MarkGlobalActorFunction final : public ContextualMismatch {
752752
bool diagnose(const Solution &solution, bool asNote = false) const override;
753753

754754
static MarkGlobalActorFunction *create(ConstraintSystem &cs, Type lhs,
755-
Type rhs, ConstraintLocator *locator);
755+
Type rhs, ConstraintLocator *locator,
756+
bool warning);
756757

757758
static bool classof(ConstraintFix *fix) {
758759
return fix->getKind() == FixKind::MarkGlobalActorFunction;
@@ -787,9 +788,10 @@ class ForceOptional final : public ContextualMismatch {
787788
/// function types, repair it by adding @Sendable attribute.
788789
class AddSendableAttribute final : public ContextualMismatch {
789790
AddSendableAttribute(ConstraintSystem &cs, FunctionType *fromType,
790-
FunctionType *toType, ConstraintLocator *locator)
791+
FunctionType *toType, ConstraintLocator *locator,
792+
bool warning)
791793
: ContextualMismatch(cs, FixKind::AddSendableAttribute, fromType, toType,
792-
locator) {
794+
locator, warning) {
793795
assert(fromType->isSendable() != toType->isSendable());
794796
}
795797

@@ -801,7 +803,8 @@ class AddSendableAttribute final : public ContextualMismatch {
801803
static AddSendableAttribute *create(ConstraintSystem &cs,
802804
FunctionType *fromType,
803805
FunctionType *toType,
804-
ConstraintLocator *locator);
806+
ConstraintLocator *locator,
807+
bool warning);
805808

806809
static bool classof(ConstraintFix *fix) {
807810
return fix->getKind() == FixKind::AddSendableAttribute;

lib/AST/ModuleDependencies.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ void ModuleDependencies::addModuleDependencies(
100100
if (!importDecl)
101101
continue;
102102

103-
addModuleDependency(importDecl->getModulePath(), &alreadyAddedModules);
103+
ImportPath::Builder scratch;
104+
auto realPath = importDecl->getRealModulePath(scratch);
105+
addModuleDependency(realPath, &alreadyAddedModules);
104106
}
105107

106108
auto fileName = sf.getFilename();

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
438438
Opts.EnableExperimentalNamedOpaqueTypes |=
439439
Args.hasArg(OPT_enable_experimental_named_opaque_types);
440440

441-
Opts.EnableExperimentalStructuralOpaqueTypes |=
442-
Args.hasArg(OPT_enable_experimental_structural_opaque_types);
443-
444441
Opts.EnableExperimentalDistributed |=
445442
Args.hasArg(OPT_enable_experimental_distributed);
446443

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,7 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
16851685
if (subInstance.setup(subInvocation)) {
16861686
return std::make_error_code(std::errc::not_supported);
16871687
}
1688+
16881689
info.BuildArguments = BuildArgs;
16891690
info.Hash = CacheHash;
16901691
auto target = *(std::find(BuildArgs.rbegin(), BuildArgs.rend(), "-target") - 1);
@@ -1826,7 +1827,12 @@ std::error_code ExplicitSwiftModuleLoader::findModuleFilesInDirectory(
18261827

18271828
bool ExplicitSwiftModuleLoader::canImportModule(
18281829
ImportPath::Element mID, llvm::VersionTuple version, bool underlyingVersion) {
1829-
StringRef moduleName = mID.Item.str();
1830+
// Look up the module with the real name (physical name on disk);
1831+
// in case `-module-alias` is used, the name appearing in source files
1832+
// and the real module name are different. For example, '-module-alias Foo=Bar'
1833+
// maps Foo appearing in source files, e.g. 'import Foo', to the real module
1834+
// name Bar (on-disk name), which should be searched for loading.
1835+
StringRef moduleName = Ctx.getRealModuleName(mID.Item).str();
18301836
auto it = Impl.ExplicitModuleMap.find(moduleName);
18311837
// If no provided explicit module matches the name, then it cannot be imported.
18321838
if (it == Impl.ExplicitModuleMap.end()) {

lib/SILGen/SILGenPattern.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,6 +3007,10 @@ void SILGenFunction::emitCatchDispatch(DoCatchStmt *S, ManagedValue exn,
30073007
// If we don't have a multi-pattern 'catch', we can emit the
30083008
// body inline. Emit the statement here and bail early.
30093009
if (clause->getCaseLabelItems().size() == 1) {
3010+
// Debug values for catch clause variables must be nested within a scope for
3011+
// the catch block to avoid name conflicts.
3012+
DebugScope scope(*this, CleanupLocation(clause));
3013+
30103014
// If we have case body vars, set them up to point at the matching var
30113015
// decls.
30123016
if (clause->hasCaseBodyVariables()) {
@@ -3027,6 +3031,11 @@ void SILGenFunction::emitCatchDispatch(DoCatchStmt *S, ManagedValue exn,
30273031
// Ok, we found a match. Update the VarLocs for the case block.
30283032
auto v = VarLocs[vd];
30293033
VarLocs[expected] = v;
3034+
3035+
// Emit a debug description of the incoming arg, nested within the scope
3036+
// for the pattern match.
3037+
SILDebugVariable dbgVar(vd->isLet(), /*ArgNo=*/0);
3038+
B.emitDebugDescription(vd, v.value, dbgVar);
30303039
}
30313040
}
30323041
}

lib/Sema/CSDiagnostics.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ template <typename... ArgTypes>
102102
InFlightDiagnostic
103103
FailureDiagnostic::emitDiagnosticAt(ArgTypes &&... Args) const {
104104
auto &DE = getASTContext().Diags;
105-
return DE.diagnose(std::forward<ArgTypes>(Args)...);
105+
auto behavior = isWarning ? DiagnosticBehavior::Warning
106+
: DiagnosticBehavior::Unspecified;
107+
return std::move(DE.diagnose(std::forward<ArgTypes>(Args)...)
108+
.limitBehavior(behavior));
106109
}
107110

108111
Expr *FailureDiagnostic::findParentExpr(const Expr *subExpr) const {
@@ -6779,12 +6782,9 @@ bool NonEphemeralConversionFailure::diagnosePointerInit() const {
67796782
return false;
67806783
}
67816784

6782-
auto diagID = DowngradeToWarning
6783-
? diag::cannot_construct_dangling_pointer_warning
6784-
: diag::cannot_construct_dangling_pointer;
6785-
67866785
auto anchor = getRawAnchor();
6787-
emitDiagnosticAt(::getLoc(anchor), diagID, constructedTy, constructorKind)
6786+
emitDiagnosticAt(::getLoc(anchor), diag::cannot_construct_dangling_pointer,
6787+
constructedTy, constructorKind)
67886788
.highlight(::getSourceRange(anchor));
67896789

67906790
emitSuggestionNotes();
@@ -6814,20 +6814,12 @@ bool NonEphemeralConversionFailure::diagnoseAsError() {
68146814

68156815
auto *argExpr = getArgExpr();
68166816
if (isa<InOutExpr>(argExpr)) {
6817-
auto diagID = DowngradeToWarning
6818-
? diag::cannot_use_inout_non_ephemeral_warning
6819-
: diag::cannot_use_inout_non_ephemeral;
6820-
6821-
emitDiagnosticAt(argExpr->getLoc(), diagID, argDesc, getCallee(),
6822-
getCalleeFullName())
6817+
emitDiagnosticAt(argExpr->getLoc(), diag::cannot_use_inout_non_ephemeral,
6818+
argDesc, getCallee(), getCalleeFullName())
68236819
.highlight(argExpr->getSourceRange());
68246820
} else {
6825-
auto diagID = DowngradeToWarning
6826-
? diag::cannot_pass_type_to_non_ephemeral_warning
6827-
: diag::cannot_pass_type_to_non_ephemeral;
6828-
6829-
emitDiagnosticAt(argExpr->getLoc(), diagID, getArgType(), argDesc,
6830-
getCallee(), getCalleeFullName())
6821+
emitDiagnosticAt(argExpr->getLoc(), diag::cannot_pass_type_to_non_ephemeral,
6822+
getArgType(), argDesc, getCallee(), getCalleeFullName())
68316823
.highlight(argExpr->getSourceRange());
68326824
}
68336825
emitSuggestionNotes();

0 commit comments

Comments
 (0)