Uh oh!
There was an error while loading. Please reload this page.
Make UtEnumConstModel and UtClassRefModel reference models #414 - #611
Conversation
19214b2 to
06e56adCompare
Damtev
left a comment
There was a problem hiding this comment.
Logic LGTM, some issues about codestyle
| * Get model id or null if id is null or the model has no id. | ||
| */ | ||
| fun UtModel.idOrNull(): Int? = when (this) { | ||
| is UtNullModel -> 0 |
There was a problem hiding this comment.
Could you link this constant with org.utbot.engine.ResolverKt#NULL_ADDR somehow, please?
There was a problem hiding this comment.
What do you think about moving the constant from Resolver into Api.kt?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
3de411a to
84c66ceCompare
sergeypospelov
left a comment
There was a problem hiding this comment.
The concrete part looks good to me.
| import org.utbot.engine.UtNamedStore | ||
| import org.utbot.framework.plugin.api.ClassId | ||
| import org.utbot.framework.plugin.api.FieldId | ||
| import org.utbot.framework.plugin.api.classId |
There was a problem hiding this comment.
Looks like these imports are redundant.
54af0a3 to
410613aComparedtim
commented
Aug 3, 2022
Updated |
f4959aa to
e29923fCompareHistorically `UtEnumConstModel` and `UtClassRefModel` have been processed not as other reference models, but in a special way, more like to primitive types. This approach leads to several problems, especially to class cast errors when processing generic collections with enums or class references as elements. This commit makes `UtEnumConstModel` and `UtClassRefModel` subtypes of `UtReferenceModel`. * Concrete executor is modified to respect the identity of static fields to avoid rewriting enum values and `Class<?>` instances. * Special processing for enums is implemented. When a new enum value is created, or an `Object` is being cast to the enum type, static values for the enum class are initialized, and the set of hard constraint is added to require that the new instance has the same address and ordinal as any one of enum constants to implement reference equality for enums. * Corresponding changes in fuzzer model providers have been implemented. * UtModelVisitor has been updated to reflect the new inheritance hierarchy.
A custom id generator interface hierarchy is used instead of `IntSupplier`: * `IdGenerator` that allows to create fresh identifiers, * `IdentityPreservingIdGenerator`: `IdGenerator` that can return the same id for the same object. A default implementation of `IdentityPreservingIdGenerator` is used in fuzzer. It uses reference equality for object comparison, that allows to create distinct models of equal object (in `equals` sense), and to always assign the same id to the same enum value.
374eb3c to
b11b184CompareMake UtEnumConstModel and UtClassRefModel reference models #414 Historically `UtEnumConstModel` and `UtClassRefModel` have been processed not as other reference models, but in a special way, more like to primitive types. This approach leads to several problems, especially to class cast errors when processing generic collections with enums or class references as elements. This commit makes `UtEnumConstModel` and `UtClassRefModel` subtypes of `UtReferenceModel`. * Concrete executor is modified to respect the identity of static fields to avoid rewriting enum values and `Class<?>` instances. * Special processing for enums is implemented. When a new enum value is created, or an `Object` is being cast to the enum type, static values for the enum class are initialized, and the set of hard constraint is added to require that the new instance has the same address and ordinal as any one of enum constants to implement reference equality for enums. * `UtModelVisitor` has been updated to reflect the new inheritance hierarchy. * Corresponding changes in the fuzzer have been implemented, including id generation refactoring. A custom id generator interface hierarchy is now used instead of `IntSupplier`: - `IdGenerator` that allows to create fresh identifiers, - `IdentityPreservingIdGenerator`: `IdGenerator` that can return the same id for the same object. A default implementation of `IdentityPreservingIdGenerator` is used in fuzzer. It uses reference equality for object comparison, that allows to create distinct models of equal object (in `equals` sense), and to always assign the same id to the same enum value.
Description
Historically
UtEnumConstModelandUtClassRefModelhave been processed not as other reference models, but in a special way, more like to primitive types. This approach leads to several problems, especially to class cast errors when processing generic collections with enums or class references as elements.This commit makes
UtEnumConstModelandUtClassRefModelsubtypes ofUtReferenceModel.Concrete executor is modified to respect the identity of static fields to avoid rewriting enum values and
Class<?>instances.Special processing for enums is implemented. When a new enum value is created, or an
Objectis being cast to the enum type, static values for the enum class are initialized, and the set of hard constraint is added to require that the new instance has the same address and ordinal as any one of enum constants to implement reference equality for enums.Corresponding changes in fuzzer model providers have been implemented.
Limitations (probably have been there for a long time, addressed separately):
Fixes#414 (meta-issue)
Fixes#230
Fixes#300
Type of Change
How Has This Been Tested?
Automated Testing
All existing unit tests should pass.
New unit tests for enums have been added:
org.utbot.examples.enums.ComplexEnumExamplesTestNote: the test
org.utbot.examples.enums.ComplexEnumExamplesTest#testFindStateis currently disabled because of limited anonymous classes support.Manual Scenario
To check that #230 is fixed: generate the test suite for the code example in issue #230 description. Test should be generated, no exceptions should be thrown.
To check that #300 is fixed: run the contest estimator with settings from issue #300 description. Generated file should compile, class name should be present in qualified enum constant names.
Checklist:
This is the author self-check list