Commit Graph

3150 Commits

Author SHA1 Message Date
Arnold Schwaighofer
b0424759d7 Add support for objective c protocol symbolic references
Using symbolic references instead of a text based mangling avoids the
expensive type descriptor scan when objective c protocols are requested.

rdar://111536582
2023-10-05 13:11:32 -07:00
Tim Kientzle
c078479ce9 [Casting] Make more casts look inside __SwiftValue
The following sequence of casts would previously succeed
```
struct S {}
let s = S() as AnyObject
s as? NSObject
```
The final cast here should fail, since `S` clearly is not a
subclass of NSObject.  But it would previously succeed because
the `as AnyObject` would package the struct into an ObjC-compatible
`__SwiftValue` class.  This latter is an NSObject subclass.

This bug was fixed in the main `swift_dynamicCast` runtime function
some time ago, but not in the `swift_dynamicCastObjCClass` which
is chosen by IRGen to optimize casts to ObjC class types.
This PR changes the latter to test for `__SwiftValue` and fall
back to the former in that case in order to get the correct
handling.  Falling back to `swift_dynamicCast` also ensures that
the contents of the `__SwiftValue` are correctly unwrapped/bridged/etc
as necessary to fully support Swift casting semantics.

Resolves: rdar://111422725

TODO: I've left an XFAILed test here about the behavior of `type(of:)`
with `__SwiftValue` boxes.
2023-10-03 14:50:23 -07:00
Tony Allevato
5f5b24f96e [C++20] Make operator{==,!=}s const.
In C++20, the compiler will synthesize a version of the operator
with its arguments reversed to ease commutativity. This reversed
version is ambiguous with the hand-written operator when the
argument is const but `this` isn't.
2023-10-03 17:10:57 -04:00
Mike Ash
e2b4d2f465 [Runtime] Fix lazy ivar list copying.
The `ivar` reference still pointed to the original list, so the first modification went to the wrong place. Change `ivar` to a pointer, and re-point it when we copy the list.

rdar://116339597
2023-10-02 16:06:01 -04:00
Tim Kientzle
b35987fdcd Merge pull request #68720 from tbkka/tbkka-SwiftValue-Equatable
Make ObjC isEqual: delegate to Equatable when Hashable isn't available
2023-09-29 12:28:56 -07:00
Tim Kientzle
b1b78184dc Make the caches be uintptr_t
This simplified a lot of things.  (Thanks @MikeAsh for the
suggestion!)

Also reorganized the code a bit.
2023-09-28 12:02:31 -07:00
Mike Ash
641870a205 [Runtime] Lazily copy ivar list in initObjCClass.
There's often nothing that needs to be fixed up in the ivar list. In that case, we can avoid copying it. This saves time and memory, and allows the class rodata to be in immutable memory.

rdar://116189946
2023-09-28 14:19:04 -04:00
Tim Kientzle
5cff70337a Cache Equatable conformance if Hashable is not present 2023-09-27 19:15:37 -07:00
Alastair Houghton
c9efa69ef1 [Linux] Make the backtracing symbol reference conditional.
On the LSan builds, we disable the backtracer, which results in a
link error because we completely remove the code from libswiftCore.

rdar://116105222
2023-09-27 09:56:22 +01:00
Alastair Houghton
62c4999249 Merge pull request #68669 from al45tair/eng/PR-115774613
[Linux] Force the inclusion of the backtracing code when static linking.
2023-09-26 22:16:06 +01:00
Tim Kientzle
659d1cfb13 Make ObjC isEqual: delegate to Equatable when Hashable isn't available
When a Swift struct gets bridged to Obj-C, we box it into an opaque
`_SwiftValue` Obj-C object.  This object previously supported the
Obj-C `isEqual:` and `hash` selectors by dispatching to the Swift
Hashable conformance, if present.

This does not work if the Swift struct conforms to Equatable but
does not conform to Hashable.  This case seems to have been
overlooked in PR #4124.

This PR extends the earlier work to support `isEqual:` by
first checking for a Hashable conformance, then falling back
on an Equatable conformance if there is no Hashable conformance.

