Skip to content

Commit fbb8abd

Browse files
refactor: Remove optional feature attribute from stable feature gates (#1741)
* Remove feature flag from post-stabilization feature gates This commit removes the optional `feature` specification from feature gates (`@since`, in particular). This change should simplify the usage of feature gates (see WebAssembly/component-model#387) for more discussion. This is a breaking change for those who were depending on `wit-parser` as `feature` now no longer present. Signed-off-by: Victor Adossi <vadossi@cosmonic.com> * Update wit-component to not use feature option in since This commit updates `wit-component` to remove reliance on the `feature` option when dealing with post-stabilization (`@since`) feature gates. Signed-off-by: Victor Adossi <vadossi@cosmonic.com> * Update tests to remove optional feature on since gates Signed-off-by: Victor Adossi <vadossi@cosmonic.com> --------- Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
1 parent 57e1f32 commit fbb8abd

File tree

7 files changed

+12
-50
lines changed

7 files changed

+12
-50
lines changed

crates/wit-component/src/printing.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -913,17 +913,9 @@ impl WitPrinter {
913913
fn print_stability(&mut self, stability: &Stability) {
914914
match stability {
915915
Stability::Unknown => {}
916-
Stability::Stable {
917-
since,
918-
feature,
919-
deprecated,
920-
} => {
916+
Stability::Stable { since, deprecated } => {
921917
self.output.push_str("@since(version = ");
922918
self.output.push_str(&since.to_string());
923-
if let Some(feature) = feature {
924-
self.output.push_str(", feature = ");
925-
self.output.push_str(feature);
926-
}
927919
self.output.push_str(")\n");
928920
if let Some(version) = deprecated {
929921
self.output.push_str("@deprecated(version = ");

crates/wit-parser/src/ast.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,19 +1545,9 @@ fn err_expected(
15451545
}
15461546

15471547
enum Attribute<'a> {
1548-
Since {
1549-
span: Span,
1550-
version: Version,
1551-
feature: Option<Id<'a>>,
1552-
},
1553-
Unstable {
1554-
span: Span,
1555-
feature: Id<'a>,
1556-
},
1557-
Deprecated {
1558-
span: Span,
1559-
version: Version,
1560-
},
1548+
Since { span: Span, version: Version },
1549+
Unstable { span: Span, feature: Id<'a> },
1550+
Deprecated { span: Span, version: Version },
15611551
}
15621552

15631553
impl<'a> Attribute<'a> {
@@ -1571,18 +1561,10 @@ impl<'a> Attribute<'a> {
15711561
eat_id(tokens, "version")?;
15721562
tokens.expect(Token::Equals)?;
15731563
let (_span, version) = parse_version(tokens)?;
1574-
let feature = if tokens.eat(Token::Comma)? {
1575-
eat_id(tokens, "feature")?;
1576-
tokens.expect(Token::Equals)?;
1577-
Some(parse_id(tokens)?)
1578-
} else {
1579-
None
1580-
};
15811564
tokens.expect(Token::RightParen)?;
15821565
Attribute::Since {
15831566
span: id.span,
15841567
version,
1585-
feature,
15861568
}
15871569
}
15881570
"unstable" => {

crates/wit-parser/src/ast/resolve.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,28 +1386,20 @@ impl<'a> Resolver<'a> {
13861386
match attrs {
13871387
[] => Ok(Stability::Unknown),
13881388

1389-
[ast::Attribute::Since {
1390-
version, feature, ..
1391-
}] => Ok(Stability::Stable {
1389+
[ast::Attribute::Since { version, .. }] => Ok(Stability::Stable {
13921390
since: version.clone(),
1393-
feature: feature.as_ref().map(|s| s.name.to_string()),
13941391
deprecated: None,
13951392
}),
13961393

1397-
[ast::Attribute::Since {
1398-
version, feature, ..
1399-
}, ast::Attribute::Deprecated {
1394+
[ast::Attribute::Since { version, .. }, ast::Attribute::Deprecated {
14001395
version: deprecated,
14011396
..
14021397
}]
14031398
| [ast::Attribute::Deprecated {
14041399
version: deprecated,
14051400
..
1406-
}, ast::Attribute::Since {
1407-
version, feature, ..
1408-
}] => Ok(Stability::Stable {
1401+
}, ast::Attribute::Since { version, .. }] => Ok(Stability::Stable {
14091402
since: version.clone(),
1410-
feature: feature.as_ref().map(|s| s.name.to_string()),
14111403
deprecated: Some(deprecated.clone()),
14121404
}),
14131405

crates/wit-parser/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,6 @@ pub enum Stability {
845845
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_version"))]
846846
#[cfg_attr(feature = "serde", serde(deserialize_with = "deserialize_version"))]
847847
since: Version,
848-
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
849-
feature: Option<String>,
850848
#[cfg_attr(
851849
feature = "serde",
852850
serde(

crates/wit-parser/tests/ui/since-and-unstable.wit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package a:b@1.0.1;
33
@since(version = 1.0.0)
44
interface foo1 {}
55

6-
@since(version = 1.0.0, feature = foo)
6+
@since(version = 1.0.0)
77
interface foo2 {}
88

9-
@since(version = 1.0.0, feature = foo-bar)
9+
@since(version = 1.0.0)
1010
interface foo3 {}
1111

1212
@unstable(feature = foo2)

crates/wit-parser/tests/ui/since-and-unstable.wit.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@
155155
"functions": {},
156156
"stability": {
157157
"stable": {
158-
"since": "1.0.0",
159-
"feature": "foo"
158+
"since": "1.0.0"
160159
}
161160
},
162161
"package": 0
@@ -167,8 +166,7 @@
167166
"functions": {},
168167
"stability": {
169168
"stable": {
170-
"since": "1.0.0",
171-
"feature": "foo-bar"
169+
"since": "1.0.0"
172170
}
173171
},
174172
"package": 0

tests/cli/since-on-future-package.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface foo {
88
@since(version = 0.1.1)
99
b: func(s: string) -> string;
1010

11-
@since(version = 0.1.1, feature = c-please)
11+
@since(version = 0.1.1)
1212
c: func(s: string) -> string;
1313
}
1414

0 commit comments

Comments
 (0)