Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes the API for making existing modules (e.g. the standard library) compatible with Dx.
All functions that take functions as arguments must be implemented natively, i.e. not via
defd
but via explicit handling of Dx-internal return types, usually{:ok, ...}
or{:not_loaded}
.To aid with the implementation, the Dx compiler provides an API to pre-process the arguments before they're passed to the functions, e.g. loading any scopes (used to lazily translate Elixir code to SQL). See the extension API docs for more info. The compiler can skip any unneeded functions, and perform other optimizations.
This API is currently defined via a callback function,
__fun_info(fun_name, arity)
.This PR introduces annotations that are co-located with the function definitions, instead of defining all callback clauses at the top of the module, and implementing the functions further below. See the changed in
Dx.Enum
in this PR for an example.To pick up the annotations,
def
must be changed todefd_
, standing for "native defd". The only difference currently being that it supports the annotations.Further options
These options are non-exclusive:
Allow annotations for
def
(removingdefd_
)This would make it more intuitive, as it's in line with libraries such as decorator.
On the other hand, keeping
defd_
could be used to define modules with a mix ofdefd
,defd_
anddef
(not compatible with defd) functions.Rename the callback & annotations to
__dx_compile__
and@dx_compile
This would make it clearer that it's an interface for instructions to the Dx compiler.