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

Toplevel error when checking package Convex #281

Closed
goerch opened this issue Dec 4, 2021 · 5 comments · Fixed by #283
Closed

Toplevel error when checking package Convex #281

goerch opened this issue Dec 4, 2021 · 5 comments · Fixed by #283

Comments

@goerch
Copy link
Contributor

goerch commented Dec 4, 2021

┌ @ C:\Users\Win10\.julia\packages\Convex\uI27T\src\variable.jl:204 
│ UndefRefError: access to undefined reference
└───────────────────────────────────────────────────────────────────
@goerch
Copy link
Contributor Author

goerch commented Dec 4, 2021

handle_err shows the problem to occur here

handle_err UndefRefError() Frame for Main.##JETVirtualModule#278.Convex
   1 204  1 ─ %1  = Int32[0, 1, 2]
   2 204  │   %2  = ($(QuoteNode(Base.IteratorSize)))(%1)
   3 204  │   %3  = %2 isa $(QuoteNode(Base.SizeUnknown))
   4 204  │   %4  = Base._array_for($(QuoteNode(Any)), %1, %2)
   5 204  │   %5  = ($(QuoteNode(LinearIndices)))(%4)
   6 204  │         @_2 = Base.first(%5)
   7 204  │         #s9 = Base.iterate(%1)
   8 204  │   %8  = #s9 === nothing
   9 204  │   %9  = ($(QuoteNode(Core.Intrinsics.not_int)))(%8)
  10 204  └──       goto #7 if not %9
  11 204  2 ┄ %11 = #s9
  12 204  │         v = Core.getfield(%11, 1)
  13 204  │   %13 = Core.getfield(%11, 2)
  14 204  │   %14 = VarType(v)
  15 204  │         nothing
  16 204  └──       goto #4 if not %3
  17 204  3 ─       Base.push!(%4, %14)
  18 204  └──       goto #5
  19 204  4 ─       Base.setindex!(%4, %14, @_2)
  20 204  5 ┄       nothing
  21 204  │         @_2 = ($(QuoteNode(Core.Intrinsics.add_int)))(@_2, 1)
  22 204  │         #s9 = Base.iterate(%1, %13)
  23 204  │   %23 = #s9 === nothing
  24 204  │   %24 = ($(QuoteNode(Core.Intrinsics.not_int)))(%23)
  25 204  └──       goto #7 if not %24
  26 204  6 ─       goto #2
  27 204  7 ┄ %27 = Core._apply_iterate($(QuoteNode(iterate)), $(QuoteNode(tuple)), %4)
  28 204  │         insts = %27
  29 205  │   %29 = Base.getproperty($(QuoteNode(Base)), :instances)
  30 205  │   %30 = Core.Typeof(%29)
  31 205  │   %31 = Core.apply_type($(QuoteNode(Type)), VarType)
  32 205  │   %32 = Core.svec(%30, %31)
  33 205  │   %33 = Core.svec()
  34 205  │   %34 = Core.svec(%32, %33, $(QuoteNode(:(#= Enums.jl:205 =#))))
  35 205  │   %35 = $(Expr(:copyast, :($(QuoteNode(Any[Symbol("#self#"), Symbol("#unused#")])))))
  36 205  │   %36 = $(Expr(:copyast, :($(QuoteNode(Any[Any[Any[Symbol("#self#"), :(Core.Any), 0], Any[Symbol("#unused#"), :(Core.Any), 0]], Any[], 2, Any[]])))))
  37 205  │   %37 = ($(QuoteNode(QuoteNode)))(insts)
  38 205  │   %38 = $(Expr(:copyast, :($(QuoteNode(:(return %1))))))
  39 205  │   %39 = Core._expr(:block, %37, %38)
  40 205  │   %40 = $(Expr(:copyast, :($(QuoteNode(Any[1, 1])))))
  41 205  │   %41 = $(Expr(:copyast, :($(QuoteNode(Any[Core.LineInfoNode(Main.##JETVirtualModule#278.Convex, :none, Symbol("Enums.jl"), 205, 0)])))))
  42 205  │   %42 = Core._expr(:lambda, %35, %36, %39, %40, %41)
  43 205  │         $(Expr(:method, nothing, :(%34), :(%42)))
  44 205  └──       return nothing```

at pc 27, JET references this source code

    function Variable(size::Tuple{Int, Int}, sign::Sign, vartype::VarType)
        if iscomplex(sign) && vartype != ContVar
            throw(ArgumentError("vartype must be `ContVar` for complex variables; got vartype = $vartype"))
        end
-->     this = new(:variable, 0, nothing, size, AffineVexity(), sign, Constraint[], vartype) 
        this.id_hash = objectid(this)
        return this
    end
        this = new(:variable, 0, nothing, size, AffineVexity(), sign, Constraint[], vartype)

in variable.jl at line 204.

@goerch
Copy link
Contributor Author

goerch commented Dec 4, 2021

This looks a bit like trouble with Enums, see #175.

Edit: no, when isolating the struct and the dependents, report_file seems to work fine...

@enum VarType BinVar IntVar ContVar

const Value = Union{Number, AbstractArray}
const ValueOrNothing = Union{Value, Nothing}

abstract type Vexity end
struct AffineVexity <: Vexity end

abstract type Sign end

abstract type Constraint end

abstract type AbstractVariable end
mutable struct Variable <: AbstractVariable
    head::Symbol
    id_hash::UInt64
    value::ValueOrNothing
    size::Tuple{Int, Int}
    vexity::Vexity
    sign::Sign
    constraints::Vector{Constraint}
    vartype::VarType
    function Variable(size::Tuple{Int, Int}, sign::Sign, vartype::VarType)
        if iscomplex(sign) && vartype != ContVar
            throw(ArgumentError("vartype must be `ContVar` for complex variables; got vartype = $vartype"))
        end
        this = new(:variable, 0, nothing, size, AffineVexity(), sign, Constraint[], vartype)
        this.id_hash = objectid(this)
        return this
    end
end

Maybe the order of includes matters?

@goerch
Copy link
Contributor Author

goerch commented Dec 4, 2021

This could be:

### modeling framework
include("dcp.jl")
include("expressions.jl")
# need to define `Variable` before `UniqueConicForms`
include("variable.jl")
include("conic_form.jl")
# need to define `conic_form!` for `Variable`s after `UniqueConicForms`
include("variable_conic_form.jl")
include("constant.jl")
include("constraints/constraints.jl")
include("constraints/signs_and_sets.jl")
include("constraints/soc_constraints.jl")
include("constraints/exp_constraints.jl")
include("constraints/sdp_constraints.jl")
include("problems.jl")
include("solution.jl")

constraints.jl is included after variable.jl for example.

@goerch
Copy link
Contributor Author

goerch commented Dec 4, 2021

Would multiple passes help here somehow? Or maybe the internal constructor is the problem?

@goerch
Copy link
Contributor Author

goerch commented Dec 4, 2021

Doing it this way

@enum VarType BinVar IntVar ContVar

const Value = Union{Number, AbstractArray}
const ValueOrNothing = Union{Value, Nothing}

abstract type Vexity end
struct AffineVexity <: Vexity end

abstract type Sign end

abstract type AbstractVariable end
mutable struct Variable <: AbstractVariable
    head::Symbol
    id_hash::UInt64
    value::ValueOrNothing
    size::Tuple{Int, Int}
    vexity::Vexity
    sign::Sign
    constraints::Vector{Constraint}
    vartype::VarType
    function Variable(size::Tuple{Int, Int}, sign::Sign, vartype::VarType)
        if iscomplex(sign) && vartype != ContVar
            throw(ArgumentError("vartype must be `ContVar` for complex variables; got vartype = $vartype"))
        end
        this = new(:variable, 0, nothing, size, AffineVexity(), sign, Vector{Constraint}(), vartype)
        this.id_hash = objectid(this)
        return this
    end
end

abstract type Constraint end

I see

│ UndefVarError: Constraint not defined

This seems to support the hypothesis. I don't understand the difference in message yet. Interestingly enough it is not the constructor but the member which induces the top level error.

Edit: but the above isn't valid Julia either. Now I'm perplexed: they are using some trick I'm missing...

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 a pull request may close this issue.

1 participant