Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ enum class TsRuntimeFeatureLimitationReason {
REGULAR_EXPRESSION_LITERAL,
FRONTEND_UNSUPPORTED_VALUE,
FUNCTION_REFERENCE_RESOLUTION,
VARIABLE_BINDING_RESOLUTION,
STRING_CONCAT_OPERAND_CONVERSION,
STRING_PRIMITIVE_CONVERSION,
ARRAY_STORAGE_TYPE,
Expand Down
35 changes: 19 additions & 16 deletions usvm-ts/src/main/kotlin/org/usvm/machine/expr/TsExprResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1639,8 +1639,7 @@ class TsSimpleValueResolver(
private val observer: TsInterpreterObserver? = null,
) : EtsValue.Visitor<UExpr<out USort>?> {

private fun stopFunctionReferenceResolution(detail: String) {
val reason = TsRuntimeFeatureLimitationReason.FUNCTION_REFERENCE_RESOLUTION
private fun stopBindingResolution(reason: TsRuntimeFeatureLimitationReason, detail: String) {
scope.doWithState {
observer?.onRuntimeFeatureLimitationSafely(
TsRuntimeFeatureLimitationEvent(statement = lastStmt, reason = reason, detail = detail),
Expand Down Expand Up @@ -1755,22 +1754,24 @@ class TsSimpleValueResolver(
return readGlobal(scope, importedFile, importedName)
}

is SymbolResolutionResult.FileNotFound -> {
logger.error { "Cannot resolve import for '$local': ${resolutionResult.reason}" }
scope.assert(falseExpr)
return null
}
is SymbolResolutionResult.FileNotFound -> stopBindingResolution(
reason = TsRuntimeFeatureLimitationReason.VARIABLE_BINDING_RESOLUTION,
detail = "Cannot resolve import for '$local': ${resolutionResult.reason}",
)

is SymbolResolutionResult.SymbolNotFound -> {
logger.error { "Cannot find symbol '$local' in '${resolutionResult.file.name}': ${resolutionResult.reason}" }
scope.assert(falseExpr)
return null
}
is SymbolResolutionResult.SymbolNotFound -> stopBindingResolution(
reason = TsRuntimeFeatureLimitationReason.VARIABLE_BINDING_RESOLUTION,
detail = "Cannot find symbol '$local' in '${resolutionResult.file.name}': " +
resolutionResult.reason,
)
}
return null
}

logger.error { "Cannot resolve local variable '$local' in method: $currentMethod" }
scope.assert(falseExpr)
stopBindingResolution(
reason = TsRuntimeFeatureLimitationReason.VARIABLE_BINDING_RESOLUTION,
detail = "Cannot resolve variable '$local' in ${currentMethod.signature}",
)
return null
}

Expand All @@ -1794,7 +1795,8 @@ class TsSimpleValueResolver(
.flatMap { it.methods }
.filter { it.signature == signature && it.cfg.stmts.isNotEmpty() }
if (methods.size != 1) {
stopFunctionReferenceResolution(
stopBindingResolution(
reason = TsRuntimeFeatureLimitationReason.FUNCTION_REFERENCE_RESOLUTION,
detail = "Cannot uniquely resolve named function reference $local: " +
"${methods.size} executable targets",
)
Expand All @@ -1815,7 +1817,8 @@ class TsSimpleValueResolver(
.flatMap { it.methods }
.filter { it.name == local.name && it.cfg.stmts.isNotEmpty() }
if (methods.size != 1) {
stopFunctionReferenceResolution(
stopBindingResolution(
reason = TsRuntimeFeatureLimitationReason.FUNCTION_REFERENCE_RESOLUTION,
detail = "Cannot uniquely resolve anonymous function reference $local in $owner: " +
"${methods.size} executable targets",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.usvm.machine.expr

import org.usvm.machine.TsAnalysisStopReason
import org.usvm.machine.TsMachine
import org.usvm.machine.TsOptions
import org.usvm.machine.TsRuntimeFeatureLimitationReason
import org.usvm.machine.TsStoppedStatesObserver
import org.usvm.machine.state.TsState
import org.usvm.util.TsMethodTestRunner
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class BindingResolutionBoundariesTest : TsMethodTestRunner() {
override val scene = loadScene("/models/BindingResolutionBoundaries.ts")

@Test
fun `unresolved bindings outside the local register layout retain feasible diagnostic prefixes`() {
val missingBindings = listOf(
Triple("readUnavailableImport", "unavailableMarker", "UnavailableDependency"),
Triple("readUnavailableHostValue", "unavailableHostNumber", "unavailableHostNumber"),
)

for ((methodName, localName, missingBinding) in missingBindings) {
val method = getMethod(methodName = methodName, className = "BindingResolutionBoundaries")
// The DTO currently registers even read-only unresolved names as locals. Exercise the
// fallback resolver contract for IR producers that omit such names from the register layout.
method.body.locals = method.locals.filterNot { it.name == localName }
val prefixes = mutableListOf<TsState>()
val stoppedObserver = TsStoppedStatesObserver { prefixes += it }

val outcome = TsMachine(
scene = scene,
options = options.copy(stopOnCoverage = 0, throwExceptionOnStepFailure = true),
tsOptions = TsOptions(),
observer = stoppedObserver,
machineObserverFactory = stoppedObserver::createMachineObserver,
).use { machine -> machine.analyzeWithMetadata(methods = listOf(method)) }

assertEquals(TsAnalysisStopReason.EXHAUSTED, outcome.stopReason)
assertFalse(outcome.engineFailed)
assertFalse(outcome.unsupportedCall)
assertTrue(outcome.states.isEmpty())
val reason = outcome.unsupportedPaths.single()
assertContains(reason, TsRuntimeFeatureLimitationReason.VARIABLE_BINDING_RESOLUTION.name)
assertContains(reason, missingBinding)
val prefix = prefixes.single()
assertEquals(reason, prefix.unsupportedReason)
assertTrue(prefix.models.isNotEmpty())
}
}
}
12 changes: 12 additions & 0 deletions usvm-ts/src/test/resources/models/BindingResolutionBoundaries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @ts-nocheck
import { marker as unavailableMarker } from "./UnavailableDependency";

export class BindingResolutionBoundaries {
static readUnavailableImport(): number {
return unavailableMarker;
}

static readUnavailableHostValue(): number {
return unavailableHostNumber;
}
}
Loading