Skip to content

Fix compute_follow_kernel_items to properly index bool array per kernel#785

Open
ydah wants to merge 1 commit intoruby:masterfrom
ydah:fix-compute-follow-kernel-items
Open

Fix compute_follow_kernel_items to properly index bool array per kernel#785
ydah wants to merge 1 commit intoruby:masterfrom
ydah:fix-compute-follow-kernel-items

Conversation

@ydah
Copy link
Copy Markdown
Member

@ydah ydah commented Mar 28, 2026

Fix a bug where each kernel was mapped to the full Bitmap.to_bool_array result (Array[bool]) instead of its indexed bool value.
Since arrays are always truthy in Ruby, follow_kernel_items[goto][kernel] evaluated to true for every kernel, making the filtering in goto_follow_set (Definition 3.39) and lhs_contributions (Definition 3.31) ineffective.

The fix computes the bool array once and assigns each kernel its corresponding value:

# Before (buggy): every kernel mapped to the full bool array
state.follow_kernel_items[goto] = state.kernels.map {|kernel|
  [kernel, Bitmap.to_bool_array(follow_kernel_items, state.kernels.count)]
}.to_h

# After: each kernel mapped to its corresponding bool value
bool_array = Bitmap.to_bool_array(follow_kernel_items, state.kernels.count)
state.follow_kernel_items[goto] = state.kernels.each_with_index.to_h {|kernel, i|
  [kernel, bool_array[i]]
}

Each kernel was incorrectly mapped to the full `Bitmap.to_bool_array`
result (`Array[bool]`) instead of its indexed value. Since arrays are
always truthy in Ruby, `follow_kernel_items[goto][kernel]` evaluated to
true for every kernel, making the filtering in `goto_follow_set`
(Definition 3.39) and `lhs_contributions` (Definition 3.31) ineffective.

The fix computes the bool array once and assigns each kernel its
corresponding bool value via index, which also eliminates redundant
`Bitmap.to_bool_array` calls (previously N calls per goto, now 1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant