Commit Graph

41 Commits

Author SHA1 Message Date
Tim Kientzle
cb03a459fe Make SwiftValue == support unconditional
PR #71620 made this behavior conditional as a way to help
provide binary compatibility for legacy software that might
be relying on the old behavior.

So far, it appears the only such problems arose from the
SwiftObject behavior changes, not from SwiftValue behavior.
So let's optimistically back this out and make the new behavior
unconditional.

Resolves rdar://127839540
2024-05-09 14:38:36 -07:00
Tim Kientzle
fac88221c5 Fix hash/isEqual interop conditionals, update tests
Github PR #71620 mixed up one of the bincompat conditionals.
It also had some errors in the tests for ObjC interop.

For now, this leaves the legacy behavior in place for
all Apple platforms.
2024-02-27 17:46:49 -08:00
Tim Kientzle
b3ed7aee24 Bincompat hooks for revised hash/isEqual interop
This adds in hooks so that the new hash/isEqual interop
(which bridges Obj-C hash/isEqual: calls to the corresponding
Swift Hashable/Equatable conformances) can be selectively
disabled based on the OS and/or client.

For now, enable the new semantics everywhere except Apple platforms
(which have legacy apps that may be relying on the old semantics).
2024-02-14 12:13:07 -08:00
Tim Kientzle
2cbd70e531 Make SwiftValue hash/equality work the same as SwiftObject
Update PR #68720 with lessons learned in reviewing #69464

Background:

* SwiftValue can expose Swift value types (structs/enums)
  to ObjC by wrapping them in an Obj-C object on the heap

* SwiftObject is the Obj-C type that Swift class objects all
  inherit from (when viewed from Obj-C).  This allows arbitrary
  Swift class objects to be passed into Obj-C.

History:

* PR #4124 made Obj-C `-hash` and `-isEqual:` work for SwiftValue for Hashable Swift types

* PR #68720 extended SwiftValue to also support Equatable Swift types

* PR #69464 added similar support to SwiftObject

In the process of working through #69464, we found a better way
to handle an ObjC request for `-hash` for a type that is Swift
Equatable but not Hashable.  This PR updates SwiftValue to use
the same approach.  The approach considers three cases:

1. A Hashable type can forward both `-hash` and `-isEqual:` to
   the Swift object.

2. A type that is neither Equatable nor Hashable can implement
   `-isEqual:` as the identity check and `-hash` as returning
   the address of the object in memory.

3. A type is that Equatable but not Hashable is more complex.

In this last case, we can easily forward `-isEqual:` to the
Equatable conformance but ObjC also requires us to
always provide a compatible `-hash` implementation.
The only way to do this is to have `-hash` return a constant,
but that is a very bad idea in general, so we're also including
a log message whenever we see a request for `-hash` on
a Swift value that is Equatable but not Hashable.
To limit performance problems from the logging itself, we
emit the log message only once for each type.
2023-11-02 11:24:04 -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
Tim Kientzle
5cff70337a Cache Equatable conformance if Hashable is not present 2023-09-27 19:15:37 -07: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
Mike Ash
fe7e13bba5 [Runtime][IRGen] Sign type context descriptor pointers.
Ensure that context descriptor pointers are signed in the runtime by putting the ptrauth_struct attribute on the types.

We use the new __builtin_ptrauth_struct_key/disc to conditionally apply ptrauth_struct to TrailingObjects based on the signing of the base type, so that pointers to TrailingObjects get signed when used with a context descriptor pointer.

We add new runtime entrypoints that take signed pointers where appropriate, and have the compiler emit calls to the new entrypoints when targeting a sufficiently new OS.

