@@ -8,10 +8,12 @@ import org.utbot.fuzzing.Feedback
88import org.utbot.fuzzing.Fuzzing
99import org.utbot.fuzzing.Seed
1010import org.utbot.fuzzing.Statistic
11+ import org.utbot.fuzzing.ValueProvider
1112import org.utbot.fuzzing.utils.Trie
1213import org.utbot.python.coverage.PyInstruction
1314import org.utbot.python.engine.ExecutionFeedback
1415import org.utbot.python.framework.api.python.PythonTree
16+ import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
1517import org.utbot.python.fuzzing.provider.BoolValueProvider
1618import org.utbot.python.fuzzing.provider.BytearrayValueProvider
1719import org.utbot.python.fuzzing.provider.BytesValueProvider
@@ -41,6 +43,9 @@ import org.utbot.python.newtyping.inference.InferredTypeFeedback
4143import org.utbot.python.newtyping.inference.InvalidTypeFeedback
4244import org.utbot.python.newtyping.inference.SuccessFeedback
4345import org.utbot.python.newtyping.inference.baseline.BaselineAlgorithm
46+ import org.utbot.python.newtyping.pythonModuleName
47+ import org.utbot.python.newtyping.pythonName
48+ import org.utbot.python.newtyping.pythonTypeName
4449import org.utbot.python.newtyping.pythonTypeRepresentation
4550import org.utbot.python.utils.ExecutionWithTimoutMode
4651import org.utbot.python.utils.FakeWithTimeoutMode
@@ -49,12 +54,33 @@ import kotlin.random.Random
4954
5055private val logger = KotlinLogging .logger {}
5156
57+ typealias PythonValueProvider = ValueProvider <FuzzedUtType , PythonFuzzedValue , PythonMethodDescription >
58+
5259data class PythonFuzzedConcreteValue (
5360 val type : UtType ,
5461 val value : Any ,
5562 val fuzzedContext : FuzzedContext = FuzzedContext .Unknown ,
5663)
5764
65+ data class FuzzedUtType (
66+ val utType : UtType ,
67+ val fuzzAny : Boolean = false ,
68+ ) {
69+ fun activateAny () = FuzzedUtType (utType, true )
70+
71+ fun isAny (): Boolean = utType.isAny()
72+ fun pythonName (): String = utType.pythonName()
73+ fun pythonTypeName (): String = utType.pythonTypeName()
74+ fun pythonModuleName (): String = utType.pythonModuleName()
75+ fun pythonTypeRepresentation (): String = utType.pythonTypeRepresentation()
76+
77+ companion object {
78+ fun Collection<UtType>.toFuzzed () = this .map { it.toFuzzed() }
79+ fun UtType.toFuzzed () = FuzzedUtType (this )
80+ fun Collection<FuzzedUtType>.activateAny () = this .map { it.activateAny() }
81+ }
82+ }
83+
5884class PythonMethodDescription (
5985 val name : String ,
6086 val concreteValues : Collection <PythonFuzzedConcreteValue > = emptyList(),
@@ -63,7 +89,7 @@ class PythonMethodDescription(
6389 val random : Random ,
6490 val limitManager : TestGenerationLimitManager ,
6591 val type : FunctionType ,
66- ) : Description<UtType >(type.arguments)
92+ ) : Description<FuzzedUtType >(type.arguments.toFuzzed() )
6793
6894data class PythonExecutionResult (
6995 val executionFeedback : ExecutionFeedback ,
@@ -75,7 +101,7 @@ data class PythonFeedback(
75101 val result : Trie .Node <PyInstruction > = Trie .emptyNode(),
76102 val typeInferenceFeedback : InferredTypeFeedback = InvalidTypeFeedback ,
77103 val fromCache : Boolean = false ,
78- ) : Feedback<UtType , PythonFuzzedValue> {
104+ ) : Feedback<FuzzedUtType , PythonFuzzedValue> {
79105 fun fromCache (): PythonFeedback {
80106 return PythonFeedback (
81107 control = control,
@@ -132,27 +158,38 @@ class PythonFuzzing(
132158 private val typeInferenceAlgorithm : BaselineAlgorithm ,
133159 private val globalIsCancelled : () -> Boolean ,
134160 val execute : suspend (description: PythonMethodDescription , values: List <PythonFuzzedValue >) -> PythonFeedback ,
135- ) : Fuzzing<UtType , PythonFuzzedValue, PythonMethodDescription, PythonFeedback> {
161+ ) : Fuzzing<FuzzedUtType , PythonFuzzedValue, PythonMethodDescription, PythonFeedback> {
136162
137- private fun generateDefault (description : PythonMethodDescription , type : UtType )= sequence {
138- pythonDefaultValueProviders(pythonTypeStorage) .asSequence().forEach { provider ->
163+ private fun generateDefault (providers : List < PythonValueProvider >, description : PythonMethodDescription , type : FuzzedUtType )= sequence {
164+ providers .asSequence().forEach { provider ->
139165 if (provider.accept(type)) {
140166 logger.debug { " Provider ${provider.javaClass.simpleName} accepts type ${type.pythonTypeRepresentation()} " }
141167 yieldAll(provider.generate(description, type))
142168 }
143169 }
144170 }
145171
146- override fun generate (description : PythonMethodDescription , type : UtType ): Sequence <Seed <UtType , PythonFuzzedValue >> {
147- var providers = emptyList<Seed <UtType , PythonFuzzedValue >>().asSequence()
172+ private fun generateAnyProviders (description : PythonMethodDescription , type : FuzzedUtType ) = sequence {
173+ pythonAnyTypeValueProviders().asSequence().forEach { provider ->
174+ logger.debug { " Provider ${provider.javaClass.simpleName} accepts type ${type.pythonTypeRepresentation()} with activated any" }
175+ yieldAll(provider.generate(description, type))
176+ }
177+ }
178+
179+ override fun generate (description : PythonMethodDescription , type : FuzzedUtType ): Sequence <Seed <FuzzedUtType , PythonFuzzedValue >> {
180+ val providers = mutableSetOf<Seed <FuzzedUtType , PythonFuzzedValue >>()
148181
149182 if (type.isAny()) {
150- logger.debug(" Any does not have provider" )
183+ if (type.fuzzAny) {
184+ providers + = generateAnyProviders(description, type)
185+ } else {
186+ logger.debug(" Any does not have provider" )
187+ }
151188 } else {
152- providers + = generateDefault(description, type)
189+ providers + = generateDefault(pythonDefaultValueProviders(pythonTypeStorage), description, type)
153190 }
154191
155- return providers
192+ return providers.asSequence()
156193 }
157194
158195 override suspend fun handle (description : PythonMethodDescription , values : List <PythonFuzzedValue >): PythonFeedback {
@@ -166,7 +203,7 @@ class PythonFuzzing(
166203 return result
167204 }
168205
169- private suspend fun forkType (description : PythonMethodDescription , stats : Statistic <UtType , PythonFuzzedValue >) {
206+ private suspend fun forkType (description : PythonMethodDescription , stats : Statistic <FuzzedUtType , PythonFuzzedValue >) {
170207 val type: UtType ? = typeInferenceAlgorithm.expandState()
171208 if (type != null ) {
172209 val d = PythonMethodDescription (
@@ -190,12 +227,12 @@ class PythonFuzzing(
190227
191228 override suspend fun isCancelled (
192229 description : PythonMethodDescription ,
193- stats : Statistic <UtType , PythonFuzzedValue >
230+ stats : Statistic <FuzzedUtType , PythonFuzzedValue >
194231 ): Boolean {
195232 if (globalIsCancelled()) {
196233 return true
197234 }
198- if (description.limitManager.isCancelled() || description.parameters.any { it.isAny() }) {
235+ if (description.limitManager.isCancelled()) { // || description.parameters.any { it.isAny() }) {
199236 forkType(description, stats)
200237 if (description.limitManager.isRootManager) {
201238 return FakeWithTimeoutMode .isCancelled(description.limitManager)
0 commit comments