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.
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
Mixin Template Intermediary Storage #237
base: master
Are you sure you want to change the base?
Mixin Template Intermediary Storage #237
Changes from all commits
c0a4f07c1f054d0bfff0bFile filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Mixin Template Intermediary Storage
Abstract
Use intermediary variables inside mixin template without making it get included in the code generation.
Contents
Rationale
Using mixin template inside a class scope does not allow you to define intermediary data (as this intermediary data will be included in the class as members, which can cause unintended behavior). The common solution to that has been to generate a mixin template that executes a string mixin with a function, such as that:
The problem with that approach is that it introduces a lot of mental friction from getting the syntax correctly inside a string, it makes compilation times slower as the possibility of using
formator string append is really high.Another pattern that is also used for using variables inside
mixin template, is creating a private template containg all variables necessary inside the mixin template:In summary, this is an attempt to make
mixin templatemore capable. The following code errors out today with redefinition:As this code is not being able to compile, to run that code without using the string mixin or template trick, one would need to:
This makes the code fairly unreadable and a lot more verbose. With the proposed solution, one could even reduce templates usage by using the following code:
The proposed solution for this problem is then the keywords
mixin private:Prior Work
No prior work has been done on that.
Description
All code inside
mixin privatewill need to be evaluated on compilation time, and will be usable insidemixin template.It must allow redefinition of variables or have other kind of mechanism for compatibility with
static foreach(maybe generating an specific scope for mixin templates).Breaking Changes and Deprecations
Breaking changes aren't anticipated as both
mixinandprivatekeywords are reserved and the combination of them still doesn't exists.Copyright & License
Copyright (c) 2022 by the D Language Foundation
Licensed under Creative Commons Zero 1.0
Reviews
The DIP Manager will supplement this section with a summary of each review stage of the DIP process beyond the Draft Review.