-
Notifications
You must be signed in to change notification settings - Fork 6
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 an inverse use
block
#362
Comments
So this would essentially create a "hole" (or maybe "shadow" is a better metaphor) in the use of a resource. I'm not sure why this would be useful. Can you sketch an example of where you'd want it? |
This was something I was proposing for Plasma, I was thinking about some supply chain and similar attacks that can happen when dependencies change. One day you have some code that's like: A logging library provides this function, which uses the logging resource.
So you use it in your code:
Note that the
When you re-compile your application you're not aware that the logging code now has access to the password database. It can read and change passwords! But you never chose that because you hadn't read the updated declaration. There's probably other ways to solve this, like checking changed declarations. Having a scope that white/black-lists particular resources is one way you can make it very clear in your code what's acceptable within the scope:
Now an update to the library that adds additional resources will cause a compilation error. And you'll be asking "why would a logging framework need access to the password database?" |
That's an interesting example, Paul, not something I've thought about. To use something like |
So I imagine that you'd only use one of these scopes when you want to change what's implicitly available. if you don't use any scope then the same things are available to "capture". And the trap with resources is that they're captured less obviously than variables (eg in lambdas). My example above uses a whitelist of "these are the resources that should be available, everything else is denied". I'm not sure if the example is all that motivating. It'd have to be a pretty targeted supply chain attack, but there may be other reasons to do this also. |
If you have some "sensitive" value that you don't want widely shared, you shouldn't put it in a resource. So the motivating example for a You have a good point about resources being easily captured. Each proc that uses a resource controls what they have access to, but they don't control what resources are used by the procs they call, except that it must be a subset of the resources they have access to themselves. But if they want to, they can control that, too, by calling a proc they write themselves with a limited |
Interesting. That means that something like i.e.,
is equivalent to
This would differ slightly when there are variables being bound in the block, but they can be passed in/out as additional parameters, as would the arguments of I think there would be some merit to having this as a language feature, with a similar argument to wanting a lambda block, though a little bit weaker as I'd consider this less useful than a lambda. |
That's what I assumed the semantics of I agree that Can't you achieve the effect of lambda with code like |
Why couldn't we handle HO resources as we currently do, in that we can't stop a HO term from using a resource. In essence, a HO term can always use it's in scope resources, even if the resource isn't in the current scope. That would mean something like this is possible
This is inline with the current semantics of HO resources, as this is possible
These procs, I don't think |
We could, but this is a flaw, as it violates interface integrity. I'm hoping we can eventually add an analysis to check that HO code is using resources properly, without violating interface integrity, and report an error if not.
I think I'm just misunderstanding what you mean by "lambda". If code like |
Once a resource is in scope it is always in scope for the current block. Adding an inverse
use
block (disuse
, name tentative) would allow you to have a block of code where a resource is unavailable inside, assuming it was previously in scope. This would allow you to ensure that you have not accidentally used a resource.For example,
I'm unsure of how this would be handled in the case of higher order calls, as there's no way to ensure a higher order call doesn't use a resource. It could be a useful way of ensuring a resource isn't used inside a closure, too.
This could be extended to variables in general without much difference. Mode checking could simply place these variables/resources as out of scope inside this block.
The text was updated successfully, but these errors were encountered: