Skip to content

Commit 56ece28

Browse files
authored
Merge branch 'apple:main' into main
2 parents 6e5a083 + c3af0ff commit 56ece28

File tree

121 files changed

+2827
-1256
lines changed

Some content is hidden

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

121 files changed

+2827
-1256
lines changed

docs/Backtracing.rst

Lines changed: 98 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Swift now supports:
2727

2828
* Automatic crash catching and backtrace generation out of the box.
2929
* Built-in symbolication.
30-
* A choice of unwind algorithms, including "fast", DWARF and SEH.
3130
* Interactive(!) crash/runtime error catching.
3231

3332
Crash catching is enabled by default, and won't interfere with any system-wide
@@ -61,10 +60,7 @@ follows:
6160
+-----------------+---------+--------------------------------------------------+
6261
| unwind | auto | Specifies which unwind algorithm to use. |
6362
| | | ``auto`` means to choose appropriately for the |
64-
| | | platform. Other options are ``fast``, which |
65-
| | | does a naïve stack walk; and ``precise``, which |
66-
| | | uses exception handling data to perform an |
67-
| | | unwind. |
63+
| | | platform. |
6864
+-----------------+---------+--------------------------------------------------+
6965
| preset | auto | Specifies which set of preset formatting options |
7066
| | | to use. Options are ``friendly``, ``medium`` or |
@@ -106,7 +102,7 @@ follows:
106102
| | | to the runtime library, or using ``SWIFT_ROOT``. |
107103
+-----------------+---------+--------------------------------------------------+
108104

109-
(*) On macOS, this defaults to ``tty`` rather than ``yes``.
105+
(*) On macOS, this defaults to ``no`` rather than ``yes``.
110106

111107
Backtrace limits
112108
----------------
@@ -179,10 +175,10 @@ triggered automatically by the runtime.
179175
System specifics
180176
----------------
181177

182-
macOS
183-
^^^^^
178+
Signal Handling
179+
^^^^^^^^^^^^^^^
184180

185-
On macOS, we catch crashes and other events using a signal handler. At time of
181+
On macOS and Linux, program crashes are caught using a signal handler. At time of
186182
writing, this is installed for the following signals:
187183

188184
+--------------+--------------------------+-------------------------------------+
@@ -217,9 +213,43 @@ finds that there is already a handler for that signal. Similarly if something
217213
else has already configured an alternate signal stack, it will leave that
218214
stack alone.
219215

220-
Once the backtracer has finished handling the crash, it will allow the crashing
221-
program to continue and crash normally, which will result in the usual Crash
222-
Reporter log file being generated.
216+
macOS
217+
^^^^^
218+
219+
The backtracer is not active by default on macOS. You can enable it by setting
220+
``SWIFT_BACKTRACE`` to ``enable=yes``, which is sufficient if you build your
221+
programs using Xcode. If you are using some other build tool to build your
222+
program, you will need to sign the program with the entitlement
223+
``com.apple.security.get-task-allow`` in order for the backtracer to work. This
224+
is the same entitlement you would need to make various other tools work on your
225+
program, so you may already be doing this. If not, you will need to make a
226+
property list file containing the entitlements you wish to sign your program
227+
with, e.g. ::
228+
229+
<?xml version="1.0" encoding="UTF-8"?>
230+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
231+
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
232+
<plist version="1.0">
233+
<dict>
234+
<key>com.apple.security.get-task-allow</key>
235+
<true/>
236+
</dict>
237+
</plist>
238+
239+
and then to sign your program you should do::
240+
241+
$ codesign --force --sign - --entitlements entitlements.plist \
242+
/path/to/your/program
243+
244+
Note that programs with the ``com.apple.security.get-task-allow`` entitlement
245+
will not be accepted for distribution in the App Store, and will be rejected by
246+
notarization. The entitlement is strictly for debugging purposes only and
247+
software should not be shipped to end users with it enabled.
248+
249+
On macOS, we catch crashes and other events using a signal handler. Once the
250+
backtracer has finished handling the crash, it will allow the crashing program
251+
to continue and crash normally, which will result in the usual Crash Reporter
252+
log file being generated.
223253

224254
Crash catching *cannot* be enabled for setuid binaries. This is intentional as
225255
doing so might create a security hole.
@@ -229,3 +259,59 @@ Other Darwin (iOS, tvOS)
229259

