Skip to content

Commit f8e5d94

Browse files
committed
Merge branch 'main' of github.com:apple/swift into maxd/main-merge
# Conflicts: # lib/ClangImporter/ClangImporter.cpp
2 parents 6ddb247 + 2a9c148 commit f8e5d94

File tree

65 files changed

+802
-312
lines changed

Some content is hidden

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

65 files changed

+802
-312
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,9 +1094,6 @@ if(SWIFT_ENABLE_DISPATCH)
10941094
include(Libdispatch)
10951095
endif()
10961096

1097-
add_bootstrapping_target(0)
1098-
add_bootstrapping_target(1)
1099-
11001097
# Add all of the subdirectories, where we actually do work.
11011098

11021099
###############

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ function(add_libswift name)
781781
"-parse-as-library" ${sources}
782782
"-wmo" ${libswift_compile_options}
783783
"-I" "${SWIFT_SOURCE_DIR}/include/swift"
784+
"-I" "${SWIFT_SOURCE_DIR}/include"
784785
"-I" "${build_dir}"
785786
COMMENT "Building libswift module ${module}")
786787
@@ -975,13 +976,15 @@ function(add_swift_host_tool executable)
975976
INSTALL_RPATH "${RPATH_LIST}")
976977
977978
elseif(SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX" AND ASHT_HAS_LIBSWIFT AND LIBSWIFT_BUILD_MODE)
979+
set(swiftrt "swiftImageRegistrationObject${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}")
978980
if(LIBSWIFT_BUILD_MODE STREQUAL "HOSTTOOLS")
979981
# At build time and and run time, link against the swift libraries in the
980982
# installed host toolchain.
981983
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_LIBSWIFT} DIRECTORY)
982984
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
983985
set(host_lib_dir "${swift_dir}/lib/swift/linux")
984986
987+
target_link_libraries(${executable} PRIVATE ${swiftrt})
985988
target_link_libraries(${executable} PRIVATE "swiftCore")
986989
987990
target_link_directories(${executable} PRIVATE ${host_lib_dir})
@@ -995,6 +998,7 @@ function(add_swift_host_tool executable)
995998
if (NOT "${ASHT_BOOTSTRAPPING}" STREQUAL "0")
996999
get_bootstrapping_swift_lib_dir(bs_lib_dir "${ASHT_BOOTSTRAPPING}")
9971000
target_link_directories(${executable} PRIVATE ${bs_lib_dir})
1001+
target_link_libraries(${executable} PRIVATE ${swiftrt})
9981002
target_link_libraries(${executable} PRIVATE "swiftCore")
9991003
endif()
10001004

cmake/modules/SwiftUtils.cmake

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,35 +111,6 @@ function(get_bootstrapping_swift_lib_dir bs_lib_dir bootstrapping)
111111
set(bs_lib_dir ${bs_lib_dir} PARENT_SCOPE)
112112
endfunction()
113113

114-
function(add_bootstrapping_target bootstrapping)
115-
if(${LIBSWIFT_BUILD_MODE} MATCHES "BOOTSTRAPPING.*")
116-
117-
set(target "bootstrapping${bootstrapping}-all")
118-
add_custom_target(${target})
119-
120-
if(${LIBSWIFT_BUILD_MODE} STREQUAL "BOOTSTRAPPING")
121-
set(lib_target "bootstrapping${bootstrapping}-corelib")
122-
add_custom_target(${lib_target})
123-
add_dependencies(${target} ${lib_target})
124-
endif()
125-
126-
if(SWIFT_PATH_TO_LIBICU_BUILD)
127-
# Need to symlink the libicu libraries to be able to run
128-
# the bootstrapping compiler with a custom library path.
129-
get_bootstrapping_path(output_dir
130-
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}" "${bootstrapping}")
131-
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
132-
message("TODO: support for copying ICU libraries on Windows")
133-
endif()
134-
add_custom_command(TARGET "${target}" POST_BUILD
135-
COMMAND
136-
"ln" "-s" "-f" "${SWIFT_PATH_TO_LIBICU_BUILD}/lib/libicu*" "."
137-
WORKING_DIRECTORY "${output_dir}"
138-
COMMENT "symlink ICU libraries for bootstrapping stage ${bootstrapping}")
139-
endif()
140-
endif()
141-
endfunction()
142-
143114
function(is_build_type_optimized build_type result_var_name)
144115
if("${build_type}" STREQUAL "Debug")
145116
set("${result_var_name}" FALSE PARENT_SCOPE)

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(async, Async,
605605
106)
606606

607607
SIMPLE_DECL_ATTR(Sendable, Sendable,
608-
OnFunc | OnConstructor | OnAccessor |
608+
OnFunc | OnConstructor | OnAccessor | OnAnyClangDecl |
609609
ABIBreakingToAdd | ABIBreakingToRemove |
610610
APIBreakingToAdd | APIBreakingToRemove,
611611
107)

