Skip to content
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

Basic USVM TS type system with type coercion #215

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
015cbc3
Upgrade kotlin version
CaelmBleidd Dec 20, 2024
1248a67
Type coercion
CaelmBleidd Dec 20, 2024
beccd93
Some fixes
CaelmBleidd Jan 14, 2025
ff880f7
Tmp commit
CaelmBleidd Jan 16, 2025
8bbfedc
Tmp commit
CaelmBleidd Jan 16, 2025
2484658
Govno
CaelmBleidd Jan 16, 2025
c065b19
MultiExpr support
CaelmBleidd Jan 17, 2025
21c686b
EQ operator support
CaelmBleidd Jan 17, 2025
567c7f6
tmp commit
CaelmBleidd Jan 17, 2025
d227391
Remove multiexpr and multivalue
CaelmBleidd Jan 17, 2025
0fb485f
Add caches for local sorts
CaelmBleidd Jan 20, 2025
80bfa8a
Support arguments resolve
CaelmBleidd Jan 20, 2025
b45b6aa
Drochilnya with unresolved objects
CaelmBleidd Jan 22, 2025
3248239
Draft fields support
Lipen Jan 23, 2025
4e47ab5
Make tests on fields working
Lipen Jan 23, 2025
f672517
Continuation of drochilnya with unresolved objects
CaelmBleidd Jan 23, 2025
28c9fa8
Completed test
CaelmBleidd Jan 23, 2025
c323bb5
Eval expr in model
Lipen Jan 23, 2025
b80db92
Format
Lipen Jan 23, 2025
ee705a5
Format
Lipen Jan 23, 2025
057b865
Support any
Lipen Jan 23, 2025
86f124d
Fix indent
Lipen Jan 23, 2025
00cb506
Cleanup
Lipen Jan 23, 2025
9a1c43b
Use fp64Sort
Lipen Jan 23, 2025
8d288c1
Cleanup
Lipen Jan 23, 2025
8001d7d
fix ICE
Lipen Jan 23, 2025
fd7bda1
Remove old comments
Lipen Jan 23, 2025
8695f20
Fix check
Lipen Jan 23, 2025
945323e
Add comment about ToBoolean
Lipen Jan 23, 2025
0d4ad61
Cleanup
Lipen Jan 23, 2025
545c334
Add EXACTLY_ONCE invokation contract for calcOnState and doWithState
Lipen Jan 23, 2025
9047742
More tests for And
Lipen Jan 23, 2025
f85c92f
More tests
Lipen Jan 23, 2025
3de12b0
Add class for expr with type guard
CaelmBleidd Jan 24, 2025
9f61e97
Add type constraint in fake type creation
CaelmBleidd Jan 24, 2025
39a4ee5
Add example with nan equality
CaelmBleidd Jan 24, 2025
a4cabdb
Remove redundant code with expr transformer
CaelmBleidd Jan 24, 2025
6e214c4
Add a clarification comment
CaelmBleidd Jan 24, 2025
db90185
Remove multiple asserts during one scope call
CaelmBleidd Jan 24, 2025
4cabbfa
Disable test
CaelmBleidd Jan 24, 2025
0e406b7
Disable tests
CaelmBleidd Jan 24, 2025
8b7f9b1
Bump jacodb version
CaelmBleidd Jan 24, 2025
cc43637
Rebase fixes
CaelmBleidd Jan 24, 2025
aa18660
Remove non-related changes
CaelmBleidd Jan 24, 2025
56a8aef
TSTest modification
CaelmBleidd Jan 24, 2025
5306128
Throw error if a value cannot be extracted
CaelmBleidd Jan 24, 2025
4a26215
Prepare for review
CaelmBleidd Jan 24, 2025
c46970e
Notice
CaelmBleidd Jan 24, 2025
0ed314d
Move truthy utils
Lipen Jan 24, 2025
cb7112a
Manual CFG construction
Lipen Jan 24, 2025
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
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Versions {
const val clikt = "5.0.0"
const val detekt = "1.23.7"
const val ini4j = "0.5.4"
const val jacodb = "983d3538a9"
const val jacodb = "8a588e71e7"
const val juliet = "1.3.2"
const val junit = "5.9.3"
const val kotlin = "2.1.0"
Expand Down
11 changes: 11 additions & 0 deletions usvm-core/src/main/kotlin/org/usvm/StepScope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import org.usvm.StepScope.StepScopeState.CAN_BE_PROCESSED
import org.usvm.StepScope.StepScopeState.DEAD
import org.usvm.forkblacklists.UForkBlackList
import org.usvm.utils.checkSat
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
* An auxiliary class, which carefully maintains forks and asserts via [forkWithBlackList] and [assert].
Expand Down Expand Up @@ -48,7 +51,11 @@ class StepScope<T : UState<Type, *, Statement, Context, *, T>, Type, Statement,
*
* @return `null` if the underlying state is `null`.
*/
@OptIn(ExperimentalContracts::class)
fun doWithState(block: T.() -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
check(canProcessFurtherOnCurrentStep) { "Caller should check before processing the current hop further" }
return originalState.block()
}
Expand All @@ -58,7 +65,11 @@ class StepScope<T : UState<Type, *, Statement, Context, *, T>, Type, Statement,
*
* @return `null` if the underlying state is `null`, otherwise returns result of calling [block].
*/
@OptIn(ExperimentalContracts::class)
fun <R> calcOnState(block: T.() -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
check(canProcessFurtherOnCurrentStep) { "Caller should check before processing the current hop further" }
return originalState.block()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,21 @@ internal class CyclesTest : JavaMethodTestRunner() {
stopOnCoverage = -1
),
){
checkDiscoveredProperties(
Cycles::innerLoop,
ignoreNumberOfAnalysisResults,
{ _, x, r -> x in 1..3 && r == 0 },
{ _, x, r -> x == 4 && r == 1 },
{ _, x, r -> x >= 5 && r == 0 }
)
withOptions(
options.copy(
stopOnCoverage = 0,
stateCollectionStrategy = StateCollectionStrategy.ALL,
collectedStatesLimit = 100,
)
) {
checkDiscoveredProperties(
Cycles::innerLoop,
ignoreNumberOfAnalysisResults,
{ _, x, r -> x in 1..3 && r == 0 },
{ _, x, r -> x == 4 && r == 1 },
{ _, x, r -> x >= 5 && r == 0 }
)
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@
package org.usvm.dataflow.ts.infer.dto

import org.jacodb.ets.base.EtsAliasType
import org.jacodb.ets.base.EtsAnnotationNamespaceType
import org.jacodb.ets.base.EtsAnnotationTypeQueryType
import org.jacodb.ets.base.EtsAnyType
import org.jacodb.ets.base.EtsArrayObjectType
import org.jacodb.ets.base.EtsArrayType
import org.jacodb.ets.base.EtsBooleanType
import org.jacodb.ets.base.EtsClassType
import org.jacodb.ets.base.EtsFunctionType
import org.jacodb.ets.base.EtsGenericType
import org.jacodb.ets.base.EtsLexicalEnvType
import org.jacodb.ets.base.EtsLiteralType
import org.jacodb.ets.base.EtsNeverType
import org.jacodb.ets.base.EtsNullType
Expand All @@ -40,15 +36,12 @@ import org.jacodb.ets.base.EtsUnionType
import org.jacodb.ets.base.EtsUnknownType
import org.jacodb.ets.base.EtsVoidType
import org.jacodb.ets.dto.AliasTypeDto
import org.jacodb.ets.dto.AnnotationNamespaceTypeDto
import org.jacodb.ets.dto.AnnotationTypeQueryTypeDto
import org.jacodb.ets.dto.AnyTypeDto
import org.jacodb.ets.dto.ArrayTypeDto
import org.jacodb.ets.dto.BooleanTypeDto
import org.jacodb.ets.dto.ClassTypeDto
import org.jacodb.ets.dto.FunctionTypeDto
import org.jacodb.ets.dto.GenericTypeDto
import org.jacodb.ets.dto.LexicalEnvTypeDto
import org.jacodb.ets.dto.LiteralTypeDto
import org.jacodb.ets.dto.LocalDto
import org.jacodb.ets.dto.LocalSignatureDto
Expand Down Expand Up @@ -155,10 +148,6 @@ private object EtsTypeToDto : EtsType.Visitor<TypeDto> {
)
}

override fun visit(type: EtsArrayObjectType): TypeDto {
TODO("Not yet implemented")
}

override fun visit(type: EtsUnclearRefType): TypeDto {
return UnclearReferenceTypeDto(
name = type.typeName,
Expand All @@ -184,24 +173,4 @@ private object EtsTypeToDto : EtsType.Visitor<TypeDto> {
),
)
}

override fun visit(type: EtsAnnotationNamespaceType): TypeDto {
return AnnotationNamespaceTypeDto(
originType = type.originType,
namespaceSignature = type.namespaceSignature.toDto(),
)
}

override fun visit(type: EtsAnnotationTypeQueryType): TypeDto {
return AnnotationTypeQueryTypeDto(
originType = type.originType,
)
}

override fun visit(type: EtsLexicalEnvType): TypeDto {
return LexicalEnvTypeDto(
nestedMethod = type.nestedMethod.toDto(),
closures = type.closures.map { it.toDto() as LocalDto }, // safe cast
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ package org.usvm.dataflow.ts.infer.dto

import org.jacodb.ets.base.EtsArrayAccess
import org.jacodb.ets.base.EtsBooleanConstant
import org.jacodb.ets.base.EtsCaughtExceptionRef
import org.jacodb.ets.base.EtsClosureFieldRef
import org.jacodb.ets.base.EtsGlobalRef
import org.jacodb.ets.base.EtsInstanceFieldRef
import org.jacodb.ets.base.EtsLocal
import org.jacodb.ets.base.EtsNullConstant
Expand All @@ -33,10 +30,7 @@ import org.jacodb.ets.base.EtsUndefinedConstant
import org.jacodb.ets.base.EtsValue
import org.jacodb.ets.dto.ArrayRefDto
import org.jacodb.ets.dto.BooleanTypeDto
import org.jacodb.ets.dto.CaughtExceptionRefDto
import org.jacodb.ets.dto.ClosureFieldRefDto
import org.jacodb.ets.dto.ConstantDto
import org.jacodb.ets.dto.GlobalRefDto
import org.jacodb.ets.dto.InstanceFieldRefDto
import org.jacodb.ets.dto.LocalDto
import org.jacodb.ets.dto.NullTypeDto
Expand Down Expand Up @@ -106,27 +100,6 @@ private object EtsValueToDto : EtsValue.Visitor<ValueDto> {
)
}

override fun visit(value: EtsCaughtExceptionRef): ValueDto {
return CaughtExceptionRefDto(
type = value.type.toDto(),
)
}

override fun visit(value: EtsGlobalRef): ValueDto {
return GlobalRefDto(
name = value.name,
ref = value.ref?.toDto(),
)
}

override fun visit(value: EtsClosureFieldRef): ValueDto {
return ClosureFieldRefDto(
base = value.base.toDto() as LocalDto, // safe cast
fieldName = value.fieldName,
type = value.type.toDto(),
)
}

override fun visit(value: EtsArrayAccess): ValueDto {
return ArrayRefDto(
array = value.array.toDto(),
Expand Down
42 changes: 0 additions & 42 deletions usvm-ts/src/main/kotlin/org/usvm/TSBinaryOperator.kt

This file was deleted.

24 changes: 0 additions & 24 deletions usvm-ts/src/main/kotlin/org/usvm/TSContext.kt

This file was deleted.

Loading
Loading