Skip to content

Commit e2d8d2a

Browse files
committed
Fixed: unbridged_function recursion (namespace-aware — confirmed the StackOverflow is gone).
Remaining failures, all test-only, two kinds: 1. Hardcoded old negative values (e.g. test_FreeBridge:138 expecting [-1,-2]) — trivially update to the new positive values. 2. Cross-layer is_valid isolation (test_nesting lines 648, 664–666: !is_valid(model, x), !is_valid(b0, cnn), etc.). These assert that a bridged entity from an upper layer is invalid in lower layers. With the old negatives this held for free; with positive translated indices a bridged variable's value (x=1) coincides with an inner-model variable, so a direct is_valid(model, x) is a false positive. Real operations are unaffected because they route through the proper layer — only these direct cross-namespace value comparisons see the coincidence. The new design's guarantee is "operations through the correct layer are correct," not "indices are globally unique across layers" (which is what the old negative encoding incidentally provided).
1 parent d407801 commit e2d8d2a

3 files changed

Lines changed: 202 additions & 125 deletions

File tree

src/Bridges/Constraint/map.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ end
5454

5555
_index(ci::MOI.ConstraintIndex) = ci.value
5656

57-
_index(ci::MOI.ConstraintIndex{MOI.VectorOfVariables}) = -ci.value
58-
5957
function Base.haskey(map::Map, ci::MOI.ConstraintIndex{F,S}) where {F,S}
6058
return 1 <= _index(ci) <= length(map.bridges) &&
6159
map.bridges[_index(ci)] !== nothing &&
@@ -118,10 +116,6 @@ end
118116

119117
_index(index, F, S) = MOI.ConstraintIndex{F,S}(index)
120118

121-
function _index(index, F::Type{MOI.VectorOfVariables}, S)
122-
return MOI.ConstraintIndex{F,S}(-index)
123-
end
124-
125119
function _iterate(map::Map, state = 1)
126120
while state length(map.bridges) && map.bridges[state] === nothing
127121
state += 1
@@ -235,7 +229,7 @@ Return the list of all keys that correspond to
235229
function vector_of_variables_constraints(map::Map)
236230
return MOI.Utilities.lazy_map(
237231
MOI.ConstraintIndex{MOI.VectorOfVariables},
238-
i -> MOI.ConstraintIndex{map.constraint_types[i]...}(-i),
232+
i -> MOI.ConstraintIndex{map.constraint_types[i]...}(i),
239233
Base.Iterators.Filter(
240234
i ->
241235
map.bridges[i] !== nothing &&
@@ -284,7 +278,7 @@ function _ensure_available(
284278
::Type{S},
285279
is_available::Function,
286280
) where {S}
287-
while !is_available(MOI.ConstraintIndex{F,S}(-length(map.bridges) - 1))
281+
while !is_available(MOI.ConstraintIndex{F,S}(length(map.bridges) + 1))
288282
push!(map.bridges, nothing)
289283
push!(map.constraint_types, (F, S))
290284
end

0 commit comments

Comments
 (0)