230260
Crash catching is not enabled for non-macOS Darwin. You should continue to look
231261
at the system-provided crash logs.
262+
263+
Linux
264+
^^^^^
265+
266+
Frame Pointers
267+
""""""""""""""
268+
269+
The backtracer currently does a simple frame-pointer based unwind. As a result,
270+
if you compile your code with ``-fomit-frame-pointer``, which is often the
271+
default for release builds on Intel Linux, you may find that you get incomplete
272+
backtraces.
273+
274+
If you wish to get a more complete backtrace, at a small cost in performance,
275+
you can add the compiler flags ``-Xcc -fno-omit-frame-pointer`` when building
276+
your Swift program.
277+
278+
Static Linking Support
279+
""""""""""""""""""""""
280+
281+
For users who statically link their binaries and do not wish to ship the Swift
282+
runtime library alongside them, there is a statically linked copy of
283+
``swift-backtrace``, named ``swift-backtrace-static`` , in the ``libexec``
284+
directory alongside the normal ``swift-backtrace`` binary.
285+
286+
By default, to locate ``swift-backtrace``, the runtime will attempt to look in
287+
the following locations::
288+
289+
<swift-root>/libexec/swift/<platform>
290+
<swift-root>/libexec/swift/<platform>/<arch>
291+
<swift-root>/libexec/swift
292+
<swift-root>/libexec/swift/<arch>
293+
<swift-root>/bin
294+
<swift-root>/bin/<arch>
295+
<swift-root>
296+
297+
where ``<swift-root>`` by default is determined from the path to the runtime
298+
library, ``libswiftCore``, ``<platform>`` is the name Swift gives to the platform
299+
(in this case most likely ``linux``) and ``<arch>`` is the name Swift uses for
300+
the CPU architecture (e.g. ``x86_64``, ``arm64`` and so on).
301+
302+
When the runtime is statically linked with _your_ binary, the runtime will
303+
instead determine ``<swift-root>`` in the above patterns relative to *your
304+
binary*. For example, if your binary is installed in e.g. ``/usr/bin``,
305+
``<swift-root>`` would be ``/usr``.
306+
307+
You will therefore need to install a copy of ``swift-backtrace-static``, renamed
308+
to ``swift-backtrace``, in one of the locations above; the simplest option will
309+
often be to put it in the same directory as your own binary.
310+
311+
You can also explicitly specify the value of ``<swift-root>`` using the
312+
environment variable ``SWIFT_ROOT``, or you can explicitly specify the location
313+
of the backtracer using
314+
``SWIFT_BACKTRACE=swift-backtrace=<path-to-swift-backtrace>``.
315+
316+
If the runtime is unable to locate the backtracer, it will allow your program to
317+
crash as it would have done anyway.

include/swift/AST/Attr.h

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,53 +2847,62 @@ class DeclAttributes {
28472847
SourceLoc getStartLoc(bool forModifiers = false) const;
28482848
};
28492849

2850-
/// Predicate used to filter attributes to only the original attributes.
2851-
class OrigDeclAttrFilter {
2850+
/// Predicate used to filter attributes to only the parsed attributes.
2851+
class ParsedDeclAttrFilter {
28522852
const Decl *decl;
28532853

28542854
public:
2855-
OrigDeclAttrFilter() : decl(nullptr) {}
2855+
ParsedDeclAttrFilter() : decl(nullptr) {}
28562856

2857-
OrigDeclAttrFilter(const Decl *decl) : decl(decl) {}
2857+
ParsedDeclAttrFilter(const Decl *decl) : decl(decl) {}
28582858

28592859
llvm::Optional<const DeclAttribute *>
28602860
operator()(const DeclAttribute *Attr) const;
28612861
};
28622862

2863-
/// Attributes applied directly to the declaration.
2863+
/// Attributes written in source on a declaration.
28642864
///
28652865
/// We should really just have \c DeclAttributes and \c SemanticDeclAttributes,
28662866
/// but currently almost all callers expect the latter. Instead of changing all
28672867
/// callers of \c getAttrs, instead provide a way to retrieve the original
28682868
/// attributes.
2869-
class OrigDeclAttributes {
2869+
class ParsedDeclAttributes {
28702870
public:
2871-
using OrigFilteredRange = OptionalTransformRange<iterator_range<DeclAttributes::const_iterator>, OrigDeclAttrFilter>;
2871+
using ParsedFilteredRange =
2872+
OptionalTransformRange<iterator_range<DeclAttributes::const_iterator>,
2873+
ParsedDeclAttrFilter>;
28722874

28732875
private:
2874-
OrigFilteredRange origRange;
2876+
ParsedFilteredRange parsedRange;
28752877

28762878
public:
2877-
OrigDeclAttributes() : origRange(make_range(DeclAttributes::const_iterator(nullptr), DeclAttributes::const_iterator(nullptr)), OrigDeclAttrFilter()) {}
2879+
ParsedDeclAttributes()
2880+
: parsedRange(make_range(DeclAttributes::const_iterator(nullptr),
2881+
DeclAttributes::const_iterator(nullptr)),
2882+
ParsedDeclAttrFilter()) {}
28782883

2879-
OrigDeclAttributes(const DeclAttributes &allAttrs, const Decl *decl) : origRange(make_range(allAttrs.begin(), allAttrs.end()), OrigDeclAttrFilter(decl)) {}
2884+
ParsedDeclAttributes(const DeclAttributes &allAttrs, const Decl *decl)
2885+
: parsedRange(make_range(allAttrs.begin(), allAttrs.end()),
2886+
ParsedDeclAttrFilter(decl)) {}
28802887

2881-
OrigFilteredRange::iterator begin() const { return origRange.begin(); }
2882-
OrigFilteredRange::iterator end() const { return origRange.end(); }
2888+
ParsedFilteredRange::iterator begin() const { return parsedRange.begin(); }
2889+
ParsedFilteredRange::iterator end() const { return parsedRange.end(); }
28832890

28842891
template <typename AttrType, bool AllowInvalid>
28852892
using AttributeKindRange =
2886-
OptionalTransformRange<OrigFilteredRange, ToAttributeKind<AttrType, AllowInvalid>>;
2893+
OptionalTransformRange<ParsedFilteredRange,
2894+
ToAttributeKind<AttrType, AllowInvalid>>;
28872895

28882896
template <typename AttrType, bool AllowInvalid = false>
28892897
AttributeKindRange<AttrType, AllowInvalid> getAttributes() const {
2890-
return AttributeKindRange<AttrType, AllowInvalid>(origRange, ToAttributeKind<AttrType, AllowInvalid>());
2898+
return AttributeKindRange<AttrType, AllowInvalid>(
2899+
parsedRange, ToAttributeKind<AttrType, AllowInvalid>());
28912900
}
28922901

28932902
/// Retrieve the first attribute of the given attribute class.
28942903
template <typename AttrType>
28952904
const AttrType *getAttribute(bool allowInvalid = false) const {
2896-
for (auto *attr : origRange) {
2905+
for (auto *attr : parsedRange) {
28972906
if (auto *specificAttr = dyn_cast<AttrType>(attr)) {
28982907
if (specificAttr->isValid() || allowInvalid)
28992908
return specificAttr;

include/swift/AST/Decl.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,9 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
920920
}
921921

922922
/// Returns the attributes that were directly attached to this declaration
923-
/// as written in source, ie. does not include attributes generated by macro
924-
/// expansions.
925-
OrigDeclAttributes getOriginalAttrs() const;
923+
/// as written in source, ie. does not include semantic attributes or ones
924+
/// generated by macro expansions.
925+
ParsedDeclAttributes getParsedAttrs() const;
926926

927927
/// Returns the attributes attached to this declaration,
928928
/// including attributes that are generated as the result of member
@@ -3324,6 +3324,9 @@ class OpaqueTypeDecl final :
33243324
};
33253325
}
33263326

3327+
/// Should the underlying type be visible to clients outside of the module?
3328+
bool exportUnderlyingType() const;
3329+
33273330
/// The substitutions that map the generic parameters of the opaque type to
33283331
/// the unique underlying types, when that information is known.
33293332
llvm::Optional<SubstitutionMap> getUniqueUnderlyingTypeSubstitutions() const {
@@ -5371,6 +5374,7 @@ class BuiltinTupleDecl final : public NominalTypeDecl {
53715374
/// AbstractStorageDecl - This is the common superclass for VarDecl and
53725375
/// SubscriptDecl, representing potentially settable memory locations.
53735376
class AbstractStorageDecl : public ValueDecl {
5377+
friend class HasStorageRequest;
53745378
friend class SetterAccessLevelRequest;
53755379
friend class IsGetterMutatingRequest;
53765380
friend class IsSetterMutatingRequest;
@@ -5437,6 +5441,8 @@ class AbstractStorageDecl : public ValueDecl {
54375441
llvm::PointerIntPair<AccessorRecord*, 3, OptionalEnum<AccessLevel>> Accessors;
54385442

54395443
struct {
5444+
unsigned HasStorageComputed : 1;
5445+
unsigned HasStorage : 1;
54405446
unsigned IsGetterMutatingComputed : 1;
54415447
unsigned IsGetterMutating : 1;
54425448
unsigned IsSetterMutatingComputed : 1;
@@ -5506,7 +5512,6 @@ class AbstractStorageDecl : public ValueDecl {
55065512
return getImplInfo().getReadWriteImpl();
55075513
}
55085514

5509-
55105515
/// Return true if this is a VarDecl that has storage associated with
55115516
/// it.
55125517
bool hasStorage() const;

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,12 @@ ERROR(expr_swift_keypath_not_starting_with_type,none,
678678
ERROR(expr_swift_keypath_not_starting_with_dot,none,
679679
"a Swift key path with contextual root must begin with a leading dot",
680680
())
681-
ERROR(expr_smart_keypath_value_covert_to_contextual_type,none,
681+
ERROR(expr_keypath_value_covert_to_contextual_type,none,
682682
"key path value type %0 cannot be converted to contextual type %1",
683683
(Type, Type))
684+
ERROR(expr_keypath_type_covert_to_contextual_type,none,
685+
"cannot convert key path type %0 to contextual type %1",
686+
(Type, Type))
684687
ERROR(expr_swift_keypath_empty, none,
685688
"key path must have at least one component", ())
686689
ERROR(expr_string_interpolation_outside_string,none,
@@ -7495,6 +7498,9 @@ ERROR(extension_macro_invalid_conformance,none,
74957498
ERROR(macro_attached_to_invalid_decl,none,
74967499
"'%0' macro cannot be attached to %1 (%base2)",
74977500
(StringRef, DescriptiveDeclKind, const Decl *))
7501+
ERROR(macro_as_default_argument, none,
7502+
"non-built-in macro cannot be used as default argument",
7503+
())
74987504
ERROR(conformance_macro,none,
74997505
"conformance macros are replaced by extension macros",
75007506
())

include/swift/AST/TypeCheckRequests.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,10 +1779,9 @@ class MemberwiseInitPropertiesRequest :
17791779
bool isCached() const { return true; }
17801780
};
17811781

1782-
class HasStorageRequest :
1783-
public SimpleRequest<HasStorageRequest,
1784-
bool(AbstractStorageDecl *),
1785-
RequestFlags::Cached> {
1782+
class HasStorageRequest
1783+
: public SimpleRequest<HasStorageRequest, bool(AbstractStorageDecl *),
1784+
RequestFlags::SeparatelyCached> {
17861785
public:
17871786
using SimpleRequest::SimpleRequest;
17881787

@@ -1793,7 +1792,10 @@ class HasStorageRequest :
17931792
bool evaluate(Evaluator &evaluator, AbstractStorageDecl *decl) const;
17941793

17951794
public:
1795+
// Separate caching.
17961796
bool isCached() const { return true; }
1797+
llvm::Optional<bool> getCachedResult() const;
1798+
void cacheResult(bool hasStorage) const;
17971799
};
17981800

17991801
class StorageImplInfoRequest :
@@ -2658,7 +2660,8 @@ class SynthesizeDefaultInitRequest
26582660

26592661
class CompareDeclSpecializationRequest
26602662
: public SimpleRequest<CompareDeclSpecializationRequest,
2661-
bool(DeclContext *, ValueDecl *, ValueDecl *, bool),
2663+
bool(DeclContext *, ValueDecl *, ValueDecl *, bool,
2664+
bool),
26622665
RequestFlags::Cached> {
26632666
public:
26642667
using SimpleRequest::SimpleRequest;
@@ -2667,9 +2670,9 @@ class CompareDeclSpecializationRequest
26672670
friend SimpleRequest;
26682671

26692672
// Evaluation.
2670-
bool evaluate(Evaluator &evaluator, DeclContext *DC,
2671-
ValueDecl *VD1, ValueDecl *VD2,
2672-
bool dynamic) const;
2673+
bool evaluate(Evaluator &evaluator, DeclContext *DC, ValueDecl *VD1,
2674+
ValueDecl *VD2, bool dynamic,
2675+
bool allowMissingConformances) const;
26732676

26742677
public:
26752678
// Caching.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ SWIFT_REQUEST(TypeChecker, ClassAncestryFlagsRequest,
4747
SWIFT_REQUEST(TypeChecker, IDEInspectionFileRequest,
4848
SourceFile *(ModuleDecl *), Cached, NoLocationInfo)
4949
SWIFT_REQUEST(TypeChecker, CompareDeclSpecializationRequest,
50-
bool (DeclContext *, ValueDecl *, ValueDecl *, bool), Cached,
51-
NoLocationInfo)
50+
bool (DeclContext *, ValueDecl *, ValueDecl *, bool, bool),
51+
Cached, NoLocationInfo)
5252
SWIFT_REQUEST(TypeChecker, ConditionalRequirementsRequest,
5353
ArrayRef<Requirement> (NormalProtocolConformance *),
5454
Cached, NoLocationInfo)
@@ -311,7 +311,7 @@ SWIFT_REQUEST(TypeChecker, StorageImplInfoRequest,
311311
StorageImplInfo(AbstractStorageDecl *), SeparatelyCached,
312312
NoLocationInfo)
313313
SWIFT_REQUEST(TypeChecker, HasStorageRequest,
314-
bool(AbstractStorageDecl *), Cached,
314+
bool(AbstractStorageDecl *), SeparatelyCached,
315315
NoLocationInfo)
316316
SWIFT_REQUEST(TypeChecker, StoredPropertiesAndMissingMembersRequest,
317317
ArrayRef<Decl *>(NominalTypeDecl *), Cached, NoLocationInfo)

0 commit comments

Comments
 (0)