Skip to content

Feat: Add --rust-module-name to specify a module name #5747

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

Merged
merged 18 commits into from
Sep 16, 2024

Conversation

MikaelMayer
Copy link
Member

@MikaelMayer MikaelMayer commented Sep 4, 2024

Fixes partially #5641

This PR adds --rust-module-name so that all absolute paths from crate insert the given module name after "crate" if the option is provided.

Description

I could have made it a boolean option since it should match the name of the generated file, but by consistency with other backends, I made it so that the option accepts any string. Let me know if you think a boolean would be better.

How has this been tested?

  • A test verifies that in the generated source code, the provided module name is correctly inserted.

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

@MikaelMayer MikaelMayer changed the title Fix 5641 rust module name Feat: Add --rust-module-name to specify a module name Sep 4, 2024
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.

Implementation LGTM, but would love a test case to verify what this unlocks.

@@ -1675,7 +1675,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler {
ASSIGNED_PREFIX + "_" + rustName
}

datatype ObjectType = RawPointers | RcMut
datatype PointerType = Raw | RcMut
datatype CharType = UTF16 | Unicode
Copy link
Member

Choose a reason for hiding this comment

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

nit: "Unicode" is too vague to be much help, consider UTF32 instead

Copy link
Member

Choose a reason for hiding this comment

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

Would it be too much to ask for a test case of a manually-written Rust crate, with manually-written Rust code and a Cargo.toml, where you use dafny translate to add additional code under a given --rust-module-name, and use cargo test to verify that all works?

That's the killer application of this option by itself: not forcing the output of Dafny to be the top level namespace, and enabling incremental adoption of Dafny into an existing Rust project!

Copy link
Member Author

Choose a reason for hiding this comment

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

Test written. I removed the other one since it was obsolete

@MikaelMayer MikaelMayer enabled auto-merge (squash) September 13, 2024 16:05
Copy link
Member

Choose a reason for hiding this comment

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

Love it!

@MikaelMayer MikaelMayer merged commit 5a42b5a into master Sep 16, 2024
22 checks passed
@MikaelMayer MikaelMayer deleted the fix-5641-rust-module-name branch September 16, 2024 17:03
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.

2 participants