Skip to content
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

actor API syntax #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

actor API syntax #75

wants to merge 3 commits into from

Conversation

japaric
Copy link
Collaborator

@japaric japaric commented Apr 1, 2022

see rtic-rs/rfcs#52 for details
includes: core proposal and first #[init] extension

Co-authored-by: Jonas Schievink jonasschievink@gmail.com

Copy link
Contributor

@perlindgren perlindgren left a comment

Choose a reason for hiding this comment

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

@japaric

I've looked at the syntax PR. In src/parse/app.rs line 396, I don't quite follow

                                let ident = field.ident.as_ref().expect("UNREACHABLE");

Can this expect be triggered, if so how, and what would the implication be (what happens if the identifier is set to "UNREACHABLE")?

As I understand the extension of the syntax allow init to optionally return an actors struct, and current projects should still work as before.

Is there a mechanism checking if an Actor struct has been declared but not used returned by init?

/Per

@perlindgren
Copy link
Contributor

Another thing that would be good is some more tests (if I'm not mistaken there is just one test assumed to pass, no fail tests).

@japaric
Copy link
Collaborator Author

japaric commented Nov 15, 2022

@perlindgren the .expect method is like Option::unwrap but includes a panic message. you can think of .expect("message") it as short-hand for .unwrap_or_else(|| panic!("message"))`.

Can this expect be triggered, if so how

that panicking branch cannot be hit due to guarantees in the syn crate. when you have a FieldsNamed value, it's guaranteed that Field.ident will be the Some variant. FieldsNamed corresponds to the { a: i32 } syntax of a braced struct item (struct X { a: i32 }); whereas FieldsUnnamed is used for tuple structs like struct NewType(i32).

if you see a few lines above you'll see that the code is handling the Named (struct fields) case.

if let Fields::Named(fields) = &mut struct_item.fields {
for field in &mut fields.named {
let ident = field.ident.as_ref().expect("UNREACHABLE");

what happens if the identifier is set to "UNREACHABLE"

the syn parser has no special handling for that particular identifier so it's not handled differently here than if a different identifier was used.

Is there a mechanism checking if an Actor struct has been declared but not used returned by init?

yes, there's a parser check for that. if an #[actors] struct is defined and the tuple is missing an element then you get this error

(Some(actors_ident), None) => {
return Err(parse::Error::new(
actors_ident.span(),
format!(
"`#[init]` return type needs to include `{}` as the 4th tuple element ",
actors_ident
),
));
}

Another thing that would be good is some more tests (if I'm not mistaken there is just one test assumed to pass, no fail tests).

indeed, there are "success path" tests but no "failure path" tests in this PR. it would be possible to test the failure condition about init return type missing a tuple element in this repo

@perlindgren
Copy link
Contributor

As discussed on the Matrix, the current consensus is a "forked release", under the same rtic-rs github. Let's discuss further on next/upcoming weekly meeting.

japaric and others added 3 commits March 5, 2023 00:00
see rtic-rs/rfcs#52 for details
includes: core proposal and first `#[init]` extension

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants