Skip to content

Commit 8ffd8ef

Browse files
authored
Merge branch 'main' into es-check-exp
2 parents 30669fc + 7cbe2cf commit 8ffd8ef

File tree

197 files changed

+2700
-920
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

+2700
-920
lines changed

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
# CHANGELOG
22

3-
> **Note**\
3+
> [!NOTE]
44
> This is in reverse chronological order, so newer entries are added to the top.
55
66
## Swift 6.0
7+
* [SE-0352][]:
8+
The Swift 6 language mode will open existential values with
9+
"self-conforming" types (such as `any Error` or `@objc` protocols)
10+
passed to generic functions. For example:
11+
12+
```swift
13+
func takeError<E: Error>(_ error: E) { }
14+
15+
func passError(error: any Error) {
16+
takeError(error) // Swift 5 does not open `any Error`, Swift 6 does
17+
}
18+
```
19+
20+
This behavior can be enabled prior to the Swift 6 language mode
21+
using the upcoming language feature `ImplicitOpenExistentials`.
22+
723
* [SE-0422][]:
824
Non-built-in expression macros can now be used as default arguments that
925
expand at each call site. For example, a custom `#CurrentFile` macro used as
@@ -285,6 +301,8 @@ concurrency checking.
285301

286302
## Swift 5.9.2
287303

304+
### 2023-12-11 (Xcode 15.1)
305+
288306
* [SE-0407][]:
289307

290308
Member macros can specify a list of protocols via the `conformances` argument to the macro role. The macro implementation will be provided with those protocols that are listed but have not already been implemented by the type to which the member macro is attached, in the same manner as extension macros.
@@ -10133,6 +10151,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
1013310151
[SE-0417]: https://github.com/apple/swift-evolution/blob/main/proposals/0417-task-executor-preference.md
1013410152
[SE-0412]: https://github.com/apple/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md
1013510153
[SE-0413]: https://github.com/apple/swift-evolution/blob/main/proposals/0413-typed-throws.md
10154+
[SE-0422]: https://github.com/apple/swift-evolution/blob/main/proposals/0422-caller-side-default-argument-macro-expression.md
1013610155
[#64927]: <https://github.com/apple/swift/issues/64927>
1013710156
[#42697]: <https://github.com/apple/swift/issues/42697>
1013810157
[#42728]: <https://github.com/apple/swift/issues/42728>

docs/LSANFailureSymbolication.md

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
1. Clone (or pull) swift-docker: https://github.com/apple/swift-docker
66
2. Build the Ubuntu 18.04 container: `cd swift-ci/master/ubuntu/18.04; docker build .`
7-
3. `docker run -it cpus <CPUs> memory <Memory> -v ~/<path to your local sources>:/src-on-host:cached name lsan-reproducer cap-add=SYS_PTRACE security-opt seccomp=unconfined <hash that docker build outputs> bash`
7+
3. `docker run -it --cpus <CPUs> --memory <Memory> -v ~/<path to your local sources>:/src-on-host:cached --name lsan-reproducer --cap-add=SYS_PTRACE --security-opt seccomp=unconfined <hash that docker build outputs> bash`
88
- The `-cap-add` and `-security-opt` arguments are needed to run LLDB inside the Docker container
9-
4. Copy the sources to inside the Docker container: `cp /src-on-host/* ~`
9+
4. Copy the sources to inside the Docker container: `cp -r /src-on-host/* ~`
1010
- We need to to this because the build needs a case-sensitive file system and your host machine probably has a case-insensitive file system
1111

1212
Build inside the Container
@@ -36,36 +36,25 @@ Direct leak of 120 byte(s) in 3 object(s) allocated from:
3636
SUMMARY: LeakSanitizer: 120 byte(s) leaked in 3 allocation(s).
3737
```
3838
2. `lldb -- <your swiftc invocation above>`
39-
3. Set a breakpoint somewhere in swiftc, eg. at the start of main: `br s -f driver.cpp -l 19`. This should output something like
40-
41-
```
42-
Breakpoint 1: where = swiftc`main + 4 at driver.cpp:20:10, address = 0x00000000014d25d4
43-
```
44-
45-
4. Run swiftc to the breakpoint
46-
5. This should stop you with something like
47-
39+
3. Start running swiftc inside lldb by executing `r`
40+
4. Find the loaded offset of swift-frontend by running `image list`
41+
For example, this might output
4842
```
49-
* thread #1, name = 'swiftc', stop reason = breakpoint 1.1
50-
frame #0: 0x0000555556a265d4 swiftc`main(argc_=168, argv_=0x00007fffffffced8) at driver.cpp:20:10
51-
17 #include "swift/DriverTool/DriverTool.h"
52-
18
53-
19 int main(int argc_, const char **argv_) {
54-
→ 20 return swift::mainEntry(argc_, argv_);
55-
21 }
43+
[ 0] 0AEA10C1 0x0000555555554000 /home/build-user/build/buildbot_incremental_lsan/swift-linux-x86_64/bin/swift-frontend
44+
[ 1] D52BB67A-BBBB-E429-6E87-FC16144CA7CE-55276DD6 0x00007ffff7ffb000 [vdso] (0x00007ffff7ffb000)
45+
[ 2] 9EA8014C-F020-21A2-9E57-AA3E0512E9BB-6E30541D 0x00007ffff7dd3000 /lib/x86_64-linux-gnu/ld-2.27.so
5646
```
57-
58-
6. Find the loaded offset of swift-frontend by subtracting the breakpoint address from the frame address. With the example above, that’s `0x0000555556a265d4 - 0x00000000014d25d4 = 0x555555554000`.
59-
7. For the frame that you want to symbolicate,, add the offset you computed above to the stack frame in the LSAN report, eg. to symbolicate frame 1 `0x555555554000 + 0x292d81c = 0x555557E8181C`
60-
8. Look up the address using `image lookup -a <address you computed>`. This should output something like
47+
The loaded offset is `0x0000555555554000`
48+
5. For the frame that you want to symbolicate,, add the offset you computed above to the stack frame in the LSAN report, eg. to symbolicate frame 1 `0x555555554000 + 0x292d81c = 0x555557E8181C`
49+
6. Look up the address using `image lookup -a <address you computed>`. This should output something like
6150

6251
```
6352
(lldb) image lookup -a 0x555557E8181C
6453
Address: swiftc[0x000000000292d81c] (swiftc.PT_LOAD[0]..text + 22056284)
6554
Summary: swiftc`registerFunctionTest(BridgedStringRef, void*) + 28 at SILBridging.cpp:148:3
6655
```
6756

68-
9. Hoorray, you know which function is leaking.
57+
7. Hoorray, you know which function is leaking.
6958

7059
### Making Local Changes Inside the Container
7160

include/swift/AST/ASTBridging.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ BridgedAlignmentAttr_createParsed(BridgedASTContext cContext,
481481
BridgedSourceLoc cAtLoc,
482482
BridgedSourceRange cRange, size_t cValue);
483483

484+
SWIFT_NAME("BridgedAllowFeatureSuppressionAttr.createParsed(_:atLoc:range:features:)")
485+
BridgedAllowFeatureSuppressionAttr
486+
BridgedAllowFeatureSuppressionAttr_createParsed(
487+
BridgedASTContext cContext,
488+
BridgedSourceLoc cAtLoc,
489+
BridgedSourceRange cRange,
490+
BridgedArrayRef cFeatures);
491+
484492
SWIFT_NAME("BridgedCDeclAttr.createParsed(_:atLoc:range:name:)")
485493
BridgedCDeclAttr BridgedCDeclAttr_createParsed(BridgedASTContext cContext,
486494
BridgedSourceLoc cAtLoc,

include/swift/AST/Attr.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ class DeclAttribute : public AttributeBase {
191191
SWIFT_INLINE_BITFIELD(NonisolatedAttr, DeclAttribute, 1,
192192
isUnsafe : 1
193193
);
194+
195+
SWIFT_INLINE_BITFIELD_FULL(AllowFeatureSuppressionAttr, DeclAttribute, 32,
196+
: NumPadBits,
197+
NumFeatures : 32
198+
);
194199
} Bits;
195200
// clang-format on
196201

@@ -2636,6 +2641,32 @@ template <typename ATTR, bool AllowInvalid> struct ToAttributeKind {
26362641
}
26372642
};
26382643

2644+
/// The @_allowFeatureSuppression(Foo, Bar) attribute. The feature
2645+
/// names are intentionally not validated, and the attribute itself is
2646+
/// not printed when rendering a module interface.
2647+
class AllowFeatureSuppressionAttr final
2648+
: public DeclAttribute,
2649+
private llvm::TrailingObjects<AllowFeatureSuppressionAttr, Identifier> {
2650+
friend TrailingObjects;
2651+
2652+
/// Create an implicit @objc attribute with the given (optional) name.
2653+
AllowFeatureSuppressionAttr(SourceLoc atLoc, SourceRange range,
2654+
bool implicit, ArrayRef<Identifier> features);
2655+
public:
2656+
static AllowFeatureSuppressionAttr *create(ASTContext &ctx, SourceLoc atLoc,
2657+
SourceRange range, bool implicit,
2658+
ArrayRef<Identifier> features);
2659+
2660+
ArrayRef<Identifier> getSuppressedFeatures() const {
2661+
return {getTrailingObjects<Identifier>(),
2662+
Bits.AllowFeatureSuppressionAttr.NumFeatures};
2663+
}
2664+
2665+
static bool classof(const DeclAttribute *DA) {
2666+
return DA->getKind() == DeclAttrKind::AllowFeatureSuppression;
2667+
}
2668+
};
2669+
26392670
/// Attributes that may be applied to declarations.
26402671
class DeclAttributes {
26412672
/// Linked list of declaration attributes.

include/swift/AST/DeclAttr.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ SIMPLE_DECL_ATTR(_noObjCBridging, NoObjCBridging,
488488
DECL_ATTR(_distributedThunkTarget, DistributedThunkTarget,
489489
OnAbstractFunction | UserInaccessible | ABIStableToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
490490
156)
491-
LAST_DECL_ATTR(DistributedThunkTarget)
491+
DECL_ATTR(_allowFeatureSuppression, AllowFeatureSuppression,
492+
OnAnyDecl | UserInaccessible | NotSerialized | ABIStableToAdd | APIStableToAdd | ABIStableToRemove | APIStableToRemove,
493+
157)
494+
LAST_DECL_ATTR(AllowFeatureSuppression)
492495

493496
#undef DECL_ATTR_ALIAS
494497
#undef CONTEXTUAL_DECL_ATTR_ALIAS

include/swift/AST/DiagnosticEngine.h

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ namespace swift {
8888
};
8989
}
9090

91+
template <class... ArgTypes>
92+
using DiagArgTuple =
93+
std::tuple<typename detail::PassArgument<ArgTypes>::type...>;
94+
9195
/// A family of wrapper types for compiler data types that forces its
9296
/// underlying data to be formatted with full qualification.
9397
///
@@ -476,20 +480,28 @@ namespace swift {
476480
friend DiagnosticEngine;
477481
friend class InFlightDiagnostic;
478482

483+
Diagnostic(DiagID ID) : ID(ID) {}
484+
479485
public:
480486
// All constructors are intentionally implicit.
481487
template<typename ...ArgTypes>
482488
Diagnostic(Diag<ArgTypes...> ID,
483489
typename detail::PassArgument<ArgTypes>::type... VArgs)
484-
: ID(ID.ID) {
485-
DiagnosticArgument DiagArgs[] = {
486-
DiagnosticArgument(0), std::move(VArgs)...
487-
};
488-
Args.append(DiagArgs + 1, DiagArgs + 1 + sizeof...(VArgs));
490+
: Diagnostic(ID.ID) {
491+
Args.reserve(sizeof...(ArgTypes));
492+
gatherArgs(VArgs...);
489493
}
490494

491495
/*implicit*/Diagnostic(DiagID ID, ArrayRef<DiagnosticArgument> Args)
492496
: ID(ID), Args(Args.begin(), Args.end()) {}
497+
498+
template <class... ArgTypes>
499+
static Diagnostic fromTuple(Diag<ArgTypes...> id,
500+
const DiagArgTuple<ArgTypes...> &tuple) {
501+
Diagnostic result(id.ID);
502+
result.gatherArgsFromTuple<DiagArgTuple<ArgTypes...>, 0, ArgTypes...>(tuple);
503+
return result;
504+
}
493505

494506
// Accessors.
495507
DiagID getID() const { return ID; }
@@ -528,6 +540,37 @@ namespace swift {
528540

529541
void addChildNote(Diagnostic &&D);
530542
void insertChildNote(unsigned beforeIndex, Diagnostic &&D);
543+
544+
private:
545+
// gatherArgs could just be `Args.emplace_back(args)...;` if C++
546+
// allowed pack expansions in statement context.
547+
548+
// Base case.
549+
void gatherArgs() {}
550+
551+
// Pull one off the pack.
552+
template <class ArgType, class... RemainingArgTypes>
553+
void gatherArgs(ArgType arg, RemainingArgTypes... remainingArgs) {
554+
Args.emplace_back(arg);
555+
gatherArgs(remainingArgs...);
556+
}
557+
558+
// gatherArgsFromTuple could just be
559+
// `Args.emplace_back(std::get<packIndexOf<ArgTypes>>(tuple))...;`
560+
// in a better world.
561+
562+
// Base case.
563+
template <class Tuple, size_t Index>
564+
void gatherArgsFromTuple(const Tuple &tuple) {}
565+
566+
// Pull one off the pack.
567+
template <class Tuple, size_t Index,
568+
class ArgType, class... RemainingArgTypes>
569+
void gatherArgsFromTuple(const Tuple &tuple) {
570+
Args.emplace_back(std::move(std::get<Index>(tuple)));
571+
gatherArgsFromTuple<Tuple, Index + 1, RemainingArgTypes...>(
572+
std::move(tuple));
573+
}
531574
};
532575

533576
/// A diagnostic that has no input arguments, so it is trivially-destructable.
@@ -866,6 +909,73 @@ namespace swift {
866909
DiagnosticState &operator=(DiagnosticState &&) = default;
867910
};
868911

912+
/// A lightweight reference to a diagnostic that's been fully applied to
913+
/// its arguments. This allows a general routine (in the parser, say) to
914+
/// be customized to emit an arbitrary diagnostic without needing to
915+
/// eagerly construct a full Diagnostic. Like ArrayRef and function_ref,
916+
/// this stores a reference to what's likely to be a temporary, so it
917+
/// should only be used as a function parameter. If you need to persist
918+
/// the diagnostic, you'll have to call createDiagnostic().
919+
///
920+
/// You can initialize a DiagRef parameter in one of two ways:
921+
/// - passing a Diag<> as the argument, e.g.
922+
/// diag::circular_reference
923+
/// or
924+
/// - constructing it with a Diag and its arguments, e.g.
925+
/// {diag::circular_protocol_def, {proto->getName()}}
926+
///
927+
/// It'd be nice to let people write `{diag::my_error, arg0, arg1}`
928+
/// instead of `{diag::my_error, {arg0, arg1}}`, but we can't: the
929+
/// temporary needs to be created in the calling context.
930+
class DiagRef {
931+
DiagID id;
932+
933+
/// If this is null, then id is a Diag<> and there are no arguments.
934+
Diagnostic (*createFn)(DiagID id, const void *opaqueStorage);
935+
const void *opaqueStorage;
936+
937+
public:
938+
/// Construct a diagnostic from a diagnostic ID that's known to not take
939+
/// arguments.
940+
DiagRef(Diag<> id)
941+
: id(id.ID), createFn(nullptr), opaqueStorage(nullptr) {}
942+
943+
/// Construct a diagnostic from a diagnostic ID and its arguments.
944+
template <class... ArgTypes>
945+
DiagRef(Diag<ArgTypes...> id, const DiagArgTuple<ArgTypes...> &tuple)
946+
: id(id.ID),
947+
createFn(&createFromTuple<ArgTypes...>),
948+
opaqueStorage(&tuple) {}
949+
950+
// A specialization of the general constructor above for diagnostics
951+
// with no arguments; this is a useful optimization when a DiagRef
952+
// is constructed generically.
953+
DiagRef(Diag<> id, const DiagArgTuple<> &tuple)
954+
: DiagRef(id) {}
955+
956+
/// Return the diagnostic ID that this will emit.
957+
DiagID getID() const {
958+
return id;
959+
}
960+
961+
/// Create a full Diagnostic. It's safe to do this multiple times on
962+
/// a single DiagRef.
963+
Diagnostic createDiagnostic() {
964+
if (!createFn) {
965+
return Diagnostic(Diag<> {id});
966+
} else {
967+
return createFn(id, opaqueStorage);
968+
}
969+
}
970+
971+
private:
972+
template <class... ArgTypes>
973+
static Diagnostic createFromTuple(DiagID id, const void *opaqueStorage) {
974+
auto tuple = static_cast<const DiagArgTuple<ArgTypes...> *>(opaqueStorage);
975+
return Diagnostic::fromTuple(Diag<ArgTypes...> {id}, *tuple);
976+
}
977+
};
978+
869979
/// Class responsible for formatting diagnostics and presenting them
870980
/// to the user.
871981
class DiagnosticEngine {
@@ -1113,6 +1223,12 @@ namespace swift {
11131223
return diagnose(Loc, Diagnostic(ID, std::move(Args)...));
11141224
}
11151225

1226+
/// Emit the given lazily-applied diagnostic at the specified
1227+
/// source location.
1228+
InFlightDiagnostic diagnose(SourceLoc loc, DiagRef diag) {
1229+
return diagnose(loc, diag.createDiagnostic());
1230+
}
1231+
11161232
/// Delete an API that may lead clients to avoid specifying source location.
11171233
template<typename ...ArgTypes>
11181234
InFlightDiagnostic

include/swift/AST/DiagnosticsCommon.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ NOTE(brace_stmt_suggest_do,none,
4545
"did you mean to use a 'do' statement?", ())
4646

4747
WARNING(error_in_future_swift_version,none,
48-
"%0; this is an error in Swift %1",
48+
"%0; this is an error in the Swift %1 language mode",
4949
(DiagnosticInfo *, unsigned))
5050

5151
// Generic disambiguation

include/swift/AST/DiagnosticsParse.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,10 @@ ERROR(attr_rawlayout_expected_params,none,
18891889

18901890
ERROR(attr_extern_expected_label,none,
18911891
"expected %0 argument to @_extern attribute", (StringRef))
1892+
1893+
ERROR(attr_expected_feature_name,none,
1894+
"expected feature name in @%0 attribute", (StringRef))
1895+
18921896
//------------------------------------------------------------------------------
18931897
// MARK: Generics parsing diagnostics
18941898
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6812,7 +6812,7 @@ WARNING(inlinable_decl_ref_from_hidden_module_warn,
68126812
none, "%kind0 cannot be used in " FRAGILE_FUNC_KIND "1 "
68136813
"because %select{<<ERROR>>|<<ERROR>>|<<ERROR>>|<<ERROR>>|"
68146814
"%2 was not imported by this file}3"
6815-
"; this is an error in Swift 6",
6815+
"; this is an error in the Swift 6 language mode",
68166816
(const ValueDecl *, unsigned, Identifier, unsigned))
68176817

68186818
ERROR(inlinable_typealias_desugars_to_type_from_hidden_module,

include/swift/AST/EducationalNotes.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,8 @@ EDUCATIONAL_NOTES(result_builder_missing_build_array,
8686

8787
EDUCATIONAL_NOTES(multiple_inheritance,
8888
"multiple-inheritance.md")
89-
89+
90+
EDUCATIONAL_NOTES(error_in_future_swift_version,
91+
"error-in-future-swift-version.md")
92+
9093
#undef EDUCATIONAL_NOTES

0 commit comments

Comments
 (0)