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

Fix: Constant initialization in the Dafny-to-Rust code generator #5837

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MikaelMayer
Copy link
Member

Fixes #5833

Description

There are now three kinds of generated fields:

  • Internal constant fields (internal const): They have the same type and assigned and read using regular field read and field update.
  • Mutable fields (var): They are wrapped with ::dafny_runtime::Field<...> to avoid any soundness issue, and use the wrappers read_field and modify_field to read and modify them.
  • Constant fields (const): They are called with a function call with zero argument.

Before this PR, only the last two were implemented, which lead to issues when trying to assign the default value of a class constant.
This issue was not captured because the test started to fail but since it's was marked %testForEachCompiler and these tests are ignored in the CI, we did not detect it.

How has this been tested?

Updated the file classes.dfy. All other tests in comp/rust should pass.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@MikaelMayer MikaelMayer marked this pull request as ready for review October 16, 2024 19:15
@MikaelMayer MikaelMayer enabled auto-merge (squash) October 16, 2024 20:53
Copy link
Member

@robin-aws robin-aws left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix. As a follow up can we re-enable the Rust backend in %testDafnyForEachCompiler?

Copy link
Member

Choose a reason for hiding this comment

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

Intentional?

Have we been announcing bug fixes like this while the Rust code generator isn't fully supported yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer to leave it quiet too.

@@ -323,6 +323,7 @@ module {:extern "DAST"} DAST {
UnboundedIntRange(start: Expression, up: bool) |
Quantifier(elemType: Type, collection: Expression, is_forall: bool, lambda: Expression)

datatype FieldMutability = ConstantField | MutableField | InternalConstantField
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
datatype FieldMutability = ConstantField | MutableField | InternalConstantField
datatype FieldMutability = ConstantField | ClassMutableField | ClassConstantField

I didn't understand "InternalConstantField" until I looked at the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

ClassMutableField is ok, but the last one is really internal, so it should be ClassInternalConstantField, all right?

} else {
r := read_field_macro.Apply1(r); // Already contains a clone.
assert fieldMutability.MutableField?;
Copy link
Member

@robin-aws robin-aws Oct 16, 2024

Choose a reason for hiding this comment

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

Wouldn't a match statement be a little cleaner? (Instead of the chained if)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

constant assignment fails in Rust
2 participants