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 #2269

Merged
merged 5 commits into from
Sep 19, 2023
Merged

Fix various JET errors #2269

merged 5 commits into from
Sep 19, 2023

Conversation

odow
Copy link
Member

@odow odow commented Sep 18, 2023

Part of #2268

Brings count from 211 down to 196. I'll comment in-line.

function MOI.get(
o::ObjectiveContainer{T},
::MOI.ObjectiveFunction{F},
) where {T,F}
if o.scalar_affine !== nothing
return convert(F, o.scalar_affine)
return convert(F, _get_scalar_affine(o))
Copy link
Member Author

Choose a reason for hiding this comment

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

All the changes in this file deal with the problem that o.scalar_affine::Union{Nothing,MOI.ScalarAffineFunction{T}}.

At runtime, the if statement handles the nothing case, so we never call convert(F, nothing), but it's useful to have a type-stable way to get the non-nothing function.

Although writing this now, I wonder if I could use _not_nothing(o.scalar_affine) to disambiguate the union.

intvar_idx = Int[]
c = nothing
funcs = nothing
funcs = MOI.VectorAffineFunction{T}[]
Copy link
Member Author

Choose a reason for hiding this comment

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

This was just a type stability issue, where various variables were initialized as nothing and then swapped to vectors.

_assert_has_model(model.model, attr)
return MOI.get(model.model, attr)
inner = _assert_has_model(model.model, attr)
return MOI.get(inner, attr)
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously compiler couldn't prove that model.model was not nothing because the check happened in _assert_has_model. Okay at runtime, not at compilation.

@@ -1319,7 +1319,7 @@ function parse_name_line(data::TempMPSModel, line::String)
if m === nothing
error("Malformed NAME line: ", line)
end
data.name = strip(m[1])
data.name = strip(m[1]::AbstractString)
Copy link
Member Author

Choose a reason for hiding this comment

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

There's actually a bunch of problems where we assume that the regex finds something.

@odow odow merged commit c5de829 into master Sep 19, 2023
15 of 16 checks passed
@odow odow deleted the od/jet branch September 19, 2023 03:50
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.

1 participant