-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
[Containers] add utilities to support extensions writing macros #3620
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3620 +/- ##
==========================================
+ Coverage 98.14% 98.15% +0.01%
==========================================
Files 43 43
Lines 5651 5634 -17
==========================================
- Hits 5546 5530 -16
+ Misses 105 104 -1 ☔ View full report in Codecov by Sentry. |
3d21bfa
to
ea44fe4
Compare
I tried this out in InfiniteOpt: infiniteopt/InfiniteOpt.jl#334 |
One workflow that I ended up copy and pasting a lot is: base_name = get(kwargs, :base_name, string(something(name, "")))
if base_name isa Expr
base_name = esc(base_name)
end
name_expr = _base_name_with_indices(base_name, index_vars) where I also directly copied: function _base_name_with_indices(base_name, index_vars::Vector)
if isempty(index_vars) || base_name == ""
return base_name
end
expr = Expr(:call, :string, base_name, "[")
for index in index_vars
# Converting the arguments to strings before concatenating is faster:
# https://github.com/JuliaLang/julia/issues/29550.
push!(expr.args, :(string($(esc(index)))))
push!(expr.args, ",")
end
expr.args[end] = "]"
return expr
end It would be nice to have a public function of the form: function parse_name_expr(name, kwargs, index_vars)
base_name = pop!(kwargs, :base_name, string(something(name, "")))
if base_name isa Expr
base_name = esc(base_name)
end
return _base_name_with_indices(base_name, index_vars)
end |
Added |
Thanks, I just updated the InfiniteOpt PR accordingly. |
Nice. I think we're converging on some good improvements to the macro code. |
196d9e4
to
b3ad761
Compare
I'm fairly happy with this, so I'd propose we merge unless there are suggestions for further improvements. It has made infiniteopt/InfiniteOpt.jl#334 a lot nicer |
I'll merge this for now. Then I plan to open a PR ticking off the macro rewrite from the roadmap, so that can be the gate for people to review the full sequence of changes that I have been making. We're not in a rush to release JuMP v1.18. |
Part of #3513