-
Notifications
You must be signed in to change notification settings - Fork 0
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
Embedding for String
s
#244
base: formal-verification
Are you sure you want to change the base?
Changes from all commits
2b6eb83
732e313
7af9a8e
7ac7b17
18869c5
3f3e6d4
0cf6d42
1a1bb1c
f2ca6ff
1f913d3
ca786ff
91c03b1
13aaa25
99fbb1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.formver.conversion | |
import org.jetbrains.kotlin.KtSourceElement | ||
import org.jetbrains.kotlin.descriptors.ClassKind | ||
import org.jetbrains.kotlin.descriptors.Visibilities | ||
import org.jetbrains.kotlin.descriptors.isInterface | ||
import org.jetbrains.kotlin.fir.FirSession | ||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction | ||
import org.jetbrains.kotlin.fir.declarations.utils.* | ||
|
@@ -21,16 +22,7 @@ import org.jetbrains.kotlin.formver.domains.RuntimeTypeDomain | |
import org.jetbrains.kotlin.formver.embeddings.* | ||
import org.jetbrains.kotlin.formver.embeddings.callables.* | ||
import org.jetbrains.kotlin.formver.embeddings.expression.* | ||
import org.jetbrains.kotlin.formver.embeddings.types.ClassEmbeddingDetails | ||
import org.jetbrains.kotlin.formver.embeddings.types.TypeEmbedding | ||
import org.jetbrains.kotlin.formver.embeddings.types.ClassTypeEmbedding | ||
import org.jetbrains.kotlin.formver.embeddings.types.FunctionPretypeBuilder | ||
import org.jetbrains.kotlin.formver.embeddings.types.FunctionTypeEmbedding | ||
import org.jetbrains.kotlin.formver.embeddings.types.PretypeBuilder | ||
import org.jetbrains.kotlin.formver.embeddings.types.TypeBuilder | ||
import org.jetbrains.kotlin.formver.embeddings.types.buildClassPretype | ||
import org.jetbrains.kotlin.formver.embeddings.types.buildFunctionPretype | ||
import org.jetbrains.kotlin.formver.embeddings.types.buildType | ||
import org.jetbrains.kotlin.formver.embeddings.types.* | ||
import org.jetbrains.kotlin.formver.linearization.Linearizer | ||
import org.jetbrains.kotlin.formver.linearization.SeqnBuilder | ||
import org.jetbrains.kotlin.formver.linearization.SharedLinearizationState | ||
|
@@ -49,7 +41,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifTrue | |
*/ | ||
class ProgramConverter(val session: FirSession, override val config: PluginConfiguration, override val errorCollector: ErrorCollector) : | ||
ProgramConversionContext { | ||
private val methods: MutableMap<MangledName, FunctionEmbedding> = SpecialKotlinFunctions.byName.toMutableMap() | ||
private val methods: MutableMap<MangledName, FunctionEmbedding> = | ||
SpecialKotlinFunctions.byName.toMutableMap().also { | ||
it.putAll(PartiallySpecialKotlinFunctions.byName) | ||
} | ||
private val classes: MutableMap<MangledName, ClassTypeEmbedding> = mutableMapOf() | ||
private val properties: MutableMap<MangledName, PropertyEmbedding> = mutableMapOf() | ||
private val fields: MutableSet<FieldEmbedding> = mutableSetOf() | ||
|
@@ -119,12 +114,23 @@ class ProgramConverter(val session: FirSession, override val config: PluginConfi | |
} | ||
} | ||
|
||
override fun embedFunction(symbol: FirFunctionSymbol<*>): FunctionEmbedding = | ||
methods.getOrPut(symbol.embedName(this)) { | ||
val signature = embedFullSignature(symbol) | ||
val callable = processCallable(symbol, signature) | ||
UserFunctionEmbedding(callable) | ||
override fun embedFunction(symbol: FirFunctionSymbol<*>): FunctionEmbedding { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code here seems to be the reason to have |
||
return when (val existing = methods[symbol.embedName(this)]) { | ||
null, is PartiallySpecialKotlinFunction -> { | ||
if (existing is PartiallySpecialKotlinFunction && existing.baseEmbedding != null) | ||
return existing | ||
val signature = embedFullSignature(symbol) | ||
val callable = processCallable(symbol, signature) | ||
val userFunction = UserFunctionEmbedding(callable) | ||
when { | ||
existing is PartiallySpecialKotlinFunction -> | ||
existing.also { it.initBaseEmbedding(userFunction) } | ||
else -> userFunction.also { methods[symbol.embedName(this)] = it } | ||
} | ||
Comment on lines
+125
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it's a bit strange to have |
||
} | ||
else -> existing | ||
} | ||
} | ||
|
||
/** | ||
* Returns an embedding of the class type, with details set. | ||
|
@@ -138,7 +144,10 @@ class ProgramConverter(val session: FirSession, override val config: PluginConfi | |
} | ||
if (embedding.hasDetails) return embedding | ||
|
||
val newDetails = ClassEmbeddingDetails(embedding, symbol.classKind == ClassKind.INTERFACE) | ||
val sharedPredicateEnhancer = embedding.isString.ifTrue { | ||
StringSharedPredicateEnhancer | ||
} | ||
val newDetails = ClassEmbeddingDetails(embedding, symbol.classKind.isInterface, sharedPredicateEnhancer) | ||
embedding.initDetails(newDetails) | ||
|
||
// The full class embedding is necessary to process the signatures of the properties of the class, since | ||
|
@@ -289,7 +298,7 @@ class ProgramConverter(val session: FirSession, override val config: PluginConfi | |
} | ||
} | ||
return if (invariants.isEmpty()) null | ||
else UnfoldingClassPredicateEmbedding(returnVariable, invariants.toConjunction()) | ||
else UnfoldingSharedClassPredicateEmbedding(returnVariable, invariants.toConjunction()) | ||
} | ||
|
||
override val declarationSource: KtSourceElement? = symbol.source | ||
|
@@ -409,6 +418,7 @@ class ProgramConverter(val session: FirSession, override val config: PluginConfi | |
isNullable = true; any() | ||
} | ||
type.isUnit -> unit() | ||
type.isChar -> char() | ||
type.isInt -> int() | ||
type.isBoolean -> boolean() | ||
type.isNothing -> nothing() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super important, but it's a bit weird that we are making a map, then turning it into a mutable map, and then mutating it again. If this is what we'll do with
SpecialKotlinFunctions.byName
anyway, maybe let's have it take a mutable map/mutable map builder? That would also make it clear it is stateless.