mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
When a Swift function shadows a clang function of the same name, the assumption was that Swift code would refer only to the Swift one. However, if the Swift function is `@usableFromInline internal` it can be called only from the local module and inlined automatically in other clients. Outside of that module, sources see only the clang function, so their inlinable code calls only the clang function and ignores the Swift one. This configuration passed type checking but it could crash the compiler at inlining the call as the compiler couldn't see the clang function. Let's update the deserialization logic to support inlined calls to the shadowed or the shadower. Typical shadowing is already handled by the custom deserialization cross-reference filtering logic which looks for the defining module, scope and whether it's a Swift or clang decl. We can disable the lookup shadowing logic and rely only on the deserialization filtering. rdar://146320871 https://github.com/swiftlang/swift/issues/79801
65 lines
1.6 KiB
Swift
65 lines
1.6 KiB
Swift
/// Ensure inlined code in swiftmodules differentiates between shadowed Swift
|
|
/// and clang decls.
|
|
|
|
// RUN: %empty-directory(%t)
|
|
// RUN: split-file %s %t
|
|
// REQUIRES: objc_interop
|
|
|
|
/// Reference build: Build libs and client for a normal build.
|
|
// RUN: %target-swift-frontend -emit-module %t/RootLib.swift -I %t \
|
|
// RUN: -emit-module-path %t/RootLib.swiftmodule
|
|
// RUN: %target-swift-frontend -emit-module %t/MiddleLib.swift -I %t \
|
|
// RUN: -emit-module-path %t/MiddleLib.swiftmodule
|
|
// RUN: %target-swift-frontend -emit-sil -O %t/Client.swift -I %t > %t/Client.sil
|
|
// RUN: %FileCheck %s --input-file=%t/Client.sil
|
|
|
|
//--- module.modulemap
|
|
module RootLib {
|
|
header "RootLib.h"
|
|
}
|
|
|
|
//--- RootLib.h
|
|
#include <stdio.h>
|
|
void ShadowedFunc() {
|
|
printf("Clang\n");
|
|
}
|
|
|
|
//--- RootLib.swift
|
|
@_exported import RootLib
|
|
|
|
@usableFromInline
|
|
internal func ShadowedFunc() {
|
|
print("Swift")
|
|
}
|
|
|
|
@inlinable
|
|
@inline(__always)
|
|
public func swiftUser() {
|
|
ShadowedFunc() // Swift one
|
|
}
|
|
|
|
//--- MiddleLib.swift
|
|
|
|
import RootLib
|
|
|
|
@inlinable
|
|
@inline(__always)
|
|
public func clangUser() {
|
|
ShadowedFunc() // Clang one
|
|
}
|
|
|
|
//--- Client.swift
|
|
|
|
import RootLib
|
|
import MiddleLib
|
|
|
|
swiftUser()
|
|
// CHECK: [[SWIFT_FUNC:%.*]] = function_ref @$s7RootLib12ShadowedFuncyyF : $@convention(thin) () -> ()
|
|
// CHECK: apply [[SWIFT_FUNC]]() : $@convention(thin) () -> ()
|
|
// CHECK-NOT: apply [[SWIFT_FUNC]]() : $@convention(thin) () -> ()
|
|
|
|
clangUser()
|
|
// CHECK: [[CLANG_FUNC:%.*]] = function_ref @ShadowedFunc : $@convention(c) () -> ()
|
|
// CHECK: apply [[CLANG_FUNC]]() : $@convention(c) () -> ()
|
|
// CHECK-NOT: apply [[CLANG_FUNC]]() : $@convention(c) () -> ()
|