@unsafe

⚠️ Warning

@unsafe disables safety protections. Only use it when you fully understand the consequences. An unprotected loop can freeze your program indefinitely.

What is @unsafe?

@unsafe is an annotation you place directly before a while, for, orfor-in loop to disable the built-in loop protection.

Without @unsafe, a loop is halted when an iteration takes more than 2 seconds of real work or the loop exceeds 1,000,000 iterations. With @unsafe, the loop runs with no checks.

Syntax

@unsafe while (condition) {
    // loop body — no speed protection
}

@unsafe for (let i = 0; i < n; i = i + 1) {
    // loop body — no speed protection
}

@unsafe for (item in array) {
    // loop body — no speed protection
}

Example

class App {
    fn fastCount(n) {
        @unsafe while (n > 0) {
            print("count:", n);
            n = n - 1;
        }
    }

    fastCount(1000);
}

When to use @unsafe

  • Tight computational loops (math, sorting, processing)
  • Game loops that run at high frame rates
  • Benchmarking or performance testing
  • Any loop where you are certain it will terminate

When NOT to use @unsafe

  • When you are unsure if the loop will terminate
  • In production code where stability matters more than speed
  • When learning VDX — let the safety system help you

What @unsafe disables

ProtectionNormal loop@unsafe loop
Iteration work limit (2s, excluding wait/input)✓ Active✗ Disabled
Max iteration count (1,000,000) — v0.1.5+✓ Active✗ Disabled

Rules

  • @unsafe can be placed directly before while, for, orfor-in loops
  • It cannot be used on other statements (if, fn, let, etc.)
  • Using @unsafe before anything other than a loop is a compile error