Skip to content

Conversation

il-yb-ono
Copy link

This PR addresses the memory usage issue that occurs when the number of bit flags in int-mask-of or int-mask types grows. Currently, types with many bit flags cannot be properly validated, as demonstrated in this example.

This change treats TIntMask and TIntMaskOf as bit flags without decomposing them into individual TLiteralInt types, significantly reducing memory consumption.

#10440

Key Changes

  • Implemented new TIntMaskVerifier atomic type for efficient bit flag validation
  • Modified TypeExpander and TypeParser to return TIntMaskVerifier instead of expanding all combinations
  • Enhanced TemplateInferredTypeReplacer to properly handle conditional expressions with TIntMaskVerifier types
  • Extended ArithmeticOpAnalyzer with support for TIntMaskVerifier bitwise operations (AND, OR, XOR, SHIFT)
    • Added maxIntMaskCombinations configuration option to limit computation complexity when calculating all possible values
  • Added tests to ensure functionality.

so expand it to TLiteralInt to allow multiple conditional expressions to be selected.
…is methods for TIntMaskVerifier"

This reverts commit b821530.
Copy link

I found these snippets:

https://psalm.dev/r/154cd2c5da
<?php

final class C {
    // const C0 = 1 << 0;
    // const C1 = 1 << 1;
    // const C2 = 1 << 2;
    const C3 = 1 << 3;
    const C4 = 1 << 4;
    const C5 = 1 << 5;
    const C6 = 1 << 6;
    const C7 = 1 << 7;
    const C8 = 1 << 8;
    const C9 = 1 << 9;
    const C10 = 1 << 10;
    const C11 = 1 << 11;
    const C12 = 1 << 12;
    const C13 = 1 << 13;
    const C14 = 1 << 14;
    const C15 = 1 << 15;
    const C16 = 1 << 16;
    const C17 = 1 << 17;
    const C18 = 1 << 18;
    const C19 = 1 << 19;
}

/**
 * @return int-mask-of<C::C*>
 */
function processFlags(): int {
    $result = 0;
    $result |= 1;
    $result |= 2;
    return $result;
}
Psalm output (using commit cdceda0):

No issues!

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