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

Add BlockApi trait. #635

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

azteca1998
Copy link
Contributor

Solves #634 by moving the Block's API into a separate trait.

The same principle can probably be applied also to RegionRef and OperationRef.

@edg-l
Copy link
Member

edg-l commented Dec 9, 2024

Looks good to me, it duplicates a bit of code but I don't know another way that isn't a big rewrite, what do you think @raviqqe ?

@azteca1998
Copy link
Contributor Author

The alternative would be to duplicate the methods manually, but doing it this way allows us to have functions that accept both Block and BlockRefs by declaring the argument as block: impl BlockApi.

@raviqqe
Copy link
Member

raviqqe commented Dec 10, 2024

Thank you for the changes! I'm gonna take a look soon.

melior/src/ir/block.rs Outdated Show resolved Hide resolved
}
}

impl<'c, 'v> BlockApi<'c, 'v> for Block<'c> {
Copy link
Member

Choose a reason for hiding this comment

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

Is this typing correct although blocks can be dangling? We don't need to append blocks to regions first to modify blocks in the current API.

Looking at the types and lifetimes of the implemented methods, you meant for 'v to be the lifetime of Block's themselves?

For example, currently the following test passes:

    #[test]
    fn static_argument() {
        let context = create_test_context();
        context.set_allow_unregistered_dialects(true);
        let block = Block::new(&[(
            IntegerType::new(&context, 64).into(),
            Location::unknown(&context),
        )]);
        let _arg: BlockArgument<'_, 'static> = block.argument(0).unwrap();
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, but it seems you've figured it out already.
Your way is probably better since you're binding the 'v lifetime to Self.

@raviqqe
Copy link
Member

raviqqe commented Dec 10, 2024

@edg-l @azteca1998 It doesn't have to be addressed here. But FYI, we should technically have BlockRefMut in the future although we use BlockRef for both immutable and mutable references now. 😅

@raviqqe
Copy link
Member

raviqqe commented Dec 10, 2024

Ah, sorry I somehow force pushed to your branch!

@raviqqe
Copy link
Member

raviqqe commented Dec 10, 2024

@azteca1998 @edg-l Can you take a look at this? azteca1998#1

Update `BlockApi` implementation
@azteca1998
Copy link
Contributor Author

Ah, sorry I somehow force pushed to your branch!

No problem.

Can you take a look at this? azteca1998#1

Merged.

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.

3 participants