csharp: omit version namespace segment when package is unambiguous (#1078)#1635
Open
sano-suguru wants to merge 1 commit into
Open
csharp: omit version namespace segment when package is unambiguous (#1078)#1635sano-suguru wants to merge 1 commit into
sano-suguru wants to merge 1 commit into
Conversation
4bf5825 to
8c48205
Compare
Port the `pkg_has_multiple_versions` guard from the C generator
(crates/c/src/lib.rs, `interface_identifier`) to the C# backend.
Previously the C# generator unconditionally appended a version segment
to the namespace of every versioned package (e.g. `my.dep.v0_1_0`).
Now the segment is emitted only when the same package namespace+name
appears at more than one version in the Resolve — i.e. when
omitting it would cause a name collision.
The guard logic is identical to the C backend's. The mangling format
intentionally differs: C# emits `v{major}_{minor}_{patch}.` while C
uses a trailing-underscore snake-case segment.
Tests:
- Unit tests on `interface_name` assert the namespace directly: the
segment is dropped for a single-version package and kept when two
versions coexist (verified to fail if the guard is reverted).
- A `tests/codegen/single-version-package` fixture (one versioned
import, single version) builds the drop path across all backends,
alongside the existing `multiversion` fixture (two versions).
Closes bytecodealliance#1078
8c48205 to
23e4c85
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the
pkg_has_multiple_versionsguard from the C generator (crates/c/src/lib.rs,interface_identifier) to the C# backend, closing #1078.What changes
Previously the C# generator unconditionally appended a version segment to the namespace of every versioned WIT package:
After this change the segment is only emitted when the same package
namespace:nameappears at more than one version in the Resolve — the only situation where omitting it would cause a collision:The guard logic is identical to the C backend's. The mangling format intentionally differs by design: C# emits
v{major}_{minor}_{patch}.while C uses a trailing-underscore snake-case segment.Tests
interface_nameassert the generated namespace directly: the segment is dropped for a single-version package and kept when two versions coexist. I verified they fail if the guard is reverted to the unconditional form, so they lock the behavior (not just compilation) and run on every platform without the dotnet toolchain.tests/codegen/single-version-package(one versioned import, single version in the Resolve) builds the drop path across all backends, alongside the existingmultiversionfixture (two versions of the same package) which guards the must-keep path.C# codegen build tests don't run on my machine (macOS), so the
dotnet buildstep is left to CI;cargo buildand the unit tests pass locally.Design decision
I asked on the issue whether this should be a silent default or gated behind a flag. @yowl preferred the default/no-flag approach for consistency with the C backend (#1078 (comment)). This changes generated C# namespace names for single-version packages — a breaking change that's acceptable pre-1.0 per that discussion.