Resolves rdar://114294889
2023-09-22 17:58:22 -07:00
Slava Pestov
156fd080e7 Merge pull request #68700 from slavapestov/fix-rdar115459973
ASTDemangler: Fix round-tripping of SILBoxTypeWithLayout
2023-09-22 19:25:11 -04:00
Slava Pestov
57b702be07 ASTDemangler: Fix round-tripping of SILBoxTypeWithLayout
The more awkward setup with pushGenericParams()/popGenericParams()
is required so that when demangling requirements and field types
we get the correct pack-ness for each type parameter. The pack-ness
is encoded as part of the generic signature, and not as part of
the type parameter mangling itself.

Fixes the ASTDemangler issue from rdar://problem/115459973.
2023-09-22 11:27:18 -04:00
Dario Rexin
70e7df902e Merge pull request #68675 from drexin/wip-remove-nul
[IRGen+Runtime] Remove unnecessary null terminator in layout strings
2023-09-21 14:56:07 -07:00
Dario Rexin
75f6103898 [IRGen+Runtime] Remove unnecessary null terminator in layout strings
The last offset also signals the end of the layout string, so the null terminator is unnecessary
2023-09-21 10:46:19 -07:00
Dario Rexin
56d0975668 [Runtime] Add layout string handling in swift_arrayAssignWithCopyFrontToBack
By using a specialize function, we only call through the witness table and fetch the layout string once for the whoe buffer, instead of once per element.
2023-09-21 09:52:46 -07:00
Alastair Houghton
598bce2404 [Linux] Force the inclusion of the backtracing code when static linking.
When we're statically linking the standard library, we need to force
the inclusion of the backtracing code in the runtime, otherwise we don't
get on-crash backtraces.

Also, add a test to make sure that this works.

rdar://115774613
2023-09-21 15:03:51 +01:00
Alejandro Alonso
60774fb722 Merge pull request #68450 from Azoy/fix-array-like
[IRGen] Some fixes for raw layout types and noncopyable types in the stdlib
2023-09-13 21:49:48 -07:00
Alejandro Alonso
ab143ee3ee Some fixes for raw layout types and noncopyable types in the stdlib 2023-09-11 20:45:09 -07:00
Dario Rexin
c1b07f0f99 Merge pull request #68283 from drexin/wip-narf
[Runtime] Use handleRefCountsAssignWithCopy in swift_generic_assignWi…
2023-09-09 23:09:31 -07:00
Alejandro Alonso
1375ce6247 Merge pull request #68359 from Azoy/packs-pack-packs
[Runtime] Add a function to check type creation
2023-09-07 07:24:55 -07:00
Alejandro Alonso
80187e8096 Expect caller heap pack and rename
Fix comment
2023-09-06 21:37:00 -07:00
Alejandro Alonso
3dbad6e1fd Add a runtime function to check type creation 2023-09-06 11:32:22 -07:00
Evan Wilde
176bf3417e Merge pull request #65076 from etcwilde/ewilde/metadata-cleanup
Replace mismatched `delete` with `swift_cxx_deleteObject`
2023-09-01 20:31:29 -07:00
Dario Rexin
ee28da2bf2 [Runtime] Use handleRefCountsAssignWithCopy in swift_generic_assignWithCopy
rdar://114840977

This was accidentally committed after debugging an issue
2023-09-01 14:53:52 -07:00
Dario Rexin
6e3d1ae726 [Runtime] Check if objc pointers are tagged before masking
In layout string value witnesses runtime functions, if an objc pointer is tagged, there is no ref counting necessary.
2023-08-30 18:50:38 -07:00
Dario Rexin
8fe4c77b3e [Runtime] Properly mask pointers before ref counting and other fixes
The fixes are all around enum support. Some tag comparisons and pointer masking were incorrect and led to crashes.

