-
Notifications
You must be signed in to change notification settings - Fork 375
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
[ elab ] Make %macro
-function be callable without the ElabReflection
extension
#3034
Conversation
ca1a3c1
to
a58356f
Compare
a58356f
to
99741bd
Compare
50ccae5
to
60e851c
Compare
So to reiterate, this would allow modules without the elab extension turned on, to depend on libraries that use macro functions internally, if they dont expose that implementation detail to the end user? |
It depends on what you are calling the implementation detail. E.g., if there is a library that internally uses some macro function, but this is completely not exposed to the end user, it is okay now. E.g.: module Lib1
import public Language.Reflection
export %macro
deriveNiceThing : Params -> Elab NiceThing
... module Lib2
import Lib1
%language ElabReflection
export
aNiceThing : NiceThing
aNiceThing = deriveNiceThing niceThingParams module SomeApp
import Lib2
usageOfNiceThing : Nat
usageOfNiceThing = someComputationOf aNiceThing In this case a library But if we look at the |
f8704b9
to
5422495
Compare
"Lib2 which uses this function as if it is a regular function of type Params -> NiceThing, needs to declare %language Elab.Reflection" |
No, So, answering shortly, |
While I support the idea of making macros more accessible by detaching them from the ElabReflection extension, I think it's crucial that they still require a specific extension to activate. Metaprogramming features have a history of being revised or updated, either for better design or to prevent unintended leakage of internal language details. Take Rust as an example. It started with compiler plugins and pattern-matching macros. Later, more advanced procedural macros were introduced. These were initially intended to only replace compiler plugins but ended up largely replacing the first macro system as well due to its limitations and flaws. Eventually rust attempted to replace its pattern-matching macros with a new system, but this turned out to be a much bigger undertaking than anticipated, leaving the situation unresolved. That situation would have been even more complicated if those features had been available by default, Idris 2 should keep current macros feature gated as well, potentially under a dedicated extension. This approach minimizes the risk of complications as the language evolves |
I don't understand how this approach minimizes the risk. I, as a library author, either solve a problem with a macro, or I don't solve the problem. A user either has to use some extension (currently, |
5422495
to
4649a2b
Compare
Probably worth talking about it during one of the weekly meetings to get @edwinb's opinion. |
Looks like next week's meeting was cancelled. We should coordinate on discord whether we can all discuss this the week after that |
4649a2b
to
5d9465e
Compare
Description
Macro-functions are a great way of hiding some complex thing in a library without showing this to a user. A pretty example was shown as a motivating example in PR #2930.
But since currently call to a macro function, generally, is just a
%runElab
of an appropriate expression, each use of such function means to users that they need to turn on the language extension flagElabReflection
, despite they may not feel why.I mean, imagine a library that does some hard stuff in a macro function (like enabling some syntax in PR mentioned above, or some DSL-y thing), and user just imports this library and uses its functions and gets "
%language ElabReflection not enabled
" all the time. I understand this requirement in explicit%runElab
expressions and declarations -- here a user explicitly has chosen to run an elaboration script and we hope they know what they are doing, thus, this is their responsibility to say explicitly that they want this extension.But
%macro
function seem to fill the different use case, when we want to hide this machinery from the user, i.e. to put all the responsibility on the effects to the library's author. But the current setting makes such library's user still to enable an extension, which, probably, they don't understand. The current setting also unables library authors to change existing function definition to a%macro
without additional requirements from the users to enable the extension.So, my suggestion is to enable usage of
%macro
-functions without the language extension, with no change in the behaviour of explicit%runElab
calls. This is fully a backward-compatible change. This PR does this, among with couple of tiny textual improvements.Should this change go in the CHANGELOG?
implementation, I have updated
CHANGELOG.md
(and potentially alsoCONTRIBUTORS.md
).