Skip to content

Commit

Permalink
Update kotlin version to 2.1.0 (#230)
Browse files Browse the repository at this point in the history
* Upgrade kotlin version

* Fix tailrec warning in usvm-util module

* Remove context receivers from the project

* Remove the context receivers compiler option

* Test fixes
  • Loading branch information
CaelmBleidd authored Dec 20, 2024
1 parent 722b5bf commit 4014545
Show file tree
Hide file tree
Showing 30 changed files with 927 additions and 887 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
`kotlin-dsl`
}

val kotlinVersion = "1.9.20"
val kotlinVersion = "2.1.0"
val detektVersion = "1.23.5"
val gjavahVersion = "0.3.1"

Expand Down
12 changes: 6 additions & 6 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import org.gradle.plugin.use.PluginDependenciesSpec
object Versions {
const val detekt = "1.18.1"
const val ini4j = "0.5.4"
const val jacodb = "81ccf5aaed"
const val jacodb = "6539d5020c"
const val juliet = "1.3.2"
const val junit = "5.9.3"
const val kotlin = "1.9.20"
const val kotlin_logging = "1.8.3"
const val kotlinx_collections = "0.3.5"
const val kotlinx_coroutines = "1.6.4"
const val kotlinx_serialization = "1.4.1"
const val kotlin = "2.1.0"
const val kotlin_logging = "3.0.5"
const val kotlinx_collections = "0.3.8"
const val kotlinx_coroutines = "1.10.0"
const val kotlinx_serialization = "1.7.3"
const val ksmt = "0.5.26"
const val logback = "1.4.8"
const val mockk = "1.13.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs += "-Xallow-result-return-type"
freeCompilerArgs += "-Xsam-conversions=class"
allWarningsAsErrors = true
}
Expand Down
8 changes: 0 additions & 8 deletions usvm-dataflow/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("usvm.kotlin-conventions")
}
Expand All @@ -10,12 +8,6 @@ dependencies {
implementation(Libs.sarif4k)
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xcontext-receivers"
}
}

