Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resolving imported functions when importing the same function more than once #639

Merged
merged 3 commits into from
Nov 18, 2020

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented Nov 11, 2020

No description provided.

@@ -408,8 +408,7 @@ std::vector<ExternalFunction> resolve_imported_functions(
" output type doesn't match imported function in module"};
}

external_functions.emplace_back(
ExternalFunction{std::move(it->function), module_func_type});
external_functions.emplace_back(ExternalFunction{it->function, module_func_type});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now input imported_functions could be passed by const reference, not sure it's worth to change.

@codecov
Copy link

codecov bot commented Nov 11, 2020

Codecov Report

Merging #639 (cc52b35) into master (b23e347) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #639   +/-   ##
=======================================
  Coverage   98.37%   98.37%           
=======================================
  Files          69       69           
  Lines        9658     9682   +24     
=======================================
+ Hits         9501     9525   +24     
  Misses        157      157           

@gumb0 gumb0 requested review from axic and chfast November 11, 2020 11:47
@chfast chfast added the bug Something isn't working label Nov 11, 2020
{
/* wat2wasm
(func (import "mod1" "foo1") (param i32) (result i32))
(func (import "mod1" "foo1") (param i32) (result i32))
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, are there such test cases in spectests?

Copy link
Member

Choose a reason for hiding this comment

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

Also can such a test be added to the C++ part as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, are there such test cases in spectests?

I found at least this one case of importing the same function twice:
https://github.com/wasmx/wasm-spec/blob/7526564b56c30250b66504fe795e9c1e88a938af/test/core/imports.wast#L30-L33

Our spec test runner doesn't use resolve function, so it wouldn't be affected by this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also there's this curious case of importing overloaded functions with different types, which is expected to be valid but fail to instantiate:
https://github.com/wasmx/wasm-spec/blob/7526564b56c30250b66504fe795e9c1e88a938af/test/core/imports.wast#L568

Perhaps resolve should allow several functions with the same name and different types, too. I would fix this in another PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also can such a test be added to the C++ part as well?

I assume you mean to C API part, because this is C++ API test.

Copy link
Member

Choose a reason for hiding this comment

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

Also can such a test be added to the C++ part as well?

I assume you mean to C API part, because this is C++ API test.

Ah you do seem to have it in both.

Copy link
Member

Choose a reason for hiding this comment

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

Our spec test runner doesn't use resolve function, so it wouldn't be affected by this.

Hm, should it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Our spec test runner doesn't use resolve function, so it wouldn't be affected by this.

Hm, should it?

I think maybe not necessary, and in current form it would be really inconvenient.

To me it seems that resolve API suits more to import host functions - because of convenience of flattened ImportedFunction struct and other Imported* from #637. Whereas importing from one module to another requires External* structs - which are returned from find_exported_* functions - that's what spectest runner uses.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added an issue #645

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also there's this curious case of importing overloaded functions with different types, which is expected to be valid but fail to instantiate:
https://github.com/wasmx/wasm-spec/blob/7526564b56c30250b66504fe795e9c1e88a938af/test/core/imports.wast#L568

Perhaps resolve should allow several functions with the same name and different types, too. I would fix this in another PR.

Also an issue for this #647

@gumb0 gumb0 requested a review from axic November 16, 2020 11:10
@gumb0 gumb0 force-pushed the resolve-imported-function-twice branch from 0c5d63c to cc52b35 Compare November 18, 2020 10:14
@gumb0 gumb0 merged commit c044c54 into master Nov 18, 2020
@gumb0 gumb0 deleted the resolve-imported-function-twice branch November 18, 2020 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants