Serialization: apply the SDK build version as part of the cache hash

The SDK build version is a decent heuristic for expected changes in the
SDK. Any change in SDK, to clang headers in particular, can break
references from cached swiftmodules.

Track the SDK build version as part of the swiftmodule cache hash. This
will ensure we rebuild from swiftinterfaces on SDK updates.

rdar://122655978
This commit is contained in:
Alexis Laferrière
2024-02-12 11:09:18 -08:00
parent 8bb6846285
commit 86ea594f21
7 changed files with 108 additions and 12 deletions

View File

@@ -0,0 +1,71 @@
/// ProductBuildVersion of the SDK is tracked as part of the module cache hash.
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/ModuleCache)
// RUN: %empty-directory(%t/sdk/System/Library/CoreServices/)
// RUN: split-file %s %t
/// Setup an "old" SDK.
// RUN: cp %t/SystemVersion.plist.old %t/sdk/System/Library/CoreServices/SystemVersion.plist
/// Build Lib against the old SDK.
// RUN: %target-swift-frontend -emit-module -sdk %t/sdk %t/Lib.swift \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -emit-module-path %t/Lib.swiftmodule \
// RUN: -emit-module-interface-path %t/Lib.swiftinterface
/// Baseline check, we should read the adjacent swiftmodule.
// RUN: %target-swift-frontend -typecheck -verify -sdk %t/sdk -I %t \
// RUN: %t/Client_NoRebuild.swift \
// RUN: -Rmodule-interface-rebuild -module-cache-path %t/ModuleCache
/// Keep only the swiftinterface.
// RUN: rm %t/Lib.swiftmodule
/// Build client, which should trigger a build from swiftinterface.
// RUN: %target-swift-frontend -typecheck -verify -sdk %t/sdk -I %t \
// RUN: %t/Client.swift \
// RUN: -Rmodule-interface-rebuild -module-cache-path %t/ModuleCache
/// Update SDK.
// RUN: cp %t/SystemVersion.plist.new %t/sdk/System/Library/CoreServices/SystemVersion.plist
/// Build client, which should trigger a build from swiftinterface.
// RUN: %target-swift-frontend -typecheck -verify -sdk %t/sdk -I %t \
// RUN: %t/Client.swift \
// RUN: -Rmodule-interface-rebuild -module-cache-path %t/ModuleCache
/// Baseline check, we should reused the newly cached swiftmodule.
// RUN: %target-swift-frontend -typecheck -verify -sdk %t/sdk -I %t \
// RUN: %t/Client_NoRebuild.swift \
// RUN: -Rmodule-interface-rebuild -module-cache-path %t/ModuleCache
//--- SystemVersion.plist.old
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ProductBuildVersion</key>
<string>10A100</string>
</dict>
</plist>
//--- SystemVersion.plist.new
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ProductBuildVersion</key>
<string>10A200</string>
</dict>
</plist>
//--- Lib.swift
public func foo() {}
//--- Client.swift
import Lib // expected-remark {{rebuilding module 'Lib' from interface}}
//--- Client_NoRebuild.swift
import Lib