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

Language idea: Friend modules #23

Open
alexrp opened this issue Feb 19, 2023 · 1 comment
Open

Language idea: Friend modules #23

alexrp opened this issue Feb 19, 2023 · 1 comment
Assignees
Labels
area: language Issues related to the design of the language. state: deliberation Issues that require design work and/or discussion.
Milestone

Comments

@alexrp
Copy link
Sponsor Member

alexrp commented Feb 19, 2023

A module A can declare that module B is a friend and so is allowed to access private members of A. The keyword is already reserved.

Something like this:

a.cel:

mod {
    friend B;

    fn foo() {
        42;
    }
}

b.cel:

mod {
    fn bar() {
        A.foo(); // OK; no panic.
    }
}

For this to work, the semantics of a field expression (. operator) would be changed to pass along the accessing module when looking up the member. The runtime would then check if the resolved module declares the accessing module as a friend.

This sounds inefficient, but I think object shapes and basic block versioning based on types would allow us to fully specialize most such cases. This feature can only realistically be prototyped and considered once we have a runtime capable of such optimizations.

This is tentatively approved for 2.0, pending prototyping.

@alexrp alexrp added state: deliberation Issues that require design work and/or discussion. type: feature area: language Issues related to the design of the language. labels Feb 19, 2023
@alexrp alexrp added this to the v2.0 milestone Feb 19, 2023
@alexrp alexrp self-assigned this Feb 19, 2023
@alexrp alexrp added state: approved Enhancements and tasks that have been approved. and removed state: deliberation Issues that require design work and/or discussion. labels Feb 20, 2023
@alexrp
Copy link
Sponsor Member Author

alexrp commented May 7, 2023

Having thought through the design of basic block versioning and shapes in the runtime, I'm now completely confident this can be implemented in a performant way.

That said, there are still some design issues here that I want to think through. For example, what if a module A declares friend B - is it also a friend of B::C?

@alexrp alexrp added state: deliberation Issues that require design work and/or discussion. and removed state: approved Enhancements and tasks that have been approved. labels May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: language Issues related to the design of the language. state: deliberation Issues that require design work and/or discussion.
Development

No branches or pull requests

1 participant