Skip to content

Commit faca65c

Browse files
committed
tests passing
Signed-off-by: James Sturtevant <[email protected]>
1 parent 74e004a commit faca65c

File tree

4 files changed

+73
-6
lines changed

4 files changed

+73
-6
lines changed

Diff for: crates/wit-component/tests/merge/success/merge/foo.wit

+2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ world shared-world {
5454
export shared-items;
5555
}
5656
world shared-world-with-versions {
57+
@since(version = 1.0.0)
5758
import shared-version-on-from;
5859
@since(version = 1.0.0)
5960
import shared-version-on-into;
6061
}
6162
world shared-world-with-versions-and-include {
63+
@since(version = 1.0.0)
6264
import shared-version-on-from;
6365
@since(version = 1.0.0)
6466
import shared-version-on-into;

Diff for: crates/wit-parser/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ fn find_futures_and_streams(resolve: &Resolve, ty: Type, results: &mut Vec<TypeI
10791079
///
10801080
/// This is added for WebAssembly/component-model#332 where @since and @unstable
10811081
/// annotations were added to WIT.
1082-
#[derive(Debug, Clone, PartialEq, Eq)]
1082+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
10831083
#[cfg_attr(feature = "serde", derive(serde_derive::Deserialize, Serialize))]
10841084
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
10851085
pub enum Stability {

Diff for: crates/wit-parser/src/resolve.rs

+62-2
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,41 @@ package {name} is defined in two different locations:\n\
694694
let new_id = match world_map.get(&id).copied() {
695695
Some(id) => {
696696
update_stability(&world.stability, &mut self.worlds[id].stability)?;
697+
for import in world.imports.iter() {
698+
match import.0 {
699+
WorldKey::Name(_) => {}
700+
key @ WorldKey::Interface(_) => {
701+
let name = |from_name: &WorldKey| -> WorldKey {
702+
match from_name {
703+
WorldKey::Name(s) => WorldKey::Name(s.clone()),
704+
WorldKey::Interface(id) => WorldKey::Interface(
705+
interface_map.get(id).copied().unwrap_or(*id),
706+
),
707+
}
708+
};
709+
let newkey = name(key);
710+
if let Some(into_import) = self.worlds[id].imports.get_mut(&newkey)
711+
{
712+
match (import.1, into_import) {
713+
(
714+
WorldItem::Interface {
715+
id: _,
716+
stability: astability,
717+
},
718+
WorldItem::Interface {
719+
id: _,
720+
stability: bstability,
721+
},
722+
) => {
723+
//assert_eq!(*aid, *bid);
724+
merge_stability(astability, bstability)?;
725+
}
726+
_ => unreachable!(),
727+
}
728+
}
729+
}
730+
}
731+
}
697732
id
698733
}
699734
None => {
@@ -3404,13 +3439,20 @@ impl Remap {
34043439
let prev = items.entry(key.clone()).or_insert(item.1.clone());
34053440
match (&item.1, prev) {
34063441
(
3407-
WorldItem::Interface { id: aid, .. },
3408-
WorldItem::Interface { id: bid, .. },
3442+
WorldItem::Interface {
3443+
id: aid,
3444+
stability: astability,
3445+
},
3446+
WorldItem::Interface {
3447+
id: bid,
3448+
stability: bstability,
3449+
},
34093450
) => {
34103451
// At this point in processing we care that the interfaces are the same
34113452
// but don't need to verify stability. We've already confirmed that the interface should be
34123453
// apart of the component and versions/features are enabled so if they are the same it can be used.
34133454
assert_eq!(*aid, *bid);
3455+
merge_stability(astability, bstability)?;
34143456
}
34153457
(WorldItem::Interface { .. }, _) => unreachable!(),
34163458
(WorldItem::Function(_), _) => unreachable!(),
@@ -3832,6 +3874,24 @@ fn update_stability(from: &Stability, into: &mut Stability) -> Result<()> {
38323874
bail!("mismatch in stability from '{:?}' to '{:?}'", from, into)
38333875
}
38343876

3877+
fn merge_stability(from: &Stability, into: &mut Stability) -> Result<()> {
3878+
// If the two stability annotations are equal then
3879+
// there's nothing to do here.
3880+
if from == into {
3881+
return Ok(());
3882+
}
3883+
3884+
// if the from is higher elevate into
3885+
// note: enums defined at the top are lower than ones at the bottem
3886+
// stable is at the top so we are doing the opposite here.
3887+
if from < into {
3888+
*into = from.clone();
3889+
return Ok(());
3890+
}
3891+
3892+
return Ok(());
3893+
}
3894+
38353895
/// An error that can be returned during "world elaboration" during various
38363896
/// [`Resolve`] operations.
38373897
///

Diff for: crates/wit-parser/tests/ui/gated-include-use-with-stable.wit.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@
151151
"interface": {
152152
"id": 2,
153153
"stability": {
154-
"unstable": {
155-
"feature": "active"
154+
"stable": {
155+
"since": "0.2.0"
156156
}
157157
}
158158
}
@@ -205,7 +205,12 @@
205205
},
206206
"interface-1": {
207207
"interface": {
208-
"id": 1
208+
"id": 1,
209+
"stability": {
210+
"unstable": {
211+
"feature": "active"
212+
}
213+
}
209214
}
210215
},
211216
"interface-0": {

0 commit comments

Comments
 (0)