Commit Graph

2981 Commits

Author SHA1 Message Date
Dario Rexin
cae740d902 [Runtime] Use MetadataAllocator to allocate runtime instantiated layout strings (#66055)
rdar://109660582

This will create more visibility into layout string allocations when using swift-inspect.
2023-05-22 12:55:09 -07:00
swift-ci
8dcf7575d5 Merge pull request #65972 from apple/better-deinit-escape-wording
[Runtime] Improve wording of deinit escape warning.
2023-05-19 12:23:53 -07:00
Mike Ash
dc3416bd72 [Runtime] Improve wording of deinit escape warning.
Describe in more detail how an object can end up with a non-zero refcount on deallocation, and the consequences.

rdar://109045333
2023-05-17 11:01:32 -04:00
Alastair Houghton
d58183306f [Runtime][Backtracing] Conditionalise initialisation of the spawnattr.
We don't need to initialise the posix_spawnattr unless we're enabling the
backtracer, so don't.

rdar://109354306
2023-05-15 16:07:58 +01:00
Kuba (Brecka) Mracek
1028050d34 ImageInspectionMachO.cpp: Guard including objc/runtime.h under SWIFT_OBJC_INTEROP (#65890) 2023-05-12 15:12:35 -07:00
Kuba (Brecka) Mracek
1125e45cca Don't include <thread> in MetadataCache.h, all we need there is <atomic> (#65826) 2023-05-12 10:34:31 -07:00
swift-ci
8db4b9fb55 Merge pull request #65776 from mikeash/dealloc-partial-class-instance-setclass-readonly
[Runtime] Immediate release and return when destroying partial instance of pure ObjC class.
2023-05-09 19:08:22 -07:00
Mike Ash
3a396af086 [Runtime] Immediate release and return when destroying partial instance of pure ObjC class.
Make swift_deallocPartialClassInstance check if the object's class is a pure ObjC class, in which case there are no ivar destroyers and we can just return immediately.

It's possible for an allocWithZone: override to cause self to be a special object constructed in read-only memory. swift_deallocPartialClassInstance calls object_setClass to avoid running the dealloc method of any Swift subclasses, but this call crashes if self is read-only. It's unnecessary when the object's class is pure ObjC and therefore there are no Swift subclasses, so just skip it entirely.

rdar://107756747
2023-05-09 16:47:47 -04:00
Alastair Houghton
18a753cd87 [Runtime] Print type names in escape-from-deinit messages.
In addition to giving the object's address, we can print the name of its
type (since the object is still live at this point).

rdar://108882759
2023-05-05 11:51:49 +01:00
Alastair Houghton
2e36235451 Merge pull request #65140 from al45tair/eng/PR-107718586
[Runtime] Ensure we *always* generate names for ObjC classes.
2023-04-27 13:53:46 +01:00
Kuba (Brecka) Mracek
b58818f153 To be able to correctly exercise Concurrency on freestanding, default to using 'pthread' threading package (#65329)
To be able to correctly exercise Concurrency on freestanding, default to using 'pthread' threading package

rdar://102259828
2023-04-21 14:47:51 -07:00
Dario Rexin
022311e438 [IRGen] Fix layout string generation for pre-specialized metadata (#65162)
* [IRGen] Fix layout string generation for pre-specialized metadata

rdar://108012057

Pre-specialized metadata has to be specifically handled by using the bound generic type instead of the unbound one. All the necessary information is already being passed down as BoundGenericTypeCharacteristics, we just need to apply them when present.

* Add tests and a few fixes

* Fixes after rebase

* Attempt to fix Windows linker issue in test
2023-04-20 13:26:41 -07:00
Alastair Houghton
6f8b2ef9e5 [Runtime] Fix swift_weakTakeStrong().
It turns out that when taking the last weak reference for an object that
has been deallocated, we might have returned a non-null pointer when we
shouldn't have.  Which is exciting.

rdar://106375185
2023-04-14 19:15:38 +01:00
Alastair Houghton
2f6baac55e [Runtime] Ensure we *always* generate names for ObjC classes.
If something fails while trying to generate a name for an ObjC class,
we fall back to a generated name based on the metadata pointer.  This
ensures that we won't crash, and if the name turns up in the debugger
or somewhere it should be obvious that something went wrong.

rdar://107718586
2023-04-13 15:34:03 +01:00
Alastair Houghton
e5680de071 [Backtracing] Security improvements.
Use `task_read_for_pid()` rather than having the crashing program pass its
own task port through.  This opts us in to additional OS security measures
surrounding the use of this call.

rdar://107362003
2023-04-12 12:48:33 +01:00
Evan Wilde
f47d56336e Replace mismatched delete with swift_cxx_deleteObject
The `allocatedEntry` is allocated with `swift_cxx_newObject` so it
should be deallocated with the `swift_cxx_deleteObject`.
2023-04-11 14:15:24 -07:00
Alastair Houghton
316dfaffa1 Merge pull request #64714 from al45tair/eng/PR-107360391
[Backtracing] Support specifying a hard-coded path for swift-backtrace.
2023-03-30 18:28:48 +01:00
Mike Ash
e439d271b2 [Runtime] Redeclare _dyld_lookup_section_info as weak.
This lets us build against it and still run on systems without it.
2023-03-29 15:39:01 -04:00
Alastair Houghton
0261a29fee [Backtracing] Support specifying a hard-coded path for swift-backtrace.
Add a way to disable dynamic lookup of the backtracer path, for situations
where a hard-coded path makes more sense.

rdar://107360391
2023-03-29 15:08:48 +01:00
Mike Ash
f7e325663a [Runtime] Avoid referring to enum _dyld_section_location_kind.
If the SDK has dyld_priv.h but doesn't have enum _dyld_section_location_kind, we can't use enum _dyld_section_location_kind and it's hard to detect that. Instead, just use `int`, and use #defines for the values.
2023-03-29 09:33:27 -04:00
Ben Barham
20ba6125ae Revert "[Runtime] Redeclare _dyld_lookup_section_info as weak."
This reverts commit a4c572fc03, to be
added back in after https://github.com/apple/swift/pull/64042.
2023-03-28 14:32:23 -07:00
Konrad `ktoso` Malawski
0586c14b60 [Concurrency] SerialExecutor.isSameExclusiveExecutionContext (#64604) 2023-03-28 15:56:28 +09:00
Alastair Houghton
0f98eccb73 Merge pull request #64611 from al45tair/eng/PR-107192120
[Backtracing] Add an option to output to stderr.
2023-03-27 15:37:05 +01:00
Alastair Houghton
9209bdd8c4 [Backtracing] Add an option to output to stderr.
In CI, it would be better if the backtraces went to stderr rather than
stdout, so provide an option for that.

rdar://107192120
2023-03-24 17:13:52 +00:00
Mike Ash
a4c572fc03 [Runtime] Redeclare _dyld_lookup_section_info as weak.
This allows us to run even if that call is not available at runtime.
2023-03-24 10:32:04 -04:00
Slava Pestov
5f0d7320df Runtime: Fix MetadataCacheKey::installInto() for variadic generics 2023-03-22 16:53:25 -04:00
Slava Pestov
9acd2446cc Runtime: MetadataCacheKey is bit too large to pass by value 2023-03-22 16:53:25 -04:00
Slava Pestov
c50e8bb5de Runtime: Check same-type pack requirements in checkGenericPackRequirement() 2023-03-17 22:19:18 -04:00
Slava Pestov
f12be70da5 Runtime: Demangling DependentMemberType whose base type is a pack type 2023-03-17 22:19:18 -04:00
Slava Pestov
a21b0d9749 Runtime: Check layout pack requirements in checkGenericPackRequirement() 2023-03-17 22:19:18 -04:00
Slava Pestov
d17baed985 Runtime: Check superclass pack requirements in checkGenericPackRequirement() 2023-03-17 22:19:17 -04:00
Dario Rexin
2f8c1a402c [IRGen] Make pointers to accessor functions in layout strings relative (#64155)
* [IRGen] Make pointers to accessor functions in layout strings relative

rdar://106319336

Pointers embedded in static layout strings should always be relative, so layout strings can reside in read-only memory.

* Properly handle reference storage ownership

* Pass layout tag and metadata / type layout ppointers separately

* Layout string instantiation fully working

* Fix cases where hasLayoutString flag was not set when it should have

* Update include/swift/ABI/Metadata.h
2023-03-17 09:02:51 -07:00
swift-ci
6f31afb7a3 Merge pull request #64427 from al45tair/eng/PR-106813646
[Backtracing] Disable the warning about not finding swift-backtrace.
2023-03-16 12:32:09 -07:00
Alastair Houghton
725d2e1d1b [Backtracing] Disable the warning about not finding swift-backtrace.
This needs to be disabled for now.  We'll re-enable it later.

rdar://106813646
2023-03-16 17:13:10 +00:00
Kuba (Brecka) Mracek
78a406a75d In Metadata.h/.cpp, start building the relative wtable support even on platforms that don't use it yet (#64354) 2023-03-15 09:41:40 -07:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Arnold Schwaighofer
7afab4735d Runtime: Fix swift_getAssociatedTypeWitnessRelativeSlowImpl for MetadataOrPack change 2023-03-14 07:58:12 -07:00
Mike Ash
1dfd1ede9e Merge pull request #64327 from mikeash/fewer-news
[Runtime] Remove a few uses of operator new/delete.
2023-03-14 08:57:44 -04:00
Joe Groff
730c5cf632 Merge pull request #64295 from jckarter/noncopyable-hide-field-types
Don't let reflection handle noncopyable types yet.
2023-03-13 17:01:25 -07:00
Mike Ash
69d0905e80 [Runtime] Remove a few uses of operator new/delete.
Replace them with swift_cxx_newObject/swift_cxx_deleteObject to avoid calling overridden global operators. Overridden global operators can sometimes fail when called from places the authors didn't expect.

The particular uses being changed here are:

1. Creation of new SingletonMetadataCacheEntry objects.
2. Allocation of the _globalIvarOffsets array in initGenericObjCClass.
3. Creation/destruction of SwiftTLSContext objects.

rdar://106238547
2023-03-13 16:05:37 -04:00
Joe Groff
4d6d7657fa Don't let reflection handle noncopyable types yet.
We don't have any language or runtime support for noncopyable types as generic
or dynamic types yet, and existing reflection code almost certainly assumes it
can copy the values it's working with, and will trap or corrupt state if it does
so with noncopyable types. But a class can have noncopyable fields while the
type itself is copyable, and existing code assumes that it can use `Mirror` or
other reflection mechanisms to safely traverse the contents of an arbitrary
class.

Allow this sort of code to continue working, while still preparing for forward
compatibility with future runtimes that do support noncopyable generics, by
emitting the type references for fields using a function that probes the
address of a new symbol in the Swift runtime. The symbol will either be missing
or defined with an absolute address of zero in current or previous runtime
versions, but can be changed to a non-null address in the future.
2023-03-13 11:50:24 -07:00
Joe Groff
e4d3d6d838 Merge pull request #64215 from jckarter/noncopyable-hide-type-metadata-records
IRGen: Hide type metadata records for noncopyable types from discovery by existing runtimes.
2023-03-09 11:08:28 -08:00
Slava Pestov
d776f71b4f Runtime: Teach checkGenericRequirements() to check same-shape and conformance pack requirements 2023-03-09 09:42:00 -05:00
Slava Pestov
2cf1241a7c Runtime: Extract checkGenericRequirement() from checkGenericRequirements() 2023-03-09 01:54:51 -05:00
Slava Pestov
17086962c3 Runtime: Add swift_getTypePackByMangledName() entry point
For now this has SWIFT_RUNTIME_LIBRARY_VISIBILITY, but in the
future we might want to make it public so that IRGen can use it
to build packs out of concrete types.
2023-03-09 01:54:51 -05:00
Slava Pestov
cdd1c6da57 Runtime: Move MetadataOrPack to Private.h 2023-03-09 01:54:51 -05:00
Slava Pestov
ae2c3a5820 Runtime: Fix silly bug in MetadataCacheKey::operator== 2023-03-09 01:54:51 -05:00
Slava Pestov
2b68ee1065 Runtime: Teach _gatherWrittenGenericArgs() about metadata packs 2023-03-09 01:54:51 -05:00
Slava Pestov
bcf6f26579 Runtime: Make SubstGenericParametersFromWrittenArgs and _gatherWrittenGenericArgs() completely private to MetadataLoookup.cpp 2023-03-09 01:54:51 -05:00
Slava Pestov
39aa4d4001 Runtime: Preliminary refactoring for demangling variadic generic types to metadata 2023-03-09 01:54:51 -05:00