-
Notifications
You must be signed in to change notification settings - Fork 273
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
Feat: Rust operators and immutable collections #5081
Conversation
Dafny clone more generic Test for native array pointers
Ensure formatting only consider the opened file
Added Rust Fun AST
Functions in Rust
# Conflicts: # Source/DafnyCore/AST/Grammar/IndentationFormatter.cs # Source/DafnyCore/AST/Grammar/TokenNewIndentCollector.cs
Added multisets
Pretty-print the ! (==) and all the other operators are now supported
Rust AST for many expressions Detection of unimplemented features Code review Rewriting of a few Rust AST to make them more appealing Support for operators, it compiles
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.
Okay I'm ready to ship, with just two blocking comments:
- The remaining
compileName += $"({why})";
without failing compilation (and any others I didn't catch), since that means emitting bad code without failing the pipeline by default. - The point about using
options.Get
instead of adding another flag to the legacy options implementation (weaker but should be a quick fix).
I still don't feel like I've give the core code generation logic in Dafny enough of a review, but I think that can be backfilled before marking the backend stable.
if (!isTpSupported(typeArg.Formal, out var why)) { | ||
compileName += $"({why})"; |
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.
Another case of emitting bad code without emitUncompilableCode
.
I'd strongly suggest using compiler.AddUnsupported
instead now that you have it, so it's harder to make this mistake.
cargo.toml | ||
``` | ||
|
||
With `dafny translate`, only `program-rust/src/program.rs` is emitted. |
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.
Just FYI, note this is debatably not correct: #5203
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.
Yep indeed, will have to fix it separately.
- Function parameters always take primitive types without borrowing them (`bool`, `u32`, etc.) | ||
- Function parameters always borrows variables of other types (`DafnyString`, structs, etc.), because | ||
borrowing is always cheaper than cloning for non-Copy types. | ||
Open question: There are at least two more alternatives make |
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.
Fragment?
@@ -11,14 +11,17 @@ namespace Microsoft.Dafny.Compilers; | |||
|
|||
public abstract class DafnyExecutableBackend : ExecutableBackend { | |||
|
|||
protected virtual bool PreventShadowing => true; | |||
protected virtual bool SupportsUncompilableCode => true; |
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.
nit: reads like "can compile uncompilable code" but I think we want a shorter version of "supports outputting partial code for programs that have uncompilable code"
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.
Renamed to CanEmitUncompilableCode
Source/DafnyCore/DafnyOptions.cs
Outdated
@@ -360,6 +360,7 @@ public enum ContractTestingMode { | |||
public int DeprecationNoise = 1; | |||
public bool VerifyAllModules = false; | |||
public bool SeparateModuleOutput = false; | |||
public bool EmitUncompilableCode { get; set; } |
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.
options.Get(CommonOptionBag.EmitUncompilableCode)
is the incantation you're looking for. :)
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.
🚀 🦀
Rocket craaaaaaaaab, burning out his fumes out here alone...
…)" This reverts commit 3e38580.
This reverts commit 3e38580 to fix failing nightly: https://github.com/dafny-lang/dafny/actions/runs/8868313153 --------- Co-authored-by: Fabio Madge <fmadge@amazon.com>
### Description This PR implements most immutable types in Dafny (Sequence, Set, Multiset, Map) and implements most if not all operators on them. It also sets an architecture that can now be relied on. List of features in this PR: - More comprehensive Rust AST, precedence and associativity to render parentheses - The Rust compiler no longer crash when not in /runAllTests, but emits invalid code. It makes it possible to see which features are missing by searching for `<i>` in the generated code. - Made verification of GenExpr less brittle - Previous PR review comments - Ability to use shadowed identifiers to avoid numbers in names. Rust has the same rules as Dafny for shadowing, and I will continue to monitor cases where semantics might differ. ### How has this been tested? I added an integration test for compiling Dafny to Rust, and I added unit tests for the runtime in Rust *All tests for each compiler now have a `.rs.check` if they fail.*. <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small> --------- Co-authored-by: Robin Salkeld <salkeldr@amazon.com>
This PR is a replay of #5081 after fixing the issue with the paths too long for Windows, so it should no longer break the CI. ### Description This PR implements most immutable types in Dafny (Sequence, Set, Multiset, Map) and implements most if not all operators on them. It also sets an architecture that can now be relied on. List of features in this PR: - More comprehensive Rust AST, precedence and associativity to render parentheses - The Rust compiler no longer crash when not in /runAllTests, but emits invalid code. It makes it possible to see which features are missing by searching for `<i>` in the generated code. - Made verification of GenExpr less brittle - Previous PR review comments - Ability to use shadowed identifiers to avoid numbers in names. Rust has the same rules as Dafny for shadowing, and I will continue to monitor cases where semantics might differ. ### How has this been tested? I added an integration test for compiling Dafny to Rust, and I added unit tests for the runtime in Rust *All tests for each compiler now have a `.rs.check` if they fail.*. <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small> --------- Co-authored-by: Robin Salkeld <salkeldr@amazon.com>
Description
This PR implements most immutable types in Dafny (Sequence, Set, Multiset, Map) and implements most if not all operators on them. It also sets an architecture that can now be relied on.
List of features in this PR:
<i>
in the generated code.How has this been tested?
I added an integration test for compiling Dafny to Rust, and I added unit tests for the runtime in Rust
All tests for each compiler now have a
.rs.check
if they fail..By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.