Skip to content

Commit

Permalink
Revert "Fix Kotlin compiler may not in all cases be released."
Browse files Browse the repository at this point in the history
This reverts commit 3d2b20f.
  • Loading branch information
Tapchicoma committed Oct 14, 2021
1 parent 2440159 commit 295cbce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ public object KtLint {
}
} catch (e: Exception) {
val (line, col) = preparedCode.positionInTextLocator(node.startOffset)
kotlinPsiFileFactory.releasePsiFileFactory()
throw RuleExecutionException(line, col, fqRuleId, e)
}
}
}

kotlinPsiFileFactory.releasePsiFileFactory()
errors
.sortedWith { l, r -> if (l.line != r.line) l.line - r.line else l.col - r.col }
.forEach { e -> params.cb(e, false) }

kotlinPsiFileFactory.releasePsiFileFactory()
}

@OptIn(FeatureInAlphaState::class)
Expand Down Expand Up @@ -400,7 +400,6 @@ public object KtLint {
}
}
} catch (e: Exception) {
kotlinPsiFileFactory.releasePsiFileFactory()
// line/col cannot be reliably mapped as exception might originate from a node not present
// in the original AST
throw RuleExecutionException(0, 0, fqRuleId, e)
Expand Down Expand Up @@ -429,7 +428,6 @@ public object KtLint {
}
} catch (e: Exception) {
val (line, col) = preparedCode.positionInTextLocator(node.startOffset)
kotlinPsiFileFactory.releasePsiFileFactory()
throw RuleExecutionException(line, col, fqRuleId, e)
}
}
Expand All @@ -441,7 +439,6 @@ public object KtLint {
}

if (!mutated) {
kotlinPsiFileFactory.releasePsiFileFactory()
return params.text
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ internal class KotlinPsiFileFactory {
private val acquireCounter = AtomicInteger(0)
private val initializerLock = Any()

internal fun acquirePsiFileFactory(isFromCli: Boolean): PsiFileFactory = synchronized(initializerLock) {
internal fun acquirePsiFileFactory(isFromCli: Boolean): PsiFileFactory {
acquireCounter.incrementAndGet()
return psiFileFactory ?: initializePsiFileFactory(isFromCli).also {
psiFileFactory = it
return psiFileFactory ?: synchronized(initializerLock) {
initializePsiFileFactory(isFromCli).also {
psiFileFactory = it
}
}
}

internal fun releasePsiFileFactory() = synchronized(initializerLock) {
internal fun releasePsiFileFactory() {
val acquiredCount = acquireCounter.decrementAndGet()
if (acquiredCount == 0) {
if (acquiredCount == 0) synchronized(initializerLock) {
tempFiles?.toFile()?.deleteRecursively()
tempFiles = null
psiFileFactory = null
Expand Down

0 comments on commit 295cbce

Please sign in to comment.