Skip to content

Commit 9276bb0

Browse files
authored
Merge branch 'apple:main' into my-branch
2 parents 2be845e + 4b1deb0 commit 9276bb0

File tree

116 files changed

+1246
-618
lines changed

Some content is hidden

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

116 files changed

+1246
-618
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LetPropertyLowering.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ private func insertEndInitInstructions(
9999
atEndOf initRegion: InstructionRange,
100100
_ context: FunctionPassContext
101101
) {
102-
var ssaUpdater = SSAUpdater(type: markUninitialized.type, ownership: .owned, context)
102+
var ssaUpdater = SSAUpdater(function: markUninitialized.parentFunction,
103+
type: markUninitialized.type, ownership: .owned, context)
103104
ssaUpdater.addAvailableValue(markUninitialized, in: markUninitialized.parentBlock)
104105

105106
for endInst in initRegion.ends {

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/RedundantLoadElimination.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ private extension LoadInst {
236236
}
237237

238238
private func replace(load: LoadInst, with availableValues: [AvailableValue], _ context: FunctionPassContext) {
239-
var ssaUpdater = SSAUpdater(type: load.type, ownership: load.ownership, context)
239+
var ssaUpdater = SSAUpdater(function: load.parentFunction,
240+
type: load.type, ownership: load.ownership, context)
240241

241242
for availableValue in availableValues {
242243
let block = availableValue.instruction.parentBlock

SwiftCompilerSources/Sources/Optimizer/Utilities/SSAUpdater.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import OptimizerBridging
1717
struct SSAUpdater<Context: MutatingContext> {
1818
let context: Context
1919

20-
init(type: Type, ownership: Ownership, _ context: Context) {
20+
init(function: Function, type: Type, ownership: Ownership,
21+
_ context: Context) {
2122
self.context = context
22-
context._bridged.SSAUpdater_initialize(type.bridged, ownership._bridged)
23+
context._bridged.SSAUpdater_initialize(function.bridged, type.bridged,
24+
ownership._bridged)
2325
}
2426

2527
mutating func addAvailableValue(_ value: Value, in block: BasicBlock) {

docs/Android.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ To follow along with this guide, you'll need:
3636
instructions in the Swift project README.
3737
2. The latest build of the Swift compiler for your Linux distro, available at
3838
https://www.swift.org/download/ or sometimes your distro package manager.
39-
3. The last version of the Android LTS NDK (r25c, the latest LTS NDK 26 at the
40-
time of this writing doesn't work yet), available to download here:
39+
3. The latest version of the Android LTS NDK (r26c at the time of this writing),
40+
available to download here:
4141
https://developer.android.com/ndk/downloads
4242
4. An Android device with remote debugging enabled or the emulator. We require
4343
remote debugging in order to deploy built stdlib products to the device. You
@@ -54,7 +54,7 @@ and the prebuilt Swift toolchain (add --skip-early-swift-driver if you already
5454
have a Swift toolchain in your path):
5555

5656
```
57-
$ NDK_PATH=path/to/android-ndk-r25c
57+
$ NDK_PATH=path/to/android-ndk-r26c
5858
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2023-09-30-a-ubuntu20.04/usr/bin
5959
$ git checkout swift-DEVELOPMENT-SNAPSHOT-2023-09-30-a
6060
$ utils/build-script \
@@ -83,7 +83,7 @@ Then use the standalone Swift stdlib from the previous step to compile a Swift
8383
source file, targeting Android:
8484

8585
```
86-
$ NDK_PATH="path/to/android-ndk-r25c"
86+
$ NDK_PATH="path/to/android-ndk-r26c"
8787
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2023-09-30-a-ubuntu20.04/usr/bin
8888
$ $SWIFT_PATH/swiftc \ # The prebuilt Swift compiler you downloaded
8989
# The location of the tools used to build Android binaries
@@ -133,7 +133,7 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libBlo
133133
In addition, you'll also need to copy the Android NDK's libc++:
134134

135135
```
136-
$ adb push /path/to/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
136+
$ adb push /path/to/android-ndk-r26c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
137137
```
138138

139139
Finally, you'll need to copy the `hello` executable you built in the
@@ -176,7 +176,7 @@ $ utils/build-script \
176176
-R \ # Build in ReleaseAssert mode.
177177
-T \ # Run all tests, including on the Android device (add --host-test to only run Android tests on the Linux host).
178178
--android \ # Build for Android.
179-
--android-ndk ~/android-ndk-r25c \ # Path to an Android NDK.
179+
--android-ndk ~/android-ndk-r26c \ # Path to an Android NDK.
180180
--android-arch aarch64 \ # Optionally specify Android architecture, alternately armv7
181181
--android-api-level 21
182182
```

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ typedef struct {
6161
size_t count;
6262
} swiftscan_dependency_set_t;
6363

64+
typedef enum {
65+
SWIFTSCAN_DIAGNOSTIC_SEVERITY_ERROR = 0,
66+
SWIFTSCAN_DIAGNOSTIC_SEVERITY_WARNING = 1,
67+
SWIFTSCAN_DIAGNOSTIC_SEVERITY_NOTE = 2,
68+
SWIFTSCAN_DIAGNOSTIC_SEVERITY_REMARK = 3
69+
} swiftscan_diagnostic_severity_t;
70+
71+
typedef struct {
72+
swiftscan_diagnostic_info_t *diagnostics;
73+
size_t count;
74+
} swiftscan_diagnostic_set_t;
75+
6476
//=== Batch Scan Input Specification --------------------------------------===//
6577

6678
/// Opaque container to a container of batch scan entry information.
@@ -92,6 +104,12 @@ SWIFTSCAN_PUBLIC swiftscan_dependency_set_t *
92104
swiftscan_dependency_graph_get_dependencies(
93105
swiftscan_dependency_graph_t result);
94106

107+
// Return value disposed of together with the dependency_graph
108+
// using `swiftscan_dependency_graph_dispose`
109+
SWIFTSCAN_PUBLIC swiftscan_diagnostic_set_t *
110+
swiftscan_dependency_graph_get_diagnostics(
111+
swiftscan_dependency_graph_t result);
112+
95113
//=== Dependency Module Info Functions ------------------------------------===//
96114

97115
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
@@ -277,6 +295,11 @@ swiftscan_batch_scan_entry_get_is_swift(swiftscan_batch_scan_entry_t entry);
277295
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
278296
swiftscan_import_set_get_imports(swiftscan_import_set_t result);
279297

298+
// Return value disposed of together with the dependency_graph
299+
// using `swiftscan_import_set_dispose`
300+
SWIFTSCAN_PUBLIC swiftscan_diagnostic_set_t *
301+
swiftscan_import_set_get_diagnostics(swiftscan_import_set_t result);
302+
280303
//=== Scanner Invocation Functions ----------------------------------------===//
281304

282305
/// Create an \c swiftscan_scan_invocation_t instance.
@@ -378,18 +401,6 @@ SWIFTSCAN_PUBLIC swiftscan_import_set_t swiftscan_import_set_create(
378401

379402

380403
//=== Scanner Diagnostics -------------------------------------------------===//
381-
typedef enum {
382-
SWIFTSCAN_DIAGNOSTIC_SEVERITY_ERROR = 0,
383-
SWIFTSCAN_DIAGNOSTIC_SEVERITY_WARNING = 1,
384-
SWIFTSCAN_DIAGNOSTIC_SEVERITY_NOTE = 2,
385-
SWIFTSCAN_DIAGNOSTIC_SEVERITY_REMARK = 3
386-
} swiftscan_diagnostic_severity_t;
387-
388-
typedef struct {
389-
swiftscan_diagnostic_info_t *diagnostics;
390-
size_t count;
391-
} swiftscan_diagnostic_set_t;
392-
393404
/// For the specified \c scanner instance, query all insofar emitted diagnostics
394405
SWIFTSCAN_PUBLIC swiftscan_diagnostic_set_t*
395406
swiftscan_scanner_diagnostics_query(swiftscan_scanner_t scanner);

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2465,7 +2465,7 @@ ERROR(spi_only_imports_not_enabled, none,
24652465
ERROR(access_level_on_import_unsupported, none,
24662466
"The access level %0 is unsupported on imports: "
24672467
"only 'public', 'package', 'internal', 'fileprivate' and 'private' "
2468-
"are unsupported",
2468+
"are accepted",
24692469
(DeclAttribute))
24702470
ERROR(access_level_conflict_with_exported,none,
24712471
"'%0' is incompatible with %1; it can only be applied to public imports",

include/swift/AST/Module.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ class ModuleDecl
846846
bool allowMissing = false);
847847

848848
/// Global conformance lookup, checks conditional requirements.
849+
/// Requires a contextualized type.
849850
///
850851
/// \param type The type for which we are computing conformance. Must not
851852
/// contain type parameters.
@@ -859,8 +860,32 @@ class ModuleDecl
859860
/// \returns An invalid conformance if the search failed, otherwise an
860861
/// abstract, concrete or pack conformance, depending on the lookup type.
861862
ProtocolConformanceRef checkConformance(Type type, ProtocolDecl *protocol,
862-
// Note: different default than above
863-
bool allowMissing = true);
863+
// Note: different default from lookupConformance
864+
bool allowMissing = true);
865+
866+
/// Global conformance lookup, checks conditional requirements.
867+
/// Accepts interface types without context. If the conformance cannot be
868+
/// definitively established without the missing context, returns \c nullopt.
869+
///
870+
/// \param type The type for which we are computing conformance. Must not
871+
/// contain type parameters.
872+
///
873+
/// \param protocol The protocol to which we are computing conformance.
874+
///
875+
/// \param allowMissing When \c true, the resulting conformance reference
876+
/// might include "missing" conformances, which are synthesized for some
877+
/// protocols as an error recovery mechanism.
878+
///
879+
/// \returns An invalid conformance if the search definitively failed. An
880+
/// abstract, concrete or pack conformance, depending on the lookup type,
881+
/// if the search succeeded. `std::nullopt` if the type could have
882+
/// conditionally conformed depending on the context of the interface types.
883+
std::optional<ProtocolConformanceRef>
884+
checkConformanceWithoutContext(Type type,
885+
ProtocolDecl *protocol,
886+
// Note: different default from lookupConformance
887+
bool allowMissing = true);
888+
864889

865890
/// Look for the conformance of the given existential type to the given
866891
/// protocol.

include/swift/AST/PlatformKind.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ StringRef platformString(PlatformKind platform);
4242
/// or None if such a platform kind does not exist.
4343
std::optional<PlatformKind> platformFromString(StringRef Name);
4444

45+
/// Safely converts the given unsigned value to a valid \c PlatformKind value or
46+
/// \c nullopt otherwise.
47+
std::optional<PlatformKind> platformFromUnsigned(unsigned value);
48+
4549
/// Returns a valid platform string that is closest to the candidate string
4650
/// based on edit distance. Returns \c None if the closest valid platform
4751
/// distance is not within a minimum threshold.

include/swift/AST/Requirement.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ enum class CheckRequirementsResult : uint8_t {
223223
/// not contain any type parameters.
224224
CheckRequirementsResult checkRequirements(ArrayRef<Requirement> requirements);
225225

226+
/// Check if each substituted requirement is satisfied. If the requirement
227+
/// contains type parameters, and the answer would depend on the context of
228+
/// those type parameters, then `nullopt` is returned.
229+
std::optional<CheckRequirementsResult>
230+
checkRequirementsWithoutContext(ArrayRef<Requirement> requirements);
231+
226232
/// Check if each requirement is satisfied after applying the given
227233
/// substitutions. The substitutions must replace all type parameters that
228234
/// appear in the requirement with concrete types or archetypes.

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ struct swiftscan_dependency_graph_s {
3030

3131
/// The complete list of modules discovered
3232
swiftscan_dependency_set_t *dependencies;
33+
34+
/// Diagnostics produced during this scan
35+
swiftscan_diagnostic_set_t *diagnostics;
3336
};
3437

3538
struct swiftscan_dependency_info_s {
@@ -192,6 +195,8 @@ struct swiftscan_batch_scan_entry_s {
192195
struct swiftscan_import_set_s {
193196
/// The complete list of imports discovered
194197
swiftscan_string_set_t *imports;
198+
/// Diagnostics produced during this import scan
199+
swiftscan_diagnostic_set_t *diagnostics;
195200
};
196201

197202
struct swiftscan_scan_invocation_s {

include/swift/DependencyScan/DependencyScanningTool.h

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,48 @@
2424
namespace swift {
2525
namespace dependencies {
2626
class DependencyScanningTool;
27+
class DependencyScanDiagnosticCollector;
28+
29+
struct ScanQueryInstance {
30+
std::unique_ptr<CompilerInstance> ScanInstance;
31+
std::unique_ptr<DependencyScanDiagnosticCollector> ScanDiagnostics;
32+
};
2733

2834
/// Diagnostic consumer that simply collects the diagnostics emitted so-far
29-
class DependencyScannerDiagnosticCollectingConsumer : public DiagnosticConsumer {
30-
public:
31-
friend DependencyScanningTool;
32-
DependencyScannerDiagnosticCollectingConsumer() {}
33-
void reset() { Diagnostics.clear(); }
35+
class DependencyScanDiagnosticCollector : public DiagnosticConsumer {
3436
private:
3537
struct ScannerDiagnosticInfo {
3638
std::string Message;
3739
llvm::SourceMgr::DiagKind Severity;
3840
};
39-
40-
void handleDiagnostic(SourceManager &SM,
41-
const DiagnosticInfo &Info) override;
42-
void addDiagnostic(SourceManager &SM, const DiagnosticInfo &Info);
41+
42+
void handleDiagnostic(SourceManager &SM, const DiagnosticInfo &Info) override;
4343
std::vector<ScannerDiagnosticInfo> Diagnostics;
44-
// FIXME: For now, we isolate access to shared state of this object
45-
// but we really should make sure that it doesn't get shared.
46-
llvm::sys::SmartMutex<true> ScanningDiagnosticConsumerStateLock;
44+
45+
protected:
46+
virtual void addDiagnostic(SourceManager &SM, const DiagnosticInfo &Info);
47+
48+
public:
49+
friend DependencyScanningTool;
50+
DependencyScanDiagnosticCollector() {}
51+
void reset() { Diagnostics.clear(); }
52+
const std::vector<ScannerDiagnosticInfo> &getDiagnostics() const {
53+
return Diagnostics;
54+
}
4755
};
4856

57+
/// Locking variant of the above diagnostic collector that guards accesses to
58+
/// its state with a lock.
59+
class LockingDependencyScanDiagnosticCollector
60+
: public DependencyScanDiagnosticCollector {
61+
private:
62+
void addDiagnostic(SourceManager &SM, const DiagnosticInfo &Info) override;
63+
llvm::sys::SmartMutex<true> ScanningDiagnosticConsumerStateLock;
64+
65+
public:
66+
friend DependencyScanningTool;
67+
LockingDependencyScanDiagnosticCollector() {}
68+
};
4969

5070
/// Given a set of arguments to a print-target-info frontend tool query, produce the
5171
/// JSON target info.
@@ -93,19 +113,19 @@ class DependencyScanningTool {
93113
/// Discard the tool's current `SharedCache` and start anew.
94114
void resetCache();
95115
/// Query diagnostics consumed so far.
96-
std::vector<DependencyScannerDiagnosticCollectingConsumer::ScannerDiagnosticInfo> getDiagnostics();
116+
std::vector<DependencyScanDiagnosticCollector::ScannerDiagnosticInfo> getDiagnostics();
97117
/// Discared the collection of diagnostics encountered so far.
98118
void resetDiagnostics();
99119

100120
/// Using the specified invocation command, instantiate a CompilerInstance
101121
/// that will be used for this scan.
102-
llvm::ErrorOr<std::unique_ptr<CompilerInstance>>
122+
llvm::ErrorOr<ScanQueryInstance>
103123
initCompilerInstanceForScan(ArrayRef<const char *> Command);
104124

105125
private:
106126
/// Using the specified invocation command, initialize the scanner instance
107127
/// for this scan. Returns the `CompilerInstance` that will be used.
108-
llvm::ErrorOr<std::unique_ptr<CompilerInstance>>
128+
llvm::ErrorOr<ScanQueryInstance>
109129
initScannerForAction(ArrayRef<const char *> Command);
110130

111131
/// Shared cache of module dependencies, re-used by individual full-scan queries
@@ -120,7 +140,7 @@ class DependencyScanningTool {
120140
llvm::sys::SmartMutex<true> DependencyScanningToolStateLock;
121141

122142
/// A shared consumer that accumulates encountered diagnostics.
123-
DependencyScannerDiagnosticCollectingConsumer CDC;
143+
LockingDependencyScanDiagnosticCollector CDC;
124144
llvm::BumpPtrAllocator Alloc;
125145
llvm::StringSaver Saver;
126146
};

include/swift/DependencyScan/ScanDependencies.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ModuleDependenciesCache;
3030
class SwiftDependencyScanningService;
3131

3232
namespace dependencies {
33+
class DependencyScanDiagnosticCollector;
3334

3435
using CompilerArgInstanceCacheMap =
3536
llvm::StringMap<std::tuple<std::unique_ptr<CompilerInstance>,
@@ -59,16 +60,19 @@ bool batchScanDependencies(CompilerInstance &instance,
5960
/// Scans the dependencies of the main module of \c instance.
6061
llvm::ErrorOr<swiftscan_dependency_graph_t>
6162
performModuleScan(CompilerInstance &instance,
63+
DependencyScanDiagnosticCollector *diagnostics,
6264
ModuleDependenciesCache &cache);
6365

6466
/// Scans the main module of \c instance for all direct module imports
6567
llvm::ErrorOr<swiftscan_import_set_t>
6668
performModulePrescan(CompilerInstance &instance,
69+
DependencyScanDiagnosticCollector *diagnostics,
6770
ModuleDependenciesCache &cache);
6871

6972
/// Batch scan the dependencies for modules specified in \c batchInputFile.
7073
std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t>>
7174
performBatchModuleScan(CompilerInstance &invocationInstance,
75+
DependencyScanDiagnosticCollector *diagnostics,
7276
ModuleDependenciesCache &invocationCache,
7377
CompilerArgInstanceCacheMap *versionedPCMInstanceCache,
7478
llvm::StringSaver &saver,

include/swift/SIL/AbstractionPattern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ class AbstractionPattern {
10141014

10151015
bool requiresClass() const;
10161016
LayoutConstraint getLayoutConstraint() const;
1017+
bool isNoncopyable(CanType substTy) const;
10171018

10181019
/// Return the Swift type which provides structure for this
10191020
/// abstraction pattern.

include/swift/SIL/SILBuilder.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ class SILBuilder {
200200
assert(F && "cannot create this instruction without a function context");
201201
return *F;
202202
}
203-
203+
204+
/// If this SILBuilder is inserting into a function, return that function. If
205+
/// we are inserting into a global, this returns nullptr.
206+
SILFunction *maybeGetFunction() const { return F; }
207+
204208
bool isInsertingIntoGlobal() const { return F == nullptr; }
205209

206210
TypeExpansionContext getTypeExpansionContext() const {

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ SILCloner<ImplClass>::getMappedValue(SILValue Value) {
593593
if (auto *U = dyn_cast<SILUndef>(Value)) {
594594
auto type = getOpType(U->getType());
595595
ValueBase *undef =
596-
(type == U->getType() ? U : SILUndef::get(type, Builder.getFunction()));
596+
(type == U->getType() ? U : SILUndef::get(Builder.getFunction(), type));
597597
return SILValue(undef);
598598
}
599599

0 commit comments

Comments
 (0)