Skip to content

Commit

Permalink
Updates for Kotlin 1.8 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
serras authored Mar 21, 2023
1 parent 154a402 commit edd4ca7
Show file tree
Hide file tree
Showing 50 changed files with 495 additions and 517 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/generate-alpha-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main

env:
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xmx5g -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xmx5g -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"

jobs:
build:
Expand All @@ -19,10 +19,10 @@ jobs:
fetch-depth: 0

- name: Set up Java
uses: actions/setup-java@v3.3.0
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '15'
distribution: 'temurin'
java-version: '17'

- name: Gradle build
run: ./gradlew --full-stacktrace build "-Psemver.stage=alpha"
Expand All @@ -44,10 +44,10 @@ jobs:
token: ${{ secrets.TOKEN_GITHUB_ACTION }}

- name: Set up Java
uses: actions/setup-java@v3.3.0
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '15'
distribution: 'temurin'
java-version: '17'

- name: Generate Tag
run: ./gradlew --full-stacktrace createSemverTag "-Psemver.stage=alpha"
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/generate-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ on:
- 'auto'

env:
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xmx5g -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xmx5g -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"

jobs:
build:
Expand All @@ -39,10 +39,10 @@ jobs:
fetch-depth: 0

- name: Set up Java
uses: actions/setup-java@v3.3.0
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '15'
distribution: 'temurin'
java-version: '17'

- name: Gradle build
run: ./gradlew --full-stacktrace build "-Psemver.scope=${{ github.event.inputs.scope }}" "-Psemver.stage=${{ github.event.inputs.stage }}"
Expand All @@ -64,10 +64,10 @@ jobs:
token: ${{ secrets.TOKEN_GITHUB_ACTION }}

- name: Set up Java
uses: actions/setup-java@v3.3.0
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '15'
distribution: 'temurin'
java-version: '17'

- name: Generate Tag
run: ./gradlew --full-stacktrace createSemverTag "-Psemver.scope=${{ github.event.inputs.scope }}" "-Psemver.stage=${{ github.event.inputs.stage }}"
Expand Down
35 changes: 15 additions & 20 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,24 @@ jobs:

strategy:
fail-fast: false
matrix:
kotlin: [ '1.6.0', '1.6.10' ]
jvm_target: [ '1.8', '11', '15' ]

outputs:
analysis-version: ${{ steps.get-analysis-version.outputs.analysis-version }}

steps:
- uses: actions/checkout@v3.0.2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-java@v3.3.0
- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '15'
distribution: 'temurin'
java-version: '17'

- name: Build and test with Gradle
uses: gradle/gradle-build-action@v2.1.5
uses: gradle/gradle-build-action@v2
with:
arguments: -PkotlinVersion=${{ matrix.kotlin }} -PjvmTargetVersion=${{ matrix.jvm_target }} build --scan --stacktrace
arguments: build --scan --stacktrace

- id: get-analysis-version
name: Get Analysis version
Expand All @@ -53,7 +50,7 @@ jobs:
echo "::set-output name=analysis-version::$(head -n 1 build/semver/version.txt)"
- name: Upload reports
uses: actions/upload-artifact@v3.0.0
uses: actions/upload-artifact@v3
with:
name: 'reports-${{ matrix.os }}'
path: '**/build/reports/**'
Expand All @@ -73,18 +70,16 @@ jobs:
#
publish:
needs: build
env:
JAVA_OPTS: -Xms512m -Xmx1024m

runs-on: macos-11

steps:
- uses: actions/checkout@v3.0.2
- uses: actions/checkout@v3

- uses: actions/setup-java@v3.3.0
- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '15'
distribution: 'temurin'
java-version: '17'
cache: 'gradle'

- name: Publish alpha/beta/rc artifacts
Expand Down Expand Up @@ -131,12 +126,12 @@ jobs:
S3_BUCKET: ${{ secrets.S3_BUCKET }}

steps:
- uses: actions/checkout@v3.0.2
- uses: actions/checkout@v3

- uses: actions/setup-java@v3.3.0
- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '15'
distribution: 'temurin'
java-version: '17'
cache: 'gradle'

- name: Prepare environment
Expand Down
25 changes: 10 additions & 15 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ name: Build Artifacts for PR
on: pull_request

env:
JAVA_OPTS: -Xms512m -Xmx1024m
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.configureondemand=true -Dorg.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"

GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xmx5g -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"

jobs:
pull_request:
Expand All @@ -15,27 +13,24 @@ jobs:

strategy:
fail-fast: false
matrix:
kotlin: ['1.6.0', '1.6.10', '1.6.21']
jvm_target: ['1.8', '11', '15']

steps:
- uses: actions/checkout@v3.0.2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-java@v3.3.0
- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '15'
distribution: 'temurin'
java-version: '17'

- name: Build and test with Gradle
uses: gradle/gradle-build-action@v2.1.5
uses: gradle/gradle-build-action@v2
with:
arguments: -PkotlinVersion=${{ matrix.kotlin }} -PjvmTargetVersion=${{ matrix.jvm_target }} build --scan --stacktrace
arguments: build --scan --stacktrace

- name: Upload reports
uses: actions/upload-artifact@v3.0.0
uses: actions/upload-artifact@v3
with:
name: 'reports-${{ matrix.os }}'
path: '**/build/reports/**'
Expand Down Expand Up @@ -63,15 +58,15 @@ jobs:
fetch-depth: 0

- name: Build
uses: gradle/gradle-build-action@v2.1.5
uses: gradle/gradle-build-action@v2
with:
arguments: apiDump

- name: Stop Gradle daemons
run: ./gradlew --stop

- name: "Commit new API files"
uses: stefanzweifel/git-auto-commit-action@v4.14.1
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update API files
file_pattern: /**/api/*.api
1 change: 1 addition & 0 deletions analysis/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ dependencies {
api(libs.javaSmt)
api(libs.apacheCommonsText)
api(libs.sarif4k)
implementation(libs.kotlinx.serialization.core)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ sealed class ContSeq<out A> {
*/
fun <B> map(f: suspend ContSyntax.(A) -> B): ContSeq<B> = ContSeq {
// Weird hack for RestrictSuspension
val f = f as suspend ContSeqSyntax<B>.(A) -> B
forEach { a -> yield(f(a)) }
val g = f as suspend ContSeqSyntax<B>.(A) -> B
forEach { a -> yield(g(a)) }
}

/** Side-effecting version of map */
Expand Down Expand Up @@ -223,7 +223,8 @@ private class ContSeqBuilder<T> : ContSeqSyntax<T>, Iterator<T>, Continuation<Un
nextIterator = null
}
State_Done -> return false
State_Ready, State_ManyReady -> return true
State_Ready,
State_ManyReady -> return true
else -> throw exceptionalState()
}

Expand All @@ -236,7 +237,8 @@ private class ContSeqBuilder<T> : ContSeqSyntax<T>, Iterator<T>, Continuation<Un