publishing {
publications {
create<MavenPublication>("maven") {
Expand Down
22 changes: 11 additions & 11 deletions usvm-dataflow/src/main/kotlin/org/usvm/dataflow/config/Condition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ import org.usvm.dataflow.taint.Tainted
import org.usvm.dataflow.util.Traits
import org.usvm.dataflow.util.removeTrailingElementAccessors

context(Traits<CommonMethod, CommonInst>)
open class BasicConditionEvaluator(
internal val positionResolver: PositionResolver<Maybe<CommonValue>>,
val traits: Traits<CommonMethod, CommonInst>,
internal val positionResolver: PositionResolver<Maybe<CommonValue>>
) : ConditionVisitor<Boolean> {

override fun visit(condition: ConstantTrue): Boolean {
Expand Down Expand Up @@ -74,35 +74,35 @@ open class BasicConditionEvaluator(
error("Unexpected condition: $condition")
}

override fun visit(condition: IsConstant): Boolean {
override fun visit(condition: IsConstant): Boolean = with(traits) {
positionResolver.resolve(condition.position).onSome {
return isConstant(it)
}
return false
}

override fun visit(condition: ConstantEq): Boolean {
override fun visit(condition: ConstantEq): Boolean = with(traits) {
positionResolver.resolve(condition.position).onSome { value ->
return eqConstant(value, condition.value)
}
return false
}

override fun visit(condition: ConstantLt): Boolean {
override fun visit(condition: ConstantLt): Boolean = with(traits) {
positionResolver.resolve(condition.position).onSome { value ->
return ltConstant(value, condition.value)
}
return false
}

override fun visit(condition: ConstantGt): Boolean {
override fun visit(condition: ConstantGt): Boolean = with(traits) {
positionResolver.resolve(condition.position).onSome { value ->
return gtConstant(value, condition.value)
}
return false
}

override fun visit(condition: ConstantMatches): Boolean {
override fun visit(condition: ConstantMatches): Boolean = with(traits) {
positionResolver.resolve(condition.position).onSome { value ->
return matches(value, condition.pattern)
}
Expand All @@ -117,21 +117,21 @@ open class BasicConditionEvaluator(
error("This visitor does not support condition $condition. Use FactAwareConditionEvaluator instead")
}

override fun visit(condition: TypeMatches): Boolean {
override fun visit(condition: TypeMatches): Boolean = with(traits) {
positionResolver.resolve(condition.position).onSome { value ->
return typeMatches(value, condition)
}
return false
}
}

context(Traits<CommonMethod, CommonInst>)
class FactAwareConditionEvaluator(
traits: Traits<CommonMethod, CommonInst>,
private val fact: Tainted,
positionResolver: PositionResolver<Maybe<CommonValue>>,
) : BasicConditionEvaluator(positionResolver) {
) : BasicConditionEvaluator(traits, positionResolver) {

override fun visit(condition: ContainsMark): Boolean {
override fun visit(condition: ContainsMark): Boolean = with(traits) {
if (fact.mark != condition.mark) return false
positionResolver.resolve(condition.position).onSome { value ->
val variable = convertToPath(value)
Expand Down
60 changes: 33 additions & 27 deletions usvm-dataflow/src/main/kotlin/org/usvm/dataflow/config/Position.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,30 @@ import org.usvm.dataflow.ifds.fmap
import org.usvm.dataflow.ifds.toMaybe
import org.usvm.dataflow.util.Traits

context(Traits<CommonMethod, CommonInst>)
class CallPositionToAccessPathResolver(
private val traits: Traits<CommonMethod, CommonInst>,
private val callStatement: CommonInst,
) : PositionResolver<Maybe<AccessPath>> {
private val callExpr = getCallExpr(callStatement)
private val callExpr = traits.getCallExpr(callStatement)
?: error("Call statement should have non-null callExpr")

override fun resolve(position: Position): Maybe<AccessPath> = when (position) {
AnyArgument -> Maybe.none()
is Argument -> convertToPathOrNull(callExpr.args[position.index]).toMaybe()
This -> (callExpr as? CommonInstanceCallExpr)?.instance?.let { convertToPathOrNull(it) }.toMaybe()
Result -> (callStatement as? CommonAssignInst)?.lhv?.let { convertToPathOrNull(it) }.toMaybe()
ResultAnyElement -> (callStatement as? CommonAssignInst)?.lhv?.let { convertToPathOrNull(it) }.toMaybe()
.fmap { it + ElementAccessor }
override fun resolve(position: Position): Maybe<AccessPath> = with(traits) {
when (position) {
AnyArgument -> Maybe.none()
is Argument -> convertToPathOrNull(callExpr.args[position.index]).toMaybe()
This -> (callExpr as? CommonInstanceCallExpr)?.instance?.let { convertToPathOrNull(it) }.toMaybe()
Result -> (callStatement as? CommonAssignInst)?.lhv?.let { convertToPathOrNull(it) }.toMaybe()
ResultAnyElement -> (callStatement as? CommonAssignInst)?.lhv?.let { convertToPathOrNull(it) }.toMaybe()
.fmap { it + ElementAccessor }
}
}
}

context(Traits<CommonMethod, CommonInst>)
class CallPositionToValueResolver(
traits: Traits<CommonMethod, CommonInst>,
private val callStatement: CommonInst,
) : PositionResolver<Maybe<CommonValue>> {
private val callExpr = getCallExpr(callStatement)
private val callExpr = traits.getCallExpr(callStatement)
?: error("Call statement should have non-null callExpr")

override fun resolve(position: Position): Maybe<CommonValue> = when (position) {
Expand All @@ -68,34 +70,38 @@ class CallPositionToValueResolver(
}
}

context(Traits<CommonMethod, CommonInst>)
class EntryPointPositionToValueResolver(
private val traits: Traits<CommonMethod, CommonInst>,
private val method: CommonMethod,
) : PositionResolver<Maybe<CommonValue>> {
override fun resolve(position: Position): Maybe<CommonValue> = when (position) {
This -> Maybe.some(getThisInstance(method))
override fun resolve(position: Position): Maybe<CommonValue> = with(traits) {
when (position) {
This -> Maybe.some(getThisInstance(method))

is Argument -> {
val p = method.parameters[position.index]
getArgument(p).toMaybe()
}
is Argument -> {
val p = method.parameters[position.index]
getArgument(p).toMaybe()
}

AnyArgument, Result, ResultAnyElement -> error("Unexpected $position")
AnyArgument, Result, ResultAnyElement -> error("Unexpected $position")
}
}
}

context(Traits<CommonMethod, CommonInst>)
class EntryPointPositionToAccessPathResolver(
private val traits: Traits<CommonMethod, CommonInst>,
private val method: CommonMethod,
) : PositionResolver<Maybe<AccessPath>> {
override fun resolve(position: Position): Maybe<AccessPath> = when (position) {
This -> convertToPathOrNull(getThisInstance(method)).toMaybe()
override fun resolve(position: Position): Maybe<AccessPath> = with(traits) {
when (position) {
This -> convertToPathOrNull(getThisInstance(method)).toMaybe()

is Argument -> {
val p = method.parameters[position.index]
getArgument(p)?.let { convertToPathOrNull(it) }.toMaybe()
}
is Argument -> {
val p = method.parameters[position.index]
getArgument(p)?.let { convertToPathOrNull(it) }.toMaybe()
}

AnyArgument, Result, ResultAnyElement -> error("Unexpected $position")
AnyArgument, Result, ResultAnyElement -> error("Unexpected $position")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ interface Runner<Fact, Method, Statement>
fun getIfdsResult(): IfdsResult<Fact, Statement>
}

context(Traits<Method, Statement>)
class UniRunner<Fact, Event, Method, Statement>(
private val traits: Traits<Method, Statement>,
private val manager: Manager<Fact, Event, Method, Statement>,
override val graph: ApplicationGraph<Method, Statement>,
private val analyzer: Analyzer<Fact, Event, Method, Statement>,
Expand Down Expand Up @@ -139,7 +139,7 @@ class UniRunner<Fact, Event, Method, Statement>(
private fun tabulationAlgorithmStep(
currentEdge: Edge<Fact, Statement>,
scope: CoroutineScope,
) {
) = with(traits) {
val (startVertex, currentVertex) = currentEdge
val (current, currentFact) = currentVertex

Expand Down
13 changes: 7 additions & 6 deletions usvm-dataflow/src/main/kotlin/org/usvm/dataflow/sarif/Sarif.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ private const val JACODB_INFORMATION_URI =
"https://github.com/UnitTestBot/jacodb/blob/develop/jacodb-analysis/README.md"
private const val DEFAULT_PATH_COUNT = 3

context(Traits<*, Statement>)
fun <Statement : CommonInst> sarifReportFromVulnerabilities(
traits: Traits<*, Statement>,
vulnerabilities: List<VulnerabilityInstance<*, Statement>>,
maxPathsCount: Int = DEFAULT_PATH_COUNT,
isDeduplicate: Boolean = true,
Expand Down Expand Up @@ -71,14 +71,15 @@ fun <Statement : CommonInst> sarifReportFromVulnerabilities(
level = instance.description.level,
locations = listOfNotNull(
instToSarifLocation(
traits,
instance.traceGraph.sink.statement,
sourceFileResolver
)
),
codeFlows = instance.traceGraph
.getAllTraces()
.take(maxPathsCount)
.map { traceToSarifCodeFlow(it, sourceFileResolver, isDeduplicate) }
.map { traceToSarifCodeFlow(traits, it, sourceFileResolver, isDeduplicate) }
.toList(),
)
}
Expand All @@ -87,11 +88,11 @@ fun <Statement : CommonInst> sarifReportFromVulnerabilities(
)
}

context(Traits<*, Statement>)
private fun <Statement : CommonInst> instToSarifLocation(
traits: Traits<*, Statement>,
inst: Statement,
sourceFileResolver: SourceFileResolver<Statement>,
): Location? {
): Location? = with(traits) {
val sourceLocation = sourceFileResolver.resolve(inst) ?: return null
return Location(
physicalLocation = PhysicalLocation(
Expand All @@ -110,8 +111,8 @@ private fun <Statement : CommonInst> instToSarifLocation(
)
}

context(Traits<*, Statement>)
private fun <Statement : CommonInst> traceToSarifCodeFlow(
traits: Traits<*, Statement>,
trace: List<Vertex<*, Statement>>,
sourceFileResolver: SourceFileResolver<Statement>,
isDeduplicate: Boolean = true,
Expand All @@ -121,7 +122,7 @@ private fun <Statement : CommonInst> traceToSarifCodeFlow(
ThreadFlow(
locations = trace.map {
ThreadFlowLocation(
location = instToSarifLocation(it.statement, sourceFileResolver),
location = instToSarifLocation(traits, it.statement, sourceFileResolver),
state = mapOf(
"fact" to MultiformatMessageString(
text = it.fact.toString()
Expand Down
Loading

0 comments on commit 4014545

Please sign in to comment.