Skip to content

Conversation

@kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Oct 10, 2023

This attribute instructs the compiler that this function declaration should be "import"ed from host environment. It's equivalent of Clang's __attribute__((import_module("module"), import_name("field")))

The attribute doesn't have any effect on to function signature and calling convention but only adds LLVM meta attribute to the function. Currently there is no way to declare a function with non SwiftCC, so functions are always imported as having SwiftCC. (I'm planning to add @_extern(c) after this change will be merged. Combination with them makes the declaration to be imported from WebAssembly host using C convention)

This is the import version of #68524, which adds an attribute to export functions.

  • [Parse] Parse new attribute @_extern(wasm, module: <module-name>, name: <name>)
  • [TypeCheck] Reject function decl with the attribute with body or non-top-level context.
  • [IRGen] Add corresponding LLVM metadata wasm-import-name and wasm-import-module

Resolves rdar://115502075

This attribute instructs the compiler that this function declaration
should be "import"ed from host environment. It's equivalent of Clang's
`__attribute__((import_module("module"), import_name("field")))`
@kateinoigakukun kateinoigakukun changed the title [wasm] add @_extern(wasm) attribute support [wasm] Add @_extern(wasm) attribute support Oct 10, 2023
@kateinoigakukun
Copy link
Member Author

@swift-ci Please smoke test

@kateinoigakukun kateinoigakukun added WebAssembly Platform: WebAssembly attributes Feature: Declaration and type attributes labels Oct 10, 2023
@kateinoigakukun kateinoigakukun marked this pull request as ready for review October 11, 2023 03:49
Copy link
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

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

LGTM. I'm definitely looking forward to @extern(c) being added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

attributes Feature: Declaration and type attributes WebAssembly Platform: WebAssembly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants