-
Notifications
You must be signed in to change notification settings - Fork 288
Nested interfaces in wit #1624
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
Open
macovedj
wants to merge
15
commits into
bytecodealliance:main
Choose a base branch
from
macovedj:nested-interfaces
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Nested interfaces in wit #1624
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
af8879c
init
macovedj 403d1a3
bulk
macovedj e91ccd5
field gates, nesting nest statements, doc comments
macovedj c9ee248
versioned nest package names and general tidying
macovedj 9906c2e
nest interface item uses UsePath
macovedj 9cd7738
Merge branch 'main' into nested-interfaces
macovedj e834356
handle nested when resolving interface
macovedj 9d58da3
better use interface ids
macovedj 4728637
use iface ids for nested encoding
macovedj 9f33021
print path to interface for nest
macovedj 48c6c86
dedupe nested encoding logic
macovedj 226fa06
some comments addressed
macovedj fc9b6bb
more comments
macovedj 09737ba
Merge branch 'main' into nested-interfaces
macovedj ba550f4
cleaner recursion
macovedj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(component | ||
(type (;0;) | ||
(component | ||
(type (;0;) | ||
(instance | ||
(type (;0;) (record (field "foo" string))) | ||
(export (;1;) "my-record" (type (eq 0))) | ||
(type (;2;) (func (result string))) | ||
(export (;0;) "hello" (func (type 2))) | ||
(type (;3;) | ||
(instance | ||
(type (;0;) (record (field "foo" string))) | ||
(export (;1;) "nest-record" (type (eq 0))) | ||
(type (;2;) | ||
(instance | ||
(type (;0;) (record (field "foo" string))) | ||
(export (;1;) "nest-record" (type (eq 0))) | ||
) | ||
) | ||
(export (;0;) "foo:nestnest/deep" (instance (type 2))) | ||
) | ||
) | ||
(export (;0;) "foo:nestee/[email protected]" (instance (type 3))) | ||
(type (;4;) | ||
(instance | ||
(export (;0;) "foo" (type (sub resource))) | ||
) | ||
) | ||
(export (;1;) "foo:nestee/[email protected]" (instance (type 4))) | ||
) | ||
) | ||
(export (;0;) "foo:thing/something" (instance (type 0))) | ||
) | ||
) | ||
(export (;1;) "something" (type 0)) | ||
(@custom "package-docs" "\01{\22interfaces\22:{\22something\22:{\22types\22:{\22my-record\22:{\22stability\22:{\22stable\22:{\22since\22:\221.0.0\22}}}},\22nested\22:{\22foo:nestee/[email protected]\22:{\22docs\22:{\22contents\22:\22nesting can be documented\22},\22stability\22:\22unknown\22},\22foo:nestee/[email protected]\22:{\22docs\22:{\22contents\22:null},\22stability\22:{\22stable\22:{\22since\22:\221.0.0\22}}}}}}}") | ||
(@producers | ||
(processed-by "wit-component" "$CARGO_PKG_VERSION") | ||
) | ||
) |
17 changes: 17 additions & 0 deletions
17
crates/wit-component/tests/interfaces/nested/deps/nestee.wit
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package foo:[email protected]; | ||
|
||
interface things { | ||
//nesting can be documented | ||
@since(version = 1.0.0) | ||
nest foo:nestnest/deep; | ||
record nest-record { | ||
foo: string | ||
} | ||
hello: func() -> string; | ||
} | ||
|
||
interface more { | ||
resource foo { | ||
bar: func() -> option<string>; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/wit-component/tests/interfaces/nested/deps/nestnest.wit
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package foo:nestnest; | ||
|
||
interface deep { | ||
record deep-record { | ||
foo: string | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package foo:thing; | ||
|
||
interface something { | ||
//nesting can be documented | ||
nest foo:nestee/[email protected]; | ||
@since(version = 1.0.0) | ||
nest foo:nestee/[email protected]; | ||
@since(version = 1.0.0) | ||
record my-record { | ||
foo: string | ||
} | ||
|
||
hello: func() -> string; | ||
} |
15 changes: 15 additions & 0 deletions
15
crates/wit-component/tests/interfaces/nested/thing.wit.print
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package foo:thing; | ||
|
||
interface something { | ||
/// nesting can be documented | ||
nest foo:nestee/[email protected]; | ||
@since(version = 1.0.0) | ||
nest foo:nestee/[email protected]; | ||
@since(version = 1.0.0) | ||
record my-record { | ||
foo: string, | ||
} | ||
|
||
hello: func() -> string; | ||
} | ||
|
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,19 @@ impl<'a> DeclList<'a> { | |
} | ||
Ok(()) | ||
} | ||
|
||
fn for_each_nest<'b>(&'b self, mut f: impl FnMut(&'b Nest<'a>) -> Result<()>) -> Result<()> { | ||
for item in self.items.iter() { | ||
if let AstItem::Interface(i) = item { | ||
for item in i.items.iter() { | ||
if let InterfaceItem::Nest(n) = item { | ||
f(n)?; | ||
} | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
enum AstItem<'a> { | ||
|
@@ -545,6 +558,48 @@ enum InterfaceItem<'a> { | |
TypeDef(TypeDef<'a>), | ||
Func(NamedFunc<'a>), | ||
Use(Use<'a>), | ||
Nest(Nest<'a>), | ||
} | ||
|
||
struct Nest<'a> { | ||
docs: Docs<'a>, | ||
id: PackageName<'a>, | ||
name: Id<'a>, | ||
attributes: Vec<Attribute<'a>>, | ||
} | ||
|
||
impl<'a> Nest<'a> { | ||
fn parse( | ||
tokens: &mut Tokenizer<'a>, | ||
docs: Docs<'a>, | ||
attributes: Vec<Attribute<'a>>, | ||
) -> Result<Self> { | ||
tokens.eat(Token::Nest)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you'll want to |
||
let id = parse_id(tokens)?; | ||
tokens.expect(Token::Colon)?; | ||
// `foo:bar/[email protected]` | ||
let namespace = id; | ||
let pkg_name = parse_id(tokens)?; | ||
tokens.expect(Token::Slash)?; | ||
let name = parse_id(tokens)?; | ||
let version = parse_opt_version(tokens)?; | ||
macovedj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tokens.expect_semicolon()?; | ||
Ok(Self { | ||
id: PackageName { | ||
docs: Default::default(), | ||
span: Span { | ||
start: namespace.span.start, | ||
end: pkg_name.span.end, | ||
}, | ||
namespace, | ||
name: pkg_name, | ||
version, | ||
}, | ||
docs, | ||
name, | ||
attributes, | ||
}) | ||
} | ||
} | ||
|
||
struct Use<'a> { | ||
|
@@ -983,6 +1038,9 @@ impl<'a> InterfaceItem<'a> { | |
NamedFunc::parse(tokens, docs, attributes).map(InterfaceItem::Func) | ||
} | ||
Some((_span, Token::Use)) => Use::parse(tokens, attributes).map(InterfaceItem::Use), | ||
Some((_span, Token::Nest)) => { | ||
Nest::parse(tokens, docs, attributes).map(InterfaceItem::Nest) | ||
} | ||
other => Err(err_expected(tokens, "`type`, `resource` or `func`", other).into()), | ||
} | ||
} | ||
|
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.