Skip to content

Commit 9aa1772

Browse files
authored
Merge pull request #69224 from etcwilde/rebranch
2 parents 521ba9d + 6260970 commit 9aa1772

File tree

93 files changed

+2107
-764
lines changed

Some content is hidden

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

93 files changed

+2107
-764
lines changed

docs/Android.md

Lines changed: 2 additions & 2 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 latest version of the Android LTS NDK (r25c at the time of this writing),
40-
available to download here:
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:
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

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,6 @@ typedef struct swiftscan_cas_options_s *swiftscan_cas_options_t;
437437
/// ActionCache.
438438
typedef struct swiftscan_cas_s *swiftscan_cas_t;
439439

440-
/// Enum types for output types for cache key computation.
441-
/// TODO: complete the list.
442-
typedef enum {
443-
SWIFTSCAN_OUTPUT_TYPE_OBJECT = 0,
444-
SWIFTSCAN_OUTPUT_TYPE_SWIFTMODULE = 1,
445-
SWIFTSCAN_OUTPUT_TYPE_SWIFTINTERFACE = 2,
446-
SWIFTSCAN_OUTPUT_TYPE_SWIFTPRIVATEINTERFACE = 3,
447-
SWIFTSCAN_OUTPUT_TYPE_CLANG_MODULE = 4,
448-
SWIFTSCAN_OUTPUT_TYPE_CLANG_PCH = 5
449-
} swiftscan_output_kind_t;
450-
451440
/// Create a \c CASOptions for creating CAS inside scanner specified.
452441
SWIFTSCAN_PUBLIC swiftscan_cas_options_t swiftscan_cas_options_create(void);
453442

@@ -489,13 +478,15 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
489478
swiftscan_cas_store(swiftscan_cas_t cas, uint8_t *data, unsigned size,
490479
swiftscan_string_ref_t *error);
491480

492-
/// Compute \c CacheKey for output of \c kind from the compiler invocation \c
493-
/// argc and \c argv with \c input. Return \c CacheKey as string.
481+
/// Compute \c CacheKey for the outputs of a primary input file from a compiler
482+
/// invocation with command-line \c argc and \c argv. When primary input file
483+
/// is not available for compilation, e.g., using WMO, primary file is the first
484+
/// swift input on the command-line by convention. Return \c CacheKey as string.
494485
/// If error happens, the error message is returned via `error` parameter, and
495486
/// caller needs to free the error message via `swiftscan_string_dispose`.
496-
SWIFTSCAN_PUBLIC swiftscan_string_ref_t swiftscan_compute_cache_key(
497-
swiftscan_cas_t cas, int argc, const char **argv, const char *input,
498-
swiftscan_output_kind_t kind, swiftscan_string_ref_t *error);
487+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
488+
swiftscan_cache_compute_key(swiftscan_cas_t cas, int argc, const char **argv,
489+
const char *input, swiftscan_string_ref_t *error);
499490

500491
//===----------------------------------------------------------------------===//
501492

include/swift/AST/ASTScope.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define SWIFT_AST_AST_SCOPE_H
3030

3131
#include "swift/AST/ASTNode.h"
32+
#include "swift/AST/CatchNode.h"
3233
#include "swift/AST/NameLookup.h"
3334
#include "swift/AST/SimpleRequest.h"
3435
#include "swift/Basic/Compiler.h"
@@ -85,6 +86,7 @@ class SILGenFunction;
8586

8687
namespace ast_scope {
8788
class ASTScopeImpl;
89+
class BraceStmtScope;
8890
class GenericTypeOrExtensionScope;
8991
class IterableTypeScope;
9092
class TypeAliasScope;
@@ -211,6 +213,7 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
211213
#pragma mark common queries
212214
public:
213215
virtual NullablePtr<AbstractClosureExpr> getClosureIfClosureScope() const;
216+
virtual NullablePtr<const BraceStmtScope> getAsBraceStmtScope() const;
214217
virtual ASTContext &getASTContext() const;
215218
virtual NullablePtr<Decl> getDeclIfAny() const { return nullptr; };
216219
virtual NullablePtr<Stmt> getStmtIfAny() const { return nullptr; };
@@ -287,10 +290,18 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
287290
SourceFile *sourceFile, SourceLoc loc,
288291
llvm::function_ref<bool(ASTScope::PotentialMacro)> consume);
289292

