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

fix: derive dynamic RustSBI on struct with generics(type, const, lifetime, where clause) #68

Merged
merged 1 commit into from
May 8, 2024

Conversation

Plucky923
Copy link
Contributor

@Plucky923 Plucky923 commented May 8, 2024

In PR #67 , a RustSBI macro implementation that can be processed dynamically has been added.

But the current implementation has some problems. Take the following struct as an example.

#[derive(RustSBI)]
#[rustsbi(dynamic)]
struct WithLifetime<'a> {
    info: &'a DummyEnvInfo,
}

The macro code cannot compile this struct because its strcut prober struct does not handle lifetime situations. In fact, all generics are not handled, including lifetime, type generics, constant generics, and where clauses. These problems limit the application of rustsbi dynamic in actual projects.

This pull request solves the problem of generics not being processed. The definition of struct _Prober is extended to include generics, which is composed of impl generics, type generics and where clause. We add them to the generated code of struct _Prober, thus solving the problem.

struct _Prober #impl_generics (&'_lt #name #origin_ty_generics) #where_clause;
impl #impl_generics ::rustsbi::_ExtensionProbe for _Prober #ty_generics #where_clause 

Until now,rustsbi dynamic can be used for struct with lifetime, and its application scope will be expanded.

In order to verify the effectiveness of this modification, an additional unit test module(tests/dynamic-generics.rs) has been added. All structures in this unit test file contain different types of generics to comprehensively test the correctness of the macro generated code, thereby verifying the repair results of this pull request.

…time, where clause)

Signed-off-by: Zhenchen Wang <m202372036@hust.edu.cn>
Copy link
Member

@luojia65 luojia65 left a comment

Choose a reason for hiding this comment

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

Good job, the added unit test file is great as well.

Copy link
Member

@duskmoon314 duskmoon314 left a comment

Choose a reason for hiding this comment

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

LGTM

@luojia65 luojia65 merged commit a231d8c into rustsbi:main May 8, 2024
10 checks passed
@Plucky923 Plucky923 deleted the plucky/fix-macro-generics branch May 8, 2024 06:46
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.

None yet

4 participants