-
Notifications
You must be signed in to change notification settings - Fork 205
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
How do we restrict core libraries for macros? #1916
Comments
Options 1 and 2 definitely sound more "proper" than number 3. Making every function throw a runtime error, while maybe consistent with the potential Based on that I'd say option 1. Option 2 is safe, but then writing an import line is essentially dead code, so option 1 would cover that base too. |
I have always assumed we would do option 1, and use the existing libraries.json files to support it, so its essentially just another platform, with its own set of available libraries. In practice though, if we run macros inside the compiler isolate itself, that might be a bit weird to deal with enforcing. |
Option 1 works for me too if we can pull it off. I do worry that it can end up being too conservative. If any library in the entire transitive import graph from the macro definition imports a forbidden library—even if it doesn't use it—the macro won't compile. That's more or less the situation with libraries like |
Disabling From my naive point of view, static meta programming will be mainly used by code that is not complex but solves repetitive tasks, which does not require external libraries. That's a big assumption on my part but you could judge the need for the unrestrictiveness better by first being overly restrictive. |
I think option 1 is the right (and achievable) approach. A platform library is either available or not, and if we want to prevent I'd very much prefer if the core platform libraries are available: We possibly want I fully expect people to request On the other I'd be very worried about adding restrictions on the features of individual platform libraries (option 3). I see no good way (or reason) to disable |
The macro proposal says:
What does this mean precisely? Some options:
It is a compile-time error for the macro class created by a macro application to be declared in a library that contains an import of any prohibited library, imports any other library (transitively) that contains a prohibited import.
It is a compile-time error for a macro class to refer to anything imported from a prohibited library. In other words, it's like the libraries exist but are completely empty.
It is a macro execution-time error to call any function or method in a prohibited library. In other words, it's like the libraries exist but all function and method bodies are
throw UnsupportedError()
.I think we will also want to restrict some functionality in libraries that are otherwise allowed. For example,
dart:core
is allowed, butDateTime.now()
should not be (#1915). Given that, option 3 might be the most consistent choice. In other words, all libraries are available but some functionality throws a runtime error. And it just happens to be that in some libraries likedart:isolate
that all functions throw runtime errors.I think there is prior art here for how things like
dart:io
are handled on Flutter that we can consult.The text was updated successfully, but these errors were encountered: