Skip to content

Make USVM descriptor to UtModel cache consider state kind (initial or final) #2697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ class JcToUtModelConverter(
private val jcClasspath: JcClasspath,
private val instToUtModelConverter: UTestInstToUtModelConverter,
) {
private val descriptorToModelCache = mutableMapOf<UTestValueDescriptor, UtModel>()
private val descriptorToModelCache =
mutableMapOf<Pair<UTestValueDescriptor, EnvironmentStateKind>, UtModel>()
private val refIdAndStateKindToDescriptorCache =
mutableMapOf<Pair<Int, EnvironmentStateKind>, UTestValueDescriptor>()

fun convert(
valueDescriptor: UTestValueDescriptor,
stateKind: EnvironmentStateKind,
): UtModel = descriptorToModelCache.getOrPut(valueDescriptor) {
): UtModel = descriptorToModelCache.getOrPut(valueDescriptor to stateKind) {
if (stateKind == EnvironmentStateKind.INITIAL || valueDescriptor.origin is UTestMock)
valueDescriptor.origin?.let { originExpr ->
val model = instToUtModelConverter.findModelByInst(originExpr as UTestExpression)
Expand Down Expand Up @@ -79,7 +80,7 @@ class JcToUtModelConverter(
valueDescriptor: UTestValueDescriptor,
stateKind: EnvironmentStateKind,
curModelId: Int,
): UtModel = descriptorToModelCache.getOrPut(valueDescriptor) {
): UtModel = descriptorToModelCache.getOrPut(valueDescriptor to stateKind) {
if (valueDescriptor is UTestRefDescriptor) {
refIdAndStateKindToDescriptorCache[valueDescriptor.refId to stateKind] = valueDescriptor
}
Expand All @@ -96,7 +97,7 @@ class JcToUtModelConverter(
fields = fields,
)

descriptorToModelCache[valueDescriptor] = model
descriptorToModelCache[valueDescriptor to stateKind] = model

fields += valueDescriptor.fields
.entries
Expand All @@ -120,7 +121,7 @@ class JcToUtModelConverter(
stores = stores,
)

descriptorToModelCache[valueDescriptor] = model
descriptorToModelCache[valueDescriptor to stateKind] = model

valueDescriptor.value
.map { elemDescr -> convert(elemDescr, stateKind) }
Expand Down Expand Up @@ -182,6 +183,6 @@ class JcToUtModelConverter(
stateKind: EnvironmentStateKind
): UtModel? =
refIdAndStateKindToDescriptorCache[refId to stateKind]?.let {
descriptorToModelCache[it]
descriptorToModelCache[it to stateKind]
}
}