Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resume building releases with Xcode 13 #7426

Merged
merged 4 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ x.y.z Release notes (yyyy-MM-dd)
=============================================================
### Enhancements
* Add additional `observe` methods for Objects and RealmCollections which take a `PartialKeyPath` type key path parameter.
* The release package once again contains Xcode 13 binaries for iOS.

### Fixed
* `Map<Key, Value>` did not conform to `Codable`. ([Cocoa #7418](https://github.com/realm/realm-cocoa/pull/7418), since v10.8.0)
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile.releasability
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xcodeVersions = ['12.2', '12.4', '12.5.1']
xcodeVersions = ['12.2', '12.4', '12.5.1', '13.0']
platforms = ['osx', 'ios', 'watchos', 'tvos', 'catalyst']
carthagePlatforms = ['osx', 'ios', 'watchos', 'tvos']
platformNames = ['osx': 'macOS', 'ios': 'iOS', 'watchos': 'watchOS', 'tvos': 'tvOS', 'catalyst': 'Catalyst']
Expand Down
8 changes: 5 additions & 3 deletions RealmSwift/BSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,20 @@ extension MinKey: BSON {
/// Return this BSON as a `Decimal128` if possible.
/// This will coerce numeric cases (e.g. `.double`) into a `Decimal128` if such coercion would be lossless.
public func asDecimal128() -> Decimal128? {
let str: String
switch self {
case let .decimal128(d):
return d
case let .int64(i):
return try? Decimal128(string: String(i))
str = String(i)
case let .int32(i):
return try? Decimal128(string: String(i))
str = String(i)
case let .double(d):
return try? Decimal128(string: String(d))
str = String(d)
default:
return nil
}
return try? Decimal128(string: str)
Comment on lines +382 to +395
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change made this function compile in 5ms rather than 150ms (as reported by -debug-time-function-bodies)

}

/// Return this BSON as a `T` if possible, otherwise nil.
Expand Down
20 changes: 10 additions & 10 deletions RealmSwift/Decimal128.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public final class Decimal128: RLMDecimal128, Decodable {

/// The mininum value for Decimal128
public static var min: Decimal128 {
__minimumDecimalNumber as! Self
unsafeDowncast(__minimumDecimalNumber, to: Self.self)
}

/// The maximum value for Decimal128
public static var max: Decimal128 {
__maximumDecimalNumber as! Self
unsafeDowncast(__maximumDecimalNumber, to: Self.self)
}
}

Expand Down Expand Up @@ -201,7 +201,7 @@ extension Decimal128 {

/// The magnitude of this Decimal128.
public var magnitude: Magnitude {
self.__magnitude as! Magnitude
unsafeDowncast(self.__magnitude, to: Magnitude.self)
}

/// Adds two decimal128 values and produces their sum.
Expand All @@ -210,7 +210,7 @@ extension Decimal128 {
/// - lhs: The first Decimal128 value to add.
/// - rhs: The second Decimal128 value to add.
public static func + (lhs: Decimal128, rhs: Decimal128) -> Decimal128 {
lhs.decimalNumber(byAdding: rhs) as! Decimal128
unsafeDowncast(lhs.decimalNumber(byAdding: rhs), to: Decimal128.self)
}

/// Subtracts one Decimal128 value from another and produces their difference.
Expand All @@ -219,7 +219,7 @@ extension Decimal128 {
/// - lhs: A Decimal128 value.
/// - rhs: The Decimal128 value to subtract from `lhs`.
public static func - (lhs: Decimal128, rhs: Decimal128) -> Decimal128 {
lhs.decimalNumber(bySubtracting: rhs) as! Decimal128
unsafeDowncast(lhs.decimalNumber(bySubtracting: rhs), to: Decimal128.self)
}

/// Multiplies two Decimal128 values and produces their product.
Expand All @@ -228,7 +228,7 @@ extension Decimal128 {
/// - lhs: The first value to multiply.
/// - rhs: The second value to multiply.
public static func * (lhs: Decimal128, rhs: Decimal128) -> Decimal128 {
lhs.decimalNumberByMultiplying(by: rhs) as! Decimal128
unsafeDowncast(lhs.decimalNumberByMultiplying(by: rhs), to: Decimal128.self)
}

/// Returns the quotient of dividing the first Decimal128 value by the second.
Expand All @@ -237,7 +237,7 @@ extension Decimal128 {
/// - lhs: The Decimal128 value to divide.
/// - rhs: The Decimal128 value to divide `lhs` by. `rhs` must not be zero.
public static func / (lhs: Decimal128, rhs: Decimal128) -> Decimal128 {
lhs.decimalNumberByDividing(by: rhs) as! Decimal128
unsafeDowncast(lhs.decimalNumberByDividing(by: rhs), to: Decimal128.self)
}
}

Expand All @@ -250,8 +250,8 @@ extension Decimal128 {
///
/// - Parameter other: The Decimal128 value to calculate the distance to.
/// - Returns: The distance from this value to `other`.
public func distance(to other: Decimal128) -> Stride {
other - self
public func distance(to other: Decimal128) -> Decimal128 {
unsafeDowncast(other.decimalNumber(bySubtracting: self), to: Decimal128.self)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overloaded operators take a really long time to type-check so each of these were taking close to 100ms to build and now are <1ms. unsafeDowncast() ended up not speeding up the build but made the release binary a bit smaller (but not enough to justify listing it in the changelog).

Copy link
Contributor

@leemaguire leemaguire Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding some comments to say why you use unsafeDowncast? Its not initially apparent that it improves binary size.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I suppose you could just always trace the git blame

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between unsafeDowncast() and as! is that the latter inserts runtime checks to verify that it actually has the type, while unsafeDowncast() doesn't in optimized builds. Those checks ended up being a significant percentage of this file due to how little the Swift wrapper actually does, but in absolute terms they weren't large.

}

/// Returns a Decimal128 that is offset the specified distance from this value.
Expand All @@ -263,7 +263,7 @@ extension Decimal128 {
/// - Parameter n: The distance to advance this Decimal128.
/// - Returns: A Decimal128 that is offset from this value by `n`.
public func advanced(by n: Decimal128) -> Decimal128 {
self + n
unsafeDowncast(decimalNumber(byAdding: n), to: Decimal128.self)
}
}

Expand Down
2 changes: 1 addition & 1 deletion RealmSwift/ObjectiveCSupport+BSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public extension ObjectiveCSupport {
return convertBson(object: value)
}
return .null
}.map { $0 == .null ? nil : $0 })
}.map { (v: AnyBSON) -> AnyBSON? in v == .null ? nil : v })
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly this type hint made this function a lot faster to build.

case .UUID:
guard let val = bson as? NSUUID else {
return nil
Expand Down
3 changes: 1 addition & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,7 @@ case "$COMMAND" in
export ASAN_OPTIONS='check_initialization_order=true:detect_stack_use_after_return=true'
fi
xcrun swift package resolve
find .build -name views.cpp -delete
xcrun swift test --configuration "$(echo "$CONFIGURATION" | tr "[:upper:]" "[:lower:]")" $SANITIZER
xcrun swift test -Xcc -g0 --configuration "$(echo "$CONFIGURATION" | tr "[:upper:]" "[:lower:]")" $SANITIZER
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-SPM pull request jobs were already disabling debug symbols so this brings SPM in line with them. This knocks ~20% off the build time and cuts the total size of all the object files and such in half, which might fix some of the jobs which were timing out.

exit 0
;;

Expand Down
6 changes: 4 additions & 2 deletions examples/installation/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ xctest() {
)
elif [[ $NAME == SwiftPackageManager* ]]; then
if [ -n "$sha" ]; then
sed -i '' 's@branch = "master"@branch = "'"$sha"'"@' "$DIRECTORY/$NAME.xcodeproj/project.pbxproj"
ex '+%s@branch = "master"@branch = "'"$sha"'"@' -scwq "$DIRECTORY/$NAME.xcodeproj/project.pbxproj"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sed -i doesn't work on symlinks and this file has been a symlink for a while. ex (the line-editor part of vim) does and is a reasonably drop-in replacement.

fi
elif [[ $LANG == swift* ]]; then
download_zip_if_needed swift
Expand All @@ -133,7 +133,9 @@ xctest() {
local scheme=(-scheme "$NAME")

# Ensure that dynamic framework tests try to use the correct version of the prebuilt libraries.
sed -i '' 's@/realm-swift-latest@/realm-swift-latest/'"${REALM_XCODE_VERSION}"'@' "$DIRECTORY/$NAME.xcodeproj/project.pbxproj"
if grep '/realm-swift-latest' "$DIRECTORY/$NAME.xcodeproj/project.pbxproj"; then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike sed, ex reports failure if the expression isn't present in the file so check first.

ex '+%s@/realm-swift-latest@/realm-swift-latest/'"${REALM_XCODE_VERSION}"'@' -scwq "$DIRECTORY/$NAME.xcodeproj/project.pbxproj"
fi

xcodebuild "${project[@]}" "${scheme[@]}" clean build "${destination[@]}" "${code_signing_flags[@]}"
if [[ $PLATFORM != watchos ]]; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/package_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def replace_framework(example, path)
"examples/tvos/swift",
]

xcode_versions = %w(12.2 12.4 12.5.1)
xcode_versions = %w(12.2 12.4 12.5.1 13.0)

# Remove reference to Realm.xcodeproj from all example workspaces.
base_examples.each do |example|
Expand Down