mirror of
https://github.com/apple/swift.git
synced 2026-10-30 22:15:52 +01:00
Serialize/deserialize wasm import module/name for SIL serialization so inlined decls keep their import names. Otherwise, inlining a function with `@_extern(wasm)` would lose the import name and cause IRGen to emit an import from the default module "env". Related links: https://github.com/swiftwasm/JavaScriptKit/pull/631 https://github.com/swiftwasm/JavaScriptKit/pull/628 Resolves https://github.com/swiftlang/swift/issues/87320
37 lines
1.7 KiB
Swift
37 lines
1.7 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: split-file %s %t
|
|
// RUN: %target-swift-frontend -emit-sib -emit-module-path %t/Lib.swiftmodule \
|
|
// RUN: -module-name Lib -target wasm32-unknown-wasip1 \
|
|
// RUN: -enable-experimental-feature Extern -parse-stdlib %t/Lib.swift -o %t/Lib.sib
|
|
// RUN: %target-swift-frontend -emit-ir -I %t -target wasm32-unknown-wasip1 \
|
|
// RUN: -enable-experimental-feature Extern -parse-stdlib %t/Client.swift | %FileCheck %s
|
|
|
|
// Check that wasm import names are preserved in the serialized SIL
|
|
// RUN: %target-swift-frontend -emit-sib -I %t -target wasm32-unknown-wasip1 \
|
|
// RUN: -enable-experimental-feature Extern -parse-stdlib %t/Client.swift -o %t/Client.sib
|
|
// RUN: %target-swift-frontend -emit-ir -I %t -target wasm32-unknown-wasip1 \
|
|
// RUN: -enable-experimental-feature Extern -parse-stdlib %t/Client.sib | %FileCheck %s
|
|
|
|
// REQUIRES: swift_feature_Extern
|
|
// REQUIRES: CODEGENERATOR=WebAssembly
|
|
|
|
//--- Lib.swift
|
|
@_extern(wasm, module: "mod", name: "foo") public func foo()
|
|
@_extern(wasm, module: "modOnly", name: "") public func modOnly()
|
|
@_extern(wasm, module: "", name: "nameOnly") public func nameOnly()
|
|
|
|
//--- Client.swift
|
|
import Lib
|
|
public func use() {
|
|
foo()
|
|
modOnly()
|
|
nameOnly()
|
|
}
|
|
|
|
// CHECK: declare swiftcc void @"$s3Lib3fooyyF"() #[[ATTR:[0-9]+]]
|
|
// CHECK: declare swiftcc void @"$s3Lib7modOnlyyyF"() #[[ATTR_MOD_ONLY:[0-9]+]]
|
|
// CHECK: declare swiftcc void @"$s3Lib8nameOnlyyyF"() #[[ATTR_NAME_ONLY:[0-9]+]]
|
|
// CHECK: attributes #[[ATTR]] = {{.*}}"wasm-import-module"="mod"{{.*}}"wasm-import-name"="foo"
|
|
// CHECK: attributes #[[ATTR_MOD_ONLY]] = {{.*}}"wasm-import-module"="modOnly"{{.*}}
|
|
// CHECK: attributes #[[ATTR_NAME_ONLY]] = {{.*}}"wasm-import-name"="nameOnly"{{.*}}
|