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

Allow resources with the same name to be imported from different modules and used in statements/expressions #431

Open
pschachte opened this issue Dec 11, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@pschachte
Copy link
Owner

This will permit a much more satisfactory fix for #414. Until then, procs that use the multiple resources with the same resource name (and different modules) can't be supported, and that includes any module that imports multiple modules that each define initialised resources with the same name and has top-level code.

@pschachte pschachte added the enhancement New feature or request label Dec 11, 2023
@jimbxb
Copy link
Collaborator

jimbxb commented Dec 11, 2023

An alternative to this could be to support aliases for resources. Something like this:

use resource foo.res as foo_res
use resource bar.res as bar_res

def proc use !foo_res, !bar_res in {
    pass
}

This would also be beneficial for module imports too, I think.

Implementation wise, an extra normalisation pass would be required, transforming resource aliases into their fully qualified names, and then replacing any resource-variable reference with that alias as a reference to said resource.

@pschachte
Copy link
Owner Author

That's a great idea! I'll change the title of this issue.

@pschachte pschachte changed the title Allow resource names to be module qualified in statements/expressions Allow resources with the same name to be imported from different modules and used in statements/expressions Dec 11, 2023
@jimbxb
Copy link
Collaborator

jimbxb commented Dec 11, 2023

I'm thinking also, we could do this at the proc level:

def proc use !foo.res as foo_res, !bar.res as foo_res {
    pass
}

It has the benefit of being easier to parse (as we don't have a new top-level item to parse, and can also be extended to use blocks:

use foo.res as foo_res in {
    pass
}

but it has the downside of being repeated everywhere the resource is used if there's a conflict in that proc/use block.

Now that I'm thinking about it, though, I like my original syntax better. It has the benefit of being applicable to more than just resources, potentially giving aliases for procs and types 👀

@pschachte
Copy link
Owner Author

One of the principles of resources is to name things consistently. Of course, the case under discussion is where we can't do that due to conflict, but I think it's still desirable in this case to be as consistent as we can. In this case, that's file-level consistency, which your first suggestion provides.

I'm not sure if it's really warranted, but we could generalise this idea to cover procs and functions and even types by providing a syntax to rename things as they are imported. Maybe generalise the existing from ... use ... syntax, something like

from foo.bar use foobar_res = res, fbfunc = func, t = type

to use the name foobar_res for the resource foo.bar.res, use fbfunc to call foo.bar.func, and use the name t for the type type.

@jimbxb
Copy link
Collaborator

jimbxb commented Dec 17, 2023

I like the idea of having aliases for anything that can be exported. Using from would introduce a new keyword (which isn't necessarily a bad thing), but I think we could do with with less. Something like

use module (alias = submodule.item, other = type)

I assume that this aliasing would have to be restricted to aliasing all items that have the same name (synonymous procs with differing arities/modes), unless we introduce some syntax for that, a la

use module (inout = proc(+,-))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants