mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[embedded] Relax assert in SILLinkerVisitor::maybeAddFunctionToWorklist to allow external forward-declarations even in regular Swift, add tests
This commit is contained in:
@@ -1354,6 +1354,20 @@ public:
|
||||
WasmImportModuleAndField = std::make_pair(module, field);
|
||||
}
|
||||
|
||||
bool isExternForwardDeclaration() const {
|
||||
if (isExternalDeclaration()) {
|
||||
if (auto declContext = getDeclContext()) {
|
||||
if (auto decl = declContext->getAsDecl()) {
|
||||
if (decl->getAttrs().hasAttribute<ExternAttr>())
|
||||
return true;
|
||||
if (decl->getAttrs().hasAttribute<SILGenNameAttr>())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Returns true if this function belongs to a declaration that returns
|
||||
/// an opaque result type with one or more availability conditions that are
|
||||
/// allowed to produce a different underlying type at runtime.
|
||||
|
||||
@@ -102,7 +102,7 @@ void SILLinkerVisitor::maybeAddFunctionToWorklist(SILFunction *F,
|
||||
bool setToSerializable) {
|
||||
SILLinkage linkage = F->getLinkage();
|
||||
assert((!setToSerializable || F->hasValidLinkageForFragileRef() ||
|
||||
hasSharedVisibility(linkage) || Mod.getOptions().EmbeddedSwift) &&
|
||||
hasSharedVisibility(linkage) || F->isExternForwardDeclaration()) &&
|
||||
"called function has wrong linkage for serialized function");
|
||||
|
||||
if (!F->isExternalDeclaration()) {
|
||||
|
||||
26
test/SIL/modules-extern.swift
Normal file
26
test/SIL/modules-extern.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %{python} %utils/split_file.py -o %t %s
|
||||
|
||||
// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -parse-as-library
|
||||
// RUN: %target-swift-frontend -c -I %t %t/Main.swift -o %t/a.o
|
||||
|
||||
// BEGIN MyModule.swift
|
||||
|
||||
@_extern(c)
|
||||
@_alwaysEmitIntoClient
|
||||
func some_c_api()
|
||||
|
||||
@_transparent
|
||||
public func publicFuncInAModule() {
|
||||
some_c_api()
|
||||
}
|
||||
|
||||
// BEGIN Main.swift
|
||||
|
||||
import MyModule
|
||||
|
||||
@_extern(c)
|
||||
func some_c_api()
|
||||
|
||||
some_c_api()
|
||||
publicFuncInAModule()
|
||||
26
test/SIL/modules-extern2.swift
Normal file
26
test/SIL/modules-extern2.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %{python} %utils/split_file.py -o %t %s
|
||||
|
||||
// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -parse-as-library
|
||||
// RUN: %target-swift-frontend -c -I %t %t/Main.swift -o %t/a.o
|
||||
|
||||
// BEGIN MyModule.swift
|
||||
|
||||
@_silgen_name("some_forward_declared_api")
|
||||
@_alwaysEmitIntoClient
|
||||
func some_forward_declared_api()
|
||||
|
||||
@_transparent
|
||||
public func publicFuncInAModule() {
|
||||
some_forward_declared_api()
|
||||
}
|
||||
|
||||
// BEGIN Main.swift
|
||||
|
||||
import MyModule
|
||||
|
||||
@_silgen_name("some_forward_declared_api")
|
||||
func some_forward_declared_api()
|
||||
|
||||
some_forward_declared_api()
|
||||
publicFuncInAModule()
|
||||
33
test/embedded/modules-extern.swift
Normal file
33
test/embedded/modules-extern.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %{python} %utils/split_file.py -o %t %s
|
||||
|
||||
// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
|
||||
// RUN: %target-swift-frontend -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: OS=macosx || OS=linux-gnu
|
||||
|
||||
// BEGIN MyModule.swift
|
||||
|
||||
@_extern(c)
|
||||
func some_c_api()
|
||||
|
||||
@_transparent
|
||||
public func publicFuncInAModule() {
|
||||
internalFuncInAModule()
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
internal func internalFuncInAModule() {
|
||||
some_c_api()
|
||||
}
|
||||
|
||||
// BEGIN Main.swift
|
||||
|
||||
import MyModule
|
||||
|
||||
@_extern(c)
|
||||
func some_c_api()
|
||||
|
||||
some_c_api()
|
||||
publicFuncInAModule()
|
||||
Reference in New Issue
Block a user