Commit Graph

16 Commits

Author SHA1 Message Date
Tim Kientzle
48eb993349 Verify that hash/equality behavior is all consistent
It's not obvious that we can check that hash/equality behavior
is entirely correct, since there are two very different behaviors
which depend on environmental factors that are not easy to test for.

But we can do a quick probe to see whether the current environment
seems to be offering the legacy or non-legacy behavior and then
carefully verify that everything else is consistent with our initial
probe.

This gives us confidence that at least we're not getting inconsistent
behavior.
2024-07-09 13:30:13 -07:00
Tim Kientzle
716b58e956 Handle ObjC -hash differently for Equatable and non-Equatable types
For an Equatable type, we need a hash implementation that
is compatible with any possible definition of `==`.
Conservatively, that means `-hash` must return a constant.

For non-Equatable types, we know that `==` is identity based,
so we can get better hash behavior by using the object address.

Caveat:  This means that non-Equatable types will do two
protocol conformance checks on every call to `hash`.
2023-10-31 14:26:20 -07:00
Tim Kientzle
6fd39741d6 Fix a number of issues (review feedback)
* Fix how we were looking for common parent class
* Use a constant hashValue for types that are Equatable but not Hashable
2023-10-30 15:57:47 -07:00
Tim Kientzle
a840c69392 Use Swift Equatable and Hashable conformances from ObjC
If a Swift type implements Equatable and/or Hashable and
we then pass that object into ObjC, we want ObjC
`isEqual:` and `hashValue` to use that.  This allows
ObjC code to build ObjC collections of Swift objects.

* Support for Hashable struct/enum types was implemented in #4124
* Support for Equatable struct/enum types was implemented in #68720
* This implements support for Hashable and Equatable _class_ types

Caveats:
1. This does a lot of dynamic lookup work for each operation, so is
   inherently rather slow.  Unlike the struct/enum case, there is no convenient
   place to cache the conformance information, so it's not clear that there is a
   viable way to make it significantly faster.
2. This is a behavioral change to low-level support code.  There is a
   risk of breaking code that may be relying on the old behavior.
2023-10-27 12:01:44 -07:00
Mike Ash
7d4bf753f4 [Test] Don't test demangling of SwiftObject's name, as it's subject to change.
rdar://problem/57163094
2019-11-15 12:56:24 -05:00
Mike Ash
597dcd8f3f [Stdlib][Frontend][CMake] Remove SWIFT_DARWIN_ENABLE_STABLE_ABI_BIT option, make it permanently on. 2019-03-13 09:31:50 -04:00
Greg Parker
368ca184fa [runtime] Fix some bugs when the stable ABI's is-Swift bit is set. (#21114)
* cmake: Propagate SWIFT_DARWIN_ENABLE_STABLE_ABI_BIT to overlay builds.
* runtime: Clear the correct bit in getROData()
* test/IRGen/objc_class_export.swift: Allow either is-Swift bit.
* test/stdlib/SwiftObjectNSObject.swift: Allow either name for SwiftObject.
2018-12-07 12:47:39 -08:00
Saleem Abdulrasool
687aeaa37d runtime: remove unnecessary preprocessor condition, flip cases (NFC)
The use of `__APPLE__` is unnecessary as the case is guarded by the
`SWIFT_DARWIN_ENABLE_STABLE_ABI_BIT` preprocessor guard which is implicitly
specific to that environment.  Additionally, flip the condition around so that
the positive (which is the future) appears ahead of the negative case.
2018-09-20 15:27:48 -07:00
Greg Parker
072e9827aa Use SwiftObject's old name when building for the pre-stable ABI.
rdar://35554345
2018-03-26 14:04:30 -07:00
Greg Parker
9637b4a6e1 [runtime] Rename class SwiftObject to Swift._SwiftObject. (#13748)
SwiftObject needs to be renamed to avoid ObjC class name collisions between
the Swift stable ABI and older Swift apps.

rdar://35554345
2018-01-09 16:16:55 -08:00
Greg Parker
0bae31c1f0 [runtime] Add some missing -isNSWhatever__ methods to SwiftObject. (#11891)
SR-5636, rdar://33764085
2017-09-13 03:01:37 -07:00
Greg Parker
f3bd55eb52 [runtime] Implement SwiftObject -methodForSelector: and +instanceMethodForSelector:.
Fixes SR-5577 and rdar://33606034.
2017-08-23 17:11:47 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01: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
cc852042c9 [gardening] Fix accidental trailing whitespace. 2016-10-29 10:22:58 +02:00
Max Moiseev
9fc37efee4 [test] renaming test/1_stdlib to just test/stdlib 2016-09-01 16:51:43 -07:00