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

Remove trait bounds from generated program type's declaration #25

Merged
merged 5 commits into from
Mar 16, 2024

Conversation

regexident
Copy link
Contributor

Fixes #23

@regexident
Copy link
Contributor Author

Following up on #23 (comment) I've amended this PR to support the following (optional) syntax for specifying diverging impl trait bounds:

Non-diverging impl trait bounds

If only a generic struct is specified, then the macro will behave as is, using the provided type generics and bounds for both, the type's declaration, as well as its impls:

The following …

ascent!{
    struct AscentProgram<T> where T: Clone + Eq + Hash;

    // ...
}

… expands to something along the lines of this:

struct AscentProgram<T>
where
   T: Clone + Hash + Eq
{
   // ...
}

impl<T> AscentProgram<T>
where
   T: Clone + Hash + Eq,
{
   // ...
}

impl<T> Default for AscentProgram<T>
where
   T: Clone + Hash + Eq
{
   // ...
}

Diverging impl trait bounds

If both, a generic struct, as well as an impl … are specified, then the macro use the provided type generics and bounds for the type's declaration, as well as the impl Default, while using the provided impl generics and bounds for the type's impls:

The following …

ascent!{
    struct AscentProgram<T> where T: Clone;
    impl<T> AscentProgram<T> where T: Clone + Eq + Hash;
    // ...
}

… expands to something along the lines of this:

struct AscentProgram<T>
where
    T: Clone
{
   // ...
}

impl<T> AscentProgram<T>
where
   T: Clone + Hash + Eq,
{
   // ...
}

impl<T> Default for AscentProgram<T>
where
    T: Clone
{
   // ...
}

Impl-only trait bounds

Similarly the following …

ascent!{
    struct AscentProgram<T>;
    impl<T> AscentProgram<T> where T: Clone + Eq + Hash;
    // ...
}

… expands to something along the lines of this:

struct AscentProgram<T> {
   // ...
}

impl<T> AscentProgram<T>
where
   T: Clone + Hash + Eq,
{
   // ...
}

impl<T> Default for AscentProgram<T> {
   // ...
}

@regexident regexident force-pushed the omit-trait-bounds-on-type branch 3 times, most recently from 032ba02 to de24744 Compare December 17, 2023 18:06
Copy link
Owner

@s-arash s-arash left a comment

Choose a reason for hiding this comment

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

We should also disallow custom impl signatures on ascent_run and ascent_run_par. This could be done at the start of the compile_mir function.

ascent_macro/src/ascent_syntax.rs Show resolved Hide resolved
ascent_macro/src/ascent_codegen.rs Show resolved Hide resolved
ascent_macro/src/ascent_codegen.rs Show resolved Hide resolved
ascent_macro/src/ascent_codegen.rs Outdated Show resolved Hide resolved
@s-arash
Copy link
Owner

s-arash commented Mar 9, 2024

Hi @regexident, and thanks again for the PR!
Do you have time to fix the remaining errors in this PR? If not, let me know and I can take it from here.

@regexident
Copy link
Contributor Author

I'll try to give it a go tomorrow or the day after.

…nto `Signatures`)

This allows for specifying deviating trait bounds on the program's impls
@regexident
Copy link
Contributor Author

@s-arash Looks like the experimental "attrs on relations" in AscentProgram got broken my changes of the Signatures type.

The handling of attritibute parsing within impl Parse for AscentProgram { … } looks a bit shady to me (leaky abstraction) since any changes within Signatures should not break the parsing of the outer AscentProgram.

I'm not sure how to best address this. Feel free to take it from here, if you do.

ascent_macro/src/ascent_codegen.rs Outdated Show resolved Hide resolved
@s-arash
Copy link
Owner

s-arash commented Mar 11, 2024

The handling of attritibute parsing within impl Parse for AscentProgram { … } looks a bit shady to me (leaky abstraction) since any changes within Signatures should not break the parsing of the outer AscentProgram.

It wasn't changes to Signatures that broke parsing, it was unnecessary changes to AscentProgram parsing that broke AscentProgram parsing!

@s-arash s-arash merged commit a022abb into s-arash:master Mar 16, 2024
2 checks passed
@regexident regexident deleted the omit-trait-bounds-on-type branch March 16, 2024 17:32
regexident added a commit to regexident/ascent that referenced this pull request Nov 2, 2024
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.

Ascent should omit trait bounds on the generated program's type declaration
2 participants