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

Chore: Ordering of modules now deterministic in compiled code #5684

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2961,6 +2961,12 @@ protected override void EmitSingleValueGenerator(Expression e, bool inLetExprBod
AddUnsupportedFeature(e.Tok, Feature.ExactBoundedPool);
}

protected override void OrganizeModules(Program program, out List<ModuleDefinition> modules) {
modules = program.CompileModules.ToList();
modules.Sort((a, b) =>
String.Compare(a.FullDafnyName, b.FullDafnyName, StringComparison.Ordinal));
}

protected override void EmitHaltRecoveryStmt(Statement body, string haltMessageVarName, Statement recoveryBody, ConcreteSyntaxTree wr) {
TrStmt(body, wr);
}
Expand Down
Copy link
Member

Choose a reason for hiding this comment

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

Clever test!

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// NONUNIFORM: Test of the Rust compiler to ensure it emits modules in a deterministic order.
// RUN: %baredafny translate rs "%s" > "%t"
// RUN: %OutputCheck --file-to-check "%S/moduleordering-rust/src/moduleordering.rs" "%s"
// CHECK-L: pub mod A {
// CHECK-L: pub mod B {
// CHECK-L: pub mod C {
// CHECK-L: pub mod D {
// CHECK-L: pub mod E {
// CHECK-L: pub mod F {
// CHECK-L: pub mod G {
// CHECK-L: pub mod H {

module B { const X := "B" }
module D { import B const X := B.X }
module C { import A const X := A.X }
module E { import C const X := C.X }
module A { import G const X := G.X }
module G { const X := "G" }
module F { const X := "F" }
module H { const X := "H" }
Loading