Skip to content
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

Merged
merged 9 commits into from
Dec 14, 2023

Conversation

odow
Copy link
Member

@odow odow commented Dec 11, 2023

Part of #3513

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (44b56b1) 98.14% compared to head (b3ad761) 98.15%.

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.
📢 Have feedback on the report? Share it here.

@odow odow changed the title [Containers] add container_name [Containers] add parse_ref_sets Dec 11, 2023
@odow odow mentioned this pull request Dec 11, 2023
@odow odow changed the title [Containers] add parse_ref_sets [Containers] add utilities to support extensions writing macros Dec 11, 2023
@pulsipher
Copy link
Contributor

I tried this out in InfiniteOpt: infiniteopt/InfiniteOpt.jl#334

@pulsipher
Copy link
Contributor

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

@odow
Copy link
Member Author

odow commented Dec 12, 2023

Added Containerss.name_with_index_expr

@pulsipher
Copy link
Contributor

Added Containerss.name_with_index_expr

Thanks, I just updated the InfiniteOpt PR accordingly.

test/Containers/test_macro.jl Outdated Show resolved Hide resolved
docs/make.jl Outdated Show resolved Hide resolved
@odow
Copy link
Member Author

odow commented Dec 12, 2023

Nice. I think we're converging on some good improvements to the macro code.

@odow
Copy link
Member Author

odow commented Dec 13, 2023

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

@odow
Copy link
Member Author

odow commented Dec 14, 2023

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.

@odow odow merged commit 65d12dc into master Dec 14, 2023
12 checks passed
@odow odow deleted the od/container-name branch December 14, 2023 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants