WebAssembly / WebAssembly/binaryen

BinaryenAddFunctionImport lost internalName on export, is this intentional?

Open
#7,272 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

 BinaryenAddFunctionImport(module, internalName, "env", "externalBaseName", params, result);
BinaryenFunctionRef func = BinaryenGetFunction(module, ret);
func->setExplicitName(internalName);

i think add and Get , It's a bit wasteful. why not return BinaryenFunctionRef on BinaryenAddFunctionImport?
i find that, BinaryenAddFunction directly setExplicitName. why not BinaryenAddFunctionImport?

void BinaryenAddFunctionImport(BinaryenModuleRef module,
                               const char* internalName,
                               const char* externalModuleName,
                               const char* externalBaseName,
                               BinaryenType params,
                               BinaryenType results) {
  auto* func = ((Module*)module)->getFunctionOrNull(internalName);
  if (func == nullptr) {
    auto func = std::make_unique<Function>();
    if (internalName)
      func->setExplicitName(internalName); 
    func->name = internalName;
    func->module = externalModuleName;
    func->base = externalBaseName;
    // TODO: Take a HeapType rather than params and results.
    func->type = Signature(Type(params), Type(results));
    ((Module*)module)->addFunction(std::move(func));
  } else {
    // already exists so just set module and base
    func->module = externalModuleName;
    func->base = externalBaseName;
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the implementation of BinaryenAddFunctionImport shown in the issue and compare it with BinaryenAddFunction, then inspect how BinaryenGetFunction and export naming use internalName. Verify the current behavior for imported functions and determine what API behavior or naming preservation should be covered before adding a focused regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
api, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.