Skip to content

Commit aee9ec2

Browse files
committed
Add nospecialize to some very highly specialized methods
1 parent 0001bcd commit aee9ec2

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

src/Bridges/Constraint/bridge.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ additionally implement:
1919
"""
2020
abstract type AbstractBridge <: MOI.Bridges.AbstractBridge end
2121

22+
@nospecialize
2223
"""
2324
MOI.supports_constraint(
2425
BT::Type{<:AbstractBridge},
@@ -42,6 +43,7 @@ function MOI.supports_constraint(
4243
)
4344
return false
4445
end
46+
@specialize
4547

4648
"""
4749
concrete_bridge_type(

src/Bridges/lazy_bridge_optimizer.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ function _reset_bridge_graph(b::LazyBridgeOptimizer)
149149
return
150150
end
151151

152+
@nospecialize
152153
"""
153154
_variable_nodes(b::LazyBridgeOptimizer, ::Type{BT}) where {BT}
154155
@@ -162,7 +163,9 @@ function _variable_nodes(
162163
return node(b, S)::VariableNode
163164
end
164165
end
166+
@specialize
165167

168+
@nospecialize
166169
"""
167170
_constraint_nodes(b::LazyBridgeOptimizer, ::Type{BT}) where {BT}
168171
@@ -176,7 +179,9 @@ function _constraint_nodes(
176179
node(b, F, S) for (F, S) in added_constraint_types(BT)
177180
]
178181
end
182+
@specialize
179183

184+
@nospecialize
180185
"""
181186
_edge(b::LazyBridgeOptimizer, index::Int, BT::Type{<:AbstractBridge})
182187
@@ -191,6 +196,7 @@ function _edge(b::LazyBridgeOptimizer, index::Int, BT::Type{<:AbstractBridge})
191196
bridging_cost(BT),
192197
)
193198
end
199+
@specialize
194200

195201
# Method for objective bridges because they produce ObjectiveEdge.
196202
function _edge(
@@ -376,12 +382,14 @@ function _bridge_types(
376382
return b.variable_bridge_types
377383
end
378384

385+
@nospecialize
379386
function _bridge_types(
380387
b::LazyBridgeOptimizer,
381388
::Type{<:Constraint.AbstractBridge},
382389
)
383390
return b.constraint_bridge_types
384391
end
392+
@specialize
385393

386394
function _bridge_types(
387395
b::LazyBridgeOptimizer,
@@ -390,6 +398,7 @@ function _bridge_types(
390398
return b.objective_bridge_types
391399
end
392400

401+
@nospecialize
393402
"""
394403
add_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
395404
@@ -402,6 +411,7 @@ function add_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
402411
end
403412
return
404413
end
414+
@specialize
405415

406416
"""
407417
remove_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
@@ -422,14 +432,16 @@ function remove_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
422432
return
423433
end
424434

435+
@nospecialize
425436
"""
426437
has_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
427438
428439
Return a `Bool` indicating whether the bridges of type `BT` are used by `b`.
429440
"""
430-
function has_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
441+
function has_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})::Bool
431442
return findfirst(isequal(BT), _bridge_types(b, BT)) !== nothing
432443
end
444+
@specialize
433445

434446
# It only bridges when the constraint is not supporting, hence the name "Lazy"
435447
function is_bridged(b::LazyBridgeOptimizer, S::Type{<:MOI.AbstractScalarSet})

src/Test/Test.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ function _test_attribute_value_type(
499499
return
500500
end
501501

502+
@nospecialize
502503
function _test_attribute_value_type(
503504
model::MOI.ModelLike,
504505
attribute::MOI.AbstractConstraintAttribute,
@@ -508,6 +509,7 @@ function _test_attribute_value_type(
508509
@test @inferred(T, MOI.get(model, attribute, ci)) isa T
509510
return
510511
end
512+
@specialize
511513

512514
function _test_attribute_value_type(
513515
model::MOI.ModelLike,

src/Utilities/model.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,15 @@ function MOI.is_valid(model::AbstractModel, ci::MOI.ConstraintIndex)
302302
return MOI.is_valid(constraints(model, ci), ci)
303303
end
304304

305+
@nospecialize
305306
function MOI.supports_constraint(
306307
model::AbstractModel,
307308
::Type{F},
308309
::Type{S},
309310
) where {F<:MOI.AbstractFunction,S<:MOI.AbstractSet}
310311
return MOI.supports_constraint(model.constraints, F, S)
311312
end
313+
@specialize
312314

313315
function MOI.add_constraint(
314316
model::AbstractModel,

src/constraints.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Use of this source code is governed by an MIT-style license that can be found
55
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
66

7+
@nospecialize
78
"""
89
supports_constraint(
910
model::ModelLike,
@@ -24,6 +25,7 @@ function supports_constraint(
2425
)
2526
return false
2627
end
28+
@specialize
2729

2830
"""
2931
struct UnsupportedConstraint{F<:AbstractFunction,S<:AbstractSet} <: UnsupportedError

0 commit comments

Comments
 (0)