Skip to content

feat(component): add extended interface version canonicalization supp…#4590

Open
sagar-h007 wants to merge 5 commits intoWasmEdge:masterfrom
sagar-h007:feat/component-version-canonicalization
Open

feat(component): add extended interface version canonicalization supp…#4590
sagar-h007 wants to merge 5 commits intoWasmEdge:masterfrom
sagar-h007:feat/component-version-canonicalization

Conversation

@sagar-h007
Copy link

Summary

This PR adds support for extended interface version canonicalization to WasmEdge’s Component Model loader, following the Component Model spec (PR #536).

In practical terms, this lets WasmEdge correctly handle versioned component interfaces, including canonical version matching, while remaining fully compatible with existing components.

What’s included

Versioned interfaces

  • Import and export names now support canonical interface versions
  • Both formats are handled:
  • Legacy 0x00 encoding
  • Extended 0x01 encoding with version suffixes

Version handling

  • Introduces a small utility for:
  • Parsing semantic versions
  • Canonicalizing them according to the spec
  • Checking version compatibility

Examples:

  • 1.2.3 → 1
  • 0.2.6-rc.1 → 0.2
  • 0.0.1-alpha → 0.0.1

Loader changes

The binary loader now understands extended import/export names
Version suffixes are stored separately so the full version is preserved for:
Better error messages
Future validation and tooling

Tests

Adds unit tests covering:
Valid and invalid semantic versions
Canonicalization rules
Version compatibility
Real WASI Preview 2 cases
Updates interface name parsing tests to include canonical versions

Why this matters

The Component Model relies on canonical version matching to allow compatible components to link even when their patch versions differ.

Without this support, versioned interfaces either fail to match or rely on fragile string comparisons. This PR fixes that and brings WasmEdge in line with the spec.

comprehensive unit tests for semver parsing, canonicalization, and WASI Preview 2 cases

Testing

  • New unit tests added
  • Existing test suite passes

Fixes: #4276.

@github-project-automation github-project-automation bot moved this to Triage-required in WasmEdge Roadmap Jan 31, 2026
@github-actions github-actions bot added the c-Test An issue/PR to enhance the test suite label Jan 31, 2026
Copy link
Collaborator

@q82419 q82419 left a comment

Choose a reason for hiding this comment

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

Thanks for your PR.

  1. I think the VersionSuffix can simply be std::string, and the default is "" for no suffix.
  2. It's not a good choice to add the LastNamePrefix flag. You can pass the flag to the loadExternName() as argument.
  3. The related issue is about the loader phase. For the validator, please separate to another PR. And also, currently the code still not connected to the validator implementation.
  4. Please care about the naming style.

@github-project-automation github-project-automation bot moved this from Triage-required to In progress in WasmEdge Roadmap Feb 2, 2026
@sagar-h007
Copy link
Author

@q82419 I’ll update VersionSuffix to be a std::string and use an empty string to represent no suffix. I’ll also refactor the loader to remove the LastNamePrefix state and pass the prefix flag directly into loadExternName().

I’ll move the validator-related changes into a separate PR so this one stays focused on the loader, and I’ll fix the naming to match the existing style.

I’ll push an updated version soon.

Copy link
Collaborator

@q82419 q82419 left a comment

Choose a reason for hiding this comment

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

  1. Please use clang-format to lint your code.
  2. I think it's better to extend the loadExternName() as std::string &Name, std::string &Suffix than return the flag and duplicated the code about loading suffix string.

#include "ast/component/sort.h"
#include "ast/component/type.h"

#include <optional>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why delete this header?

Copy link
Author

Choose a reason for hiding this comment

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

The < optional > header is no longer required in this file.
All previous usages were removed/refactored, and the file compiles cleanly without it.
Keeping it would be an unused include, so I removed it to avoid unnecessary dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No longer? What container in line 48?

Copy link
Author

Choose a reason for hiding this comment

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

You’re right — line 48 still uses std::optional. I missed that.
I’ll restore the include and update the patch accordingly.

@sagar-h007 sagar-h007 requested a review from q82419 February 9, 2026 07:19
@sagar-h007 sagar-h007 force-pushed the feat/component-version-canonicalization branch from 16ccd1c to 21d412b Compare February 9, 2026 09:39
Copy link
Collaborator

@q82419 q82419 left a comment

Choose a reason for hiding this comment

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

Alignment the = in comments.

@sagar-h007 sagar-h007 force-pushed the feat/component-version-canonicalization branch from 83c1f79 to b2c58d6 Compare February 11, 2026 21:25
Comment on lines 25 to 29
if (B == 0x01) {
EXPECTED_TRY(Suffix, FMgr.readName());
} else {
Suffix.clear();
}
Copy link
Member

Choose a reason for hiding this comment

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

Use switch case and default case use unreachable

…ort.

Implement Component Model extended interface version handling per PR WasmEdge#536.

- Add version suffix support to component import/export AST nodes
- Introduce semver parsing and canonicalization utilities
- Support canonical version matching and compatibility checks
- Extend binary loader to handle 0x01-prefixed versioned names
- Preserve legacy 0x00 name encoding for backward compatibility
- Add comprehensive unit tests for semver parsing, canonicalization, and WASI Preview 2 cases

Fixes: WasmEdge#4276.
Signed-off-by: sagar <[email protected]>
- Replace optional VersionSuffix with std::string
- Remove LastNamePrefix state from loader
- Pass name prefix explicitly during extern name loading
- Drop validator-related changes from this commit

Signed-off-by: sagar <[email protected]>
…clude

- Replace if-else with switch-case in loadExternName function

Signed-off-by: sagar <[email protected]>
@sagar-h007 sagar-h007 force-pushed the feat/component-version-canonicalization branch from b2c58d6 to c1b9662 Compare February 12, 2026 17:20
@sagar-h007 sagar-h007 requested a review from dannypsnl February 12, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c-Common c-Loader c-Test An issue/PR to enhance the test suite

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

feat: Component Model: Extend interface version canonization in loader

3 participants