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

Add code to generate signature from Method #1

Merged
merged 30 commits into from
Apr 14, 2020
Merged

Add code to generate signature from Method #1

merged 30 commits into from
Apr 14, 2020

Conversation

oxinabox
Copy link
Member

@oxinabox oxinabox commented Mar 5, 2020

Goal is to generate a dictionary like is returned from splitdef when given only a Method object.
So that you can manipulate it,
and then call combinedef on the result, to get the AST of the code you want to eval.

@oxinabox
Copy link
Member Author

oxinabox commented Mar 5, 2020

Not tests show that it works for VarArgs

@codecov
Copy link

codecov bot commented Mar 5, 2020

Codecov Report

Merging #1 into master will increase coverage by 3.64%.
The diff coverage is 98.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #1      +/-   ##
==========================================
+ Coverage   94.93%   98.58%   +3.64%     
==========================================
  Files           2        4       +2     
  Lines          79      141      +62     
==========================================
+ Hits           75      139      +64     
+ Misses          4        2       -2     
Impacted Files Coverage Δ
src/ExprTools.jl 100.00% <ø> (ø)
src/method.jl 98.30% <98.30%> (ø)
src/function.jl 98.73% <100.00%> (+3.86%) ⬆️
src/type_utils.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0ecb56a...7819b56. Read the comment docs.

@oxinabox
Copy link
Member Author

oxinabox commented Mar 5, 2020

Turns out this does not work in Julia 1.0, because I access a field of Method that doesn't exist

src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
test/method.jl Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
test/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
test/function.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
@oxinabox oxinabox changed the title Add code to generate signature from Method WIP: Add code to generate signature from Method Mar 18, 2020
@oxinabox oxinabox changed the title WIP: Add code to generate signature from Method Add code to generate signature from Method Mar 27, 2020
src/method.jl Outdated
return whereparams
end

function parameters(meth::Method)
Copy link
Member Author

@oxinabox oxinabox Mar 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It bothers me a bit that this shared a name with the other parameters method.
Though I guess they do the same thing.

One option would be to rename this to params to match the dict key it is filling

src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
test/method.jl Outdated Show resolved Hide resolved
Copy link
Contributor

@omus omus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests currently failing with:

LoadError: syntax: unsupported `const` declaration on local variable around /home/travis/build/invenia/ExprTools.jl/test/method.jl:136

@oxinabox
Copy link
Member Author

oxinabox commented Apr 9, 2020

Tests currently failing with:

LoadError: syntax: unsupported `const` declaration on local variable around /home/travis/build/invenia/ExprTools.jl/test/method.jl:136

This only happens in 1.0
I think this is to do with the scoping of the creation of a struct inside of a @testset.
But if I declare it outside the testset I struggle with finding its methods.

I am tempted to just disable this test in 1.0

@oxinabox
Copy link
Member Author

oxinabox commented Apr 9, 2020

How close is this to being ready for merge @omus ?

@omus
Copy link
Contributor

omus commented Apr 9, 2020

How close is this to being ready for merge @omus ?

I was mainly waiting for the tests to be fixed. I think we're pretty close to merging. I'll do another review today but I think we're in pretty good shape.

test/function.jl Show resolved Hide resolved
test/method.jl Outdated Show resolved Hide resolved
test/method.jl Outdated Show resolved Hide resolved
haskey(target, :params) && @test target[:params] == get(candidate, :params, nothing)
haskey(target, :args) && @test target[:args] == get(candidate, :args, nothing)
haskey(target, :whereparams) &&
@test target[:whereparams] == get(candidate, :whereparams, nothing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add tests for the other fields that splitdef returns and just use @test_broken?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is required. Do you think it is?
Right now we are matching what we have documented it does I would.
Should we save test broken for actual bugs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do @test !haskey(candidate, :rtype) to ensure these aren't set which is what we expect. If someone attempts to get these working then the test will fail and they will need to update these tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i became convinced and added @test_broken

test/method.jl Outdated Show resolved Hide resolved
test/method.jl Outdated Show resolved Hide resolved
test/method.jl Show resolved Hide resolved
test/method.jl Outdated Show resolved Hide resolved
test/method.jl Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
test/method.jl Outdated Show resolved Hide resolved
test/method.jl Outdated Show resolved Hide resolved

Limitted support for:
- `:kwargs`: Keyword arguments of the function.
Only the names will be included, not the default values or type constraints.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this much support is exactly as hard as detecting if there are any or not.

Copy link
Contributor

@nickrobinson251 nickrobinson251 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I can see all of @omus's comments have been addressed, and tests pass (and are thorough) 👍

src/method.jl Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
src/method.jl Outdated Show resolved Hide resolved
oxinabox and others added 2 commits April 14, 2020 15:39
Co-Authored-By: Nick Robinson <[email protected]>
Co-Authored-By: Nick Robinson <[email protected]>
@oxinabox oxinabox merged commit 5b643de into master Apr 14, 2020
@nickrobinson251 nickrobinson251 deleted the ox/method branch April 14, 2020 15:32
@omus
Copy link
Contributor

omus commented Apr 20, 2020

Thanks @nickrobinson251

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants