Skip to content

Commit aa76845

Browse files
authored
Merge branch 'main' into block-list
2 parents 2c2431e + eef39a9 commit aa76845

File tree

197 files changed

+2504
-1098
lines changed

Some content is hidden

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

197 files changed

+2504
-1098
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
44

55
## Swift 5.9
66

7+
* Marking stored properties as unavailable with `@available` has been banned,
8+
closing an unintentional soundness hole that had allowed arbitrary
9+
unavailable code to run and unavailable type metadata to be used at runtime:
10+
11+
```swift
12+
@available(*, unavailable)
13+
struct Unavailable {
14+
init() {
15+
print("Unavailable.init()")
16+
}
17+
}
18+
19+
struct S {
20+
@available(*, unavailable)
21+
var x = Unavailable()
22+
}
23+
24+
_ = S() // prints "Unavailable.init()"
25+
```
26+
27+
Marking `deinit` as unavailable has also been banned for similar reasons.
28+
729
* [SE-0366][]:
830

931
The lifetime of a local variable value can be explicitly ended using the
File renamed without changes.

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ class SwiftDeclCollector: public VisibleDeclConsumer {
784784
void deSerialize(StringRef Filename);
785785

786786
// Serialize the content of all roots to a given file using JSON format.
787-
void serialize(StringRef Filename);
788-
static void serialize(StringRef Filename, SDKNode *Root, PayLoad otherInfo);
787+
void serialize(llvm::raw_ostream &os);
788+
static void serialize(llvm::raw_ostream &os, SDKNode *Root, PayLoad otherInfo);
789789

790790
// After collecting decls, either from imported modules or from a previously
791791
// serialized JSON file, using this function to get the root of the SDK.
@@ -835,14 +835,15 @@ SDKNodeRoot *getSDKNodeRoot(SDKContext &SDKCtx,
835835

836836
SDKNodeRoot *getEmptySDKNodeRoot(SDKContext &SDKCtx);
837837

838-
void dumpSDKRoot(SDKNodeRoot *Root, PayLoad load, StringRef OutputFile);
839-
void dumpSDKRoot(SDKNodeRoot *Root, StringRef OutputFile);
838+
void dumpSDKRoot(SDKNodeRoot *Root, PayLoad load, llvm::raw_ostream &os);
839+
void dumpSDKRoot(SDKNodeRoot *Root, llvm::raw_ostream &os);
840840

841841
int dumpSDKContent(const CompilerInvocation &InitInvoke,
842842
const llvm::StringSet<> &ModuleNames,
843-
StringRef OutputFile, CheckerOptions Opts);
843+
llvm::raw_ostream &os, CheckerOptions Opts);
844844

845-
void dumpModuleContent(ModuleDecl *MD, StringRef OutputFile, bool ABI, bool Empty);
845+
void dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os, bool ABI,
846+
bool Empty);
846847

847848
/// Mostly for testing purposes, this function de-serializes the SDK dump in
848849
/// dumpPath and re-serialize them to OutputPath. If the tool performs correctly,

include/swift/AST/ASTContext.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "llvm/ADT/TinyPtrVector.h"
4646
#include "llvm/Support/Allocator.h"
4747
#include "llvm/Support/DataTypes.h"
48+
#include "llvm/Support/VirtualOutputBackend.h"
4849
#include <functional>
4950
#include <memory>
5051
#include <utility>
@@ -232,6 +233,7 @@ class ASTContext final {
232233
ClangImporterOptions &ClangImporterOpts,
233234
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
234235
SourceManager &SourceMgr, DiagnosticEngine &Diags,
236+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr,
235237
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback = {});
236238

237239
public:
@@ -249,6 +251,7 @@ class ASTContext final {
249251
ClangImporterOptions &ClangImporterOpts,
250252
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
251253
SourceManager &SourceMgr, DiagnosticEngine &Diags,
254+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr,
252255
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback = {});
253256
~ASTContext();
254257

@@ -282,6 +285,9 @@ class ASTContext final {
282285
/// Diags - The diagnostics engine.
283286
DiagnosticEngine &Diags;
284287

288+
/// OutputBackend for writing outputs.
289+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend;
290+
285291
/// If the shared pointer is not a \c nullptr and the pointee is \c true,
286292
/// all operations working on this ASTContext should be aborted at the next
287293
/// possible opportunity.
@@ -894,8 +900,10 @@ class ASTContext final {
894900
/// Get the back-deployed availability for concurrency.
895901
AvailabilityContext getBackDeployedConcurrencyAvailability();
896902

897-
/// The the availability since when distributed actors are able to have custom executors.
898-
AvailabilityContext getConcurrencyDistributedActorWithCustomExecutorAvailability();
903+
/// The the availability since when distributed actors are able to have custom
904+
/// executors.
905+
AvailabilityContext
906+
getConcurrencyDistributedActorWithCustomExecutorAvailability();
899907

900908
/// Get the runtime availability of support for differentiation.
901909
AvailabilityContext getDifferentiationAvailability();
@@ -1519,6 +1527,18 @@ class ASTContext final {
15191527

15201528
const llvm::StringSet<> &getLoadedPluginLibraryPaths() const;
15211529

1530+
/// Get the output backend. The output backend needs to be initialized via
1531+
/// constructor or `setOutputBackend`.
1532+
llvm::vfs::OutputBackend &getOutputBackend() const {
1533+
assert(OutputBackend && "OutputBackend is not setup");
1534+
return *OutputBackend;
1535+
}
1536+
/// Set output backend for virtualized outputs.
1537+
void setOutputBackend(
1538+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend) {
1539+
OutputBackend = std::move(OutBackend);
1540+
}
1541+
15221542
private:
15231543
friend Decl;
15241544

include/swift/AST/ASTScope.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class GenericContext;
7878
class DeclName;
7979
class StmtConditionElement;
8080

81+
namespace Lowering {
82+
class SILGenFunction;
83+
}
84+
8185
namespace ast_scope {
8286
class ASTScopeImpl;
8387
class GenericTypeOrExtensionScope;
@@ -129,6 +133,7 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
129133
friend class IterableTypeBodyPortion;
130134
friend class ScopeCreator;
131135
friend class ASTSourceFileScope;
136+
friend class Lowering::SILGenFunction;
132137

133138
#pragma mark - tree state
134139
protected:
@@ -273,6 +278,10 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
273278
static std::pair<CaseStmt *, CaseStmt *>
274279
lookupFallthroughSourceAndDest(SourceFile *sourceFile, SourceLoc loc);
275280

281+
/// Scopes that cannot bind variables may set this to true to create more
282+
/// compact scope tree in the debug info.
283+
virtual bool ignoreInDebugInfo() const { return false; }
284+
276285
#pragma mark - - lookup- starting point
277286
private:
278287
static const ASTScopeImpl *findStartingScopeForLookup(SourceFile *,
@@ -777,6 +786,7 @@ class ParameterListScope final : public ASTScopeImpl {
777786
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
778787

779788
NullablePtr<const void> addressForPrinting() const override { return params; }
789+
bool ignoreInDebugInfo() const override { return true; }
780790
};
781791

782792
/// Body of functions, methods, constructors, destructors and accessors.
@@ -799,6 +809,7 @@ class FunctionBodyScope : public ASTScopeImpl {
799809
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
800810
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
801811
Decl *getDecl() const { return decl; }
812+
bool ignoreInDebugInfo() const override { return true; }
802813

803814
protected:
804815
bool lookupLocalsOrMembers(DeclConsumer) const override;
@@ -825,6 +836,7 @@ class DefaultArgumentInitializerScope final : public ASTScopeImpl {
825836
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
826837
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
827838
Decl *getDecl() const { return decl; }
839+
bool ignoreInDebugInfo() const override { return true; }
828840
};
829841

830842
/// Consider:
@@ -858,7 +870,7 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
858870
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
859871
return attr;
860872
}
861-
873+
bool ignoreInDebugInfo() const override { return true; }
862874
private:
863875
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
864876
};
@@ -972,6 +984,7 @@ class ConditionalClauseInitializerScope final : public ASTScopeImpl {
972984
SourceRange
973985
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
974986
std::string getClassName() const override;
987+
bool ignoreInDebugInfo() const override { return true; }
975988

976989
private:
977990
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
@@ -1049,6 +1062,7 @@ class ClosureParametersScope final : public ASTScopeImpl {
10491062
}
10501063
NullablePtr<Expr> getExprIfAny() const override { return closureExpr; }
10511064
Expr *getExpr() const { return closureExpr; }
1065+
bool ignoreInDebugInfo() const override { return true; }
10521066

10531067
protected:
10541068
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;

include/swift/AST/AbstractSourceFileDepGraphFactory.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/Decl.h"
1717
#include "swift/AST/DeclContext.h"
1818
#include "swift/AST/FineGrainedDependencies.h"
19+
#include "llvm/Support/VirtualOutputBackend.h"
1920

2021
namespace swift {
2122
class DiagnosticEngine;
@@ -39,6 +40,9 @@ class AbstractSourceFileDepGraphFactory {
3940

4041
DiagnosticEngine &diags;
4142

43+
/// OutputBackend.
44+
llvm::vfs::OutputBackend &backend;
45+
4246
/// Graph under construction
4347
SourceFileDepGraph g;
4448

@@ -49,7 +53,8 @@ class AbstractSourceFileDepGraphFactory {
4953
StringRef swiftDeps,
5054
Fingerprint fileFingerprint,
5155
bool emitDotFileAfterConstruction,
52-
DiagnosticEngine &diags);
56+
DiagnosticEngine &diags,
57+
llvm::vfs::OutputBackend &outputBackend);
5358

5459
virtual ~AbstractSourceFileDepGraphFactory() = default;
5560

include/swift/AST/Availability.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ class VersionRange {
3939
// x.y.x: all versions greater than or equal to x.y.z
4040

4141
enum class ExtremalRange { Empty, All };
42-
42+
4343
// A version range is either an extremal value (Empty, All) or
4444
// a single version tuple value representing the lower end point x.y.z of a
4545
// range [x.y.z, +Inf).
4646
union {
4747
llvm::VersionTuple LowerEndpoint;
4848
ExtremalRange ExtremalValue;
4949
};
50-
50+
5151
unsigned HasLowerEndpoint : 1;
5252

5353
public:
@@ -86,7 +86,7 @@ class VersionRange {
8686
bool isContainedIn(const VersionRange &Other) const {
8787
if (isEmpty() || Other.isAll())
8888
return true;
89-
89+
9090
if (isAll() || Other.isEmpty())
9191
return false;
9292

@@ -326,17 +326,15 @@ class AvailabilityContext {
326326
OSVersion.unionWith(other.getOSVersion());
327327
}
328328

329-
bool isAvailableAsSPI() const {
330-
return SPI && *SPI;
331-
}
329+
bool isAvailableAsSPI() const { return SPI && *SPI; }
332330

333331
/// Returns a representation of this range as a string for debugging purposes.
334332
std::string getAsString() const {
335-
return "AvailabilityContext(" + OSVersion.getAsString() + (isAvailableAsSPI() ? ", spi" : "") + ")";
333+
return "AvailabilityContext(" + OSVersion.getAsString() +
334+
(isAvailableAsSPI() ? ", spi" : "") + ")";
336335
}
337336
};
338337

339-
340338
class AvailabilityInference {
341339
public:
342340
/// Returns the decl that should be considered the parent decl of the given
@@ -348,8 +346,8 @@ class AvailabilityInference {
348346
/// to ToDecl.
349347
static void
350348
applyInferredAvailableAttrs(Decl *ToDecl,
351-
ArrayRef<const Decl *> InferredFromDecls,
352-
ASTContext &Context);
349+
ArrayRef<const Decl *> InferredFromDecls,
350+
ASTContext &Context);
353351

354352
static AvailabilityContext inferForType(Type t);
355353

@@ -376,8 +374,7 @@ class AvailabilityInference {
376374
ASTContext &C);
377375

378376
static AvailabilityContext
379-
annotatedAvailableRangeForAttr(const SpecializeAttr* attr, ASTContext &ctx);
380-
377+
annotatedAvailableRangeForAttr(const SpecializeAttr *attr, ASTContext &ctx);
381378
};
382379

383380
} // end namespace swift

include/swift/AST/DiagnosticsCommon.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ ERROR(not_implemented,none,
2929
ERROR(error_opening_output,none,
3030
"error opening '%0' for output: %1", (StringRef, StringRef))
3131

32+
ERROR(error_closing_output,none,
33+
"error closing '%0' for output: %1", (StringRef, StringRef))
34+
3235
ERROR(cannot_find_group_info_file,none,
3336
"cannot find group info file at path: '%0'", (StringRef))
3437

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ REMARK(interface_file_backup_used,none,
475475

476476
WARNING(warn_flag_deprecated,none, "flag '%0' is deprecated", (StringRef))
477477

478+
// Output deterministic check
479+
ERROR(error_nondeterministic_output,none,
480+
"output file '%0' is not deterministic: hash value '%1' vs '%2' between two compilations",
481+
(StringRef, StringRef, StringRef))
482+
ERROR(error_output_missing,none,
483+
"output file '%0' is missing from %select{first|second}1 compilation for deterministic check",
484+
(StringRef, /*SecondRun=*/bool))
485+
REMARK(matching_output_produced,none,
486+
"produced matching output file '%0' for deterministic check: hash '%1'", (StringRef, StringRef))
487+
478488
// Dependency Verifier Diagnostics
479489
ERROR(missing_member_dependency,none,
480490
"expected "

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,8 +2049,8 @@ ERROR(macro_role_attr_expected_kind,PointsToFirstBadToken,
20492049
"expected %select{a freestanding|an attached}0 macro role such as "
20502050
"%select{'expression'|'accessor'}0", (bool))
20512051
ERROR(macro_role_syntax_mismatch,PointsToFirstBadToken,
2052-
"expected %select{a freestanding|an attached}0 macro cannot have "
2053-
"the %1 role", (bool, Identifier))
2052+
"%select{a freestanding|an attached}0 macro cannot have the %1 role",
2053+
(bool, Identifier))
20542054
ERROR(macro_attribute_unknown_label,PointsToFirstBadToken,
20552055
"@%select{freestanding|attached}0 has no argument with label %1",
20562056
(bool, Identifier))

include/swift/AST/DiagnosticsSema.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6133,10 +6133,18 @@ ERROR(availability_global_script_no_potential,
61336133
none, "global variable cannot be marked potentially "
61346134
"unavailable with '@available' in script mode", ())
61356135

6136+
ERROR(availability_global_script_no_unavailable,
6137+
none, "global variable cannot be marked unavailable "
6138+
"with '@available' in script mode", ())
6139+
61366140
ERROR(availability_stored_property_no_potential,
61376141
none, "stored properties cannot be marked potentially unavailable with "
61386142
"'@available'", ())
61396143

6144+
ERROR(availability_stored_property_no_unavailable,
6145+
none, "stored properties cannot be marked unavailable with '@available'",
6146+
())
6147+
61406148
ERROR(availability_enum_element_no_potential,
61416149
none, "enum cases with associated values cannot be marked potentially unavailable with "
61426150
"'@available'", ())
@@ -7032,6 +7040,11 @@ ERROR(invalid_macro_introduced_name,none,
70327040
ERROR(global_freestanding_macro_script,none,
70337041
"global freestanding macros not yet supported in script mode",
70347042
())
7043+
ERROR(invalid_macro_role_for_macro_syntax,none,
7044+
"invalid macro role for %{a freestanding|an attached}0 macro",
7045+
(unsigned))
7046+
ERROR(macro_cannot_introduce_names,none,
7047+
"'%0' macros are not allowed to introduce names", (StringRef))
70357048

70367049
//------------------------------------------------------------------------------
70377050
// MARK: Move Only Errors

0 commit comments

Comments
 (0)