Skip to content
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

Simple ADTs with a single constructor are records #1146

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

Halbaroth
Copy link
Collaborator

@Halbaroth Halbaroth commented Jun 17, 2024

This PR fixes a bug in D_cnf that have been exposed by #1130. Before merging Enum into ADT the situation was as follows:

  • simple ADT with several constructors and with at least one payload was sent to the Adt theory
  • simple ADT with several constructors but no payload was sent to Enum theory
  • simple ADT with a single constructor was sent to the Record theory.

The last corner case includes a corner corner case: an ADT with a single constructor without payload (so basically the unit type with an extra step...)

The D_cnf included a bug. It produced single constructors without payload of type ADT instead of type record but the check done in is_mine_symb prevented from sending it to Adt. As I removed this check, we got an assert on the following input:

(set-logic ALL)
(declare-datatype t ((Record)))
(define-fun a () t Record)
(check-sat)

After this patch, the situation is as follows:

  • simple ADT with several constructors is sent to the Adt theory
  • simple ADT with only one constructor is sent to the Record theory
  • mutually recursive ADT whose all the types are record is sent to the Record theory

This PR fixes a bug in `D_cnf` that have been exposed by OCamlPro#1130.
Before merging `Enum` into `ADT` the situation was as follows:
- simple ADT with several constructors and with at least one payload
  was sent to the `Adt` theory
- simple ADT with several constructors but no payload was sent to `Enum` theory
- simple ADT with a single constructor was sent to the `Record` theory.

The last corner case includes a corner corner case:
An ADT with a single constructor without payload (so basically the unit type
with an extra step...)

The `D_cnf` included a bug. It produced single constructors without
payload of type ADT instead of type record but the check done in
`is_mine_symb` prevented from sending it to `Adt`. As I removed this
check, we got an assert on the following input:
```smt2
(set-logic ALL)
(declare-datatype t ((Record)))
(define-fun a () t Record)
(check-sat)
```

After this patch, the situation is as follows:
- simple ADT with several constructors is sent to the `Adt` theory
- simple ADT with only one constructor is sent to the `Record` theory
- mutually recursive ADT whose all the types are record is sent to the
  `Record` theory
@Halbaroth Halbaroth added the bug label Jun 17, 2024
@Halbaroth Halbaroth added this to the 2.6.0 milestone Jun 17, 2024
@Halbaroth Halbaroth requested a review from hra687261 June 17, 2024 08:08
Comment on lines +978 to +981
| Tunit ->
E.void
| ty ->
Fmt.failwith "unexpected type %a@." Ty.print ty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test that shows that Tunit is used? And that we crash if we don't match it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2000 regressions on ae-format without this case, so yes, we have tests :)
Actually the builtin unit type of Dolmen is an ADT but a distinct builtin type Tunit in Alt-Ergo. It's a corner corner corner case...

I tested this PR on ae-format and now there is no regression anymore ;)

Copy link
Collaborator Author

@Halbaroth Halbaroth Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a unit test to catch unit (sic) case

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, I removed the Ty.Tunit type of AE in #1148, so this corner case disappears.

@Halbaroth Halbaroth merged commit 2fc8d60 into OCamlPro:next Jun 18, 2024
14 checks passed
Halbaroth added a commit to Halbaroth/alt-ergo that referenced this pull request Jul 24, 2024
* Simple ADTs with a single constructor are records

This PR fixes a bug in `D_cnf` that have been exposed by OCamlPro#1130.
Before merging `Enum` into `ADT` the situation was as follows:
- simple ADT with several constructors and with at least one payload
  was sent to the `Adt` theory
- simple ADT with several constructors but no payload was sent to `Enum` theory
- simple ADT with a single constructor was sent to the `Record` theory.

The last corner case includes a corner corner case:
An ADT with a single constructor without payload (so basically the unit type
with an extra step...)

The `D_cnf` included a bug. It produced single constructors without
payload of type ADT instead of type record but the check done in
`is_mine_symb` prevented from sending it to `Adt`. As I removed this
check, we got an assert on the following input:
```smt2
(set-logic ALL)
(declare-datatype t ((Record)))
(define-fun a () t Record)
(check-sat)
```

After this patch, the situation is as follows:
- simple ADT with several constructors is sent to the `Adt` theory
- simple ADT with only one constructor is sent to the `Record` theory
- mutually recursive ADT whose all the types are record is sent to the
  `Record` theory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants