-
Notifications
You must be signed in to change notification settings - Fork 45
Make UtEnumConstModel and UtClassRefModel reference models #414 #611
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
Conversation
19214b2 to
06e56ad
Compare
Damtev
left a comment
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you link this constant with org.utbot.engine.ResolverKt#NULL_ADDR somehow, please?
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.
What do you think about moving the constant from Resolver into Api.kt?
utbot-framework/src/main/kotlin/org/utbot/engine/CollectionWrappers.kt
Outdated
Show resolved
Hide resolved
utbot-framework/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt
Outdated
Show resolved
Hide resolved
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt
Outdated
Show resolved
Hide resolved
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt
Outdated
Show resolved
Hide resolved
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt
Show resolved
Hide resolved
utbot-sample/src/main/java/org/utbot/examples/enums/ComplexEnumExamples.java
Show resolved
Hide resolved
3de411a to
84c66ce
Compare
sergeypospelov
left a comment
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like these imports are redundant.
54af0a3 to
410613a
Compare
|
Updated |
f4959aa to
e29923f
Compare
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.
* 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
b11b184
Compare
Make 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