diff --git a/.github/workflows/generate-alpha-tag.yaml b/.github/workflows/generate-alpha-tag.yaml index 1afe942d..b33e1ec1 100644 --- a/.github/workflows/generate-alpha-tag.yaml +++ b/.github/workflows/generate-alpha-tag.yaml @@ -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: @@ -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" @@ -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" diff --git a/.github/workflows/generate-tag.yaml b/.github/workflows/generate-tag.yaml index a46d1ce1..24f81b45 100644 --- a/.github/workflows/generate-tag.yaml +++ b/.github/workflows/generate-tag.yaml @@ -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: @@ -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 }}" @@ -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 }}" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8054caee..eb647719 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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/**' @@ -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 @@ -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 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index e6b22fda..b929854c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -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: @@ -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/**' @@ -63,7 +58,7 @@ jobs: fetch-depth: 0 - name: Build - uses: gradle/gradle-build-action@v2.1.5 + uses: gradle/gradle-build-action@v2 with: arguments: apiDump @@ -71,7 +66,7 @@ jobs: 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 diff --git a/analysis/common/build.gradle.kts b/analysis/common/build.gradle.kts index 7c5319d9..d85ec320 100644 --- a/analysis/common/build.gradle.kts +++ b/analysis/common/build.gradle.kts @@ -19,4 +19,5 @@ dependencies { api(libs.javaSmt) api(libs.apacheCommonsText) api(libs.sarif4k) + implementation(libs.kotlinx.serialization.core) } diff --git a/analysis/common/src/main/kotlin/arrow/meta/continuations/ContSeq.kt b/analysis/common/src/main/kotlin/arrow/meta/continuations/ContSeq.kt index f5b1f0f3..b448b669 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/continuations/ContSeq.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/continuations/ContSeq.kt @@ -50,8 +50,8 @@ sealed class ContSeq { */ fun map(f: suspend ContSyntax.(A) -> B): ContSeq = ContSeq { // Weird hack for RestrictSuspension - val f = f as suspend ContSeqSyntax.(A) -> B - forEach { a -> yield(f(a)) } + val g = f as suspend ContSeqSyntax.(A) -> B + forEach { a -> yield(g(a)) } } /** Side-effecting version of map */ @@ -223,7 +223,8 @@ private class ContSeqBuilder : ContSeqSyntax, Iterator, Continuation return false - State_Ready, State_ManyReady -> return true + State_Ready, + State_ManyReady -> return true else -> throw exceptionalState() } @@ -236,7 +237,8 @@ private class ContSeqBuilder : ContSeqSyntax, Iterator, Continuation nextNotReady() + State_NotReady, + State_ManyNotReady -> nextNotReady() State_ManyReady -> { state = State_ManyNotReady nextIterator!!.next() diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/Primitive.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/Primitive.kt index 0cbf0930..9f34e7d9 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/Primitive.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/Primitive.kt @@ -81,54 +81,60 @@ private fun Solver.comparisonFormula( resolvedCall: ResolvedCall, args: List ): 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 ): 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 } @@ -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 } @@ -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 } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ResolvedCallUtils.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ResolvedCallUtils.kt index 95fd6e7e..69e205d8 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ResolvedCallUtils.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ResolvedCallUtils.kt @@ -23,17 +23,18 @@ enum class SpecialKind { internal val ResolvedCall.specialKind: SpecialKind? get() = when (resultingDescriptor.fqNameSafe) { - FqName("arrow.analysis.pre"), FqName("arrow.analysis.RefinementDSLKt.pre") -> SpecialKind.Pre + FqName("arrow.analysis.pre"), + FqName("arrow.analysis.RefinementDSLKt.pre") -> SpecialKind.Pre FqName("kotlin.require") -> SpecialKind.Pre FqName(AssertExpression.FAKE_ASSERT_NAME) -> SpecialKind.Pre - FqName("arrow.analysis.post"), FqName("arrow.analysis.RefinementDSLKt.post") -> - SpecialKind.Post - FqName("arrow.analysis.invariant"), FqName("arrow.analysis.RefinementDSLKt.invariant") -> - SpecialKind.Invariant - FqName("arrow.analysis.unsafeCall"), FqName("arrow.analysis.RefinementDSLKt.unsafeCall") -> - SpecialKind.TrustCall - FqName("arrow.analysis.unsafeBlock"), FqName("arrow.analysis.RefinementDSLKt.unsafeBlock") -> - SpecialKind.TrustBlock + FqName("arrow.analysis.post"), + FqName("arrow.analysis.RefinementDSLKt.post") -> SpecialKind.Post + FqName("arrow.analysis.invariant"), + FqName("arrow.analysis.RefinementDSLKt.invariant") -> SpecialKind.Invariant + FqName("arrow.analysis.unsafeCall"), + FqName("arrow.analysis.RefinementDSLKt.unsafeCall") -> SpecialKind.TrustCall + FqName("arrow.analysis.unsafeBlock"), + FqName("arrow.analysis.RefinementDSLKt.unsafeBlock") -> SpecialKind.TrustBlock FqName("arrow.analysis.doNotLookAtArgumentsWhen"), FqName("arrow.analysis.RefinementDSLKt.doNotLookAtArgumentsWhen") -> SpecialKind.NotLookArgs else -> null @@ -94,8 +95,7 @@ internal fun ResolvedCall.allArgumentExpressions( */ internal fun ResolvedCall.getReceiverOrThisNamedArgument(): Expression? = this.getReceiverExpression() - ?: this.valueArguments - .entries + ?: this.valueArguments.entries .firstOrNull { (name, _) -> name.name.value.contains("this") } ?.value ?.arguments diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Declarations.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Declarations.kt index afa1422f..50c73f6f 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Declarations.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Declarations.kt @@ -97,9 +97,9 @@ internal fun SolverState.checkTopLevel( ParamInfo(solver, param.name.value, param.name.value, param.type, element) } val returnParam = - descriptor.returnType?.takeIf { descriptor !is ConstructorDescriptor }?.let { - ParamInfo(solver, RESULT_VAR_NAME, RESULT_VAR_NAME, it, declaration) - } + descriptor.returnType + ?.takeIf { descriptor !is ConstructorDescriptor } + ?.let { ParamInfo(solver, RESULT_VAR_NAME, RESULT_VAR_NAME, it, declaration) } // additional for 'this@info' val additional = if (declaration is NamedDeclaration) { @@ -226,25 +226,27 @@ private fun SolverState.introduceImplicitProperties( // if we have 'var' or 'var' in the parameters, // we need to assign them to fields // when the constructor is primary - klass.primaryConstructorParameters.filter { it.hasValOrVar() }.forEach { param -> - (context.descriptorFor(param) as? ValueParameterDescriptor) - ?.let { context.backingPropertyForConstructorParameter(it) } - ?.let { propertyDescriptor -> - val paramName = param.nameAsName?.value ?: THIS_VAR_NAME - addConstraint( - NamedConstraint( - "definition of property $paramName", - solver.objects { - equal( - solver.makeObjectVariable(paramName), - field(propertyDescriptor, solver.thisVariable) - ) - } - ), - context - ) - } - } + klass.primaryConstructorParameters + .filter { it.hasValOrVar() } + .forEach { param -> + (context.descriptorFor(param) as? ValueParameterDescriptor) + ?.let { context.backingPropertyForConstructorParameter(it) } + ?.let { propertyDescriptor -> + val paramName = param.nameAsName?.value ?: THIS_VAR_NAME + addConstraint( + NamedConstraint( + "definition of property $paramName", + solver.objects { + equal( + solver.makeObjectVariable(paramName), + field(propertyDescriptor, solver.thisVariable) + ) + } + ), + context + ) + } + } } private fun SolverState.checkSuperTypeEntries( @@ -373,8 +375,7 @@ private fun SolverState.checkDefaultParameters( when (declaration) { is DeclarationWithBody -> scopedBracket { - declaration - .valueParameters + declaration.valueParameters .filterNotNull() .mapNotNull { param -> val name = param.name diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Expressions.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Expressions.kt index 0e212af9..27c13f8e 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Expressions.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Expressions.kt @@ -175,7 +175,8 @@ internal fun SolverState.checkExpressionConstraints( ) } is ReturnExpression -> checkReturnConstraints(expression, data) - is BreakExpression, is ContinueExpression -> { + is BreakExpression, + is ContinueExpression -> { val withLabel = expression as ExpressionWithLabel cont { StateAfter(ExplicitLoopReturn(withLabel.getLabelName()), data) } } @@ -572,9 +573,9 @@ internal fun SolverState.checkRegularFunctionCall( getConstraintsFor(resolvedCall) ?: primitiveConstraints(data.context, resolvedCall) val doNotLook = callConstraints?.doNotLookAtArgumentsWhen.orEmpty() ContSeq { - if (doNotLook.isNotEmpty()) yield(true) - yield(false) - } + if (doNotLook.isNotEmpty()) yield(true) + yield(false) + } .flatMap { r -> continuationBracket.map { r } } .flatMap { doNotLookCase -> if (doNotLookCase) { @@ -767,9 +768,9 @@ private fun SolverState.checkReceiverWithPossibleSafeDot( // we do so by yielding 'true' and 'false' in that case, // and only 'true' when we use a "regular dot" . ContSeq { - if (wholeExpr is SafeQualifiedExpression) yield(false) - yield(true) - } + if (wholeExpr is SafeQualifiedExpression) yield(false) + yield(true) + } .flatMap { r -> continuationBracket.map { r } } .flatMap { definitelyNotNull -> solverTrace.add("?. case $definitelyNotNull") @@ -795,24 +796,24 @@ private fun SolverState.checkReceiverWithPossibleSafeDot( } } else { // the non-null case of ?., or simply regular . doOnlyWhenNotNull(receiverExpr, dataAfterReceiver.noReturn()) { rcv -> - ContSeq.unit.map { - val notNullCstr = - NamedConstraint( - "$receiverName is not null (?.)", - solver.isNotNull(receiverName) - ) - val inconsistent = - checkConditionsInconsistencies( - listOf(notNullCstr), - data.context, - rcv, - dataAfterReceiver.branch.get(), - reportIfInconsistent = false - ) - ensure(!inconsistent) - dataAfterReceiver.addBranch(solver.isNotNull(receiverName)).noReturn() + ContSeq.unit.map { + val notNullCstr = + NamedConstraint( + "$receiverName is not null (?.)", + solver.isNotNull(receiverName) + ) + val inconsistent = + checkConditionsInconsistencies( + listOf(notNullCstr), + data.context, + rcv, + dataAfterReceiver.branch.get(), + reportIfInconsistent = false + ) + ensure(!inconsistent) + dataAfterReceiver.addBranch(solver.isNotNull(receiverName)).noReturn() + } } - } .flatMap { stateAfterNotNullReceiver -> block(stateAfterNotNullReceiver.data) } } } @@ -833,9 +834,9 @@ private fun SolverState.checkElvisOperator( val left = solver.makeObjectVariable(leftName) return checkExpressionConstraints(leftName, leftExpr, data).checkReturnInfo { stateAfterLeft -> ContSeq { - yield(false) - yield(true) - } + yield(false) + yield(true) + } .flatMap { r -> continuationBracket.map { r } } .flatMap { definitelyNotNull -> if (!definitelyNotNull) { // the null case of ?: @@ -896,9 +897,9 @@ private fun SolverState.checkAsOperator( val left = solver.makeObjectVariable(leftName) return checkExpressionConstraints(leftName, leftExpr, data).checkReturnInfo { stateAfterLeft -> ContSeq { - if (kind == TypeCastExpresionKind.QUESTION_TYPE_CAST) yield(true) - yield(false) - } + if (kind == TypeCastExpresionKind.QUESTION_TYPE_CAST) yield(true) + yield(false) + } .flatMap { r -> continuationBracket.map { r } } .flatMap { asFails -> if (asFails) { @@ -997,8 +998,8 @@ private fun SolverState.checkCallArguments( val argUniqueName = solver.makeObjectVariable(newName(data.context, "vararg", expr, referencedElement)) checkExpressionConstraints(argUniqueName, expr, data).checkReturnInfo({ r, s -> - CallVarArgumentsInfo(r.left(), s.data) - }) { s -> + CallVarArgumentsInfo(r.left(), s.data) + }) { s -> cont { CallVarArgumentsInfo((argsUpToNow + listOf(argUniqueName)).right(), s.data) } } } @@ -1050,8 +1051,8 @@ private fun SolverState.checkCallArguments( val argUniqueName = solver.makeObjectVariable(newName(data.context, name, expr, referencedElement)) checkExpressionConstraints(argUniqueName, expr, data).checkReturnInfo({ r, s -> - CallArgumentsInfo(r.left(), s.data) - }) { s -> + CallArgumentsInfo(r.left(), s.data) + }) { s -> cont { CallArgumentsInfo( (argsUpToNow + listOf(CallArgumentVariable(name, argUniqueName))).right(), @@ -1141,8 +1142,7 @@ private fun SolverState.checkStringTemplate( expression: StringTemplateExpression, data: CheckData ): ContSeq = - expression - .entries + expression.entries .filterIsInstance() .map { checkExpressionConstraints("str", it.expression, data) } .sequence() @@ -1175,7 +1175,8 @@ private fun SolverState.checkStringTemplate( } private fun Type.getField(fieldName: String): DeclarationDescriptor? = - descriptor?.unsubstitutedMemberScope + descriptor + ?.unsubstitutedMemberScope ?.getContributedDescriptors { it == fieldName } ?.singleOrNull { it.name.value == fieldName && it.isField() } @@ -1271,7 +1272,7 @@ private fun SolverState.checkBinaryExpression( (operator == "ANDAND" || operator == "OROR") -> { val lhs = solver.makeObjectVariable(newName(data.context, "left", left)) val rhs = solver.makeObjectVariable(newName(data.context, "right", right)) - checkExpressionConstraints(lhs, left, data).checkReturnInfo { stateAfterLhs -> + checkExpressionConstraints(lhs, left, data).checkReturnInfo { _ -> checkExpressionConstraints(rhs, right, data).checkReturnInfo { stateAfterRhs -> cont { when (operator) { @@ -1436,18 +1437,18 @@ private fun SolverState.checkNonFunctionDeclarationExpression( val invariant = obtainInvariant(body, data) // assert the invariant if found and check its consistency doOnlyWhenNotNull(invariant, Unit) { (invBody, invFormula: BooleanFormula) -> - ContSeq.unit.map { - val renamed = solver.renameObjectVariables(invFormula, mapOf(RESULT_VAR_NAME to smtName)) - val inconsistentInvariant = - checkInvariantConsistency( - NamedConstraint("invariant in $declName", renamed), - data.context, - invBody, - data.branch.get() - ) - ensure(!inconsistentInvariant) + ContSeq.unit.map { + val renamed = solver.renameObjectVariables(invFormula, mapOf(RESULT_VAR_NAME to smtName)) + val inconsistentInvariant = + checkInvariantConsistency( + NamedConstraint("invariant in $declName", renamed), + data.context, + invBody, + data.branch.get() + ) + ensure(!inconsistentInvariant) + } } - } .flatMap { // this gives back a new temporary name for the body checkBodyAgainstInvariants(declaration, declName, invariant?.second, body, data) @@ -1776,9 +1777,9 @@ private fun SolverState.checkForExpression( data: CheckData ): ContSeq = ContSeq { - yield(LoopPlace.INSIDE_LOOP) - yield(LoopPlace.AFTER_LOOP) - } + yield(LoopPlace.INSIDE_LOOP) + yield(LoopPlace.AFTER_LOOP) + } .flatMap { when (it) { LoopPlace.INSIDE_LOOP -> @@ -1884,9 +1885,9 @@ private fun SolverState.checkTryExpression( ): ContSeq = inScope(data) { ContSeq { - yield(expression.tryBlock) - yieldAll(expression.catchClauses) - } + yield(expression.tryBlock) + yieldAll(expression.catchClauses) + } .flatMap { r -> continuationBracket.map { r } } .flatMap { when (it) { @@ -1896,7 +1897,8 @@ private fun SolverState.checkTryExpression( // if we had a throw, this will eventually end in a catch is ExplicitThrowReturn -> // is the thrown exception something in our own catch? - if (doesAnyCatchMatch( + if ( + doesAnyCatchMatch( stateAfter.returnInfo.exceptionType, expression.catchClauses, data diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/ExpressionToFormula.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/ExpressionToFormula.kt index 631a5545..8a54665b 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/ExpressionToFormula.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/ExpressionToFormula.kt @@ -87,9 +87,9 @@ private fun SolverState.expressionToFormula( ex is LambdaExpression -> recur(ex.bodyExpression) // basic blocks ex is BlockExpression -> - ex.statements.mapNotNull { recur(it) as? BooleanFormula }.let { conditions -> - solver.boolAndList(conditions) - } + ex.statements + .mapNotNull { recur(it) as? BooleanFormula } + .let { conditions -> solver.boolAndList(conditions) } ex is ConstantExpression -> ex.type(context)?.let { ty -> solver.makeConstant(ty, ex) } ex is ThisExpression -> // reference to this solver.makeObjectVariable("this") @@ -190,12 +190,14 @@ private fun SolverState.fieldFormula( descriptor: CallableDescriptor, args: List> ): ObjectFormula? = - descriptor.takeIf { it.isField() }?.let { - // create a field, the 'this' may be missing - val thisExpression = - (args.getOrNull(0)?.second as? ObjectFormula) ?: solver.makeObjectVariable("this") - field(descriptor, thisExpression) - } + descriptor + .takeIf { it.isField() } + ?.let { + // create a field, the 'this' may be missing + val thisExpression = + (args.getOrNull(0)?.second as? ObjectFormula) ?: solver.makeObjectVariable("this") + field(descriptor, thisExpression) + } /** * Turns a named constant expression into a smt [Formula] represented as a constant declared in the @@ -219,8 +221,8 @@ internal fun Element.isResultReference(bindingContext: ResolutionContext): Boole val expArg = parent.resolvedArg("predicate") as? ExpressionValueArgument val lambdaArg = (expArg?.valueArgument as? ExpressionLambdaArgument)?.getLambdaExpression() - ?: (expArg?.valueArgument as? ExpressionResolvedValueArgument)?.argumentExpression as? - LambdaExpression + ?: (expArg?.valueArgument as? ExpressionResolvedValueArgument)?.argumentExpression + as? LambdaExpression val params = lambdaArg?.functionLiteral?.valueParameters?.map { it.text }.orEmpty() + listOf("it") this.text in params.distinct() @@ -228,7 +230,9 @@ internal fun Element.isResultReference(bindingContext: ResolutionContext): Boole ?: false internal fun Element.getPostOrInvariantParent(bindingContext: ResolutionContext): ResolvedCall? = - this.parents().mapNotNull { it.getResolvedCall(bindingContext) }.firstOrNull { call -> - val kind = call.specialKind - kind == SpecialKind.Post || kind == SpecialKind.Invariant - } + this.parents() + .mapNotNull { it.getResolvedCall(bindingContext) } + .firstOrNull { call -> + val kind = call.specialKind + kind == SpecialKind.Post || kind == SpecialKind.Invariant + } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FindDescriptor.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FindDescriptor.kt index dbd775a5..5bed9412 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FindDescriptor.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FindDescriptor.kt @@ -87,13 +87,15 @@ private fun ResolutionContext.obtainDeclaration( // the type either strictly checks // or we need to look for the best match return current.firstOrNull { it.isCompatibleWith(compatibleWith) } - ?: current.filter { it.isLooselyCompatibleWith(compatibleWith) }.minWithOrNull { o1, o2 -> - when { - o1.isLooselyCompatibleWith(o2) -> -1 - o2.isLooselyCompatibleWith(o1) -> 1 - else -> 0 + ?: current + .filter { it.isLooselyCompatibleWith(compatibleWith) } + .minWithOrNull { o1, o2 -> + when { + o1.isLooselyCompatibleWith(o2) -> -1 + o2.isLooselyCompatibleWith(o1) -> 1 + else -> 0 + } } - } } /** diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromAnnotations.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromAnnotations.kt index de31d25e..3bbc6276 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromAnnotations.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromAnnotations.kt @@ -46,9 +46,9 @@ private fun SolverState.collectFromLocalDeclarations( localDeclarations: List, bindingTrace: ResolutionContext ) { - localDeclarations.flatMap { it.gather { it.hasInterestingAnnotation } }.forEach { - addConstraintsFromAnnotations(it, bindingTrace) - } + localDeclarations + .flatMap { it.gather { it.hasInterestingAnnotation } } + .forEach { addConstraintsFromAnnotations(it, bindingTrace) } } private fun SolverState.collectFromClasspath( @@ -67,7 +67,9 @@ private fun SolverState.collectFromClasspath( .gather( initialPackages = listOf(FqName("arrow.analysis.hints")), addSubPackages = false - ) { it.hasPackageWithLawsAnnotation } + ) { + it.hasPackageWithLawsAnnotation + } .flatMap { it.packageWithLawsAnnotation?.argumentValueAsArrayOfString("packages").orEmpty() } @@ -141,7 +143,8 @@ internal fun SolverState.parseFormula( """ (declare-fun this () $VALUE_TYPE) (declare-fun $RESULT_VAR_NAME () $VALUE_TYPE) - """.trimIndent() + """.trimIndent( + ) val fullString = "$params\n$deps\n$rest\n(assert $formula)" return solver.parse(fullString) } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromDSL.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromDSL.kt index cf377d16..de1459da 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromDSL.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromDSL.kt @@ -43,7 +43,8 @@ public fun Declaration.collectConstraintsFromDSL( context: ResolutionContext, descriptor: DeclarationDescriptor ) { - if (this is ClassOrObject && + if ( + this is ClassOrObject && hasImplicitPrimaryConstructor() && getAnonymousInitializers().isNotEmpty() && !descriptor.hasPackageWithLawsAnnotation @@ -80,7 +81,8 @@ public fun Declaration.collectConstraintsFromDSL( constraintsFromFunctionLike(solverState, context, emptyList()) else -> Triple(arrayListOf(), arrayListOf(), arrayListOf()) }.let { (preConstraints, postConstraints, notLookConstraints) -> - if (preConstraints.isNotEmpty() || + if ( + preConstraints.isNotEmpty() || postConstraints.isNotEmpty() || notLookConstraints.isNotEmpty() ) { @@ -253,7 +255,8 @@ private fun Element.elementToConstraint( ): Pair? { val call = getResolvedCall(context) val kind = call?.specialKind - return if (kind == SpecialKind.Pre || kind == SpecialKind.Post || kind == SpecialKind.NotLookArgs + return if ( + kind == SpecialKind.Pre || kind == SpecialKind.Post || kind == SpecialKind.NotLookArgs ) { val predicateArg = call.singleArg("predicate", context) ?: call.singleArg("value", context) val result = solverState.topLevelExpressionToFormula(predicateArg, context, parameters, false) diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds.kt index 92bc6a4c..cf59800b 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds.kt @@ -44,7 +44,8 @@ sealed interface ErrorIds { The compiler won't catch these errors in its own analysis phase (like it would do with a type error), since this is perfectly good code. However, it seems desirable for the programmer to know that a particular language feature cannot be used in these blocks. - """.trimIndent() + """.trimIndent( + ) } enum class Laws : ErrorIds { @@ -63,7 +64,8 @@ sealed interface ErrorIds { - It must call **exactly one** function at the end, - The call must use the parameters **in order**. - """.trimIndent() + """.trimIndent( + ) } enum class Unsupported : ErrorIds { @@ -90,7 +92,8 @@ sealed interface ErrorIds { ```kotlin val wrong = 1 / 0 // does not satisfy '0 != 0' in Int.div law ``` - """.trimIndent() + """.trimIndent( + ) }, UnsatBodyPost { override val shortDescription: String @@ -110,7 +113,8 @@ sealed interface ErrorIds { // does not satisfy 'x + x > 1' } ``` - """.trimIndent() + """.trimIndent( + ) }, UnsatInvariants { override val shortDescription: String @@ -129,7 +133,8 @@ sealed interface ErrorIds { ... } ``` - """.trimIndent() + """.trimIndent( + ) } } @@ -149,7 +154,8 @@ sealed interface ErrorIds { ... } ``` - """.trimIndent() + """.trimIndent( + ) }, InconsistentDefaultValues { override val fullDescription: String @@ -164,7 +170,8 @@ sealed interface ErrorIds { ... } ``` - """.trimIndent() + """.trimIndent( + ) }, InconsistentConditions { override val fullDescription: String @@ -185,7 +192,8 @@ sealed interface ErrorIds { } } ``` - """.trimIndent() + """.trimIndent( + ) override val level: SeverityLevel get() = SeverityLevel.Warning @@ -197,7 +205,8 @@ sealed interface ErrorIds { The post-conditions gathered after calling a function imply that this function could not be called at all. _This is really uncommon in practice_. - """.trimIndent() + """.trimIndent( + ) override val level: SeverityLevel get() = SeverityLevel.Warning @@ -216,7 +225,8 @@ sealed interface ErrorIds { } ``` - """.trimIndent() + """.trimIndent( + ) }; override val shortDescription: String @@ -235,7 +245,8 @@ sealed interface ErrorIds { the one declared in its parent. This guarantees that we can always replace a call to the parent with a call to the child (Liskov Substitution Principle). - """.trimIndent() + """.trimIndent( + ) }, NotStrongerPostcondition { override val shortDescription: String @@ -248,7 +259,8 @@ sealed interface ErrorIds { the one declared in its parent. This guarantees that we can always replace a call to the parent with a call to the child (Liskov Substitution Principle). - """.trimIndent() + """.trimIndent( + ) } } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorMessages.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorMessages.kt index 9b66dca5..a443cc3b 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorMessages.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorMessages.kt @@ -126,7 +126,8 @@ object ErrorMessages { | -> unsatisfiable constraint: `${callPreCondition.formula.dumpKotlinLike()}` | -> ${template(callPreCondition, this)} | -> ${branch(branch)} - """.trimMargin() + """.trimMargin( + ) /** * (attached to the return value) @@ -151,7 +152,8 @@ object ErrorMessages { ): String = """|declaration `${declaration.name}` fails to satisfy the post-condition: ${postCondition.formula.dumpKotlinLike()} | -> ${branch(branch)} - """.trimMargin() + """.trimMargin( + ) /** * (attached to the new value): the invariant declared for a mutable variable is not satisfied @@ -177,7 +179,8 @@ object ErrorMessages { """|invariants are not satisfied in `${expression.text}` | -> unsatisfiable constraint: `${constraint.formula.dumpKotlinLike()}` | -> ${branch(branch)} - """.trimMargin() + """.trimMargin( + ) } /** @@ -262,7 +265,8 @@ object ErrorMessages { ): String = """|unreachable code due to conflicting conditions: ${unsatCore.dumpKotlinLike()} | -> ${branch(branch)} - """.trimMargin() + """.trimMargin( + ) /** * (attached to the function call): the post-conditions gathered after calling a function imply @@ -274,7 +278,8 @@ object ErrorMessages { ): String = """|unreachable code due to post-conditions: ${unsatCore.dumpKotlinLike()} | -> ${branch(branch)} - """.trimMargin() + """.trimMargin( + ) /** * (attached to a local declaration): there is no way in which the invariant attached to a @@ -296,19 +301,22 @@ object ErrorMessages { ): String = """|invariants are inconsistent: ${it.dumpKotlinLike()} | -> ${branch(branch)} - """.trimMargin() + """.trimMargin( + ) } object Liskov { internal fun KotlinPrinter.notWeakerPrecondition(constraint: NamedConstraint): String = """|pre-condition `${constraint.msg}` is not weaker than those from overridden members | -> problematic constraint: `${constraint.formula.dumpKotlinLike()}` - """.trimMargin() + """.trimMargin( + ) internal fun KotlinPrinter.notStrongerPostcondition(constraint: NamedConstraint): String = """|post-condition `${constraint.msg}` from overridden member is not satisfied | -> problematic constraint: `${constraint.formula.dumpKotlinLike()}` - """.trimMargin() + """.trimMargin( + ) } object Exception { @@ -329,7 +337,7 @@ object ErrorMessages { ?.joinToString(separator = System.lineSeparator()) { referencedElement -> val el = referencedElement.element val argsMapping = referencedElement.reference - argsMapping?.let { (param, resolvedArg) -> + argsMapping?.let { (param, _) -> val paramPsi = param.element() val location = paramPsi?.let { paramPsi.location() } "`${el.text}` bound to param `${param.name}` in `${param.containingDeclaration?.fqNameSafe}` ${location?.link() ?: ""}" diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/search/ConstraintSearch.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/search/ConstraintSearch.kt index 9c3c96ee..f2c01ec9 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/search/ConstraintSearch.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/search/ConstraintSearch.kt @@ -66,8 +66,7 @@ internal fun SolverState.getPostInvariantsForType(type: ClassDescriptor): List getConstraintsFor(primary)?.post else -> - type - .constructors + type.constructors .map { secondary -> getConstraintsFor(secondary)?.post } .takeIf { list -> list.isNotEmpty() && list.all { it != null } } ?.filterNotNull() // this is a bit redundant, but won't compile otherwise @@ -97,15 +96,17 @@ internal fun SolverState.typeInvariants( ): List { // invariants from the type val invariants = - type.descriptor?.let { getPostInvariantsForType(it) }?.let { constraints -> - // replace $result by new name - constraints.map { - NamedConstraint( - "${it.msg} (invariant from $type)", - solver.substituteObjectVariables(it.formula, mapOf(RESULT_VAR_NAME to result)) - ) + type.descriptor + ?.let { getPostInvariantsForType(it) } + ?.let { constraints -> + // replace $result by new name + constraints.map { + NamedConstraint( + "${it.msg} (invariant from $type)", + solver.substituteObjectVariables(it.formula, mapOf(RESULT_VAR_NAME to result)) + ) + } } - } ?: emptyList() // invariants from property code val fieldEqs = fieldEqualitiesInvariants(type, result, context) @@ -159,8 +160,7 @@ internal fun SolverState.fieldEqualitiesInvariants( internal fun SolverState.getOverriddenConstraintsFor( descriptor: DeclarationDescriptor ): DeclarationConstraints? = - descriptor - .withAliasUnwrapped + descriptor.withAliasUnwrapped .overriddenDescriptors() ?.mapNotNull { overriddenDescriptor -> getConstraintsFor(overriddenDescriptor) } ?.takeIf { it.isNotEmpty() } @@ -201,8 +201,7 @@ internal fun SolverState.primitiveConstraints( dispatch + descriptor.valueParameters.map { param -> val tyFromArg = - call - .valueArguments + call.valueArguments .filterKeys { it.name == param.name } .values .singleOrNull() diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverInteraction.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverInteraction.kt index 4d2569e5..c954a9fa 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverInteraction.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverInteraction.kt @@ -81,14 +81,14 @@ internal fun SolverState.additionalFieldConstraints( formulae: Iterable, context: ResolutionContext ): Set = - solver - .formulaManager + solver.formulaManager .fieldNames(formulae.map { it.formula }) .flatMap { (fieldName, appliedTo) -> val fqName = FqName(fieldName) val descriptor = context.descriptorFor(fqName).getOrNull(0) val constraints = singleConstraintsFromFqName(fqName) - if (descriptor != null && + if ( + descriptor != null && constraints != null && constraints.pre.isEmpty() && constraints.post.size == 1 diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FormulaToKotlin.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FormulaToKotlin.kt index 4d868db8..65fa4907 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FormulaToKotlin.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FormulaToKotlin.kt @@ -98,7 +98,8 @@ internal class DefaultKotlinPrinter( ): Void? { val (render, name, negatedName) = pFunctionDeclaration.toKotlin() when (render) { - Render.Hidden, Render.Unsupported -> { + Render.Hidden, + Render.Unsupported -> { pArgs.forEach { arg -> fmgr.visit(arg, this) } } Render.Negation -> { diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaPlugin.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaPlugin.kt index 03115f63..8c51478c 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaPlugin.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaPlugin.kt @@ -122,8 +122,7 @@ public class AnalysisJavaPlugin : Plugin { ) { val obtainedPackages = mutableListOf() todo.forEach { descriptor -> - ctx - .resolver + ctx.resolver .tree(descriptor) ?.visitRecursively( object : OurTreeVisitor(Unit) { diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaInterpreter.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaInterpreter.kt index fe08055e..c9911aff 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaInterpreter.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaInterpreter.kt @@ -1,4 +1,4 @@ -@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") +@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE", "UNCHECKED_CAST") package arrow.meta.plugins.analysis.java.ast @@ -126,8 +126,8 @@ public fun A.model(ctx: AnalysisContext): B = is PackageElement -> JavaPackageDescriptor(ctx, this) as B is VariableElement -> when (this.kind) { - ElementKind.PARAMETER, ElementKind.EXCEPTION_PARAMETER -> - JavaParameterDescriptor(ctx, this) as B + ElementKind.PARAMETER, + ElementKind.EXCEPTION_PARAMETER -> JavaParameterDescriptor(ctx, this) as B ElementKind.LOCAL_VARIABLE -> JavaLocalVariableDescriptor(ctx, this) as B ElementKind.FIELD -> JavaFieldDescriptor(ctx, this) as B ElementKind.ENUM_CONSTANT -> JavaEnumConstantDescriptor(ctx, this) as B @@ -137,7 +137,8 @@ public fun A.model(ctx: AnalysisContext): B = when (this.kind) { ElementKind.METHOD -> JavaSimpleFunctionDescriptor(ctx, this) as B ElementKind.CONSTRUCTOR -> JavaConstructorDescriptor(ctx, this) as B - ElementKind.STATIC_INIT, ElementKind.INSTANCE_INIT -> TODO("not yet supported") + ElementKind.STATIC_INIT, + ElementKind.INSTANCE_INIT -> TODO("not yet supported") else -> throw IllegalArgumentException("incorrect ExecutableElement case") } is TypeElement -> JavaClassDescriptor(ctx, this) as B @@ -146,21 +147,21 @@ public fun A.model(ctx: AnalysisContext): B = } public fun < - A : Tree, - B : arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.Element> A.modelCautious( - ctx: AnalysisContext -): B? = + A : Tree, B : arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.Element> A + .modelCautious(ctx: AnalysisContext): B? = when (this) { - is CompilationUnitTree, is PackageTree, is ModuleTree, is DirectiveTree, is ImportTree -> null + is CompilationUnitTree, + is PackageTree, + is ModuleTree, + is DirectiveTree, + is ImportTree -> null is ModifiersTree -> null else -> this.model(ctx) } public fun < - A : Tree, - B : arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.Element> A.model( - ctx: AnalysisContext -): B = + A : Tree, B : arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.Element> A + .model(ctx: AnalysisContext): B = when (this) { is ArrayTypeTree, is ParameterizedTypeTree, diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaResolutionContext.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaResolutionContext.kt index 2f37a058..4cf023cf 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaResolutionContext.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaResolutionContext.kt @@ -57,7 +57,8 @@ public class JavaResolutionContext( object : OurTreeVisitor(Unit) { override fun visitMethodInvocation(node: MethodInvocationTree, p: Unit?) { node.methodSelect?.toString()?.let { calleeText -> - if (calleeText == "pre" || + if ( + calleeText == "pre" || calleeText.endsWith(".pre") || calleeText == "post" || calleeText.endsWith(".post") || @@ -120,8 +121,7 @@ public class JavaResolutionContext( (declaration as? JavaElement)?.let { ctx.resolver.resolve(it.impl())?.model(ctx) } private val diagnosticSource: DiagnosticSource - get() = - ctx.unit?.let { DiagnosticSource(it.sourceFile, ctx.logger) } ?: DiagnosticSource.NO_SOURCE + get() = DiagnosticSource(ctx.unit.sourceFile, ctx.logger) private fun report(element: Element, builder: (JCTree) -> JCDiagnostic) { (element as? JavaElement)?.let { elt -> diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotationDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotationDescriptor.kt index f17a5737..a82699cd 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotationDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotationDescriptor.kt @@ -17,8 +17,7 @@ public class JavaAnnotationDescriptor( ) : AnnotationDescriptor { private val inside: Map get() = - ctx - .elements + ctx.elements .getElementValuesWithDefaults(impl) .map { (k, v) -> k.simpleName.toString() to v } .toMap() diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFunctionDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFunctionDescriptor.kt index 695e0994..cedc5a58 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFunctionDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFunctionDescriptor.kt @@ -58,8 +58,7 @@ public open class JavaFunctionDescriptor( null -> emptyList() else -> klass.asType().allSupertypes(ctx).flatMap { parent -> - ctx - .types + ctx.types .asElement(parent) ?.enclosedElements .orEmpty() diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaModuleDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaModuleDescriptor.kt index c7d18eb0..811dbb55 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaModuleDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaModuleDescriptor.kt @@ -14,15 +14,13 @@ public class JavaModuleDescriptor( private val impl: ModuleElement ) : JavaDescriptor(ctx, impl), ModuleDescriptor { override fun getPackage(pck: String): PackageViewDescriptor? = - impl - .enclosedElements + impl.enclosedElements .filterIsInstance() .firstOrNull { it.fqName == pck } ?.model(ctx) override fun getSubPackagesOf(fqName: FqName): List = - impl - .enclosedElements + impl.enclosedElements .filterIsInstance() .filter { it.fqName.startsWith(fqName.name + ".") } .map { it.model(ctx) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaVariableDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaVariableDescriptor.kt index 42ed0ebc..ffb77104 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaVariableDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaVariableDescriptor.kt @@ -13,7 +13,8 @@ public open class JavaVariableDescriptor(ctx: AnalysisContext, private val impl: override val isVar: Boolean get() = when (impl.kind) { - ElementKind.LOCAL_VARIABLE, ElementKind.FIELD -> true + ElementKind.LOCAL_VARIABLE, + ElementKind.FIELD -> true else -> false } override val isConst: Boolean = impl.constantValue != null diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaClass.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaClass.kt index 1d4973d0..e6ba6c44 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaClass.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaClass.kt @@ -75,9 +75,9 @@ public class JavaClass(private val ctx: AnalysisContext, private val impl: Class override val anonymousInitializers: List = emptyList() override val properties: List = emptyList() override val functions: List = - this@JavaClass.declarations.mapNotNull { it as? JavaMethod }.filter { - it !is JavaConstructor - } + this@JavaClass.declarations + .mapNotNull { it as? JavaMethod } + .filter { it !is JavaConstructor } override val enumEntries: List = emptyList() // TODO override val allCompanionObjects: List = emptyList() override val declarations: List = this@JavaClass.declarations diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedCall.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedCall.kt index c2e47198..86bcf1d0 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedCall.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedCall.kt @@ -47,15 +47,13 @@ public class JavaResolvedCall( override val typeArguments: Map get() = - resultingDescriptor - .typeParameters + resultingDescriptor.typeParameters .zip(typeArgs) .map { (descr, tree) -> descr to ctx.resolver.resolveType(tree)!!.model(ctx) } .toMap() override val valueArguments: Map get() = - resultingDescriptor - .valueParameters + resultingDescriptor.valueParameters .zip(arguments) .map { (descr, tree) -> descr to diff --git a/analysis/kotlin-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisGradlePlugin.kt b/analysis/kotlin-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisGradlePlugin.kt index a13fde32..f7868b2a 100644 --- a/analysis/kotlin-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisGradlePlugin.kt +++ b/analysis/kotlin-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisGradlePlugin.kt @@ -15,7 +15,8 @@ public class AnalysisGradlePlugin : ArrowMetaGradlePlugin { override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = // do not run on test targets - if (kotlinCompilation.compilationName.endsWith( + if ( + kotlinCompilation.compilationName.endsWith( KotlinCompilation.TEST_COMPILATION_NAME, ignoreCase = true ) diff --git a/analysis/kotlin-plugin/api/arrow-analysis-kotlin-plugin.api b/analysis/kotlin-plugin/api/arrow-analysis-kotlin-plugin.api index 61220513..90458e2f 100644 --- a/analysis/kotlin-plugin/api/arrow-analysis-kotlin-plugin.api +++ b/analysis/kotlin-plugin/api/arrow-analysis-kotlin-plugin.api @@ -2,120 +2,9 @@ public final class arrow/meta/AnalysisMetaCliProcessor : arrow/meta/MetaCliProce public fun ()V } -public class arrow/meta/AnalysisPlugin : arrow/meta/Meta { +public final class arrow/meta/AnalysisPlugin : arrow/meta/Meta { public fun ()V - public fun IrGeneration (Larrow/meta/dsl/codegen/ir/IrSyntax;Lkotlin/jvm/functions/Function3;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun additionalSources (Lkotlin/jvm/functions/Function4;)Larrow/meta/phases/analysis/CollectAdditionalSources; - public fun analysis (Lkotlin/jvm/functions/Function7;Lkotlin/jvm/functions/Function5;)Larrow/meta/phases/analysis/AnalysisHandler; - public fun callChecker (Lkotlin/jvm/functions/Function4;)Larrow/meta/phases/config/StorageComponentContainer; - public fun codegen (Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/asm/Codegen; - public fun compilerContextService ()Larrow/meta/phases/config/StorageComponentContainer; - public fun declarationAttributeAlterer (Lkotlin/jvm/functions/Function7;)Larrow/meta/phases/resolve/DeclarationAttributeAlterer; - public fun declarationChecker (Lkotlin/jvm/functions/Function4;)Larrow/meta/phases/config/StorageComponentContainer; - public fun enableIr ()Larrow/meta/phases/ExtensionPhase; - public fun extraImports (Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/analysis/ExtraImports; public fun intercept (Larrow/meta/phases/CompilerContext;)Ljava/util/List; - public fun irAnonymousInitializer (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irBlock (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irBlockBody (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irBody (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irBranch (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irBreak (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irBreakContinue (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irCall (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irCallableReference (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irCatch (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irClass (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irClassReference (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irComposite (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irConst (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irConstructor (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irConstructorCall (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irContainerExpression (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irContinue (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irDeclaration (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irDeclarationReference (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irDelegatingConstructorCall (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irDoWhileLoop (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irDump (Larrow/meta/Meta;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irDumpKotlinLike (Larrow/meta/Meta;Lorg/jetbrains/kotlin/ir/util/KotlinLikeDumpOptions;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irDynamicExpression (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irDynamicMemberExpression (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irDynamicOperatorExpression (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irElseBranch (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irEnumConstructorCall (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irEnumEntry (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irErrorCallExpression (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irErrorDeclaration (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irErrorExpression (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irExpression (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irExpressionBody (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irField (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irFieldAccess (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irFile (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irFunction (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irFunctionAccess (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irFunctionReference (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irGetClass (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irGetEnumValue (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irGetField (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irGetObjectValue (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irGetValue (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irInstanceInitializerCall (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irLocalDelegatedProperty (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irLocalDelegatedPropertyReference (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irLoop (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irMemberAccess (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irModuleFragment (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irProperty (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irPropertyReference (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irReturn (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irSetField (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irSetValue (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irSimpleFunction (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irSingletonReference (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irSpreadElement (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irStringConcatenation (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irSuspendableExpression (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irSuspensionPoint (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irSyntheticBody (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irThrow (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irTry (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irTypeAlias (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irTypeOperator (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irTypeParameter (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irValueAccess (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irValueParameter (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irVararg (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irVariable (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irWhen (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun irWhileLoop (Larrow/meta/Meta;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/codegen/ir/IRGeneration; - public fun meta ([Larrow/meta/phases/ExtensionPhase;)Ljava/util/List; - public fun packageFragmentProvider (Lkotlin/jvm/functions/Function7;)Larrow/meta/phases/resolve/PackageProvider; - public fun packageFragmentProvider (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/resolve/PackageProvider;Larrow/meta/phases/CompilerContext;)V - public fun preprocessedVirtualFileFactory (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/analysis/PreprocessedVirtualFileFactory; - public fun registerAnalysisHandler (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/analysis/AnalysisHandler;Larrow/meta/phases/CompilerContext;)V - public fun registerClassBuilder (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/codegen/asm/ClassBuilder;Larrow/meta/phases/CompilerContext;)V - public fun registerCodegen (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/codegen/asm/Codegen;Larrow/meta/phases/CompilerContext;)V - public fun registerCollectAdditionalSources (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/analysis/CollectAdditionalSources;Larrow/meta/phases/CompilerContext;)V - public fun registerCompilerConfiguration (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/config/Config;Larrow/meta/phases/CompilerContext;)V - public fun registerDeclarationAttributeAlterer (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/resolve/DeclarationAttributeAlterer;Larrow/meta/phases/CompilerContext;)V - public fun registerExtraImports (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/analysis/ExtraImports;Larrow/meta/phases/CompilerContext;)V - public fun registerIRGeneration (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/codegen/ir/IRGeneration;Larrow/meta/phases/CompilerContext;)V - public fun registerMetaAnalyzer ()Larrow/meta/phases/ExtensionPhase; - public fun registerMetaComponents (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Lorg/jetbrains/kotlin/config/CompilerConfiguration;Larrow/meta/phases/CompilerContext;)V - public fun registerPreprocessedVirtualFileFactory (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/analysis/PreprocessedVirtualFileFactory;Larrow/meta/phases/CompilerContext;)V - public fun registerProjectComponents (Lorg/jetbrains/kotlin/com/intellij/mock/MockProject;Lorg/jetbrains/kotlin/config/CompilerConfiguration;)V - public fun registerStorageComponentContainer (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/config/StorageComponentContainer;Larrow/meta/phases/CompilerContext;)V - public fun registerSyntheticResolver (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/resolve/synthetics/SyntheticResolver;Larrow/meta/phases/CompilerContext;)V - public fun registerSyntheticScopeProvider (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;Larrow/meta/phases/resolve/synthetics/SyntheticScopeProvider;Larrow/meta/phases/CompilerContext;)V - public fun registerSyntheticScopeProviderIfNeeded (Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project;)V - public fun storageComponent (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function4;)Larrow/meta/phases/config/StorageComponentContainer; - public fun suppressDiagnostic (Lkotlin/jvm/functions/Function1;)Larrow/meta/phases/ExtensionPhase; - public fun suppressDiagnosticWithTrace (Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/ExtensionPhase; - public fun syntheticResolver (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function6;Lkotlin/jvm/functions/Function6;Lkotlin/jvm/functions/Function6;Lkotlin/jvm/functions/Function6;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/resolve/synthetics/SyntheticResolver; - public fun syntheticScopes (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Larrow/meta/phases/ExtensionPhase; - public fun updateConfig (Lkotlin/jvm/functions/Function2;)Larrow/meta/phases/config/Config; } public class arrow/meta/plugins/analysis/errors/MetaDefaultErrorMessagesJvm : org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages$Extension { diff --git a/analysis/kotlin-plugin/build.gradle.kts b/analysis/kotlin-plugin/build.gradle.kts index 45b43e82..a2ea89e4 100644 --- a/analysis/kotlin-plugin/build.gradle.kts +++ b/analysis/kotlin-plugin/build.gradle.kts @@ -27,4 +27,7 @@ dependencies { testRuntimeOnly(projects.arrowAnalysisTypes) testRuntimeOnly(projects.arrowAnalysisKotlinPlugin) testRuntimeOnly(libs.arrowCore) + + testImplementation(libs.ksp.api) + testImplementation(libs.ksp.lib) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/AnalysisPlugin.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/AnalysisPlugin.kt index 1a1f10b8..86767357 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/AnalysisPlugin.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/AnalysisPlugin.kt @@ -3,7 +3,7 @@ package arrow.meta import arrow.meta.phases.CompilerContext import arrow.meta.plugins.analysis.phases.analysisPhases -open class AnalysisPlugin : Meta { +class AnalysisPlugin : Meta() { override fun intercept(ctx: CompilerContext): List = listOf("Arrow Analysis" { meta(analysisPhases()) }) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/Phases.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/Phases.kt index b1395445..c03428bd 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/Phases.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/Phases.kt @@ -113,7 +113,8 @@ internal fun Meta.analysisPhases(): ExtensionPhase = }, ), declarationChecker { declaration, descriptor, context -> - if (isInStage(context.moduleDescriptor, Stage.Init) || + if ( + isInStage(context.moduleDescriptor, Stage.Init) || isInStage(context.moduleDescriptor, Stage.CollectConstraints) ) { setStageAs(context.moduleDescriptor, Stage.CollectConstraints) diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolutionContext.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolutionContext.kt index 86df5ea7..0954202c 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolutionContext.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolutionContext.kt @@ -81,7 +81,8 @@ class KotlinResolutionContext( override fun Element.constraintsDSLElements(): List { val results = hashSetOf() val visitor = callExpressionRecursiveVisitor { - if (it.calleeExpression?.text == "pre" || + if ( + it.calleeExpression?.text == "pre" || it.calleeExpression?.text == "post" || it.calleeExpression?.text == "require" || it.calleeExpression?.text == "doNotLookAtArgumentsWhen" diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolvedCall.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolvedCall.kt index f037bd01..6e8b70ad 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolvedCall.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolvedCall.kt @@ -24,12 +24,14 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver class KotlinResolvedCall( val impl: org.jetbrains.kotlin.resolve.calls.model.ResolvedCall< - out org.jetbrains.kotlin.descriptors.CallableDescriptor> + out org.jetbrains.kotlin.descriptors.CallableDescriptor + > ) : ResolvedCall { fun impl(): org.jetbrains.kotlin.resolve.calls.model.ResolvedCall< - out org.jetbrains.kotlin.descriptors.CallableDescriptor> = impl + out org.jetbrains.kotlin.descriptors.CallableDescriptor + > = impl override val callElement: Element get() = impl().call.callElement.model() diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/ast/KotlinInterpreter.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/ast/KotlinInterpreter.kt index 454befb5..3e8661ba 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/ast/KotlinInterpreter.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/ast/KotlinInterpreter.kt @@ -19,9 +19,8 @@ private fun A.repr(unit: @Suppress("UNCHECKED_CAST") fun A.repr(): B = this as B -fun < - A : org.jetbrains.kotlin.descriptors.DeclarationDescriptor, B : DeclarationDescriptor> A.model(): - B = +fun A + .model(): B = when (this) { is SimpleFunctionDescriptor -> KotlinSimpleFunctionDescriptor(this).repr() is TypeAliasConstructorDescriptor -> KotlinTypeAliasConstructorDescriptor(this).repr() @@ -61,7 +60,8 @@ fun A.model(): B = } is KtBinaryExpressionWithTypeRHS -> when (this.operationReference.getReferencedName()) { - "as", "as?" -> KotlinTypeCastExpression(this).repr() + "as", + "as?" -> KotlinTypeCastExpression(this).repr() else -> KotlinDefaultExpression(this).repr() } is KtNameReferenceExpression -> KotlinNameReferenceExpression(this).repr() diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinMemberScope.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinMemberScope.kt index 2f143228..846ee2fd 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinMemberScope.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinMemberScope.kt @@ -22,7 +22,7 @@ fun interface KotlinMemberScope : MemberScope { override fun getContributedDescriptors( filter: (name: String) -> Boolean ): List = - impl().getContributedDescriptors(DescriptorKindFilter.ALL) { filter(it.toString()) }.map { - it.model() - } + impl() + .getContributedDescriptors(DescriptorKindFilter.ALL) { filter(it.toString()) } + .map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinModuleDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinModuleDescriptor.kt index b36d5fc5..8b8084ad 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinModuleDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinModuleDescriptor.kt @@ -15,9 +15,9 @@ class KotlinModuleDescriptor(val impl: org.jetbrains.kotlin.descriptors.ModuleDe impl().getPackage(org.jetbrains.kotlin.name.FqName(pck)).model() override fun getSubPackagesOf(fqName: FqName): List = - impl().getSubPackagesOf(org.jetbrains.kotlin.name.FqName(fqName.name)) { true }.map { - FqName(it.asString()) - } + impl() + .getSubPackagesOf(org.jetbrains.kotlin.name.FqName(fqName.name)) { true } + .map { FqName(it.asString()) } override val stableName: Name? get() = impl().stableName?.let { Name(it.asString()) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclaration.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclaration.kt index d3666199..04b07d59 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclaration.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclaration.kt @@ -14,7 +14,10 @@ fun interface KotlinDeclaration : Declaration, KotlinExpression, KotlinModifierL get() = impl().name override val parents: List get() = - impl().parents.filter { it !is KtFile }.filterIsInstance().toList().map { - it.model() - } + impl() + .parents + .filter { it !is KtFile } + .filterIsInstance() + .toList() + .map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/ConstraintsAnnotations.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/ConstraintsAnnotations.kt index 426c18f6..982c7c2c 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/ConstraintsAnnotations.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/ConstraintsAnnotations.kt @@ -34,7 +34,8 @@ import org.sosy_lab.java_smt.api.FormulaManager internal fun IrUtils.annotateWithConstraints(solverState: SolverState, fn: IrFunction) { if (!solverState.hadParseErrors()) { val model = - fn.toIrBasedDescriptor() + fn + .toIrBasedDescriptor() .model() val declarationConstraints = solverState.getConstraintsFor(model) if (declarationConstraints != null) { @@ -86,8 +87,7 @@ private fun getIrReturnedExpressionWithoutPostcondition(function: IrFunction): F is IrMemberAccessExpression<*> -> when (val symbol = veryLast.symbol) { is IrFunctionSymbol -> - symbol - .owner + symbol.owner .toIrBasedDescriptor() .model() else -> null @@ -179,8 +179,7 @@ private fun IrUtils.annotation( } private fun IrUtils.arrayOfStrings(values: List): IrVarargImpl? = - moduleFragment - .descriptor + moduleFragment.descriptor .getPackage(FqName("kotlin")) .memberScope .getContributedDescriptors { it.asString() == "arrayOf" } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/Hints.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/Hints.kt index 34647304..52d26b16 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/Hints.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/Hints.kt @@ -32,7 +32,8 @@ fun hints(descriptor: ModuleDescriptor, packages: Set): String { | |@PackagesWithLaws([$packageList]) |class hints_$hintPackageName { } - |""".trimMargin() + |""".trimMargin( + ) } enum class HintState { diff --git a/analysis/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar b/analysis/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar similarity index 100% rename from analysis/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar rename to analysis/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar diff --git a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/CharAndString.kt b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/CharAndString.kt index e04b791b..8346064d 100644 --- a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/CharAndString.kt +++ b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/CharAndString.kt @@ -92,8 +92,10 @@ object CharSequenceLaws { @Law inline fun CharSequence.indexOfLawChar(element: Char, startIndex: Int, ignoreCase: Boolean): Int = indexOf(element, startIndex, ignoreCase).post({ - if (this.length <= 0) (it == -1) else (it >= -1) - }) { "bounds for indexOf" } + if (this.length <= 0) (it == -1) else (it >= -1) + }) { + "bounds for indexOf" + } @Law inline fun CharSequence.indexOfLawString( element: String, @@ -101,8 +103,10 @@ object CharSequenceLaws { ignoreCase: Boolean ): Int = indexOf(element, startIndex, ignoreCase).post({ - if (this.length <= 0) (it == -1) else (it >= -1) - }) { "bounds for indexOf" } + if (this.length <= 0) (it == -1) else (it >= -1) + }) { + "bounds for indexOf" + } @Law inline fun CharSequence.lastIndexOfLawChar( element: Char, @@ -110,8 +114,10 @@ object CharSequenceLaws { ignoreCase: Boolean ): Int = lastIndexOf(element, startIndex, ignoreCase).post({ - if (this.length <= 0) (it == -1) else (it >= -1) - }) { "bounds for lastIndexOf" } + if (this.length <= 0) (it == -1) else (it >= -1) + }) { + "bounds for lastIndexOf" + } @Law inline fun CharSequence.lastIndexOfLawString( element: String, @@ -119,8 +125,10 @@ object CharSequenceLaws { ignoreCase: Boolean ): Int = lastIndexOf(element, startIndex, ignoreCase).post({ - if (this.length <= 0) (it == -1) else (it >= -1) - }) { "bounds for lastIndexOf" } + if (this.length <= 0) (it == -1) else (it >= -1) + }) { + "bounds for lastIndexOf" + } @Law inline fun CharSequence.indexOfFirstLaw(predicate: (x: Char) -> Boolean): Int = indexOfFirst(predicate).post({ if (this.length <= 0) (it == -1) else (it >= -1) }) { @@ -166,8 +174,10 @@ object CharSequenceLaws { inline fun CharSequence.dropLaw(n: Int): CharSequence { pre(n >= 0) { "n must be non-negative" } return drop(n).post({ - if (this.length <= n) (it.length == 0) else (it.length == this.length - n) - }) { "bounds for drop" } + if (this.length <= n) (it.length == 0) else (it.length == this.length - n) + }) { + "bounds for drop" + } } @Law inline fun CharSequence.takeLaw(n: Int): CharSequence { @@ -178,8 +188,10 @@ object CharSequenceLaws { inline fun CharSequence.dropLastLaw(n: Int): CharSequence { pre(n >= 0) { "n must be non-negative" } return dropLast(n).post({ - if (this.length <= n) (it.length == 0) else (it.length == this.length - n) - }) { "bounds for drop" } + if (this.length <= n) (it.length == 0) else (it.length == this.length - n) + }) { + "bounds for drop" + } } @Law inline fun CharSequence.takeLastLaw(n: Int): CharSequence { @@ -239,9 +251,11 @@ object StringLaws { @Law inline fun String.plusLaw(other: CharSequence?): String = plus(other).post({ - when { - other == null -> it.length == this.length - else -> it.length == this.length + other.length - } - }) { "concatenation adds lengths" } + when { + other == null -> it.length == this.length + else -> it.length == this.length + other.length + } + }) { + "concatenation adds lengths" + } } diff --git a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Collections.kt b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Collections.kt index 0b327ba6..f59e7023 100644 --- a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Collections.kt +++ b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Collections.kt @@ -159,8 +159,10 @@ object CollectionLaws { inline fun Collection.zipWithNextLaw(transform: (a: T, b: T) -> V): List { doNotLookAtArgumentsWhen(size < 2) { "empty lists have no elements" } return zipWithNext(transform).post({ - if (this.size < 2) (it.size == 0) else (it.size == this.size - 1) - }) { "size bounded by the smallest" } + if (this.size < 2) (it.size == 0) else (it.size == this.size - 1) + }) { + "size bounded by the smallest" + } } // operations which remove things @@ -322,8 +324,10 @@ object CollectionLaws { inline fun Collection.flatMapLaw(transform: (A) -> Iterable): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return flatMap(transform).post({ - if (size <= 0) it.size == 0 else /* true means no info */ true - }) { "size of empty list" } + if (size <= 0) it.size == 0 else /* true means no info */ true + }) { + "size of empty list" + } } @Law inline fun Collection.flatMapIndexedLaw( @@ -331,8 +335,10 @@ object CollectionLaws { ): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return flatMapIndexed(transform).post({ - if (size <= 0) it.size == 0 else /* true means no info */ true - }) { "size of empty list" } + if (size <= 0) it.size == 0 else /* true means no info */ true + }) { + "size of empty list" + } } @Law inline fun Collection>.flattenLaw(): List = @@ -529,8 +535,10 @@ object ListLaws { inline fun List.dropLastLaw(n: Int): List { pre(n >= 0) { "n must be non-negative" } return dropLast(n).post({ - if (this.size <= n) (it.size == 0) else (it.size == this.size - n) - }) { "bounds for drop" } + if (this.size <= n) (it.size == 0) else (it.size == this.size - n) + }) { + "bounds for drop" + } } @Law inline fun List.takeLastLaw(n: Int): List { diff --git a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Math.kt b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Math.kt index 61f987ff..7d4fe1cb 100644 --- a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Math.kt +++ b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Math.kt @@ -65,7 +65,9 @@ object MathLaws { this > 0 -> it == 1 else -> it == -1 } - }) { "sign bounds + definition" } + }) { + "sign bounds + definition" + } @Law inline fun Long.signLaw(): Int = sign.post({ @@ -76,7 +78,9 @@ object MathLaws { this > 0L -> it == 1 else -> it == -1 } - }) { "sign bounds + definition" } + }) { + "sign bounds + definition" + } @Law inline fun Double.signLaw(): Double = sign.post({ @@ -87,7 +91,9 @@ object MathLaws { this > 0.0 -> it == 1.0 else -> it == -1.0 } - }) { "sign bounds + definition" } + }) { + "sign bounds + definition" + } @Law inline fun Float.signLaw(): Float = sign.post({ @@ -98,30 +104,36 @@ object MathLaws { this > 0.0F -> it == 1.0F else -> it == -1.0F } - }) { "sign bounds + definition" } + }) { + "sign bounds + definition" + } @Law inline fun signTopLevelLaw(x: Double): Double = sign(x).post({ - it >= -1.0 && - it <= 1.0 && - when { - x == 0.0 -> it == 0.0 - x > 0.0 -> it == 1.0 - else -> it == -1.0 - } - }) { "sign bounds + definition" } + it >= -1.0 && + it <= 1.0 && + when { + x == 0.0 -> it == 0.0 + x > 0.0 -> it == 1.0 + else -> it == -1.0 + } + }) { + "sign bounds + definition" + } @Law inline fun signTopLevelLaw(x: Float): Float = sign(x).post({ - it >= -1.0F && - it <= 1.0F && - when { - x == 0.0F -> it == 0.0F - x > 0.0F -> it == 1.0F - else -> it == -1.0F - } - }) { "sign bounds + definition" } + it >= -1.0F && + it <= 1.0F && + when { + x == 0.0F -> it == 0.0F + x > 0.0F -> it == 1.0F + else -> it == -1.0F + } + }) { + "sign bounds + definition" + } @Law inline fun maxLaw(a: Int, b: Int): Int = diff --git a/build.gradle.kts b/build.gradle.kts index 1d977d97..2bba330a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,8 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @Suppress("DSL_SCOPE_VIOLATION") + plugins { alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.dokka) apply false @@ -49,18 +52,29 @@ allprojects { ) systemProperty("CURRENT_VERSION", "$version") systemProperty("arrowVersion", libs.versions.arrow.get()) - systemProperty("jvmTargetVersion", properties["jvmTargetVersion"].toString()) - jvmArgs = listOf("""-Dkotlin.compiler.execution.strategy="in-process"""") + jvmArgs = listOf( + """-Dkotlin.compiler.execution.strategy="in-process"""", + "--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED" + ) } } val toolchain = project.extensions.getByType() allprojects { tasks.withType().configureEach { - javaCompiler.set(toolchain.compilerFor { - val jvmTargetVersion = properties["jvmTargetVersion"].toString() - val javaVersion = if (jvmTargetVersion == "1.8") "8" else jvmTargetVersion - languageVersion.set(JavaLanguageVersion.of(javaVersion)) - }) + javaCompiler.set( + toolchain.compilerFor { + languageVersion.set(JavaLanguageVersion.of(8)) + } + ) + } + tasks.withType().configureEach { + compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8) } } diff --git a/docs/Gemfile.lock b/docs/Gemfile.lock index d4817d74..c583fa1c 100644 --- a/docs/Gemfile.lock +++ b/docs/Gemfile.lock @@ -1,22 +1,20 @@ GEM remote: https://rubygems.org/ specs: - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) colorator (1.1.0) - concurrent-ruby (1.1.8) - em-websocket (0.5.2) + concurrent-ruby (1.2.0) + em-websocket (0.5.3) eventmachine (>= 0.12.9) - http_parser.rb (~> 0.6.0) + http_parser.rb (~> 0) eventmachine (1.2.7) - eventmachine (1.2.7-x64-mingw32) - ffi (1.15.0) - ffi (1.15.0-x64-mingw32) + ffi (1.15.5) forwardable-extended (2.6.0) - http_parser.rb (0.6.0) - i18n (1.8.10) + http_parser.rb (0.8.0) + i18n (1.12.0) concurrent-ruby (~> 1.0) - jekyll (4.2.0) + jekyll (4.2.2) addressable (~> 2.4) colorator (~> 1.0) em-websocket (~> 0.5) @@ -31,43 +29,40 @@ GEM rouge (~> 3.0) safe_yaml (~> 1.0) terminal-table (~> 2.0) - jekyll-sass-converter (2.1.0) + jekyll-sass-converter (2.2.0) sassc (> 2.0.1, < 3.0) jekyll-watch (2.2.1) listen (~> 3.0) - kramdown (2.3.1) + kramdown (2.4.0) rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) - liquid (4.0.3) - listen (3.5.1) + liquid (4.0.4) + listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) mercenary (0.4.0) pathutil (0.16.2) forwardable-extended (~> 2.6) - public_suffix (4.0.6) - rb-fsevent (0.10.4) + public_suffix (5.0.1) + rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) rexml (3.2.5) - rouge (3.26.0) + rouge (3.30.0) safe_yaml (1.0.5) sassc (2.4.0) ffi (~> 1.9) - sassc (2.4.0-x64-mingw32) - ffi (~> 1.9) terminal-table (2.0.0) unicode-display_width (~> 1.1, >= 1.1.1) - unicode-display_width (1.7.0) + unicode-display_width (1.8.0) PLATFORMS - ruby - x64-mingw32 + x86_64-darwin-21 DEPENDENCIES jekyll (~> 4.2.0) kramdown (>= 2.3.1) BUNDLED WITH - 2.1.4 + 2.4.7 diff --git a/gradle/projects.libs.versions.toml b/gradle/projects.libs.versions.toml index 0bf0429f..d525bb8e 100644 --- a/gradle/projects.libs.versions.toml +++ b/gradle/projects.libs.versions.toml @@ -1,19 +1,21 @@ [versions] -arrow = "1.1.2" -arrowMeta = "1.6.1-alpha.5" -arrowGradleConfig = "0.10.1" -classgraph = "4.8.146" -dokka = "1.6.21" -junit = "5.8.2" -junitLauncher = "1.8.2" -kotlin = "1.6.21" -kotest = "3.4.2" -javaSmt = "3.12.0" -javaCompileTesting = "0.19" +arrow = "1.1.5" +arrowMeta = "1.6.2-alpha.5" +arrowGradleConfig = "0.11.0" +classgraph = "4.8.157" +dokka = "1.8.10" +junit = "5.9.2" +junitLauncher = "1.9.2" +kotlin = "1.8.10" +kotest = "5.5.5" +javaSmt = "3.14.3" +javaCompileTesting = "0.21.0" apacheCommonsText = "1.9" -sarif4k = "0.0.1" -kotlinBinaryCompatibilityValidator = "0.9.0" -detekt = "1.20.0" +sarif4k = "0.3.0" +kotlinBinaryCompatibilityValidator = "0.13.0" +detekt = "1.22.0" +kotlinxSerialization = "1.5.0-RC" +ksp = "1.8.10-1.0.9" [libraries] arrowAnnotations = { module = "io.arrow-kt:arrow-annotations", version.ref = "arrow" } @@ -36,6 +38,9 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect" } javaCompileTesting = { module = "com.google.testing.compile:compile-testing", version.ref = "javaCompileTesting" } apacheCommonsText = { module = "org.apache.commons:commons-text", version.ref = "apacheCommonsText" } sarif4k = { module = "io.github.detekt.sarif4k:sarif4k", version.ref = "sarif4k" } +kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinxSerialization" } +ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } +ksp-lib = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" } [plugins] dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa991fce..e1bef7e8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index 7cf2cbcc..45ab96d6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,5 +1,4 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") -enableFeaturePreview("VERSION_CATALOGS") pluginManagement { repositories {