override fun next(): T =
when (state) {
State_NotReady, State_ManyNotReady -> nextNotReady()
State_NotReady,
State_ManyNotReady -> nextNotReady()
State_ManyReady -> {
state = State_ManyNotReady
nextIterator!!.next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,54 +81,60 @@ private fun Solver.comparisonFormula(
resolvedCall: ResolvedCall,
args: List<Formula>
): BooleanFormula? =
resolvedCall.allArgumentExpressions(context).takeIf { it.size == 2 }?.let {
val ty1 = it[0].type.unwrapIfNullable().primitiveType()
val ty2 = it[1].type.unwrapIfNullable().primitiveType()
val op = (resolvedCall.callElement as? BinaryExpression)?.operationToken
when {
ty1 == PrimitiveType.BOOLEAN && ty2 == PrimitiveType.BOOLEAN ->
resolvedCall
.allArgumentExpressions(context)
.takeIf { it.size == 2 }
?.let {
val ty1 = it[0].type.unwrapIfNullable().primitiveType()
val ty2 = it[1].type.unwrapIfNullable().primitiveType()
val op = (resolvedCall.callElement as? BinaryExpression)?.operationToken
when {
ty1 == PrimitiveType.BOOLEAN && ty2 == PrimitiveType.BOOLEAN ->
when (op) {
"==" -> boolEquivalence(args)
"!=" -> boolEquivalence(args)?.let { f -> not(f) }
else -> null
}
ty1 == PrimitiveType.INTEGRAL && ty2 == PrimitiveType.INTEGRAL ->
when (op) {
"==" -> intEquals(args)
"!=" -> intEquals(args)?.let { f -> not(f) }
">" -> intGreaterThan(args)
">=" -> intGreaterThanOrEquals(args)
"<" -> intLessThan(args)
"<=" -> intLessThanOrEquals(args)
else -> null
}
ty1 == PrimitiveType.RATIONAL && ty2 == PrimitiveType.RATIONAL ->
when (op) {
"==" -> rationalEquals(args)
"!=" -> rationalEquals(args)?.let { f -> not(f) }
">" -> rationalGreaterThan(args)
">=" -> rationalGreaterThanOrEquals(args)
"<" -> rationalLessThan(args)
"<=" -> rationalLessThanOrEquals(args)
else -> null
}
ty1 == null && ty2 == null -> // equality on objects
when (op) {
"==" -> boolEquivalence(args)
"!=" -> boolEquivalence(args)?.let { f -> not(f) }
else -> null
}
ty1 == PrimitiveType.INTEGRAL && ty2 == PrimitiveType.INTEGRAL ->
when (op) {
"==" -> intEquals(args)
"!=" -> intEquals(args)?.let { f -> not(f) }
">" -> intGreaterThan(args)
">=" -> intGreaterThanOrEquals(args)
"<" -> intLessThan(args)
"<=" -> intLessThanOrEquals(args)
else -> null
}
ty1 == PrimitiveType.RATIONAL && ty2 == PrimitiveType.RATIONAL ->
when (op) {
"==" -> rationalEquals(args)
"!=" -> rationalEquals(args)?.let { f -> not(f) }
">" -> rationalGreaterThan(args)
">=" -> rationalGreaterThanOrEquals(args)
"<" -> rationalLessThan(args)
"<=" -> rationalLessThanOrEquals(args)
else -> null
}
ty1 == null && ty2 == null -> // equality on objects
when (op) {
"==" -> intEquals(args)
else -> null
}
else -> null
"==" -> intEquals(args)
else -> null
}
else -> null
}
}
}

private fun Solver.booleanFormula(
descriptor: CallableDescriptor,
args: List<Formula>
): BooleanFormula? =
when (descriptor.fqNameSafe) {
FqName("kotlin.Boolean.not"), FqName("!") -> boolNot(args)
FqName("kotlin.Boolean.and"), FqName("&&") -> boolAnd(args)
FqName("kotlin.Boolean.or"), FqName("||") -> boolOr(args)
FqName("kotlin.Boolean.not"),
FqName("!") -> boolNot(args)
FqName("kotlin.Boolean.and"),
FqName("&&") -> boolAnd(args)
FqName("kotlin.Boolean.or"),
FqName("||") -> boolOr(args)
FqName("kotlin.Boolean.xor") -> boolXor(args)
else -> null
}
Expand Down Expand Up @@ -158,7 +164,8 @@ private fun Solver.integralFormula(
// "div", "/" -> intDivide(args) // not all SMT solvers support div
"inc",
"++" -> intPlus(args + listOf(integerFormulaManager.makeNumber(1)))
"dec", "--" -> intMinus(args + listOf(integerFormulaManager.makeNumber(1)))
"dec",
"--" -> intMinus(args + listOf(integerFormulaManager.makeNumber(1)))
else -> null
}

Expand Down Expand Up @@ -187,6 +194,7 @@ private fun Solver.rationalFormula(
// "div", "/" -> rationalDivide(args) // not all SMT solvers support div
"inc",
"++" -> rationalPlus(args + listOf(integerFormulaManager.makeNumber(1)))
"dec", "--" -> rationalMinus(args + listOf(integerFormulaManager.makeNumber(1)))
"dec",
"--" -> rationalMinus(args + listOf(integerFormulaManager.makeNumber(1)))
else -> null
}
Loading

0 comments on commit edd4ca7

Please sign in to comment.