rdar://111480914
2023-07-07 18:10:35 -04:00
Saleem Abdulrasool
a8b0ee24dc runtime: blanket application of namespacing and inclusion of new
Apply a blanket pass of including `new` for the placement new allocation
and namespacing the call to the global placement new allocator.  This
should repair the Android ARMv7 builds.
2022-04-14 14:21:12 -07:00
David Smith
1efa946caf Remove stdlib and runtime dependencies on Foundation and CF 2019-09-12 18:03:14 -07:00
Arnold Schwaighofer
fe69a86929 Revert "Remove stdlib and runtime dependencies on Foundation and CF"
It is causing bots to fail.

* Revert "The __has_include(<os/system_version.h>) branch here wasn't quite right, we'll just use the dlsym one for now"

This reverts commit f824922456.

* Revert "Remove stdlib and runtime dependencies on Foundation and CF"

This reverts commit 3fe46e3f16.

rdar://54709269
2019-08-26 13:00:08 -07:00
David Smith
3fe46e3f16 Remove stdlib and runtime dependencies on Foundation and CF 2019-08-23 14:10:23 -07:00
Mike Ash
317451c8ee [Runtime][Stdlib][Overlays] Add comments to all the renamed classes explaining the rename and noting that the old name cannot be used due to conflicts.
rdar://problem/35768222
2018-09-20 12:07:30 -04:00
Mike Ash
798edb9d0e [Runtime][Stdlib][Overlays] Rename various Objective-C classes and methods that would conflict when loading old Swift libraries into a process alongside ABI-stable libraries.
rdar://problem/35768222
2018-09-13 16:55:10 -04:00
Doug Gregor
3464929638 [ABI] Rework existential type metadata to use ProtocolDescriptorRef.
Use ProtocolDescriptorRefs within the runtime representation of
existential type metadata (TargetExistentialTypeMetadata) instead of
bare protocol descriptor pointers. Start rolling out the use of
ProtocolDescriptorRef in a few places in the runtime that touch this
code. Note that we’re not yet establishing any strong invariants on
the TargetProtocolDescriptorRef instances.

