Skip to content

Commit

Permalink
FIR IDE: remove duplicating withFirResolvedToBodyResolve
Browse files Browse the repository at this point in the history
  • Loading branch information
darthorimar committed Nov 27, 2020
1 parent 3141fea commit 65a7ee5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal class KtFirCompletionCandidateChecker(

private inline fun <reified T : KtFirSymbol<F>, F : FirDeclaration, R> KtCallableSymbol.withResolvedFirOfType(
noinline action: (F) -> R,
): R? = this.safeAs<T>()?.firRef?.withFirResolvedToBodyResolve(action)
): R? = this.safeAs<T>()?.firRef?.withFir(phase = FirResolvePhase.BODY_RESOLVE, action)

private fun checkExtension(
candidateSymbol: FirCallableDeclaration<*>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ internal class FirRefWithValidityCheck<D : FirDeclaration>(fir: D, resolveState:
val resolveState = resolveStateWeakRef.get()
?: throw EntityWasGarbageCollectedException("FirModuleResolveState")
fir.resolvedFirToPhase(phase, resolveState)
return resolveState.withFirDeclaration(fir) { action(it) }
}

inline fun <R> withFirResolvedToBodyResolve(action: (fir: D) -> R): R {
token.assertIsValid()
val fir = firWeakRef.get()
?: throw EntityWasGarbageCollectedException("FirElement")
val resolveState = resolveStateWeakRef.get()
?: throw EntityWasGarbageCollectedException("FirModuleResolveState")
fir.resolvedFirToPhase(FirResolvePhase.BODY_RESOLVE, resolveState)
return action(resolveState.withFirDeclaration(fir) { it })
return when (phase) {
FirResolvePhase.BODY_RESOLVE -> {
/*
The BODY_RESOLVE phase is the maximum possible phase we can resolve our declaration to
So there is not need to run whole `action` under read lock
*/
action(resolveState.withFirDeclaration(fir) { it })
}
else -> resolveState.withFirDeclaration(fir) { action(it) }
}
}

val resolveState
Expand Down

0 comments on commit 65a7ee5

Please sign in to comment.