293+
static CatchNode lookupCatchNode(ModuleDecl *module, SourceLoc loc);
294+
290295
/// Scopes that cannot bind variables may set this to true to create more
291296
/// compact scope tree in the debug info.
292297
virtual bool ignoreInDebugInfo() const { return false; }
293298

299+
/// If this scope node represents a potential catch node, return body the
300+
/// AST node describing the catch (a function, closure, or do...catch) and
301+
/// the node of it's "body", i.e., the brace statement from which errors
302+
/// thrown will be caught by that node.
303+
virtual std::pair<CatchNode, const BraceStmtScope *> getCatchNodeBody() const;
304+
294305
#pragma mark - - lookup- starting point
295306
private:
296307
static const ASTScopeImpl *findStartingScopeForLookup(SourceFile *,
@@ -824,6 +835,8 @@ class FunctionBodyScope : public ASTScopeImpl {
824835
Decl *getDecl() const { return decl; }
825836
bool ignoreInDebugInfo() const override { return true; }
826837

838+
std::pair<CatchNode, const BraceStmtScope *> getCatchNodeBody() const override;
839+
827840
protected:
828841
bool lookupLocalsOrMembers(DeclConsumer) const override;
829842

@@ -1069,6 +1082,8 @@ class ClosureParametersScope final : public ASTScopeImpl {
10691082
NullablePtr<AbstractClosureExpr> getClosureIfClosureScope() const override {
10701083
return closureExpr;
10711084
}
1085+
std::pair<CatchNode, const BraceStmtScope *> getCatchNodeBody() const override;
1086+
10721087
NullablePtr<Expr> getExprIfAny() const override { return closureExpr; }
10731088
Expr *getExpr() const { return closureExpr; }
10741089
bool ignoreInDebugInfo() const override { return true; }
@@ -1440,6 +1455,8 @@ class DoCatchStmtScope final : public AbstractStmtScope {
14401455
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
14411456

14421457
public:
1458+
std::pair<CatchNode, const BraceStmtScope *> getCatchNodeBody() const override;
1459+
14431460
std::string getClassName() const override;
14441461
Stmt *getStmt() const override { return stmt; }
14451462
};
@@ -1648,6 +1665,8 @@ class BraceStmtScope final : public AbstractStmtScope {
16481665
NullablePtr<AbstractClosureExpr> parentClosureIfAny() const; // public??
16491666
Stmt *getStmt() const override { return stmt; }
16501667

1668+
NullablePtr<const BraceStmtScope> getAsBraceStmtScope() const override;
1669+
16511670
protected:
16521671
bool lookupLocalsOrMembers(DeclConsumer) const override;
16531672
};

include/swift/AST/CatchNode.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===--- CatchNode.h - An AST node that catches errors -----------*- C++-*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_AST_CATCHNODE_H
14+
#define SWIFT_AST_CATCHNODE_H
15+
16+
#include "llvm/ADT/Optional.h"
17+
#include "llvm/ADT/PointerUnion.h"
18+
#include "swift/AST/Decl.h"
19+
#include "swift/AST/Expr.h"
20+
#include "swift/AST/Stmt.h"
21+
22+
namespace swift {
23+
24+
/// An AST node that represents a point where a thrown error can be caught and
25+
/// or rethrown, which includes functions do...catch statements.
26+
class CatchNode: public llvm::PointerUnion<
27+
AbstractFunctionDecl *, AbstractClosureExpr *, DoCatchStmt *
28+
> {
29+
public:
30+
using PointerUnion::PointerUnion;
31+
32+
/// Determine the thrown error type within the region of this catch node
33+
/// where it will catch (and possibly rethrow) errors. All of the errors
34+
/// thrown from within that region will be converted to this error type.
35+
///
36+
/// Returns the thrown error type for a throwing context, or \c llvm::None
37+
/// if this is a non-throwing context.
38+
llvm::Optional<Type> getThrownErrorTypeInContext(ASTContext &ctx) const;
39+
};
40+
41+
} // end namespace swift
42+
43+
#endif // SWIFT_AST_CATCHNODE_H

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ ERROR(error_caching_no_cas_fs, none,
494494
ERROR(error_prefix_mapping, none, "cannot create scanner prefix mapping: '%0'", (StringRef))
495495

496496
REMARK(replay_output, none, "replay output file '%0': key '%1'", (StringRef, StringRef))
497-
REMARK(output_cache_miss, none, "cache miss output file '%0': key '%1'", (StringRef, StringRef))
497+
REMARK(output_cache_miss, none, "cache miss for input file '%0': key '%1'", (StringRef, StringRef))
498498

499499
// CAS related diagnostics
500500
ERROR(error_invalid_cas_id, none, "invalid CASID '%0' (%1)", (StringRef, StringRef))
@@ -536,9 +536,6 @@ REMARK(warning_in_access_notes_file,none,
536536
"ignored invalid content in access notes file: %0",
537537
(StringRef))
538538

539-
WARNING(compiler_plugin_not_loaded,none,
540-
"compiler plugin not loaded: %0; loader error: %1", (StringRef, StringRef))
541-
542539
ERROR(dont_enable_interop_and_compat,none,
543540
"do not pass both '-enable-experimental-cxx-interop' and "
544541
"'-cxx-interoperability-mode'; remove '-enable-experimental-cxx-interop'", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5304,6 +5304,9 @@ ERROR(local_function_executed_concurrently,none,
53045304
ERROR(sendable_isolated_sync_function,none,
53055305
"%0 synchronous %kind1 cannot be marked as '@Sendable'",
53065306
(ActorIsolation, const ValueDecl *))
5307+
ERROR(nonsendable_instance_method,none,
5308+
"instance methods of non-Sendable types cannot be marked as '@Sendable'",
5309+
())
53075310
ERROR(concurrent_access_of_local_capture,none,
53085311
"%select{mutation of|reference to}0 captured %kind1 in "
53095312
"concurrently-executing code",
@@ -7312,7 +7315,7 @@ ERROR(macro_undefined,PointsToFirstBadToken,
73127315
"no macro named %0", (Identifier))
73137316
ERROR(external_macro_not_found,none,
73147317
"external macro implementation type '%0.%1' could not be found for "
7315-
"macro %2", (StringRef, StringRef, DeclName))
7318+
"macro %2; %3", (StringRef, StringRef, DeclName, StringRef))
73167319
ERROR(macro_must_be_defined,none,
73177320
"macro %0 requires a definition", (DeclName))
73187321
ERROR(external_macro_outside_macro_definition,none,

include/swift/AST/MacroDefinition.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef SWIFT_AST_MACRO_DEFINITION_H
1919
#define SWIFT_AST_MACRO_DEFINITION_H
2020

21+
#include "swift/Basic/StringExtras.h"
2122
#include "llvm/ADT/PointerUnion.h"
2223

2324
namespace swift {
@@ -26,14 +27,25 @@ class ASTContext;
2627

2728
/// A reference to an external macro definition that is understood by ASTGen.
2829
struct ExternalMacroDefinition {
29-
enum class PluginKind {
30+
enum class PluginKind : int8_t {
3031
InProcess = 0,
3132
Executable = 1,
33+
Error = -1,
3234
};
3335
PluginKind kind;
3436
/// ASTGen's notion of an macro definition, which is opaque to the C++ part
35-
/// of the compiler.
36-
void *opaqueHandle = nullptr;
37+
/// of the compiler. If 'kind' is 'PluginKind::Error', this is a C-string to
38+
/// the error message
39+
const void *opaqueHandle = nullptr;
40+
41+
static ExternalMacroDefinition error(NullTerminatedStringRef message) {
42+
return ExternalMacroDefinition{PluginKind::Error,
43+
static_cast<const void *>(message.data())};
44+
}
45+
bool isError() const { return kind == PluginKind::Error; }
46+
NullTerminatedStringRef getErrorMessage() const {
47+
return static_cast<const char *>(opaqueHandle);
48+
}
3749
};
3850

3951
/// A reference to an external macro.

include/swift/AST/NameLookup.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_AST_NAME_LOOKUP_H
1919

2020
#include "swift/AST/ASTVisitor.h"
21+
#include "swift/AST/CatchNode.h"
2122
#include "swift/AST/GenericSignature.h"
2223
#include "swift/AST/Identifier.h"
2324
#include "swift/AST/Module.h"
@@ -833,6 +834,25 @@ class ASTScope : public ASTAllocated<ASTScope> {
833834
SourceFile *sourceFile, SourceLoc loc,
834835
llvm::function_ref<bool(PotentialMacro macro)> consume);
835836

837+
/// Look up the scope tree for the nearest point at which an error thrown from
838+
/// this location can be caught or rethrown.
839+
///
840+
/// For example, given this code:
841+
///
842+
/// \code
843+
/// func f() throws {
844+
/// do {
845+
/// try g() // A
846+
/// } catch {
847+
/// throw ErrorWrapper(error) // B
848+
/// }
849+
/// }
850+
/// \endcode
851+
///
852+
/// At the point marked A, the catch node is the enclosing do...catch
853+
/// statement. At the point marked B, the catch node is the function itself.
854+
static CatchNode lookupCatchNode(ModuleDecl *module, SourceLoc loc);
855+
836856
SWIFT_DEBUG_DUMP;
837857
void print(llvm::raw_ostream &) const;
838858
void dumpOneScopeMapLocation(std::pair<unsigned, unsigned>);

include/swift/AST/PluginLoader.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,15 @@ class PluginLoader {
7676
/// returns a nullptr.
7777
/// NOTE: This method is idempotent. If the plugin is already loaded, the same
7878
/// instance is simply returned.
79-
LoadedLibraryPlugin *loadLibraryPlugin(llvm::StringRef path);
79+
llvm::Expected<LoadedLibraryPlugin *> loadLibraryPlugin(llvm::StringRef path);
8080

8181
/// Launch the specified executable plugin path resolving the path with the
8282
/// current VFS. If it fails to load the plugin, a diagnostic is emitted, and
8383
/// returns a nullptr.
8484
/// NOTE: This method is idempotent. If the plugin is already loaded, the same
8585
/// instance is simply returned.
86-
LoadedExecutablePlugin *loadExecutablePlugin(llvm::StringRef path);
86+
llvm::Expected<LoadedExecutablePlugin *>
87+
loadExecutablePlugin(llvm::StringRef path);
8788
};
8889

8990
} // namespace swift

include/swift/AST/PluginRegistry.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ class LoadedLibraryPlugin {
3333
/// Cache of loaded symbols.
3434
llvm::StringMap<void *> resolvedSymbols;
3535

36+
/// Path to the plugin library.
37+
const std::string LibraryPath;
38+
3639
public:
37-
LoadedLibraryPlugin(void *handle) : handle(handle) {}
40+
LoadedLibraryPlugin(void *handle, StringRef path)
41+
: handle(handle), LibraryPath(path) {}
3842

3943
/// Finds the address of the given symbol within the library.
4044
void *getAddressOfSymbol(const char *symbolName);
45+
46+
NullTerminatedStringRef getLibraryPath() {
47+
return {LibraryPath.c_str(), LibraryPath.size()};
48+
}
4149
};
4250

4351
/// Represent a "resolved" executable plugin.

0 commit comments

Comments
 (0)