-
Notifications
You must be signed in to change notification settings - Fork 25
[TS] Arrays methods #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TS] Arrays methods #304
Conversation
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Outdated
Show resolved
Hide resolved
usvm-ts/src/main/kotlin/org/usvm/machine/interpreter/TsInterpreter.kt
Outdated
Show resolved
Hide resolved
3cada77
to
dd67fdc
Compare
9187a68
to
b71e504
Compare
b71e504
to
1209ec8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
bdc0374
to
6d4b763
Compare
*/ | ||
private fun TsExprResolver.handleArrayJoin( | ||
expr: EtsInstanceCallExpr, | ||
arrayType: EtsArrayType, |
Check warning
Code scanning / detekt
Function parameter is unused and should be removed. Warning
private fun TsExprResolver.handleArrayJoin( | ||
expr: EtsInstanceCallExpr, | ||
arrayType: EtsArrayType, | ||
elementSort: USort, |
Check warning
Code scanning / detekt
Function parameter is unused and should be removed. Warning
private fun TsExprResolver.handleArrayIndexOf( | ||
expr: EtsInstanceCallExpr, | ||
arrayType: EtsArrayType, | ||
elementSort: USort, |
Check warning
Code scanning / detekt
Function parameter is unused and should be removed. Warning
*/ | ||
private fun TsExprResolver.handleArrayIncludes( | ||
expr: EtsInstanceCallExpr, | ||
arrayType: EtsArrayType, |
Check warning
Code scanning / detekt
Function parameter is unused and should be removed. Warning
private fun TsExprResolver.handleArrayIncludes( | ||
expr: EtsInstanceCallExpr, | ||
arrayType: EtsArrayType, | ||
elementSort: USort, |
Check warning
Code scanning / detekt
Function parameter is unused and should be removed. Warning
|
||
/** |
Check warning
Code scanning / detekt
Disallow blank lines in lists before, between or after any list element. Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds approximations for several TypeScript array methods (push
, pop
, fill
, shift
, unshift
) to enable symbolic execution. The implementation focuses on single-argument calls and includes test cases to verify the behavior of these array operations.
- Implements array method approximations with proper memory management and length tracking
- Refactors string constant handling to improve state management
- Adds comprehensive test coverage for the new array methods
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
usvm-ts/src/test/resources/samples/arrays/ArrayMethods.ts |
TypeScript test samples for array methods including push, pop, fill, shift, unshift, join, slice, concat, indexOf, includes, and reverse |
usvm-ts/src/test/kotlin/org/usvm/util/TsTestResolver.kt |
Minor refactor to extract string constant value retrieval logic |
usvm-ts/src/test/kotlin/org/usvm/samples/arrays/ArrayMethods.kt |
Test implementations verifying array method behavior through symbolic execution |
usvm-ts/src/test/kotlin/org/usvm/project/DemoCalc.kt |
Updates test configuration for demo calculator project |
usvm-ts/src/main/kotlin/org/usvm/machine/state/TsState.kt |
Adds string constant tracking and initialization methods to state management |
usvm-ts/src/main/kotlin/org/usvm/machine/interpreter/TsInterpreter.kt |
Fixes array type resolution for allocated heap references |
usvm-ts/src/main/kotlin/org/usvm/machine/expr/TsExprResolver.kt |
Refactors expression resolution by extracting call approximations |
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt |
New file implementing array method approximations and call handling logic |
usvm-ts/src/main/kotlin/org/usvm/machine/TsContext.kt |
Refactors string constant management for better separation of concerns |
Comments suppressed due to low confidence (1)
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt:625
- The documentation is incorrect. According to the ECMAScript specification,
Array.concat()
returns a new array and does not modify the original array in place.
* https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.concat
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Outdated
Show resolved
Hide resolved
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Outdated
Show resolved
Hide resolved
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Outdated
Show resolved
Hide resolved
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Outdated
Show resolved
Hide resolved
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Outdated
Show resolved
Hide resolved
usvm-ts/src/test/kotlin/org/usvm/samples/arrays/ArrayMethods.kt
Outdated
Show resolved
Hide resolved
usvm-ts/src/test/kotlin/org/usvm/samples/arrays/ArrayMethods.kt
Outdated
Show resolved
Hide resolved
@Lipen please, take a look at the comments |
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Dismissed
Show dismissed
Hide dismissed
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Dismissed
Show dismissed
Hide dismissed
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Outdated
Show resolved
Hide resolved
e0488d3
to
da024c5
Compare
41bb8a0
to
7a5a1ce
Compare
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Outdated
Show resolved
Hide resolved
usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt
Outdated
Show resolved
Hide resolved
elementSort: USort, | ||
): UExpr<*>? = with(ctx) { | ||
val array = resolve(expr.instance)?.asExpr(addressSort) ?: return null | ||
check(expr.args.size >= 1 && expr.args.size <= 3) { |
Check warning
Code scanning / detekt
Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning
} else { | ||
mkBv(0) | ||
} | ||
val startBv: UExpr<TsSizeSort> = when (start.sort) { |
Check warning
Code scanning / detekt
Braces do not comply with the specified policy Warning
val lengthLValue = mkArrayLengthLValue(array, arrayType) | ||
scope.calcOnState { memory.read(lengthLValue) } | ||
} | ||
val endBv: UExpr<TsSizeSort> = when (end.sort) { |
Check warning
Code scanning / detekt
Braces do not comply with the specified policy Warning
check(expr.args.size == 1) { | ||
"Array.indexOf() should have exactly one argument, but got ${expr.args.size}" | ||
} | ||
val searchElement = resolve(expr.args.single()) ?: return null |
Check warning
Code scanning / detekt
Property is unused and should be removed. Warning
check(expr.args.size == 1) { | ||
"Array.includes() should have exactly one argument, but got ${expr.args.size}" | ||
} | ||
val searchElement = resolve(expr.args.single()) ?: return null |
Check warning
Code scanning / detekt
Property is unused and should be removed. Warning
} | ||
) | ||
|
||
//! Note: `reversedArray` is a temporary object not used outside this function, |
Check warning
Code scanning / detekt
Checks if comments have the right spacing Warning
This PR adds approximations for some
Array
methods:push
,pop
,fill
,shift
,unshift
,join
,slice
,concat
,indexOf
,includes
,reverse
.In most cases, only single-argument (and non-array) calls (where it is applicable) are supported for now. For example,
Array.unshift(...items)
prependsitems
to the left, but we currently assumeunshift
receives a single value.In all methods that receive
start
/end
indices (e.g.slice
orfill
), negative indices are not yet supported.In
Array.fill
andArray.reverse
, only relatively small arrays are supported (of size at most 10000 and 5000, respectively), since it is (yet) impossible to create a symbolic array of symbolic length.