include/swift/AST/Attr.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ class DeclAttribute : public AttributeBase {
168168
);
169169

170170
SWIFT_INLINE_BITFIELD(SynthesizedProtocolAttr, DeclAttribute,
171-
NumKnownProtocolKindBits,
172-
kind : NumKnownProtocolKindBits
171+
NumKnownProtocolKindBits+1,
172+
kind : NumKnownProtocolKindBits,
173+
isUnchecked : 1
173174
);
174175
} Bits;
175176

@@ -288,6 +289,9 @@ class DeclAttribute : public AttributeBase {
288289

289290
/// Whether this attribute is only valid when distributed is enabled.
290291
DistributedOnly = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 17),
292+
293+
/// Whether this attribute is valid on additional decls in ClangImporter.
294+
OnAnyClangDecl = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 18),
291295
};
292296

293297
LLVM_READNONE
@@ -1276,11 +1280,13 @@ class SynthesizedProtocolAttr : public DeclAttribute {
12761280

12771281
public:
12781282
SynthesizedProtocolAttr(KnownProtocolKind protocolKind,
1279-
LazyConformanceLoader *Loader)
1283+
LazyConformanceLoader *Loader,
1284+
bool isUnchecked)
12801285
: DeclAttribute(DAK_SynthesizedProtocol, SourceLoc(), SourceRange(),
12811286
/*Implicit=*/true), Loader(Loader)
12821287
{
12831288
Bits.SynthesizedProtocolAttr.kind = unsigned(protocolKind);
1289+
Bits.SynthesizedProtocolAttr.isUnchecked = unsigned(isUnchecked);
12841290
}
12851291

12861292
/// Retrieve the known protocol kind naming the protocol to be
@@ -1289,6 +1295,10 @@ class SynthesizedProtocolAttr : public DeclAttribute {
12891295
return KnownProtocolKind(Bits.SynthesizedProtocolAttr.kind);
12901296
}
12911297

1298+
bool isUnchecked() const {
1299+
return bool(Bits.SynthesizedProtocolAttr.isUnchecked);
1300+
}
1301+
12921302
/// Retrieve the lazy loader that will be used to populate the
12931303
/// synthesized conformance.
12941304
LazyConformanceLoader *getLazyLoader() const { return Loader; }
@@ -2217,6 +2227,15 @@ class DeclAttributes {
22172227
return nullptr;
22182228
}
22192229

2230+
/// Returns the "winning" \c NonSendableAttr or \c SendableAttr in this
2231+
/// attribute list, or \c nullptr if there are none.
2232+
const DeclAttribute *getEffectiveSendableAttr() const;
2233+
2234+
DeclAttribute *getEffectiveSendableAttr() {
2235+
return const_cast<DeclAttribute *>(
2236+
const_cast<const DeclAttributes *>(this)->getEffectiveSendableAttr());
2237+
}
2238+
22202239
private:
22212240
/// Predicate used to filter MatchingAttributeRange.
22222241
template <typename ATTR, bool AllowInvalid> struct ToAttributeKind {

include/swift/AST/Builtins.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,9 @@ BUILTIN_MISC_OPERATION(InitializeDistributedRemoteActor,
770770
BUILTIN_MISC_OPERATION(ResumeNonThrowingContinuationReturning,
771771
"resumeNonThrowingContinuationReturning", "", Special)
772772

773+
/// targetOSVersionAtLeast has type (Builtin.Int32, Builtin.Int32, Builtin.Int32) -> Builtin.Int32
774+
BUILTIN_MISC_OPERATION(TargetOSVersionAtLeast, "targetOSVersionAtLeast", "n", Special)
775+
773776
/// Resume a throwing continuation normally with the given result.
774777
BUILTIN_MISC_OPERATION(ResumeThrowingContinuationReturning,
775778
"resumeThrowingContinuationReturning", "", Special)

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ NOTE(unresolvable_clang_decl_is_a_framework_bug,none,
8585
WARNING(clang_swift_attr_unhandled,none,
8686
"Ignoring unknown Swift attribute or modifier '%0'", (StringRef))
8787

88+
WARNING(clang_error_code_must_be_sendable,none,
89+
"cannot make error code type '%0' non-sendable because Swift errors "
90+
"are always sendable", (StringRef))
91+
8892
WARNING(implicit_bridging_header_imported_from_module,none,
8993
"implicit import of bridging header '%0' via module %1 "
9094
"is deprecated and will be removed in a later version of Swift",

include/swift/AST/FileUnit.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
#include "swift/AST/RawComment.h"
1818
#include "swift/Basic/BasicSourceInfo.h"
1919

20+
#include "llvm/ADT/PointerIntPair.h"
21+
2022
namespace swift {
23+
class SynthesizedFileUnit;
24+
2125
/// A container for module-scope declarations that itself provides a scope; the
2226
/// smallest unit of code organization.
2327
///
@@ -33,19 +37,25 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
3337
friend class DirectOperatorLookupRequest;
3438
friend class DirectPrecedenceGroupLookupRequest;
3539

36-
// FIXME: Stick this in a PointerIntPair.
37-
const FileUnitKind Kind;
40+
// The pointer is FileUnit insted of SynthesizedFileUnit to break circularity.
41+
llvm::PointerIntPair<FileUnit *, 3, FileUnitKind> SynthesizedFileAndKind;
3842

3943
protected:
4044
FileUnit(FileUnitKind kind, ModuleDecl &M)
41-
: DeclContext(DeclContextKind::FileUnit, &M), Kind(kind) {
45+
: DeclContext(DeclContextKind::FileUnit, &M),
46+
SynthesizedFileAndKind(nullptr, kind) {
4247
}
4348

4449
public:
4550
FileUnitKind getKind() const {
46-
return Kind;
51+
return SynthesizedFileAndKind.getInt();
4752
}
4853

54+
/// Returns the synthesized file for this source file, if it exists.
55+
SynthesizedFileUnit *getSynthesizedFile() const;
56+
57+
SynthesizedFileUnit &getOrCreateSynthesizedFile();
58+
4959
/// Look up a (possibly overloaded) value set at top-level scope
5060
/// (but with the specified access path, which may come from an import decl)
5161
/// within this file.

include/swift/AST/Module.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ class ModuleDecl
758758
/// The order of the results is not guaranteed to be meaningful.
759759
///
760760
/// This can differ from \c getTopLevelDecls, e.g. it returns decls from a
761-
/// shadowed clang module.
761+
/// shadowed clang module. It does not force synthesized top-level decls that
762+
/// should be printed to be added; use \c swift::getTopLevelDeclsForDisplay()
763+
/// for that.
762764
void getDisplayDecls(SmallVectorImpl<Decl*> &results) const;
763765

764766
using LinkLibraryCallback = llvm::function_ref<void(LinkLibrary)>;

include/swift/AST/PrintOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ struct PrintOptions {
235235
/// Whether to print unavailable parts of the AST.
236236
bool SkipUnavailable = false;
237237

238+
/// Whether to print synthesized extensions created by '@_nonSendable', even
239+
/// if SkipImplicit or SkipUnavailable is set.
240+
bool AlwaysPrintNonSendableExtensions = true;
241+
238242
bool SkipSwiftPrivateClangDecls = false;
239243

240244
/// Whether to skip internal stdlib declarations.
@@ -667,6 +671,7 @@ struct PrintOptions {
667671
PO.ShouldQualifyNestedDeclarations = QualifyNestedDeclarations::TypesOnly;
668672
PO.PrintParameterSpecifiers = true;
669673
PO.SkipImplicit = true;
674+
PO.AlwaysPrintNonSendableExtensions = false;
670675
PO.AlwaysTryPrintParameterLabels = true;
671676
return PO;
672677
}

include/swift/AST/ProtocolConformance.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,13 @@ class NormalProtocolConformance : public RootProtocolConformance,
514514
return ContextAndBits.getInt() & UncheckedFlag;
515515
}
516516

517+
/// Mark the conformance as unchecked (equivalent to the @unchecked
518+
/// conformance attribute).
519+
void setUnchecked() {
520+
// OK to mutate because the flags are not part of the folding set node ID.
521+
ContextAndBits.setInt(ContextAndBits.getInt() | UncheckedFlag);
522+
}
523+
517524
/// Get the kind of source from which this conformance comes.
518525
ConformanceEntryKind getSourceKind() const {
519526
return SourceKindAndImplyingConformance.getInt();

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ class SourceFile final : public FileUnit {
8989
/// same module.
9090
mutable Identifier PrivateDiscriminator;
9191

92-
/// A synthesized file corresponding to this file, created on-demand.
93-
SynthesizedFileUnit *SynthesizedFile = nullptr;
94-
9592
/// The root TypeRefinementContext for this SourceFile.
9693
///
9794
/// This is set during type checking.
@@ -409,11 +406,6 @@ class SourceFile final : public FileUnit {
409406
Optional<ExternalSourceLocs::RawLocs>
410407
getExternalRawLocsForDecl(const Decl *D) const override;
411408

412-
/// Returns the synthesized file for this source file, if it exists.
413-
SynthesizedFileUnit *getSynthesizedFile() const { return SynthesizedFile; };
414-
415-
SynthesizedFileUnit &getOrCreateSynthesizedFile();
416-
417409
virtual bool walk(ASTWalker &walker) override;
418410

419411
/// The buffer ID for the file that was imported, or None if there

include/swift/AST/SynthesizedFileUnit.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818

1919
namespace swift {
2020

21-
class SourceFile;
22-
2321
/// A container for synthesized declarations, attached to a `SourceFile`.
2422
///
2523
/// Currently, only module-level synthesized declarations are supported.
2624
class SynthesizedFileUnit final : public FileUnit {
2725
/// The parent source file.
28-
SourceFile &SF;
26+
FileUnit &FU;
2927

3028
/// Synthesized top level declarations.
3129
TinyPtrVector<Decl *> TopLevelDecls;
@@ -36,11 +34,11 @@ class SynthesizedFileUnit final : public FileUnit {
3634
mutable Identifier PrivateDiscriminator;
3735

3836
public:
39-
SynthesizedFileUnit(SourceFile &SF);
37+
SynthesizedFileUnit(FileUnit &FU);
4038
~SynthesizedFileUnit() = default;
4139

4240
/// Returns the parent source file.
43-
SourceFile &getSourceFile() const { return SF; }
41+
FileUnit &getFileUnit() const { return FU; }
4442

4543
/// Add a synthesized top-level declaration.
4644
void addTopLevelDecl(Decl *D) { TopLevelDecls.push_back(D); }

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,16 @@ FUNCTION(TSanInoutAccess, __tsan_external_write, C_CC, AlwaysAvailable,
16911691
ATTRS(NoUnwind),
16921692
EFFECT(NoEffect))
16931693

1694+
// int32 __isPlatformVersionAtLeast(uint32_t platform, uint32_t major,
1695+
// uint32_t minor, uint32_t patch);
1696+
// This a C builtin provided by compiler-rt.
1697+
FUNCTION(PlatformVersionAtLeast, __isPlatformVersionAtLeast,
1698+
C_CC, AlwaysAvailable,
1699+
RETURNS(Int32Ty),
1700+
ARGS(Int32Ty, Int32Ty, Int32Ty, Int32Ty),
1701+
ATTRS(NoUnwind),
1702+
EFFECT(NoEffect))
1703+
16941704
FUNCTION(GetKeyPath, swift_getKeyPath, C_CC, AlwaysAvailable,
16951705
RETURNS(RefCountedPtrTy),
16961706
ARGS(Int8PtrTy, Int8PtrTy),

include/swift/SIL/BridgedSwiftObject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
#include <stdint.h>
2222

23+
#if !defined(__has_feature)
24+
#define __has_feature(feature) 0
25+
#endif
26+
2327
// TODO: These macro definitions are duplicated in Visibility.h. Move
2428
// them to a single file if we find a location that both Visibility.h and
2529
// BridgedSwiftObject.h can import.

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef SWIFT_SILOPTIMIZER_OPTIMIZERBRIDGING_H
1414
#define SWIFT_SILOPTIMIZER_OPTIMIZERBRIDGING_H
1515

16-
#include "../SIL/SILBridging.h"
16+
#include "swift/SIL/SILBridging.h"
1717

1818
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
1919

include/swift/Sema/IDETypeChecking.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ namespace swift {
140140
LookupResult
141141
lookupSemanticMember(DeclContext *DC, Type ty, DeclName name);
142142

143+
/// Get all of the top-level declarations that should be printed as part of
144+
/// this module. This may force synthesis of top-level declarations that
145+
/// \c ModuleDecl::getDisplayDecls() would only return if previous
146+
/// work happened to have synthesized them.
147+
void
148+
getTopLevelDeclsForDisplay(ModuleDecl *M, SmallVectorImpl<Decl*> &Results);
149+
143150
struct ExtensionInfo {
144151
// The extension with the declarations to apply.
145152
ExtensionDecl *Ext;

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "llvm/ADT/STLExtras.h"
2+
#include "swift/AST/ASTMangler.h"
23
#include "swift/Basic/Defer.h"
4+
#include "swift/Sema/IDETypeChecking.h"
35
#include "swift/SIL/SILDeclRef.h"
4-
#include "swift/AST/ASTMangler.h"
56
#include <swift/APIDigester/ModuleAnalyzerNodes.h>
67
#include <algorithm>
78

@@ -1872,7 +1873,7 @@ void SwiftDeclCollector::printTopLevelNames() {
18721873
void SwiftDeclCollector::lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules) {
18731874
for (auto M: Modules) {
18741875
llvm::SmallVector<Decl*, 512> Decls;
1875-
M->getDisplayDecls(Decls);
1876+
swift::getTopLevelDeclsForDisplay(M, Decls);
18761877
for (auto D : Decls) {
18771878
if (Ctx.shouldIgnore(D))
18781879
continue;

0 commit comments

Comments
 (0)