Skip to content

Commit d04de18

Browse files
authored
Add nospecialize to some very highly specialized methods (#2830)
1 parent 2e5e7da commit d04de18

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

src/Bridges/Constraint/bridge.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ Return a `Bool` indicating whether the bridges of type `BT` support bridging
3636
constraint types that the bridge implements.
3737
"""
3838
function MOI.supports_constraint(
39-
::Type{<:AbstractBridge},
40-
::Type{<:MOI.AbstractFunction},
41-
::Type{<:MOI.AbstractSet},
39+
@nospecialize(BT::Type{<:AbstractBridge}),
40+
@nospecialize(F::Type{<:MOI.AbstractFunction}),
41+
@nospecialize(S::Type{<:MOI.AbstractSet}),
4242
)
4343
return false
4444
end

src/Bridges/Constraint/single_bridge_optimizer.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ function MOI.Bridges.supports_bridging_constrained_variable(
105105
end
106106

107107
function MOI.Bridges.supports_bridging_constraint(
108-
::SingleBridgeOptimizer{BT},
109-
F::Type{<:MOI.AbstractFunction},
110-
S::Type{<:MOI.AbstractSet},
108+
@nospecialize(b::SingleBridgeOptimizer{BT}),
109+
@nospecialize(F::Type{<:MOI.AbstractFunction}),
110+
@nospecialize(S::Type{<:MOI.AbstractSet}),
111111
) where {BT}
112112
return MOI.supports_constraint(BT, F, S)
113113
end

src/Bridges/lazy_bridge_optimizer.jl

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ end
155155
Return the list of `VariableNode` that would be added if `BT` is used in `b`.
156156
"""
157157
function _variable_nodes(
158-
b::LazyBridgeOptimizer,
159-
::Type{BT},
160-
) where {BT<:AbstractBridge}
158+
@nospecialize(b::LazyBridgeOptimizer),
159+
@nospecialize(BT),
160+
)
161161
return map(added_constrained_variable_types(BT)) do (S,)
162162
return node(b, S)::VariableNode
163163
end
@@ -169,9 +169,9 @@ end
169169
Return the list of `ConstraintNode` that would be added if `BT` is used in `b`.
170170
"""
171171
function _constraint_nodes(
172-
b::LazyBridgeOptimizer,
173-
::Type{BT},
174-
) where {BT<:AbstractBridge}
172+
@nospecialize(b::LazyBridgeOptimizer),
173+
@nospecialize(BT),
174+
)
175175
return ConstraintNode[
176176
node(b, F, S) for (F, S) in added_constraint_types(BT)
177177
]
@@ -183,7 +183,11 @@ end
183183
Return the `Edge` or `ObjectiveEdge` in the hyper-graph associated with the
184184
bridge `BT`, where `index` is the index of `BT` in the list of bridges.
185185
"""
186-
function _edge(b::LazyBridgeOptimizer, index::Int, BT::Type{<:AbstractBridge})
186+
function _edge(
187+
@nospecialize(b::LazyBridgeOptimizer),
188+
@nospecialize(index::Int),
189+
@nospecialize(BT::Type{<:AbstractBridge}),
190+
)
187191
return Edge(
188192
index,
189193
_variable_nodes(b, BT),
@@ -247,7 +251,10 @@ end
247251
248252
Return the `VariableNode` associated with set `S` in `b`.
249253
"""
250-
function node(b::LazyBridgeOptimizer, S::Type{<:MOI.AbstractSet})
254+
function node(
255+
@nospecialize(b::LazyBridgeOptimizer),
256+
@nospecialize(S::Type{<:MOI.AbstractSet}),
257+
)
251258
# If we support the set, the node is 0.
252259
if (
253260
S <: MOI.AbstractScalarSet &&
@@ -304,9 +311,9 @@ end
304311
Return the `ConstraintNode` associated with constraint `F`-in-`S` in `b`.
305312
"""
306313
function node(
307-
b::LazyBridgeOptimizer,
308-
F::Type{<:MOI.AbstractFunction},
309-
S::Type{<:MOI.AbstractSet},
314+
@nospecialize(b::LazyBridgeOptimizer),
315+
@nospecialize(F::Type{<:MOI.AbstractFunction}),
316+
@nospecialize(S::Type{<:MOI.AbstractSet}),
310317
)
311318
# If we support the constraint type, the node is 0.
312319
if MOI.supports_constraint(b.model, F, S)
@@ -377,8 +384,8 @@ function _bridge_types(
377384
end
378385

379386
function _bridge_types(
380-
b::LazyBridgeOptimizer,
381-
::Type{<:Constraint.AbstractBridge},
387+
@nospecialize(b::LazyBridgeOptimizer),
388+
@nospecialize(BT::Type{<:Constraint.AbstractBridge}),
382389
)
383390
return b.constraint_bridge_types
384391
end
@@ -395,7 +402,10 @@ end
395402
396403
Enable the use of the bridges of type `BT` by `b`.
397404
"""
398-
function add_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
405+
function add_bridge(
406+
@nospecialize(b::LazyBridgeOptimizer),
407+
@nospecialize(BT::Type{<:AbstractBridge}),
408+
)
399409
if !has_bridge(b, BT)
400410
push!(_bridge_types(b, BT), BT)
401411
_reset_bridge_graph(b)
@@ -427,7 +437,10 @@ end
427437
428438
Return a `Bool` indicating whether the bridges of type `BT` are used by `b`.
429439
"""
430-
function has_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
440+
function has_bridge(
441+
@nospecialize(b::LazyBridgeOptimizer),
442+
@nospecialize(BT::Type{<:AbstractBridge}),
443+
)::Bool
431444
return findfirst(isequal(BT), _bridge_types(b, BT)) !== nothing
432445
end
433446

src/Test/Test.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,9 @@ function _test_attribute_value_type(
500500
end
501501

502502
function _test_attribute_value_type(
503-
model::MOI.ModelLike,
504-
attribute::MOI.AbstractConstraintAttribute,
505-
ci::MOI.ConstraintIndex,
503+
@nospecialize(model::MOI.ModelLike),
504+
@nospecialize(attribute::MOI.AbstractConstraintAttribute),
505+
@nospecialize(ci::MOI.ConstraintIndex),
506506
)
507507
T = MOI.attribute_value_type(attribute)
508508
@test @inferred(T, MOI.get(model, attribute, ci)) isa T

src/constraints.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ combined with another type of constraint, it should still return `true`.
1919
"""
2020
function supports_constraint(
2121
::ModelLike,
22-
::Type{<:AbstractFunction},
23-
::Type{<:AbstractSet},
22+
F::Type{<:AbstractFunction},
23+
S::Type{<:AbstractSet},
2424
)
2525
return false
2626
end

0 commit comments

Comments
 (0)