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

Fix various JET errors #2289

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Bridges/Constraint/bridges/set_dot_scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ end
function MOI.Bridges.map_set(
::Type{<:SetDotScalingBridge{T,S}},
set::S,
) where {T,S}
) where {T,S<:MOI.AbstractVectorSet}
return MOI.Scaled(set)
end

Expand Down Expand Up @@ -158,7 +158,7 @@ end
function MOI.Bridges.inverse_map_set(
::Type{<:SetDotInverseScalingBridge{T,S}},
set::S,
) where {T,S}
) where {T,S<:MOI.AbstractVectorSet}
return MOI.Scaled(set)
end

Expand Down
9 changes: 7 additions & 2 deletions src/Utilities/matrix_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ function set_from_constants end

Return the list of the types of the sets allowed in `sets`.
"""
function set_types end
function set_types(f::Any)
# Because these methods get defined in rather obtuse macros, it helps JET to
# have a default fallback implementation, even if it's identical to what
# would happen regardless.
return throw(MethodError(set_types, (typeof(f),)))
end

"""
set_index(sets, ::Type{S})::Union{Int,Nothing} where {S<:MOI.AbstractSet}
Expand Down Expand Up @@ -271,7 +276,7 @@ function rows end

MOI.is_empty(v::MatrixOfConstraints) = MOI.is_empty(v.sets)

function MOI.empty!(v::MatrixOfConstraints{T,AT,BT,ST}) where {T,AT,BT,ST}
function MOI.empty!(v::MatrixOfConstraints{T}) where {T}
MOI.empty!(v.coefficients)
empty!(v.constants)
MOI.empty!(v.sets)
Expand Down
3 changes: 2 additions & 1 deletion src/Utilities/struct_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,9 @@ function struct_of_constraint_code(struct_name, types, field_types = nothing)
# Here we make an internal constructor for our type. It needs to be an
# internal constructor to avoid someone trying to provide
# `typed_struct(args...)` which will throw an error about `T not defined`.
nothings = fill(nothing, length(field_types))
constructor_code = :(function $typed_struct() where {$T}
return new{$T}(0, $([:(nothing) for _ in field_types]...))
return new{$T}(0, $(nothings...))
end)
if type_parametrized
# A bit confusing: we need to add the extra type parameters to `{T}`.
Expand Down
3 changes: 2 additions & 1 deletion src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1815,8 +1815,9 @@ function Base.getproperty(
f::Symbol,
)
if f == :side_dimension
return getproperty(set.set, f)
return getproperty(getfield(set, :set), f)
else
@assert f == :set
return getfield(set, f)
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/Utilities/matrix_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,11 @@ function test_empty_product_of_sets(T = Int)
return
end

function test_set_types_fallback()
@test_throws MethodError MOI.Utilities.set_types(1)
return
end

end

TestMatrixOfConstraints.runtests()