Skip to content

Commit 17de700

Browse files
authored
Fix precompilation of MOI.delete(model, x) (#3126)
1 parent 2a2a75d commit 17de700

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

‎src/MathOptInterface.jl‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ PrecompileTools.@setup_workload begin
465465
)
466466
set(model, Silent(), true)
467467
x = add_variables(model, 3)
468+
y = add_variable(model)
469+
delete(model, y)
468470
add_constraint(model, x[1], ZeroOne())
469471
add_constraint(model, x[2], Integer())
470472
add_constraint(model, x[1], GreaterThan(0.0))

‎src/Utilities/struct_of_constraints.jl‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ function final_touch(model::StructOfConstraints, index_map)
3333
end
3434

3535
function _throw_if_cannot_delete(model::StructOfConstraints, vis, fast_in_vis)
36-
broadcastcall(model) do constrs
37-
if constrs !== nothing
38-
_throw_if_cannot_delete(constrs, vis, fast_in_vis)
39-
end
40-
return
36+
# constrs is not specialized because of MathOptInterface#3124
37+
#
38+
# The inner _throw_if_cannot_delete will be specialized, so the runtime
39+
# penalty for this is very small. It's just the dispatch in broadcastcall.
40+
function inner(@nospecialize constrs)
41+
return _throw_if_cannot_delete(constrs, vis, fast_in_vis)
4142
end
43+
inner(::Nothing) = nothing
44+
broadcastcall(inner, model)
4245
return
4346
end
4447

@@ -47,12 +50,13 @@ function _deleted_constraints(
4750
model::StructOfConstraints,
4851
vi,
4952
)
50-
broadcastcall(model) do constrs
51-
if constrs !== nothing
52-
_deleted_constraints(callback, constrs, vi)
53-
end
54-
return
55-
end
53+
# constrs is not specialized because of MathOptInterface#3124
54+
#
55+
# The inner _deleted_constraints will be specialized, so the runtime penalty
56+
# for this is very small. It's just the dispatch in broadcastcall.
57+
inner(@nospecialize constrs) = _deleted_constraints(callback, constrs, vi)
58+
inner(::Nothing) = nothing
59+
broadcastcall(inner, model)
5660
return
5761
end
5862

0 commit comments

Comments
 (0)