While here, replace TargetExistentialTypeMetadata’s hand-rolled pointer 
arithmetic with swift::ABI::TrailingObjects and centralize knowledge of
its layout better.
2018-07-20 20:54:49 -07:00
troughton
cf28ff448c Remove TwoWordPair and use SwiftCC instead. 2018-02-03 09:43:00 +13:00
Greg Parker
7b9224794e [runtime] Reinstate TwoWordPair hack for swiftcall returns. (#14079)
clang is miscompiling some swiftcall functions on armv7s.
Stop using swiftcall in some places until it is fixed.

Reverts c5bf2ec (#13299).

rdar://35973477
2018-01-23 01:04:01 -08:00
Karoy Lorentey
f2a96496a0 [StringGuts] Support for 32-bit platforms
Add 32-bit support to the new StringGuts.
2018-01-21 12:36:09 -08:00
Thomas Roughton
c5bf2ec553 [runtime] Remove TwoWordPair and use the Swift calling convention instead. (#13299) 2017-12-07 19:27:24 -08:00
Greg Parker
1e894cd80b [runtime] Clean up symbols in error machinery. (#12853)
* [runtime] Clean up symbols in error machinery.

* [runtime] Clean up symbols in Foundation overlay.

* [runtime] Clean up symbols in collections and hashing.

* [runtime] Remove symbol controls from the Linux definition of swift_allocError.

* [tests] Add more stub functions for tests that link directly to the runtime.
2017-11-15 22:20:11 -08:00
Greg Parker
dd38ace506 [runtime] Fix more const cast warnings. (#11725)
* [runtime] Fix more const cast warnings.
2017-09-05 13:13:01 -07:00
Arnold Schwaighofer
ca63326e1b Delete unused existential value witnesses from the old existential
implementation

And remove the SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS flag.
2017-06-02 14:34:41 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Slava Pestov
1615915780 Runtime: Dynamic casts to subclass existentials 2017-04-27 20:46:36 -07:00
John McCall
2c40b39f26 Move runtime functions for casting into their own header. 2017-04-17 17:16:13 -04:00
Arnold Schwaighofer
d5cbb0bd62 Runtime changes for the copy-on-write existential implementation
Adds the runtime implementation for copy-on-write existentials. This support is
enabled if SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS is defined. Focus is on
correctness -- not performance yet.

Don't use allocate/deallocate/projectBuffer witnesses for globals in cow
existential mode.

Use SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS configuration to set the default for
SILOptions.

This includes an IRGen fix to use the right projection in
emitMetatypeOfOpaqueExistential if SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS is set.

Use unknownRetain instead of native retain in dynamicCastToExistential.
2017-03-15 14:54:55 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Saleem Abdulrasool
c67a33fbc7 build: remove TARGET_SDKS from the runtime
The runtime and stubs are built for ALL targets, not specific ones.  This allows
us to configure when cross-compiling to Windows again.  Collapse the dual
addition of the swiftRuntime into a single build.  This unifies the runtime
build for the apple and non-Apple SDKs.  The difference here was the ObjC
interop sources.  In order to deal with that unification add a CPP macro to
indicate whether the interop sources should be included or not.
2016-12-03 17:02:44 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
practicalswift
f44686d825 [gardening] Fix trailing whitespace in *.cfg.in, *.html, *.mm and *.sil files 2016-10-29 14:06:43 +02:00
Maxim Moiseev
46b860b5f8 [stdlib] returning false in case where comparison cannot succeed in SwiftValue (#4813) 2016-09-20 10:01:00 -07:00
Dmitri Gribenko
dfb4f56e55 runtime: rename _TMps8Hashable to HashableProtocolDescriptor 2016-08-31 09:53:39 -07:00
Greg Parker
deb562dccf [stdlib] Remove struct SwiftObject_s. (#4501)
[stdlib] Remove struct SwiftObject_s.

SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS works just as well with less redundancy.
2016-08-25 00:33:43 -07:00
John McCall
b937bdf717 Dynamic casts to AnyObject should succeed for an arbitrary source
type because we can always make a SwiftValue.

rdar://26268575
2016-08-19 10:36:18 -07:00
Joe Groff
f998c624e6 Runtime: Add a convenient -[_SwiftValue _swiftTypeName] method for debugging.
This makes it a bit easier to diagnose unexpected boxing problems in the debugger, by allowing `po [value _swiftTypeName]` to work, instead of forcing users to know how to call `swift_getTypeName` from lldb themselves.
2016-08-15 13:53:59 -07:00
Dmitri Gribenko
783fafa36a runtime: rename SwiftValue to _SwiftValue (it is a private class) 2016-08-10 15:45:16 -07:00
Dmitri Gribenko
45ab914bb1 runtime: make SwiftValue use the Hashable conformance, if available
If a value error wrapped in a SwiftValue box conforms to Hashable, the box now
uses the Swift's conformance to Hashable.

Part of rdar://problem/27574348.
2016-08-09 00:49:20 -07:00
Luke Larson
74e0498015 Revert "Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs."
This reverts commit 62d1fa760c.
2016-07-19 15:18:17 -07:00
Mishal Shah
62d1fa760c Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-07-19 22:31:34 +02:00
Joe Groff
9cba38537e Runtime: Forward SwiftValue -description and -debugDescription to the boxed value.
Following the example of SwiftObject, use swift_getSummary to get the description string for a Swift value as the description of a boxed SwiftValue.
2016-07-18 12:21:54 -07:00
Joe Groff
bc8433f186 Runtime: Implement an opaque 'SwiftValue' ObjC class to hold bridged values.
If there's no better mapping for a Swift value into an Objective-C object for bridging purposes, we can fall back to boxing the value in a class. This class doesn't have any public interface beyond being `NSObject`-conforming in Objective-C, but is recognized by the Swift runtime so that it can be dynamically cast back to the boxed type.
2016-07-15 15:56:25 -07:00