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
robin-aws
left a comment
There was a problem hiding this comment.
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.Getinstead 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.
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.
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 |
| public abstract class DafnyExecutableBackend : ExecutableBackend { | ||
|
|
||
| protected virtual bool PreventShadowing => true; | ||
| protected virtual bool SupportsUncompilableCode => true; |
There was a problem hiding this comment.
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.
Renamed to CanEmitUncompilableCode
| public int DeprecationNoise = 1; | ||
| public bool VerifyAllModules = false; | ||
| public bool SeparateModuleOutput = false; | ||
| public bool EmitUncompilableCode { get; set; } |
There was a problem hiding this comment.
options.Get(CommonOptionBag.EmitUncompilableCode) is the incantation you're looking for. :)
robin-aws
left a comment
There was a problem hiding this comment.
🚀 🦀
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.checkif they fail..By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.