rdar://114575149
2023-08-30 17:54:47 -07:00
Saleem Abdulrasool
898f9efe3e Merge pull request #68099 from hjyamauchi/abort
Fix a fatal error not-terminating issue in Windows
2023-08-27 12:08:32 -07:00
Hiroshi Yamauchi
5fc3ad3a81 Fix a fatal error not-terminating issue in Windows.
Fix the issue that fatal errors in certain cases don't terminate the
process and the process keeps running in Windows by disabling the
exception swallowing that supressed the illegal instruction exceptions
coming from llvm.trap.
2023-08-25 13:04:36 -07:00
Dario Rexin
030daee5ad Merge pull request #68042 from drexin/wip-layout-strings-work
Improve layout strings runtime code and fix several issues
2023-08-24 16:03:34 -07:00
Kshitij Jain
d5a3e2e630 [AutoDiff] Fixes memory leaks in autodiff linear map context allocation builtins (#67944)
When the differentiating a function containing loops, we allocate a linear map context object on the heap. This context object may store non-trivial objects, such as closures, that need to be released explicitly. Fix the autodiff linear map context allocation builtins to correctly release such objects and not just free the memory they occupy.
2023-08-24 13:57:10 -07:00
Dario Rexin
e3a1bac859 [Runtime] Use copy of addrOffset in single payload assign with copy 2023-08-24 11:01:14 -07:00
Dario Rexin
21f4064380 [Runtime] Fix singlePayloadEnumSimpleAssignWithCopy 2023-08-21 10:59:15 -07:00
Dario Rexin
fd967fd9e3 [Runtime] Properly handle boxed references in layout string instantiation 2023-08-21 10:58:25 -07:00
Dario Rexin
7e3f56de24 [Runtime] Fix generic existentials in layout strings 2023-08-21 10:57:33 -07:00
Dario Rexin
56048ac19f [Runtime+IRGen] Fix existential offset for multiple protocol witnesses 2023-08-21 10:57:06 -07:00
Dario Rexin
8b3aaf5423 [Runtime] Compute end before looping over single payload ref count 2023-08-21 10:56:42 -07:00
Dario Rexin
7c0203dd55 [Runtime] Combine copy and destroy in assignWithCopy 2023-08-21 10:56:19 -07:00
Dario Rexin
8ab845fdca [Runtime+IRGen] Fix offsets of existentials in layout strings 2023-08-21 10:55:51 -07:00
Dario Rexin
4f6e69b35f [Runtime] Reduce instruction count in simple layout string operations 2023-08-21 10:55:25 -07:00
Dario Rexin
30d628270b [IRGen+Runtime] Make more fine grained copies in layout string runtime functions 2023-08-21 10:55:02 -07:00
Dario Rexin
27b1764d13 [Runtime+IRGen] Fix layout string flag in type layout and add array functions 2023-08-21 10:54:35 -07:00
Dario Rexin
31de67c713 [IRGen+Runtime] Further fixes for layout strings 2023-08-21 10:54:14 -07:00
Dario Rexin
4a395cb8d3 [Runtime+IRGen] Some fixes and optimizations for layout strings 2023-08-21 10:53:44 -07:00
Dario Rexin
2f61e2a9c9 [Runtime] Further abstract shared functionality in BytecodeLayouts 2023-08-21 10:53:14 -07:00
Dario Rexin
ec3a2dc370 [Runtime] Templatize shared functionality in BytecodeLayouts 2023-08-21 10:52:39 -07:00
Dario Rexin
c25b3b43a2 [Runtime] Restructure BytecodeLayouts 2023-08-21 10:52:24 -07:00
Alejandro Alonso
44198d16a4 Merge pull request #67611 from Azoy/raw-types-are-cool!
[WIP] Implement dependent layouts for raw types
2023-08-16 06:55:42 -07:00
Alejandro Alonso
c20ab10cef Use an i32 argument instead of size
more int32

zzz
2023-08-15 19:49:44 -07:00
Mike Ash
dbd2f82739 [Runtime] Fix up the heap destroyer in objc_setClassCopyFixupHandler.
We fix up the VWT pointer, but not the heap destroyer. This doesn't matter for classes which use ObjC refcounting, which is the common case for dynamic subclasses, because that doesn't use the heap destroyer pointer. But it does matter for classes that use native Swift refcounting, such as classes that don't inherit from NSObject, or actors.

rdar://113657917
2023-08-10 15:19:18 -04:00