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

kwargs are annoying in the debugger #141

Closed
Keno opened this issue Mar 24, 2019 · 12 comments
Closed

kwargs are annoying in the debugger #141

Keno opened this issue Mar 24, 2019 · 12 comments

Comments

@Keno
Copy link
Member

Keno commented Mar 24, 2019

Here's a transcript of what I had to do to get through a bunch of kwargs:

1|debug > n
In attach_optimizer(model) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Utilities/cachingoptimizer.jl:128
128       @assert model.state == EMPTY_OPTIMIZER
129       # We do not need to copy names because name-related operations are handled by `m.model_cache`
130       indexmap = MOI.copy_to(model.optimizer, model.model_cache, copy_names=false)
131       model.state = ATTACHED_OPTIMIZER
132       # MOI does not define the type of index_map, so we have to copy it into a

About to run: (Core.apply_type)(NamedTuple, (:copy_names,))
1|debug > nc
In attach_optimizer(model) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Utilities/cachingoptimizer.jl:128
128       @assert model.state == EMPTY_OPTIMIZER
129       # We do not need to copy names because name-related operations are handled by `m.model_cache`
130       indexmap = MOI.copy_to(model.optimizer, model.model_cache, copy_names=false)
131       model.state = ATTACHED_OPTIMIZER
132       # MOI does not define the type of index_map, so we have to copy it into a

About to run: (tuple)(false)
1|debug >
In attach_optimizer(model) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Utilities/cachingoptimizer.jl:128
128       @assert model.state == EMPTY_OPTIMIZER
129       # We do not need to copy names because name-related operations are handled by `m.model_cache`
130       indexmap = MOI.copy_to(model.optimizer, model.model_cache, copy_names=false)
131       model.state = ATTACHED_OPTIMIZER
132       # MOI does not define the type of index_map, so we have to copy it into a

About to run: (NamedTuple{(:copy_names,),T} where T<:Tuple)((false,))
1|debug >
In attach_optimizer(model) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Utilities/cachingoptimizer.jl:128
128       @assert model.state == EMPTY_OPTIMIZER
129       # We do not need to copy names because name-related operations are handled by `m.model_cache`
130       indexmap = MOI.copy_to(model.optimizer, model.model_cache, copy_names=false)
131       model.state = ATTACHED_OPTIMIZER
132       # MOI does not define the type of index_map, so we have to copy it into a

About to run: (Core.kwfunc)(MathOptInterface.copy_to)
1|debug >
In attach_optimizer(model) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Utilities/cachingoptimizer.jl:128
128       @assert model.state == EMPTY_OPTIMIZER
129       # We do not need to copy names because name-related operations are handled by `m.model_cache`
130       indexmap = MOI.copy_to(model.optimizer, model.model_cache, copy_names=false)
131       model.state = ATTACHED_OPTIMIZER
132       # MOI does not define the type of index_map, so we have to copy it into a

About to run: (getproperty)(<suppressed 28148 bytes of output>, :optimizer)
1|debug >
In attach_optimizer(model) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Utilities/cachingoptimizer.jl:128
128       @assert model.state == EMPTY_OPTIMIZER
129       # We do not need to copy names because name-related operations are handled by `m.model_cache`
130       indexmap = MOI.copy_to(model.optimizer, model.model_cache, copy_names=false)
131       model.state = ATTACHED_OPTIMIZER
132       # MOI does not define the type of index_map, so we have to copy it into a

About to run: (getproperty)(<suppressed 28148 bytes of output>, :model_cache)
1|debug >
In attach_optimizer(model) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Utilities/cachingoptimizer.jl:128
128       @assert model.state == EMPTY_OPTIMIZER
129       # We do not need to copy names because name-related operations are handled by `m.model_cache`
130       indexmap = MOI.copy_to(model.optimizer, model.model_cache, copy_names=false)
131       model.state = ATTACHED_OPTIMIZER
132       # MOI does not define the type of index_map, so we have to copy it into a

About to run: (<suppressed 52 bytes of output>)((copy_names = false,), MathOptInterface.copy_to, <suppressed 16897 bytes of output>, <suppressed 10650 bytes of output>)
1|debug > s
In #copy_to(, , mock, src) at none:0
?
About to run: (pairs)((copy_names = false,))
1|debug > nc
In #copy_to(, , mock, src) at none:0
?
About to run: (MathOptInterface.Bridges.#copy_to#1)(Base.Iterators.Pairs(:copy_names => 0), MathOptInterface.copy_to, <suppressed 16897 bytes of output>, <suppressed 10650 bytes of output>)
1|debug > s
In #copy_to#1(kws, , mock, src) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Bridges/bridgeoptimizer.jl:91
91      MOIU.automatic_copy_to(mock, src; kws...)
92  end
93  function MOIU.supports_default_copy_to(b::AbstractBridgeOptimizer,

About to run: (NamedTuple)()
1|debug > nc
In #copy_to#1(kws, , mock, src) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Bridges/bridgeoptimizer.jl:91
91      MOIU.automatic_copy_to(mock, src; kws...)
92  end
93  function MOIU.supports_default_copy_to(b::AbstractBridgeOptimizer,

About to run: (merge)(NamedTuple(), Base.Iterators.Pairs(:copy_names => 0))
1|debug >
In #copy_to#1(kws, , mock, src) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Bridges/bridgeoptimizer.jl:91
91      MOIU.automatic_copy_to(mock, src; kws...)
92  end
93  function MOIU.supports_default_copy_to(b::AbstractBridgeOptimizer,

About to run: (isempty)((copy_names = false,))
1|debug >
In #copy_to#1(kws, , mock, src) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Bridges/bridgeoptimizer.jl:91
91      MOIU.automatic_copy_to(mock, src; kws...)
92  end
93  function MOIU.supports_default_copy_to(b::AbstractBridgeOptimizer,

About to run: (Core.kwfunc)(MathOptInterface.Utilities.automatic_copy_to)
1|debug >
In #copy_to#1(kws, , mock, src) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Bridges/bridgeoptimizer.jl:91
91      MOIU.automatic_copy_to(mock, src; kws...)
92  end
93  function MOIU.supports_default_copy_to(b::AbstractBridgeOptimizer,

About to run: (<suppressed 72 bytes of output>)((copy_names = false,), <suppressed 44 bytes of output>, <suppressed 16897 bytes of output>, <suppressed 10650 bytes of output>)
1|debug > s
In #automatic_copy_to(, , dest, src) at none:0
?
About to run: (haskey)((copy_names = false,), :copy_names)
1|debug > nc
In #automatic_copy_to(, , dest, src) at none:0
?
About to run: (getindex)((copy_names = false,), :copy_names)
1|debug >
In #automatic_copy_to(, , dest, src) at none:0
?
About to run: (isa)(false, Bool)
1|debug >
In #automatic_copy_to(, , dest, src) at none:0
?
About to run: (Core.apply_type)(NamedTuple, (:copy_names,))
1|debug >
In #automatic_copy_to(, , dest, src) at none:0
?
About to run: (Base.structdiff)((copy_names = false,), NamedTuple{(:copy_names,),T} where T<:Tuple)
1|debug >
In #automatic_copy_to(, , dest, src) at none:0
?
About to run: (pairs)(NamedTuple())
1|debug >
In #automatic_copy_to(, , dest, src) at none:0
?
About to run: (isempty)(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}())
1|debug >
In #automatic_copy_to(, , dest, src) at none:0
?
About to run: (<suppressed 48 bytes of output>)(false, <suppressed 44 bytes of output>, <suppressed 16897 bytes of output>, <suppressed 10650 bytes of output>)
1|debug > s

I'm not really sure what the best thing to do here is. Perhaps we should by default automatically skip any builtins (and maybe other calls inserted by the kwarg lowering). At the very least, this transcript shows that this causes some problems.

@KristofferC
Copy link
Member

We already try to skip the "kwprep" (the setup before a kwarg call) but perhaps we miss some cases.

This would be easier to start working on if the function (ideally a MWE) was available to step through.

@pfitzseb
Copy link
Member

You sure you're on the latest versions of Debugger and JuliaInterpreter, @Keno? The REPL snippet looks like it's from a pretty old version.

@KristofferC
Copy link
Member

KristofferC commented Mar 24, 2019

Yeah, it doesn't show the line number indicator which was added quite a while back.

@pfitzseb
Copy link
Member

Also prints the ? instead of the CodeInfo, which shouldn't happen after #22.

@Keno
Copy link
Member Author

Keno commented Mar 24, 2019

Indeed, looks like my check out was old in this project. Will try again with master.

@Keno
Copy link
Member Author

Keno commented Mar 24, 2019

Same stepping behavior on master. FWIW, the thing I'm stepping through is JuliaLang/julia#31439 (step into optimize!, optimize!, attach_optimizer, and that's where the call to copy_to is that starts above transcript).

@timholy
Copy link
Member

timholy commented Mar 24, 2019

Could you get to the beginning of the trouble and then hit L to display the lowered code, then paste here?

@Keno
Copy link
Member Author

Keno commented Mar 24, 2019

In attach_optimizer(model) at /home/keno/.julia/packages/MathOptInterface/C3lip/src/Utilities/cachingoptimizer.jl:128
  6  └──       goto #3 if not %4
  7  2 ─       goto #4
  8  3 ─ %7  = (AssertionError)("model.state == EMPTY_OPTIMIZER")
  9  └──       (throw)(%7)
>10      @ /home/keno/.julia/packages/MathOptInterface/C3lip/src/Utilities/cachingoptimizer.jl:130 within `attach_optimizer'
 11  4 ┄ %9  = (:copy_names,)
 12  │   %10 = (Core.apply_type)(NamedTuple, %9)
 13  │   %11 = (tuple)(false)
 14  │   %12 = (%10)(%11)

@timholy
Copy link
Member

timholy commented Mar 24, 2019

A little farther forward please. You're starting to match this pattern but we need to see 15 and 16.

@Keno
Copy link
Member Author

Keno commented Mar 24, 2019

 15  │   %13 = MathOptInterface.copy_to
>16  │   %14 = (Core.kwfunc)(%13)
 17  │   %15 = MathOptInterface.copy_to
 18  │   %16 = (getproperty)(model, :optimizer)
 19  │   %17 = (getproperty)(model, :model_cache)
 20  │         indexmap = (%14)(%12, %15, %16, %17)

@timholy
Copy link
Member

timholy commented Mar 24, 2019

OK, that's the problem; the kwfunc call is offset by 5 rather than 4 from the tuple construction. I wish I knew what the rules were and didn't just have to figure this stuff out from failures.

I will fix. Can I ask if fixing JuliaLang/julia#31073 is on your radar? (It was caused by your PR JuliaLang/julia#28707.) We've come up with a workaround for Base and the stdlibs, but any package that explicitly ccalls memcpy will crash, and there's nothing we can do about that.

timholy added a commit to JuliaDebug/JuliaInterpreter.jl that referenced this issue Mar 24, 2019
This happens when the call is module-scoped.
Fixes JuliaDebug/Debugger.jl#141
timholy added a commit to JuliaDebug/JuliaInterpreter.jl that referenced this issue Mar 24, 2019
This happens when the call is module-scoped.
Fixes JuliaDebug/Debugger.jl#141
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

No branches or pull requests

4 participants