From cca1c96620b56388a2032769a30d07d62c779051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Mayer?= Date: Mon, 24 Feb 2025 09:30:07 -0600 Subject: [PATCH 1/2] Fixes: Rust supports overriding traits (#5948) ### Description The PR https://github.com/dafny-lang/dafny/pull/5940 defined a preliminary support for value traits. This PR fixes everything that encompasses value traits and newtypes. Here is the list of fixes. * Fix to support functions declared in a trait and implemented in another trait * Fix to support for equality in type parameters and conditional equality support for datatypes. * Fix to support constants in datatypes * Fix to support constants in traits * Fix to support back/forth conversions between &self and the underlying type * Fix to ensure we don't support coercions where it's not possible (that caused compilation errors for Rust and it's behind the discovery of soundness issue #5972) * Fix support of equality for newtypes (that caused compilation errors for Rust and it's behind the discovery of soundness issue #5978) * Fix to support type bounds in type parameters * Fix to support newtypes on booleans * Fix to support correct borrowing of type arguments in methods when the method instantiate a trait method which always borrows the arguments with the type parameter * Fix to support static constants in datatypes, including type parameters * Fix to support type parameters in static functions * Fix to ensure type parameter equality is correctly generated * Fix to support downcast from one value trait to another value trait of the same hierarchy (needed to change the resolver to record all such traits) * Fix to support the enclosing module name in externs Also some enhancements * Unification of extern semantics: Remove the error message about `{:extern}` on types requiring a hint when it can simply take the Dafny name, like for modules and classes. * `DafnyCodeGenerator.GenType` now caches its result to avoid exponential computations I also updated the documentation regarding the use of externs ### How has this been tested? * All the tests of comp/rust/traits-datatypes.dfy and comp/rust/small/* were not passing before this PR, and now they are. * The way to downcast traits from one to the other is tested in the test/mod.rs of the runtime. 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). --- .../FactorPathsOptimizationTest.cs | 2 +- .../AST/TypeDeclarations/Declaration.cs | 27 +- .../AST/TypeDeclarations/TraitDecl.cs | 78 + Source/DafnyCore/Backends/Dafny/AST.dfy | 143 +- Source/DafnyCore/Backends/Dafny/ASTBuilder.cs | 77 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 327 +- Source/DafnyCore/Backends/GeneratorErrors.cs | 6 - .../Rust/Dafny-compiler-rust-definitions.dfy | 367 +- .../Rust/Dafny-compiler-rust-rast.dfy | 123 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 921 ++- Source/DafnyCore/Backends/Rust/RustBackend.cs | 6 +- .../Backends/Rust/RustCodeGenerator.cs | 14 + .../SinglePassCodeGenerator.cs | 93 +- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 927 ++- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 5223 +++++++++-------- .../DafnyCompilerRustUtils.cs | 14 +- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 177 +- .../FactorPathsOptimization.cs | 12 +- Source/DafnyCore/GeneratedFromDafny/RAST.cs | 459 +- Source/DafnyCore/Resolver/ModuleResolver.cs | 12 +- .../Resolver/TypeCharacteristicChecker.cs | 17 +- .../DafnyRuntimeRustTest/Cargo.lock | 14 - Source/DafnyRuntime/DafnyRuntimeRust/Makefile | 2 +- .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 27 +- .../DafnyRuntimeRust/src/system/mod.rs | 818 ++- .../DafnyRuntimeRust/src/tests/mod.rs | 168 +- .../LitTest/comp/rust/arc/tokiouser.dfy | 2 +- .../LitTests/LitTest/comp/rust/arrays.dfy | 2 +- .../LitTest/comp/rust/arrays.dfy.expect | 2 +- .../LitTests/LitTest/comp/rust/autoinit.dfy | 2 +- .../LitTest/comp/rust/autoinit.dfy.expect | 5 +- .../LitTest/comp/rust/avoid_soundness_mut.dfy | 4 +- .../LitTests/LitTest/comp/rust/borrowing.dfy | 2 +- .../LitTests/LitTest/comp/rust/bymethod.dfy | 2 +- .../LitTest/comp/rust/cargoreleasefailure.dfy | 2 +- .../LitTests/LitTest/comp/rust/cargotest.dfy | 2 +- .../LitTest/comp/rust/classes-relax.dfy | 36 + .../comp/rust/classes-relax.dfy.expect | 3 + .../comp/rust/classes-relax.dfy.wrong.expect | 3 + .../LitTests/LitTest/comp/rust/classes.dfy | 20 +- .../LitTests/LitTest/comp/rust/constants.dfy | 2 +- .../LitTests/LitTest/comp/rust/continue.dfy | 4 +- .../LitTest/comp/rust/conversions.dfy | 2 +- .../LitTest/comp/rust/datatypes-impl.dfy | 2 +- .../LitTest/comp/rust/datatypes-scoping.dfy | 20 +- .../comp/rust/datatypes-scoping.dfy.expect | 4 +- .../LitTests/LitTest/comp/rust/datatypes.dfy | 4 +- .../LitTest/comp/rust/docstring.check | 3 +- .../LitTests/LitTest/comp/rust/docstring.dfy | 6 +- .../LitTests/LitTest/comp/rust/elephant.dfy | 2 +- .../comp/rust/externalclasses-errors.dfy | 2 +- .../LitTest/comp/rust/externalclasses.dfy | 18 +- .../comp/rust/externalclasses.dfy.expect | 2 +- .../LitTest/comp/rust/externalclasses.rs | 18 + .../LitTests/LitTest/comp/rust/lambda.dfy | 8 +- .../LitTest/comp/rust/lambda.dfy.expect | 3 + .../LitTests/LitTest/comp/rust/loops.dfy | 2 +- .../LitTest/comp/rust/loops.dfy.expect | 2 +- .../LitTests/LitTest/comp/rust/mapsubsets.dfy | 2 +- .../LitTests/LitTest/comp/rust/methods.dfy | 2 +- .../LitTest/comp/rust/moduleordering.dfy | 2 +- .../LitTest/comp/rust/nestedmodules.dfy | 2 +- .../LitTest/comp/rust/newtype-set-comp.dfy | 2 +- .../LitTests/LitTest/comp/rust/newtypes.dfy | 6 +- .../LitTest/comp/rust/newtypesrefresh.dfy | 2 +- .../LitTest/comp/rust/nomaybeplacebos.dfy | 2 +- .../LitTests/LitTest/comp/rust/operators.dfy | 2 +- .../LitTest/comp/rust/reserved-names.dfy | 2 +- .../LitTest/comp/rust/small/01-hash.dfy | 22 + .../comp/rust/small/01-hash.dfy.expect | 3 + .../LitTest/comp/rust/small/02-binary.dfy | 17 + .../comp/rust/small/02-binary.dfy.expect | 3 + .../comp/rust/small/03-methodnamed.dfy | 29 + .../comp/rust/small/03-methodnamed.dfy.expect | 3 + .../LitTest/comp/rust/small/04-mismatched.dfy | 28 + .../comp/rust/small/04-mismatched.dfy.expect | 2 + .../LitTest/comp/rust/small/05-coerce.dfy | 36 + .../comp/rust/small/05-coerce.dfy.expect | 3 + .../comp/rust/small/06-type-bounds.dfy | 45 + .../comp/rust/small/06-type-bounds.dfy.expect | 3 + .../rust/small/07-instantiated-methods.dfy | 20 + .../small/07-instantiated-methods.dfy.expect | 3 + .../08-not-all-trait-items-implemented.dfy | 52 + ...not-all-trait-items-implemented.dfy.expect | 3 + .../comp/rust/small/09-trait-method.dfy | 11 + .../rust/small/10-type-parameter-equality.dfy | 59 + .../10-type-parameter-equality.dfy.expect | 3 + .../LitTests/LitTest/comp/rust/strings.dfy | 4 +- .../LitTest/comp/rust/subsetconstraints.dfy | 2 +- .../LitTests/LitTest/comp/rust/tests.dfy | 4 +- .../LitTest/comp/rust/traits-datatypes.dfy | 131 +- .../comp/rust/traits-datatypes.dfy.expect | 8 +- .../LitTests/LitTest/comp/rust/traits.dfy | 3 +- .../LitTest/comp/rust/traits.dfy.expect | 2 +- .../rust/translate-additional/more_dafny.dfy | 2 +- .../LitTests/LitTest/comp/rust/type-test.dfy | 4 +- .../LitTest/dafny0/Tooltips.dfy.expect | 2 +- .../LitTest/git-issues/git-issue-5644.dfy | 3 +- .../git-issues/git-issue-5644.dfy.expect | 5 +- ...stentCompilerBehavior.dfy.testdafny.expect | 7 - ...tBeyondVerifierExpect.dfy.testdafny.expect | 7 - .../integration- rust/IntegrationRust.md | 45 +- docs/HowToFAQ/Errors-Compiler.md | 9 - docs/HowToFAQ/Errors-Compiler.template | 9 - 104 files changed, 7132 insertions(+), 3729 deletions(-) create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs b/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs index b0e543c04a5..82b0a7ed54e 100644 --- a/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs +++ b/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs @@ -40,7 +40,7 @@ public static void TestApply() _3_std__any__Any = (((RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("std"))).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any")); RAST._IType _4_Any; _4_Any = RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Any")); - FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(RAST.__default.NoDoc, Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_0_T__Decl), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), (_3_std__any__Any).AsType())))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_0_T__Decl), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (_3_std__any__Any).AsType(), ((((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("test"))).AsType()).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_StructDecl(RAST.Struct.create(RAST.__default.NoDoc, Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_1_T__Decl__simp), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), _4_Any)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), _4_Any, (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))); + FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(RAST.__default.NoDoc, Dafny.Sequence.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_0_T__Decl), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), (_3_std__any__Any).AsType())))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_0_T__Decl), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (_3_std__any__Any).AsType(), ((((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("test"))).AsType()).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_StructDecl(RAST.Struct.create(RAST.__default.NoDoc, Dafny.Sequence.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_1_T__Decl__simp), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), _4_Any)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), _4_Any, (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))); FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject"))).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject")))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("UpcastObject"))).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))); FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummy"), (_3_std__any__Any).AsType(), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("doit"), Std.Wrappers.Option.create_Some((RAST.__default.RcType).Apply1(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("unknown")))), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("something"))).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_DynType((RAST.__default.std__default__Default).AsType())))).Apply(Dafny.Sequence.FromElements(RAST.__default.std__default__Default__default, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rd!"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("obj"))))))), RAST.Expr.create_TypeAscription(RAST.Expr.create_ExprFromType(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyString"))).AsType()), ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType"))).AsType()))))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), RAST.__default.RcPath)), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), RAST.__default.std__default__Default)), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rd")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyString")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummy"), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Any")), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("doit"), Std.Wrappers.Option.create_Some((RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Rc"))).Apply1(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("unknown")))), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("something"))).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Default")))))).Apply(Dafny.Sequence.FromElements(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Default"))).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply(Dafny.Sequence.FromElements()), (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("rd!"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("obj"))))))), RAST.Expr.create_TypeAscription(RAST.Expr.create_ExprFromType(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("DafnyString"))), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("DafnyType"))))))))); FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.FromElements(), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Something")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummyExtern"), (((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("anothermodule"))).MSel(Dafny.Sequence.UnicodeFromString("Something"))).AsType(), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing")))), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummyIntern"), (((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("Something"))).AsType(), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing"))))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.FromElements(), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Something")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummyExtern"), (((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("anothermodule"))).MSel(Dafny.Sequence.UnicodeFromString("Something"))).AsType(), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing")))), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummyIntern"), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Something")), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing"))))))); diff --git a/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs b/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs index e6d43aa65fd..6d9fa21a33d 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs @@ -111,17 +111,42 @@ public bool IsVisibleInScope(VisibilityScope scope) { protected string? sanitizedName; public virtual string SanitizedName => sanitizedName ??= NonglobalVariable.SanitizeName(Name); + protected string enclosingModuleName; // Computed at the same time as compileName + protected string? compileName; public virtual string GetCompileName(DafnyOptions options) { if (compileName == null) { - this.IsExtern(options, out _, out compileName); + this.IsExtern(options, out var possibleEnclosingModuleName, out compileName); + if (!IsCompiled) { + enclosingModuleName = possibleEnclosingModuleName; + } + if (this is TopLevelDecl topDecl) { + enclosingModuleName ??= topDecl.EnclosingModuleDefinition.GetCompileName(options); + } + compileName ??= SanitizedName; } return compileName; } + public bool IsCompiled { + get { + var compile = true; + return !Attributes.ContainsBool(Attributes, "compile", ref compile) || compile; + } + } + + public string GetQualificationName(DafnyOptions options) { + if (compileName == null) { + GetCompileName(options); // Sets the enclosing module name if defined by externs. + return enclosingModuleName; + } + + return enclosingModuleName; + } + public Attributes? Attributes; // readonly, except during class merging in the refinement transformations and when changed by Compiler.MarkCapitalizationConflict Attributes? IAttributeBearingDeclaration.Attributes { get => Attributes; diff --git a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs index 2339e304b4a..900d15b19d4 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.Dafny.Auditor; using System.Diagnostics.Contracts; +using System.Linq; namespace Microsoft.Dafny; @@ -9,6 +10,8 @@ public class TraitDecl : ClassLikeDecl { public bool IsParent { set; get; } public override bool AcceptThis => true; + [FilledInDuringResolution] public List TraitDeclsCanBeDowncastedTo = new(); + internal void SetUpAsReferenceType(bool isReferenceType) { // Note, it's important to set .NonNullTypeDecl first, before calling NewSelfSynonym(), since the latter will look at the former. Contract.Assert(NonNullTypeDecl == null); // SetUpAsReferenceType should be called only once @@ -41,4 +44,79 @@ public override IEnumerable Assumptions(Declaration decl) { yield return new Assumption(this, Origin, AssumptionDescription.HasTerminationFalseAttribute); } } + + // Given a trait declaration, returns the list of traits that this trait can downcast to, + // using its type parameters only (no run-time information about the type available) + // Used in backends that apply monomorphization + public List DowncastableSubTraitsIfMonomorphized() { + var downcastableTraits = new List(); + foreach (var subTrait in TraitDeclsCanBeDowncastedTo) { + // Recovers which of the parent traits of the subTraits is the current trait declaration + var parentTrait = subTrait.Traits.FirstOrDefault(t => t.AsTraitType == this); + Type downcastType = null; + if (parentTrait is UserDefinedType { TypeArgs: var parentTypeArguments } && + CanDowncastIfMonomorphized(parentTypeArguments, subTrait, ref downcastType)) { + downcastableTraits.Add(downcastType); + } + } + + return downcastableTraits; + } + + /// When traits generics are monomorphized, i.e. they are simply instantiated for every type for which they are used, + /// it becomes impossible to express some downcasts in the target language. For example, + /// trait SuperTrait {} + /// trait SubTrait extends SuperTrait {} + /// Although it's possible to cast a SubTrait to a SuperTrait, the other direction is not possible + /// if traits are monomorphized, because there could be infinitely new traits depending on the generic argument, + /// and traits only build a finite virtual dispatch table. + /// This algorithm determines if there are enough type parameters in common so that the downcast can be known + /// no matter what + public bool CanDowncastIfMonomorphized( + List parentTypeArguments, TraitDecl subTrait, ref Type downcastType) { + // Algorithm: + // trait Sub extends Parent where trait Parent + // Foreach type parameter in the parent TPi + // if PTi is some TCj, store the mapping TCj => TPi. We need only to store the first of such mapping + // If PTi is anything else, ok + // End of the loop: if not all children type parameters were found, cancel + // build the type Sub by iterating on the type parameters TC. + Contract.Assert(TypeArgs.Count == parentTypeArguments.Count); + var mapping = new Dictionary(); + for (var i = 0; i < TypeArgs.Count; i++) { + var TP = TypeArgs[i]; + var maybeTc = parentTypeArguments[i]; + if (maybeTc is UserDefinedType { ResolvedClass: TypeParameter maybeTc2 }) { + if (subTrait.TypeArgs.Contains(maybeTc2) && !mapping.ContainsKey(maybeTc2)) { + mapping.Add(maybeTc2, new UserDefinedType(TP)); + } + } + } + + var allTypeParametersCovered = subTrait.TypeArgs.TrueForAll( + tp => mapping.ContainsKey(tp)); + if (allTypeParametersCovered) { + // Now we need to make sure that type characteristics are compatible + var typeArgs = subTrait.TypeArgs.Select(tp => mapping[tp]).ToList(); + for (var i = 0; i < typeArgs.Count; i++) { + var downcastTypeParam = subTrait.TypeArgs[i]; + var parentType = typeArgs[i]; + if (!IsCompatibleWith(parentType, downcastTypeParam)) { + return false; + } + } + + var subTraitTypeDowncastable = + new UserDefinedType(Token.NoToken, subTrait.Name, subTrait, typeArgs); + downcastType = subTraitTypeDowncastable; + return true; + } + + return false; + } + + private static bool IsCompatibleWith(Type type, TypeParameter typeParameter) { + return (typeParameter.Characteristics.EqualitySupport == TypeParameter.EqualitySupportValue.Unspecified || + type.SupportsEquality) && typeParameter.TypeBounds.TrueForAll(t => type.IsSubtypeOf(t, false, true)); + } } \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index abf6b485f67..6ec80c938d3 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -142,6 +142,102 @@ module {:extern "DAST"} DAST { case _ => false } } + + function GetGeneralTraitType(): (r: Type) + requires IsGeneralTrait() + ensures r.UserDefined? && r.resolved.kind == ResolvedTypeBase.Trait(GeneralTrait) + { + match this { + case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => + match typeKind { + case SynonymType(typ) => + typ.GetGeneralTraitType() + case _ => this + } + } + } + + predicate IsClassOrObjectTrait() { + match this { + case UserDefined(ResolvedType(_, _, base, _, _, _)) => + base.Class? || (base.Trait? && base.traitType.ObjectTrait?) + case _ => false + } + } + + predicate IsDatatype() { + match this { + case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => + match typeKind { + case SynonymType(typ) => + typ.IsDatatype() + case Datatype(_, _) => true + case _ => false + } + case _ => false + } + } + + function GetDatatypeType(): (r: Type) + requires IsDatatype() + ensures r.UserDefined? && r.resolved.kind.Datatype? + { + match this { + case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => + match typeKind { + case SynonymType(typ) => + typ.GetDatatypeType() + case _ => this + } + } + } + + // Works well without diamond inheritance. If the case arise, we will need to memoize this function + // or ensure extendedTypes contains all supertypes. + predicate Extends(other: Type) + ensures this.Extends(other) ==> other < this + { + match this { + case UserDefined(ResolvedType(_, _, _, _, _, extendedTypes)) => + other in extendedTypes || exists i | 0 <= i < |extendedTypes| :: extendedTypes[i].Extends(other) + case _ => false + } + } + + function RemoveSynonyms(): Type { + match this { + case UserDefined(ResolvedType(path, typeArgs, typeKind, attributes, properMethods, extendedTypes)) => + match typeKind { + case SynonymType(typ) => + typ.RemoveSynonyms() + case _ => + var newtypeArgs := seq(|typeArgs|, i requires 0 <= i < |typeArgs| => typeArgs[i].RemoveSynonyms()); + UserDefined(ResolvedType(path, newtypeArgs, typeKind, attributes, properMethods, extendedTypes)) + } + case Tuple(arguments) => + Type.Tuple(Std.Collections.Seq.Map( + t requires t in arguments => t.RemoveSynonyms(), arguments)) + case Array(element, dims) => + Type.Array(element.RemoveSynonyms(), dims) + case Seq(element) => + Type.Seq(element.RemoveSynonyms()) + case Set(element) => + Type.Set(element.RemoveSynonyms()) + case Multiset(element) => + Type.Multiset(element.RemoveSynonyms()) + case Map(key, value) => + Type.Map(key.RemoveSynonyms(), value.RemoveSynonyms()) + case SetBuilder(element) => + Type.SetBuilder(element.RemoveSynonyms()) + case MapBuilder(key, value) => + Type.MapBuilder(key.RemoveSynonyms(), value.RemoveSynonyms()) + case Arrow(args: seq, result: Type) => + Type.Arrow(Std.Collections.Seq.Map( + t requires t in args => t.RemoveSynonyms(), args), result.RemoveSynonyms()) + case Primitive(_) | Passthrough(_) | Object() | TypeArg(_) => + this + } + } } datatype Variance = @@ -149,11 +245,15 @@ module {:extern "DAST"} DAST { | Covariant | Contravariant - datatype TypeArgDecl = TypeArgDecl(name: Ident, bounds: seq, variance: Variance) + datatype TypeArgDecl = TypeArgDecl( + name: Ident, + bounds: seq, + info: TypeParameterInfo) datatype TypeArgBound = | SupportsEquality | SupportsDefault + | TraitBound(typ: Type) datatype Primitive = Int | Real | String | Bool | Char | Native @@ -172,13 +272,15 @@ module {:extern "DAST"} DAST { | NativeArrayIndex | BigInt | Bool + | Sequence + | Map | NoRange { predicate CanOverflow() { (U8? || I8? || U16? || I16? || U32? || I32? || U64? || I64? || U128? || I128?) && overflow } predicate HasArithmeticOperations() { - !Bool?// To change when newtypes will have sequences and sets as ranges. + !Bool? && !Map? && !Sequence? } } @@ -190,9 +292,14 @@ module {:extern "DAST"} DAST { | ObjectTrait() // Traits that extend objects with --type-system-refresh, all traits otherwise | GeneralTrait() // Traits that don't necessarily extend objects with --type-system-refresh + datatype TypeParameterInfo = + TypeParameterInfo(variance: Variance, necessaryForEqualitySupportOfSurroundingInductiveDatatype: bool) + + datatype EqualitySupport = Never | ConsultTypeArguments + datatype ResolvedTypeBase = | Class() - | Datatype(variances: seq) + | Datatype(equalitySupport: EqualitySupport, info: seq) | Trait(traitType: TraitType) | SynonymType(baseType: Type) | Newtype(baseType: Type, range: NewtypeRange, erase: bool) @@ -240,6 +347,7 @@ module {:extern "DAST"} DAST { typeParams: seq, traitType: TraitType, parents: seq, + downcastableTraits: seq, body: seq, attributes: seq) @@ -251,8 +359,11 @@ module {:extern "DAST"} DAST { ctors: seq, body: seq, isCo: bool, + equalitySupport: EqualitySupport, attributes: seq, - superTraitTypes: seq) + superTraitTypes: seq, + superTraitNegativeTypes: seq // Traits that one or more superTraits know they can downcast to, but the datatype does not. + ) datatype DatatypeDtor = DatatypeDtor( formal: Formal, @@ -270,7 +381,9 @@ module {:extern "DAST"} DAST { docString: string, typeParams: seq, base: Type, range: NewtypeRange, constraint: Option, - witnessStmts: seq, witnessExpr: Option, attributes: seq, + witnessStmts: seq, witnessExpr: Option, + equalitySupport: EqualitySupport, + attributes: seq, classItems: seq) datatype NewtypeConstraint = NewtypeConstraint(variable: Formal, constraintStmts: seq) @@ -303,11 +416,12 @@ module {:extern "DAST"} DAST { name: Name, typeParams: seq, params: seq, + inheritedParams: seq, body: seq, outTypes: seq, outVars: Option>) - datatype CallSignature = CallSignature(parameters: seq) + datatype CallSignature = CallSignature(parameters: seq, inheritedParams: seq) datatype CallName = CallName(name: Name, onType: Option, receiverArg: Option, receiverAsArgument: bool, signature: CallSignature) | @@ -362,6 +476,9 @@ module {:extern "DAST"} DAST { Concat() | Passthrough(string) + datatype SelectContext = + SelectContextDatatype | SelectContextGeneralTrait | SelectContextClassOrObjectTrait + datatype Expression = Literal(Literal) | Ident(name: VarName) | @@ -378,10 +495,10 @@ module {:extern "DAST"} DAST { SeqValue(elements: seq, typ: Type) | SetValue(elements: seq) | MultisetValue(elements: seq) | - MapValue(mapElems: seq<(Expression, Expression)>) | + MapValue(mapElems: seq<(Expression, Expression)>, domainType: Type, rangeType: Type) | MapBuilder(keyType: Type, valueType: Type) | - SeqUpdate(expr: Expression, indexExpr: Expression, value: Expression) | - MapUpdate(expr: Expression, indexExpr: Expression, value: Expression) | + SeqUpdate(expr: Expression, indexExpr: Expression, value: Expression, collectionType: Type, exprType: Type) | + MapUpdate(expr: Expression, indexExpr: Expression, value: Expression, collectionType: Type, exprType: Type) | SetBuilder(elemType: Type) | ToMultiset(Expression) | This() | @@ -392,7 +509,7 @@ module {:extern "DAST"} DAST { MapKeys(expr: Expression) | MapValues(expr: Expression) | MapItems(expr: Expression) | - Select(expr: Expression, field: VarName, fieldMutability: FieldMutability, isDatatype: bool, fieldType: Type) | + Select(expr: Expression, field: VarName, fieldMutability: FieldMutability, selectContext: SelectContext, isfieldType: Type) | SelectFn(expr: Expression, field: VarName, onDatatype: bool, isStatic: bool, isConstant: bool, arguments: seq) | Index(expr: Expression, collKind: CollKind, indices: seq) | IndexRange(expr: Expression, isArray: bool, low: Option, high: Option) | @@ -413,7 +530,11 @@ module {:extern "DAST"} DAST { ExactBoundedPool(of: Expression) | IntRange(elemType: Type, lo: Expression, hi: Expression, up: bool) | UnboundedIntRange(start: Expression, up: bool) | - Quantifier(elemType: Type, collection: Expression, is_forall: bool, lambda: Expression) + Quantifier(elemType: Type, collection: Expression, is_forall: bool, lambda: Expression) { + predicate IsThisUpcast() { + Convert? && value.This? && from.Extends(typ) + } + } // Since constant fields need to be set up in the constructor, // accessing constant fields is done in two ways: diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index 994e4ce30a1..24d24722d7d 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -166,9 +166,9 @@ public object Finish() { interface TraitContainer : Container { void AddTrait(Trait item); - public TraitBuilder Trait(string name, List typeParams, List parents, - ISequence<_IAttribute> attributes, string docString, _ITraitType traitType) { - return new TraitBuilder(this, name, docString, typeParams, parents, attributes, traitType); + public TraitBuilder Trait(string name, List typeParams, List parents, + ISequence<_IAttribute> attributes, string docString, _ITraitType traitType, List downcastableTraits) { + return new TraitBuilder(this, name, docString, typeParams, parents, attributes, traitType, downcastableTraits); } } @@ -179,16 +179,18 @@ class TraitBuilder : ClassLike { private readonly List parents; readonly List body = []; private ISequence<_IAttribute> attributes; - private string docString; - private _ITraitType traitType; + private readonly string docString; + private readonly _ITraitType traitType; + private readonly List downcastableTraits; - public TraitBuilder(TraitContainer parent, string name, string docString, List typeParams, List parents, ISequence<_IAttribute> attributes, _ITraitType traitType) { + public TraitBuilder(TraitContainer parent, string name, string docString, List typeParams, List parents, ISequence<_IAttribute> attributes, _ITraitType traitType, List downcastableTraits) { this.parent = parent; this.name = name; this.typeParams = typeParams; this.attributes = attributes; this.docString = docString; this.traitType = traitType; + this.downcastableTraits = downcastableTraits; this.parents = parents; } @@ -215,6 +217,7 @@ public object Finish() { Sequence.FromArray(typeParams.ToArray()), traitType, Sequence.FromArray(parents.ToArray()), + Sequence.FromArray(downcastableTraits.ToArray()), Sequence.FromArray(body.ToArray()), attributes) ); @@ -225,10 +228,11 @@ public object Finish() { interface NewtypeContainer : Container { void AddNewtype(Newtype item); - public NewtypeBuilder Newtype(string name, List typeParams, - DAST.Type baseType, NewtypeRange newtypeRange, Option constraint, List witnessStmts, DAST.Expression witness, - ISequence<_IAttribute> attributes, string docString) { - return new NewtypeBuilder(this, name, typeParams, newtypeRange, baseType, constraint, witnessStmts, witness, attributes, docString); + public NewtypeBuilder Newtype(string name, List typeParams, + DAST.Type baseType, NewtypeRange newtypeRange, Option constraint, + List witnessStmts, DAST.Expression witness, + ISequence<_IAttribute> attributes, string docString, _IEqualitySupport equalitySupport) { + return new NewtypeBuilder(this, name, typeParams, newtypeRange, baseType, constraint, witnessStmts, witness, attributes, docString, equalitySupport); } } @@ -244,11 +248,12 @@ class NewtypeBuilder : ClassLike { private ISequence<_IAttribute> attributes; private readonly List methods; private string docString; + private _IEqualitySupport equalitySupport; public NewtypeBuilder(NewtypeContainer parent, string name, List typeParams, NewtypeRange newtypeRange, DAST.Type baseType, Option constraint, List statements, DAST.Expression witness, - ISequence<_IAttribute> attributes, string docString) { + ISequence<_IAttribute> attributes, string docString, _IEqualitySupport equalitySupport) { this.parent = parent; this.name = name; this.typeParams = typeParams; @@ -259,6 +264,7 @@ public NewtypeBuilder(NewtypeContainer parent, string name, List ty this.witness = witness; this.attributes = attributes; this.docString = docString; + this.equalitySupport = equalitySupport; this.methods = []; } @@ -282,6 +288,7 @@ public object Finish() { this.witness == null ? Option.create_None() : Option.create_Some(this.witness), + equalitySupport, attributes, Sequence.FromArray(methods.ToArray()) )); @@ -341,9 +348,10 @@ public object Finish() { interface DatatypeContainer : Container { void AddDatatype(Datatype item); - public DatatypeBuilder Datatype(string name, string enclosingModule, List typeParams, - List ctors, bool isCo, ISequence<_IAttribute> attributes, string docString, List superTraitTypes) { - return new DatatypeBuilder(this, name, docString, enclosingModule, typeParams, ctors, isCo, attributes, superTraitTypes); + public DatatypeBuilder Datatype(string name, string enclosingModule, List typeParams, + List ctors, bool isCo, ISequence<_IAttribute> attributes, string docString, + List superTraitTypes, List superNegativeTraitTypes, _IEqualitySupport equalitySupport) { + return new DatatypeBuilder(this, name, docString, enclosingModule, typeParams, ctors, isCo, attributes, superTraitTypes, superNegativeTraitTypes, equalitySupport); } } @@ -355,11 +363,13 @@ class DatatypeBuilder : ClassLike { readonly List ctors; readonly bool isCo; readonly List body = []; - private ISequence<_IAttribute> attributes; - private string docString; - private List superTraitTypes; + readonly ISequence<_IAttribute> attributes; + readonly string docString; + readonly List superTraitTypes; + readonly List superNegativeTraitTypes; + private _IEqualitySupport equalitySupport; - public DatatypeBuilder(DatatypeContainer parent, string name, string docString, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes, List superTraitTypes) { + public DatatypeBuilder(DatatypeContainer parent, string name, string docString, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes, List superTraitTypes, List superNegativeTraitTypes, _IEqualitySupport equalitySupport) { this.parent = parent; this.name = name; this.docString = docString; @@ -369,6 +379,8 @@ public DatatypeBuilder(DatatypeContainer parent, string name, string docString, this.isCo = isCo; this.attributes = attributes; this.superTraitTypes = superTraitTypes; + this.superNegativeTraitTypes = superNegativeTraitTypes; + this.equalitySupport = equalitySupport; } public void AddMethod(DAST.Method item) { @@ -387,8 +399,9 @@ public object Finish() { Sequence.FromArray(typeParams.ToArray()), Sequence.FromArray(ctors.ToArray()), Sequence.FromArray(body.ToArray()), - this.isCo, attributes, - Sequence.FromArray(superTraitTypes.ToArray()) + this.isCo, equalitySupport, attributes, + Sequence.FromArray(superTraitTypes.ToArray()), + Sequence.FromArray(superNegativeTraitTypes.ToArray()) )); return parent; } @@ -405,9 +418,9 @@ public MethodBuilder Method(bool isStatic, bool hasBody, bool outVarsAreUninitFi ISequence<_IAttribute> attributes, string name, List typeArgs, - Sequence params_, + Sequence params_, Sequence inheritedParams, List outTypes, List> outVars) { - return new MethodBuilder(this, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, docString, attributes, name, typeArgs, params_, outTypes, outVars); + return new MethodBuilder(this, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, docString, attributes, name, typeArgs, params_, inheritedParams, outTypes, outVars); } public object Finish(); @@ -423,6 +436,7 @@ class MethodBuilder : StatementContainer { readonly ISequence> overridingPath; readonly List typeArgs; readonly Sequence params_; + readonly Sequence inheritedParams; readonly List outTypes; readonly List> outVars; readonly List body = []; @@ -437,9 +451,8 @@ public MethodBuilder( ISequence<_IAttribute> attributes, string name, List typeArgs, - Sequence params_, - List outTypes, List> outVars - ) { + Sequence params_, Sequence inheritedParams, + List outTypes, List> outVars) { this.parent = parent; this.isStatic = isStatic; this.hasBody = hasBody; @@ -453,6 +466,7 @@ public MethodBuilder( this.params_ = params_; this.outTypes = outTypes; this.outVars = outVars; + this.inheritedParams = inheritedParams; } public List ForkList() { @@ -483,6 +497,7 @@ public DAST.Method Build() { Sequence.UnicodeFromString(this.name), Sequence.FromArray(typeArgs.ToArray()), params_, + inheritedParams, Sequence.FromArray(builtStatements.ToArray()), Sequence.FromArray(outTypes.ToArray()), outVars != null ? Option>>.create_Some(Sequence>.FromArray(outVars.ToArray())) : Option>>.create_None() @@ -563,7 +578,7 @@ public TailRecursiveBuilder TailRecursive() { return ret; } - public CallStmtBuilder Call(ISequence<_IFormal> signature) { + public CallStmtBuilder Call(_ICallSignature signature) { var ret = new CallStmtBuilder(signature); AddBuildable(ret); return ret; @@ -966,9 +981,9 @@ class CallStmtBuilder : ExprContainer, BuildableStatement { List typeArgs = null; readonly List args = []; List> outs = null; - public readonly ISequence<_IFormal> Signature; + public readonly _ICallSignature Signature; - public CallStmtBuilder(ISequence<_IFormal> signature) { + public CallStmtBuilder(_ICallSignature signature) { this.Signature = signature; } @@ -1283,7 +1298,7 @@ BinOpBuilder BinOp(string op, Func signature) { + CallExprBuilder Call(_ICallSignature signature) { var ret = new CallExprBuilder(signature); AddBuildable(ret); return ret; @@ -1468,9 +1483,9 @@ class CallExprBuilder : ExprContainer, BuildableExpr { readonly List args = []; List> outs = null; - public ISequence<_IFormal> Signature { get; } + public _ICallSignature Signature { get; } - public CallExprBuilder(ISequence<_IFormal> signature) { + public CallExprBuilder(_ICallSignature signature) { Signature = signature; } diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 9f33fd0862f..4182dc792dd 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -22,7 +22,12 @@ class DafnyCodeGenerator : SinglePassCodeGenerator { public string internalFieldPrefix; public bool preventShadowing; - protected override bool InstanceMethodsAllowedToCallTraitMethods => false; + // In a language like Rust, trait methods with bodies don't need to be called by + // the class or datatype extending it with overriding functions or methods that call into the trait. + // However, if a method is declared in a trait A, and another trait B implements it, + // then any class or datatype extending that last trait B must also explicitly implement the first trait A + // by calling the trait implementation in B + protected override bool InstanceMethodsCanOnlyCallOverridenTraitMethods => true; public void Start() { if (items != null) { @@ -198,15 +203,26 @@ protected override IClassWriter CreateClass(string moduleName, bool isExtern, st if (currentBuilder is ClassContainer builder) { List typeParams = typeParameters.Select(tp => GenTypeArgDecl(tp)).ToList(); - return new ClassWriter(this, typeParams.Count > 0, builder.Class( + var classWriter = new ClassWriter(this, typeParams.Count > 0, builder.Class( IdName(cls), moduleName, typeParams, superClasses.Select(t => GenType(t)).ToList(), ParseAttributes(cls.Attributes), GetDocString(cls)) ); + + return classWriter; } else { throw new InvalidOperationException(); } } + private TypeParameterInfo GenTypeParameterInfo(TypeParameter tp) { + return (TypeParameterInfo)TypeParameterInfo.create_TypeParameterInfo(GenTypeVariance(tp), + tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype); + } + + private ISequence GenTypeParameterInfos(List typeParams) { + return Sequence.FromArray(typeParams.Select(GenTypeParameterInfo).ToArray()); + } + private Variance GenTypeVariance(TypeParameter tp) { if (tp.Variance is TypeParameter.TPVariance.Co) { return (Variance)Variance.create_Covariant(); @@ -218,7 +234,7 @@ private Variance GenTypeVariance(TypeParameter tp) { return (Variance)Variance.create_Nonvariant(); } - private static ISequence<_ITypeArgBound> GenTypeBounds(TypeParameter tp) { + private ISequence<_ITypeArgBound> GenTypeBounds(TypeParameter tp) { var characteristics = new List<_ITypeArgBound>(); if (tp.Characteristics.AutoInit is Type.AutoInitInfo.CompilableValue) { characteristics.Add(DAST.TypeArgBound.create_SupportsDefault()); @@ -228,6 +244,11 @@ private static ISequence<_ITypeArgBound> GenTypeBounds(TypeParameter tp) { characteristics.Add(DAST.TypeArgBound.create_SupportsEquality()); } + foreach (var typebound in tp.TypeBounds) { + var traitType = GenType(typebound); + characteristics.Add(DAST.TypeArgBound.create_TraitBound(traitType)); + } + var bounds = Sequence<_ITypeArgBound>.FromArray(characteristics.ToArray()); return bounds; } @@ -239,8 +260,11 @@ protected TypeArgDecl GenTypeArgDecl(TypeParameter tp, string name = null) { name ??= tp.GetCompileName(Options); + var info = TypeParameterInfo.create_TypeParameterInfo(variance, + tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype); + return (DAST.TypeArgDecl)DAST.TypeArgDecl.create_TypeArgDecl( - Sequence.UnicodeFromString(name), bounds, variance); + Sequence.UnicodeFromString(name), bounds, info); } protected override IClassWriter CreateTrait(string name, bool isExtern, List typeParameters, @@ -261,8 +285,9 @@ protected override IClassWriter CreateTrait(string name, bool isExtern, List typeParams = []; - foreach (var tp in dt.TypeArgs) { - typeParams.Add(GenTypeArgDecl(tp)); - } + var typeParams = GenTypeParams(dt.TypeArgs); IEnumerable ctors = from ctor in dt.Ctors @@ -311,7 +333,11 @@ from arg in ctor.Formals var superClasses = dt.ParentTypeInformation.UniqueParentTraits(); var superTraitTypes = superClasses.Select(GenType).ToList(); - return new ClassWriter(this, typeParams.Count > 0, builder.Datatype( + var superNegativeTraitTypes = GetNegativeTraitTypes(superClasses); + + var equalitySupport = GenEqualitySupport(dt); + + var datatypeBuilder = builder.Datatype( dt.GetCompileName(Options), dt.EnclosingModuleDefinition.GetCompileName(Options), typeParams, @@ -319,13 +345,53 @@ from arg in ctor.Formals dt is CoDatatypeDecl, ParseAttributes(dt.Attributes), GetDocString(dt), - superTraitTypes - )); + superTraitTypes, + superNegativeTraitTypes, equalitySupport); + + return new ClassWriter(this, typeParams.Count > 0, datatypeBuilder); } else { throw new InvalidOperationException("Cannot declare datatype outside of a module: " + currentBuilder); } } + private List GenTypeParams(List typePargs) { + List typeParams = []; + foreach (var tp in typePargs) { + typeParams.Add(GenTypeArgDecl(tp)); + } + + return typeParams; + } + + // Given a list of super traits implemented by a datatype, + // find the list of all instantiated traits that the super traits can be downcasted to, + // but that are not in the super classes, + // and return them + private List GetNegativeTraitTypes(List superClasses) { + var superNegativeTraitTypes = new List(); + var traitDeclsNegative = new HashSet(); + var traitDeclsImplemented = superClasses.Select(t => t.AsTraitType) + .Where(t => t != null).ToHashSet(); + foreach (var superClass in superClasses) { + if (superClass.AsTraitType is { } traitDecl) { + var downcastableTraitTypes = traitDecl.DowncastableSubTraitsIfMonomorphized(); + foreach (var downcastableTraitType in downcastableTraitTypes) { + if (downcastableTraitType is { AsTraitType: { } downcastTraitDecl } && + !traitDeclsNegative.Contains(downcastTraitDecl) && !traitDeclsImplemented.Contains(downcastTraitDecl)) { + traitDeclsNegative.Add(downcastTraitDecl); + // downcastableTraitType is instantiated with the type parameters of traitDecl + var typeParametersInstantiation = + traitDecl.TypeArgs.Zip(superClass.TypeArgs).ToDictionary(kv => kv.Item1, kv => kv.Item2); + var typeForDatatype = downcastableTraitType.Subst(typeParametersInstantiation); + superNegativeTraitTypes.Add(GenType(typeForDatatype)); + } + } + } + } + + return superNegativeTraitTypes; + } + protected override IClassWriter DeclareNewtype(NewtypeDecl nt, ConcreteSyntaxTree wr) { if (currentBuilder is NewtypeContainer builder) { List witnessStmts = []; @@ -358,11 +424,12 @@ protected override IClassWriter DeclareNewtype(NewtypeDecl nt, ConcreteSyntaxTre } else { constraint = (Option)Option.create_None(); } - + var equalitySupport = GenEqualitySupport(nt); + var typeParams = GenTypeParams(nt.TypeArgs); return new ClassWriter(this, false, builder.Newtype( - nt.GetCompileName(Options), [], + nt.GetCompileName(Options), typeParams, GenType(nt.BaseType), NativeTypeToNewtypeRange(nt, false), - constraint, witnessStmts, witness, ParseAttributes(nt.Attributes), GetDocString(nt))); + constraint, witnessStmts, witness, ParseAttributes(nt.Attributes), GetDocString(nt), equalitySupport)); } else { throw new InvalidOperationException(); } @@ -524,6 +591,14 @@ protected override bool InstanceConstAreStatic() { return false; } + [CanBeNull] + public MemberDecl GetTopMostOverriddenMemberDeclIfDifferent(MemberDecl member) { + while (member.OverriddenMember is { OverriddenMember: { } } upMember) { + member = upMember; + } + return member.OverriddenMember; + } + private class ClassWriter : IClassWriter { private readonly DafnyCodeGenerator compiler; private readonly ClassLike builder; @@ -538,14 +613,9 @@ public ClassWriter(DafnyCodeGenerator compiler, bool hasTypeArgs, ClassLike buil public ConcreteSyntaxTree CreateMethod(Method m, List typeArgs, bool createBody, bool forBodyInheritance, bool lookasideBody) { - if (m.IsStatic && this.hasTypeArgs) { - compiler.AddUnsupported(m.Origin, "Static methods with type arguments"); - return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); - } + var astTypeArgs = m.TypeArgs.Select(typeArg => compiler.GenTypeArgDecl(typeArg)).ToList(); - var astTypeArgs = typeArgs.Select(typeArg => compiler.GenTypeArgDecl(typeArg.Formal)).ToList(); - - var params_ = compiler.GenFormals(m.Ins); + var params_ = compiler.GetParameters(m, out var inheritedParams, out var overriddenMethod); List> outVars = []; List outTypes = []; @@ -556,10 +626,6 @@ public ConcreteSyntaxTree CreateMethod(Method m, List } } - var overriddenMethod = m.OverriddenMethod; - while (overriddenMethod != null && overriddenMethod.OverriddenMethod != null) { - overriddenMethod = overriddenMethod.OverriddenMethod; - } var overridingTrait = overriddenMethod?.EnclosingClass; if (m is Constructor { EnclosingClass: TopLevelDeclWithMembers cm }) { @@ -583,9 +649,8 @@ public ConcreteSyntaxTree CreateMethod(Method m, List compiler.GetDocString(m), attributes, m.GetCompileName(compiler.Options), - astTypeArgs, params_, - outTypes, outVars - ); + astTypeArgs, params_, inheritedParams, + outTypes, outVars); methods.Add(builder); if (createBody) { @@ -604,16 +669,22 @@ public ConcreteSyntaxTree SynthesizeMethod(Method m, List typeArgs, List formals, Type resultType, IOrigin tok, bool isStatic, bool createBody, MemberDecl member, bool forBodyInheritance, bool lookasideBody) { - if (isStatic && this.hasTypeArgs) { - compiler.AddUnsupported(tok, "Static functions with type arguments"); - return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); - } - var astTypeArgs = typeArgs.Select(typeArg => compiler.GenTypeArgDecl(typeArg.Formal)).ToList(); + var astTypeArgs = (member is Function fun ? fun.TypeArgs : Enumerable.Empty()).Select(typeArg => compiler.GenTypeArgDecl(typeArg)).ToList(); - var params_ = compiler.GenFormals(formals); + Sequence params_; + Sequence inheritedParams; + MemberDecl overridingFunction; + if (member is Function fun2) { + params_ = compiler.GetParameters(fun2, out inheritedParams, out overridingFunction); + } else { + params_ = compiler.GenFormals(formals); + overridingFunction = compiler.GetTopMostOverriddenMemberDeclIfDifferent(member); + inheritedParams = params_; + } + + var overridingTrait = overridingFunction?.EnclosingClass; - var overridingTrait = member.OverriddenMember?.EnclosingClass; var attributes = compiler.ParseAttributes(member.Attributes); var builder = this.builder.Method( isStatic, createBody, false, true, @@ -621,9 +692,8 @@ public ConcreteSyntaxTree CreateFunction(string name, ListStatic fields with type arguments"); - return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); - } - - var overridingTrait = member.OverriddenMember?.EnclosingClass; + var overridingTrait = compiler.GetTopMostOverriddenMemberDeclIfDifferent(member)?.EnclosingClass; var attributes = compiler.ParseAttributes(enclosingDecl.Attributes); @@ -651,8 +716,8 @@ public ConcreteSyntaxTree CreateGetter(string name, TopLevelDecl enclosingDecl, attributes, name, [], (Sequence)Sequence.Empty, - [compiler.GenType(resultType)], null - ); + (Sequence)Sequence.Empty, + [compiler.GenType(resultType)], null); methods.Add(builder); if (createBody) { @@ -1004,8 +1069,8 @@ protected override void TrCallStmt(CallStmt s, string receiverReplacement, Concr if (s.Method == enclosingMethod && enclosingMethod.IsTailRecursive) { base.TrCallStmt(s, receiverReplacement, wr, wrStmts, wrStmtsAfterCall); } else { - var parameters = GenFormals(s.Method.Ins); - var callBuilder = stmtContainer.Builder.Call(parameters); + var signature = GetCallSignature(s.Method); ; + var callBuilder = stmtContainer.Builder.Call(signature); base.TrCallStmt(s, receiverReplacement, new BuilderSyntaxTree(callBuilder, this), wrStmts, wrStmtsAfterCall); } } else { @@ -1032,18 +1097,35 @@ protected override void EmitStaticExternMethodQualifier(string qual, ConcreteSyn protected override void EmitCallToInheritedMethod(Method method, [CanBeNull] TopLevelDeclWithMembers heir, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts, ConcreteSyntaxTree wStmtsAfterCall) { if (wr is BuilderSyntaxTree stmtContainer) { - var callBuilder = stmtContainer.Builder.Call(GenFormals(method.Ins)); + var signature = GetCallSignature(method); + var callBuilder = stmtContainer.Builder.Call(signature); base.EmitCallToInheritedMethod(method, heir, new BuilderSyntaxTree(callBuilder, this), wStmts, wStmtsAfterCall); } else { throw new InvalidOperationException("Cannot call inherited method in this context: " + currentBuilder); } } - protected override void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLevelDeclWithMembers heir, - ConcreteSyntaxTree wr) { + private _ICallSignature GetCallSignature(MethodOrFunction method) { + var parameters = GetParameters(method, out var inheritedParameters, out _); + var signature = DAST.CallSignature.create_CallSignature(parameters, inheritedParameters); + return signature; + } + + private Sequence GetParameters(MethodOrFunction method, out Sequence inheritedParameters, out MemberDecl inheritedMethod) { + var parameters = GenFormals(method.Ins); + inheritedMethod = GetTopMostOverriddenMemberDeclIfDifferent(method); + var oldThisContext = thisContext; + thisContext = null; + inheritedParameters = inheritedMethod is MethodOrFunction m ? GenFormals(m.Ins) : parameters; + thisContext = oldThisContext; + return parameters; + } + + protected override ConcreteSyntaxTree StartCall(Function f, ConcreteSyntaxTree wr) { if (wr is BuilderSyntaxTree exprContainer) { - var callBuilder = exprContainer.Builder.Call(GenFormals(f.Ins)); - base.EmitCallToInheritedFunction(f, heir, new BuilderSyntaxTree(callBuilder, this)); + var signature = GetCallSignature(f); + var callBuilder = exprContainer.Builder.Call(signature); + return new BuilderSyntaxTree(callBuilder, this); } else { throw new InvalidOperationException("Cannot call inherited function in this context: " + currentBuilder); } @@ -1064,7 +1146,8 @@ protected override void CompileFunctionCallExpr(FunctionCallExpr e, ConcreteSynt wr = EmitCoercionIfNecessary(fromType, toType, e.Origin, wr); if (wr is BuilderSyntaxTree builder) { - var callBuilder = builder.Builder.Call(GenFormals(e.Function.Ins)); + var signature = GetCallSignature(e.Function); + var callBuilder = builder.Builder.Call(signature); base.CompileFunctionCallExpr(e, new BuilderSyntaxTree(callBuilder, this), inLetExprBody, wStmts, tr, true); } else { throw new InvalidOperationException("Cannot call function in this context: " + currentBuilder); @@ -1679,12 +1762,24 @@ private DAST.Type FullTypeNameAST(UserDefinedType udt, MemberDecl member = null) } } + private readonly Dictionary>> topLevelDeclPath = new(); + private ISequence> PathFromTopLevel(TopLevelDecl topLevel) { - List> path = [ - Sequence.UnicodeFromString(topLevel.EnclosingModuleDefinition.GetCompileName(Options)), - Sequence.UnicodeFromString(topLevel.GetCompileName(Options)) + if (topLevel is NonNullTypeDecl { Class: var classLikeDecl } nonNullTypeDecl) { + topLevel = classLikeDecl; + } + if (topLevelDeclPath.TryGetValue(topLevel, out var path)) { + return path; + } + var enclosingName = topLevel.GetQualificationName(Options); + var compileName = topLevel.GetCompileName(Options); + List> pathList = [ + Sequence.UnicodeFromString(enclosingName), + Sequence.UnicodeFromString(compileName) ]; - return Sequence>.FromArray(path.ToArray()); + var p = Sequence>.FromArray(pathList.ToArray()); + topLevelDeclPath[topLevel] = p; + return p; } private DAST.NewtypeRange NativeTypeToNewtypeRange(NewtypeDecl newtypeDecl, bool overflows) { @@ -1701,9 +1796,11 @@ private DAST.NewtypeRange NativeTypeToNewtypeRange(NewtypeDecl newtypeDecl, bool NativeType.Selection.UDoubleLong => NewtypeRange.create_U128(overflows), NativeType.Selection.DoubleLong => NewtypeRange.create_I128(overflows), _ => - EraseNewtypeLayers(newtypeDecl) is BoolType - ? NewtypeRange.create_Bool() - : NewtypeRange.create_NoRange() + EraseNewtypeLayers(newtypeDecl) is { } resType ? + resType is BoolType ? NewtypeRange.create_Bool() : + resType is MapType ? NewtypeRange.create_Map() : + resType is SeqType ? NewtypeRange.create_Sequence() + : NewtypeRange.create_NoRange() : NewtypeRange.create_NoRange() }); } @@ -1778,37 +1875,65 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type var seqTypeArgs = Sequence.FromArray(typeArgs.Select(m => GenType(m)).ToArray()); DAST.ResolvedTypeBase resolvedTypeBase; + var attributes = topLevel.Attributes; if (topLevel is NewtypeDecl newType) { var range = NativeTypeToNewtypeRange(newType, false); - var newtypeBase = newType.BaseType; + var newtypeBase = newType.RhsWithArgument(typeArgs); resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Newtype( GenType(newtypeBase), range, erasedIfNewtype); } else if (topLevel is TypeSynonymDecl typeSynonym) { // Also SubsetTypeDecl resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_SynonymType( - GenType(typeSynonym.Rhs.Subst(typeSynonym.TypeArgs.Zip(typeArgs).ToDictionary(kv => kv.Item1, kv => kv.Item2)).NormalizeExpand())); + GenType(typeSynonym.RhsWithArgument(typeArgs))); } else if (topLevel is TraitDecl traitDecl) { var traitType = traitDecl.IsReferenceTypeDecl ? TraitType.create_ObjectTrait() : TraitType.create_GeneralTrait(); resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Trait(traitType); } else if (topLevel is DatatypeDecl dd) { - var variances = Sequence.FromArray(dd.TypeArgs.Select(GenTypeVariance).ToArray()); - resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Datatype(variances); + var infos = GenTypeParameterInfos(dd.TypeArgs); + var equalitySupport = GenEqualitySupport(dd); + resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Datatype( + equalitySupport, infos); } else if (topLevel is ClassDecl) { resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Class(); + } else if (topLevel is AbstractTypeDecl atd) { + resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Datatype(GenEqualitySupport(topLevel), GenTypeParameterInfos(topLevel.TypeArgs)); + attributes = new Attributes("rust_rc", [Expression.CreateBoolLiteral(Token.NoToken, false)], attributes); } else { // SubsetTypeDecl are covered by TypeSynonymDecl throw new InvalidOperationException(topLevel.GetType().ToString()); } var resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_ResolvedType( - path, seqTypeArgs, resolvedTypeBase, ParseAttributes(topLevel.Attributes), seqProperMethods, seqExtendTraits); + path, seqTypeArgs, resolvedTypeBase, ParseAttributes(attributes), seqProperMethods, seqExtendTraits); DAST.Type baseType = (DAST.Type)DAST.Type.create_UserDefined(resolvedType); return baseType; } + private static _IEqualitySupport GenEqualitySupport(Declaration decl) { + Contract.Requires(decl is IndDatatypeDecl or NewtypeDecl); + IndDatatypeDecl.ES equalitySupport = + decl is IndDatatypeDecl indDecl ? indDecl.EqualitySupport : + decl is NewtypeDecl nt ? nt.EqualitySupport : + decl is AbstractTypeDecl atd ? + atd.Characteristics.EqualitySupport switch { + TypeParameter.EqualitySupportValue.Required => IndDatatypeDecl.ES.ConsultTypeArguments, + TypeParameter.EqualitySupportValue.InferredRequired => IndDatatypeDecl.ES.ConsultTypeArguments, + TypeParameter.EqualitySupportValue.Unspecified => IndDatatypeDecl.ES.Never, + _ => throw new ArgumentOutOfRangeException() + } + : + IndDatatypeDecl.ES.Never; + + return equalitySupport switch { + IndDatatypeDecl.ES.Never => EqualitySupport.create_Never(), + IndDatatypeDecl.ES.ConsultTypeArguments => EqualitySupport.create_ConsultTypeArguments(), + _ => throw new InvalidOperationException() + }; + } + private static Type EraseNewtypeLayers(TopLevelDecl topLevel) { var topLevelType = UserDefinedType.FromTopLevelDecl(topLevel.Origin, topLevel); return topLevelType.NormalizeToAncestorType(); @@ -1973,6 +2098,13 @@ protected override void GetSpecialFieldInfo(SpecialField.ID id, object idParam, } } + _ISelectContext GetSelectContext(TopLevelDecl decl) { + return decl is DatatypeDecl or NewtypeDecl ? SelectContext.create_SelectContextDatatype() : + decl is TraitDecl { IsReferenceTypeDecl: false } ? + SelectContext.create_SelectContextGeneralTrait() : + SelectContext.create_SelectContextClassOrObjectTrait(); + } + protected override ILvalue EmitMemberSelect(Action obj, Type objType, MemberDecl member, List typeArgs, Dictionary typeMap, Type expectedType, string additionalCustomParameter = null, bool internalAccess = false) { @@ -2002,7 +2134,7 @@ protected override ILvalue EmitMemberSelect(Action obj, Type objExpr, Sequence.UnicodeFromString(compileName), FieldMutabilityOf(member), - member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) + GetSelectContext(member.EnclosingClass), GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), @@ -2047,7 +2179,7 @@ member is ConstantField objExpr, Sequence.UnicodeFromString(compiledName), FieldMutabilityOf(member), - member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) + GetSelectContext(member.EnclosingClass), GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(compiledName), @@ -2080,7 +2212,7 @@ member is ConstantField objExpr, Sequence.UnicodeFromString(InternalFieldPrefix + member.GetCompileName(Options)), FieldMutabilityOf(member, isInternal: true), - member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) + GetSelectContext(member.EnclosingClass), GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(InternalFieldPrefix + member.GetCompileName(Options)), @@ -2091,7 +2223,7 @@ member is ConstantField objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), FieldMutabilityOf(member), - member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) + GetSelectContext(member.EnclosingClass), GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), @@ -2236,11 +2368,11 @@ protected override void EmitIndexCollectionUpdate(Expression source, Expression if (GetExprConverter(wr, wStmts, out var builder, out var convert)) { if (resultCollectionType.AsSeqType is { }) { builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_SeqUpdate( - convert(source), convert(index), convert(value) + convert(source), convert(index), convert(value), GenType(resultCollectionType), GenType(source.Type) )); } else if (resultCollectionType.AsMapType is { }) { builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_MapUpdate( - convert(source), convert(index), convert(value) + convert(source), convert(index), convert(value), GenType(resultCollectionType), GenType(source.Type) )); } else { AddUnsupported(source.Origin, "EmitIndexCollectionUpdate for " + resultCollectionType.ToString() + ""); @@ -2373,7 +2505,7 @@ protected override void EmitDestructor(Action source, Formal sourceAST, Sequence.UnicodeFromString(compileName), new FieldMutability_InternalClassConstantFieldOrDatatypeDestructor(), - true, GenType(dtor.Type) + GetSelectContext(ctor.EnclosingDatatype), GenType(dtor.Type) )); } } @@ -2436,9 +2568,10 @@ protected override ConcreteSyntaxTree EmitCallToIsMethod(RedirectingTypeDecl dec return wrRhs; } - var signature = Sequence<_IFormal>.FromArray([ + var parameters = Sequence<_IFormal>.FromArray([ new DAST.Formal(Sequence.UnicodeFromString("_dummy_"), GenType(type), Sequence.Empty) ]); + var signature = CreateSignature(parameters); var c = builder.Builder.Call(signature); c.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString("is"), Option<_IType>.create_None(), Option<_IFormal>.create_None(), false, signature)); @@ -2545,7 +2678,8 @@ protected override void EmitDatatypeBoundedPool(IVariable bv, string propertySuf if (GetExprConverter(wr, wStmts, out var exprBuilder, out var convert)) { if (bv.Type.IsDatatype && bv.Type.AsDatatype is { } datatypeDecl) { - var signature = Sequence<_IFormal>.FromArray([]); + var parameters = Sequence<_IFormal>.FromArray([]); + var signature = CreateSignature(parameters); var c = exprBuilder.Builder.Call(signature); c.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString("_AllSingletonConstructors"), Option<_IType>.create_None(), Option<_IFormal>.create_None(), false, signature)); @@ -2949,17 +3083,33 @@ protected override void EmitConstructorCheck(string source, DatatypeCtor ctor, C } protected override void EmitTypeTest(string localName, Type fromType, Type toType, IOrigin tok, ConcreteSyntaxTree wr) { + // This method needs to be implemented, but because we override EmitTypeTestExpr, it's never going to be called Still, we leave the body for completeness and maintenance. if (GetExprBuilder(wr, out var builder)) { - builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_Is( - DAST.Expression.create_Ident(Sequence.UnicodeFromString(localName)), - GenType(fromType), - GenType(toType) - )); + EmitTypeTestDAST(fromType, toType, builder, + (DAST.Expression)DAST.Expression.create_Ident(Sequence.UnicodeFromString(localName))); } else { throw new InvalidOperationException(); } } + protected override void EmitTypeTestExpr(Expression expr, Type fromType, Type toType, IOrigin tok, + bool inLetExprBody, ConcreteSyntaxTree wr, ref ConcreteSyntaxTree wStmts) { + if (GetExprConverter(wr, wStmts, out var builder, out var convert)) { + var exprDAST = convert(expr); + EmitTypeTestDAST(fromType, toType, builder, exprDAST); + } else { + throw new InvalidOperationException();//TODO + } + } + + private void EmitTypeTestDAST(Type fromType, Type toType, BuilderSyntaxTree builder, DAST.Expression exprDAST) { + builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_Is( + exprDAST, + GenType(fromType), + GenType(toType) + )); + } + protected override void EmitIsIntegerTest(Expression source, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { AddUnsupportedFeature(source.Origin, Feature.TypeTests); } @@ -3010,7 +3160,8 @@ protected override void EmitMapDisplay(MapType mt, IOrigin tok, List>.FromArray(elementsAST.ToArray()) + Sequence<_System.Tuple2>.FromArray(elementsAST.ToArray()), + GenType(mt.Domain), GenType(mt.Range) )); } else { throw new InvalidOperationException(); @@ -3061,7 +3212,7 @@ protected override void EmitMapBuilder_New(ConcreteSyntaxTree wr, MapComprehensi protected override void EmitSetBuilder_Add(CollectionType ct, string collName, Expression elmt, bool inLetExprBody, ConcreteSyntaxTree wr) { if (GetStatementBuilder(wr, out var builder)) { - var stmtBuilder = new CallStmtBuilder(Sequence<_IFormal>.Empty); + var stmtBuilder = new CallStmtBuilder(CreateSignature(Sequence<_IFormal>.Empty)); stmtBuilder.SetName((DAST.CallName)DAST.CallName.create_SetBuilderAdd()); stmtBuilder.SetTypeArgs([]); stmtBuilder.SetOuts([]); ; @@ -3074,6 +3225,10 @@ protected override void EmitSetBuilder_Add(CollectionType ct, string collName, E //throw new InvalidOperationException(); } + private static _ICallSignature CreateSignature(ISequence<_IFormal> params_) { + return CallSignature.create_CallSignature(params_, params_); + } + // Normally wStmt is a BuilderSyntaxTree but it might not while the compiler is being developed private DAST.Expression ConvertExpression(Expression term, ConcreteSyntaxTree wStmt) { EmitExpr(term, false, WrBuffer(out var buffer0), wStmt); @@ -3093,7 +3248,7 @@ private BuilderSyntaxTree CreateExprBuilder() { protected override ConcreteSyntaxTree EmitMapBuilder_Add(MapType mt, IOrigin tok, string collName, Expression term, bool inLetExprBody, ConcreteSyntaxTree wr) { if (GetStatementBuilder(wr, out var builder)) { - var stmtBuilder = new CallStmtBuilder(Sequence<_IFormal>.Empty); + var stmtBuilder = new CallStmtBuilder(CreateSignature(Sequence<_IFormal>.Empty)); stmtBuilder.SetName((DAST.CallName)DAST.CallName.create_MapBuilderAdd()); stmtBuilder.SetTypeArgs([]); stmtBuilder.SetOuts([]); ; @@ -3175,7 +3330,7 @@ protected override Action GetSubtypeCondition(string tmpVarN protected override void GetCollectionBuilder_Build(CollectionType ct, IOrigin tok, string collName, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmt) { if (GetExprBuilder(wr, out var builder)) { - var callExpr = new CallExprBuilder(Sequence<_IFormal>.Empty); + var callExpr = new CallExprBuilder(CreateSignature(Sequence<_IFormal>.Empty)); if (ct.IsMapType) { callExpr.SetName((DAST.CallName)DAST.CallName.create_MapBuilderBuild()); } else { diff --git a/Source/DafnyCore/Backends/GeneratorErrors.cs b/Source/DafnyCore/Backends/GeneratorErrors.cs index 1d1ebc80f2d..32b4aa04ff3 100644 --- a/Source/DafnyCore/Backends/GeneratorErrors.cs +++ b/Source/DafnyCore/Backends/GeneratorErrors.cs @@ -13,7 +13,6 @@ public enum ErrorId { c_process_exit, c_process_failed_to_start, c_unsupported_feature, - c_abstract_type_needs_hint, c_abstract_type_cannot_be_compiled, c_iterators_are_not_deterministic, c_iterator_has_no_body, @@ -87,11 +86,6 @@ such as the proper files not having the correct permissions. - the feature is not listed in the in-tool list of unsupported features. The latter is an omission in the in-tool documentation. Please report this error message and the part of the program provoking it to the Dafny team's [issue tracker](https://github.com/dafny-lang/dafny/issues). -".TrimStart()); - - Add(ErrorId.c_abstract_type_needs_hint, - @" -The type needs a name given to know which type in the target language it is associated with. ".TrimStart()); Add(ErrorId.c_abstract_type_cannot_be_compiled, diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index e99e03116c3..c79f31e51aa 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -27,7 +27,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { // Method names that would automatically resolve to trait methods instead of inherent methods // Hence, full name is always required for these methods const builtin_trait_preferred_methods := { - "le", "eq", "lt", "ge", "gt" + "le", "eq", "lt", "ge", "gt", "hash" } @@ -190,7 +190,8 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { { Environment(names + [name], types[name := tpe], assignmentStatusKnown - {name}) } - function merge(other: Environment): Environment + // Merges a current environment with a new one + function Merge(other: Environment): Environment { Environment( names + other.names, @@ -198,6 +199,15 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { assignmentStatusKnown + other.assignmentStatusKnown ) } + // When exiting If-then-else, we can remove variables that were unassigned in both branches + function Join(thenBranch: Environment, elseBranch: Environment): Environment { + var removed := types.Keys - (thenBranch.types.Keys + elseBranch.types.Keys); + Environment( + Std.Collections.Seq.Filter(name => name !in removed, names), + types - removed, + assignmentStatusKnown - removed + ) + } // Used to removed from the environment the "_is_assigned" vars used to initialize fields function RemoveAssigned(name: string): Environment requires name in names @@ -292,6 +302,31 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { predicate IsSelf() { ThisTyped? && rSelfName == "self" } + predicate IsGeneralTrait() { + ThisTyped? && dafnyType.IsGeneralTrait() + } + predicate IsClassOrObjectTrait() { + ThisTyped? && dafnyType.IsClassOrObjectTrait() + } + predicate IsRcWrappedDatatype() { + ThisTyped? && IsRcWrappedDatatypeRec(dafnyType) + } + } + + predicate IsRcWrappedDatatypeRec(dafnyType: Type) { + match dafnyType { + case UserDefined(ResolvedType(_, _, Datatype(_, _), attributes, _, _)) => + IsRcWrapped(attributes) + case UserDefined(ResolvedType(_, _, SynonymType(tpe), attributes, _, _)) => + IsRcWrappedDatatypeRec(tpe) + case _ => false + } + } + + predicate IsRcWrapped(attributes: seq) { + (Attribute("auto-nongrowing-size", []) !in attributes && + Attribute("rust_rc", ["false"]) !in attributes) || + Attribute("rust_rc", ["true"]) in attributes } datatype ExternAttribute = @@ -494,13 +529,18 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { ensures BecomesLeftCallsRight(op) ==> !BecomesRightCallsLeft(op) {} + function Panic(optText: string := ""): R.Expr { + if optText == "" then + R.Identifier("panic!").Apply0() + else + R.Identifier("panic!").Apply1(R.LiteralString(optText, binary := false, verbatim := false)) + } + function UnreachablePanicIfVerified(pointerType: PointerType, optText: string := ""): R.Expr { if pointerType.Raw? then R.Unsafe(R.Block(R.std.MSel("hint").AsExpr().FSel("unreachable_unchecked").Apply0())) - else if optText == "" then - R.Identifier("panic!").Apply0() else - R.Identifier("panic!").Apply1(R.LiteralString(optText, binary := false, verbatim := false)) + Panic(optText) } function DefaultDatatypeImpl( @@ -594,6 +634,33 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { )) } + function EqImpl(rTypeParamsDeclsWithEq: seq, datatypeType: R.Type, rTypeParams: seq, eqImplBody: R.Expr): seq { + [ R.ImplDecl( + R.ImplFor( + rTypeParamsDeclsWithEq, + R.PartialEq, + datatypeType, + [ R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "eq", + [], + [R.Formal.selfBorrowed, R.Formal("other", R.SelfBorrowed)], + Some(R.Bool), + Some(eqImplBody) + ) + )])), + R.ImplDecl( + R.ImplFor( + rTypeParamsDeclsWithEq, + R.Eq, + datatypeType, + [] + ) + ) + ] + } + function CoerceImpl( rc: R.Type -> R.Type, rcNew: R.Expr -> R.Expr, @@ -605,7 +672,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { coerceTypes: seq, coerceImplBody: R.Expr ): R.ModDecl { - R.ImplDecl( R.Impl( rTypeParamsDecls, @@ -665,13 +731,96 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { R.NoDoc, R.NoAttr, R.PRIV, R.Fn( - "hash", [R.TypeParamDecl("_H", [R.std.MSel("hash").MSel("Hasher").AsType()])], - [R.Formal.selfBorrowed, - R.Formal("_state", R.BorrowedMut(R.TIdentifier("_H")))], + "hash", hash_type_parameters, + hash_parameters, None, Some(hashImplBody)))] )) } + const hash_type_parameters := [R.TypeParamDecl("_H", [R.std.MSel("hash").MSel("Hasher").AsType()])] + const hash_parameters := [ + R.Formal.selfBorrowed, + R.Formal("_state", R.BorrowedMut(R.TIdentifier("_H")))] + const hash_function := R.std.MSel("hash").MSel("Hash").AsExpr().FSel("hash") + /** + fn _hash(&self) -> u64 { + let mut hasher = ::std::hash::DefaultHasher::new(); + self.hash(&mut hasher); + hasher.finish() + } */ + function hasher_trait(supportsEquality: bool, pointerType: PointerType): R.ImplMember { + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn( + "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), + Some( + if supportsEquality then + R.DeclareVar(R.MUT, "hasher", None, Some(R.std.MSel("hash").MSel("DefaultHasher").AsExpr().FSel("new").Apply0())).Then( + R.self.Sel("hash").Apply1(R.UnaryOp("&mut", R.Identifier("hasher"), Format.UnaryOpFormat.NoFormat)).Then( + R.Identifier("hasher").Sel("finish").Apply0() + ) + ) + else + UnreachablePanicIfVerified(pointerType, "The type does not support equality") + ))) + } + + /** + fn _eq(&self, other: &Box) -> bool { + Test::_as_any(other.as_ref()).downcast_ref::().map_or(false, |x| self == x) + } */ + function eq_trait(fullTraitPath: R.Type, fullTraitExpr: R.Expr, supportsEquality: bool, pointerType: PointerType): R.ImplMember { + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn( + "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(fullTraitPath))))], Some(R.Type.Bool), + Some( + if supportsEquality then + fullTraitExpr.FSel("_as_any").Apply1(R.Identifier("other").Sel("as_ref").Apply0()).Sel("downcast_ref").ApplyType([R.SelfOwned]).Apply0().Sel("map_or").Apply( + [ + R.LiteralBool(false), + R.Lambda([R.Formal("x", R.RawType("_"))], None, R.BinaryOp("==", R.self, R.Identifier("x"), Format.BinaryOpFormat.NoFormat)) + ] + ) + else + UnreachablePanicIfVerified(pointerType, "The type does not support equality") + ))) + } + + function clone_trait(fullTraitPath: R.Type): R.ImplMember { + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn( + "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), + Some(R.BoxNew(R.self.Sel("clone").Apply0())))) + } + + /** + fn _fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { + self.fmt_print(f, in_seq) + } */ + const print_trait := + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn( + "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), + Some(R.self.Sel("fmt_print").Apply([R.Identifier("_formatter"), R.Identifier("in_seq")])))) + + /** + fn _as_any(&self) -> &dyn ::std::any::Any { + self + } */ + const as_any_trait := + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn( + "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.AnyTrait))), + Some(R.self))) function UnaryOpsImpl( op: char, @@ -764,14 +913,199 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { R.Formal("other", R.SelfBorrowed)], Some(R.std.MSel("option").MSel("Option").AsType().Apply1(R.std.MSel("cmp").MSel("Ordering").AsType())), Some( - R.std.MSel("cmp").MSel("PartialOrd").AsExpr().FSel("partial_cmp").Apply([ - R.Borrow(R.self.Sel("0")), - R.Borrow(R.Identifier("other").Sel("0")) - ])) + R.std.MSel("cmp").MSel("PartialOrd").AsExpr().FSel("partial_cmp").Apply( + [ + R.Borrow(R.self.Sel("0")), + R.Borrow(R.Identifier("other").Sel("0")) + ])) )) ])) } + const fmt_print_parameters := [ + R.Formal.selfBorrowed, + R.Formal("_formatter", R.BorrowedMut(R.std.MSel("fmt").MSel("Formatter").AsType())), + R.Formal("in_seq", R.Type.Bool)] + + const fmt_print_result := R.std.MSel("fmt").MSel("Result").AsType() + + /* + pub trait _Downcast_BDatatype { + fn _is(&self) -> bool; + fn _as(&self) -> Rc> or ADatatype or Box; + } */ + function DowncastTraitDeclFor( + rTypeParamsDecls: seq, + fullType: R.Type + ): Option { + var downcast_type :- fullType.ToDowncast(); + Some( + R.TraitDecl( + R.Trait( + R.NoDoc, R.NoAttr, + rTypeParamsDecls, + downcast_type, + [], + [ R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn( + "_is", [], + [R.Formal.selfBorrowed], + Some(R.Bool), + None)), + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn( + "_as", [], + [R.Formal.selfBorrowed], + Some(fullType), + None)) + ]))) + } + + /* + impl _Downcast_TypeToDowncastTo for dyn Any { + fn _is(&self) -> bool { + self.downcast_ref::().is_some() + } + fn _as(&self) -> TypeToDowncastTo { // Possibly wrapped with rc + self.downcast_ref::().unwrap().clone() // Optimization: Could be unwrap_unchecked + } + } */ + function DowncastImplFor( + rcNew: R.Expr -> R.Expr, + rTypeParamsDecls: seq, + datatypeType: R.Type + ): Option { + var downcast_type :- datatypeType.ToDowncast(); + var isRc := datatypeType.IsRc(); + var datatypeTypeRaw := if isRc then datatypeType.RcUnderlying() else datatypeType; + var isBody := + R.self.Sel("downcast_ref").ApplyType([datatypeTypeRaw]).Apply0().Sel("is_some").Apply0(); + var asBody := + R.self.Sel("downcast_ref").ApplyType([datatypeTypeRaw]).Apply0().Sel("unwrap").Apply0().Sel("clone").Apply0(); + var asBody := if isRc then rcNew(asBody) else asBody; + Some( + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + downcast_type, + R.DynType(R.AnyTrait), + [ R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("_is", [], [R.Formal.selfBorrowed], Some(R.Bool), Some(isBody))), + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("_as", [], [R.Formal.selfBorrowed], Some(datatypeType), Some(asBody))) + ])) + ) + } + + /* + impl _Downcast_TraitNotImplemented + for CDatatype { + fn _is(&self) -> bool { false } + fn _as(&self) -> Box { panic!(); } + } + */ + function DowncastNotImplFor( + rTypeParamsDecls: seq, + traitType: R.Type, + datatypeType: R.Type + ): Option { + var downcast_type :- traitType.ToDowncast(); + var isRc := datatypeType.IsRc(); + var datatypeTypeRaw := if isRc then datatypeType.RcUnderlying() else datatypeType; + var isBody := R.LiteralBool(false); + var asBody := R.Identifier("panic!").Apply0(); + Some( + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + downcast_type, + datatypeTypeRaw, + [ R.FnDecl( + datatypeTypeRaw.ToString("") + " does not implement that trait", R.NoAttr, + R.PRIV, + R.Fn("_is", [], [R.Formal.selfBorrowed], Some(R.Bool), Some(isBody))), + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("_as", [], [R.Formal.selfBorrowed], Some(traitType), Some(asBody))) + ])) + ) + } + + /* + impl _Downcast_SuperSubTrait for ADatatype { + fn _is(&self) -> bool { + true + } + fn _as(&self) -> Box { + Box::new(self.clone()) + } + } + */ + function DowncastImplTraitFor( + rTypeParamsDecls: seq, + traitType: R.Type, + implementsTrait: bool, + datatypeType: R.Type + ): Option { + var downcast_type :- traitType.ToDowncast(); + var isRc := datatypeType.IsRc(); + var forType := if isRc then datatypeType.RcUnderlying() else datatypeType; + var resultType := traitType; + var isBody := R.LiteralBool(implementsTrait); + var asBody := R.BoxNew(R.self.Clone()); + Some( + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + downcast_type, + forType, + [ R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("_is", [], [R.Formal.selfBorrowed], Some(R.Bool), Some(isBody))), + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("_as", [], [R.Formal.selfBorrowed], Some(resultType), Some(asBody))) + ])) + ) + } + + /* + impl UpcastBox for Box { + fn upcast(&self) -> Box { + SuperTrait::_clone(self.as_ref()) + } + } + */ + function UpcastDynTraitFor( + rTypeParamsDecls: seq, + forBoxedTraitType: R.Type, + superTraitType: R.Type, + superTraitExpr: R.Expr + ): R.ModDecl { + var superBoxedTraitType := R.Box(R.DynType(superTraitType)); + var body := superTraitExpr.FSel("_clone").Apply1(R.self.Sel("as_ref").Apply0()); + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.dafny_runtime.MSel("UpcastBox").AsType().Apply([R.DynType(superTraitType)]), + forBoxedTraitType, + [ R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn("upcast", [], [R.Formal.selfBorrowed], Some(superBoxedTraitType), Some(body))) + ])) + } + // Overapproximate but sound static analysis domain for assignment of a variable datatype AssignmentStatus = NotAssigned | SurelyAssigned | Unknown { // After a if, typically. What we know if either of the assignment status is taken @@ -846,4 +1180,11 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } return NotAssigned; } + + function prefixWith2(s: string): string { + if |s| >= 2 && s[..2] == "r#" then + "_2_" + s[2..] + else + "_2_" + s + } } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index d4e5a19c5a6..52d3b3c87e8 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -497,11 +497,31 @@ module RAST visibility.ToString() + fn.ToString(ind) } } - datatype Attribute = RawAttribute(content: string) { + datatype Attribute = + | ApplyAttribute(name: string, derived: seq) { + static const DeriveClone := + ApplyAttribute("derive", ["Clone"]) + static const DeriveCloneAndCopy := + ApplyAttribute("derive", ["Clone", "Copy"]) + static const CfgTest := + ApplyAttribute("cfg", ["test"]) + static function Name(name: string): Attribute { + ApplyAttribute(name, []) + } + + function ToString(ind: string): string { + match this { + case ApplyAttribute(name, derived) => + var arguments := if |derived| != 0 then + "("+SeqToString(derived, (derived: string) => derived, ", ")+")" + else ""; + "#["+name+arguments+"]" + } + } static function ToStringMultiple(attributes: seq, ind: string): string { SeqToString( attributes, - (attribute: Attribute) => attribute.content + "\n" + ind) + (attribute: Attribute) => attribute.ToString(ind) + "\n" + ind) } } @@ -679,6 +699,8 @@ module RAST const BoxPath := std.MSel("boxed").MSel("Box") + const BoxType := BoxPath.AsType() + const Ptr := PtrPath.AsExpr() function PtrType(underlying: Type): Type { @@ -718,6 +740,13 @@ module RAST | Self() // Self::... | PMemberSelect(base: Path, name: string) { + static const DowncastPrefix := "_Downcast_" + function ToDowncast(): Path { + match this { + case PMemberSelect(base, name) => PMemberSelect(base, DowncastPrefix + name) + case _ => this + } + } function MSel(name: string): Path { PMemberSelect(this, name) } @@ -773,6 +802,55 @@ module RAST | TSynonym(display: Type, base: Type) | TMetaData(display: Type, nameonly copySemantics: bool, nameonly overflow: bool) { + /** Removes the synonym and metadata elements of a type */ + function RemoveSynonyms(): (t: Type) + ensures t == this || t < this + { + match this { + case TSynonym(display, base) => + display.RemoveSynonyms() + case TMetaData(display, _, _) => + display.RemoveSynonyms() + case _ => + this + } + } + /** Given a type, returns the _Downcast_* prefix version of that type */ + function ToDowncast(): Option { + var t := this.RemoveSynonyms(); + if t.IsRc() then t.RcUnderlying().ToDowncast() else // For Rc-wrapped datatypes + if t.IsBoxDyn() then t.BoxDynUnderlying().ToDowncast() else // For general traits + match t { + case TypeFromPath(path) => Some(TypeFromPath(path.ToDowncast())) + case TypeApp(baseName, arguments) => + var baseNameExpr :- baseName.ToDowncast(); + Some(baseNameExpr.Apply(arguments)) + case TIdentifier(name) => + Some(TIdentifier(Path.DowncastPrefix + name)) + case _ => None + } + } + /** Given a type, returns the _Downcast_* prefix version of that type but suitable to call methods */ + function ToDowncastExpr(): Option { + var tpe :- this.ToDowncast(); + tpe.ToExpr() + } + /** Converts Name (the type) to Name:: (the expr) */ + function ToExpr(): Option { + match this { + case TypeFromPath(path) => Some(ExprFromPath(path)) + case TypeApp(baseName, arguments) => + var baseNameExpr :- baseName.ToExpr(); + Some(baseNameExpr.ApplyType(arguments)) + case TSynonym(display, base) => + display.ToExpr() + case TMetaData(display, _, _) => + display.ToExpr() + case TIdentifier(name) => + Some(Identifier(name)) + case _ => None + } + } function Expand(): (r: Type) ensures !r.TSynonym? && !r.TMetaData? && (!TSynonym? && !TMetaData? ==> r == this) { @@ -1106,14 +1184,30 @@ module RAST } } + /** Returns true if the type has the shape Rc, so that one can extract T = .arguments[0] + * Useful to detect rc-wrapped datatypes */ predicate IsRc() { TypeApp? && (baseName == RcType || baseName == ArcType) && |arguments| == 1 } - function RcUnderlying(): Type + function RcUnderlying(): (t: Type) requires IsRc() + ensures t < this { arguments[0] } + + /** Returns true if the type has the shape Box, so that one can extract T = .arguments[0].underlying + * Useful to detect general traits */ + predicate IsBoxDyn() { + this.TypeApp? && this.baseName == BoxType && |arguments| == 1 && arguments[0].DynType? + } + + function BoxDynUnderlying(): (t: Type) + requires IsBoxDyn() + ensures t < this + { + arguments[0].underlying + } } function SystemTupleType(elements: seq): Type { @@ -1135,6 +1229,7 @@ module RAST const DafnyTypeEq := dafny_runtime.MSel("DafnyTypeEq").AsType() const Eq := std.MSel("cmp").MSel("Eq").AsType() const Hash := std.MSel("hash").MSel("Hash").AsType() + const PartialEq := std.MSel("cmp").MSel("PartialEq").AsType() const DafnyInt := dafny_runtime.MSel("DafnyInt").AsType() const SyncType := std.MSel("marker").MSel("Sync").AsType() const SendType := std.MSel("marker").MSel("Send").AsType() @@ -1633,6 +1728,8 @@ module RAST PrecedenceAssociativity(9, LeftToRight) else PrecedenceAssociativity(110, RightToLeft) + case "=>" => // Not a Rust operation, used in the map macro syntax + PrecedenceAssociativity(120, RightToLeft) case _ => PrecedenceAssociativity(0, RequiresParentheses) } case Lambda(_, _, _) => PrecedenceAssociativity(300, LeftToRight) @@ -1853,6 +1950,13 @@ module RAST assert r.RawExpr?; AddIndent(r.content, ind) } } + function And(rhs2: Expr): Expr { + if this == LiteralBool(true) then rhs2 else + BinaryOp("&&", this, rhs2, Format.BinaryOpFormat.NoFormat) + } + function Equals(rhs2: Expr): Expr { + BinaryOp("==", this, rhs2, Format.BinaryOpFormat.NoFormat) + } function Then(rhs2: Expr): Expr { if this.StmtExpr? then StmtExpr(stmt, rhs.Then(rhs2)) @@ -1968,6 +2072,19 @@ module RAST } } } + predicate IsBorrowUpcastBox(r: Expr) { + match r { + case UnaryOp("&", Call(Call(CallType(name, targs0), args0), args1), _) => + name == dafny_runtime.MSel("upcast_box").AsExpr() && |args0| == 0 && + |args1| == 1 && + match args1[0] { + case Call(Select(Identifier("self"), clone), args2) => + |args2| == 0 + case _ => false + } + case _ => false + } + } /** Placeholder when there is no Rust docstring */ const NoDoc := "" diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index c00da14501b..a018fb5b39c 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -86,6 +86,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { this.optimizations := [ ExpressionOptimization.apply, FactorPathsOptimization.apply(thisFile)]; + var thisAsSelf := rcNew(R.self.Clone()); + this.rcDatatypeThis := thisAsSelf; + this.borrowedRcDatatypeThis := R.Borrow(thisAsSelf); new; } @@ -108,7 +111,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var optExtern: ExternAttribute := ExtractExternMod(mod); var attributes := []; if HasAttribute(mod.attributes, "rust_cfg_test") { - attributes := [R.RawAttribute("#[cfg(test)]")]; + attributes := [R.Attribute.CfgTest]; } var body, allmodules := GenModuleBody(mod, mod.body.value, containingPath + [Ident.Ident(innerName)]); if optExtern.SimpleExtern? { @@ -160,13 +163,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenTypeParam(tp: TypeArgDecl) returns (typeArg: Type, typeParam: R.TypeParamDecl) { typeArg := TypeArg(tp.name); - var genTpConstraint := if SupportsEquality in tp.bounds then - [R.DafnyTypeEq] - else - [R.DafnyType]; - if SupportsDefault in tp.bounds { - genTpConstraint := genTpConstraint + [R.DefaultTrait]; + var supportsEquality := false; + var supportsDefault := false; + var genTpConstraint := []; + for i := 0 to |tp.bounds| { + var bound := tp.bounds[i]; + match bound + case SupportsEquality() => + supportsEquality := true; + case SupportsDefault() => + supportsDefault := true; + case TraitBound(typ) => + var tpe := GenType(typ, GenTypeContext.ForTraitParents()); + var upcast_tpe := R.dafny_runtime.MSel("UpcastBox").AsType().Apply([R.DynType(tpe)]); + genTpConstraint := genTpConstraint + [upcast_tpe]; + } + if supportsDefault { + genTpConstraint := [R.DefaultTrait] + genTpConstraint; } + var dafnyType := if supportsEquality then R.DafnyTypeEq else R.DafnyType; + genTpConstraint := [dafnyType] + genTpConstraint; typeParam := R.TypeParamDecl(escapeName(tp.name.id), genTpConstraint); } @@ -175,12 +191,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { typeParamsSeq: seq, rTypeParams: seq, rTypeParamsDecls: seq) + ensures |rTypeParams| == |rTypeParamsDecls| == |typeParamsSeq| == |params| { typeParamsSeq := []; rTypeParams := []; rTypeParamsDecls := []; if |params| > 0 { - for tpI := 0 to |params| { + for tpI := 0 to |params| + invariant |rTypeParams| == |rTypeParamsDecls| == |typeParamsSeq| == tpI + { var tp := params[tpI]; var typeArg, typeParam := GenTypeParam(tp); var rType := GenType(typeArg, GenTypeContext.default()); @@ -263,39 +282,42 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } method GenTraitImplementations( - path: seq, + classPath: seq, rTypeParams: seq, rTypeParamsDecls: seq, superTraitTypes: seq, traitBodies: map, seq>, extern: ExternAttribute, + supportsEquality: bool, kind: string) returns (s: seq) modifies this { s := []; - var genPath := GenPath(path); + var genPath := GenPath(classPath); var genSelfPath := genPath.AsType(); var genPathExpr := genPath.AsExpr(); for i := 0 to |superTraitTypes| { var superTraitType := superTraitTypes[i]; match superTraitType { case UserDefined(ResolvedType(traitPath, typeArgs, Trait(traitType), _, properMethods, _)) => { - var pathStr := GenPathType(traitPath); + var path := GenPath(traitPath); + var pathType := path.AsType(); var typeArgs := GenTypeArgs(typeArgs, GenTypeContext.default()); var body: seq := []; if traitPath in traitBodies { body := traitBodies[traitPath]; } - var fullTraitPath := R.TypeApp(pathStr, typeArgs); + var fullTraitPath := R.TypeApp(pathType, typeArgs); + var fullTraitExpr := path.AsExpr().ApplyType(typeArgs); if !extern.NoExtern? { // An extern of some kind // Either the Dafny code implements all the methods of the trait or none, if |body| == 0 && |properMethods| != 0 { continue; // We assume everything is implemented externally } if |body| != |properMethods| { - error := Some("Error: In the "+kind+" " + R.SeqToString(path, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + + error := Some("Error: In the "+kind+" " + R.SeqToString(classPath, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + fullTraitPath.ToString("") + " are marked {:extern} and some are not." + " For the Rust compiler, please make all methods (" + R.SeqToString(properMethods, (s: Name) => s.dafny_name, ", ") + ") bodiless and mark as {:extern} and implement them in a Rust file, "+ @@ -307,19 +329,33 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // Extern type, we assume } if traitType.GeneralTrait? { - // One more method: Cloning when boxed + // More methods: Cloning, printing, hashing, equality when boxed /*impl Test for Wrapper { + ... fn _clone(&self) -> Box { Box::new(self.clone()) } + fn _fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { + self.fmt_print(f, in_seq) + } + fn _hash(&self) -> u64 { + let mut hasher = ::std::hash::DefaultHasher::new(); + self.hash(&mut hasher); + hasher.finish() + } + fn _eq(&self, other: &Box>) -> bool { + other._as_any().downcast_ref::().map_or(false, |x| self == x) + } + fn _as_any(&self) -> &dyn ::std::any::Any { + self + } }*/ body := body + [ - R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, - R.Fn( - "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), - Some(R.BoxNew(R.self.Sel("clone").Apply0())))) + clone_trait(fullTraitPath), + print_trait, + hasher_trait(supportsEquality, pointerType), + eq_trait(fullTraitPath, fullTraitExpr, supportsEquality, pointerType), + as_any_trait ]; } else { if kind == "datatype" || kind == "newtype" { @@ -336,9 +372,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )); s := s + [x]; - var upcastTraitToImplement, upcastTraitFn; if traitType.GeneralTrait? { - upcastTraitToImplement, upcastTraitFn := "UpcastBox", "UpcastStructBoxFn!"; s := s + [ R.ImplDecl( R.ImplFor( @@ -352,7 +386,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { "upcast", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), - Some(genPathExpr.ApplyType(rTypeParams).FSel("_clone").Apply1(R.self))) // Difference with UpcastStructBox is that there is no .as_ref() + Some(path.AsExpr().ApplyType(typeArgs).FSel("_clone").Apply1(R.self))) // Difference with UpcastStructBox is that there is no .as_ref() ) ])) ]; } else { @@ -477,7 +511,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.TopFnDecl( R.TopFn( m.docString, - [R.RawAttribute("#[test]")], R.PUB, + [R.Attribute.Name("test")], R.PUB, R.Fn( fnName, [], [], None, Some(R.Identifier("_default").FSel(fnName).Apply([]))) @@ -513,6 +547,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { superTraitTypes, traitBodies, extern, + true, "class"); s := s + superTraitImplementations; } @@ -536,9 +571,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var fullPath := containingPath + [Ident.Ident(t.name)]; var name := escapeName(t.name); - var traitFulltype := R.TIdentifier(name).Apply(typeParams); + var traitFullType := R.TIdentifier(name).Apply(typeParams); var traitFullExpr := R.Identifier(name).ApplyType(typeParams); - var implBody, _ := GenClassImplBody( + var implBody, implBodyImplementingOtherTraits := GenClassImplBody( t.body, true, UserDefined( ResolvedType( @@ -550,67 +585,112 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // fn _clone(&self) -> Box; implBody := implBody + [ R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( - "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(traitFulltype))), + "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(traitFullType))), None + )), + R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), None + )), + R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), None + )), + R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(traitFullType))))], + Some(R.Bool), None + )), + R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.AnyTrait))), None )) ]; } - var parents := []; - var upcastImplemented := []; + while |implBodyImplementingOtherTraits| > 0 { + var otherTrait :| otherTrait in implBodyImplementingOtherTraits; + var otherMethods := implBodyImplementingOtherTraits[otherTrait]; + for i := 0 to |otherMethods| { + implBody := implBody + [otherMethods[i]]; // Defined in the trait, but not overriding. Implementations would have to ensure they call into that trait + } + implBodyImplementingOtherTraits := implBodyImplementingOtherTraits - {otherTrait}; + } + var parents: seq := []; + var upcastImplemented: seq := []; + var instantiatedFullType: R.Type; + if t.traitType.GeneralTrait? { // TODO: Make it work also for object traits + instantiatedFullType := R.Box(R.DynType(traitFullType)); + var upcastDynTrait := UpcastDynTraitFor(rTypeParamsDecls, instantiatedFullType, traitFullType, traitFullExpr); + upcastImplemented := upcastImplemented + [upcastDynTrait]; + } for i := 0 to |t.parents| { var parentTyp := t.parents[i]; var parentTpe := GenType(parentTyp, GenTypeContext.ForTraitParents()); parents := parents + [parentTpe]; var upcastTrait := if parentTyp.IsGeneralTrait() then "UpcastBox" else Upcast; parents := parents + [R.dafny_runtime.MSel(upcastTrait).AsType().Apply1(R.DynType(parentTpe))]; - if parentTyp.IsGeneralTrait() { - /*impl UpcastBox for Box { - fn upcast(&self) -> ::std::boxed::Box { - GeneralTrait::::_clone(self.as_ref()) - } - }*/ - upcastImplemented := upcastImplemented + [ - R.ImplDecl( - R.ImplFor( - rTypeParamsDecls, - R.dafny_runtime.MSel("UpcastBox").AsType().Apply1(R.DynType(parentTpe)), - R.Box(R.DynType(traitFulltype)), - [ R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, - R.Fn( - "upcast", - [], [R.Formal.selfBorrowed], - Some(R.Box(R.DynType(parentTpe))), - Some(traitFullExpr.FSel("_clone").Apply1(R.self.FSel("as_ref").Apply0())) - ) - )])) - ]; + if parentTyp.IsGeneralTrait() && t.traitType.GeneralTrait? && parentTpe != AnyTrait { + var parentTpeExprMaybe := parentTpe.ToExpr(); + var parentTpeExpr; + if parentTpeExprMaybe.None? { + parentTpeExpr := Error("Cannot convert " + parentTpe.ToString("") + " to an expression"); + } else { + parentTpeExpr := parentTpeExprMaybe.value; + } + var upcastDynTrait := UpcastDynTraitFor(rTypeParamsDecls, instantiatedFullType, parentTpe, parentTpeExpr); + upcastImplemented := upcastImplemented + [upcastDynTrait]; + } + } + var downcastDefinition := []; + if |t.parents| > 0 && t.traitType.GeneralTrait? { // We will need to downcast + var downcastDefinitionOpt := DowncastTraitDeclFor(rTypeParamsDecls, instantiatedFullType); + if downcastDefinitionOpt.None? { + var dummy := Error("Could not generate downcast definition for " + instantiatedFullType.ToString("")); + } else { + downcastDefinition := [downcastDefinitionOpt.value]; + } + } else if t.traitType.GeneralTrait? { + // Any top-most general trait must extend AnyRef so that we can perform downcasts to actual datatypes + parents := [R.dafny_runtime.MSel("AnyRef").AsType()] + parents; + } + if |t.downcastableTraits| > 0 && t.traitType.GeneralTrait? { + for i := 0 to |t.downcastableTraits| { + var downcastableTrait := GenType(t.downcastableTraits[i], GenTypeContext.ForTraitParents()); + var downcastTraitOpt := downcastableTrait.ToDowncast(); + if downcastTraitOpt.Some? { + parents := parents + [downcastTraitOpt.value]; + } else { + var r := Error("Cannot convert "+downcastableTrait.ToString("")+" to its downcast version"); + } } } s := [ R.TraitDecl( R.Trait( t.docString, [], - rTypeParamsDecls, traitFulltype, + rTypeParamsDecls, traitFullType, parents, implBody ))]; + s := s + downcastDefinition; if t.traitType.GeneralTrait? { - /*impl Clone for Box { - fn clone(&self) -> Box { - Test::_clone(self.as_ref()) - } - }*/ s := s + [ + /*impl Clone for Box { + fn clone(&self) -> Box { + Test::_clone(self.as_ref()) + } + }*/ R.ImplDecl( R.ImplFor( rTypeParamsDecls, R.std.MSel("clone").MSel("Clone").AsType(), - R.Box(R.DynType(traitFulltype)), + R.Box(R.DynType(traitFullType)), [R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, @@ -618,7 +698,76 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [ R.Formal.selfBorrowed ], Some(R.SelfOwned), Some(traitFullExpr.FSel("_clone").Apply1(R.self.Sel("as_ref").Apply0())) + ))])), + /* + impl DafnyPrint for Box { + fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { + self._fmt_print(f, in_seq) + } + }*/ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.DafnyPrint, + R.Box(R.DynType(traitFullType)), + [R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("fmt_print", [], fmt_print_parameters, + Some(fmt_print_result), + Some(traitFullExpr.FSel("_fmt_print").Apply([R.self.Sel("as_ref").Apply0(), R.Identifier("_formatter"), R.Identifier("in_seq")])) ))]))]; + s := s + [ + /* + impl PartialEq for Box { + fn eq(&self, other: &Self) -> bool { + Test::_eq(self.as_ref(), other) + } + } + impl Eq for Box {} + */ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.std.MSel("cmp").MSel("PartialEq").AsType(), + R.Box(R.DynType(traitFullType)), + [R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.SelfBorrowed)], + Some(R.Bool), + Some(traitFullExpr.FSel("_eq").Apply([R.self.Sel("as_ref").Apply0(), R.Identifier("other")])) + ))])), + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.std.MSel("cmp").MSel("Eq").AsType(), + R.Box(R.DynType(traitFullType)), + []))]; + s := s + [ + /* + impl Hash + for Box { + fn hash<_H: Hasher>(&self, _state: &mut _H) { + Test::_hash(self.as_ref()).hash(_state) + Hash::hash(&Test::_hash(self.as_ref()), _state) + } + } + */ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.Hash, + R.Box(R.DynType(traitFullType)), + [R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "hash", hash_type_parameters, + hash_parameters, + None, + Some(hash_function.Apply([R.Borrow(traitFullExpr.FSel("_hash").Apply1(R.self.Sel("as_ref").Apply0())), R.Identifier("_state")])) + ))])) + ]; } s := s + upcastImplemented; } @@ -645,23 +794,36 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var newtypeName := escapeName(c.name); var resultingType := R.TypeApp(R.TIdentifier(newtypeName), rTypeParams); var attributes: string; + var deriveTraits := ["Clone"]; if IsNewtypeCopy(c.range) { - attributes := "#[derive(Clone, PartialEq, Copy)]"; - } else { - attributes := "#[derive(Clone, PartialEq)]"; + deriveTraits := deriveTraits + ["Copy"]; } s := [ R.StructDecl( R.Struct( c.docString, [ - R.RawAttribute(attributes), - R.RawAttribute("#[repr(transparent)]") + R.ApplyAttribute("derive", deriveTraits), + R.ApplyAttribute("repr", ["transparent"]) ], newtypeName, rTypeParamsDecls, R.NamelessFields([R.NamelessField(R.PUB, wrappedType)]) ))]; + if c.equalitySupport.ConsultTypeArguments? { + var eqImplBody := + R.self.Sel("0").Equals(R.Identifier("other").Sel("0")); + var hashImplBody := + hash_function.Apply([R.Borrow(R.self.Sel("0")), R.Identifier("_state")]); + var impls := GenEqHashImpls( + c.typeParams, + rTypeParamsDecls, + rTypeParams, + resultingType, + eqImplBody, + hashImplBody); + s := s + impls; + } var fnBody; @@ -724,10 +886,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { "For Dafny print statements", R.NoAttr, R.PRIV, R.Fn("fmt_print", [], - [ R.Formal.selfBorrowed, - R.Formal("_formatter", R.BorrowedMut(R.std.MSel("fmt").MSel("Formatter").AsType())), - R.Formal("in_seq", R.Type.Bool)], - Some(R.std.MSel("fmt").MSel("Result").AsType()), + fmt_print_parameters, + Some(fmt_print_result), Some(R.dafny_runtime.MSel("DafnyPrint").AsExpr().FSel("fmt_print").Apply( [ R.Borrow(R.self.Sel("0")), R.Identifier("_formatter"), @@ -765,15 +925,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Block( //"The newtype is marked as transparent", R.std.MSel("mem").MSel("transmute").AsExpr().Apply1(R.Identifier("o")))))))]))]; - var rTypeParamsDeclsWithHash := R.TypeParamDecl.AddConstraintsMultiple( - rTypeParamsDecls, [R.Hash] - ); - s := s + [ - HashImpl( - rTypeParamsDeclsWithHash, - resultingType, - R.Identifier("self").Sel("0").Sel("hash").Apply1(R.Identifier("_state")) - )]; if c.range.HasArithmeticOperations() { s := s + [ OpsImpl('+', rTypeParamsDecls, resultingType, newtypeName), @@ -843,30 +994,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - predicate TypeIsEq(t: Type) - decreases t - { - match t - case UserDefined(_) => true // ResolvedTypes are assumed to support equality - case Tuple(ts) => forall t <- ts :: TypeIsEq(t) - case Array(t, _) => TypeIsEq(t) - case Seq(t) => TypeIsEq(t) - case Set(t) => TypeIsEq(t) - case Multiset(t) => TypeIsEq(t) - case Map(k, v) => TypeIsEq(k) && TypeIsEq(v) - case SetBuilder(t) => TypeIsEq(t) - case MapBuilder(k, v) => TypeIsEq(k) && TypeIsEq(v) - case Arrow(_, _) => false - case Primitive(_) => true - case Passthrough(_) => true // should be Rust primitive types - case TypeArg(i) => true // i(==) is asserted at the point of use by the verifier - case Object() => true - } - - predicate DatatypeIsEq(c: Datatype) { - !c.isCo && forall ctor <- c.ctors, arg <- ctor.args :: TypeIsEq(arg.formal.typ) - } - function write(r: R.Expr, final: bool := false): R.Expr { var result := R.Identifier("write!").Apply([ @@ -882,13 +1009,45 @@ module {:extern "DCOMP"} DafnyToRustCompiler { write(R.LiteralString(s, binary := false, verbatim := false)) } + /** eqImplBody assumes the existence of borrowed "self" and borrowed "other" */ + method GenEqHashImpls( + typeParamsDecls: seq, + rTypeParamsDecls: seq, + rTypeParams: seq, + datatypeType: R.Type, + eqImplBody: R.Expr, + hashImplBody: R.Expr + ) returns (impls: seq) + requires |typeParamsDecls| == |rTypeParamsDecls| == |rTypeParams| + { + var rTypeParamsDeclsWithEq := rTypeParamsDecls; + var rTypeParamsDeclsWithHash := rTypeParamsDecls; + for i := 0 to |rTypeParamsDecls| + invariant |rTypeParamsDeclsWithEq| == |rTypeParamsDecls| + invariant |rTypeParamsDeclsWithHash| == |rTypeParamsDecls| + { + if typeParamsDecls[i].info.necessaryForEqualitySupportOfSurroundingInductiveDatatype { + rTypeParamsDeclsWithEq := rTypeParamsDeclsWithEq[i := rTypeParamsDeclsWithEq[i].AddConstraints([R.Eq, R.Hash])]; + rTypeParamsDeclsWithHash := rTypeParamsDeclsWithHash[i := rTypeParamsDeclsWithHash[i].AddConstraints([R.Hash])]; + } + } + impls := EqImpl(rTypeParamsDeclsWithEq, datatypeType, rTypeParams, eqImplBody); + // Implementation of Hash trait + impls := impls + [ + HashImpl( + rTypeParamsDeclsWithHash, + datatypeType, + hashImplBody)]; + } + method GenDatatype(c: Datatype, path: seq) returns (s: seq) modifies this { + var isRcWrapped := IsRcWrapped(c.attributes); var typeParamsSeq, rTypeParams, rTypeParamsDecls := GenTypeParameters(c.typeParams); var datatypeName, extern := GetName(c.attributes, c.name, "datatypes"); var ctors: seq := []; - var variances := Std.Collections.Seq.Map((typeParamDecl: TypeArgDecl) => typeParamDecl.variance, c.typeParams); + var typeParamInfos := Std.Collections.Seq.Map((typeParamDecl: TypeArgDecl) => typeParamDecl.info, c.typeParams); var singletonConstructors := []; var usedTypeParams: set := {}; for i := 0 to |c.ctors| { @@ -897,7 +1056,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var isNumeric := false; if |ctor.args| == 0 { var instantiation := R.StructBuild(R.Identifier(datatypeName).FSel(escapeName(ctor.name)), []); - if IsRcWrapped(c.attributes) { + if isRcWrapped { instantiation := rcNew(instantiation); } singletonConstructors := singletonConstructors + [ @@ -943,7 +1102,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ResolvedType( selfPath, typeParamsSeq, - ResolvedTypeBase.Datatype(variances), + ResolvedTypeBase.Datatype(c.equalitySupport, typeParamInfos), c.attributes, [], [])), typeParamsSeq); var implBody: seq := implBodyRaw; @@ -1044,7 +1203,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var rTypeArg := GenType(typeArg, GenTypeContext.default()); types := types + [R.TypeApp(R.std.MSel("marker").MSel("PhantomData").AsType(), [rTypeArg])]; // Coercion arguments - if typeI < |variances| && variances[typeI].Nonvariant? { + if typeI < |typeParamInfos| && typeParamInfos[typeI].variance.Nonvariant? { coerceTypes := coerceTypes + [rTypeArg]; continue; // We ignore nonvariant arguments } @@ -1076,18 +1235,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )]; } } - - var cIsEq := DatatypeIsEq(c); + var cIsAlwaysEq := c.equalitySupport.ConsultTypeArguments? && + forall t <- c.typeParams :: !t.info.necessaryForEqualitySupportOfSurroundingInductiveDatatype; + var datatypeType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Derive PartialEq when c supports equality / derive Clone in all cases s := [R.EnumDecl( R.Enum( c.docString, - if cIsEq then - [R.RawAttribute("#[derive(PartialEq, Clone)]")] - else - [R.RawAttribute("#[derive(Clone)]")], + [R.Attribute.DeriveClone], datatypeName, rTypeParamsDecls, ctors @@ -1095,13 +1252,53 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplDecl( R.Impl( rTypeParamsDecls, - R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), + datatypeType, implBody ))]; + if |c.superTraitTypes| > 0 { // We will need to downcast + var fullType := if isRcWrapped then rc(datatypeType) else datatypeType; + var downcastDefinitionOpt := DowncastTraitDeclFor(rTypeParamsDecls, fullType); + if downcastDefinitionOpt.None? { + var dummy := Error("Could not generate downcast definition for " + fullType.ToString("")); + } else { + s := s + [downcastDefinitionOpt.value]; + } + var downcastImplementationsOpt := DowncastImplFor(rcNew, rTypeParamsDecls, fullType); + if downcastImplementationsOpt.None? { + var dummy := Error("Could not generate downcast implementation for " + fullType.ToString("")); + } else { + s := s + [downcastImplementationsOpt.value]; + } + for i := 0 to |c.superTraitNegativeTypes| { + var negativeTraitType := GenType(c.superTraitNegativeTypes[i], GenTypeContext.default()); + var downcastDefinitionOpt := DowncastNotImplFor(rTypeParamsDecls, negativeTraitType, fullType); + if downcastDefinitionOpt.None? { + var dummy := Error("Could not generate negative downcast definition for " + fullType.ToString("")); + } else { + s := s + [downcastDefinitionOpt.value]; + } + } + for i := 0 to |c.superTraitTypes| { + var c := c.superTraitTypes[i]; + if c.UserDefined? && c.resolved.kind.Trait? && |c.resolved.extendedTypes| == 0 { + continue; // No need to generate this Downcast implementation + } + var cType := GenType(c, GenTypeContext.default()); + // TODO: Gather also all trait that traits know they extend but are not among the traits the datatype extends. + var isImplementing := true; + var downcastImplementationsOpt := DowncastImplTraitFor(rTypeParamsDecls, cType, isImplementing, fullType); + if downcastImplementationsOpt.None? { + var dummy := Error("Could not generate downcast implementation of "+cType.ToString("")+" for " + fullType.ToString("")); + } else { + s := s + [downcastImplementationsOpt.value]; + } + } + } var printImplBodyCases: seq := []; var hashImplBodyCases: seq := []; var coerceImplBodyCases: seq := []; + var partialEqImplBodyCases: seq := []; for i := 0 to |c.ctors| { var ctor := c.ctors[i]; @@ -1114,10 +1311,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var printRhs := writeStr(ctorName + (if ctor.hasAnyArgs then "(" else "")); var hashRhs := InitEmptyExpr(); + var partialEqRhs := R.LiteralBool(true); var coerceRhsArgs := []; var isNumeric := false; var ctorMatchInner := ""; + var ctorMatchInner2 := ""; for j := 0 to |ctor.args| { var dtor := ctor.args[j]; var patternName := escapeVar(dtor.formal.name); @@ -1132,9 +1331,17 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if formalType.Arrow? then hashRhs.Then(R.LiteralInt("0").Sel("hash").Apply1(R.Identifier("_state"))) else - hashRhs.Then(R.std.MSel("hash").MSel("Hash").AsExpr().FSel("hash").Apply([R.Identifier(patternName), R.Identifier("_state")])); + hashRhs.Then(hash_function.Apply([R.Identifier(patternName), R.Identifier("_state")])); ctorMatchInner := ctorMatchInner + patternName + ", "; + var matchingVariable2 := prefixWith2(patternName); + var patternPrefix := if isNumeric then "" else patternName + ": "; + ctorMatchInner2 := ctorMatchInner2 + patternPrefix + matchingVariable2 + ", "; // field: _2_field, + partialEqRhs := + if formalType.Arrow? then + partialEqRhs.And(R.LiteralBool(false)) // No equality support for arrow + else + partialEqRhs.And(R.Identifier(patternName).Equals(R.Identifier(matchingVariable2))); if (j > 0) { printRhs := printRhs.Then(writeStr(", ")); @@ -1144,12 +1351,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if formalType.Arrow? then writeStr("") else - R.UnaryOp("?", - R.dafny_runtime.MSel("DafnyPrint").AsExpr().FSel("fmt_print").Apply([ - R.Identifier(patternName), - R.Identifier("_formatter"), - R.LiteralBool(false) - ]), Format.UnaryOpFormat.NoFormat) + R.UnaryOp( + "?", + R.dafny_runtime.MSel("DafnyPrint").AsExpr().FSel("fmt_print").Apply( + [ + R.Identifier(patternName), + R.Identifier("_formatter"), + R.LiteralBool(false) + ]), Format.UnaryOpFormat.NoFormat) ); var coerceRhsArg: R.Expr; @@ -1174,11 +1383,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var coerceRhs := R.StructBuild(R.Identifier(datatypeName).FSel(escapeName(ctor.name)), coerceRhsArgs); - + var pattern, pattern2; if isNumeric { - ctorMatch := ctorMatch + "(" + ctorMatchInner + ")"; + pattern := ctorMatch + "(" + ctorMatchInner + ")"; + pattern2 := ctorMatch + "(" + ctorMatchInner2 + ")"; } else { - ctorMatch := ctorMatch + "{" + ctorMatchInner + "}"; + pattern := ctorMatch + "{" + ctorMatchInner + "}"; + pattern2 := ctorMatch + "{" + ctorMatchInner2 + "}"; } if (ctor.hasAnyArgs) { @@ -1188,18 +1399,27 @@ module {:extern "DCOMP"} DafnyToRustCompiler { printRhs := printRhs.Then(R.Identifier("Ok").Apply([R.Tuple([])])); printImplBodyCases := printImplBodyCases + [ - R.MatchCase(R.RawPattern(datatypeName + "::" + ctorMatch), + R.MatchCase(R.RawPattern(datatypeName + "::" + pattern), R.Block(printRhs)) ]; hashImplBodyCases := hashImplBodyCases + [ - R.MatchCase(R.RawPattern(datatypeName + "::" + ctorMatch), + R.MatchCase(R.RawPattern(datatypeName + "::" + pattern), R.Block(hashRhs)) ]; + partialEqImplBodyCases := partialEqImplBodyCases + [ + R.MatchCase(R.RawPattern("(" + datatypeName + "::" + pattern + ", " + datatypeName + "::" + pattern2 + ")"), + R.Block(partialEqRhs)) + ]; coerceImplBodyCases := coerceImplBodyCases + [ - R.MatchCase(R.RawPattern(datatypeName + "::" + ctorMatch), + R.MatchCase(R.RawPattern(datatypeName + "::" + pattern), R.Block(coerceRhs)) ]; } + partialEqImplBodyCases := partialEqImplBodyCases + [ + R.MatchCase( + R.RawPattern("_"), + R.Block(R.LiteralBool(false))) + ]; if |c.typeParams| > 0 && |unusedTypeParams| > 0 { var extraCases := [ @@ -1214,12 +1434,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var defaultConstrainedTypeParams := R.TypeParamDecl.AddConstraintsMultiple( rTypeParamsDecls, [R.DefaultTrait] ); - var rTypeParamsDeclsWithEq := R.TypeParamDecl.AddConstraintsMultiple( - rTypeParamsDecls, [R.Eq] - ); - var rTypeParamsDeclsWithHash := R.TypeParamDecl.AddConstraintsMultiple( - rTypeParamsDecls, [R.Hash] - ); var printImplBody := R.Match( R.self, printImplBodyCases); @@ -1227,9 +1441,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.self, hashImplBodyCases ); + var eqImplBody := R.Match( + R.Tuple([R.self, R.Identifier("other")]), + partialEqImplBodyCases + ); // Implementation of Debug and Print traits - var datatypeType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); s := s + [ DebugImpl(rTypeParamsDecls, datatypeType, rTypeParams), PrintImpl(rTypeParamsDecls, datatypeType, rTypeParams, printImplBody) @@ -1245,7 +1462,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if |singletonConstructors| == |c.ctors| { var instantiationType := - if IsRcWrapped(c.attributes) then + if isRcWrapped then rc(datatypeType) else datatypeType; @@ -1253,26 +1470,17 @@ module {:extern "DCOMP"} DafnyToRustCompiler { SingletonsImpl(rTypeParamsDecls, datatypeType, instantiationType, singletonConstructors)]; } - // Implementation of Eq when c supports equality - if cIsEq { - s := s + [ - R.ImplDecl( - R.ImplFor( - rTypeParamsDeclsWithEq, - R.Eq, - R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), - [] - ) - )]; + if c.equalitySupport.ConsultTypeArguments? { + var impls := GenEqHashImpls( + c.typeParams, + rTypeParamsDecls, + rTypeParams, + datatypeType, + eqImplBody, + hashImplBody); + s := s + impls; } - // Implementation of Hash trait - s := s + [ - HashImpl( - rTypeParamsDeclsWithHash, - R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), - hashImplBody)]; - if |c.ctors| > 0 { var structName := R.Identifier(datatypeName).FSel(escapeName(c.ctors[0].name)); var structAssignments: seq := []; @@ -1284,14 +1492,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.std.MSel("default").MSel("Default").AsExpr().FSel("default").Apply0()) ]; } - var fullType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Implementation of Default trait when c supports equality - if cIsEq { + if false && cIsAlwaysEq { // We don't emit default because datatype defaults are broken. + // - There should be no default when an argument is a lambda + // - There is no possiblity to define witness for datatypes so that we know if it's (0) or (00) + // - General traits don't have defaults but can be wrapped in datatypes and datatypes are assumed to have default values always + // Default values are not used in --enforce-determinism anyway, only placebos values are useful and they are implemented with + // a custom option type. + // Leaving this code here for when datatypes' defaults will be fixed s := s + [ DefaultDatatypeImpl( rTypeParamsDecls, - fullType, + datatypeType, structName, structAssignments)]; } @@ -1300,7 +1513,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := s + [ AsRefDatatypeImpl( rTypeParamsDecls, - fullType + datatypeType )]; } var superTraitImplementations := GenTraitImplementations( @@ -1310,6 +1523,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { c.superTraitTypes, traitBodies, extern, + cIsAlwaysEq, "datatype"); s := s + superTraitImplementations; } @@ -1365,12 +1579,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - predicate IsRcWrapped(attributes: seq) { - (Attribute("auto-nongrowing-size", []) !in attributes && - Attribute("rust_rc", ["false"]) !in attributes) || - Attribute("rust_rc", ["true"]) in attributes - } - /** The type context is useful in the case when we need to generate a type in a position that requires a variant of the given type. @@ -1400,7 +1608,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Class() => { s := Object(s); } - case Datatype(_) => { + case Datatype(_, _) => { if IsRcWrapped(resolved.attributes) { s := rc(s); } @@ -1568,14 +1776,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } // Transform DAST formals to Rust formals - method GenParams(params: seq, forLambda: bool := false) returns (s: seq) + method GenParams(params: seq, inheritedParams: seq := params, forLambda: bool := false) returns (s: seq) ensures |s| == |params| { s := []; for i := 0 to |params| invariant |s| == i && i <= |params| { var param := params[i]; + var inheritedParam := if i < |inheritedParams| then inheritedParams[i] else param; var paramType := GenType(param.typ, GenTypeContext.default()); - if (!paramType.CanReadWithoutClone() || forLambda) && AttributeOwned !in param.attributes { + var inheritedParamType := GenType(inheritedParam.typ, GenTypeContext.default()); + if (!inheritedParamType.CanReadWithoutClone() || forLambda) && AttributeOwned !in param.attributes { paramType := R.Borrowed(paramType); } s := s + [R.Formal(escapeVar(param.name), paramType)]; @@ -1585,7 +1795,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenMethod(m: Method, forTrait: bool, enclosingType: Type, enclosingTypeParams: seq) returns (s: R.ImplMember) modifies this { - var params: seq := GenParams(m.params); + var params: seq := GenParams(m.params, m.inheritedParams); var paramNames := []; var paramTypes := map[]; for paramI := 0 to |m.params| { @@ -1623,12 +1833,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else if selfId == "self" { if tpe.IsObjectOrPointer() { // For classes and traits tpe := R.SelfBorrowed; - } else { // For Rc-defined datatypes - if enclosingType.UserDefined? && enclosingType.resolved.kind.Datatype? - && IsRcWrapped(enclosingType.resolved.attributes) { - tpe := R.Borrowed(rc(R.SelfOwned)); - } else if enclosingType.UserDefined? && enclosingType.resolved.kind.Newtype? - && IsNewtypeCopy(enclosingType.resolved.kind.range) { + } else { + if enclosingType.UserDefined? && enclosingType.resolved.kind.Newtype? + && IsNewtypeCopy(enclosingType.resolved.kind.range) + && !forTrait { tpe := R.TMetaData( R.SelfOwned, copySemantics := true, @@ -1913,8 +2121,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - @IsolateAssertions @ResourceLimit("1e6") - method GenOwnedCallPart(ghost e: Expression, on: Expression, selfIdent: SelfInfo, name: CallName, typeArgs: seq, args: seq, env: Environment) returns (r: R.Expr, readIdents: set) + const rcDatatypeThis: R.Expr + const borrowedRcDatatypeThis: R.Expr + + // General borrow include &Box, but for dynamic dispatch we need &dyn Type + function FromGeneralBorrowToSelfBorrow(onExpr: R.Expr, onExprOwnership: Ownership, env: Environment): R.Expr { + if onExpr.Identifier? && env.NeedsAsRefForBorrow(onExpr.name) then + onExpr.Sel("as_ref").Apply0() // It's not necessarily the trait, it's usually Box::as_ref or Rc::as_ref + else if onExpr == R.self || onExpr == rcDatatypeThis || onExpr == borrowedRcDatatypeThis then + R.self + else if onExprOwnership.OwnershipBorrowed? then + // If the resulting expression is a borrow, e.g. &something() or datatype.field(), it means the trait was owned. + // In our case we want dynamic dispatch, so we need to get the bare reference. + // Because "on" is a general trait, we need to call as_ref() instead to get the bare expression + // If "on" was a field extraction, then the field is borrowed as well. + R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(onExpr) + else + onExpr + } + + method GenCall(ghost e: Expression, on: Expression, selfIdent: SelfInfo, name: CallName, typeArgs: seq, args: seq, env: Environment) returns (r: R.Expr, readIdents: set) requires forall a <- args :: a < e requires on < e modifies this @@ -1923,6 +2149,11 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var argExprs, recIdents, typeExprs, fullNameQualifier := GenArgs(e, selfIdent, name, typeArgs, args, env); readIdents := recIdents; + if selfIdent.IsSelf() && name.CallName? && name.receiverArg.Some? && |argExprs| > 0 && R.IsBorrowUpcastBox(argExprs[0]) { + // The first argument is self and should not need conversion if it was applied as it should be passed raw. + argExprs := [R.Identifier("self")] + argExprs[1..]; + } + match fullNameQualifier { // Trait calls are fully specified as we can't guarantee traits will be in context case Some(ResolvedType(path, onTypeArgs, base, _, _, _)) => @@ -1938,17 +2169,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // General traits borrow their self, from a Box // The underlying type is a Box, self: Datatype or Rc // 'on' is going to return an owned version of this box. - onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); - if onExpr.Identifier? && env.NeedsAsRefForBorrow(onExpr.name) { - onExpr := onExpr.Sel("as_ref").Apply0(); - } else if onExpr.IsBorrow() { - // If the resulting expression is a borrow, e.g. &something(), it means the trait was owned. - // In our case we want dynamic dispatch, so we need to get the bare reference. - // Because "on" is a general trait, we need to call as_ref() instead to get the bare expression - // If the onExpr is an identifier but not "self", we apply the same treatment - onExpr := R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(onExpr); + + if on.IsThisUpcast() { + // Special case, in Rust, we don't need to upcast "self" because upcasted methods are automatically available + onExpr := R.self; // Already self borrow + readIdents := readIdents + {"self"}; + } else { + onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + onExpr := FromGeneralBorrowToSelfBorrow(onExpr, recOwnership, env); + readIdents := readIdents + recIdents; } - readIdents := readIdents + recIdents; } else if base.Newtype? && IsNewtypeCopy(base.range) { // The self type of a newtype that is copy is also copy onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); @@ -1956,11 +2186,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else { // The self type of any other type is borrowed onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + onExpr := FromGeneralBorrowToSelfBorrow(onExpr, recOwnership, env); readIdents := readIdents + recIdents; } r := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); - case _ => // Infix call on.name(args) - var onExpr, _, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + case _ => // Infix call on.name(args) or Companion::name(args) + var onExpr, recIdents, dummy; + if on.IsThisUpcast() { + // Special case, in Rust, we don't need to upcast "self" because upcasted methods are automatically available + onExpr := R.self; // Already self borrow + recIdents := {"self"}; + } else { + onExpr, dummy, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + } readIdents := readIdents + recIdents; var renderedName := GetMethodName(on, name); // Pointers in the role of "self" must be converted to borrowed versions. @@ -2000,9 +2238,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var fieldName := escapeVar(field.formal.name); var fieldTyp := GenType(field.formal.typ, GenTypeContext.default()); var isAssignedVar := AddAssignedPrefix(fieldName); - if isAssignedVar in newEnv.names { - assume {:axiom} InitializationValue(field.formal.typ) < stmt; // Needed for termination - var rhs, _, _ := GenExpr(InitializationValue(field.formal.typ), selfIdent, env, OwnershipOwned); + if isAssignedVar in newEnv.names { // We can't determine statically if the field was assigned + var panicked := "Field "+ fieldName +" is not initialized"; + var rhs := UnreachablePanicIfVerified(pointerType, panicked); readIdents := readIdents + {isAssignedVar}; var update_if_uninit := if field.isConstant then update_field_if_uninit_macro else update_field_mut_if_uninit_macro; @@ -2078,7 +2316,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := readIdents + thnIdents; var els, elsIdents, elsEnv := GenStmts(elsDafny, selfIdent, env, isLast, earlyReturn); readIdents := readIdents + elsIdents; - newEnv := env; + + // All variables that both thnEnv and elsEnv remove can be removed from the environment + newEnv := env.Join(thnEnv, elsEnv); generated := R.IfExpr(cond, thn, els); } case Labeled(lbl, body) => { @@ -2171,8 +2411,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } case Call(on, name, typeArgs, args, maybeOutVars) => { assume {:axiom} Expression.Call(on, name, typeArgs, args) < stmt; - generated, readIdents := GenOwnedCallPart(Expression.Call(on, name, typeArgs, args), on, selfIdent, name, typeArgs, args, env); - + generated, readIdents := GenCall(Expression.Call(on, name, typeArgs, args), on, selfIdent, name, typeArgs, args, env); newEnv := env; if maybeOutVars.Some? && |maybeOutVars.value| == 1 { var outVar := escapeVar(maybeOutVars.value[0]); @@ -2639,9 +2878,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + method GenExprConvertTo( + expr: R.Expr, + exprOwnership: Ownership, + fromTpeWithSynonyms: Type, + toTpeWithSynonyms: Type, + env: Environment, + expectedOwnership: Ownership + ) returns (r: R.Expr, resultingOwnership: Ownership) + requires exprOwnership != OwnershipAutoBorrowed + modifies this + ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) + { + var fromTpe := fromTpeWithSynonyms.RemoveSynonyms(); + var toTpe := toTpeWithSynonyms.RemoveSynonyms(); + r, resultingOwnership := GenExprConvertToWithoutSynonyms(expr, exprOwnership, fromTpe, toTpe, env, expectedOwnership); + } + // To use when we know that the expression is a Convert(_, _, toTpe) // and toTpe is a newtype - method GenExprConvertTo( + method GenExprConvertToWithoutSynonyms( expr: R.Expr, exprOwnership: Ownership, fromTpe: Type, @@ -2655,29 +2911,22 @@ module {:extern "DCOMP"} DafnyToRustCompiler { decreases fromTpe, toTpe // We unwrap newtypes { r := expr; + // For conversion purpose, synonyms are not desired if fromTpe == toTpe { r, resultingOwnership := FromOwnership(r, exprOwnership, expectedOwnership); return; } - if fromTpe.UserDefined? && fromTpe.resolved.kind.SynonymType? { - r, resultingOwnership := GenExprConvertTo(expr, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, env, expectedOwnership); - return; - } - if toTpe.UserDefined? && toTpe.resolved.kind.SynonymType? { - r, resultingOwnership := GenExprConvertTo(expr, exprOwnership, fromTpe, toTpe.resolved.kind.baseType, env, expectedOwnership); - return; - } if NeedsUnwrappingConversion(fromTpe) { // From type is a newtype but it's not a primitive one. r := UnwrapNewtype(r, exprOwnership, fromTpe); r, resultingOwnership := - GenExprConvertTo(r, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, env, expectedOwnership); + GenExprConvertToWithoutSynonyms(r, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, env, expectedOwnership); return; } if NeedsUnwrappingConversion(toTpe) { var toKind := toTpe.resolved.kind; r, resultingOwnership := - GenExprConvertTo(r, exprOwnership, fromTpe, toKind.baseType, env, expectedOwnership); + GenExprConvertToWithoutSynonyms(r, exprOwnership, fromTpe, toKind.baseType, env, expectedOwnership); r := WrapWithNewtype(r, resultingOwnership, toTpe); r, resultingOwnership := FromOwnership(r, resultingOwnership, expectedOwnership); return; @@ -2850,25 +3099,27 @@ module {:extern "DCOMP"} DafnyToRustCompiler { else if SameTypesButDifferentTypeParameters(fromType, fromTpe, toType, toTpe) then var indices := if fromType.UserDefined? && fromType.resolved.kind.Datatype? then - Std.Collections.Seq.Filter(i => - if 0 <= i < |fromTpe.arguments| then - (0 <= i < |fromType.resolved.kind.variances| ==> - !fromType.resolved.kind.variances[i].Nonvariant?) - else - false - , seq(|fromTpe.arguments|, i => i)) + Std.Collections.Seq.Filter( + i => + if 0 <= i < |fromTpe.arguments| then + (0 <= i < |fromType.resolved.kind.info| ==> + !fromType.resolved.kind.info[i].variance.Nonvariant?) + else + false + , seq(|fromTpe.arguments|, i => i)) else seq(|fromTpe.arguments|, i => i); - var lambdas :- SeqResultToResultSeq( - seq(|indices|, j requires 0 <= j < |indices| => - var i := indices[j]; - UpcastConversionLambda( - fromType.resolved.typeArgs[i], - fromTpe.arguments[i], - toType.resolved.typeArgs[i], - toTpe.arguments[i], - typeParams - ))); + var lambdas :- + SeqResultToResultSeq( + seq(|indices|, j requires 0 <= j < |indices| => + var i := indices[j]; + UpcastConversionLambda( + fromType.resolved.typeArgs[i], + fromTpe.arguments[i], + toType.resolved.typeArgs[i], + toTpe.arguments[i], + typeParams + ))); Success(R.ExprFromType(fromTpe.baseName).ApplyType( seq(|fromTpe.arguments|, i requires 0 <= i < |fromTpe.arguments| => fromTpe.arguments[i]) @@ -2927,14 +3178,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { underlying else underlying.Clone() // Auto-borrow allows for implicit code - case _ => expr.Clone() + case _ => + expr.Clone() } method GenExprConvertOther( expr: R.Expr, exprOwnership: Ownership, - fromTpe: Type, - toTpe: Type, + fromTyp: Type, + toTyp: Type, env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership) @@ -2944,14 +3196,67 @@ module {:extern "DCOMP"} DafnyToRustCompiler { { r := expr; resultingOwnership := exprOwnership; - var fromTpeGen := GenType(fromTpe, GenTypeContext.default()); - var toTpeGen := GenType(toTpe, GenTypeContext.default()); - var upcastConverter := UpcastConversionLambda(fromTpe, fromTpeGen, toTpe, toTpeGen, map[]); + var fromTpeGen := GenType(fromTyp, GenTypeContext.default()); + var toTpeGen := GenType(toTyp, GenTypeContext.default()); + + var isDatatype := toTyp.IsDatatype(); + var isGeneralTrait := !isDatatype && toTyp.IsGeneralTrait(); + if isDatatype || isGeneralTrait { + var isDowncast := toTyp.Extends(fromTyp); + if isDowncast { + var underlyingType := if isDatatype then toTyp.GetDatatypeType() else toTyp.GetGeneralTraitType(); + var toTpeRaw := GenType(underlyingType, GenTypeContext.default()); + var toTpeRawDowncastOpt: Option := toTpeRaw.ToDowncastExpr(); + if toTpeRawDowncastOpt.Some? { + var newExpr := expr; + if exprOwnership.OwnershipOwned? { + match newExpr { + case Call(Select(Identifier(name), "clone"), arguments) => + if |arguments| == 0 { + newExpr := R.Identifier(name); + if !env.IsBorrowed(name) { + newExpr := R.Borrow(newExpr); + } + } else { + newExpr, resultingOwnership := FromOwnership(newExpr, OwnershipOwned, OwnershipBorrowed); + } + case _ => { + newExpr, resultingOwnership := FromOwnership(newExpr, OwnershipOwned, OwnershipBorrowed); + } + } + } + newExpr := FromGeneralBorrowToSelfBorrow(newExpr, OwnershipBorrowed, env); + if isDatatype { + newExpr := R.dafny_runtime.MSel("AnyRef").AsExpr().FSel("as_any_ref").Apply1(newExpr); + } + r := toTpeRawDowncastOpt.value.FSel("_as").Apply1(newExpr); + r, resultingOwnership := FromOwnership(r, OwnershipOwned, expectedOwnership); + return; + } else { + r := Error("Could not convert " + toTpeRaw.ToString("") + " to a Downcast trait"); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; + } + } + } + var upcastConverter := UpcastConversionLambda(fromTyp, fromTpeGen, toTyp, toTpeGen, map[]); if upcastConverter.Success? { var conversionLambda := upcastConverter.value; if resultingOwnership == OwnershipBorrowed { - // we need the value to be owned for conversion - r := BorrowedToOwned(r, env); + if fromTyp.IsGeneralTrait() && r == R.Identifier("self") { + // The self in this case does not implement the clone method, we need to call _clone from the trait + // Similar to the code at the end of GenIdent() + var traitType := GenType(fromTyp, GenTypeContext.ForTraitParents()); + var traitExpr := traitType.ToExpr(); + if traitExpr.None? { + r := Error("Could not convert " + traitType.ToString("") + " to an expression"); + } else { + r := traitExpr.value.FSel("_clone").Apply1(r); + } + } else { + // we need the value to be owned for conversion + r := BorrowedToOwned(r, env); + } resultingOwnership := OwnershipOwned; } r := conversionLambda.Apply1(r); @@ -3035,23 +3340,37 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } resultingOwnership := OwnershipBorrowedMut; } else if expectedOwnership == OwnershipOwned { - var needObjectFromRef := - isSelf && - match selfIdent.dafnyType { - case UserDefined(ResolvedType(_, _, base, attributes, _, _)) => - base.Class? || (base.Trait? && base.traitType.ObjectTrait?) - case _ => false - }; - if needObjectFromRef { + var needsObjectFromRef := isSelf && selfIdent.IsClassOrObjectTrait(); + var needsRcWrapping := isSelf && selfIdent.IsRcWrappedDatatype(); + if needsObjectFromRef { r := R.dafny_runtime.MSel("Object").AsExpr().ApplyType([R.TIdentifier("_")]).FSel("from_ref").Apply([r]); + } else if needsRcWrapping { + r := rcNew(r.Clone()); } else { if !noNeedOfClone { - r := r.Clone(); // We don't transfer the ownership of an identifier + var needUnderscoreClone := isSelf && selfIdent.IsGeneralTrait(); + if needUnderscoreClone { + // In the case when self: &Self and self is a general trait, self.Clone() == self so it's useless. + // What we need is to build self._clone(), and since _clone() can be ambiguous, we need the full trait type instead. + var traitType := GenType(selfIdent.dafnyType, GenTypeContext.ForTraitParents()); + var traitExpr := traitType.ToExpr(); + if traitExpr.None? { + r := Error("Could not convert " + traitType.ToString("") + " to an expression"); + } else { + r := traitExpr.value.FSel("_clone").Apply1(r); + } + } else { + r := r.Clone(); // We don't transfer the ownership of an identifier + } } } resultingOwnership := OwnershipOwned; } else if currentlyBorrowed { assert expectedOwnership == OwnershipBorrowed; + var needsRcWrapping := isSelf && selfIdent.IsRcWrappedDatatype(); + if needsRcWrapping { + r := R.Borrow(rcNew(r.Clone())); + } resultingOwnership := OwnershipBorrowed; } else { assert expectedOwnership == OwnershipBorrowed; @@ -3095,18 +3414,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { { argExprs := []; readIdents := {}; - var signature := - if name.CallName? then - if name.receiverArg.Some? && name.receiverAsArgument then - [name.receiverArg.value] + name.signature.parameters - else - name.signature.parameters - else - []; + var borrowSignature; + if name.CallName? { + if name.receiverArg.Some? && name.receiverAsArgument { + borrowSignature := [name.receiverArg.value] + name.signature.inheritedParams; + } else { + borrowSignature := name.signature.inheritedParams; + } + } else { + borrowSignature := []; + } for i := 0 to |args| { var argOwnership := OwnershipBorrowed; - if i < |signature| { - var tpe := GenType(signature[i].typ, GenTypeContext.default()); + if i < |borrowSignature| { + var tpe := GenType(borrowSignature[i].typ, GenTypeContext.default()); // Take the typ from the signature, but ownership from the trait. if tpe.CanReadWithoutClone() { argOwnership := OwnershipOwned; } @@ -3308,10 +3629,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var typeExpr := GenType(typeArgs[i], GenTypeContext.default()); genTypeArgs := genTypeArgs + [typeExpr]; } + r := r.FSel(escapeName(variant)); if |typeArgs| > 0 { r := r.ApplyType(genTypeArgs); } - r := r.FSel(escapeName(variant)); readIdents := {}; var assignments: seq := []; @@ -3447,47 +3768,54 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r, resultingOwnership := FromOwned(r, expectedOwnership); return; } - case MapValue(mapElems) => { + case MapValue(mapElems, rangeType, domainType) => { var generatedValues := []; readIdents := {}; - var i := 0; - while i < |mapElems| { + for i := 0 to |mapElems| { var recursiveGenKey, _, recIdentsKey := GenExpr(mapElems[i].0, selfIdent, env, OwnershipOwned); var recursiveGenValue, _, recIdentsValue := GenExpr(mapElems[i].1, selfIdent, env, OwnershipOwned); generatedValues := generatedValues + [(recursiveGenKey, recursiveGenValue)]; readIdents := readIdents + recIdentsKey + recIdentsValue; - i := i + 1; } - i := 0; var arguments := []; - while i < |generatedValues| { + for i := 0 to |generatedValues| { var genKey := generatedValues[i].0; var genValue := generatedValues[i].1; arguments := arguments + [R.BinaryOp("=>", genKey, genValue, DAST.Format.BinaryOpFormat.NoFormat())]; - i := i + 1; } r := R.dafny_runtime.MSel("map!").AsExpr().Apply(arguments); + if |generatedValues| == 0 { // Rust cannot infer the type + var rangeTpe := GenType(rangeType, GenTypeContext.default()); + var domainTpe := GenType(domainType, GenTypeContext.default()); + r := R.TypeAscription( + r, R.dafny_runtime.MSel("Map").AsType().Apply([rangeTpe, domainTpe]) + ); + } r, resultingOwnership := FromOwned(r, expectedOwnership); return; } - case SeqUpdate(expr, index, value) => { + case SeqUpdate(expr, index, value, collectionType, exprType) => { var exprR, _, exprIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); var indexR, indexOwnership, indexIdents := GenExpr(index, selfIdent, env, OwnershipBorrowed); var valueR, valueOwnership, valueIdents := GenExpr(value, selfIdent, env, OwnershipBorrowed); r := exprR.Sel("update_index").Apply([indexR, valueR]); - r, resultingOwnership := FromOwned(r, expectedOwnership); + // if exprType is a newtype, autoderef will take care of calling this method + // However, we need to convert the result back to the newtype + r, resultingOwnership := GenExprConvertTo(r, OwnershipOwned, collectionType, exprType, env, expectedOwnership); readIdents := exprIdents + indexIdents + valueIdents; return; } - case MapUpdate(expr, index, value) => { + case MapUpdate(expr, index, value, collectionType, exprType) => { var exprR, _, exprIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); var indexR, indexOwnership, indexIdents := GenExpr(index, selfIdent, env, OwnershipBorrowed); var valueR, valueOwnership, valueIdents := GenExpr(value, selfIdent, env, OwnershipBorrowed); r := exprR.Sel("update_index").Apply([indexR, valueR]); - r, resultingOwnership := FromOwned(r, expectedOwnership); + // if exprType is a newtype, autoderef will take care of calling this method + // However, we need to convert the result back to the newtype + r, resultingOwnership := GenExprConvertTo(r, OwnershipOwned, collectionType, exprType, env, expectedOwnership); readIdents := exprIdents + indexIdents + valueIdents; return; } @@ -3495,6 +3823,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { match selfIdent { case ThisTyped(id, dafnyType) => { r, resultingOwnership, readIdents := GenIdent(id, selfIdent, env, expectedOwnership); + return; } case None => { r := Error("this outside of a method"); @@ -3662,7 +3991,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := recIdents; return; } - case Select(on, field, fieldMutability, isDatatype, fieldType) => { + case Select(on, field, fieldMutability, selectContext, fieldType) => { if on.Companion? || on.ExternCompanion? { var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); @@ -3672,7 +4001,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; - } else if isDatatype { + } else if selectContext.SelectContextDatatype? { var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); // onExpr.field() r := onExpr.Sel(escapeVar(field)).Apply0(); @@ -3688,6 +4017,23 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // All fields are returned as addresses for now until we have something more clever r, resultingOwnership := FromOwnership(r, originalMutability, expectedOwnership); readIdents := recIdents; + } else if selectContext.SelectContextGeneralTrait? { + var onOwned, recIdents; + readIdents := {}; + if on.IsThisUpcast() { + // Special case, in Rust, we don't need to upcast "self" because upcasted methods are automatically available + r := R.self; // Already self borrow + recIdents := {"self"}; + } else { + r, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + if r != R.self { + r := R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(r); + } + } + readIdents := readIdents + recIdents; + r := r.Sel(escapeVar(field)).Apply0(); + r, resultingOwnership := FromOwned(r, expectedOwnership); + readIdents := recIdents; } else { var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); r := onExpr; @@ -3819,12 +4165,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case Call(on, name, typeArgs, args) => { - r, readIdents := GenOwnedCallPart(e, on, selfIdent, name, typeArgs, args, env); + r, readIdents := GenCall(e, on, selfIdent, name, typeArgs, args, env); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case Lambda(paramsDafny, retType, body) => { - var params := GenParams(paramsDafny, true); + var params := GenParams(paramsDafny, forLambda := true); var paramNames := []; var paramTypesMap := map[]; for i := 0 to |params| { @@ -3832,7 +4178,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { paramNames := paramNames + [name]; paramTypesMap := paramTypesMap[name := params[i].tpe]; } - var subEnv := env.ToOwned().merge(Environment(paramNames, paramTypesMap, {})); + var subEnv := env.ToOwned().Merge(Environment(paramNames, paramTypesMap, {})); var recursiveGen, recIdents, _ := GenStmts(body, if selfIdent != NoSelf then ThisTyped("_this", selfIdent.dafnyType) else NoSelf, subEnv, true, None); readIdents := {}; @@ -3936,18 +4282,43 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := recIdents; return; } - case Is(expr, fromType, toType) => { - var expr, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - var fromType := GenType(fromType, GenTypeContext.default()); - var toType := GenType(toType, GenTypeContext.default()); - if fromType.IsObjectOrPointer() && toType.IsObjectOrPointer() { - r := expr.Sel("is_instance_of").ApplyType([toType.ObjectOrPointerUnderlying()]).Apply0(); + case Is(expr, fromTyp, toTyp) => { + var fromTpe := GenType(fromTyp, GenTypeContext.default()); + var toTpe := GenType(toTyp, GenTypeContext.default()); + if fromTpe.IsObjectOrPointer() && toTpe.IsObjectOrPointer() { + var expr, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); + r := expr.Sel("is_instance_of").ApplyType([toTpe.ObjectOrPointerUnderlying()]).Apply0(); + r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + readIdents := recIdents; } else { - r := Error("Source and/or target types of type test is/are not Object or Ptr"); - readIdents := {}; + var expr, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipBorrowed); + var isDatatype := toTyp.IsDatatype(); + var isGeneralTrait := !isDatatype && toTyp.IsGeneralTrait(); + if isDatatype || isGeneralTrait { // TODO: Detect downcast/upcast + var isDowncast := toTyp.Extends(fromTyp); + if isDowncast { + var underlyingType := if isDatatype then toTyp.GetDatatypeType() else toTyp.GetGeneralTraitType(); + var toTpeRaw := GenType(underlyingType, GenTypeContext.default()); + var toTpeRawDowncastOpt: Option := toTpeRaw.ToDowncastExpr(); + if toTpeRawDowncastOpt.Some? { + expr := FromGeneralBorrowToSelfBorrow(expr, OwnershipBorrowed, env); + if isDatatype { + expr := R.dafny_runtime.MSel("AnyRef").AsExpr().FSel("as_any_ref").Apply1(expr); + } + r := toTpeRawDowncastOpt.value.FSel("_is").Apply1(expr); + recOwned := OwnershipOwned(); + } else { + r := Error("Could not convert " + toTpeRaw.ToString("") + " to a Downcast trait"); + } + } else { + r := Error("Needs support for upcasting general traits"); + } + } else { + r := Error("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"); + } + r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + readIdents := recIdents; } - r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); - readIdents := recIdents; return; } case BoolBoundedPool() => { diff --git a/Source/DafnyCore/Backends/Rust/RustBackend.cs b/Source/DafnyCore/Backends/Rust/RustBackend.cs index 8a6c3e8e50a..6e948c748b8 100644 --- a/Source/DafnyCore/Backends/Rust/RustBackend.cs +++ b/Source/DafnyCore/Backends/Rust/RustBackend.cs @@ -97,7 +97,11 @@ public override async Task OnPostGenerate(string dafnyProgramName, string foreach (var keyValue in ImportFilesMapping(dafnyProgramName)) { var fullRustExternName = keyValue.Key; var expectedRustName = keyValue.Value; - File.Copy(fullRustExternName, Path.Combine(targetDirectory, expectedRustName), true); + var targetName = Path.Combine(targetDirectory, expectedRustName); + if (fullRustExternName == targetName) { + return true; + } + File.Copy(fullRustExternName, targetName, true); } if (Options.IncludeRuntime) { diff --git a/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs b/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs index b3a35ea5f96..10424e22074 100644 --- a/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs @@ -39,6 +39,20 @@ public override void Compile(Sequence program, Sequence false; } protected virtual bool SupportsStaticsInGenericClasses => true; protected virtual bool TraitRepeatsInheritedDeclarations => false; - protected virtual bool InstanceMethodsAllowedToCallTraitMethods => true; + protected virtual bool InstanceMethodsCanOnlyCallOverridenTraitMethods => false; protected IClassWriter CreateClass(string moduleName, TopLevelDecl cls, ConcreteSyntaxTree wr) { return CreateClass(moduleName, false, null, cls.TypeArgs, cls, (cls as TopLevelDeclWithMembers)?.ParentTypeInformation.UniqueParentTraits(), null, wr); @@ -1439,6 +1439,14 @@ protected virtual void CompileBinOp(BinaryExpr.ResolvedOpcode op, /// protected abstract void EmitTypeTest(string localName, Type fromType, Type toType, IOrigin tok, ConcreteSyntaxTree wr); + + protected virtual void EmitTypeTestExpr(Expression expr, Type fromType, Type toType, IOrigin tok, + bool inLetExprBody, ConcreteSyntaxTree wr, ref ConcreteSyntaxTree wStmts) { + var name = $"_is_{GetUniqueAstNumber(expr)}"; + wr = CreateIIFE_ExprBody(name, fromType, tok, expr, inLetExprBody, Type.Bool, expr.Origin, wr, ref wStmts); + EmitTypeTest(name, fromType, toType, tok, wr); + } + /// /// Emit a conjunct that tests if the Dafny real number "source" is an integer, like: /// "TestIsInteger(source) && " @@ -1618,14 +1626,13 @@ private void EmitModule(Program program, ConcreteSyntaxTree programNode, ModuleD bool externP = Attributes.Contains(at.Attributes, "extern"); if (externP) { var exprs = Attributes.FindExpressions(at.Attributes, "extern"); - Contract.Assert(exprs != null); // because externP is true - if (exprs.Count == 1) { - DeclareExternType(at, exprs[0], wr); - } else { - Error(ErrorId.c_abstract_type_needs_hint, d.Origin, - "Abstract type ('{0}') with extern attribute requires a compile hint. Expected {{:extern compile_type_hint}}", - wr, at.FullName); + if (exprs == null || exprs.Count == 0) { + exprs = new List() { + Expression.CreateStringLiteral(Token.NoToken, at.Name) + }; } + Contract.Assert(exprs != null); // because externP is true + DeclareExternType(at, exprs[0], wr); v.Visit(exprs); } else { @@ -2075,7 +2082,7 @@ seqType.Arg.AsSeqType is not { } subSeqType || return true; } - void OrderedBySCC(List decls, TopLevelDeclWithMembers c) { + protected void OrderedBySCC(List decls, TopLevelDeclWithMembers c) { List consts = []; foreach (var decl in decls) { if (decl is ConstantField) { @@ -2159,9 +2166,9 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite if (c is not TraitDecl || TraitRepeatsInheritedDeclarations) { thisContext = c; - var canRedeclareMemberDefinedInTrait = c is not ClassLikeDecl and not DatatypeDecl and not NewtypeDecl || - InstanceMethodsAllowedToCallTraitMethods; foreach (var member in inheritedMembers.Select(memberx => (memberx as Function)?.ByMethodDecl ?? memberx)) { + var canRedeclareMemberDefinedInTrait = c is not ClassLikeDecl and not DatatypeDecl and not NewtypeDecl || + !InstanceMethodsCanOnlyCallOverridenTraitMethods || member.IsOverrideThatAddsBody; enclosingDeclaration = member; Contract.Assert(!member.IsStatic); // only instance members should ever be added to .InheritedMembers if (member.IsGhost) { @@ -2169,25 +2176,29 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite } else if (c is TraitDecl) { RedeclareInheritedMember(member, classWriter); } else if (member is ConstantField) { - var cf = (ConstantField)member; - var cfType = cf.Type.Subst(c.ParentFormalTypeParametersToActuals); - if (cf.Rhs == null && c is ClassLikeDecl) { - // create a backing field, since this constant field may be assigned in constructors - Contract.Assert(!cf.IsStatic); // as checked above, only instance members can be inherited - classWriter.DeclareField(InternalFieldPrefix + cf.GetCompileName(Options), c, false, false, cfType, cf.Origin, PlaceboValue(cfType, errorWr, cf.Origin, true), cf); - } - var w = CreateFunctionOrGetter(cf, IdName(cf), c, false, true, true, classWriter); - Contract.Assert(w != null); // since the previous line asked for a body - if (cf.Rhs != null) { - EmitCallToInheritedConstRHS(cf, w); - } else if (!cf.IsStatic && c is ClassLikeDecl) { - var sw = EmitReturnExpr(w); - sw = EmitCoercionIfNecessary(cfType, cf.Type, cf.Origin, sw); - // get { return this._{0}; } - EmitThis(sw); - sw.Write(".{0}{1}", InternalFieldPrefix, cf.GetCompileName(Options)); - } else { - EmitReturnExpr(PlaceboValue(cfType, errorWr, cf.Origin, true), w); + if (canRedeclareMemberDefinedInTrait) { + var cf = (ConstantField)member; + var cfType = cf.Type.Subst(c.ParentFormalTypeParametersToActuals); + if (cf.Rhs == null && c is ClassLikeDecl) { + // create a backing field, since this constant field may be assigned in constructors + Contract.Assert(!cf.IsStatic); // as checked above, only instance members can be inherited + classWriter.DeclareField(InternalFieldPrefix + cf.GetCompileName(Options), c, false, false, cfType, + cf.Origin, PlaceboValue(cfType, errorWr, cf.Origin, true), cf); + } + + var w = CreateFunctionOrGetter(cf, IdName(cf), c, false, true, true, classWriter); + Contract.Assert(w != null); // since the previous line asked for a body + if (cf.Rhs != null) { + EmitCallToInheritedConstRHS(cf, w); + } else if (!cf.IsStatic && c is ClassLikeDecl) { + var sw = EmitReturnExpr(w); + sw = EmitCoercionIfNecessary(cfType, cf.Type, cf.Origin, sw); + // get { return this._{0}; } + EmitThis(sw); + sw.Write(".{0}{1}", InternalFieldPrefix, cf.GetCompileName(Options)); + } else { + EmitReturnExpr(PlaceboValue(cfType, errorWr, cf.Origin, true), w); + } } } else if (member is Field f) { var fType = f.Type.Subst(c.ParentFormalTypeParametersToActuals); @@ -2212,7 +2223,10 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite } else if (member is Function fn) { if (!IsExternallyImported(fn) && canRedeclareMemberDefinedInTrait) { Contract.Assert(fn.Body != null); - var w = classWriter.CreateFunction(IdName(fn), CombineAllTypeArguments(fn), fn.Ins, fn.ResultType, fn.Origin, fn.IsStatic, true, fn, true, false); + var typeArguments = InstanceMethodsCanOnlyCallOverridenTraitMethods ? + new List() + : CombineAllTypeArguments(fn); + var w = classWriter.CreateFunction(IdName(fn), typeArguments, fn.Ins, fn.ResultType, fn.Origin, fn.IsStatic, true, fn, true, false); w = EmitReturnExpr(w); EmitCallToInheritedFunction(fn, null, w); } @@ -2220,7 +2234,10 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite if (!IsExternallyImported(method) && canRedeclareMemberDefinedInTrait) { Contract.Assert(method.Body != null); - var w = classWriter.CreateMethod(method, CombineAllTypeArguments(member), true, true, false); + var typeArguments = InstanceMethodsCanOnlyCallOverridenTraitMethods ? + new List() + : CombineAllTypeArguments(member); + var w = classWriter.CreateMethod(method, typeArguments, true, true, false); var wBefore = w.Fork(); var wCall = w.Fork(); var wAfter = w; @@ -2273,7 +2290,7 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite // that takes a parameter, because trait-equivalents in target languages don't allow implementations. wBody = classWriter.CreateFunction(IdName(cf), CombineAllTypeArguments(cf), [], cf.Type, cf.Origin, InstanceConstAreStatic(), true, cf, false, true); Contract.Assert(wBody != null); // since the previous line asked for a body - if (c is TraitDecl) { + if (c is TraitDecl && !InstanceMethodsCanOnlyCallOverridenTraitMethods) { // also declare a function for the field in the interface var wBodyInterface = CreateFunctionOrGetter(cf, IdName(cf), c, false, false, false, classWriter); Contract.Assert(wBodyInterface == null); // since the previous line said not to create a body @@ -2459,6 +2476,10 @@ protected void EmitCallToInheritedConstRHS(ConstantField f, ConcreteSyntaxTree w wr.Write(")"); } + protected virtual ConcreteSyntaxTree StartCall(Function f, ConcreteSyntaxTree wr) { + return wr; + } + /// /// "heir" is the type declaration that inherits the function. Or, it can be "null" to indicate that the function is declared in /// the type itself, in which case the "call to inherited" is actually a call from the dynamically dispatched function to its implementation. @@ -2484,6 +2505,8 @@ protected virtual void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLe // the same signature as in "f.Original.EnclosingClass". wr = EmitCoercionIfNecessary(f.ResultType, f.Original.ResultType, f.Origin, wr); + wr = StartCall(f, wr); + var companionName = CompanionMemberIdName(f); var calleeReceiverType = UserDefinedType.FromTopLevelDecl(f.Origin, f.EnclosingClass).Subst(thisContext.ParentFormalTypeParametersToActuals); wr.Write("{0}{1}", TypeName_Companion(calleeReceiverType, wr, f.Origin, f), StaticClassAccessor); @@ -4845,9 +4868,7 @@ private void CompileTypeTest(TypeTestExpr expr, bool inLetExprBody, ConcreteSynt // Notes: // - The constraint of a non-null reference type can be omitted in some cases, see note (c) above. if (fromType.IsTraitType || fromType.IsRefType) { - var name = $"_is_{GetUniqueAstNumber(expr)}"; - wr = CreateIIFE_ExprBody(name, fromType, expr.Origin, expr.E, inLetExprBody, Type.Bool, expr.Origin, wr, ref wStmts); - EmitTypeTest(name, fromType, expr.ToType, expr.Origin, wr); + EmitTypeTestExpr(expr.E, fromType, expr.ToType, expr.Origin, inLetExprBody, wr, ref wStmts); return; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index b6152f6d382..7853d90ab1f 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -571,6 +571,12 @@ public interface _IType { DAST._IType Replace(Dafny.IMap mapping); bool IsPrimitiveInt(); bool IsGeneralTrait(); + DAST._IType GetGeneralTraitType(); + bool IsClassOrObjectTrait(); + bool IsDatatype(); + DAST._IType GetDatatypeType(); + bool Extends(DAST._IType other); + DAST._IType RemoveSynonyms(); } public abstract class Type : _IType { public Type() { @@ -854,6 +860,209 @@ public bool IsGeneralTrait() { return false; } } + public DAST._IType GetGeneralTraitType() { + _IType _this = this; + TAIL_CALL_START: ; + DAST._IType _source0 = _this; + { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _0_typeKind = resolved0.dtor_kind; + DAST._IResolvedTypeBase _source1 = _0_typeKind; + { + if (_source1.is_SynonymType) { + DAST._IType _1_typ = _source1.dtor_baseType; + DAST._IType _in0 = _1_typ; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + { + return _this; + } + } + } + public bool IsClassOrObjectTrait() { + DAST._IType _source0 = this; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _0_base = resolved0.dtor_kind; + return ((_0_base).is_Class) || (((_0_base).is_Trait) && (((_0_base).dtor_traitType).is_ObjectTrait)); + } + } + { + return false; + } + } + public bool IsDatatype() { + _IType _this = this; + TAIL_CALL_START: ; + DAST._IType _source0 = _this; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _0_typeKind = resolved0.dtor_kind; + DAST._IResolvedTypeBase _source1 = _0_typeKind; + { + if (_source1.is_SynonymType) { + DAST._IType _1_typ = _source1.dtor_baseType; + DAST._IType _in0 = _1_typ; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + { + if (_source1.is_Datatype) { + return true; + } + } + { + return false; + } + } + } + { + return false; + } + } + public DAST._IType GetDatatypeType() { + _IType _this = this; + TAIL_CALL_START: ; + DAST._IType _source0 = _this; + { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _0_typeKind = resolved0.dtor_kind; + DAST._IResolvedTypeBase _source1 = _0_typeKind; + { + if (_source1.is_SynonymType) { + DAST._IType _1_typ = _source1.dtor_baseType; + DAST._IType _in0 = _1_typ; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + { + return _this; + } + } + } + public bool Extends(DAST._IType other) { + DAST._IType _source0 = this; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + Dafny.ISequence _0_extendedTypes = resolved0.dtor_extendedTypes; + return ((_0_extendedTypes).Contains(other)) || (Dafny.Helpers.Id, DAST._IType, bool>>((_1_extendedTypes, _2_other) => Dafny.Helpers.Quantifier(Dafny.Helpers.IntegerRange(BigInteger.Zero, new BigInteger((_1_extendedTypes).Count)), false, (((_exists_var_0) => { + BigInteger _3_i = (BigInteger)_exists_var_0; + return (((_3_i).Sign != -1) && ((_3_i) < (new BigInteger((_1_extendedTypes).Count)))) && (((_1_extendedTypes).Select(_3_i)).Extends(_2_other)); + }))))(_0_extendedTypes, other)); + } + } + { + return false; + } + } + public DAST._IType RemoveSynonyms() { + DAST._IType _source0 = this; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + Dafny.ISequence> _0_path = resolved0.dtor_path; + Dafny.ISequence _1_typeArgs = resolved0.dtor_typeArgs; + DAST._IResolvedTypeBase _2_typeKind = resolved0.dtor_kind; + Dafny.ISequence _3_attributes = resolved0.dtor_attributes; + Dafny.ISequence> _4_properMethods = resolved0.dtor_properMethods; + Dafny.ISequence _5_extendedTypes = resolved0.dtor_extendedTypes; + DAST._IResolvedTypeBase _source1 = _2_typeKind; + { + if (_source1.is_SynonymType) { + DAST._IType _6_typ = _source1.dtor_baseType; + return (_6_typ).RemoveSynonyms(); + } + } + { + Dafny.ISequence _7_newtypeArgs = ((System.Func>) (() => { + BigInteger dim10 = new BigInteger((_1_typeArgs).Count); + var arr10 = new DAST._IType[Dafny.Helpers.ToIntChecked(dim10, "array size exceeds memory limit")]; + for (int i10 = 0; i10 < dim10; i10++) { + var _8_i = (BigInteger) i10; + arr10[(int)(_8_i)] = ((_1_typeArgs).Select(_8_i)).RemoveSynonyms(); + } + return Dafny.Sequence.FromArray(arr10); + }))(); + return DAST.Type.create_UserDefined(DAST.ResolvedType.create(_0_path, _7_newtypeArgs, _2_typeKind, _3_attributes, _4_properMethods, _5_extendedTypes)); + } + } + } + { + if (_source0.is_Tuple) { + Dafny.ISequence _9_arguments = _source0.dtor_Tuple_a0; + return DAST.Type.create_Tuple(Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Func>>((_10_arguments) => ((System.Func)((_11_t) => { + return (_11_t).RemoveSynonyms(); +})))(_9_arguments), _9_arguments)); + } + } + { + if (_source0.is_Array) { + DAST._IType _12_element = _source0.dtor_element; + BigInteger _13_dims = _source0.dtor_dims; + return DAST.Type.create_Array((_12_element).RemoveSynonyms(), _13_dims); + } + } + { + if (_source0.is_Seq) { + DAST._IType _14_element = _source0.dtor_element; + return DAST.Type.create_Seq((_14_element).RemoveSynonyms()); + } + } + { + if (_source0.is_Set) { + DAST._IType _15_element = _source0.dtor_element; + return DAST.Type.create_Set((_15_element).RemoveSynonyms()); + } + } + { + if (_source0.is_Multiset) { + DAST._IType _16_element = _source0.dtor_element; + return DAST.Type.create_Multiset((_16_element).RemoveSynonyms()); + } + } + { + if (_source0.is_Map) { + DAST._IType _17_key = _source0.dtor_key; + DAST._IType _18_value = _source0.dtor_value; + return DAST.Type.create_Map((_17_key).RemoveSynonyms(), (_18_value).RemoveSynonyms()); + } + } + { + if (_source0.is_SetBuilder) { + DAST._IType _19_element = _source0.dtor_element; + return DAST.Type.create_SetBuilder((_19_element).RemoveSynonyms()); + } + } + { + if (_source0.is_MapBuilder) { + DAST._IType _20_key = _source0.dtor_key; + DAST._IType _21_value = _source0.dtor_value; + return DAST.Type.create_MapBuilder((_20_key).RemoveSynonyms(), (_21_value).RemoveSynonyms()); + } + } + { + if (_source0.is_Arrow) { + Dafny.ISequence _22_args = _source0.dtor_args; + DAST._IType _23_result = _source0.dtor_result; + return DAST.Type.create_Arrow(Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Func>>((_24_args) => ((System.Func)((_25_t) => { + return (_25_t).RemoveSynonyms(); +})))(_22_args), _22_args), (_23_result).RemoveSynonyms()); + } + } + { + return this; + } + } } public class Type_UserDefined : Type { public readonly DAST._IResolvedType _resolved; @@ -1354,32 +1563,32 @@ public interface _ITypeArgDecl { bool is_TypeArgDecl { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_bounds { get; } - DAST._IVariance dtor_variance { get; } + DAST._ITypeParameterInfo dtor_info { get; } _ITypeArgDecl DowncastClone(); } public class TypeArgDecl : _ITypeArgDecl { public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _bounds; - public readonly DAST._IVariance _variance; - public TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds, DAST._IVariance variance) { + public readonly DAST._ITypeParameterInfo _info; + public TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds, DAST._ITypeParameterInfo info) { this._name = name; this._bounds = bounds; - this._variance = variance; + this._info = info; } public _ITypeArgDecl DowncastClone() { if (this is _ITypeArgDecl dt) { return dt; } - return new TypeArgDecl(_name, _bounds, _variance); + return new TypeArgDecl(_name, _bounds, _info); } public override bool Equals(object other) { var oth = other as DAST.TypeArgDecl; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._bounds, oth._bounds) && object.Equals(this._variance, oth._variance); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._bounds, oth._bounds) && object.Equals(this._info, oth._info); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._bounds)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._variance)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._info)); return (int) hash; } public override string ToString() { @@ -1389,11 +1598,11 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._bounds); s += ", "; - s += Dafny.Helpers.ToString(this._variance); + s += Dafny.Helpers.ToString(this._info); s += ")"; return s; } - private static readonly DAST._ITypeArgDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.Variance.Default()); + private static readonly DAST._ITypeArgDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.TypeParameterInfo.Default()); public static DAST._ITypeArgDecl Default() { return theDefault; } @@ -1401,11 +1610,11 @@ public static DAST._ITypeArgDecl Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITypeArgDecl create(Dafny.ISequence name, Dafny.ISequence bounds, DAST._IVariance variance) { - return new TypeArgDecl(name, bounds, variance); + public static _ITypeArgDecl create(Dafny.ISequence name, Dafny.ISequence bounds, DAST._ITypeParameterInfo info) { + return new TypeArgDecl(name, bounds, info); } - public static _ITypeArgDecl create_TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds, DAST._IVariance variance) { - return create(name, bounds, variance); + public static _ITypeArgDecl create_TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds, DAST._ITypeParameterInfo info) { + return create(name, bounds, info); } public bool is_TypeArgDecl { get { return true; } } public Dafny.ISequence dtor_name { @@ -1418,9 +1627,9 @@ public Dafny.ISequence dtor_bounds { return this._bounds; } } - public DAST._IVariance dtor_variance { + public DAST._ITypeParameterInfo dtor_info { get { - return this._variance; + return this._info; } } } @@ -1428,6 +1637,8 @@ public DAST._IVariance dtor_variance { public interface _ITypeArgBound { bool is_SupportsEquality { get; } bool is_SupportsDefault { get; } + bool is_TraitBound { get; } + DAST._IType dtor_typ { get; } _ITypeArgBound DowncastClone(); } public abstract class TypeArgBound : _ITypeArgBound { @@ -1447,12 +1658,16 @@ public static _ITypeArgBound create_SupportsEquality() { public static _ITypeArgBound create_SupportsDefault() { return new TypeArgBound_SupportsDefault(); } + public static _ITypeArgBound create_TraitBound(DAST._IType typ) { + return new TypeArgBound_TraitBound(typ); + } public bool is_SupportsEquality { get { return this is TypeArgBound_SupportsEquality; } } public bool is_SupportsDefault { get { return this is TypeArgBound_SupportsDefault; } } - public static System.Collections.Generic.IEnumerable<_ITypeArgBound> AllSingletonConstructors { + public bool is_TraitBound { get { return this is TypeArgBound_TraitBound; } } + public DAST._IType dtor_typ { get { - yield return TypeArgBound.create_SupportsEquality(); - yield return TypeArgBound.create_SupportsDefault(); + var d = this; + return ((TypeArgBound_TraitBound)d)._typ; } } public abstract _ITypeArgBound DowncastClone(); @@ -1499,6 +1714,33 @@ public override string ToString() { return s; } } + public class TypeArgBound_TraitBound : TypeArgBound { + public readonly DAST._IType _typ; + public TypeArgBound_TraitBound(DAST._IType typ) : base() { + this._typ = typ; + } + public override _ITypeArgBound DowncastClone() { + if (this is _ITypeArgBound dt) { return dt; } + return new TypeArgBound_TraitBound(_typ); + } + public override bool Equals(object other) { + var oth = other as DAST.TypeArgBound_TraitBound; + return oth != null && object.Equals(this._typ, oth._typ); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typ)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.TypeArgBound.TraitBound"; + s += "("; + s += Dafny.Helpers.ToString(this._typ); + s += ")"; + return s; + } + } public interface _IPrimitive { bool is_Int { get; } @@ -1697,6 +1939,8 @@ public interface _INewtypeRange { bool is_NativeArrayIndex { get; } bool is_BigInt { get; } bool is_Bool { get; } + bool is_Sequence { get; } + bool is_Map { get; } bool is_NoRange { get; } bool dtor_overflow { get; } _INewtypeRange DowncastClone(); @@ -1753,6 +1997,12 @@ public static _INewtypeRange create_BigInt() { public static _INewtypeRange create_Bool() { return new NewtypeRange_Bool(); } + public static _INewtypeRange create_Sequence() { + return new NewtypeRange_Sequence(); + } + public static _INewtypeRange create_Map() { + return new NewtypeRange_Map(); + } public static _INewtypeRange create_NoRange() { return new NewtypeRange_NoRange(); } @@ -1769,6 +2019,8 @@ public static _INewtypeRange create_NoRange() { public bool is_NativeArrayIndex { get { return this is NewtypeRange_NativeArrayIndex; } } public bool is_BigInt { get { return this is NewtypeRange_BigInt; } } public bool is_Bool { get { return this is NewtypeRange_Bool; } } + public bool is_Sequence { get { return this is NewtypeRange_Sequence; } } + public bool is_Map { get { return this is NewtypeRange_Map; } } public bool is_NoRange { get { return this is NewtypeRange_NoRange; } } public bool dtor_overflow { get { @@ -1790,7 +2042,7 @@ public bool CanOverflow() { return (((((((((((this).is_U8) || ((this).is_I8)) || ((this).is_U16)) || ((this).is_I16)) || ((this).is_U32)) || ((this).is_I32)) || ((this).is_U64)) || ((this).is_I64)) || ((this).is_U128)) || ((this).is_I128)) && ((this).dtor_overflow); } public bool HasArithmeticOperations() { - return !((this).is_Bool); + return ((!((this).is_Bool)) && (!((this).is_Map))) && (!((this).is_Sequence)); } } public class NewtypeRange_U8 : NewtypeRange { @@ -2126,6 +2378,48 @@ public override string ToString() { return s; } } + public class NewtypeRange_Sequence : NewtypeRange { + public NewtypeRange_Sequence() : base() { + } + public override _INewtypeRange DowncastClone() { + if (this is _INewtypeRange dt) { return dt; } + return new NewtypeRange_Sequence(); + } + public override bool Equals(object other) { + var oth = other as DAST.NewtypeRange_Sequence; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 13; + return (int) hash; + } + public override string ToString() { + string s = "DAST.NewtypeRange.Sequence"; + return s; + } + } + public class NewtypeRange_Map : NewtypeRange { + public NewtypeRange_Map() : base() { + } + public override _INewtypeRange DowncastClone() { + if (this is _INewtypeRange dt) { return dt; } + return new NewtypeRange_Map(); + } + public override bool Equals(object other) { + var oth = other as DAST.NewtypeRange_Map; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 14; + return (int) hash; + } + public override string ToString() { + string s = "DAST.NewtypeRange.Map"; + return s; + } + } public class NewtypeRange_NoRange : NewtypeRange { public NewtypeRange_NoRange() : base() { } @@ -2139,7 +2433,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 13; + hash = ((hash << 5) + hash) + 15; return (int) hash; } public override string ToString() { @@ -2362,13 +2656,153 @@ public override string ToString() { } } + public interface _ITypeParameterInfo { + bool is_TypeParameterInfo { get; } + DAST._IVariance dtor_variance { get; } + bool dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype { get; } + _ITypeParameterInfo DowncastClone(); + } + public class TypeParameterInfo : _ITypeParameterInfo { + public readonly DAST._IVariance _variance; + public readonly bool _necessaryForEqualitySupportOfSurroundingInductiveDatatype; + public TypeParameterInfo(DAST._IVariance variance, bool necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + this._variance = variance; + this._necessaryForEqualitySupportOfSurroundingInductiveDatatype = necessaryForEqualitySupportOfSurroundingInductiveDatatype; + } + public _ITypeParameterInfo DowncastClone() { + if (this is _ITypeParameterInfo dt) { return dt; } + return new TypeParameterInfo(_variance, _necessaryForEqualitySupportOfSurroundingInductiveDatatype); + } + public override bool Equals(object other) { + var oth = other as DAST.TypeParameterInfo; + return oth != null && object.Equals(this._variance, oth._variance) && this._necessaryForEqualitySupportOfSurroundingInductiveDatatype == oth._necessaryForEqualitySupportOfSurroundingInductiveDatatype; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._variance)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._necessaryForEqualitySupportOfSurroundingInductiveDatatype)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.TypeParameterInfo.TypeParameterInfo"; + s += "("; + s += Dafny.Helpers.ToString(this._variance); + s += ", "; + s += Dafny.Helpers.ToString(this._necessaryForEqualitySupportOfSurroundingInductiveDatatype); + s += ")"; + return s; + } + private static readonly DAST._ITypeParameterInfo theDefault = create(DAST.Variance.Default(), false); + public static DAST._ITypeParameterInfo Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.TypeParameterInfo.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _ITypeParameterInfo create(DAST._IVariance variance, bool necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + return new TypeParameterInfo(variance, necessaryForEqualitySupportOfSurroundingInductiveDatatype); + } + public static _ITypeParameterInfo create_TypeParameterInfo(DAST._IVariance variance, bool necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + return create(variance, necessaryForEqualitySupportOfSurroundingInductiveDatatype); + } + public bool is_TypeParameterInfo { get { return true; } } + public DAST._IVariance dtor_variance { + get { + return this._variance; + } + } + public bool dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype { + get { + return this._necessaryForEqualitySupportOfSurroundingInductiveDatatype; + } + } + } + + public interface _IEqualitySupport { + bool is_Never { get; } + bool is_ConsultTypeArguments { get; } + _IEqualitySupport DowncastClone(); + } + public abstract class EqualitySupport : _IEqualitySupport { + public EqualitySupport() { + } + private static readonly DAST._IEqualitySupport theDefault = create_Never(); + public static DAST._IEqualitySupport Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.EqualitySupport.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IEqualitySupport create_Never() { + return new EqualitySupport_Never(); + } + public static _IEqualitySupport create_ConsultTypeArguments() { + return new EqualitySupport_ConsultTypeArguments(); + } + public bool is_Never { get { return this is EqualitySupport_Never; } } + public bool is_ConsultTypeArguments { get { return this is EqualitySupport_ConsultTypeArguments; } } + public static System.Collections.Generic.IEnumerable<_IEqualitySupport> AllSingletonConstructors { + get { + yield return EqualitySupport.create_Never(); + yield return EqualitySupport.create_ConsultTypeArguments(); + } + } + public abstract _IEqualitySupport DowncastClone(); + } + public class EqualitySupport_Never : EqualitySupport { + public EqualitySupport_Never() : base() { + } + public override _IEqualitySupport DowncastClone() { + if (this is _IEqualitySupport dt) { return dt; } + return new EqualitySupport_Never(); + } + public override bool Equals(object other) { + var oth = other as DAST.EqualitySupport_Never; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + return (int) hash; + } + public override string ToString() { + string s = "DAST.EqualitySupport.Never"; + return s; + } + } + public class EqualitySupport_ConsultTypeArguments : EqualitySupport { + public EqualitySupport_ConsultTypeArguments() : base() { + } + public override _IEqualitySupport DowncastClone() { + if (this is _IEqualitySupport dt) { return dt; } + return new EqualitySupport_ConsultTypeArguments(); + } + public override bool Equals(object other) { + var oth = other as DAST.EqualitySupport_ConsultTypeArguments; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + return (int) hash; + } + public override string ToString() { + string s = "DAST.EqualitySupport.ConsultTypeArguments"; + return s; + } + } + public interface _IResolvedTypeBase { bool is_Class { get; } bool is_Datatype { get; } bool is_Trait { get; } bool is_SynonymType { get; } bool is_Newtype { get; } - Dafny.ISequence dtor_variances { get; } + DAST._IEqualitySupport dtor_equalitySupport { get; } + Dafny.ISequence dtor_info { get; } DAST._ITraitType dtor_traitType { get; } DAST._IType dtor_baseType { get; } DAST._INewtypeRange dtor_range { get; } @@ -2389,8 +2823,8 @@ public static DAST._IResolvedTypeBase Default() { public static _IResolvedTypeBase create_Class() { return new ResolvedTypeBase_Class(); } - public static _IResolvedTypeBase create_Datatype(Dafny.ISequence variances) { - return new ResolvedTypeBase_Datatype(variances); + public static _IResolvedTypeBase create_Datatype(DAST._IEqualitySupport equalitySupport, Dafny.ISequence info) { + return new ResolvedTypeBase_Datatype(equalitySupport, info); } public static _IResolvedTypeBase create_Trait(DAST._ITraitType traitType) { return new ResolvedTypeBase_Trait(traitType); @@ -2406,10 +2840,16 @@ public static _IResolvedTypeBase create_Newtype(DAST._IType baseType, DAST._INew public bool is_Trait { get { return this is ResolvedTypeBase_Trait; } } public bool is_SynonymType { get { return this is ResolvedTypeBase_SynonymType; } } public bool is_Newtype { get { return this is ResolvedTypeBase_Newtype; } } - public Dafny.ISequence dtor_variances { + public DAST._IEqualitySupport dtor_equalitySupport { + get { + var d = this; + return ((ResolvedTypeBase_Datatype)d)._equalitySupport; + } + } + public Dafny.ISequence dtor_info { get { var d = this; - return ((ResolvedTypeBase_Datatype)d)._variances; + return ((ResolvedTypeBase_Datatype)d)._info; } } public DAST._ITraitType dtor_traitType { @@ -2461,28 +2901,33 @@ public override string ToString() { } } public class ResolvedTypeBase_Datatype : ResolvedTypeBase { - public readonly Dafny.ISequence _variances; - public ResolvedTypeBase_Datatype(Dafny.ISequence variances) : base() { - this._variances = variances; + public readonly DAST._IEqualitySupport _equalitySupport; + public readonly Dafny.ISequence _info; + public ResolvedTypeBase_Datatype(DAST._IEqualitySupport equalitySupport, Dafny.ISequence info) : base() { + this._equalitySupport = equalitySupport; + this._info = info; } public override _IResolvedTypeBase DowncastClone() { if (this is _IResolvedTypeBase dt) { return dt; } - return new ResolvedTypeBase_Datatype(_variances); + return new ResolvedTypeBase_Datatype(_equalitySupport, _info); } public override bool Equals(object other) { var oth = other as DAST.ResolvedTypeBase_Datatype; - return oth != null && object.Equals(this._variances, oth._variances); + return oth != null && object.Equals(this._equalitySupport, oth._equalitySupport) && object.Equals(this._info, oth._info); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 1; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._variances)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._equalitySupport)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._info)); return (int) hash; } public override string ToString() { string s = "DAST.ResolvedTypeBase.Datatype"; s += "("; - s += Dafny.Helpers.ToString(this._variances); + s += Dafny.Helpers.ToString(this._equalitySupport); + s += ", "; + s += Dafny.Helpers.ToString(this._info); s += ")"; return s; } @@ -2896,6 +3341,7 @@ public interface _ITrait { Dafny.ISequence dtor_typeParams { get; } DAST._ITraitType dtor_traitType { get; } Dafny.ISequence dtor_parents { get; } + Dafny.ISequence dtor_downcastableTraits { get; } Dafny.ISequence dtor_body { get; } Dafny.ISequence dtor_attributes { get; } _ITrait DowncastClone(); @@ -2906,24 +3352,26 @@ public class Trait : _ITrait { public readonly Dafny.ISequence _typeParams; public readonly DAST._ITraitType _traitType; public readonly Dafny.ISequence _parents; + public readonly Dafny.ISequence _downcastableTraits; public readonly Dafny.ISequence _body; public readonly Dafny.ISequence _attributes; - public Trait(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { + public Trait(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence downcastableTraits, Dafny.ISequence body, Dafny.ISequence attributes) { this._name = name; this._docString = docString; this._typeParams = typeParams; this._traitType = traitType; this._parents = parents; + this._downcastableTraits = downcastableTraits; this._body = body; this._attributes = attributes; } public _ITrait DowncastClone() { if (this is _ITrait dt) { return dt; } - return new Trait(_name, _docString, _typeParams, _traitType, _parents, _body, _attributes); + return new Trait(_name, _docString, _typeParams, _traitType, _parents, _downcastableTraits, _body, _attributes); } public override bool Equals(object other) { var oth = other as DAST.Trait; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._traitType, oth._traitType) && object.Equals(this._parents, oth._parents) && object.Equals(this._body, oth._body) && object.Equals(this._attributes, oth._attributes); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._traitType, oth._traitType) && object.Equals(this._parents, oth._parents) && object.Equals(this._downcastableTraits, oth._downcastableTraits) && object.Equals(this._body, oth._body) && object.Equals(this._attributes, oth._attributes); } public override int GetHashCode() { ulong hash = 5381; @@ -2933,6 +3381,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._traitType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._parents)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._downcastableTraits)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); return (int) hash; @@ -2950,13 +3399,15 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._parents); s += ", "; + s += Dafny.Helpers.ToString(this._downcastableTraits); + s += ", "; s += Dafny.Helpers.ToString(this._body); s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ")"; return s; } - private static readonly DAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.TraitType.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.TraitType.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._ITrait Default() { return theDefault; } @@ -2964,11 +3415,11 @@ public static DAST._ITrait Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITrait create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { - return new Trait(name, docString, typeParams, traitType, parents, body, attributes); + public static _ITrait create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence downcastableTraits, Dafny.ISequence body, Dafny.ISequence attributes) { + return new Trait(name, docString, typeParams, traitType, parents, downcastableTraits, body, attributes); } - public static _ITrait create_Trait(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { - return create(name, docString, typeParams, traitType, parents, body, attributes); + public static _ITrait create_Trait(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence downcastableTraits, Dafny.ISequence body, Dafny.ISequence attributes) { + return create(name, docString, typeParams, traitType, parents, downcastableTraits, body, attributes); } public bool is_Trait { get { return true; } } public Dafny.ISequence dtor_name { @@ -2996,6 +3447,11 @@ public Dafny.ISequence dtor_parents { return this._parents; } } + public Dafny.ISequence dtor_downcastableTraits { + get { + return this._downcastableTraits; + } + } public Dafny.ISequence dtor_body { get { return this._body; @@ -3017,8 +3473,10 @@ public interface _IDatatype { Dafny.ISequence dtor_ctors { get; } Dafny.ISequence dtor_body { get; } bool dtor_isCo { get; } + DAST._IEqualitySupport dtor_equalitySupport { get; } Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_superTraitTypes { get; } + Dafny.ISequence dtor_superTraitNegativeTypes { get; } _IDatatype DowncastClone(); } public class Datatype : _IDatatype { @@ -3029,9 +3487,11 @@ public class Datatype : _IDatatype { public readonly Dafny.ISequence _ctors; public readonly Dafny.ISequence _body; public readonly bool _isCo; + public readonly DAST._IEqualitySupport _equalitySupport; public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _superTraitTypes; - public Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes) { + public readonly Dafny.ISequence _superTraitNegativeTypes; + public Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { this._name = name; this._docString = docString; this._enclosingModule = enclosingModule; @@ -3039,16 +3499,18 @@ public Datatype(Dafny.ISequence name, Dafny.ISequence do this._ctors = ctors; this._body = body; this._isCo = isCo; + this._equalitySupport = equalitySupport; this._attributes = attributes; this._superTraitTypes = superTraitTypes; + this._superTraitNegativeTypes = superTraitNegativeTypes; } public _IDatatype DowncastClone() { if (this is _IDatatype dt) { return dt; } - return new Datatype(_name, _docString, _enclosingModule, _typeParams, _ctors, _body, _isCo, _attributes, _superTraitTypes); + return new Datatype(_name, _docString, _enclosingModule, _typeParams, _ctors, _body, _isCo, _equalitySupport, _attributes, _superTraitTypes, _superTraitNegativeTypes); } public override bool Equals(object other) { var oth = other as DAST.Datatype; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._ctors, oth._ctors) && object.Equals(this._body, oth._body) && this._isCo == oth._isCo && object.Equals(this._attributes, oth._attributes) && object.Equals(this._superTraitTypes, oth._superTraitTypes); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._ctors, oth._ctors) && object.Equals(this._body, oth._body) && this._isCo == oth._isCo && object.Equals(this._equalitySupport, oth._equalitySupport) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._superTraitTypes, oth._superTraitTypes) && object.Equals(this._superTraitNegativeTypes, oth._superTraitNegativeTypes); } public override int GetHashCode() { ulong hash = 5381; @@ -3060,8 +3522,10 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._ctors)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isCo)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._equalitySupport)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superTraitTypes)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superTraitNegativeTypes)); return (int) hash; } public override string ToString() { @@ -3081,13 +3545,17 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._isCo); s += ", "; + s += Dafny.Helpers.ToString(this._equalitySupport); + s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += Dafny.Helpers.ToString(this._superTraitTypes); + s += ", "; + s += Dafny.Helpers.ToString(this._superTraitNegativeTypes); s += ")"; return s; } - private static readonly DAST._IDatatype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._IDatatype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, DAST.EqualitySupport.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._IDatatype Default() { return theDefault; } @@ -3095,11 +3563,11 @@ public static DAST._IDatatype Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IDatatype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes) { - return new Datatype(name, docString, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes); + public static _IDatatype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { + return new Datatype(name, docString, enclosingModule, typeParams, ctors, body, isCo, equalitySupport, attributes, superTraitTypes, superTraitNegativeTypes); } - public static _IDatatype create_Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes) { - return create(name, docString, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes); + public static _IDatatype create_Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { + return create(name, docString, enclosingModule, typeParams, ctors, body, isCo, equalitySupport, attributes, superTraitTypes, superTraitNegativeTypes); } public bool is_Datatype { get { return true; } } public Dafny.ISequence dtor_name { @@ -3137,6 +3605,11 @@ public bool dtor_isCo { return this._isCo; } } + public DAST._IEqualitySupport dtor_equalitySupport { + get { + return this._equalitySupport; + } + } public Dafny.ISequence dtor_attributes { get { return this._attributes; @@ -3147,6 +3620,11 @@ public Dafny.ISequence dtor_superTraitTypes { return this._superTraitTypes; } } + public Dafny.ISequence dtor_superTraitNegativeTypes { + get { + return this._superTraitNegativeTypes; + } + } } public interface _IDatatypeDtor { @@ -3309,6 +3787,7 @@ public interface _INewtype { Std.Wrappers._IOption dtor_constraint { get; } Dafny.ISequence dtor_witnessStmts { get; } Std.Wrappers._IOption dtor_witnessExpr { get; } + DAST._IEqualitySupport dtor_equalitySupport { get; } Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_classItems { get; } _INewtype DowncastClone(); @@ -3322,9 +3801,10 @@ public class Newtype : _INewtype { public readonly Std.Wrappers._IOption _constraint; public readonly Dafny.ISequence _witnessStmts; public readonly Std.Wrappers._IOption _witnessExpr; + public readonly DAST._IEqualitySupport _equalitySupport; public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _classItems; - public Newtype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes, Dafny.ISequence classItems) { + public Newtype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence classItems) { this._name = name; this._docString = docString; this._typeParams = typeParams; @@ -3333,16 +3813,17 @@ public Newtype(Dafny.ISequence name, Dafny.ISequence doc this._constraint = constraint; this._witnessStmts = witnessStmts; this._witnessExpr = witnessExpr; + this._equalitySupport = equalitySupport; this._attributes = attributes; this._classItems = classItems; } public _INewtype DowncastClone() { if (this is _INewtype dt) { return dt; } - return new Newtype(_name, _docString, _typeParams, _base, _range, _constraint, _witnessStmts, _witnessExpr, _attributes, _classItems); + return new Newtype(_name, _docString, _typeParams, _base, _range, _constraint, _witnessStmts, _witnessExpr, _equalitySupport, _attributes, _classItems); } public override bool Equals(object other) { var oth = other as DAST.Newtype; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._base, oth._base) && object.Equals(this._range, oth._range) && object.Equals(this._constraint, oth._constraint) && object.Equals(this._witnessStmts, oth._witnessStmts) && object.Equals(this._witnessExpr, oth._witnessExpr) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._classItems, oth._classItems); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._base, oth._base) && object.Equals(this._range, oth._range) && object.Equals(this._constraint, oth._constraint) && object.Equals(this._witnessStmts, oth._witnessStmts) && object.Equals(this._witnessExpr, oth._witnessExpr) && object.Equals(this._equalitySupport, oth._equalitySupport) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._classItems, oth._classItems); } public override int GetHashCode() { ulong hash = 5381; @@ -3355,6 +3836,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._constraint)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._witnessStmts)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._witnessExpr)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._equalitySupport)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._classItems)); return (int) hash; @@ -3378,13 +3860,15 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._witnessExpr); s += ", "; + s += Dafny.Helpers.ToString(this._equalitySupport); + s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += Dafny.Helpers.ToString(this._classItems); s += ")"; return s; } - private static readonly DAST._INewtype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.Type.Default(), DAST.NewtypeRange.Default(), Std.Wrappers.Option.Default(), Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._INewtype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.Type.Default(), DAST.NewtypeRange.Default(), Std.Wrappers.Option.Default(), Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), DAST.EqualitySupport.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._INewtype Default() { return theDefault; } @@ -3392,11 +3876,11 @@ public static DAST._INewtype Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _INewtype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes, Dafny.ISequence classItems) { - return new Newtype(name, docString, typeParams, @base, range, constraint, witnessStmts, witnessExpr, attributes, classItems); + public static _INewtype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence classItems) { + return new Newtype(name, docString, typeParams, @base, range, constraint, witnessStmts, witnessExpr, equalitySupport, attributes, classItems); } - public static _INewtype create_Newtype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes, Dafny.ISequence classItems) { - return create(name, docString, typeParams, @base, range, constraint, witnessStmts, witnessExpr, attributes, classItems); + public static _INewtype create_Newtype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence classItems) { + return create(name, docString, typeParams, @base, range, constraint, witnessStmts, witnessExpr, equalitySupport, attributes, classItems); } public bool is_Newtype { get { return true; } } public Dafny.ISequence dtor_name { @@ -3439,6 +3923,11 @@ public Std.Wrappers._IOption dtor_witnessExpr { return this._witnessExpr; } } + public DAST._IEqualitySupport dtor_equalitySupport { + get { + return this._equalitySupport; + } + } public Dafny.ISequence dtor_attributes { get { return this._attributes; @@ -3858,6 +4347,7 @@ public interface _IMethod { Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_params { get; } + Dafny.ISequence dtor_inheritedParams { get; } Dafny.ISequence dtor_body { get; } Dafny.ISequence dtor_outTypes { get; } Std.Wrappers._IOption>> dtor_outVars { get; } @@ -3874,10 +4364,11 @@ public class Method : _IMethod { public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _params; + public readonly Dafny.ISequence _inheritedParams; public readonly Dafny.ISequence _body; public readonly Dafny.ISequence _outTypes; public readonly Std.Wrappers._IOption>> _outVars; - public Method(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { + public Method(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence inheritedParams, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { this._docString = docString; this._attributes = attributes; this._isStatic = isStatic; @@ -3888,17 +4379,18 @@ public Method(Dafny.ISequence docString, Dafny.ISequence.Empty, Dafny.Sequence.Empty, false, false, false, false, Std.Wrappers.Option>>.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option>>.Default()); + private static readonly DAST._IMethod theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, false, false, false, Std.Wrappers.Option>>.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option>>.Default()); public static DAST._IMethod Default() { return theDefault; } @@ -3957,11 +4452,11 @@ public static DAST._IMethod Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IMethod create(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { - return new Method(docString, attributes, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, name, typeParams, @params, body, outTypes, outVars); + public static _IMethod create(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence inheritedParams, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { + return new Method(docString, attributes, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, name, typeParams, @params, inheritedParams, body, outTypes, outVars); } - public static _IMethod create_Method(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { - return create(docString, attributes, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, name, typeParams, @params, body, outTypes, outVars); + public static _IMethod create_Method(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence inheritedParams, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { + return create(docString, attributes, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, name, typeParams, @params, inheritedParams, body, outTypes, outVars); } public bool is_Method { get { return true; } } public Dafny.ISequence dtor_docString { @@ -4014,6 +4509,11 @@ public Dafny.ISequence dtor_params { return this._params; } } + public Dafny.ISequence dtor_inheritedParams { + get { + return this._inheritedParams; + } + } public Dafny.ISequence dtor_body { get { return this._body; @@ -4034,45 +4534,53 @@ public Std.Wrappers._IOption>> dtor_ public interface _ICallSignature { bool is_CallSignature { get; } Dafny.ISequence dtor_parameters { get; } + Dafny.ISequence dtor_inheritedParams { get; } + _ICallSignature DowncastClone(); } public class CallSignature : _ICallSignature { public readonly Dafny.ISequence _parameters; - public CallSignature(Dafny.ISequence parameters) { + public readonly Dafny.ISequence _inheritedParams; + public CallSignature(Dafny.ISequence parameters, Dafny.ISequence inheritedParams) { this._parameters = parameters; + this._inheritedParams = inheritedParams; } - public static Dafny.ISequence DowncastClone(Dafny.ISequence _this) { - return _this; + public _ICallSignature DowncastClone() { + if (this is _ICallSignature dt) { return dt; } + return new CallSignature(_parameters, _inheritedParams); } public override bool Equals(object other) { var oth = other as DAST.CallSignature; - return oth != null && object.Equals(this._parameters, oth._parameters); + return oth != null && object.Equals(this._parameters, oth._parameters) && object.Equals(this._inheritedParams, oth._inheritedParams); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._parameters)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._inheritedParams)); return (int) hash; } public override string ToString() { string s = "DAST.CallSignature.CallSignature"; s += "("; s += Dafny.Helpers.ToString(this._parameters); + s += ", "; + s += Dafny.Helpers.ToString(this._inheritedParams); s += ")"; return s; } - private static readonly Dafny.ISequence theDefault = Dafny.Sequence.Empty; - public static Dafny.ISequence Default() { + private static readonly DAST._ICallSignature theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty); + public static DAST._ICallSignature Default() { return theDefault; } - private static readonly Dafny.TypeDescriptor> _TYPE = new Dafny.TypeDescriptor>(Dafny.Sequence.Empty); - public static Dafny.TypeDescriptor> _TypeDescriptor() { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.CallSignature.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ICallSignature create(Dafny.ISequence parameters) { - return new CallSignature(parameters); + public static _ICallSignature create(Dafny.ISequence parameters, Dafny.ISequence inheritedParams) { + return new CallSignature(parameters, inheritedParams); } - public static _ICallSignature create_CallSignature(Dafny.ISequence parameters) { - return create(parameters); + public static _ICallSignature create_CallSignature(Dafny.ISequence parameters, Dafny.ISequence inheritedParams) { + return create(parameters, inheritedParams); } public bool is_CallSignature { get { return true; } } public Dafny.ISequence dtor_parameters { @@ -4080,6 +4588,11 @@ public Dafny.ISequence dtor_parameters { return this._parameters; } } + public Dafny.ISequence dtor_inheritedParams { + get { + return this._inheritedParams; + } + } } public interface _ICallName { @@ -4092,13 +4605,13 @@ public interface _ICallName { Std.Wrappers._IOption dtor_onType { get; } Std.Wrappers._IOption dtor_receiverArg { get; } bool dtor_receiverAsArgument { get; } - Dafny.ISequence dtor_signature { get; } + DAST._ICallSignature dtor_signature { get; } _ICallName DowncastClone(); } public abstract class CallName : _ICallName { public CallName() { } - private static readonly DAST._ICallName theDefault = create_CallName(Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Std.Wrappers.Option.Default(), false, Dafny.Sequence.Empty); + private static readonly DAST._ICallName theDefault = create_CallName(Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Std.Wrappers.Option.Default(), false, DAST.CallSignature.Default()); public static DAST._ICallName Default() { return theDefault; } @@ -4106,7 +4619,7 @@ public static DAST._ICallName Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ICallName create_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, Dafny.ISequence signature) { + public static _ICallName create_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, DAST._ICallSignature signature) { return new CallName_CallName(name, onType, receiverArg, receiverAsArgument, signature); } public static _ICallName create_MapBuilderAdd() { @@ -4150,7 +4663,7 @@ public bool dtor_receiverAsArgument { return ((CallName_CallName)d)._receiverAsArgument; } } - public Dafny.ISequence dtor_signature { + public DAST._ICallSignature dtor_signature { get { var d = this; return ((CallName_CallName)d)._signature; @@ -4163,8 +4676,8 @@ public class CallName_CallName : CallName { public readonly Std.Wrappers._IOption _onType; public readonly Std.Wrappers._IOption _receiverArg; public readonly bool _receiverAsArgument; - public readonly Dafny.ISequence _signature; - public CallName_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, Dafny.ISequence signature) : base() { + public readonly DAST._ICallSignature _signature; + public CallName_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, DAST._ICallSignature signature) : base() { this._name = name; this._onType = onType; this._receiverArg = receiverArg; @@ -6362,6 +6875,108 @@ public override string ToString() { } } + public interface _ISelectContext { + bool is_SelectContextDatatype { get; } + bool is_SelectContextGeneralTrait { get; } + bool is_SelectContextClassOrObjectTrait { get; } + _ISelectContext DowncastClone(); + } + public abstract class SelectContext : _ISelectContext { + public SelectContext() { + } + private static readonly DAST._ISelectContext theDefault = create_SelectContextDatatype(); + public static DAST._ISelectContext Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.SelectContext.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _ISelectContext create_SelectContextDatatype() { + return new SelectContext_SelectContextDatatype(); + } + public static _ISelectContext create_SelectContextGeneralTrait() { + return new SelectContext_SelectContextGeneralTrait(); + } + public static _ISelectContext create_SelectContextClassOrObjectTrait() { + return new SelectContext_SelectContextClassOrObjectTrait(); + } + public bool is_SelectContextDatatype { get { return this is SelectContext_SelectContextDatatype; } } + public bool is_SelectContextGeneralTrait { get { return this is SelectContext_SelectContextGeneralTrait; } } + public bool is_SelectContextClassOrObjectTrait { get { return this is SelectContext_SelectContextClassOrObjectTrait; } } + public static System.Collections.Generic.IEnumerable<_ISelectContext> AllSingletonConstructors { + get { + yield return SelectContext.create_SelectContextDatatype(); + yield return SelectContext.create_SelectContextGeneralTrait(); + yield return SelectContext.create_SelectContextClassOrObjectTrait(); + } + } + public abstract _ISelectContext DowncastClone(); + } + public class SelectContext_SelectContextDatatype : SelectContext { + public SelectContext_SelectContextDatatype() : base() { + } + public override _ISelectContext DowncastClone() { + if (this is _ISelectContext dt) { return dt; } + return new SelectContext_SelectContextDatatype(); + } + public override bool Equals(object other) { + var oth = other as DAST.SelectContext_SelectContextDatatype; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + return (int) hash; + } + public override string ToString() { + string s = "DAST.SelectContext.SelectContextDatatype"; + return s; + } + } + public class SelectContext_SelectContextGeneralTrait : SelectContext { + public SelectContext_SelectContextGeneralTrait() : base() { + } + public override _ISelectContext DowncastClone() { + if (this is _ISelectContext dt) { return dt; } + return new SelectContext_SelectContextGeneralTrait(); + } + public override bool Equals(object other) { + var oth = other as DAST.SelectContext_SelectContextGeneralTrait; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + return (int) hash; + } + public override string ToString() { + string s = "DAST.SelectContext.SelectContextGeneralTrait"; + return s; + } + } + public class SelectContext_SelectContextClassOrObjectTrait : SelectContext { + public SelectContext_SelectContextClassOrObjectTrait() : base() { + } + public override _ISelectContext DowncastClone() { + if (this is _ISelectContext dt) { return dt; } + return new SelectContext_SelectContextClassOrObjectTrait(); + } + public override bool Equals(object other) { + var oth = other as DAST.SelectContext_SelectContextClassOrObjectTrait; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 2; + return (int) hash; + } + public override string ToString() { + string s = "DAST.SelectContext.SelectContextClassOrObjectTrait"; + return s; + } + } + public interface _IExpression { bool is_Literal { get; } bool is_Ident { get; } @@ -6434,10 +7049,14 @@ public interface _IExpression { DAST._IExpression dtor_elem { get; } Dafny.ISequence dtor_elements { get; } Dafny.ISequence<_System._ITuple2> dtor_mapElems { get; } + DAST._IType dtor_domainType { get; } + DAST._IType dtor_rangeType { get; } DAST._IType dtor_keyType { get; } DAST._IType dtor_valueType { get; } DAST._IExpression dtor_expr { get; } DAST._IExpression dtor_indexExpr { get; } + DAST._IType dtor_collectionType { get; } + DAST._IType dtor_exprType { get; } DAST._IType dtor_elemType { get; } DAST._IExpression dtor_ToMultiset_a0 { get; } DAST._IExpression dtor_cond { get; } @@ -6449,13 +7068,12 @@ public interface _IExpression { DAST._IExpression dtor_left { get; } DAST._IExpression dtor_right { get; } DAST.Format._IBinaryOpFormat dtor_format2 { get; } - DAST._IType dtor_exprType { get; } BigInteger dtor_dim { get; } bool dtor_native { get; } Dafny.ISequence dtor_field { get; } DAST._IFieldMutability dtor_fieldMutability { get; } - bool dtor_isDatatype { get; } - DAST._IType dtor_fieldType { get; } + DAST._ISelectContext dtor_selectContext { get; } + DAST._IType dtor_isfieldType { get; } bool dtor_onDatatype { get; } bool dtor_isStatic { get; } bool dtor_isConstant { get; } @@ -6466,6 +7084,7 @@ public interface _IExpression { Std.Wrappers._IOption dtor_low { get; } Std.Wrappers._IOption dtor_high { get; } BigInteger dtor_index { get; } + DAST._IType dtor_fieldType { get; } DAST._IExpression dtor_on { get; } DAST._ICallName dtor_callName { get; } Dafny.ISequence dtor_params { get; } @@ -6487,6 +7106,7 @@ public interface _IExpression { bool dtor_is__forall { get; } DAST._IExpression dtor_lambda { get; } _IExpression DowncastClone(); + bool IsThisUpcast(); } public abstract class Expression : _IExpression { public Expression() { @@ -6544,17 +7164,17 @@ public static _IExpression create_SetValue(Dafny.ISequence el public static _IExpression create_MultisetValue(Dafny.ISequence elements) { return new Expression_MultisetValue(elements); } - public static _IExpression create_MapValue(Dafny.ISequence<_System._ITuple2> mapElems) { - return new Expression_MapValue(mapElems); + public static _IExpression create_MapValue(Dafny.ISequence<_System._ITuple2> mapElems, DAST._IType domainType, DAST._IType rangeType) { + return new Expression_MapValue(mapElems, domainType, rangeType); } public static _IExpression create_MapBuilder(DAST._IType keyType, DAST._IType valueType) { return new Expression_MapBuilder(keyType, valueType); } - public static _IExpression create_SeqUpdate(DAST._IExpression expr, DAST._IExpression indexExpr, DAST._IExpression @value) { - return new Expression_SeqUpdate(expr, indexExpr, @value); + public static _IExpression create_SeqUpdate(DAST._IExpression expr, DAST._IExpression indexExpr, DAST._IExpression @value, DAST._IType collectionType, DAST._IType exprType) { + return new Expression_SeqUpdate(expr, indexExpr, @value, collectionType, exprType); } - public static _IExpression create_MapUpdate(DAST._IExpression expr, DAST._IExpression indexExpr, DAST._IExpression @value) { - return new Expression_MapUpdate(expr, indexExpr, @value); + public static _IExpression create_MapUpdate(DAST._IExpression expr, DAST._IExpression indexExpr, DAST._IExpression @value, DAST._IType collectionType, DAST._IType exprType) { + return new Expression_MapUpdate(expr, indexExpr, @value, collectionType, exprType); } public static _IExpression create_SetBuilder(DAST._IType elemType) { return new Expression_SetBuilder(elemType); @@ -6586,8 +7206,8 @@ public static _IExpression create_MapValues(DAST._IExpression expr) { public static _IExpression create_MapItems(DAST._IExpression expr) { return new Expression_MapItems(expr); } - public static _IExpression create_Select(DAST._IExpression expr, Dafny.ISequence field, DAST._IFieldMutability fieldMutability, bool isDatatype, DAST._IType fieldType) { - return new Expression_Select(expr, field, fieldMutability, isDatatype, fieldType); + public static _IExpression create_Select(DAST._IExpression expr, Dafny.ISequence field, DAST._IFieldMutability fieldMutability, DAST._ISelectContext selectContext, DAST._IType isfieldType) { + return new Expression_Select(expr, field, fieldMutability, selectContext, isfieldType); } public static _IExpression create_SelectFn(DAST._IExpression expr, Dafny.ISequence field, bool onDatatype, bool isStatic, bool isConstant, Dafny.ISequence arguments) { return new Expression_SelectFn(expr, field, onDatatype, isStatic, isConstant, arguments); @@ -6841,6 +7461,18 @@ public Dafny.ISequence dtor_elements { return ((Expression_MapValue)d)._mapElems; } } + public DAST._IType dtor_domainType { + get { + var d = this; + return ((Expression_MapValue)d)._domainType; + } + } + public DAST._IType dtor_rangeType { + get { + var d = this; + return ((Expression_MapValue)d)._rangeType; + } + } public DAST._IType dtor_keyType { get { var d = this; @@ -6880,6 +7512,21 @@ public DAST._IExpression dtor_indexExpr { return ((Expression_MapUpdate)d)._indexExpr; } } + public DAST._IType dtor_collectionType { + get { + var d = this; + if (d is Expression_SeqUpdate) { return ((Expression_SeqUpdate)d)._collectionType; } + return ((Expression_MapUpdate)d)._collectionType; + } + } + public DAST._IType dtor_exprType { + get { + var d = this; + if (d is Expression_SeqUpdate) { return ((Expression_SeqUpdate)d)._exprType; } + if (d is Expression_MapUpdate) { return ((Expression_MapUpdate)d)._exprType; } + return ((Expression_ArrayLen)d)._exprType; + } + } public DAST._IType dtor_elemType { get { var d = this; @@ -6948,12 +7595,6 @@ public DAST.Format._IBinaryOpFormat dtor_format2 { return ((Expression_BinOp)d)._format2; } } - public DAST._IType dtor_exprType { - get { - var d = this; - return ((Expression_ArrayLen)d)._exprType; - } - } public BigInteger dtor_dim { get { var d = this; @@ -6979,17 +7620,16 @@ public DAST._IFieldMutability dtor_fieldMutability { return ((Expression_Select)d)._fieldMutability; } } - public bool dtor_isDatatype { + public DAST._ISelectContext dtor_selectContext { get { var d = this; - return ((Expression_Select)d)._isDatatype; + return ((Expression_Select)d)._selectContext; } } - public DAST._IType dtor_fieldType { + public DAST._IType dtor_isfieldType { get { var d = this; - if (d is Expression_Select) { return ((Expression_Select)d)._fieldType; } - return ((Expression_TupleSelect)d)._fieldType; + return ((Expression_Select)d)._isfieldType; } } public bool dtor_onDatatype { @@ -7052,6 +7692,12 @@ public BigInteger dtor_index { return ((Expression_TupleSelect)d)._index; } } + public DAST._IType dtor_fieldType { + get { + var d = this; + return ((Expression_TupleSelect)d)._fieldType; + } + } public DAST._IExpression dtor_on { get { var d = this; @@ -7181,6 +7827,9 @@ public DAST._IExpression dtor_lambda { } } public abstract _IExpression DowncastClone(); + public bool IsThisUpcast() { + return (((this).is_Convert) && (((this).dtor_value).is_This)) && (((this).dtor_from).Extends((this).dtor_typ)); + } } public class Expression_Literal : Expression { public readonly DAST._ILiteral _a0; @@ -7654,27 +8303,37 @@ public override string ToString() { } public class Expression_MapValue : Expression { public readonly Dafny.ISequence<_System._ITuple2> _mapElems; - public Expression_MapValue(Dafny.ISequence<_System._ITuple2> mapElems) : base() { + public readonly DAST._IType _domainType; + public readonly DAST._IType _rangeType; + public Expression_MapValue(Dafny.ISequence<_System._ITuple2> mapElems, DAST._IType domainType, DAST._IType rangeType) : base() { this._mapElems = mapElems; + this._domainType = domainType; + this._rangeType = rangeType; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_MapValue(_mapElems); + return new Expression_MapValue(_mapElems, _domainType, _rangeType); } public override bool Equals(object other) { var oth = other as DAST.Expression_MapValue; - return oth != null && object.Equals(this._mapElems, oth._mapElems); + return oth != null && object.Equals(this._mapElems, oth._mapElems) && object.Equals(this._domainType, oth._domainType) && object.Equals(this._rangeType, oth._rangeType); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 15; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._mapElems)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._domainType)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._rangeType)); return (int) hash; } public override string ToString() { string s = "DAST.Expression.MapValue"; s += "("; s += Dafny.Helpers.ToString(this._mapElems); + s += ", "; + s += Dafny.Helpers.ToString(this._domainType); + s += ", "; + s += Dafny.Helpers.ToString(this._rangeType); s += ")"; return s; } @@ -7715,18 +8374,22 @@ public class Expression_SeqUpdate : Expression { public readonly DAST._IExpression _expr; public readonly DAST._IExpression _indexExpr; public readonly DAST._IExpression _value; - public Expression_SeqUpdate(DAST._IExpression expr, DAST._IExpression indexExpr, DAST._IExpression @value) : base() { + public readonly DAST._IType _collectionType; + public readonly DAST._IType _exprType; + public Expression_SeqUpdate(DAST._IExpression expr, DAST._IExpression indexExpr, DAST._IExpression @value, DAST._IType collectionType, DAST._IType exprType) : base() { this._expr = expr; this._indexExpr = indexExpr; this._value = @value; + this._collectionType = collectionType; + this._exprType = exprType; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_SeqUpdate(_expr, _indexExpr, _value); + return new Expression_SeqUpdate(_expr, _indexExpr, _value, _collectionType, _exprType); } public override bool Equals(object other) { var oth = other as DAST.Expression_SeqUpdate; - return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._indexExpr, oth._indexExpr) && object.Equals(this._value, oth._value); + return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._indexExpr, oth._indexExpr) && object.Equals(this._value, oth._value) && object.Equals(this._collectionType, oth._collectionType) && object.Equals(this._exprType, oth._exprType); } public override int GetHashCode() { ulong hash = 5381; @@ -7734,6 +8397,8 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._indexExpr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._collectionType)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._exprType)); return (int) hash; } public override string ToString() { @@ -7744,6 +8409,10 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._indexExpr); s += ", "; s += Dafny.Helpers.ToString(this._value); + s += ", "; + s += Dafny.Helpers.ToString(this._collectionType); + s += ", "; + s += Dafny.Helpers.ToString(this._exprType); s += ")"; return s; } @@ -7752,18 +8421,22 @@ public class Expression_MapUpdate : Expression { public readonly DAST._IExpression _expr; public readonly DAST._IExpression _indexExpr; public readonly DAST._IExpression _value; - public Expression_MapUpdate(DAST._IExpression expr, DAST._IExpression indexExpr, DAST._IExpression @value) : base() { + public readonly DAST._IType _collectionType; + public readonly DAST._IType _exprType; + public Expression_MapUpdate(DAST._IExpression expr, DAST._IExpression indexExpr, DAST._IExpression @value, DAST._IType collectionType, DAST._IType exprType) : base() { this._expr = expr; this._indexExpr = indexExpr; this._value = @value; + this._collectionType = collectionType; + this._exprType = exprType; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_MapUpdate(_expr, _indexExpr, _value); + return new Expression_MapUpdate(_expr, _indexExpr, _value, _collectionType, _exprType); } public override bool Equals(object other) { var oth = other as DAST.Expression_MapUpdate; - return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._indexExpr, oth._indexExpr) && object.Equals(this._value, oth._value); + return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._indexExpr, oth._indexExpr) && object.Equals(this._value, oth._value) && object.Equals(this._collectionType, oth._collectionType) && object.Equals(this._exprType, oth._exprType); } public override int GetHashCode() { ulong hash = 5381; @@ -7771,6 +8444,8 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._indexExpr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._collectionType)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._exprType)); return (int) hash; } public override string ToString() { @@ -7781,6 +8456,10 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._indexExpr); s += ", "; s += Dafny.Helpers.ToString(this._value); + s += ", "; + s += Dafny.Helpers.ToString(this._collectionType); + s += ", "; + s += Dafny.Helpers.ToString(this._exprType); s += ")"; return s; } @@ -8103,22 +8782,22 @@ public class Expression_Select : Expression { public readonly DAST._IExpression _expr; public readonly Dafny.ISequence _field; public readonly DAST._IFieldMutability _fieldMutability; - public readonly bool _isDatatype; - public readonly DAST._IType _fieldType; - public Expression_Select(DAST._IExpression expr, Dafny.ISequence field, DAST._IFieldMutability fieldMutability, bool isDatatype, DAST._IType fieldType) : base() { + public readonly DAST._ISelectContext _selectContext; + public readonly DAST._IType _isfieldType; + public Expression_Select(DAST._IExpression expr, Dafny.ISequence field, DAST._IFieldMutability fieldMutability, DAST._ISelectContext selectContext, DAST._IType isfieldType) : base() { this._expr = expr; this._field = field; this._fieldMutability = fieldMutability; - this._isDatatype = isDatatype; - this._fieldType = fieldType; + this._selectContext = selectContext; + this._isfieldType = isfieldType; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_Select(_expr, _field, _fieldMutability, _isDatatype, _fieldType); + return new Expression_Select(_expr, _field, _fieldMutability, _selectContext, _isfieldType); } public override bool Equals(object other) { var oth = other as DAST.Expression_Select; - return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._field, oth._field) && object.Equals(this._fieldMutability, oth._fieldMutability) && this._isDatatype == oth._isDatatype && object.Equals(this._fieldType, oth._fieldType); + return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._field, oth._field) && object.Equals(this._fieldMutability, oth._fieldMutability) && object.Equals(this._selectContext, oth._selectContext) && object.Equals(this._isfieldType, oth._isfieldType); } public override int GetHashCode() { ulong hash = 5381; @@ -8126,8 +8805,8 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._field)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fieldMutability)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isDatatype)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fieldType)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._selectContext)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isfieldType)); return (int) hash; } public override string ToString() { @@ -8139,9 +8818,9 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._fieldMutability); s += ", "; - s += Dafny.Helpers.ToString(this._isDatatype); + s += Dafny.Helpers.ToString(this._selectContext); s += ", "; - s += Dafny.Helpers.ToString(this._fieldType); + s += Dafny.Helpers.ToString(this._isfieldType); s += ")"; return s; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index bfad8e31821..5ec3c109194 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -23,6 +23,8 @@ public COMP() { this._charType = Defs.CharType.Default(); this._pointerType = Defs.PointerType.Default(); this._syncType = Defs.SyncType.Default(); + this._rcDatatypeThis = RAST.Expr.Default(); + this._borrowedRcDatatypeThis = RAST.Expr.Default(); } public RAST._IType Object(RAST._IType underlying) { if (((this).pointerType).is_Raw) { @@ -41,6 +43,10 @@ public void __ctor(Defs._ICharType charType, Defs._IPointerType pointerType, Def (this)._syncType = syncType; (this).error = Std.Wrappers.Option>.create_None(); (this).optimizations = Dafny.Sequence>.FromElements(ExpressionOptimization.__default.apply, FactorPathsOptimization.__default.apply((this).thisFile)); + RAST._IExpr _0_thisAsSelf; + _0_thisAsSelf = Dafny.Helpers.Id>((this).rcNew)((RAST.__default.self).Clone()); + (this)._rcDatatypeThis = _0_thisAsSelf; + (this)._borrowedRcDatatypeThis = RAST.__default.Borrow(_0_thisAsSelf); } public bool HasAttribute(Dafny.ISequence attributes, Dafny.ISequence name) { @@ -64,10 +70,10 @@ public bool HasAttribute(Dafny.ISequence attributes, Dafny.ISe } else { Defs._IExternAttribute _4_optExtern; _4_optExtern = Defs.__default.ExtractExternMod(mod); - Dafny.ISequence> _5_attributes; - _5_attributes = Dafny.Sequence>.FromElements(); + Dafny.ISequence _5_attributes; + _5_attributes = Dafny.Sequence.FromElements(); if ((this).HasAttribute((mod).dtor_attributes, Dafny.Sequence.UnicodeFromString("rust_cfg_test"))) { - _5_attributes = Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[cfg(test)]")); + _5_attributes = Dafny.Sequence.FromElements(RAST.Attribute.CfgTest); } Dafny.ISequence _6_body; DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _7_allmodules; @@ -162,16 +168,52 @@ public void GenTypeParam(DAST._ITypeArgDecl tp, out DAST._IType typeArg, out RAS typeArg = DAST.Type.Default(); typeParam = RAST.TypeParamDecl.Default(); typeArg = DAST.Type.create_TypeArg((tp).dtor_name); - Dafny.ISequence _0_genTpConstraint; - if (((tp).dtor_bounds).Contains(DAST.TypeArgBound.create_SupportsEquality())) { - _0_genTpConstraint = Dafny.Sequence.FromElements(RAST.__default.DafnyTypeEq); - } else { - _0_genTpConstraint = Dafny.Sequence.FromElements(RAST.__default.DafnyType); + bool _0_supportsEquality; + _0_supportsEquality = false; + bool _1_supportsDefault; + _1_supportsDefault = false; + Dafny.ISequence _2_genTpConstraint; + _2_genTpConstraint = Dafny.Sequence.FromElements(); + BigInteger _hi0 = new BigInteger(((tp).dtor_bounds).Count); + for (BigInteger _3_i = BigInteger.Zero; _3_i < _hi0; _3_i++) { + DAST._ITypeArgBound _4_bound; + _4_bound = ((tp).dtor_bounds).Select(_3_i); + DAST._ITypeArgBound _source0 = _4_bound; + { + if (_source0.is_SupportsEquality) { + _0_supportsEquality = true; + goto after_match0; + } + } + { + if (_source0.is_SupportsDefault) { + _1_supportsDefault = true; + goto after_match0; + } + } + { + DAST._IType _5_typ = _source0.dtor_typ; + RAST._IType _6_tpe; + RAST._IType _out0; + _out0 = (this).GenType(_5_typ, Defs.GenTypeContext.ForTraitParents()); + _6_tpe = _out0; + RAST._IType _7_upcast__tpe; + _7_upcast__tpe = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_6_tpe))); + _2_genTpConstraint = Dafny.Sequence.Concat(_2_genTpConstraint, Dafny.Sequence.FromElements(_7_upcast__tpe)); + } + after_match0: ; + } + if (_1_supportsDefault) { + _2_genTpConstraint = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.__default.DefaultTrait), _2_genTpConstraint); } - if (((tp).dtor_bounds).Contains(DAST.TypeArgBound.create_SupportsDefault())) { - _0_genTpConstraint = Dafny.Sequence.Concat(_0_genTpConstraint, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IType _8_dafnyType; + if (_0_supportsEquality) { + _8_dafnyType = RAST.__default.DafnyTypeEq; + } else { + _8_dafnyType = RAST.__default.DafnyType; } - typeParam = RAST.TypeParamDecl.create(Defs.__default.escapeName(((tp).dtor_name)), _0_genTpConstraint); + _2_genTpConstraint = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_8_dafnyType), _2_genTpConstraint); + typeParam = RAST.TypeParamDecl.create(Defs.__default.escapeName(((tp).dtor_name)), _2_genTpConstraint); } public void GenTypeParameters(Dafny.ISequence @params, out Dafny.ISequence typeParamsSeq, out Dafny.ISequence rTypeParams, out Dafny.ISequence rTypeParamsDecls) { @@ -280,13 +322,13 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } } } - public Dafny.ISequence GenTraitImplementations(Dafny.ISequence> path, Dafny.ISequence rTypeParams, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence superTraitTypes, Dafny.IMap>,Dafny.ISequence> traitBodies, Defs._IExternAttribute @extern, Dafny.ISequence kind) + public Dafny.ISequence GenTraitImplementations(Dafny.ISequence> classPath, Dafny.ISequence rTypeParams, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence superTraitTypes, Dafny.IMap>,Dafny.ISequence> traitBodies, Defs._IExternAttribute @extern, bool supportsEquality, Dafny.ISequence kind) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); RAST._IPath _0_genPath; RAST._IPath _out0; - _out0 = (this).GenPath(path, true); + _out0 = (this).GenPath(classPath, true); _0_genPath = _out0; RAST._IType _1_genSelfPath; _1_genSelfPath = (_0_genPath).AsType(); @@ -307,56 +349,54 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc DAST._ITraitType _7_traitType = kind0.dtor_traitType; Dafny.ISequence> _8_properMethods = resolved0.dtor_properMethods; { - RAST._IType _9_pathStr; - RAST._IType _out1; - _out1 = (this).GenPathType(_5_traitPath); - _9_pathStr = _out1; - Dafny.ISequence _10_typeArgs; + RAST._IPath _9_path; + RAST._IPath _out1; + _out1 = (this).GenPath(_5_traitPath, true); + _9_path = _out1; + RAST._IType _10_pathType; + _10_pathType = (_9_path).AsType(); + Dafny.ISequence _11_typeArgs; Dafny.ISequence _out2; _out2 = (this).GenTypeArgs(_6_typeArgs, Defs.GenTypeContext.@default()); - _10_typeArgs = _out2; - Dafny.ISequence _11_body; - _11_body = Dafny.Sequence.FromElements(); + _11_typeArgs = _out2; + Dafny.ISequence _12_body; + _12_body = Dafny.Sequence.FromElements(); if ((traitBodies).Contains(_5_traitPath)) { - _11_body = Dafny.Map>, Dafny.ISequence>.Select(traitBodies,_5_traitPath); + _12_body = Dafny.Map>, Dafny.ISequence>.Select(traitBodies,_5_traitPath); } - RAST._IType _12_fullTraitPath; - _12_fullTraitPath = RAST.Type.create_TypeApp(_9_pathStr, _10_typeArgs); + RAST._IType _13_fullTraitPath; + _13_fullTraitPath = RAST.Type.create_TypeApp(_10_pathType, _11_typeArgs); + RAST._IExpr _14_fullTraitExpr; + _14_fullTraitExpr = ((_9_path).AsExpr()).ApplyType(_11_typeArgs); if (!((@extern).is_NoExtern)) { - if (((new BigInteger((_11_body).Count)).Sign == 0) && ((new BigInteger((_8_properMethods).Count)).Sign != 0)) { + if (((new BigInteger((_12_body).Count)).Sign == 0) && ((new BigInteger((_8_properMethods).Count)).Sign != 0)) { goto continue_0; } - if ((new BigInteger((_11_body).Count)) != (new BigInteger((_8_properMethods).Count))) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(path, ((System.Func, Dafny.ISequence>)((_13_s) => { - return ((_13_s)); -})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_12_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_8_properMethods, ((System.Func, Dafny.ISequence>)((_14_s) => { - return (_14_s); + if ((new BigInteger((_12_body).Count)) != (new BigInteger((_8_properMethods).Count))) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(classPath, ((System.Func, Dafny.ISequence>)((_15_s) => { + return ((_15_s)); +})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_13_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_8_properMethods, ((System.Func, Dafny.ISequence>)((_16_s) => { + return (_16_s); })), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") bodiless and mark as {:extern} and implement them in a Rust file, ")), Dafny.Sequence.UnicodeFromString("or mark none of them as {:extern} and implement them in Dafny. ")), Dafny.Sequence.UnicodeFromString("Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."))); } } if ((_7_traitType).is_GeneralTrait) { - _11_body = Dafny.Sequence.Concat(_11_body, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_12_fullTraitPath))), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))))); + _12_body = Dafny.Sequence.Concat(_12_body, Dafny.Sequence.FromElements(Defs.__default.clone__trait(_13_fullTraitPath), Defs.__default.print__trait, Defs.__default.hasher__trait(supportsEquality, (this).pointerType), Defs.__default.eq__trait(_13_fullTraitPath, _14_fullTraitExpr, supportsEquality, (this).pointerType), Defs.__default.as__any__trait)); } else { if (((kind).Equals(Dafny.Sequence.UnicodeFromString("datatype"))) || ((kind).Equals(Dafny.Sequence.UnicodeFromString("newtype")))) { - RAST._IExpr _15_dummy; + RAST._IExpr _17_dummy; RAST._IExpr _out3; _out3 = (this).Error(Dafny.Sequence.UnicodeFromString("Cannot extend non-general traits"), (this).InitEmptyExpr()); - _15_dummy = _out3; + _17_dummy = _out3; } } - RAST._IModDecl _16_x; - _16_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _12_fullTraitPath, RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), _11_body)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_16_x)); - Dafny.ISequence _17_upcastTraitToImplement = Dafny.Sequence.Empty; - Dafny.ISequence _18_upcastTraitFn = Dafny.Sequence.Empty; + RAST._IModDecl _18_x; + _18_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _13_fullTraitPath, RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), _12_body)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_18_x)); if ((_7_traitType).is_GeneralTrait) { - Dafny.ISequence _rhs0 = Dafny.Sequence.UnicodeFromString("UpcastBox"); - Dafny.ISequence _rhs1 = Dafny.Sequence.UnicodeFromString("UpcastStructBoxFn!"); - _17_upcastTraitToImplement = _rhs0; - _18_upcastTraitFn = _rhs1; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_12_fullTraitPath)), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_12_fullTraitPath))), Std.Wrappers.Option.create_Some((((_2_genPathExpr).ApplyType(rTypeParams)).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(RAST.__default.self))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_13_fullTraitPath)), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_13_fullTraitPath))), Std.Wrappers.Option.create_Some(((((_9_path).AsExpr()).ApplyType(_11_typeArgs)).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(RAST.__default.self))))))))); } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_12_fullTraitPath))), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_12_fullTraitPath))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_13_fullTraitPath))), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_13_fullTraitPath))))))))); } } goto after_match0; @@ -439,7 +479,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _16_className = _out9; _17_extern = _out10; RAST._IStruct _18_struct; - _18_struct = RAST.Struct.create((c).dtor_docString, Dafny.Sequence>.FromElements(), _16_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_4_fields)); + _18_struct = RAST.Struct.create((c).dtor_docString, Dafny.Sequence.FromElements(), _16_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_4_fields)); s = Dafny.Sequence.FromElements(); if ((_17_extern).is_NoExtern) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_18_struct))); @@ -482,7 +522,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc if (((this).HasAttribute((_25_m).dtor_attributes, Dafny.Sequence.UnicodeFromString("test"))) && ((new BigInteger(((_25_m).dtor_params).Count)).Sign == 0)) { Dafny.ISequence _27_fnName; _27_fnName = Defs.__default.escapeName((_25_m).dtor_name); - _23_testMethods = Dafny.Sequence.Concat(_23_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create((_25_m).dtor_docString, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[test]")), RAST.Visibility.create_PUB(), RAST.Fn.create(_27_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_27_fnName)).Apply(Dafny.Sequence.FromElements()))))))); + _23_testMethods = Dafny.Sequence.Concat(_23_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create((_25_m).dtor_docString, Dafny.Sequence.FromElements(RAST.Attribute.Name(Dafny.Sequence.UnicodeFromString("test"))), RAST.Visibility.create_PUB(), RAST.Fn.create(_27_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_27_fnName)).Apply(Dafny.Sequence.FromElements()))))))); } } s = Dafny.Sequence.Concat(s, _23_testMethods); @@ -502,7 +542,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } Dafny.ISequence _30_superTraitImplementations; Dafny.ISequence _out14; - _out14 = (this).GenTraitImplementations(path, _1_rTypeParams, _2_rTypeParamsDecls, _29_superTraitTypes, _20_traitBodies, _17_extern, Dafny.Sequence.UnicodeFromString("class")); + _out14 = (this).GenTraitImplementations(path, _1_rTypeParams, _2_rTypeParamsDecls, _29_superTraitTypes, _20_traitBodies, _17_extern, true, Dafny.Sequence.UnicodeFromString("class")); _30_superTraitImplementations = _out14; s = Dafny.Sequence.Concat(s, _30_superTraitImplementations); return s; @@ -541,49 +581,124 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _8_fullPath = Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((t).dtor_name)); Dafny.ISequence _9_name; _9_name = Defs.__default.escapeName((t).dtor_name); - RAST._IType _10_traitFulltype; - _10_traitFulltype = (RAST.Type.create_TIdentifier(_9_name)).Apply(_2_typeParams); + RAST._IType _10_traitFullType; + _10_traitFullType = (RAST.Type.create_TIdentifier(_9_name)).Apply(_2_typeParams); RAST._IExpr _11_traitFullExpr; _11_traitFullExpr = (RAST.Expr.create_Identifier(_9_name)).ApplyType(_2_typeParams); Dafny.ISequence _12_implBody; - Dafny.IMap>,Dafny.ISequence> _13___v5; + Dafny.IMap>,Dafny.ISequence> _13_implBodyImplementingOtherTraits; Dafny.ISequence _out3; Dafny.IMap>,Dafny.ISequence> _out4; (this).GenClassImplBody((t).dtor_body, true, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_8_fullPath, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Trait((t).dtor_traitType), (t).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out3, out _out4); _12_implBody = _out3; - _13___v5 = _out4; + _13_implBodyImplementingOtherTraits = _out4; + if (((t).dtor_traitType).is_GeneralTrait) { + _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType(RAST.__default.AnyTrait))), Std.Wrappers.Option.create_None())))); + } + while ((new BigInteger((_13_implBodyImplementingOtherTraits).Count)).Sign == 1) { + Dafny.ISequence> _14_otherTrait; + foreach (Dafny.ISequence> _assign_such_that_0 in (_13_implBodyImplementingOtherTraits).Keys.Elements) { + _14_otherTrait = (Dafny.ISequence>)_assign_such_that_0; + if ((_13_implBodyImplementingOtherTraits).Contains(_14_otherTrait)) { + goto after__ASSIGN_SUCH_THAT_0; + } + } + throw new System.Exception("assign-such-that search produced no value"); + after__ASSIGN_SUCH_THAT_0: ; + Dafny.ISequence _15_otherMethods; + _15_otherMethods = Dafny.Map>, Dafny.ISequence>.Select(_13_implBodyImplementingOtherTraits,_14_otherTrait); + BigInteger _hi1 = new BigInteger((_15_otherMethods).Count); + for (BigInteger _16_i = BigInteger.Zero; _16_i < _hi1; _16_i++) { + _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements((_15_otherMethods).Select(_16_i))); + } + _13_implBodyImplementingOtherTraits = Dafny.Map>, Dafny.ISequence>.Subtract(_13_implBodyImplementingOtherTraits, Dafny.Set>>.FromElements(_14_otherTrait)); + } + Dafny.ISequence _17_parents; + _17_parents = Dafny.Sequence.FromElements(); + Dafny.ISequence _18_upcastImplemented; + _18_upcastImplemented = Dafny.Sequence.FromElements(); + RAST._IType _19_instantiatedFullType = RAST.Type.Default(); if (((t).dtor_traitType).is_GeneralTrait) { - _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))), Std.Wrappers.Option.create_None())))); - } - Dafny.ISequence _14_parents; - _14_parents = Dafny.Sequence.FromElements(); - Dafny.ISequence _15_upcastImplemented; - _15_upcastImplemented = Dafny.Sequence.FromElements(); - BigInteger _hi1 = new BigInteger(((t).dtor_parents).Count); - for (BigInteger _16_i = BigInteger.Zero; _16_i < _hi1; _16_i++) { - DAST._IType _17_parentTyp; - _17_parentTyp = ((t).dtor_parents).Select(_16_i); - RAST._IType _18_parentTpe; + _19_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); + RAST._IModDecl _20_upcastDynTrait; + _20_upcastDynTrait = Defs.__default.UpcastDynTraitFor(_1_rTypeParamsDecls, _19_instantiatedFullType, _10_traitFullType, _11_traitFullExpr); + _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(_20_upcastDynTrait)); + } + BigInteger _hi2 = new BigInteger(((t).dtor_parents).Count); + for (BigInteger _21_i = BigInteger.Zero; _21_i < _hi2; _21_i++) { + DAST._IType _22_parentTyp; + _22_parentTyp = ((t).dtor_parents).Select(_21_i); + RAST._IType _23_parentTpe; RAST._IType _out5; - _out5 = (this).GenType(_17_parentTyp, Defs.GenTypeContext.ForTraitParents()); - _18_parentTpe = _out5; - _14_parents = Dafny.Sequence.Concat(_14_parents, Dafny.Sequence.FromElements(_18_parentTpe)); - Dafny.ISequence _19_upcastTrait; - if ((_17_parentTyp).IsGeneralTrait()) { - _19_upcastTrait = Dafny.Sequence.UnicodeFromString("UpcastBox"); + _out5 = (this).GenType(_22_parentTyp, Defs.GenTypeContext.ForTraitParents()); + _23_parentTpe = _out5; + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements(_23_parentTpe)); + Dafny.ISequence _24_upcastTrait; + if ((_22_parentTyp).IsGeneralTrait()) { + _24_upcastTrait = Dafny.Sequence.UnicodeFromString("UpcastBox"); } else { - _19_upcastTrait = (this).Upcast; - } - _14_parents = Dafny.Sequence.Concat(_14_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_19_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)))); - if ((_17_parentTyp).IsGeneralTrait()) { - _15_upcastImplemented = Dafny.Sequence.Concat(_15_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_18_parentTpe))), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); + _24_upcastTrait = (this).Upcast; + } + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_24_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_23_parentTpe)))); + if ((((_22_parentTyp).IsGeneralTrait()) && (((t).dtor_traitType).is_GeneralTrait)) && (!object.Equals(_23_parentTpe, (this).AnyTrait))) { + Std.Wrappers._IOption _25_parentTpeExprMaybe; + _25_parentTpeExprMaybe = (_23_parentTpe).ToExpr(); + RAST._IExpr _26_parentTpeExpr = RAST.Expr.Default(); + if ((_25_parentTpeExprMaybe).is_None) { + RAST._IExpr _out6; + _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_23_parentTpe)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + _26_parentTpeExpr = _out6; + } else { + _26_parentTpeExpr = (_25_parentTpeExprMaybe).dtor_value; + } + RAST._IModDecl _27_upcastDynTrait; + _27_upcastDynTrait = Defs.__default.UpcastDynTraitFor(_1_rTypeParamsDecls, _19_instantiatedFullType, _23_parentTpe, _26_parentTpeExpr); + _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(_27_upcastDynTrait)); + } + } + Dafny.ISequence _28_downcastDefinition; + _28_downcastDefinition = Dafny.Sequence.FromElements(); + if (((new BigInteger(((t).dtor_parents).Count)).Sign == 1) && (((t).dtor_traitType).is_GeneralTrait)) { + Std.Wrappers._IOption _29_downcastDefinitionOpt; + _29_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_1_rTypeParamsDecls, _19_instantiatedFullType); + if ((_29_downcastDefinitionOpt).is_None) { + RAST._IExpr _30_dummy; + RAST._IExpr _out7; + _out7 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_19_instantiatedFullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _30_dummy = _out7; + } else { + _28_downcastDefinition = Dafny.Sequence.FromElements((_29_downcastDefinitionOpt).dtor_value); + } + } else if (((t).dtor_traitType).is_GeneralTrait) { + _17_parents = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsType()), _17_parents); + } + if (((new BigInteger(((t).dtor_downcastableTraits).Count)).Sign == 1) && (((t).dtor_traitType).is_GeneralTrait)) { + BigInteger _hi3 = new BigInteger(((t).dtor_downcastableTraits).Count); + for (BigInteger _31_i = BigInteger.Zero; _31_i < _hi3; _31_i++) { + RAST._IType _32_downcastableTrait; + RAST._IType _out8; + _out8 = (this).GenType(((t).dtor_downcastableTraits).Select(_31_i), Defs.GenTypeContext.ForTraitParents()); + _32_downcastableTrait = _out8; + Std.Wrappers._IOption _33_downcastTraitOpt; + _33_downcastTraitOpt = (_32_downcastableTrait).ToDowncast(); + if ((_33_downcastTraitOpt).is_Some) { + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((_33_downcastTraitOpt).dtor_value)); + } else { + RAST._IExpr _34_r; + RAST._IExpr _out9; + _out9 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_32_downcastableTrait)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to its downcast version")), (this).InitEmptyExpr()); + _34_r = _out9; + } } } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create((t).dtor_docString, Dafny.Sequence>.FromElements(), _1_rTypeParamsDecls, _10_traitFulltype, _14_parents, _12_implBody))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create((t).dtor_docString, Dafny.Sequence.FromElements(), _1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); + s = Dafny.Sequence.Concat(s, _28_downcastDefinition); if (((t).dtor_traitType).is_GeneralTrait) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_eq"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements())))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.Hash, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_hash"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))))))))); } - s = Dafny.Sequence.Concat(s, _15_upcastImplemented); + s = Dafny.Sequence.Concat(s, _18_upcastImplemented); return s; } public Dafny.ISequence GenNewtype(DAST._INewtype c, Dafny.ISequence> path) @@ -618,43 +733,54 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc RAST._IType _8_resultingType; _8_resultingType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams); Dafny.ISequence _9_attributes = Dafny.Sequence.Empty; + Dafny.ISequence> _10_deriveTraits; + _10_deriveTraits = Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("Clone")); if (Defs.__default.IsNewtypeCopy((c).dtor_range)) { - _9_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq, Copy)]"); - } else { - _9_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq)]"); - } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create((c).dtor_docString, Dafny.Sequence>.FromElements(_9_attributes, Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), _7_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _4_wrappedType)))))); - RAST._IExpr _10_fnBody = RAST.Expr.Default(); + _10_deriveTraits = Dafny.Sequence>.Concat(_10_deriveTraits, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("Copy"))); + } + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create((c).dtor_docString, Dafny.Sequence.FromElements(RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("derive"), _10_deriveTraits), RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("repr"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("transparent")))), _7_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _4_wrappedType)))))); + if (((c).dtor_equalitySupport).is_ConsultTypeArguments) { + RAST._IExpr _11_eqImplBody; + _11_eqImplBody = ((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))).Equals((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))); + RAST._IExpr _12_hashImplBody; + _12_hashImplBody = (Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + Dafny.ISequence _13_impls; + Dafny.ISequence _out4; + _out4 = (this).GenEqHashImpls((c).dtor_typeParams, _2_rTypeParamsDecls, _1_rTypeParams, _8_resultingType, _11_eqImplBody, _12_hashImplBody); + _13_impls = _out4; + s = Dafny.Sequence.Concat(s, _13_impls); + } + RAST._IExpr _14_fnBody = RAST.Expr.Default(); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; { if (_source0.is_Some) { - DAST._IExpression _11_e = _source0.dtor_value; + DAST._IExpression _15_e = _source0.dtor_value; { - DAST._IExpression _12_e; - _12_e = DAST.Expression.create_Convert(_11_e, (c).dtor_base, _6_newtypeType); - RAST._IExpr _13_r; - Defs._IOwnership _14___v6; - Dafny.ISet> _15___v7; - RAST._IExpr _out4; - Defs._IOwnership _out5; - Dafny.ISet> _out6; - (this).GenExpr(_12_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out4, out _out5, out _out6); - _13_r = _out4; - _14___v6 = _out5; - _15___v7 = _out6; - _10_fnBody = _13_r; + DAST._IExpression _16_e; + _16_e = DAST.Expression.create_Convert(_15_e, (c).dtor_base, _6_newtypeType); + RAST._IExpr _17_r; + Defs._IOwnership _18___v5; + Dafny.ISet> _19___v6; + RAST._IExpr _out5; + Defs._IOwnership _out6; + Dafny.ISet> _out7; + (this).GenExpr(_16_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); + _17_r = _out5; + _18___v5 = _out6; + _19___v6 = _out7; + _14_fnBody = _17_r; } goto after_match0; } } { { - _10_fnBody = (RAST.Expr.create_Identifier(_7_newtypeName)).Apply1(RAST.__default.std__default__Default__default); + _14_fnBody = (RAST.Expr.create_Identifier(_7_newtypeName)).Apply1(RAST.__default.std__default__Default__default); } } after_match0: ; - RAST._IImplMember _16_body; - _16_body = RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _7_newtypeName), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(_10_fnBody))); + RAST._IImplMember _20_body; + _20_body = RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _7_newtypeName), Dafny.Sequence.FromElements(), RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(_14_fnBody))); Std.Wrappers._IOption _source1 = (c).dtor_constraint; { if (_source1.is_None) { @@ -663,50 +789,47 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } { DAST._INewtypeConstraint value0 = _source1.dtor_value; - DAST._IFormal _17_formal = value0.dtor_variable; - Dafny.ISequence _18_constraintStmts = value0.dtor_constraintStmts; - RAST._IExpr _19_rStmts; - Dafny.ISet> _20___v8; - Defs._IEnvironment _21_newEnv; - RAST._IExpr _out7; - Dafny.ISet> _out8; - Defs._IEnvironment _out9; - (this).GenStmts(_18_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out7, out _out8, out _out9); - _19_rStmts = _out7; - _20___v8 = _out8; - _21_newEnv = _out9; - Dafny.ISequence _22_rFormals; - Dafny.ISequence _out10; - _out10 = (this).GenParams(Dafny.Sequence.FromElements(_17_formal), false); - _22_rFormals = _out10; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Constraint check"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _22_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_19_rStmts)))))))); + DAST._IFormal _21_formal = value0.dtor_variable; + Dafny.ISequence _22_constraintStmts = value0.dtor_constraintStmts; + RAST._IExpr _23_rStmts; + Dafny.ISet> _24___v7; + Defs._IEnvironment _25_newEnv; + RAST._IExpr _out8; + Dafny.ISet> _out9; + Defs._IEnvironment _out10; + (this).GenStmts(_22_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out8, out _out9, out _out10); + _23_rStmts = _out8; + _24___v7 = _out9; + _25_newEnv = _out10; + Dafny.ISequence _26_rFormals; + Dafny.ISequence _out11; + _out11 = (this).GenParams(Dafny.Sequence.FromElements(_21_formal), Dafny.Sequence.FromElements(_21_formal), false); + _26_rFormals = _out11; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Constraint check"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _26_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_23_rStmts)))))))); } after_match1: ; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.FromElements(_16_body))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("For Dafny print statements"), RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.FromElements(_20_body))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("For Dafny print statements"), RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _4_wrappedType), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("SAFETY: The newtype is marked as transparent"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); - Dafny.ISequence _23_rTypeParamsDeclsWithHash; - _23_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_23_rTypeParamsDeclsWithHash, _8_resultingType, (((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))); if (((c).dtor_range).HasArithmeticOperations()) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.OpsImpl(new Dafny.Rune('+'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('-'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('*'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('/'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.PartialOrdImpl(_2_rTypeParamsDecls, _8_resultingType, _7_newtypeName))); } if (((c).dtor_range).is_Bool) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.UnaryOpsImpl(new Dafny.Rune('!'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName))); } - Dafny.ISequence _24_implementation; - Dafny.IMap>,Dafny.ISequence> _25_traitBodies; - Dafny.ISequence _out11; - Dafny.IMap>,Dafny.ISequence> _out12; - (this).GenClassImplBody((c).dtor_classItems, false, _6_newtypeType, _0_typeParamsSeq, out _out11, out _out12); - _24_implementation = _out11; - _25_traitBodies = _out12; - if ((new BigInteger((_25_traitBodies).Count)).Sign == 1) { + Dafny.ISequence _27_implementation; + Dafny.IMap>,Dafny.ISequence> _28_traitBodies; + Dafny.ISequence _out12; + Dafny.IMap>,Dafny.ISequence> _out13; + (this).GenClassImplBody((c).dtor_classItems, false, _6_newtypeType, _0_typeParamsSeq, out _out12, out _out13); + _27_implementation = _out12; + _28_traitBodies = _out13; + if ((new BigInteger((_28_traitBodies).Count)).Sign == 1) { (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("No support for trait in newtypes yet")); } - if ((new BigInteger((_24_implementation).Count)).Sign == 1) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams), _24_implementation)))); + if ((new BigInteger((_27_implementation).Count)).Sign == 1) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams), _27_implementation)))); } return s; } @@ -729,7 +852,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc RAST._IType _out3; _out3 = (this).GenType((c).dtor_base, Defs.GenTypeContext.@default()); _4_resultingType = _out3; - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create((c).dtor_docString, Dafny.Sequence>.FromElements(), _3_synonymTypeName, _2_rTypeParamsDecls, _4_resultingType))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create((c).dtor_docString, Dafny.Sequence.FromElements(), _3_synonymTypeName, _2_rTypeParamsDecls, _4_resultingType))); Dafny.ISequence _5_defaultConstrainedTypeParams; _5_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; @@ -738,28 +861,28 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc DAST._IExpression _6_e = _source0.dtor_value; { RAST._IExpr _7_rStmts; - Dafny.ISet> _8___v9; + Dafny.ISet> _8___v8; Defs._IEnvironment _9_newEnv; RAST._IExpr _out4; Dafny.ISet> _out5; Defs._IEnvironment _out6; (this).GenStmts((c).dtor_witnessStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out4, out _out5, out _out6); _7_rStmts = _out4; - _8___v9 = _out5; + _8___v8 = _out5; _9_newEnv = _out6; RAST._IExpr _10_rExpr; - Defs._IOwnership _11___v10; - Dafny.ISet> _12___v11; + Defs._IOwnership _11___v9; + Dafny.ISet> _12___v10; RAST._IExpr _out7; Defs._IOwnership _out8; Dafny.ISet> _out9; (this).GenExpr(_6_e, Defs.SelfInfo.create_NoSelf(), _9_newEnv, Defs.Ownership.create_OwnershipOwned(), out _out7, out _out8, out _out9); _10_rExpr = _out7; - _11___v10 = _out8; - _12___v11 = _out9; + _11___v9 = _out8; + _12___v10 = _out9; Dafny.ISequence _13_constantName; _13_constantName = Defs.__default.escapeName(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_init_"), ((c).dtor_name))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _3_synonymTypeName), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_13_constantName, _5_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_4_resultingType), Std.Wrappers.Option.create_Some((_7_rStmts).Then(_10_rExpr))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _3_synonymTypeName), Dafny.Sequence.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_13_constantName, _5_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_4_resultingType), Std.Wrappers.Option.create_Some((_7_rStmts).Then(_10_rExpr))))))); } goto after_match0; } @@ -769,100 +892,6 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc after_match0: ; return s; } - public bool TypeIsEq(DAST._IType t) { - DAST._IType _source0 = t; - { - if (_source0.is_UserDefined) { - return true; - } - } - { - if (_source0.is_Tuple) { - Dafny.ISequence _0_ts = _source0.dtor_Tuple_a0; - return Dafny.Helpers.Id, bool>>((_1_ts) => Dafny.Helpers.Quantifier((_1_ts).UniqueElements, true, (((_forall_var_0) => { - DAST._IType _2_t = (DAST._IType)_forall_var_0; - return !((_1_ts).Contains(_2_t)) || ((this).TypeIsEq(_2_t)); - }))))(_0_ts); - } - } - { - if (_source0.is_Array) { - DAST._IType _3_t = _source0.dtor_element; - return (this).TypeIsEq(_3_t); - } - } - { - if (_source0.is_Seq) { - DAST._IType _4_t = _source0.dtor_element; - return (this).TypeIsEq(_4_t); - } - } - { - if (_source0.is_Set) { - DAST._IType _5_t = _source0.dtor_element; - return (this).TypeIsEq(_5_t); - } - } - { - if (_source0.is_Multiset) { - DAST._IType _6_t = _source0.dtor_element; - return (this).TypeIsEq(_6_t); - } - } - { - if (_source0.is_Map) { - DAST._IType _7_k = _source0.dtor_key; - DAST._IType _8_v = _source0.dtor_value; - return ((this).TypeIsEq(_7_k)) && ((this).TypeIsEq(_8_v)); - } - } - { - if (_source0.is_SetBuilder) { - DAST._IType _9_t = _source0.dtor_element; - return (this).TypeIsEq(_9_t); - } - } - { - if (_source0.is_MapBuilder) { - DAST._IType _10_k = _source0.dtor_key; - DAST._IType _11_v = _source0.dtor_value; - return ((this).TypeIsEq(_10_k)) && ((this).TypeIsEq(_11_v)); - } - } - { - if (_source0.is_Arrow) { - return false; - } - } - { - if (_source0.is_Primitive) { - return true; - } - } - { - if (_source0.is_Passthrough) { - return true; - } - } - { - if (_source0.is_TypeArg) { - Dafny.ISequence _12_i = _source0.dtor_TypeArg_a0; - return true; - } - } - { - return true; - } - } - public bool DatatypeIsEq(DAST._IDatatype c) { - return (!((c).dtor_isCo)) && (Dafny.Helpers.Id>((_0_c) => Dafny.Helpers.Quantifier(((_0_c).dtor_ctors).UniqueElements, true, (((_forall_var_0) => { - DAST._IDatatypeCtor _1_ctor = (DAST._IDatatypeCtor)_forall_var_0; - return Dafny.Helpers.Quantifier(((_1_ctor).dtor_args).UniqueElements, true, (((_forall_var_1) => { - DAST._IDatatypeDtor _2_arg = (DAST._IDatatypeDtor)_forall_var_1; - return !((((_0_c).dtor_ctors).Contains(_1_ctor)) && (((_1_ctor).dtor_args).Contains(_2_arg))) || ((this).TypeIsEq(((_2_arg).dtor_formal).dtor_typ)); - }))); - }))))(c)); - } public RAST._IExpr write(RAST._IExpr r, bool final) { RAST._IExpr _0_result = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("write!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), r)); @@ -876,406 +905,525 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) { return (this).write(RAST.Expr.create_LiteralString(s, false, false), false); } + public Dafny.ISequence GenEqHashImpls(Dafny.ISequence typeParamsDecls, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence rTypeParams, RAST._IType datatypeType, RAST._IExpr eqImplBody, RAST._IExpr hashImplBody) + { + Dafny.ISequence impls = Dafny.Sequence.Empty; + Dafny.ISequence _0_rTypeParamsDeclsWithEq; + _0_rTypeParamsDeclsWithEq = rTypeParamsDecls; + Dafny.ISequence _1_rTypeParamsDeclsWithHash; + _1_rTypeParamsDeclsWithHash = rTypeParamsDecls; + BigInteger _hi0 = new BigInteger((rTypeParamsDecls).Count); + for (BigInteger _2_i = BigInteger.Zero; _2_i < _hi0; _2_i++) { + if ((((typeParamsDecls).Select(_2_i)).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + _0_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_0_rTypeParamsDeclsWithEq, _2_i, ((_0_rTypeParamsDeclsWithEq).Select(_2_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); + _1_rTypeParamsDeclsWithHash = Dafny.Sequence.Update(_1_rTypeParamsDeclsWithHash, _2_i, ((_1_rTypeParamsDeclsWithHash).Select(_2_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Hash))); + } + } + impls = Defs.__default.EqImpl(_0_rTypeParamsDeclsWithEq, datatypeType, rTypeParams, eqImplBody); + impls = Dafny.Sequence.Concat(impls, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_1_rTypeParamsDeclsWithHash, datatypeType, hashImplBody))); + return impls; + } public Dafny.ISequence GenDatatype(DAST._IDatatype c, Dafny.ISequence> path) { Dafny.ISequence s = Dafny.Sequence.Empty; - Dafny.ISequence _0_typeParamsSeq; - Dafny.ISequence _1_rTypeParams; - Dafny.ISequence _2_rTypeParamsDecls; + bool _0_isRcWrapped; + _0_isRcWrapped = Defs.__default.IsRcWrapped((c).dtor_attributes); + Dafny.ISequence _1_typeParamsSeq; + Dafny.ISequence _2_rTypeParams; + Dafny.ISequence _3_rTypeParamsDecls; Dafny.ISequence _out0; Dafny.ISequence _out1; Dafny.ISequence _out2; (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2); - _0_typeParamsSeq = _out0; - _1_rTypeParams = _out1; - _2_rTypeParamsDecls = _out2; - Dafny.ISequence _3_datatypeName; - Defs._IExternAttribute _4_extern; + _1_typeParamsSeq = _out0; + _2_rTypeParams = _out1; + _3_rTypeParamsDecls = _out2; + Dafny.ISequence _4_datatypeName; + Defs._IExternAttribute _5_extern; Dafny.ISequence _out3; Defs._IExternAttribute _out4; (this).GetName((c).dtor_attributes, (c).dtor_name, Dafny.Sequence.UnicodeFromString("datatypes"), out _out3, out _out4); - _3_datatypeName = _out3; - _4_extern = _out4; - Dafny.ISequence _5_ctors; - _5_ctors = Dafny.Sequence.FromElements(); - Dafny.ISequence _6_variances; - _6_variances = Std.Collections.Seq.__default.Map(((System.Func)((_7_typeParamDecl) => { - return (_7_typeParamDecl).dtor_variance; + _4_datatypeName = _out3; + _5_extern = _out4; + Dafny.ISequence _6_ctors; + _6_ctors = Dafny.Sequence.FromElements(); + Dafny.ISequence _7_typeParamInfos; + _7_typeParamInfos = Std.Collections.Seq.__default.Map(((System.Func)((_8_typeParamDecl) => { + return (_8_typeParamDecl).dtor_info; })), (c).dtor_typeParams); - Dafny.ISequence _8_singletonConstructors; - _8_singletonConstructors = Dafny.Sequence.FromElements(); - Dafny.ISet> _9_usedTypeParams; - _9_usedTypeParams = Dafny.Set>.FromElements(); + Dafny.ISequence _9_singletonConstructors; + _9_singletonConstructors = Dafny.Sequence.FromElements(); + Dafny.ISet> _10_usedTypeParams; + _10_usedTypeParams = Dafny.Set>.FromElements(); BigInteger _hi0 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _10_i = BigInteger.Zero; _10_i < _hi0; _10_i++) { - DAST._IDatatypeCtor _11_ctor; - _11_ctor = ((c).dtor_ctors).Select(_10_i); - Dafny.ISequence _12_ctorArgs; - _12_ctorArgs = Dafny.Sequence.FromElements(); - bool _13_isNumeric; - _13_isNumeric = false; - if ((new BigInteger(((_11_ctor).dtor_args).Count)).Sign == 0) { - RAST._IExpr _14_instantiation; - _14_instantiation = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_3_datatypeName)).FSel(Defs.__default.escapeName((_11_ctor).dtor_name)), Dafny.Sequence.FromElements()); - if ((this).IsRcWrapped((c).dtor_attributes)) { - _14_instantiation = Dafny.Helpers.Id>((this).rcNew)(_14_instantiation); - } - _8_singletonConstructors = Dafny.Sequence.Concat(_8_singletonConstructors, Dafny.Sequence.FromElements(_14_instantiation)); - } - BigInteger _hi1 = new BigInteger(((_11_ctor).dtor_args).Count); - for (BigInteger _15_j = BigInteger.Zero; _15_j < _hi1; _15_j++) { - DAST._IDatatypeDtor _16_dtor; - _16_dtor = ((_11_ctor).dtor_args).Select(_15_j); - RAST._IType _17_formalType; + for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi0; _11_i++) { + DAST._IDatatypeCtor _12_ctor; + _12_ctor = ((c).dtor_ctors).Select(_11_i); + Dafny.ISequence _13_ctorArgs; + _13_ctorArgs = Dafny.Sequence.FromElements(); + bool _14_isNumeric; + _14_isNumeric = false; + if ((new BigInteger(((_12_ctor).dtor_args).Count)).Sign == 0) { + RAST._IExpr _15_instantiation; + _15_instantiation = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_12_ctor).dtor_name)), Dafny.Sequence.FromElements()); + if (_0_isRcWrapped) { + _15_instantiation = Dafny.Helpers.Id>((this).rcNew)(_15_instantiation); + } + _9_singletonConstructors = Dafny.Sequence.Concat(_9_singletonConstructors, Dafny.Sequence.FromElements(_15_instantiation)); + } + BigInteger _hi1 = new BigInteger(((_12_ctor).dtor_args).Count); + for (BigInteger _16_j = BigInteger.Zero; _16_j < _hi1; _16_j++) { + DAST._IDatatypeDtor _17_dtor; + _17_dtor = ((_12_ctor).dtor_args).Select(_16_j); + RAST._IType _18_formalType; RAST._IType _out5; - _out5 = (this).GenType(((_16_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); - _17_formalType = _out5; - _9_usedTypeParams = (this).GatherTypeParamNames(_9_usedTypeParams, _17_formalType); - Dafny.ISequence _18_formalName; - _18_formalName = Defs.__default.escapeVar(((_16_dtor).dtor_formal).dtor_name); - if (((_15_j).Sign == 0) && ((Dafny.Sequence.UnicodeFromString("0")).Equals(_18_formalName))) { - _13_isNumeric = true; - } - if ((((_15_j).Sign != 0) && (_13_isNumeric)) && (!(Std.Strings.__default.OfNat(_15_j)).Equals(_18_formalName))) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Formal extern names were supposed to be numeric but got "), _18_formalName), Dafny.Sequence.UnicodeFromString(" instead of ")), Std.Strings.__default.OfNat(_15_j))); - _13_isNumeric = false; + _out5 = (this).GenType(((_17_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); + _18_formalType = _out5; + _10_usedTypeParams = (this).GatherTypeParamNames(_10_usedTypeParams, _18_formalType); + Dafny.ISequence _19_formalName; + _19_formalName = Defs.__default.escapeVar(((_17_dtor).dtor_formal).dtor_name); + if (((_16_j).Sign == 0) && ((Dafny.Sequence.UnicodeFromString("0")).Equals(_19_formalName))) { + _14_isNumeric = true; + } + if ((((_16_j).Sign != 0) && (_14_isNumeric)) && (!(Std.Strings.__default.OfNat(_16_j)).Equals(_19_formalName))) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Formal extern names were supposed to be numeric but got "), _19_formalName), Dafny.Sequence.UnicodeFromString(" instead of ")), Std.Strings.__default.OfNat(_16_j))); + _14_isNumeric = false; } if ((c).dtor_isCo) { - _12_ctorArgs = Dafny.Sequence.Concat(_12_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_18_formalName, RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("LazyFieldWrapper"))).AsType(), Dafny.Sequence.FromElements(_17_formalType)))))); + _13_ctorArgs = Dafny.Sequence.Concat(_13_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_19_formalName, RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("LazyFieldWrapper"))).AsType(), Dafny.Sequence.FromElements(_18_formalType)))))); } else { - _12_ctorArgs = Dafny.Sequence.Concat(_12_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_18_formalName, _17_formalType)))); + _13_ctorArgs = Dafny.Sequence.Concat(_13_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_19_formalName, _18_formalType)))); } } - RAST._IFields _19_namedFields; - _19_namedFields = RAST.Fields.create_NamedFields(_12_ctorArgs); - if (_13_isNumeric) { - _19_namedFields = (_19_namedFields).ToNamelessFields(); + RAST._IFields _20_namedFields; + _20_namedFields = RAST.Fields.create_NamedFields(_13_ctorArgs); + if (_14_isNumeric) { + _20_namedFields = (_20_namedFields).ToNamelessFields(); } - _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create((_11_ctor).dtor_docString, Defs.__default.escapeName((_11_ctor).dtor_name), _19_namedFields))); + _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create((_12_ctor).dtor_docString, Defs.__default.escapeName((_12_ctor).dtor_name), _20_namedFields))); } - Dafny.ISet> _20_unusedTypeParams; - _20_unusedTypeParams = Dafny.Set>.Difference(Dafny.Helpers.Id, Dafny.ISet>>>((_21_rTypeParamsDecls) => ((System.Func>>)(() => { + Dafny.ISet> _21_unusedTypeParams; + _21_unusedTypeParams = Dafny.Set>.Difference(Dafny.Helpers.Id, Dafny.ISet>>>((_22_rTypeParamsDecls) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (RAST._ITypeParamDecl _compr_0 in (_21_rTypeParamsDecls).CloneAsArray()) { - RAST._ITypeParamDecl _22_tp = (RAST._ITypeParamDecl)_compr_0; - if ((_21_rTypeParamsDecls).Contains(_22_tp)) { - _coll0.Add((_22_tp).dtor_name); + foreach (RAST._ITypeParamDecl _compr_0 in (_22_rTypeParamsDecls).CloneAsArray()) { + RAST._ITypeParamDecl _23_tp = (RAST._ITypeParamDecl)_compr_0; + if ((_22_rTypeParamsDecls).Contains(_23_tp)) { + _coll0.Add((_23_tp).dtor_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_2_rTypeParamsDecls), _9_usedTypeParams); - Dafny.ISequence> _23_selfPath; - _23_selfPath = Dafny.Sequence>.FromElements((c).dtor_name); - Dafny.ISequence _24_implBodyRaw; - Dafny.IMap>,Dafny.ISequence> _25_traitBodies; + }))())(_3_rTypeParamsDecls), _10_usedTypeParams); + Dafny.ISequence> _24_selfPath; + _24_selfPath = Dafny.Sequence>.FromElements((c).dtor_name); + Dafny.ISequence _25_implBodyRaw; + Dafny.IMap>,Dafny.ISequence> _26_traitBodies; Dafny.ISequence _out6; Dafny.IMap>,Dafny.ISequence> _out7; - (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_23_selfPath, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype(_6_variances), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out6, out _out7); - _24_implBodyRaw = _out6; - _25_traitBodies = _out7; - Dafny.ISequence _26_implBody; - _26_implBody = _24_implBodyRaw; - Dafny.ISet> _27_emittedFields; - _27_emittedFields = Dafny.Set>.FromElements(); + (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_24_selfPath, _1_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype((c).dtor_equalitySupport, _7_typeParamInfos), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _1_typeParamsSeq, out _out6, out _out7); + _25_implBodyRaw = _out6; + _26_traitBodies = _out7; + Dafny.ISequence _27_implBody; + _27_implBody = _25_implBodyRaw; + Dafny.ISet> _28_emittedFields; + _28_emittedFields = Dafny.Set>.FromElements(); BigInteger _hi2 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _28_i = BigInteger.Zero; _28_i < _hi2; _28_i++) { - DAST._IDatatypeCtor _29_ctor; - _29_ctor = ((c).dtor_ctors).Select(_28_i); - BigInteger _hi3 = new BigInteger(((_29_ctor).dtor_args).Count); - for (BigInteger _30_j = BigInteger.Zero; _30_j < _hi3; _30_j++) { - DAST._IDatatypeDtor _31_dtor; - _31_dtor = ((_29_ctor).dtor_args).Select(_30_j); - Dafny.ISequence _32_callName; - _32_callName = Std.Wrappers.Option>.GetOr((_31_dtor).dtor_callName, Defs.__default.escapeVar(((_31_dtor).dtor_formal).dtor_name)); - if (!((_27_emittedFields).Contains(_32_callName))) { - _27_emittedFields = Dafny.Set>.Union(_27_emittedFields, Dafny.Set>.FromElements(_32_callName)); - RAST._IType _33_formalType; + for (BigInteger _29_i = BigInteger.Zero; _29_i < _hi2; _29_i++) { + DAST._IDatatypeCtor _30_ctor; + _30_ctor = ((c).dtor_ctors).Select(_29_i); + BigInteger _hi3 = new BigInteger(((_30_ctor).dtor_args).Count); + for (BigInteger _31_j = BigInteger.Zero; _31_j < _hi3; _31_j++) { + DAST._IDatatypeDtor _32_dtor; + _32_dtor = ((_30_ctor).dtor_args).Select(_31_j); + Dafny.ISequence _33_callName; + _33_callName = Std.Wrappers.Option>.GetOr((_32_dtor).dtor_callName, Defs.__default.escapeVar(((_32_dtor).dtor_formal).dtor_name)); + if (!((_28_emittedFields).Contains(_33_callName))) { + _28_emittedFields = Dafny.Set>.Union(_28_emittedFields, Dafny.Set>.FromElements(_33_callName)); + RAST._IType _34_formalType; RAST._IType _out8; - _out8 = (this).GenType(((_31_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); - _33_formalType = _out8; - Dafny.ISequence _34_cases; - _34_cases = Dafny.Sequence.FromElements(); + _out8 = (this).GenType(((_32_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); + _34_formalType = _out8; + Dafny.ISequence _35_cases; + _35_cases = Dafny.Sequence.FromElements(); BigInteger _hi4 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _35_k = BigInteger.Zero; _35_k < _hi4; _35_k++) { - DAST._IDatatypeCtor _36_ctor2; - _36_ctor2 = ((c).dtor_ctors).Select(_35_k); - Dafny.ISequence _37_pattern; - _37_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), Defs.__default.escapeName((_36_ctor2).dtor_name)); - RAST._IExpr _38_rhs = RAST.Expr.Default(); - Std.Wrappers._IOption> _39_hasMatchingField; - _39_hasMatchingField = Std.Wrappers.Option>.create_None(); - Dafny.ISequence _40_patternInner; - _40_patternInner = Dafny.Sequence.UnicodeFromString(""); - bool _41_isNumeric; - _41_isNumeric = false; - BigInteger _hi5 = new BigInteger(((_36_ctor2).dtor_args).Count); - for (BigInteger _42_l = BigInteger.Zero; _42_l < _hi5; _42_l++) { - DAST._IDatatypeDtor _43_dtor2; - _43_dtor2 = ((_36_ctor2).dtor_args).Select(_42_l); - Dafny.ISequence _44_patternName; - _44_patternName = Defs.__default.escapeVar(((_43_dtor2).dtor_formal).dtor_name); - if (((_42_l).Sign == 0) && ((_44_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _41_isNumeric = true; + for (BigInteger _36_k = BigInteger.Zero; _36_k < _hi4; _36_k++) { + DAST._IDatatypeCtor _37_ctor2; + _37_ctor2 = ((c).dtor_ctors).Select(_36_k); + Dafny.ISequence _38_pattern; + _38_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), Defs.__default.escapeName((_37_ctor2).dtor_name)); + RAST._IExpr _39_rhs = RAST.Expr.Default(); + Std.Wrappers._IOption> _40_hasMatchingField; + _40_hasMatchingField = Std.Wrappers.Option>.create_None(); + Dafny.ISequence _41_patternInner; + _41_patternInner = Dafny.Sequence.UnicodeFromString(""); + bool _42_isNumeric; + _42_isNumeric = false; + BigInteger _hi5 = new BigInteger(((_37_ctor2).dtor_args).Count); + for (BigInteger _43_l = BigInteger.Zero; _43_l < _hi5; _43_l++) { + DAST._IDatatypeDtor _44_dtor2; + _44_dtor2 = ((_37_ctor2).dtor_args).Select(_43_l); + Dafny.ISequence _45_patternName; + _45_patternName = Defs.__default.escapeVar(((_44_dtor2).dtor_formal).dtor_name); + if (((_43_l).Sign == 0) && ((_45_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _42_isNumeric = true; } - if (_41_isNumeric) { - _44_patternName = Std.Wrappers.Option>.GetOr((_43_dtor2).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_42_l))); + if (_42_isNumeric) { + _45_patternName = Std.Wrappers.Option>.GetOr((_44_dtor2).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_43_l))); } - if (object.Equals(((_31_dtor).dtor_formal).dtor_name, ((_43_dtor2).dtor_formal).dtor_name)) { - _39_hasMatchingField = Std.Wrappers.Option>.create_Some(_44_patternName); + if (object.Equals(((_32_dtor).dtor_formal).dtor_name, ((_44_dtor2).dtor_formal).dtor_name)) { + _40_hasMatchingField = Std.Wrappers.Option>.create_Some(_45_patternName); } - _40_patternInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_40_patternInner, _44_patternName), Dafny.Sequence.UnicodeFromString(", ")); + _41_patternInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_41_patternInner, _45_patternName), Dafny.Sequence.UnicodeFromString(", ")); } - if (_41_isNumeric) { - _37_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_37_pattern, Dafny.Sequence.UnicodeFromString("(")), _40_patternInner), Dafny.Sequence.UnicodeFromString(")")); + if (_42_isNumeric) { + _38_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_38_pattern, Dafny.Sequence.UnicodeFromString("(")), _41_patternInner), Dafny.Sequence.UnicodeFromString(")")); } else { - _37_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_37_pattern, Dafny.Sequence.UnicodeFromString("{")), _40_patternInner), Dafny.Sequence.UnicodeFromString("}")); + _38_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_38_pattern, Dafny.Sequence.UnicodeFromString("{")), _41_patternInner), Dafny.Sequence.UnicodeFromString("}")); } - if ((_39_hasMatchingField).is_Some) { + if ((_40_hasMatchingField).is_Some) { if ((c).dtor_isCo) { - _38_rhs = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("deref"))).Apply1(RAST.__default.Borrow((RAST.Expr.create_Identifier((_39_hasMatchingField).dtor_value)).Sel(Dafny.Sequence.UnicodeFromString("0")))); + _39_rhs = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("deref"))).Apply1(RAST.__default.Borrow((RAST.Expr.create_Identifier((_40_hasMatchingField).dtor_value)).Sel(Dafny.Sequence.UnicodeFromString("0")))); } else { - _38_rhs = RAST.Expr.create_Identifier((_39_hasMatchingField).dtor_value); + _39_rhs = RAST.Expr.create_Identifier((_40_hasMatchingField).dtor_value); } } else { - _38_rhs = Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString("field does not exist on this variant")); + _39_rhs = Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString("field does not exist on this variant")); } - RAST._IMatchCase _45_ctorMatch; - _45_ctorMatch = RAST.MatchCase.create(_37_pattern, _38_rhs); - _34_cases = Dafny.Sequence.Concat(_34_cases, Dafny.Sequence.FromElements(_45_ctorMatch)); - } - if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1)) { - _34_cases = Dafny.Sequence.Concat(_34_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - } - RAST._IExpr _46_methodBody; - _46_methodBody = RAST.Expr.create_Match(RAST.__default.self, _34_cases); - _26_implBody = Dafny.Sequence.Concat(_26_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl((((new BigInteger(((c).dtor_ctors).Count)) == (BigInteger.One)) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Returns a borrow of the field "), _32_callName)) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Gets the field "), _32_callName), Dafny.Sequence.UnicodeFromString(" for all enum members which have it")))), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_32_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_33_formalType)), Std.Wrappers.Option.create_Some(_46_methodBody))))); - } - } - } - Dafny.ISequence _47_coerceTypes; - _47_coerceTypes = Dafny.Sequence.FromElements(); - Dafny.ISequence _48_rCoerceTypeParams; - _48_rCoerceTypeParams = Dafny.Sequence.FromElements(); - Dafny.ISequence _49_coerceArguments; - _49_coerceArguments = Dafny.Sequence.FromElements(); - Dafny.IMap _50_coerceMap; - _50_coerceMap = Dafny.Map.FromElements(); - Dafny.IMap _51_rCoerceMap; - _51_rCoerceMap = Dafny.Map.FromElements(); - Dafny.IMap<_System._ITuple2,RAST._IExpr> _52_coerceMapToArg; - _52_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(); + RAST._IMatchCase _46_ctorMatch; + _46_ctorMatch = RAST.MatchCase.create(_38_pattern, _39_rhs); + _35_cases = Dafny.Sequence.Concat(_35_cases, Dafny.Sequence.FromElements(_46_ctorMatch)); + } + if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { + _35_cases = Dafny.Sequence.Concat(_35_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + } + RAST._IExpr _47_methodBody; + _47_methodBody = RAST.Expr.create_Match(RAST.__default.self, _35_cases); + _27_implBody = Dafny.Sequence.Concat(_27_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl((((new BigInteger(((c).dtor_ctors).Count)) == (BigInteger.One)) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Returns a borrow of the field "), _33_callName)) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Gets the field "), _33_callName), Dafny.Sequence.UnicodeFromString(" for all enum members which have it")))), Dafny.Sequence.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_33_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_34_formalType)), Std.Wrappers.Option.create_Some(_47_methodBody))))); + } + } + } + Dafny.ISequence _48_coerceTypes; + _48_coerceTypes = Dafny.Sequence.FromElements(); + Dafny.ISequence _49_rCoerceTypeParams; + _49_rCoerceTypeParams = Dafny.Sequence.FromElements(); + Dafny.ISequence _50_coerceArguments; + _50_coerceArguments = Dafny.Sequence.FromElements(); + Dafny.IMap _51_coerceMap; + _51_coerceMap = Dafny.Map.FromElements(); + Dafny.IMap _52_rCoerceMap; + _52_rCoerceMap = Dafny.Map.FromElements(); + Dafny.IMap<_System._ITuple2,RAST._IExpr> _53_coerceMapToArg; + _53_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(); if ((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) { - Dafny.ISequence _53_types; - _53_types = Dafny.Sequence.FromElements(); + Dafny.ISequence _54_types; + _54_types = Dafny.Sequence.FromElements(); BigInteger _hi6 = new BigInteger(((c).dtor_typeParams).Count); - for (BigInteger _54_typeI = BigInteger.Zero; _54_typeI < _hi6; _54_typeI++) { - DAST._ITypeArgDecl _55_typeParam; - _55_typeParam = ((c).dtor_typeParams).Select(_54_typeI); - DAST._IType _56_typeArg; - RAST._ITypeParamDecl _57_rTypeParamDecl; + for (BigInteger _55_typeI = BigInteger.Zero; _55_typeI < _hi6; _55_typeI++) { + DAST._ITypeArgDecl _56_typeParam; + _56_typeParam = ((c).dtor_typeParams).Select(_55_typeI); + DAST._IType _57_typeArg; + RAST._ITypeParamDecl _58_rTypeParamDecl; DAST._IType _out9; RAST._ITypeParamDecl _out10; - (this).GenTypeParam(_55_typeParam, out _out9, out _out10); - _56_typeArg = _out9; - _57_rTypeParamDecl = _out10; - RAST._IType _58_rTypeArg; + (this).GenTypeParam(_56_typeParam, out _out9, out _out10); + _57_typeArg = _out9; + _58_rTypeParamDecl = _out10; + RAST._IType _59_rTypeArg; RAST._IType _out11; - _out11 = (this).GenType(_56_typeArg, Defs.GenTypeContext.@default()); - _58_rTypeArg = _out11; - _53_types = Dafny.Sequence.Concat(_53_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_58_rTypeArg)))); - if (((_54_typeI) < (new BigInteger((_6_variances).Count))) && (((_6_variances).Select(_54_typeI)).is_Nonvariant)) { - _47_coerceTypes = Dafny.Sequence.Concat(_47_coerceTypes, Dafny.Sequence.FromElements(_58_rTypeArg)); + _out11 = (this).GenType(_57_typeArg, Defs.GenTypeContext.@default()); + _59_rTypeArg = _out11; + _54_types = Dafny.Sequence.Concat(_54_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_59_rTypeArg)))); + if (((_55_typeI) < (new BigInteger((_7_typeParamInfos).Count))) && ((((_7_typeParamInfos).Select(_55_typeI)).dtor_variance).is_Nonvariant)) { + _48_coerceTypes = Dafny.Sequence.Concat(_48_coerceTypes, Dafny.Sequence.FromElements(_59_rTypeArg)); goto continue_2_0; } - DAST._ITypeArgDecl _59_coerceTypeParam; - DAST._ITypeArgDecl _60_dt__update__tmp_h0 = _55_typeParam; - Dafny.ISequence _61_dt__update_hname_h0 = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), Std.Strings.__default.OfNat(_54_typeI)); - _59_coerceTypeParam = DAST.TypeArgDecl.create(_61_dt__update_hname_h0, (_60_dt__update__tmp_h0).dtor_bounds, (_60_dt__update__tmp_h0).dtor_variance); - DAST._IType _62_coerceTypeArg; - RAST._ITypeParamDecl _63_rCoerceTypeParamDecl; + DAST._ITypeArgDecl _60_coerceTypeParam; + DAST._ITypeArgDecl _61_dt__update__tmp_h0 = _56_typeParam; + Dafny.ISequence _62_dt__update_hname_h0 = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), Std.Strings.__default.OfNat(_55_typeI)); + _60_coerceTypeParam = DAST.TypeArgDecl.create(_62_dt__update_hname_h0, (_61_dt__update__tmp_h0).dtor_bounds, (_61_dt__update__tmp_h0).dtor_info); + DAST._IType _63_coerceTypeArg; + RAST._ITypeParamDecl _64_rCoerceTypeParamDecl; DAST._IType _out12; RAST._ITypeParamDecl _out13; - (this).GenTypeParam(_59_coerceTypeParam, out _out12, out _out13); - _62_coerceTypeArg = _out12; - _63_rCoerceTypeParamDecl = _out13; - _50_coerceMap = Dafny.Map.Merge(_50_coerceMap, Dafny.Map.FromElements(new Dafny.Pair(_56_typeArg, _62_coerceTypeArg))); - RAST._IType _64_rCoerceType; + (this).GenTypeParam(_60_coerceTypeParam, out _out12, out _out13); + _63_coerceTypeArg = _out12; + _64_rCoerceTypeParamDecl = _out13; + _51_coerceMap = Dafny.Map.Merge(_51_coerceMap, Dafny.Map.FromElements(new Dafny.Pair(_57_typeArg, _63_coerceTypeArg))); + RAST._IType _65_rCoerceType; RAST._IType _out14; - _out14 = (this).GenType(_62_coerceTypeArg, Defs.GenTypeContext.@default()); - _64_rCoerceType = _out14; - _51_rCoerceMap = Dafny.Map.Merge(_51_rCoerceMap, Dafny.Map.FromElements(new Dafny.Pair(_58_rTypeArg, _64_rCoerceType))); - _47_coerceTypes = Dafny.Sequence.Concat(_47_coerceTypes, Dafny.Sequence.FromElements(_64_rCoerceType)); - _48_rCoerceTypeParams = Dafny.Sequence.Concat(_48_rCoerceTypeParams, Dafny.Sequence.FromElements(_63_rCoerceTypeParamDecl)); - Dafny.ISequence _65_coerceFormal; - _65_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_54_typeI)); - _52_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_52_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_58_rTypeArg, _64_rCoerceType), (RAST.Expr.create_Identifier(_65_coerceFormal)).Clone()))); - _49_coerceArguments = Dafny.Sequence.Concat(_49_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_65_coerceFormal, Dafny.Helpers.Id>((this).rc)(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_58_rTypeArg), _64_rCoerceType)), RAST.__default.StaticTrait))))); + _out14 = (this).GenType(_63_coerceTypeArg, Defs.GenTypeContext.@default()); + _65_rCoerceType = _out14; + _52_rCoerceMap = Dafny.Map.Merge(_52_rCoerceMap, Dafny.Map.FromElements(new Dafny.Pair(_59_rTypeArg, _65_rCoerceType))); + _48_coerceTypes = Dafny.Sequence.Concat(_48_coerceTypes, Dafny.Sequence.FromElements(_65_rCoerceType)); + _49_rCoerceTypeParams = Dafny.Sequence.Concat(_49_rCoerceTypeParams, Dafny.Sequence.FromElements(_64_rCoerceTypeParamDecl)); + Dafny.ISequence _66_coerceFormal; + _66_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_55_typeI)); + _53_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_53_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_59_rTypeArg, _65_rCoerceType), (RAST.Expr.create_Identifier(_66_coerceFormal)).Clone()))); + _50_coerceArguments = Dafny.Sequence.Concat(_50_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_66_coerceFormal, Dafny.Helpers.Id>((this).rc)(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_59_rTypeArg), _65_rCoerceType)), RAST.__default.StaticTrait))))); continue_2_0: ; } after_2_0: ; - if ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1) { - _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_66_tpe) => { - return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _66_tpe); -})), _53_types))))); - } - } - bool _67_cIsEq; - _67_cIsEq = (this).DatatypeIsEq(c); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, ((_67_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _3_datatypeName, _2_rTypeParamsDecls, _5_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), _26_implBody))); - Dafny.ISequence _68_printImplBodyCases; - _68_printImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _69_hashImplBodyCases; - _69_hashImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _70_coerceImplBodyCases; - _70_coerceImplBodyCases = Dafny.Sequence.FromElements(); - BigInteger _hi7 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _71_i = BigInteger.Zero; _71_i < _hi7; _71_i++) { - DAST._IDatatypeCtor _72_ctor; - _72_ctor = ((c).dtor_ctors).Select(_71_i); - Dafny.ISequence _73_ctorMatch; - _73_ctorMatch = Defs.__default.escapeName((_72_ctor).dtor_name); - Dafny.ISequence _74_modulePrefix; + if ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1) { + _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_67_tpe) => { + return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _67_tpe); +})), _54_types))))); + } + } + bool _68_cIsAlwaysEq; + _68_cIsAlwaysEq = (((c).dtor_equalitySupport).is_ConsultTypeArguments) && (Dafny.Helpers.Id>((_69_c) => Dafny.Helpers.Quantifier(((_69_c).dtor_typeParams).UniqueElements, true, (((_forall_var_0) => { + DAST._ITypeArgDecl _70_t = (DAST._ITypeArgDecl)_forall_var_0; + return !(((_69_c).dtor_typeParams).Contains(_70_t)) || (!(((_70_t).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype)); + }))))(c)); + RAST._IType _71_datatypeType; + _71_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, Dafny.Sequence.FromElements(RAST.Attribute.DeriveClone), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _71_datatypeType, _27_implBody))); + if ((new BigInteger(((c).dtor_superTraitTypes).Count)).Sign == 1) { + RAST._IType _72_fullType; + if (_0_isRcWrapped) { + _72_fullType = Dafny.Helpers.Id>((this).rc)(_71_datatypeType); + } else { + _72_fullType = _71_datatypeType; + } + Std.Wrappers._IOption _73_downcastDefinitionOpt; + _73_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_3_rTypeParamsDecls, _72_fullType); + if ((_73_downcastDefinitionOpt).is_None) { + RAST._IExpr _74_dummy; + RAST._IExpr _out15; + _out15 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_72_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _74_dummy = _out15; + } else { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_73_downcastDefinitionOpt).dtor_value)); + } + Std.Wrappers._IOption _75_downcastImplementationsOpt; + _75_downcastImplementationsOpt = Defs.__default.DowncastImplFor((this).rcNew, _3_rTypeParamsDecls, _72_fullType); + if ((_75_downcastImplementationsOpt).is_None) { + RAST._IExpr _76_dummy; + RAST._IExpr _out16; + _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation for "), (_72_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _76_dummy = _out16; + } else { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_75_downcastImplementationsOpt).dtor_value)); + } + BigInteger _hi7 = new BigInteger(((c).dtor_superTraitNegativeTypes).Count); + for (BigInteger _77_i = BigInteger.Zero; _77_i < _hi7; _77_i++) { + RAST._IType _78_negativeTraitType; + RAST._IType _out17; + _out17 = (this).GenType(((c).dtor_superTraitNegativeTypes).Select(_77_i), Defs.GenTypeContext.@default()); + _78_negativeTraitType = _out17; + Std.Wrappers._IOption _79_downcastDefinitionOpt; + _79_downcastDefinitionOpt = Defs.__default.DowncastNotImplFor(_3_rTypeParamsDecls, _78_negativeTraitType, _72_fullType); + if ((_79_downcastDefinitionOpt).is_None) { + RAST._IExpr _80_dummy; + RAST._IExpr _out18; + _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate negative downcast definition for "), (_72_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _80_dummy = _out18; + } else { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_79_downcastDefinitionOpt).dtor_value)); + } + } + BigInteger _hi8 = new BigInteger(((c).dtor_superTraitTypes).Count); + for (BigInteger _81_i = BigInteger.Zero; _81_i < _hi8; _81_i++) { + DAST._IType _82_c; + _82_c = ((c).dtor_superTraitTypes).Select(_81_i); + if ((((_82_c).is_UserDefined) && ((((_82_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_82_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { + goto continue_3_0; + } + RAST._IType _83_cType; + RAST._IType _out19; + _out19 = (this).GenType(_82_c, Defs.GenTypeContext.@default()); + _83_cType = _out19; + bool _84_isImplementing; + _84_isImplementing = true; + Std.Wrappers._IOption _85_downcastImplementationsOpt; + _85_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _83_cType, _84_isImplementing, _72_fullType); + if ((_85_downcastImplementationsOpt).is_None) { + RAST._IExpr _86_dummy; + RAST._IExpr _out20; + _out20 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_83_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_72_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _86_dummy = _out20; + } else { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_85_downcastImplementationsOpt).dtor_value)); + } + continue_3_0: ; + } + after_3_0: ; + } + Dafny.ISequence _87_printImplBodyCases; + _87_printImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _88_hashImplBodyCases; + _88_hashImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _89_coerceImplBodyCases; + _89_coerceImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _90_partialEqImplBodyCases; + _90_partialEqImplBodyCases = Dafny.Sequence.FromElements(); + BigInteger _hi9 = new BigInteger(((c).dtor_ctors).Count); + for (BigInteger _91_i = BigInteger.Zero; _91_i < _hi9; _91_i++) { + DAST._IDatatypeCtor _92_ctor; + _92_ctor = ((c).dtor_ctors).Select(_91_i); + Dafny.ISequence _93_ctorMatch; + _93_ctorMatch = Defs.__default.escapeName((_92_ctor).dtor_name); + Dafny.ISequence _94_modulePrefix; if (((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) { - _74_modulePrefix = Dafny.Sequence.UnicodeFromString(""); + _94_modulePrefix = Dafny.Sequence.UnicodeFromString(""); } else { - _74_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); - } - Dafny.ISequence _75_ctorName; - _75_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_74_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_72_ctor).dtor_name)); - if (((new BigInteger((_75_ctorName).Count)) >= (new BigInteger(13))) && (((_75_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { - _75_ctorName = Dafny.Sequence.UnicodeFromString(""); - } - RAST._IExpr _76_printRhs; - _76_printRhs = (this).writeStr(Dafny.Sequence.Concat(_75_ctorName, (((_72_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); - RAST._IExpr _77_hashRhs; - _77_hashRhs = (this).InitEmptyExpr(); - Dafny.ISequence _78_coerceRhsArgs; - _78_coerceRhsArgs = Dafny.Sequence.FromElements(); - bool _79_isNumeric; - _79_isNumeric = false; - Dafny.ISequence _80_ctorMatchInner; - _80_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); - BigInteger _hi8 = new BigInteger(((_72_ctor).dtor_args).Count); - for (BigInteger _81_j = BigInteger.Zero; _81_j < _hi8; _81_j++) { - DAST._IDatatypeDtor _82_dtor; - _82_dtor = ((_72_ctor).dtor_args).Select(_81_j); - Dafny.ISequence _83_patternName; - _83_patternName = Defs.__default.escapeVar(((_82_dtor).dtor_formal).dtor_name); - DAST._IType _84_formalType; - _84_formalType = ((_82_dtor).dtor_formal).dtor_typ; - if (((_81_j).Sign == 0) && ((_83_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _79_isNumeric = true; - } - if (_79_isNumeric) { - _83_patternName = Std.Wrappers.Option>.GetOr((_82_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_81_j))); - } - if ((_84_formalType).is_Arrow) { - _77_hashRhs = (_77_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _94_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); + } + Dafny.ISequence _95_ctorName; + _95_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_92_ctor).dtor_name)); + if (((new BigInteger((_95_ctorName).Count)) >= (new BigInteger(13))) && (((_95_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _95_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _96_printRhs; + _96_printRhs = (this).writeStr(Dafny.Sequence.Concat(_95_ctorName, (((_92_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); + RAST._IExpr _97_hashRhs; + _97_hashRhs = (this).InitEmptyExpr(); + RAST._IExpr _98_partialEqRhs; + _98_partialEqRhs = RAST.Expr.create_LiteralBool(true); + Dafny.ISequence _99_coerceRhsArgs; + _99_coerceRhsArgs = Dafny.Sequence.FromElements(); + bool _100_isNumeric; + _100_isNumeric = false; + Dafny.ISequence _101_ctorMatchInner; + _101_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + Dafny.ISequence _102_ctorMatchInner2; + _102_ctorMatchInner2 = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi10 = new BigInteger(((_92_ctor).dtor_args).Count); + for (BigInteger _103_j = BigInteger.Zero; _103_j < _hi10; _103_j++) { + DAST._IDatatypeDtor _104_dtor; + _104_dtor = ((_92_ctor).dtor_args).Select(_103_j); + Dafny.ISequence _105_patternName; + _105_patternName = Defs.__default.escapeVar(((_104_dtor).dtor_formal).dtor_name); + DAST._IType _106_formalType; + _106_formalType = ((_104_dtor).dtor_formal).dtor_typ; + if (((_103_j).Sign == 0) && ((_105_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _100_isNumeric = true; + } + if (_100_isNumeric) { + _105_patternName = Std.Wrappers.Option>.GetOr((_104_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_103_j))); + } + if ((_106_formalType).is_Arrow) { + _97_hashRhs = (_97_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _77_hashRhs = (_77_hashRhs).Then((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("hash"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_83_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); - } - _80_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_80_ctorMatchInner, _83_patternName), Dafny.Sequence.UnicodeFromString(", ")); - if ((_81_j).Sign == 1) { - _76_printRhs = (_76_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); - } - _76_printRhs = (_76_printRhs).Then((((_84_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_83_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); - RAST._IExpr _85_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _86_formalTpe; - RAST._IType _out15; - _out15 = (this).GenType(_84_formalType, Defs.GenTypeContext.@default()); - _86_formalTpe = _out15; - DAST._IType _87_newFormalType; - _87_newFormalType = (_84_formalType).Replace(_50_coerceMap); - RAST._IType _88_newFormalTpe; - _88_newFormalTpe = (_86_formalTpe).ReplaceMap(_51_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _89_upcastConverter; - _89_upcastConverter = (this).UpcastConversionLambda(_84_formalType, _86_formalTpe, _87_newFormalType, _88_newFormalTpe, _52_coerceMapToArg); - if ((_89_upcastConverter).is_Success) { - RAST._IExpr _90_coercionFunction; - _90_coercionFunction = (_89_upcastConverter).dtor_value; - _85_coerceRhsArg = (_90_coercionFunction).Apply1(RAST.Expr.create_Identifier(_83_patternName)); + _97_hashRhs = (_97_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_105_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); + } + _101_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_101_ctorMatchInner, _105_patternName), Dafny.Sequence.UnicodeFromString(", ")); + Dafny.ISequence _107_matchingVariable2; + _107_matchingVariable2 = Defs.__default.prefixWith2(_105_patternName); + Dafny.ISequence _108_patternPrefix; + if (_100_isNumeric) { + _108_patternPrefix = Dafny.Sequence.UnicodeFromString(""); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_81_j)), Dafny.Sequence.UnicodeFromString(" of ")), _3_datatypeName)); - _85_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + _108_patternPrefix = Dafny.Sequence.Concat(_105_patternName, Dafny.Sequence.UnicodeFromString(": ")); } - _78_coerceRhsArgs = Dafny.Sequence.Concat(_78_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_83_patternName, _85_coerceRhsArg))); - } - RAST._IExpr _91_coerceRhs; - _91_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_3_datatypeName)).FSel(Defs.__default.escapeName((_72_ctor).dtor_name)), _78_coerceRhsArgs); - if (_79_isNumeric) { - _73_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_73_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _80_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + _102_ctorMatchInner2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_102_ctorMatchInner2, _108_patternPrefix), _107_matchingVariable2), Dafny.Sequence.UnicodeFromString(", ")); + if ((_106_formalType).is_Arrow) { + _98_partialEqRhs = (_98_partialEqRhs).And(RAST.Expr.create_LiteralBool(false)); + } else { + _98_partialEqRhs = (_98_partialEqRhs).And((RAST.Expr.create_Identifier(_105_patternName)).Equals(RAST.Expr.create_Identifier(_107_matchingVariable2))); + } + if ((_103_j).Sign == 1) { + _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); + } + _96_printRhs = (_96_printRhs).Then((((_106_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_105_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); + RAST._IExpr _109_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _110_formalTpe; + RAST._IType _out21; + _out21 = (this).GenType(_106_formalType, Defs.GenTypeContext.@default()); + _110_formalTpe = _out21; + DAST._IType _111_newFormalType; + _111_newFormalType = (_106_formalType).Replace(_51_coerceMap); + RAST._IType _112_newFormalTpe; + _112_newFormalTpe = (_110_formalTpe).ReplaceMap(_52_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _113_upcastConverter; + _113_upcastConverter = (this).UpcastConversionLambda(_106_formalType, _110_formalTpe, _111_newFormalType, _112_newFormalTpe, _53_coerceMapToArg); + if ((_113_upcastConverter).is_Success) { + RAST._IExpr _114_coercionFunction; + _114_coercionFunction = (_113_upcastConverter).dtor_value; + _109_coerceRhsArg = (_114_coercionFunction).Apply1(RAST.Expr.create_Identifier(_105_patternName)); + } else { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_103_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + _109_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + } + _99_coerceRhsArgs = Dafny.Sequence.Concat(_99_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_105_patternName, _109_coerceRhsArg))); + } + RAST._IExpr _115_coerceRhs; + _115_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_92_ctor).dtor_name)), _99_coerceRhsArgs); + Dafny.ISequence _116_pattern = Dafny.Sequence.Empty; + Dafny.ISequence _117_pattern2 = Dafny.Sequence.Empty; + if (_100_isNumeric) { + _116_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _101_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + _117_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _102_ctorMatchInner2), Dafny.Sequence.UnicodeFromString(")")); } else { - _73_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_73_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _80_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); - } - if ((_72_ctor).dtor_hasAnyArgs) { - _76_printRhs = (_76_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); - } - _76_printRhs = (_76_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _68_printImplBodyCases = Dafny.Sequence.Concat(_68_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_76_printRhs)))); - _69_hashImplBodyCases = Dafny.Sequence.Concat(_69_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_77_hashRhs)))); - _70_coerceImplBodyCases = Dafny.Sequence.Concat(_70_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_91_coerceRhs)))); - } - if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1)) { - Dafny.ISequence _92_extraCases; - _92_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - _68_printImplBodyCases = Dafny.Sequence.Concat(_68_printImplBodyCases, _92_extraCases); - _69_hashImplBodyCases = Dafny.Sequence.Concat(_69_hashImplBodyCases, _92_extraCases); - _70_coerceImplBodyCases = Dafny.Sequence.Concat(_70_coerceImplBodyCases, _92_extraCases); - } - Dafny.ISequence _93_defaultConstrainedTypeParams; - _93_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - Dafny.ISequence _94_rTypeParamsDeclsWithEq; - _94_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); - Dafny.ISequence _95_rTypeParamsDeclsWithHash; - _95_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - RAST._IExpr _96_printImplBody; - _96_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _68_printImplBodyCases); - RAST._IExpr _97_hashImplBody; - _97_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _69_hashImplBodyCases); - RAST._IType _98_datatypeType; - _98_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_2_rTypeParamsDecls, _98_datatypeType, _1_rTypeParams), Defs.__default.PrintImpl(_2_rTypeParamsDecls, _98_datatypeType, _1_rTypeParams, _96_printImplBody))); - if ((new BigInteger((_48_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _99_coerceImplBody; - _99_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _70_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl((this).rc, (this).rcNew, _2_rTypeParamsDecls, _3_datatypeName, _98_datatypeType, _48_rCoerceTypeParams, _49_coerceArguments, _47_coerceTypes, _99_coerceImplBody))); - } - if ((new BigInteger((_8_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _100_instantiationType; - if ((this).IsRcWrapped((c).dtor_attributes)) { - _100_instantiationType = Dafny.Helpers.Id>((this).rc)(_98_datatypeType); + _116_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _101_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + _117_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _102_ctorMatchInner2), Dafny.Sequence.UnicodeFromString("}")); + } + if ((_92_ctor).dtor_hasAnyArgs) { + _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); + } + _96_printRhs = (_96_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); + _87_printImplBodyCases = Dafny.Sequence.Concat(_87_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _116_pattern), RAST.Expr.create_Block(_96_printRhs)))); + _88_hashImplBodyCases = Dafny.Sequence.Concat(_88_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _116_pattern), RAST.Expr.create_Block(_97_hashRhs)))); + _90_partialEqImplBodyCases = Dafny.Sequence.Concat(_90_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _116_pattern), Dafny.Sequence.UnicodeFromString(", ")), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _117_pattern2), Dafny.Sequence.UnicodeFromString(")")), RAST.Expr.create_Block(_98_partialEqRhs)))); + _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _116_pattern), RAST.Expr.create_Block(_115_coerceRhs)))); + } + _90_partialEqImplBodyCases = Dafny.Sequence.Concat(_90_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("_"), RAST.Expr.create_Block(RAST.Expr.create_LiteralBool(false))))); + if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { + Dafny.ISequence _118_extraCases; + _118_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _87_printImplBodyCases = Dafny.Sequence.Concat(_87_printImplBodyCases, _118_extraCases); + _88_hashImplBodyCases = Dafny.Sequence.Concat(_88_hashImplBodyCases, _118_extraCases); + _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, _118_extraCases); + } + Dafny.ISequence _119_defaultConstrainedTypeParams; + _119_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IExpr _120_printImplBody; + _120_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _87_printImplBodyCases); + RAST._IExpr _121_hashImplBody; + _121_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_hashImplBodyCases); + RAST._IExpr _122_eqImplBody; + _122_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _90_partialEqImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _71_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _71_datatypeType, _2_rTypeParams, _120_printImplBody))); + if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { + RAST._IExpr _123_coerceImplBody; + _123_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _89_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl((this).rc, (this).rcNew, _3_rTypeParamsDecls, _4_datatypeName, _71_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _123_coerceImplBody))); + } + if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { + RAST._IType _124_instantiationType; + if (_0_isRcWrapped) { + _124_instantiationType = Dafny.Helpers.Id>((this).rc)(_71_datatypeType); } else { - _100_instantiationType = _98_datatypeType; + _124_instantiationType = _71_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_2_rTypeParamsDecls, _98_datatypeType, _100_instantiationType, _8_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _71_datatypeType, _124_instantiationType, _9_singletonConstructors))); } - if (_67_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_94_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), Dafny.Sequence.FromElements())))); + if (((c).dtor_equalitySupport).is_ConsultTypeArguments) { + Dafny.ISequence _125_impls; + Dafny.ISequence _out22; + _out22 = (this).GenEqHashImpls((c).dtor_typeParams, _3_rTypeParamsDecls, _2_rTypeParams, _71_datatypeType, _122_eqImplBody, _121_hashImplBody); + _125_impls = _out22; + s = Dafny.Sequence.Concat(s, _125_impls); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_95_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), _97_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _101_structName; - _101_structName = (RAST.Expr.create_Identifier(_3_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _102_structAssignments; - _102_structAssignments = Dafny.Sequence.FromElements(); - BigInteger _hi9 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _103_i = BigInteger.Zero; _103_i < _hi9; _103_i++) { - DAST._IDatatypeDtor _104_dtor; - _104_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_103_i); - _102_structAssignments = Dafny.Sequence.Concat(_102_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_104_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); - } - RAST._IType _105_fullType; - _105_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams); - if (_67_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_2_rTypeParamsDecls, _105_fullType, _101_structName, _102_structAssignments))); - } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_2_rTypeParamsDecls, _105_fullType))); - } - Dafny.ISequence _106_superTraitImplementations; - Dafny.ISequence _out16; - _out16 = (this).GenTraitImplementations(path, _1_rTypeParams, _2_rTypeParamsDecls, (c).dtor_superTraitTypes, _25_traitBodies, _4_extern, Dafny.Sequence.UnicodeFromString("datatype")); - _106_superTraitImplementations = _out16; - s = Dafny.Sequence.Concat(s, _106_superTraitImplementations); + RAST._IExpr _126_structName; + _126_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _127_structAssignments; + _127_structAssignments = Dafny.Sequence.FromElements(); + BigInteger _hi11 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); + for (BigInteger _128_i = BigInteger.Zero; _128_i < _hi11; _128_i++) { + DAST._IDatatypeDtor _129_dtor; + _129_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_128_i); + _127_structAssignments = Dafny.Sequence.Concat(_127_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_129_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + } + if ((false) && (_68_cIsAlwaysEq)) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _71_datatypeType, _126_structName, _127_structAssignments))); + } + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _71_datatypeType))); + } + Dafny.ISequence _130_superTraitImplementations; + Dafny.ISequence _out23; + _out23 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _68_cIsAlwaysEq, Dafny.Sequence.UnicodeFromString("datatype")); + _130_superTraitImplementations = _out23; + s = Dafny.Sequence.Concat(s, _130_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -1355,9 +1503,6 @@ public RAST._IExpr GenPathExpr(Dafny.ISequence> p, b } return s; } - public bool IsRcWrapped(Dafny.ISequence attributes) { - return ((!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("auto-nongrowing-size"), Dafny.Sequence>.FromElements()))) && (!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("false")))))) || ((attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("true"))))); - } public RAST._IType GenType(DAST._IType c, bool genTypeContext) { RAST._IType s = RAST.Type.Default(); @@ -1391,7 +1536,7 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) { if (_source1.is_Datatype) { { - if ((this).IsRcWrapped((_0_resolved).dtor_attributes)) { + if (Defs.__default.IsRcWrapped((_0_resolved).dtor_attributes)) { s = Dafny.Helpers.Id>((this).rc)(s); } } @@ -1759,7 +1904,7 @@ public void GenClassImplBody(Dafny.ISequence body, bool forTrait, after_match0: ; } } - public Dafny.ISequence GenParams(Dafny.ISequence @params, bool forLambda) + public Dafny.ISequence GenParams(Dafny.ISequence @params, Dafny.ISequence inheritedParams, bool forLambda) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); @@ -1767,14 +1912,24 @@ public void GenClassImplBody(Dafny.ISequence body, bool forTrait, for (BigInteger _0_i = BigInteger.Zero; _0_i < _hi0; _0_i++) { DAST._IFormal _1_param; _1_param = (@params).Select(_0_i); - RAST._IType _2_paramType; + DAST._IFormal _2_inheritedParam; + if ((_0_i) < (new BigInteger((inheritedParams).Count))) { + _2_inheritedParam = (inheritedParams).Select(_0_i); + } else { + _2_inheritedParam = _1_param; + } + RAST._IType _3_paramType; RAST._IType _out0; _out0 = (this).GenType((_1_param).dtor_typ, Defs.GenTypeContext.@default()); - _2_paramType = _out0; - if (((!((_2_paramType).CanReadWithoutClone())) || (forLambda)) && (!((_1_param).dtor_attributes).Contains(Defs.__default.AttributeOwned))) { - _2_paramType = RAST.Type.create_Borrowed(_2_paramType); + _3_paramType = _out0; + RAST._IType _4_inheritedParamType; + RAST._IType _out1; + _out1 = (this).GenType((_2_inheritedParam).dtor_typ, Defs.GenTypeContext.@default()); + _4_inheritedParamType = _out1; + if (((!((_4_inheritedParamType).CanReadWithoutClone())) || (forLambda)) && (!((_1_param).dtor_attributes).Contains(Defs.__default.AttributeOwned))) { + _3_paramType = RAST.Type.create_Borrowed(_3_paramType); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.Formal.create(Defs.__default.escapeVar((_1_param).dtor_name), _2_paramType))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.Formal.create(Defs.__default.escapeVar((_1_param).dtor_name), _3_paramType))); } return s; } @@ -1783,7 +1938,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e RAST._IImplMember s = RAST.ImplMember.Default(); Dafny.ISequence _0_params; Dafny.ISequence _out0; - _out0 = (this).GenParams((m).dtor_params, false); + _out0 = (this).GenParams((m).dtor_params, (m).dtor_inheritedParams, false); _0_params = _out0; Dafny.ISequence> _1_paramNames; _1_paramNames = Dafny.Sequence>.FromElements(); @@ -1841,9 +1996,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e if ((_15_tpe).IsObjectOrPointer()) { _15_tpe = RAST.__default.SelfBorrowed; } else { - if ((((enclosingType).is_UserDefined) && ((((enclosingType).dtor_resolved).dtor_kind).is_Datatype)) && ((this).IsRcWrapped(((enclosingType).dtor_resolved).dtor_attributes))) { - _15_tpe = RAST.Type.create_Borrowed(Dafny.Helpers.Id>((this).rc)(RAST.__default.SelfOwned)); - } else if ((((enclosingType).is_UserDefined) && ((((enclosingType).dtor_resolved).dtor_kind).is_Newtype)) && (Defs.__default.IsNewtypeCopy((((enclosingType).dtor_resolved).dtor_kind).dtor_range))) { + if (((((enclosingType).is_UserDefined) && ((((enclosingType).dtor_resolved).dtor_kind).is_Newtype)) && (Defs.__default.IsNewtypeCopy((((enclosingType).dtor_resolved).dtor_kind).dtor_range))) && (!(forTrait))) { _15_tpe = RAST.Type.create_TMetaData(RAST.__default.SelfOwned, true, ((((enclosingType).dtor_resolved).dtor_kind).dtor_range).CanOverflow()); } else { _15_tpe = RAST.__default.SelfBorrowed; @@ -1976,15 +2129,15 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e after_match1: ; _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes), Dafny.Set>.FromElements()); RAST._IExpr _50_body; - Dafny.ISet> _51___v20; - Defs._IEnvironment _52___v21; + Dafny.ISet> _51___v14; + Defs._IEnvironment _52___v15; RAST._IExpr _out6; Dafny.ISet> _out7; Defs._IEnvironment _out8; (this).GenStmts((m).dtor_body, _8_selfIdent, _32_env, true, _36_earlyReturn, out _out6, out _out7, out _out8); _50_body = _out6; - _51___v20 = _out7; - _52___v21 = _out8; + _51___v14 = _out7; + _52___v15 = _out8; _31_fBody = Std.Wrappers.Option.create_Some((_33_preBody).Then(_50_body)); } else { _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes, Dafny.Set>.FromElements()); @@ -2277,14 +2430,14 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo BigInteger _hi0 = new BigInteger((_12_indices).Count); for (BigInteger _18_i = BigInteger.Zero; _18_i < _hi0; _18_i++) { RAST._IExpr _19_idx; - Defs._IOwnership _20___v29; + Defs._IOwnership _20___v23; Dafny.ISet> _21_recIdentsIdx; RAST._IExpr _out6; Defs._IOwnership _out7; Dafny.ISet> _out8; (this).GenExpr((_12_indices).Select(_18_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); _19_idx = _out6; - _20___v29 = _out7; + _20___v23 = _out7; _21_recIdentsIdx = _out8; Dafny.ISequence _22_varName; _22_varName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("__idx"), Std.Strings.__default.OfNat(_18_i)); @@ -2301,7 +2454,19 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo } after_match0: ; } - public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequence typeArgs, Dafny.ISequence args, Defs._IEnvironment env, out RAST._IExpr r, out Dafny.ISet> readIdents) + public RAST._IExpr FromGeneralBorrowToSelfBorrow(RAST._IExpr onExpr, Defs._IOwnership onExprOwnership, Defs._IEnvironment env) + { + if (((onExpr).is_Identifier) && ((env).NeedsAsRefForBorrow((onExpr).dtor_name))) { + return ((onExpr).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); + } else if (((object.Equals(onExpr, RAST.__default.self)) || (object.Equals(onExpr, (this).rcDatatypeThis))) || (object.Equals(onExpr, (this).borrowedRcDatatypeThis))) { + return RAST.__default.self; + } else if ((onExprOwnership).is_OwnershipBorrowed) { + return (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(onExpr); + } else { + return onExpr; + } + } + public void GenCall(DAST._IExpression @on, Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequence typeArgs, Dafny.ISequence args, Defs._IEnvironment env, out RAST._IExpr r, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); readIdents = Dafny.Set>.Empty; @@ -2319,6 +2484,9 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D _2_typeExprs = _out2; _3_fullNameQualifier = _out3; readIdents = _1_recIdents; + if ((((((selfIdent).IsSelf()) && ((name).is_CallName)) && (((name).dtor_receiverArg).is_Some)) && ((new BigInteger((_0_argExprs).Count)).Sign == 1)) && (RAST.__default.IsBorrowUpcastBox((_0_argExprs).Select(BigInteger.Zero)))) { + _0_argExprs = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))), (_0_argExprs).Drop(BigInteger.One)); + } Std.Wrappers._IOption _source0 = _3_fullNameQualifier; { if (_source0.is_Some) { @@ -2348,19 +2516,20 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D _9_onExpr = ((this).read__macro).Apply1(_9_onExpr); readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); } else if (((_6_base).is_Trait) && (((_6_base).dtor_traitType).is_GeneralTrait)) { - RAST._IExpr _out9; - Defs._IOwnership _out10; - Dafny.ISet> _out11; - (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out9, out _out10, out _out11); - _9_onExpr = _out9; - _10_recOwnership = _out10; - _11_recIdents = _out11; - if (((_9_onExpr).is_Identifier) && ((env).NeedsAsRefForBorrow((_9_onExpr).dtor_name))) { - _9_onExpr = ((_9_onExpr).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); - } else if ((_9_onExpr).IsBorrow()) { - _9_onExpr = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(_9_onExpr); + if ((@on).IsThisUpcast()) { + _9_onExpr = RAST.__default.self; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self"))); + } else { + RAST._IExpr _out9; + Defs._IOwnership _out10; + Dafny.ISet> _out11; + (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out9, out _out10, out _out11); + _9_onExpr = _out9; + _10_recOwnership = _out10; + _11_recIdents = _out11; + _9_onExpr = (this).FromGeneralBorrowToSelfBorrow(_9_onExpr, _10_recOwnership, env); + readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); } - readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); } else if (((_6_base).is_Newtype) && (Defs.__default.IsNewtypeCopy((_6_base).dtor_range))) { RAST._IExpr _out12; Defs._IOwnership _out13; @@ -2378,6 +2547,7 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D _9_onExpr = _out15; _10_recOwnership = _out16; _11_recIdents = _out17; + _9_onExpr = (this).FromGeneralBorrowToSelfBorrow(_9_onExpr, _10_recOwnership, env); readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); } r = ((((_7_fullPath).ApplyType(_8_onTypeExprs)).FSel(Defs.__default.escapeName((name).dtor_name))).ApplyType(_2_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_9_onExpr), _0_argExprs)); @@ -2385,17 +2555,22 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D } } { - RAST._IExpr _12_onExpr; - Defs._IOwnership _13___v34; - Dafny.ISet> _14_recIdents; - RAST._IExpr _out18; - Defs._IOwnership _out19; - Dafny.ISet> _out20; - (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out18, out _out19, out _out20); - _12_onExpr = _out18; - _13___v34 = _out19; - _14_recIdents = _out20; - readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); + RAST._IExpr _12_onExpr = RAST.Expr.Default(); + Dafny.ISet> _13_recIdents = Dafny.Set>.Empty; + Defs._IOwnership _14_dummy = Defs.Ownership.Default(); + if ((@on).IsThisUpcast()) { + _12_onExpr = RAST.__default.self; + _13_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); + } else { + RAST._IExpr _out18; + Defs._IOwnership _out19; + Dafny.ISet> _out20; + (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out18, out _out19, out _out20); + _12_onExpr = _out18; + _14_dummy = _out19; + _13_recIdents = _out20; + } + readIdents = Dafny.Set>.Union(readIdents, _13_recIdents); Dafny.ISequence _15_renderedName; _15_renderedName = (this).GetMethodName(@on, name); DAST._IExpression _source1 = @on; @@ -2472,24 +2647,18 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _5_isAssignedVar; _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { - RAST._IExpr _6_rhs; - Defs._IOwnership _7___v44; - Dafny.ISet> _8___v45; - RAST._IExpr _out1; - Defs._IOwnership _out2; - Dafny.ISet> _out3; - (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); - _6_rhs = _out1; - _7___v44 = _out2; - _8___v45 = _out3; + Dafny.ISequence _6_panicked; + _6_panicked = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Field "), _3_fieldName), Dafny.Sequence.UnicodeFromString(" is not initialized")); + RAST._IExpr _7_rhs; + _7_rhs = Defs.__default.UnreachablePanicIfVerified((this).pointerType, _6_panicked); readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); - Dafny.ISequence _9_update__if__uninit; + Dafny.ISequence _8_update__if__uninit; if ((_2_field).dtor_isConstant) { - _9_update__if__uninit = (this).update__field__if__uninit__macro; + _8_update__if__uninit = (this).update__field__if__uninit__macro; } else { - _9_update__if__uninit = (this).update__field__mut__if__uninit__macro; + _8_update__if__uninit = (this).update__field__mut__if__uninit__macro; } - generated = (generated).Then((((RAST.__default.dafny__runtime).MSel(_9_update__if__uninit)).AsExpr()).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), RAST.Expr.create_Identifier(_3_fieldName), RAST.Expr.create_Identifier(_5_isAssignedVar), _6_rhs))); + generated = (generated).Then((((RAST.__default.dafny__runtime).MSel(_8_update__if__uninit)).AsExpr()).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), RAST.Expr.create_Identifier(_3_fieldName), RAST.Expr.create_Identifier(_5_isAssignedVar), _7_rhs))); newEnv = (newEnv).RemoveAssigned(_5_isAssignedVar); } } @@ -2499,37 +2668,37 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_DeclareVar) { - Dafny.ISequence _10_name = _source0.dtor_name; - DAST._IType _11_typ = _source0.dtor_typ; + Dafny.ISequence _9_name = _source0.dtor_name; + DAST._IType _10_typ = _source0.dtor_typ; Std.Wrappers._IOption maybeValue0 = _source0.dtor_maybeValue; if (maybeValue0.is_Some) { - DAST._IExpression _12_expression = maybeValue0.dtor_value; + DAST._IExpression _11_expression = maybeValue0.dtor_value; { - RAST._IType _13_tpe; - RAST._IType _out4; - _out4 = (this).GenType(_11_typ, Defs.GenTypeContext.@default()); - _13_tpe = _out4; - Dafny.ISequence _14_varName; - _14_varName = Defs.__default.escapeVar(_10_name); - bool _15_hasCopySemantics; - _15_hasCopySemantics = (_13_tpe).CanReadWithoutClone(); - if (((_12_expression).is_InitializationValue) && (!(_15_hasCopySemantics))) { - if ((env).IsAssignmentStatusKnown(_14_varName)) { - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _14_varName, Std.Wrappers.Option.create_Some(_13_tpe), Std.Wrappers.Option.create_None()); + RAST._IType _12_tpe; + RAST._IType _out1; + _out1 = (this).GenType(_10_typ, Defs.GenTypeContext.@default()); + _12_tpe = _out1; + Dafny.ISequence _13_varName; + _13_varName = Defs.__default.escapeVar(_9_name); + bool _14_hasCopySemantics; + _14_hasCopySemantics = (_12_tpe).CanReadWithoutClone(); + if (((_11_expression).is_InitializationValue) && (!(_14_hasCopySemantics))) { + if ((env).IsAssignmentStatusKnown(_13_varName)) { + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _13_varName, Std.Wrappers.Option.create_Some(_12_tpe), Std.Wrappers.Option.create_None()); } else { - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _14_varName, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((((RAST.__default.MaybePlaceboPath).AsExpr()).ApplyType1(_13_tpe)).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0())); - _13_tpe = RAST.__default.MaybePlaceboType(_13_tpe); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _13_varName, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((((RAST.__default.MaybePlaceboPath).AsExpr()).ApplyType1(_12_tpe)).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0())); + _12_tpe = RAST.__default.MaybePlaceboType(_12_tpe); } readIdents = Dafny.Set>.FromElements(); - newEnv = (env).AddAssigned(_14_varName, _13_tpe); + newEnv = (env).AddAssigned(_13_varName, _12_tpe); } else { - RAST._IExpr _out5; - Dafny.ISet> _out6; - Defs._IEnvironment _out7; - (this).GenDeclareVarAssign(_10_name, _11_typ, _12_expression, selfIdent, env, out _out5, out _out6, out _out7); - generated = _out5; - readIdents = _out6; - newEnv = _out7; + RAST._IExpr _out2; + Dafny.ISet> _out3; + Defs._IEnvironment _out4; + (this).GenDeclareVarAssign(_9_name, _10_typ, _11_expression, selfIdent, env, out _out2, out _out3, out _out4); + generated = _out2; + readIdents = _out3; + newEnv = _out4; return ; } } @@ -2539,31 +2708,31 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_DeclareVar) { - Dafny.ISequence _16_name = _source0.dtor_name; - DAST._IType _17_typ = _source0.dtor_typ; + Dafny.ISequence _15_name = _source0.dtor_name; + DAST._IType _16_typ = _source0.dtor_typ; Std.Wrappers._IOption maybeValue1 = _source0.dtor_maybeValue; if (maybeValue1.is_None) { { - Dafny.ISequence _18_varName; - _18_varName = Defs.__default.escapeVar(_16_name); - if ((env).IsAssignmentStatusKnown(_18_varName)) { - RAST._IType _19_tpe; - RAST._IType _out8; - _out8 = (this).GenType(_17_typ, Defs.GenTypeContext.@default()); - _19_tpe = _out8; - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _18_varName, Std.Wrappers.Option.create_Some(_19_tpe), Std.Wrappers.Option.create_None()); + Dafny.ISequence _17_varName; + _17_varName = Defs.__default.escapeVar(_15_name); + if ((env).IsAssignmentStatusKnown(_17_varName)) { + RAST._IType _18_tpe; + RAST._IType _out5; + _out5 = (this).GenType(_16_typ, Defs.GenTypeContext.@default()); + _18_tpe = _out5; + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _17_varName, Std.Wrappers.Option.create_Some(_18_tpe), Std.Wrappers.Option.create_None()); readIdents = Dafny.Set>.FromElements(); - newEnv = (env).AddAssigned(_18_varName, _19_tpe); + newEnv = (env).AddAssigned(_17_varName, _18_tpe); } else { - DAST._IStatement _20_newStmt; - _20_newStmt = DAST.Statement.create_DeclareVar(_16_name, _17_typ, Std.Wrappers.Option.create_Some(DAST.Expression.create_InitializationValue(_17_typ))); - RAST._IExpr _out9; - Dafny.ISet> _out10; - Defs._IEnvironment _out11; - (this).GenStmt(_20_newStmt, selfIdent, env, isLast, earlyReturn, out _out9, out _out10, out _out11); - generated = _out9; - readIdents = _out10; - newEnv = _out11; + DAST._IStatement _19_newStmt; + _19_newStmt = DAST.Statement.create_DeclareVar(_15_name, _16_typ, Std.Wrappers.Option.create_Some(DAST.Expression.create_InitializationValue(_16_typ))); + RAST._IExpr _out6; + Dafny.ISet> _out7; + Defs._IEnvironment _out8; + (this).GenStmt(_19_newStmt, selfIdent, env, isLast, earlyReturn, out _out6, out _out7, out _out8); + generated = _out6; + readIdents = _out7; + newEnv = _out8; } } goto after_match0; @@ -2572,124 +2741,124 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Assign) { - DAST._IAssignLhs _21_lhs = _source0.dtor_lhs; - DAST._IExpression _22_expression = _source0.dtor_value; + DAST._IAssignLhs _20_lhs = _source0.dtor_lhs; + DAST._IExpression _21_expression = _source0.dtor_value; { - RAST._IExpr _23_exprGen; - Defs._IOwnership _24___v46; - Dafny.ISet> _25_exprIdents; - RAST._IExpr _out12; - Defs._IOwnership _out13; - Dafny.ISet> _out14; - (this).GenExpr(_22_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13, out _out14); - _23_exprGen = _out12; - _24___v46 = _out13; - _25_exprIdents = _out14; - if ((_21_lhs).is_Ident) { - Dafny.ISequence _26_rustId; - _26_rustId = Defs.__default.escapeVar((_21_lhs).dtor_ident); - Std.Wrappers._IOption _27_tpe; - _27_tpe = (env).GetType(_26_rustId); - if (((_27_tpe).is_Some) && ((((_27_tpe).dtor_value).ExtractMaybePlacebo()).is_Some)) { - _23_exprGen = RAST.__default.MaybePlacebo(_23_exprGen); + RAST._IExpr _22_exprGen; + Defs._IOwnership _23___v37; + Dafny.ISet> _24_exprIdents; + RAST._IExpr _out9; + Defs._IOwnership _out10; + Dafny.ISet> _out11; + (this).GenExpr(_21_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out9, out _out10, out _out11); + _22_exprGen = _out9; + _23___v37 = _out10; + _24_exprIdents = _out11; + if ((_20_lhs).is_Ident) { + Dafny.ISequence _25_rustId; + _25_rustId = Defs.__default.escapeVar((_20_lhs).dtor_ident); + Std.Wrappers._IOption _26_tpe; + _26_tpe = (env).GetType(_25_rustId); + if (((_26_tpe).is_Some) && ((((_26_tpe).dtor_value).ExtractMaybePlacebo()).is_Some)) { + _22_exprGen = RAST.__default.MaybePlacebo(_22_exprGen); } } - if (((_21_lhs).is_Index) && (((_21_lhs).dtor_expr).is_Ident)) { - Dafny.ISequence _28_rustId; - _28_rustId = Defs.__default.escapeVar(((_21_lhs).dtor_expr).dtor_name); - Std.Wrappers._IOption _29_tpe; - _29_tpe = (env).GetType(_28_rustId); - if (((_29_tpe).is_Some) && ((((_29_tpe).dtor_value).ExtractMaybeUninitArrayElement()).is_Some)) { - _23_exprGen = RAST.__default.MaybeUninitNew(_23_exprGen); + if (((_20_lhs).is_Index) && (((_20_lhs).dtor_expr).is_Ident)) { + Dafny.ISequence _27_rustId; + _27_rustId = Defs.__default.escapeVar(((_20_lhs).dtor_expr).dtor_name); + Std.Wrappers._IOption _28_tpe; + _28_tpe = (env).GetType(_27_rustId); + if (((_28_tpe).is_Some) && ((((_28_tpe).dtor_value).ExtractMaybeUninitArrayElement()).is_Some)) { + _22_exprGen = RAST.__default.MaybeUninitNew(_22_exprGen); } } - RAST._IExpr _30_lhsGen; - bool _31_needsIIFE; - Dafny.ISet> _32_recIdents; - Defs._IEnvironment _33_resEnv; - RAST._IExpr _out15; - bool _out16; - Dafny.ISet> _out17; - Defs._IEnvironment _out18; - (this).GenAssignLhs(_21_lhs, _23_exprGen, selfIdent, env, out _out15, out _out16, out _out17, out _out18); - _30_lhsGen = _out15; - _31_needsIIFE = _out16; - _32_recIdents = _out17; - _33_resEnv = _out18; - generated = _30_lhsGen; - newEnv = _33_resEnv; - if (_31_needsIIFE) { + RAST._IExpr _29_lhsGen; + bool _30_needsIIFE; + Dafny.ISet> _31_recIdents; + Defs._IEnvironment _32_resEnv; + RAST._IExpr _out12; + bool _out13; + Dafny.ISet> _out14; + Defs._IEnvironment _out15; + (this).GenAssignLhs(_20_lhs, _22_exprGen, selfIdent, env, out _out12, out _out13, out _out14, out _out15); + _29_lhsGen = _out12; + _30_needsIIFE = _out13; + _31_recIdents = _out14; + _32_resEnv = _out15; + generated = _29_lhsGen; + newEnv = _32_resEnv; + if (_30_needsIIFE) { generated = RAST.Expr.create_Block(generated); } - readIdents = Dafny.Set>.Union(_32_recIdents, _25_exprIdents); + readIdents = Dafny.Set>.Union(_31_recIdents, _24_exprIdents); } goto after_match0; } } { if (_source0.is_If) { - DAST._IExpression _34_cond = _source0.dtor_cond; - Dafny.ISequence _35_thnDafny = _source0.dtor_thn; - Dafny.ISequence _36_elsDafny = _source0.dtor_els; + DAST._IExpression _33_cond = _source0.dtor_cond; + Dafny.ISequence _34_thnDafny = _source0.dtor_thn; + Dafny.ISequence _35_elsDafny = _source0.dtor_els; { - RAST._IExpr _37_cond; - Defs._IOwnership _38___v47; - Dafny.ISet> _39_recIdents; + RAST._IExpr _36_cond; + Defs._IOwnership _37___v38; + Dafny.ISet> _38_recIdents; + RAST._IExpr _out16; + Defs._IOwnership _out17; + Dafny.ISet> _out18; + (this).GenExpr(_33_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); + _36_cond = _out16; + _37___v38 = _out17; + _38_recIdents = _out18; + Dafny.ISequence _39_condString; + _39_condString = (_36_cond)._ToString(Defs.__default.IND); + readIdents = _38_recIdents; + RAST._IExpr _40_thn; + Dafny.ISet> _41_thnIdents; + Defs._IEnvironment _42_thnEnv; RAST._IExpr _out19; - Defs._IOwnership _out20; - Dafny.ISet> _out21; - (this).GenExpr(_34_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out19, out _out20, out _out21); - _37_cond = _out19; - _38___v47 = _out20; - _39_recIdents = _out21; - Dafny.ISequence _40_condString; - _40_condString = (_37_cond)._ToString(Defs.__default.IND); - readIdents = _39_recIdents; - RAST._IExpr _41_thn; - Dafny.ISet> _42_thnIdents; - Defs._IEnvironment _43_thnEnv; + Dafny.ISet> _out20; + Defs._IEnvironment _out21; + (this).GenStmts(_34_thnDafny, selfIdent, env, isLast, earlyReturn, out _out19, out _out20, out _out21); + _40_thn = _out19; + _41_thnIdents = _out20; + _42_thnEnv = _out21; + readIdents = Dafny.Set>.Union(readIdents, _41_thnIdents); + RAST._IExpr _43_els; + Dafny.ISet> _44_elsIdents; + Defs._IEnvironment _45_elsEnv; RAST._IExpr _out22; Dafny.ISet> _out23; Defs._IEnvironment _out24; - (this).GenStmts(_35_thnDafny, selfIdent, env, isLast, earlyReturn, out _out22, out _out23, out _out24); - _41_thn = _out22; - _42_thnIdents = _out23; - _43_thnEnv = _out24; - readIdents = Dafny.Set>.Union(readIdents, _42_thnIdents); - RAST._IExpr _44_els; - Dafny.ISet> _45_elsIdents; - Defs._IEnvironment _46_elsEnv; - RAST._IExpr _out25; - Dafny.ISet> _out26; - Defs._IEnvironment _out27; - (this).GenStmts(_36_elsDafny, selfIdent, env, isLast, earlyReturn, out _out25, out _out26, out _out27); - _44_els = _out25; - _45_elsIdents = _out26; - _46_elsEnv = _out27; - readIdents = Dafny.Set>.Union(readIdents, _45_elsIdents); - newEnv = env; - generated = RAST.Expr.create_IfExpr(_37_cond, _41_thn, _44_els); + (this).GenStmts(_35_elsDafny, selfIdent, env, isLast, earlyReturn, out _out22, out _out23, out _out24); + _43_els = _out22; + _44_elsIdents = _out23; + _45_elsEnv = _out24; + readIdents = Dafny.Set>.Union(readIdents, _44_elsIdents); + newEnv = (env).Join(_42_thnEnv, _45_elsEnv); + generated = RAST.Expr.create_IfExpr(_36_cond, _40_thn, _43_els); } goto after_match0; } } { if (_source0.is_Labeled) { - Dafny.ISequence _47_lbl = _source0.dtor_lbl; - Dafny.ISequence _48_body = _source0.dtor_body; + Dafny.ISequence _46_lbl = _source0.dtor_lbl; + Dafny.ISequence _47_body = _source0.dtor_body; { - RAST._IExpr _49_body; - Dafny.ISet> _50_bodyIdents; - Defs._IEnvironment _51_env2; - RAST._IExpr _out28; - Dafny.ISet> _out29; - Defs._IEnvironment _out30; - (this).GenStmts(_48_body, selfIdent, env, isLast, earlyReturn, out _out28, out _out29, out _out30); - _49_body = _out28; - _50_bodyIdents = _out29; - _51_env2 = _out30; - readIdents = _50_bodyIdents; - generated = RAST.Expr.create_Labelled(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _47_lbl), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), RAST.Expr.create_StmtExpr(_49_body, RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())))); + RAST._IExpr _48_body; + Dafny.ISet> _49_bodyIdents; + Defs._IEnvironment _50_env2; + RAST._IExpr _out25; + Dafny.ISet> _out26; + Defs._IEnvironment _out27; + (this).GenStmts(_47_body, selfIdent, env, isLast, earlyReturn, out _out25, out _out26, out _out27); + _48_body = _out25; + _49_bodyIdents = _out26; + _50_env2 = _out27; + readIdents = _49_bodyIdents; + generated = RAST.Expr.create_Labelled(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _46_lbl), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), RAST.Expr.create_StmtExpr(_48_body, RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())))); newEnv = env; } goto after_match0; @@ -2697,91 +2866,91 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_While) { - DAST._IExpression _52_cond = _source0.dtor_cond; - Dafny.ISequence _53_body = _source0.dtor_body; + DAST._IExpression _51_cond = _source0.dtor_cond; + Dafny.ISequence _52_body = _source0.dtor_body; { - RAST._IExpr _54_cond; - Defs._IOwnership _55___v48; - Dafny.ISet> _56_recIdents; + RAST._IExpr _53_cond; + Defs._IOwnership _54___v39; + Dafny.ISet> _55_recIdents; + RAST._IExpr _out28; + Defs._IOwnership _out29; + Dafny.ISet> _out30; + (this).GenExpr(_51_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out28, out _out29, out _out30); + _53_cond = _out28; + _54___v39 = _out29; + _55_recIdents = _out30; + readIdents = _55_recIdents; + RAST._IExpr _56_bodyExpr; + Dafny.ISet> _57_bodyIdents; + Defs._IEnvironment _58_bodyEnv; RAST._IExpr _out31; - Defs._IOwnership _out32; - Dafny.ISet> _out33; - (this).GenExpr(_52_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out31, out _out32, out _out33); - _54_cond = _out31; - _55___v48 = _out32; - _56_recIdents = _out33; - readIdents = _56_recIdents; - RAST._IExpr _57_bodyExpr; - Dafny.ISet> _58_bodyIdents; - Defs._IEnvironment _59_bodyEnv; - RAST._IExpr _out34; - Dafny.ISet> _out35; - Defs._IEnvironment _out36; - (this).GenStmts(_53_body, selfIdent, env, false, earlyReturn, out _out34, out _out35, out _out36); - _57_bodyExpr = _out34; - _58_bodyIdents = _out35; - _59_bodyEnv = _out36; + Dafny.ISet> _out32; + Defs._IEnvironment _out33; + (this).GenStmts(_52_body, selfIdent, env, false, earlyReturn, out _out31, out _out32, out _out33); + _56_bodyExpr = _out31; + _57_bodyIdents = _out32; + _58_bodyEnv = _out33; newEnv = env; - readIdents = Dafny.Set>.Union(readIdents, _58_bodyIdents); - generated = RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(_54_cond), _57_bodyExpr); + readIdents = Dafny.Set>.Union(readIdents, _57_bodyIdents); + generated = RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(_53_cond), _56_bodyExpr); } goto after_match0; } } { if (_source0.is_Foreach) { - Dafny.ISequence _60_boundName = _source0.dtor_boundName; - DAST._IType _61_boundType = _source0.dtor_boundType; - DAST._IExpression _62_overExpr = _source0.dtor_over; - Dafny.ISequence _63_body = _source0.dtor_body; + Dafny.ISequence _59_boundName = _source0.dtor_boundName; + DAST._IType _60_boundType = _source0.dtor_boundType; + DAST._IExpression _61_overExpr = _source0.dtor_over; + Dafny.ISequence _62_body = _source0.dtor_body; { - RAST._IExpr _64_over; - Defs._IOwnership _65___v49; - Dafny.ISet> _66_recIdents; - RAST._IExpr _out37; - Defs._IOwnership _out38; + RAST._IExpr _63_over; + Defs._IOwnership _64___v40; + Dafny.ISet> _65_recIdents; + RAST._IExpr _out34; + Defs._IOwnership _out35; + Dafny.ISet> _out36; + (this).GenExpr(_61_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out34, out _out35, out _out36); + _63_over = _out34; + _64___v40 = _out35; + _65_recIdents = _out36; + if (((_61_overExpr).is_MapBoundedPool) || ((_61_overExpr).is_SetBoundedPool)) { + _63_over = ((_63_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); + } + RAST._IType _66_boundTpe; + RAST._IType _out37; + _out37 = (this).GenType(_60_boundType, Defs.GenTypeContext.@default()); + _66_boundTpe = _out37; + readIdents = _65_recIdents; + Dafny.ISequence _67_boundRName; + _67_boundRName = Defs.__default.escapeVar(_59_boundName); + RAST._IExpr _68_bodyExpr; + Dafny.ISet> _69_bodyIdents; + Defs._IEnvironment _70_bodyEnv; + RAST._IExpr _out38; Dafny.ISet> _out39; - (this).GenExpr(_62_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out37, out _out38, out _out39); - _64_over = _out37; - _65___v49 = _out38; - _66_recIdents = _out39; - if (((_62_overExpr).is_MapBoundedPool) || ((_62_overExpr).is_SetBoundedPool)) { - _64_over = ((_64_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); - } - RAST._IType _67_boundTpe; - RAST._IType _out40; - _out40 = (this).GenType(_61_boundType, Defs.GenTypeContext.@default()); - _67_boundTpe = _out40; - readIdents = _66_recIdents; - Dafny.ISequence _68_boundRName; - _68_boundRName = Defs.__default.escapeVar(_60_boundName); - RAST._IExpr _69_bodyExpr; - Dafny.ISet> _70_bodyIdents; - Defs._IEnvironment _71_bodyEnv; - RAST._IExpr _out41; - Dafny.ISet> _out42; - Defs._IEnvironment _out43; - (this).GenStmts(_63_body, selfIdent, (env).AddAssigned(_68_boundRName, _67_boundTpe), false, earlyReturn, out _out41, out _out42, out _out43); - _69_bodyExpr = _out41; - _70_bodyIdents = _out42; - _71_bodyEnv = _out43; - readIdents = Dafny.Set>.Difference(Dafny.Set>.Union(readIdents, _70_bodyIdents), Dafny.Set>.FromElements(_68_boundRName)); + Defs._IEnvironment _out40; + (this).GenStmts(_62_body, selfIdent, (env).AddAssigned(_67_boundRName, _66_boundTpe), false, earlyReturn, out _out38, out _out39, out _out40); + _68_bodyExpr = _out38; + _69_bodyIdents = _out39; + _70_bodyEnv = _out40; + readIdents = Dafny.Set>.Difference(Dafny.Set>.Union(readIdents, _69_bodyIdents), Dafny.Set>.FromElements(_67_boundRName)); newEnv = env; - generated = RAST.Expr.create_For(_68_boundRName, _64_over, _69_bodyExpr); + generated = RAST.Expr.create_For(_67_boundRName, _63_over, _68_bodyExpr); } goto after_match0; } } { if (_source0.is_Break) { - Std.Wrappers._IOption> _72_toLabel = _source0.dtor_toLabel; + Std.Wrappers._IOption> _71_toLabel = _source0.dtor_toLabel; { - Std.Wrappers._IOption> _source1 = _72_toLabel; + Std.Wrappers._IOption> _source1 = _71_toLabel; { if (_source1.is_Some) { - Dafny.ISequence _73_lbl = _source1.dtor_value; + Dafny.ISequence _72_lbl = _source1.dtor_value; { - generated = RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _73_lbl))); + generated = RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _72_lbl))); } goto after_match1; } @@ -2800,72 +2969,72 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_TailRecursive) { - Dafny.ISequence _74_body = _source0.dtor_body; + Dafny.ISequence _73_body = _source0.dtor_body; { generated = (this).InitEmptyExpr(); - Defs._IEnvironment _75_oldEnv; - _75_oldEnv = env; + Defs._IEnvironment _74_oldEnv; + _74_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { - RAST._IExpr _76_selfClone; - Defs._IOwnership _77___v50; - Dafny.ISet> _78___v51; - RAST._IExpr _out44; - Defs._IOwnership _out45; - Dafny.ISet> _out46; - (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); - _76_selfClone = _out44; - _77___v50 = _out45; - _78___v51 = _out46; - generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_76_selfClone))); - if (((_75_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { - _75_oldEnv = (_75_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); + RAST._IExpr _75_selfClone; + Defs._IOwnership _76___v41; + Dafny.ISet> _77___v42; + RAST._IExpr _out41; + Defs._IOwnership _out42; + Dafny.ISet> _out43; + (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); + _75_selfClone = _out41; + _76___v41 = _out42; + _77___v42 = _out43; + generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_75_selfClone))); + if (((_74_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { + _74_oldEnv = (_74_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); } } - RAST._IExpr _79_loopBegin; - _79_loopBegin = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); + RAST._IExpr _78_loopBegin; + _78_loopBegin = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); newEnv = env; - BigInteger _hi1 = new BigInteger(((_75_oldEnv).dtor_names).Count); - for (BigInteger _80_paramI = BigInteger.Zero; _80_paramI < _hi1; _80_paramI++) { - Dafny.ISequence _81_param; - _81_param = ((_75_oldEnv).dtor_names).Select(_80_paramI); - if ((_81_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { + BigInteger _hi1 = new BigInteger(((_74_oldEnv).dtor_names).Count); + for (BigInteger _79_paramI = BigInteger.Zero; _79_paramI < _hi1; _79_paramI++) { + Dafny.ISequence _80_param; + _80_param = ((_74_oldEnv).dtor_names).Select(_79_paramI); + if ((_80_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { goto continue_4_0; } - RAST._IExpr _82_paramInit; - Defs._IOwnership _83___v52; - Dafny.ISet> _84___v53; - RAST._IExpr _out47; - Defs._IOwnership _out48; - Dafny.ISet> _out49; - (this).GenIdent(_81_param, selfIdent, _75_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out47, out _out48, out _out49); - _82_paramInit = _out47; - _83___v52 = _out48; - _84___v53 = _out49; - Dafny.ISequence _85_recVar; - _85_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_80_paramI)); - generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _85_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_82_paramInit))); - if (((_75_oldEnv).dtor_types).Contains(_81_param)) { - RAST._IType _86_declaredType; - _86_declaredType = (Dafny.Map, RAST._IType>.Select((_75_oldEnv).dtor_types,_81_param)).ToOwned(); - newEnv = (newEnv).AddAssigned(_81_param, _86_declaredType); - newEnv = (newEnv).AddAssigned(_85_recVar, _86_declaredType); + RAST._IExpr _81_paramInit; + Defs._IOwnership _82___v43; + Dafny.ISet> _83___v44; + RAST._IExpr _out44; + Defs._IOwnership _out45; + Dafny.ISet> _out46; + (this).GenIdent(_80_param, selfIdent, _74_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); + _81_paramInit = _out44; + _82___v43 = _out45; + _83___v44 = _out46; + Dafny.ISequence _84_recVar; + _84_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_79_paramI)); + generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _84_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_81_paramInit))); + if (((_74_oldEnv).dtor_types).Contains(_80_param)) { + RAST._IType _85_declaredType; + _85_declaredType = (Dafny.Map, RAST._IType>.Select((_74_oldEnv).dtor_types,_80_param)).ToOwned(); + newEnv = (newEnv).AddAssigned(_80_param, _85_declaredType); + newEnv = (newEnv).AddAssigned(_84_recVar, _85_declaredType); } - _79_loopBegin = (_79_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _81_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_85_recVar)))); + _78_loopBegin = (_78_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _80_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_84_recVar)))); continue_4_0: ; } after_4_0: ; - RAST._IExpr _87_bodyExpr; - Dafny.ISet> _88_bodyIdents; - Defs._IEnvironment _89_bodyEnv; - RAST._IExpr _out50; - Dafny.ISet> _out51; - Defs._IEnvironment _out52; - (this).GenStmts(_74_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), newEnv, false, earlyReturn, out _out50, out _out51, out _out52); - _87_bodyExpr = _out50; - _88_bodyIdents = _out51; - _89_bodyEnv = _out52; - readIdents = _88_bodyIdents; - generated = (generated).Then(RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), (_79_loopBegin).Then(_87_bodyExpr)))); + RAST._IExpr _86_bodyExpr; + Dafny.ISet> _87_bodyIdents; + Defs._IEnvironment _88_bodyEnv; + RAST._IExpr _out47; + Dafny.ISet> _out48; + Defs._IEnvironment _out49; + (this).GenStmts(_73_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), newEnv, false, earlyReturn, out _out47, out _out48, out _out49); + _86_bodyExpr = _out47; + _87_bodyIdents = _out48; + _88_bodyEnv = _out49; + readIdents = _87_bodyIdents; + generated = (generated).Then(RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), (_78_loopBegin).Then(_86_bodyExpr)))); } goto after_match0; } @@ -2882,44 +3051,44 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Call) { - DAST._IExpression _90_on = _source0.dtor_on; - DAST._ICallName _91_name = _source0.dtor_callName; - Dafny.ISequence _92_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _93_args = _source0.dtor_args; - Std.Wrappers._IOption>> _94_maybeOutVars = _source0.dtor_outs; + DAST._IExpression _89_on = _source0.dtor_on; + DAST._ICallName _90_name = _source0.dtor_callName; + Dafny.ISequence _91_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _92_args = _source0.dtor_args; + Std.Wrappers._IOption>> _93_maybeOutVars = _source0.dtor_outs; { - RAST._IExpr _out53; - Dafny.ISet> _out54; - (this).GenOwnedCallPart(_90_on, selfIdent, _91_name, _92_typeArgs, _93_args, env, out _out53, out _out54); - generated = _out53; - readIdents = _out54; + RAST._IExpr _out50; + Dafny.ISet> _out51; + (this).GenCall(_89_on, selfIdent, _90_name, _91_typeArgs, _92_args, env, out _out50, out _out51); + generated = _out50; + readIdents = _out51; newEnv = env; - if (((_94_maybeOutVars).is_Some) && ((new BigInteger(((_94_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { - Dafny.ISequence _95_outVar; - _95_outVar = Defs.__default.escapeVar(((_94_maybeOutVars).dtor_value).Select(BigInteger.Zero)); - if ((env).IsMaybePlacebo(_95_outVar)) { + if (((_93_maybeOutVars).is_Some) && ((new BigInteger(((_93_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { + Dafny.ISequence _94_outVar; + _94_outVar = Defs.__default.escapeVar(((_93_maybeOutVars).dtor_value).Select(BigInteger.Zero)); + if ((env).IsMaybePlacebo(_94_outVar)) { generated = RAST.__default.MaybePlacebo(generated); } - generated = RAST.__default.AssignVar(_95_outVar, generated); - } else if (((_94_maybeOutVars).is_None) || ((new BigInteger(((_94_maybeOutVars).dtor_value).Count)).Sign == 0)) { + generated = RAST.__default.AssignVar(_94_outVar, generated); + } else if (((_93_maybeOutVars).is_None) || ((new BigInteger(((_93_maybeOutVars).dtor_value).Count)).Sign == 0)) { } else { - Dafny.ISequence _96_tmpVar; - _96_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); - RAST._IExpr _97_tmpId; - _97_tmpId = RAST.Expr.create_Identifier(_96_tmpVar); - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _96_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); - Dafny.ISequence> _98_outVars; - _98_outVars = (_94_maybeOutVars).dtor_value; - BigInteger _hi2 = new BigInteger((_98_outVars).Count); - for (BigInteger _99_outI = BigInteger.Zero; _99_outI < _hi2; _99_outI++) { - Dafny.ISequence _100_outVar; - _100_outVar = Defs.__default.escapeVar((_98_outVars).Select(_99_outI)); - RAST._IExpr _101_rhs; - _101_rhs = (_97_tmpId).Sel(Std.Strings.__default.OfNat(_99_outI)); - if ((env).IsMaybePlacebo(_100_outVar)) { - _101_rhs = RAST.__default.MaybePlacebo(_101_rhs); + Dafny.ISequence _95_tmpVar; + _95_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); + RAST._IExpr _96_tmpId; + _96_tmpId = RAST.Expr.create_Identifier(_95_tmpVar); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _95_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); + Dafny.ISequence> _97_outVars; + _97_outVars = (_93_maybeOutVars).dtor_value; + BigInteger _hi2 = new BigInteger((_97_outVars).Count); + for (BigInteger _98_outI = BigInteger.Zero; _98_outI < _hi2; _98_outI++) { + Dafny.ISequence _99_outVar; + _99_outVar = Defs.__default.escapeVar((_97_outVars).Select(_98_outI)); + RAST._IExpr _100_rhs; + _100_rhs = (_96_tmpId).Sel(Std.Strings.__default.OfNat(_98_outI)); + if ((env).IsMaybePlacebo(_99_outVar)) { + _100_rhs = RAST.__default.MaybePlacebo(_100_rhs); } - generated = (generated).Then(RAST.__default.AssignVar(_100_outVar, _101_rhs)); + generated = (generated).Then(RAST.__default.AssignVar(_99_outVar, _100_rhs)); } } newEnv = env; @@ -2929,23 +3098,23 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Return) { - DAST._IExpression _102_exprDafny = _source0.dtor_expr; + DAST._IExpression _101_exprDafny = _source0.dtor_expr; { - RAST._IExpr _103_expr; - Defs._IOwnership _104___v54; - Dafny.ISet> _105_recIdents; - RAST._IExpr _out55; - Defs._IOwnership _out56; - Dafny.ISet> _out57; - (this).GenExpr(_102_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out55, out _out56, out _out57); - _103_expr = _out55; - _104___v54 = _out56; - _105_recIdents = _out57; - readIdents = _105_recIdents; + RAST._IExpr _102_expr; + Defs._IOwnership _103___v45; + Dafny.ISet> _104_recIdents; + RAST._IExpr _out52; + Defs._IOwnership _out53; + Dafny.ISet> _out54; + (this).GenExpr(_101_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out52, out _out53, out _out54); + _102_expr = _out52; + _103___v45 = _out53; + _104_recIdents = _out54; + readIdents = _104_recIdents; if (isLast) { - generated = _103_expr; + generated = _102_expr; } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_103_expr)); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_102_expr)); } newEnv = env; } @@ -2963,27 +3132,27 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } } { - Dafny.ISequence> _106_rustIdents = _source2.dtor_value; - Dafny.ISequence _107_tupleArgs; - _107_tupleArgs = Dafny.Sequence.FromElements(); - BigInteger _hi3 = new BigInteger((_106_rustIdents).Count); - for (BigInteger _108_i = BigInteger.Zero; _108_i < _hi3; _108_i++) { - RAST._IExpr _109_rIdent; - Defs._IOwnership _110___v55; - Dafny.ISet> _111___v56; - RAST._IExpr _out58; - Defs._IOwnership _out59; - Dafny.ISet> _out60; - (this).GenIdent((_106_rustIdents).Select(_108_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); - _109_rIdent = _out58; - _110___v55 = _out59; - _111___v56 = _out60; - _107_tupleArgs = Dafny.Sequence.Concat(_107_tupleArgs, Dafny.Sequence.FromElements(_109_rIdent)); + Dafny.ISequence> _105_rustIdents = _source2.dtor_value; + Dafny.ISequence _106_tupleArgs; + _106_tupleArgs = Dafny.Sequence.FromElements(); + BigInteger _hi3 = new BigInteger((_105_rustIdents).Count); + for (BigInteger _107_i = BigInteger.Zero; _107_i < _hi3; _107_i++) { + RAST._IExpr _108_rIdent; + Defs._IOwnership _109___v46; + Dafny.ISet> _110___v47; + RAST._IExpr _out55; + Defs._IOwnership _out56; + Dafny.ISet> _out57; + (this).GenIdent((_105_rustIdents).Select(_107_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out55, out _out56, out _out57); + _108_rIdent = _out55; + _109___v46 = _out56; + _110___v47 = _out57; + _106_tupleArgs = Dafny.Sequence.Concat(_106_tupleArgs, Dafny.Sequence.FromElements(_108_rIdent)); } - if ((new BigInteger((_107_tupleArgs).Count)) == (BigInteger.One)) { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_107_tupleArgs).Select(BigInteger.Zero))); + if ((new BigInteger((_106_tupleArgs).Count)) == (BigInteger.One)) { + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_106_tupleArgs).Select(BigInteger.Zero))); } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_107_tupleArgs))); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_106_tupleArgs))); } } after_match2: ; @@ -3004,20 +3173,20 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } } { - DAST._IExpression _112_e = _source0.dtor_Print_a0; + DAST._IExpression _111_e = _source0.dtor_Print_a0; { - RAST._IExpr _113_printedExpr; - Defs._IOwnership _114_recOwnership; - Dafny.ISet> _115_recIdents; - RAST._IExpr _out61; - Defs._IOwnership _out62; - Dafny.ISet> _out63; - (this).GenExpr(_112_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out61, out _out62, out _out63); - _113_printedExpr = _out61; - _114_recOwnership = _out62; - _115_recIdents = _out63; - generated = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("print!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("{}"), false, false), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrintWrapper"))).AsExpr()).Apply1(_113_printedExpr))); - readIdents = _115_recIdents; + RAST._IExpr _112_printedExpr; + Defs._IOwnership _113_recOwnership; + Dafny.ISet> _114_recIdents; + RAST._IExpr _out58; + Defs._IOwnership _out59; + Dafny.ISet> _out60; + (this).GenExpr(_111_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out58, out _out59, out _out60); + _112_printedExpr = _out58; + _113_recOwnership = _out59; + _114_recIdents = _out60; + generated = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("print!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("{}"), false, false), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrintWrapper"))).AsExpr()).Apply1(_112_printedExpr))); + readIdents = _114_recIdents; newEnv = env; } } @@ -3083,9 +3252,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. DAST._IExpression _source0 = e; { if (_source0.is_Literal) { - DAST._ILiteral _h300 = _source0.dtor_Literal_a0; - if (_h300.is_BoolLiteral) { - bool _0_b = _h300.dtor_BoolLiteral_a0; + DAST._ILiteral _h670 = _source0.dtor_Literal_a0; + if (_h670.is_BoolLiteral) { + bool _0_b = _h670.dtor_BoolLiteral_a0; { RAST._IExpr _out0; Defs._IOwnership _out1; @@ -3101,10 +3270,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h301 = _source0.dtor_Literal_a0; - if (_h301.is_IntLiteral) { - Dafny.ISequence _1_i = _h301.dtor_IntLiteral_a0; - DAST._IType _2_t = _h301.dtor_IntLiteral_a1; + DAST._ILiteral _h671 = _source0.dtor_Literal_a0; + if (_h671.is_IntLiteral) { + Dafny.ISequence _1_i = _h671.dtor_IntLiteral_a0; + DAST._IType _2_t = _h671.dtor_IntLiteral_a1; { DAST._IType _source1 = _2_t; { @@ -3147,11 +3316,11 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h302 = _source0.dtor_Literal_a0; - if (_h302.is_DecLiteral) { - Dafny.ISequence _5_n = _h302.dtor_DecLiteral_a0; - Dafny.ISequence _6_d = _h302.dtor_DecLiteral_a1; - DAST._IType _7_t = _h302.dtor_DecLiteral_a2; + DAST._ILiteral _h672 = _source0.dtor_Literal_a0; + if (_h672.is_DecLiteral) { + Dafny.ISequence _5_n = _h672.dtor_DecLiteral_a0; + Dafny.ISequence _6_d = _h672.dtor_DecLiteral_a1; + DAST._IType _7_t = _h672.dtor_DecLiteral_a2; { DAST._IType _source2 = _7_t; { @@ -3190,10 +3359,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h303 = _source0.dtor_Literal_a0; - if (_h303.is_StringLiteral) { - Dafny.ISequence _10_l = _h303.dtor_StringLiteral_a0; - bool _11_verbatim = _h303.dtor_verbatim; + DAST._ILiteral _h673 = _source0.dtor_Literal_a0; + if (_h673.is_StringLiteral) { + Dafny.ISequence _10_l = _h673.dtor_StringLiteral_a0; + bool _11_verbatim = _h673.dtor_verbatim; { r = (((RAST.__default.dafny__runtime).MSel((this).string__of)).AsExpr()).Apply1(RAST.Expr.create_LiteralString(_10_l, false, _11_verbatim)); RAST._IExpr _out8; @@ -3210,9 +3379,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h304 = _source0.dtor_Literal_a0; - if (_h304.is_CharLiteralUTF16) { - BigInteger _12_c = _h304.dtor_CharLiteralUTF16_a0; + DAST._ILiteral _h674 = _source0.dtor_Literal_a0; + if (_h674.is_CharLiteralUTF16) { + BigInteger _12_c = _h674.dtor_CharLiteralUTF16_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(_12_c)); r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); @@ -3231,9 +3400,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h305 = _source0.dtor_Literal_a0; - if (_h305.is_CharLiteral) { - Dafny.Rune _13_c = _h305.dtor_CharLiteral_a0; + DAST._ILiteral _h675 = _source0.dtor_Literal_a0; + if (_h675.is_CharLiteral) { + Dafny.Rune _13_c = _h675.dtor_CharLiteral_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(new BigInteger((_13_c).Value))); if (!(((this).charType).is_UTF32)) { @@ -3255,8 +3424,8 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } } { - DAST._ILiteral _h306 = _source0.dtor_Literal_a0; - DAST._IType _14_tpe = _h306.dtor_Null_a0; + DAST._ILiteral _h676 = _source0.dtor_Literal_a0; + DAST._IType _14_tpe = _h676.dtor_Null_a0; { RAST._IType _15_tpeGen; RAST._IType _out14; @@ -3373,24 +3542,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v57; + Defs._IOwnership _12___v48; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v57 = _out1; + _12___v48 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v58; + Defs._IOwnership _15___v49; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v58 = _out4; + _15___v49 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -3699,7 +3868,21 @@ public RAST._IExpr WrapWithNewtype(RAST._IExpr expr, Defs._IOwnership exprOwners } return r; } - public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) + public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpeWithSynonyms, DAST._IType toTpeWithSynonyms, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) + { + r = RAST.Expr.Default(); + resultingOwnership = Defs.Ownership.Default(); + DAST._IType _0_fromTpe; + _0_fromTpe = (fromTpeWithSynonyms).RemoveSynonyms(); + DAST._IType _1_toTpe; + _1_toTpe = (toTpeWithSynonyms).RemoveSynonyms(); + RAST._IExpr _out0; + Defs._IOwnership _out1; + (this).GenExprConvertToWithoutSynonyms(expr, exprOwnership, _0_fromTpe, _1_toTpe, env, expectedOwnership, out _out0, out _out1); + r = _out0; + resultingOwnership = _out1; + } + public void GenExprConvertToWithoutSynonyms(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) { r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); @@ -3712,49 +3895,33 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out1; return ; } - if (((fromTpe).is_UserDefined) && ((((fromTpe).dtor_resolved).dtor_kind).is_SynonymType)) { + if (Defs.__default.NeedsUnwrappingConversion(fromTpe)) { RAST._IExpr _out2; - Defs._IOwnership _out3; - (this).GenExprConvertTo(expr, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, env, expectedOwnership, out _out2, out _out3); + _out2 = (this).UnwrapNewtype(r, exprOwnership, fromTpe); r = _out2; - resultingOwnership = _out3; - return ; - } - if (((toTpe).is_UserDefined) && ((((toTpe).dtor_resolved).dtor_kind).is_SynonymType)) { - RAST._IExpr _out4; - Defs._IOwnership _out5; - (this).GenExprConvertTo(expr, exprOwnership, fromTpe, (((toTpe).dtor_resolved).dtor_kind).dtor_baseType, env, expectedOwnership, out _out4, out _out5); - r = _out4; - resultingOwnership = _out5; - return ; - } - if (Defs.__default.NeedsUnwrappingConversion(fromTpe)) { - RAST._IExpr _out6; - _out6 = (this).UnwrapNewtype(r, exprOwnership, fromTpe); - r = _out6; - RAST._IExpr _out7; - Defs._IOwnership _out8; - (this).GenExprConvertTo(r, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, env, expectedOwnership, out _out7, out _out8); - r = _out7; - resultingOwnership = _out8; + RAST._IExpr _out3; + Defs._IOwnership _out4; + (this).GenExprConvertToWithoutSynonyms(r, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, env, expectedOwnership, out _out3, out _out4); + r = _out3; + resultingOwnership = _out4; return ; } if (Defs.__default.NeedsUnwrappingConversion(toTpe)) { DAST._IResolvedTypeBase _0_toKind; _0_toKind = ((toTpe).dtor_resolved).dtor_kind; - RAST._IExpr _out9; - Defs._IOwnership _out10; - (this).GenExprConvertTo(r, exprOwnership, fromTpe, (_0_toKind).dtor_baseType, env, expectedOwnership, out _out9, out _out10); - r = _out9; - resultingOwnership = _out10; - RAST._IExpr _out11; - _out11 = (this).WrapWithNewtype(r, resultingOwnership, toTpe); - r = _out11; - RAST._IExpr _out12; - Defs._IOwnership _out13; - (this).FromOwnership(r, resultingOwnership, expectedOwnership, out _out12, out _out13); - r = _out12; - resultingOwnership = _out13; + RAST._IExpr _out5; + Defs._IOwnership _out6; + (this).GenExprConvertToWithoutSynonyms(r, exprOwnership, fromTpe, (_0_toKind).dtor_baseType, env, expectedOwnership, out _out5, out _out6); + r = _out5; + resultingOwnership = _out6; + RAST._IExpr _out7; + _out7 = (this).WrapWithNewtype(r, resultingOwnership, toTpe); + r = _out7; + RAST._IExpr _out8; + Defs._IOwnership _out9; + (this).FromOwnership(r, resultingOwnership, expectedOwnership, out _out8, out _out9); + r = _out8; + resultingOwnership = _out9; return ; } Std.Wrappers._IOption _1_unwrappedFromType; @@ -3765,9 +3932,9 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D RAST._IType _3_boundedToType; _3_boundedToType = (_2_unwrappedToType).dtor_value; if ((_1_unwrappedFromType).is_Some) { - RAST._IExpr _out14; - _out14 = (this).UnwrapNewtype(r, exprOwnership, fromTpe); - r = _out14; + RAST._IExpr _out10; + _out10 = (this).UnwrapNewtype(r, exprOwnership, fromTpe); + r = _out10; Defs._IOwnership _4_inOwnership; _4_inOwnership = exprOwnership; if (!object.Equals((_1_unwrappedFromType).dtor_value, (_2_unwrappedToType).dtor_value)) { @@ -3793,14 +3960,14 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D r = RAST.Expr.create_TypeAscription(r, _5_asType); _4_inOwnership = Defs.Ownership.create_OwnershipOwned(); } - RAST._IExpr _out15; - _out15 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); - r = _out15; - RAST._IExpr _out16; - Defs._IOwnership _out17; - (this).FromOwnership(r, _4_inOwnership, expectedOwnership, out _out16, out _out17); - r = _out16; - resultingOwnership = _out17; + RAST._IExpr _out11; + _out11 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); + r = _out11; + RAST._IExpr _out12; + Defs._IOwnership _out13; + (this).FromOwnership(r, _4_inOwnership, expectedOwnership, out _out12, out _out13); + r = _out12; + resultingOwnership = _out13; return ; } if ((fromTpe).IsPrimitiveInt()) { @@ -3808,40 +3975,40 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D r = (r).Clone(); } r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("truncate!"))).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_3_boundedToType))); - RAST._IExpr _out18; - _out18 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); - r = _out18; - RAST._IExpr _out19; - Defs._IOwnership _out20; - (this).FromOwned(r, expectedOwnership, out _out19, out _out20); - r = _out19; - resultingOwnership = _out20; + RAST._IExpr _out14; + _out14 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); + r = _out14; + RAST._IExpr _out15; + Defs._IOwnership _out16; + (this).FromOwned(r, expectedOwnership, out _out15, out _out16); + r = _out15; + resultingOwnership = _out16; return ; } if (object.Equals(fromTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { r = RAST.Expr.create_TypeAscription((r).Sel(Dafny.Sequence.UnicodeFromString("0")), _3_boundedToType); - RAST._IExpr _out21; - _out21 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); - r = _out21; - RAST._IExpr _out22; - Defs._IOwnership _out23; - (this).FromOwned(r, expectedOwnership, out _out22, out _out23); - r = _out22; - resultingOwnership = _out23; + RAST._IExpr _out17; + _out17 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); + r = _out17; + RAST._IExpr _out18; + Defs._IOwnership _out19; + (this).FromOwned(r, expectedOwnership, out _out18, out _out19); + r = _out18; + resultingOwnership = _out19; return ; } RAST._IType _7_fromTpeRust; - RAST._IType _out24; - _out24 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); - _7_fromTpeRust = _out24; - RAST._IExpr _out25; - _out25 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), (_7_fromTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_3_boundedToType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - r = _out25; - RAST._IExpr _out26; - Defs._IOwnership _out27; - (this).FromOwned(r, expectedOwnership, out _out26, out _out27); - r = _out26; - resultingOwnership = _out27; + RAST._IType _out20; + _out20 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); + _7_fromTpeRust = _out20; + RAST._IExpr _out21; + _out21 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), (_7_fromTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_3_boundedToType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + r = _out21; + RAST._IExpr _out22; + Defs._IOwnership _out23; + (this).FromOwned(r, expectedOwnership, out _out22, out _out23); + r = _out22; + resultingOwnership = _out23; return ; } if ((_1_unwrappedFromType).is_Some) { @@ -3849,39 +4016,39 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D r = (r).Sel(Dafny.Sequence.UnicodeFromString("0")); } if (object.Equals(toTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { - RAST._IExpr _out28; - Defs._IOwnership _out29; - (this).FromOwnership((((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(RAST.Expr.create_TypeAscription(r, (this).DafnyCharUnderlying)), exprOwnership, expectedOwnership, out _out28, out _out29); - r = _out28; - resultingOwnership = _out29; + RAST._IExpr _out24; + Defs._IOwnership _out25; + (this).FromOwnership((((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(RAST.Expr.create_TypeAscription(r, (this).DafnyCharUnderlying)), exprOwnership, expectedOwnership, out _out24, out _out25); + r = _out24; + resultingOwnership = _out25; return ; } if ((toTpe).IsPrimitiveInt()) { - RAST._IExpr _out30; - Defs._IOwnership _out31; - (this).FromOwnership(r, exprOwnership, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31); - r = _out30; - resultingOwnership = _out31; + RAST._IExpr _out26; + Defs._IOwnership _out27; + (this).FromOwnership(r, exprOwnership, Defs.Ownership.create_OwnershipOwned(), out _out26, out _out27); + r = _out26; + resultingOwnership = _out27; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(r); - RAST._IExpr _out32; - Defs._IOwnership _out33; - (this).FromOwned(r, expectedOwnership, out _out32, out _out33); - r = _out32; - resultingOwnership = _out33; + RAST._IExpr _out28; + Defs._IOwnership _out29; + (this).FromOwned(r, expectedOwnership, out _out28, out _out29); + r = _out28; + resultingOwnership = _out29; return ; } RAST._IType _8_toTpeRust; - RAST._IType _out34; - _out34 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); - _8_toTpeRust = _out34; - RAST._IExpr _out35; - _out35 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), ((_1_unwrappedFromType).dtor_value)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_8_toTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - r = _out35; - RAST._IExpr _out36; - Defs._IOwnership _out37; - (this).FromOwned(r, expectedOwnership, out _out36, out _out37); - r = _out36; - resultingOwnership = _out37; + RAST._IType _out30; + _out30 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); + _8_toTpeRust = _out30; + RAST._IExpr _out31; + _out31 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), ((_1_unwrappedFromType).dtor_value)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_8_toTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + r = _out31; + RAST._IExpr _out32; + Defs._IOwnership _out33; + (this).FromOwned(r, expectedOwnership, out _out32, out _out33); + r = _out32; + resultingOwnership = _out33; return ; } _System._ITuple2 _source1 = _System.Tuple2.create(fromTpe, toTpe); @@ -3896,11 +4063,11 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D if (_h71.is_Real) { { r = Dafny.Helpers.Id>((this).rcNew)(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("BigRational"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("from_integer"))).Apply1(r)); - RAST._IExpr _out38; - Defs._IOwnership _out39; - (this).FromOwned(r, expectedOwnership, out _out38, out _out39); - r = _out38; - resultingOwnership = _out39; + RAST._IExpr _out34; + Defs._IOwnership _out35; + (this).FromOwned(r, expectedOwnership, out _out34, out _out35); + r = _out34; + resultingOwnership = _out35; } goto after_match1; } @@ -3919,11 +4086,11 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D if (_h73.is_Int) { { r = (((RAST.__default.dafny__runtime).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("dafny_rational_to_int"))).Apply1(r); - RAST._IExpr _out40; - Defs._IOwnership _out41; - (this).FromOwned(r, expectedOwnership, out _out40, out _out41); - r = _out40; - resultingOwnership = _out41; + RAST._IExpr _out36; + Defs._IOwnership _out37; + (this).FromOwned(r, expectedOwnership, out _out36, out _out37); + r = _out36; + resultingOwnership = _out37; } goto after_match1; } @@ -3942,9 +4109,9 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D if (_h75.is_Char) { { RAST._IType _9_rhsType; - RAST._IType _out42; - _out42 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); - _9_rhsType = _out42; + RAST._IType _out38; + _out38 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); + _9_rhsType = _out38; RAST._IType _10_uType; if (((this).charType).is_UTF32) { _10_uType = RAST.Type.create_U32(); @@ -3959,11 +4126,11 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D r = ((((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("char"))).FSel(Dafny.Sequence.UnicodeFromString("from_u32"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); } r = (((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(r); - RAST._IExpr _out43; - Defs._IOwnership _out44; - (this).FromOwned(r, expectedOwnership, out _out43, out _out44); - r = _out43; - resultingOwnership = _out44; + RAST._IExpr _out39; + Defs._IOwnership _out40; + (this).FromOwned(r, expectedOwnership, out _out39, out _out40); + r = _out39; + resultingOwnership = _out40; } goto after_match1; } @@ -3982,15 +4149,15 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D if (_h77.is_Int) { { RAST._IType _11_rhsType; - RAST._IType _out45; - _out45 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); - _11_rhsType = _out45; + RAST._IType _out41; + _out41 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); + _11_rhsType = _out41; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1((r).Sel(Dafny.Sequence.UnicodeFromString("0"))); - RAST._IExpr _out46; - Defs._IOwnership _out47; - (this).FromOwned(r, expectedOwnership, out _out46, out _out47); - r = _out46; - resultingOwnership = _out47; + RAST._IExpr _out42; + Defs._IOwnership _out43; + (this).FromOwned(r, expectedOwnership, out _out42, out _out43); + r = _out42; + resultingOwnership = _out43; } goto after_match1; } @@ -4000,11 +4167,11 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D } { { - RAST._IExpr _out48; - Defs._IOwnership _out49; - (this).GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, env, expectedOwnership, out _out48, out _out49); - r = _out48; - resultingOwnership = _out49; + RAST._IExpr _out44; + Defs._IOwnership _out45; + (this).GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, env, expectedOwnership, out _out44, out _out45); + r = _out44; + resultingOwnership = _out45; } } after_match1: ; @@ -4089,45 +4256,45 @@ public bool SameTypesButDifferentTypeParameters(DAST._IType fromType, RAST._ITyp } } else if ((this).SameTypesButDifferentTypeParameters(fromType, fromTpe, toType, toTpe)) { Dafny.ISequence _6_indices = ((((fromType).is_UserDefined) && ((((fromType).dtor_resolved).dtor_kind).is_Datatype)) ? (Std.Collections.Seq.__default.Filter(Dafny.Helpers.Id>>((_7_fromTpe, _8_fromType) => ((System.Func)((_9_i) => { - return ((((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((_7_fromTpe).dtor_arguments).Count)))) ? (!(((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((((_8_fromType).dtor_resolved).dtor_kind).dtor_variances).Count)))) || (!((((((_8_fromType).dtor_resolved).dtor_kind).dtor_variances).Select(_9_i)).is_Nonvariant))) : (false)); + return ((((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((_7_fromTpe).dtor_arguments).Count)))) ? (!(((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((((_8_fromType).dtor_resolved).dtor_kind).dtor_info).Count)))) || (!(((((((_8_fromType).dtor_resolved).dtor_kind).dtor_info).Select(_9_i)).dtor_variance).is_Nonvariant))) : (false)); })))(fromTpe, fromType), ((System.Func>) (() => { - BigInteger dim14 = new BigInteger(((fromTpe).dtor_arguments).Count); - var arr14 = new BigInteger[Dafny.Helpers.ToIntChecked(dim14, "array size exceeds memory limit")]; - for (int i14 = 0; i14 < dim14; i14++) { - var _10_i = (BigInteger) i14; - arr14[(int)(_10_i)] = _10_i; - } - return Dafny.Sequence.FromArray(arr14); - }))())) : (((System.Func>) (() => { BigInteger dim15 = new BigInteger(((fromTpe).dtor_arguments).Count); var arr15 = new BigInteger[Dafny.Helpers.ToIntChecked(dim15, "array size exceeds memory limit")]; for (int i15 = 0; i15 < dim15; i15++) { - var _11_i = (BigInteger) i15; - arr15[(int)(_11_i)] = _11_i; + var _10_i = (BigInteger) i15; + arr15[(int)(_10_i)] = _10_i; } return Dafny.Sequence.FromArray(arr15); + }))())) : (((System.Func>) (() => { + BigInteger dim16 = new BigInteger(((fromTpe).dtor_arguments).Count); + var arr16 = new BigInteger[Dafny.Helpers.ToIntChecked(dim16, "array size exceeds memory limit")]; + for (int i16 = 0; i16 < dim16; i16++) { + var _11_i = (BigInteger) i16; + arr16[(int)(_11_i)] = _11_i; + } + return Dafny.Sequence.FromArray(arr16); }))())); Std.Wrappers._IResult, _System._ITuple5,RAST._IExpr>>> _12_valueOrError1 = (this).SeqResultToResultSeq,RAST._IExpr>>>(((System.Func,RAST._IExpr>>>>>) (() => { - BigInteger dim16 = new BigInteger((_6_indices).Count); - var arr16 = new Std.Wrappers._IResult,RAST._IExpr>>>[Dafny.Helpers.ToIntChecked(dim16, "array size exceeds memory limit")]; - for (int i16 = 0; i16 < dim16; i16++) { - var _13_j = (BigInteger) i16; - arr16[(int)(_13_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_6_indices).Select(_13_j), _pat_let27_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let27_0, _14_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv1).dtor_arguments).Select(_14_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv3).dtor_arguments).Select(_14_i), _pat_let_tv4))); + BigInteger dim17 = new BigInteger((_6_indices).Count); + var arr17 = new Std.Wrappers._IResult,RAST._IExpr>>>[Dafny.Helpers.ToIntChecked(dim17, "array size exceeds memory limit")]; + for (int i17 = 0; i17 < dim17; i17++) { + var _13_j = (BigInteger) i17; + arr17[(int)(_13_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_6_indices).Select(_13_j), _pat_let27_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let27_0, _14_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv1).dtor_arguments).Select(_14_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv3).dtor_arguments).Select(_14_i), _pat_let_tv4))); } - return Dafny.Sequence,RAST._IExpr>>>>.FromArray(arr16); + return Dafny.Sequence,RAST._IExpr>>>>.FromArray(arr17); }))()); if ((_12_valueOrError1).IsFailure()) { return (_12_valueOrError1).PropagateFailure(); } else { Dafny.ISequence _15_lambdas = (_12_valueOrError1).Extract(); return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.Expr.create_ExprFromType((fromTpe).dtor_baseName)).ApplyType(((System.Func>) (() => { - BigInteger dim17 = new BigInteger(((fromTpe).dtor_arguments).Count); - var arr17 = new RAST._IType[Dafny.Helpers.ToIntChecked(dim17, "array size exceeds memory limit")]; - for (int i17 = 0; i17 < dim17; i17++) { - var _16_i = (BigInteger) i17; - arr17[(int)(_16_i)] = ((fromTpe).dtor_arguments).Select(_16_i); + BigInteger dim18 = new BigInteger(((fromTpe).dtor_arguments).Count); + var arr18 = new RAST._IType[Dafny.Helpers.ToIntChecked(dim18, "array size exceeds memory limit")]; + for (int i18 = 0; i18 < dim18; i18++) { + var _16_i = (BigInteger) i18; + arr18[(int)(_16_i)] = ((fromTpe).dtor_arguments).Select(_16_i); } - return Dafny.Sequence.FromArray(arr17); + return Dafny.Sequence.FromArray(arr18); }))())).FSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply(_15_lambdas)); } } else if (((((fromTpe).IsBuiltinCollection()) && ((toTpe).IsBuiltinCollection())) && ((this).IsBuiltinCollection(fromType))) && ((this).IsBuiltinCollection(toType))) { @@ -4184,7 +4351,7 @@ public RAST._IExpr BorrowedToOwned(RAST._IExpr expr, Defs._IEnvironment env) return (expr).Clone(); } } - public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) + public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTyp, DAST._IType toTyp, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) { r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); @@ -4192,27 +4359,131 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership resultingOwnership = exprOwnership; RAST._IType _0_fromTpeGen; RAST._IType _out0; - _out0 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); + _out0 = (this).GenType(fromTyp, Defs.GenTypeContext.@default()); _0_fromTpeGen = _out0; RAST._IType _1_toTpeGen; RAST._IType _out1; - _out1 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); + _out1 = (this).GenType(toTyp, Defs.GenTypeContext.@default()); _1_toTpeGen = _out1; - Std.Wrappers._IResult,RAST._IExpr>>> _2_upcastConverter; - _2_upcastConverter = (this).UpcastConversionLambda(fromTpe, _0_fromTpeGen, toTpe, _1_toTpeGen, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements()); - if ((_2_upcastConverter).is_Success) { - RAST._IExpr _3_conversionLambda; - _3_conversionLambda = (_2_upcastConverter).dtor_value; + bool _2_isDatatype; + _2_isDatatype = (toTyp).IsDatatype(); + bool _3_isGeneralTrait; + _3_isGeneralTrait = (!(_2_isDatatype)) && ((toTyp).IsGeneralTrait()); + if ((_2_isDatatype) || (_3_isGeneralTrait)) { + bool _4_isDowncast; + _4_isDowncast = (toTyp).Extends(fromTyp); + if (_4_isDowncast) { + DAST._IType _5_underlyingType; + if (_2_isDatatype) { + _5_underlyingType = (toTyp).GetDatatypeType(); + } else { + _5_underlyingType = (toTyp).GetGeneralTraitType(); + } + RAST._IType _6_toTpeRaw; + RAST._IType _out2; + _out2 = (this).GenType(_5_underlyingType, Defs.GenTypeContext.@default()); + _6_toTpeRaw = _out2; + Std.Wrappers._IOption _7_toTpeRawDowncastOpt; + _7_toTpeRawDowncastOpt = (_6_toTpeRaw).ToDowncastExpr(); + if ((_7_toTpeRawDowncastOpt).is_Some) { + RAST._IExpr _8_newExpr; + _8_newExpr = expr; + if ((exprOwnership).is_OwnershipOwned) { + RAST._IExpr _source0 = _8_newExpr; + { + if (_source0.is_Call) { + RAST._IExpr obj0 = _source0.dtor_obj; + if (obj0.is_Select) { + RAST._IExpr obj1 = obj0.dtor_obj; + if (obj1.is_Identifier) { + Dafny.ISequence _9_name = obj1.dtor_name; + Dafny.ISequence name0 = obj0.dtor_name; + if (object.Equals(name0, Dafny.Sequence.UnicodeFromString("clone"))) { + Dafny.ISequence _10_arguments = _source0.dtor_arguments; + if ((new BigInteger((_10_arguments).Count)).Sign == 0) { + _8_newExpr = RAST.Expr.create_Identifier(_9_name); + if (!((env).IsBorrowed(_9_name))) { + _8_newExpr = RAST.__default.Borrow(_8_newExpr); + } + } else { + RAST._IExpr _out3; + Defs._IOwnership _out4; + (this).FromOwnership(_8_newExpr, Defs.Ownership.create_OwnershipOwned(), Defs.Ownership.create_OwnershipBorrowed(), out _out3, out _out4); + _8_newExpr = _out3; + resultingOwnership = _out4; + } + goto after_match0; + } + } + } + } + } + { + { + RAST._IExpr _out5; + Defs._IOwnership _out6; + (this).FromOwnership(_8_newExpr, Defs.Ownership.create_OwnershipOwned(), Defs.Ownership.create_OwnershipBorrowed(), out _out5, out _out6); + _8_newExpr = _out5; + resultingOwnership = _out6; + } + } + after_match0: ; + } + _8_newExpr = (this).FromGeneralBorrowToSelfBorrow(_8_newExpr, Defs.Ownership.create_OwnershipBorrowed(), env); + if (_2_isDatatype) { + _8_newExpr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_8_newExpr); + } + r = (((_7_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_as"))).Apply1(_8_newExpr); + RAST._IExpr _out7; + Defs._IOwnership _out8; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out7, out _out8); + r = _out7; + resultingOwnership = _out8; + return ; + } else { + RAST._IExpr _out9; + _out9 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_6_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); + r = _out9; + RAST._IExpr _out10; + Defs._IOwnership _out11; + (this).FromOwned(r, expectedOwnership, out _out10, out _out11); + r = _out10; + resultingOwnership = _out11; + return ; + } + } + } + Std.Wrappers._IResult,RAST._IExpr>>> _11_upcastConverter; + _11_upcastConverter = (this).UpcastConversionLambda(fromTyp, _0_fromTpeGen, toTyp, _1_toTpeGen, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements()); + if ((_11_upcastConverter).is_Success) { + RAST._IExpr _12_conversionLambda; + _12_conversionLambda = (_11_upcastConverter).dtor_value; if (object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipBorrowed())) { - r = (this).BorrowedToOwned(r, env); + if (((fromTyp).IsGeneralTrait()) && (object.Equals(r, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))))) { + RAST._IType _13_traitType; + RAST._IType _out12; + _out12 = (this).GenType(fromTyp, Defs.GenTypeContext.ForTraitParents()); + _13_traitType = _out12; + Std.Wrappers._IOption _14_traitExpr; + _14_traitExpr = (_13_traitType).ToExpr(); + if ((_14_traitExpr).is_None) { + RAST._IExpr _out13; + _out13 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_13_traitType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + r = _out13; + } else { + r = (((_14_traitExpr).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(r); + } + } else { + r = (this).BorrowedToOwned(r, env); + } resultingOwnership = Defs.Ownership.create_OwnershipOwned(); } - r = (_3_conversionLambda).Apply1(r); - RAST._IExpr _out2; - Defs._IOwnership _out3; - (this).FromOwnership(r, resultingOwnership, expectedOwnership, out _out2, out _out3); - r = _out2; - resultingOwnership = _out3; + r = (_12_conversionLambda).Apply1(r); + RAST._IExpr _out14; + Defs._IOwnership _out15; + (this).FromOwnership(r, resultingOwnership, expectedOwnership, out _out14, out _out15); + r = _out14; + resultingOwnership = _out15; } else if ((this).IsDowncastConversion(_0_fromTpeGen, _1_toTpeGen)) { _1_toTpeGen = (_1_toTpeGen).ObjectOrPointerUnderlying(); if (object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipBorrowed())) { @@ -4220,27 +4491,27 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership resultingOwnership = Defs.Ownership.create_OwnershipOwned(); } r = (((RAST.__default.dafny__runtime).MSel((this).downcast)).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_1_toTpeGen))); - RAST._IExpr _out4; - Defs._IOwnership _out5; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out4, out _out5); - r = _out4; - resultingOwnership = _out5; + RAST._IExpr _out16; + Defs._IOwnership _out17; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out16, out _out17); + r = _out16; + resultingOwnership = _out17; } else { - Std.Wrappers._IResult,RAST._IExpr>>> _let_tmp_rhs0 = _2_upcastConverter; + Std.Wrappers._IResult,RAST._IExpr>>> _let_tmp_rhs0 = _11_upcastConverter; _System._ITuple5,RAST._IExpr>> _let_tmp_rhs1 = _let_tmp_rhs0.dtor_error; - DAST._IType _4_fromType = _let_tmp_rhs1.dtor__0; - RAST._IType _5_fromTpeGen = _let_tmp_rhs1.dtor__1; - DAST._IType _6_toType = _let_tmp_rhs1.dtor__2; - RAST._IType _7_toTpeGen = _let_tmp_rhs1.dtor__3; - Dafny.IMap<_System._ITuple2,RAST._IExpr> _8_m = _let_tmp_rhs1.dtor__4; - RAST._IExpr _out6; - _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_5_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_7_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); - r = _out6; - RAST._IExpr _out7; - Defs._IOwnership _out8; - (this).FromOwned(r, expectedOwnership, out _out7, out _out8); - r = _out7; - resultingOwnership = _out8; + DAST._IType _15_fromType = _let_tmp_rhs1.dtor__0; + RAST._IType _16_fromTpeGen = _let_tmp_rhs1.dtor__1; + DAST._IType _17_toType = _let_tmp_rhs1.dtor__2; + RAST._IType _18_toTpeGen = _let_tmp_rhs1.dtor__3; + Dafny.IMap<_System._ITuple2,RAST._IExpr> _19_m = _let_tmp_rhs1.dtor__4; + RAST._IExpr _out18; + _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_16_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_18_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); + r = _out18; + RAST._IExpr _out19; + Defs._IOwnership _out20; + (this).FromOwned(r, expectedOwnership, out _out19, out _out20); + r = _out19; + resultingOwnership = _out20; } } public void GenExprConvert(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership, out Dafny.ISet> readIdents) @@ -4320,41 +4591,55 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden } resultingOwnership = Defs.Ownership.create_OwnershipBorrowedMut(); } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) { - bool _5_needObjectFromRef; - _5_needObjectFromRef = (_4_isSelf) && (((System.Func)(() => { - DAST._IType _source0 = (selfIdent).dtor_dafnyType; - { - if (_source0.is_UserDefined) { - DAST._IResolvedType resolved0 = _source0.dtor_resolved; - DAST._IResolvedTypeBase _6_base = resolved0.dtor_kind; - Dafny.ISequence _7_attributes = resolved0.dtor_attributes; - return ((_6_base).is_Class) || (((_6_base).is_Trait) && (((_6_base).dtor_traitType).is_ObjectTrait)); - } - } - { - return false; - } - }))()); - if (_5_needObjectFromRef) { + bool _5_needsObjectFromRef; + _5_needsObjectFromRef = (_4_isSelf) && ((selfIdent).IsClassOrObjectTrait()); + bool _6_needsRcWrapping; + _6_needsRcWrapping = (_4_isSelf) && ((selfIdent).IsRcWrappedDatatype()); + if (_5_needsObjectFromRef) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))).FSel(Dafny.Sequence.UnicodeFromString("from_ref"))).Apply(Dafny.Sequence.FromElements(r)); + } else if (_6_needsRcWrapping) { + r = Dafny.Helpers.Id>((this).rcNew)((r).Clone()); } else { if (!(_3_noNeedOfClone)) { - r = (r).Clone(); + bool _7_needUnderscoreClone; + _7_needUnderscoreClone = (_4_isSelf) && ((selfIdent).IsGeneralTrait()); + if (_7_needUnderscoreClone) { + RAST._IType _8_traitType; + RAST._IType _out0; + _out0 = (this).GenType((selfIdent).dtor_dafnyType, Defs.GenTypeContext.ForTraitParents()); + _8_traitType = _out0; + Std.Wrappers._IOption _9_traitExpr; + _9_traitExpr = (_8_traitType).ToExpr(); + if ((_9_traitExpr).is_None) { + RAST._IExpr _out1; + _out1 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_8_traitType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + r = _out1; + } else { + r = (((_9_traitExpr).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(r); + } + } else { + r = (r).Clone(); + } } } resultingOwnership = Defs.Ownership.create_OwnershipOwned(); } else if (_2_currentlyBorrowed) { + bool _10_needsRcWrapping; + _10_needsRcWrapping = (_4_isSelf) && ((selfIdent).IsRcWrappedDatatype()); + if (_10_needsRcWrapping) { + r = RAST.__default.Borrow(Dafny.Helpers.Id>((this).rcNew)((r).Clone())); + } resultingOwnership = Defs.Ownership.create_OwnershipBorrowed(); } else { - bool _8_selfIsGeneralTrait; - _8_selfIsGeneralTrait = (_4_isSelf) && (((System.Func)(() => { - DAST._IType _source1 = (selfIdent).dtor_dafnyType; + bool _11_selfIsGeneralTrait; + _11_selfIsGeneralTrait = (_4_isSelf) && (((System.Func)(() => { + DAST._IType _source0 = (selfIdent).dtor_dafnyType; { - if (_source1.is_UserDefined) { - DAST._IResolvedType resolved1 = _source1.dtor_resolved; - DAST._IResolvedTypeBase _9_base = resolved1.dtor_kind; - Dafny.ISequence _10_attributes = resolved1.dtor_attributes; - return ((_9_base).is_Trait) && (((_9_base).dtor_traitType).is_GeneralTrait); + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _12_base = resolved0.dtor_kind; + Dafny.ISequence _13_attributes = resolved0.dtor_attributes; + return ((_12_base).is_Trait) && (((_12_base).dtor_traitType).is_GeneralTrait); } } { @@ -4387,38 +4672,38 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ fullNameQualifier = Std.Wrappers.Option.Default(); argExprs = Dafny.Sequence.FromElements(); readIdents = Dafny.Set>.FromElements(); - Dafny.ISequence _0_signature; + Dafny.ISequence _0_borrowSignature = Dafny.Sequence.Empty; if ((name).is_CallName) { if ((((name).dtor_receiverArg).is_Some) && ((name).dtor_receiverAsArgument)) { - _0_signature = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((name).dtor_receiverArg).dtor_value), ((name).dtor_signature)); + _0_borrowSignature = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((name).dtor_receiverArg).dtor_value), ((name).dtor_signature).dtor_inheritedParams); } else { - _0_signature = ((name).dtor_signature); + _0_borrowSignature = ((name).dtor_signature).dtor_inheritedParams; } } else { - _0_signature = Dafny.Sequence.FromElements(); + _0_borrowSignature = Dafny.Sequence.FromElements(); } BigInteger _hi0 = new BigInteger((args).Count); for (BigInteger _1_i = BigInteger.Zero; _1_i < _hi0; _1_i++) { Defs._IOwnership _2_argOwnership; _2_argOwnership = Defs.Ownership.create_OwnershipBorrowed(); - if ((_1_i) < (new BigInteger((_0_signature).Count))) { + if ((_1_i) < (new BigInteger((_0_borrowSignature).Count))) { RAST._IType _3_tpe; RAST._IType _out0; - _out0 = (this).GenType(((_0_signature).Select(_1_i)).dtor_typ, Defs.GenTypeContext.@default()); + _out0 = (this).GenType(((_0_borrowSignature).Select(_1_i)).dtor_typ, Defs.GenTypeContext.@default()); _3_tpe = _out0; if ((_3_tpe).CanReadWithoutClone()) { _2_argOwnership = Defs.Ownership.create_OwnershipOwned(); } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v75; + Defs._IOwnership _5___v62; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v75 = _out2; + _5___v62 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4616,14 +4901,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v85; + Defs._IOwnership _13___v72; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v85 = _out17; + _13___v72 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4672,14 +4957,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v86; + Defs._IOwnership _24___v73; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v86 = _out24; + _24___v73 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4717,14 +5002,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v87; + Defs._IOwnership _32___v74; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v87 = _out31; + _32___v74 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -4751,14 +5036,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v88; + Defs._IOwnership _37___v75; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v88 = _out36; + _37___v75 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -4781,14 +5066,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v89; + Defs._IOwnership _43___v76; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v89 = _out42; + _43___v76 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -4840,10 +5125,10 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _54_typeExpr = _out49; _52_genTypeArgs = Dafny.Sequence.Concat(_52_genTypeArgs, Dafny.Sequence.FromElements(_54_typeExpr)); } + r = (r).FSel(Defs.__default.escapeName(_49_variant)); if ((new BigInteger((_48_typeArgs).Count)).Sign == 1) { r = (r).ApplyType(_52_genTypeArgs); } - r = (r).FSel(Defs.__default.escapeName(_49_variant)); readIdents = Dafny.Set>.FromElements(); Dafny.ISequence _55_assignments; _55_assignments = Dafny.Sequence.FromElements(); @@ -4854,14 +5139,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v90; + Defs._IOwnership _60___v77; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v90 = _out51; + _60___v77 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -4884,21 +5169,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v91; + Defs._IOwnership _66___v78; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v91 = _out54; + _66___v78 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); } } r = RAST.Expr.create_StructBuild(r, _55_assignments); - if ((this).IsRcWrapped((_47_datatypeType).dtor_attributes)) { + if (Defs.__default.IsRcWrapped((_47_datatypeType).dtor_attributes)) { r = Dafny.Helpers.Id>((this).rcNew)(r); } RAST._IExpr _out56; @@ -4931,24 +5216,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v95; + Defs._IOwnership _71___v82; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v95 = _out62; + _71___v82 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v96; + Defs._IOwnership _74___v83; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v96 = _out65; + _74___v83 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -4987,14 +5272,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v97; + Defs._IOwnership _84___v84; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v97 = _out71; + _84___v84 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -5025,14 +5310,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v98; + Defs._IOwnership _90___v85; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v98 = _out76; + _90___v85 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -5060,14 +5345,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v99; + Defs._IOwnership _96___v86; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v99 = _out81; + _96___v86 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -5089,14 +5374,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v100; + Defs._IOwnership _100___v87; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v100 = _out86; + _100___v87 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -5113,54 +5398,64 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { if (_source0.is_MapValue) { Dafny.ISequence<_System._ITuple2> _102_mapElems = _source0.dtor_mapElems; + DAST._IType _103_rangeType = _source0.dtor_domainType; + DAST._IType _104_domainType = _source0.dtor_rangeType; { - Dafny.ISequence<_System._ITuple2> _103_generatedValues; - _103_generatedValues = Dafny.Sequence<_System._ITuple2>.FromElements(); + Dafny.ISequence<_System._ITuple2> _105_generatedValues; + _105_generatedValues = Dafny.Sequence<_System._ITuple2>.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _104_i; - _104_i = BigInteger.Zero; - while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { - RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v101; - Dafny.ISet> _107_recIdentsKey; + BigInteger _hi7 = new BigInteger((_102_mapElems).Count); + for (BigInteger _106_i = BigInteger.Zero; _106_i < _hi7; _106_i++) { + RAST._IExpr _107_recursiveGenKey; + Defs._IOwnership _108___v88; + Dafny.ISet> _109_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; - (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); - _105_recursiveGenKey = _out90; - _106___v101 = _out91; - _107_recIdentsKey = _out92; - RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v102; - Dafny.ISet> _110_recIdentsValue; + (this).GenExpr(((_102_mapElems).Select(_106_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); + _107_recursiveGenKey = _out90; + _108___v88 = _out91; + _109_recIdentsKey = _out92; + RAST._IExpr _110_recursiveGenValue; + Defs._IOwnership _111___v89; + Dafny.ISet> _112_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; - (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); - _108_recursiveGenValue = _out93; - _109___v102 = _out94; - _110_recIdentsValue = _out95; - _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); - _104_i = (_104_i) + (BigInteger.One); - } - _104_i = BigInteger.Zero; - Dafny.ISequence _111_arguments; - _111_arguments = Dafny.Sequence.FromElements(); - while ((_104_i) < (new BigInteger((_103_generatedValues).Count))) { - RAST._IExpr _112_genKey; - _112_genKey = ((_103_generatedValues).Select(_104_i)).dtor__0; - RAST._IExpr _113_genValue; - _113_genValue = ((_103_generatedValues).Select(_104_i)).dtor__1; - _111_arguments = Dafny.Sequence.Concat(_111_arguments, Dafny.Sequence.FromElements(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=>"), _112_genKey, _113_genValue, DAST.Format.BinaryOpFormat.create_NoFormat()))); - _104_i = (_104_i) + (BigInteger.One); - } - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("map!"))).AsExpr()).Apply(_111_arguments); - RAST._IExpr _out96; - Defs._IOwnership _out97; - (this).FromOwned(r, expectedOwnership, out _out96, out _out97); - r = _out96; - resultingOwnership = _out97; + (this).GenExpr(((_102_mapElems).Select(_106_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); + _110_recursiveGenValue = _out93; + _111___v89 = _out94; + _112_recIdentsValue = _out95; + _105_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_105_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_107_recursiveGenKey, _110_recursiveGenValue))); + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _109_recIdentsKey), _112_recIdentsValue); + } + Dafny.ISequence _113_arguments; + _113_arguments = Dafny.Sequence.FromElements(); + BigInteger _hi8 = new BigInteger((_105_generatedValues).Count); + for (BigInteger _114_i = BigInteger.Zero; _114_i < _hi8; _114_i++) { + RAST._IExpr _115_genKey; + _115_genKey = ((_105_generatedValues).Select(_114_i)).dtor__0; + RAST._IExpr _116_genValue; + _116_genValue = ((_105_generatedValues).Select(_114_i)).dtor__1; + _113_arguments = Dafny.Sequence.Concat(_113_arguments, Dafny.Sequence.FromElements(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=>"), _115_genKey, _116_genValue, DAST.Format.BinaryOpFormat.create_NoFormat()))); + } + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("map!"))).AsExpr()).Apply(_113_arguments); + if ((new BigInteger((_105_generatedValues).Count)).Sign == 0) { + RAST._IType _117_rangeTpe; + RAST._IType _out96; + _out96 = (this).GenType(_103_rangeType, Defs.GenTypeContext.@default()); + _117_rangeTpe = _out96; + RAST._IType _118_domainTpe; + RAST._IType _out97; + _out97 = (this).GenType(_104_domainType, Defs.GenTypeContext.@default()); + _118_domainTpe = _out97; + r = RAST.Expr.create_TypeAscription(r, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Map"))).AsType()).Apply(Dafny.Sequence.FromElements(_117_rangeTpe, _118_domainTpe))); + } + RAST._IExpr _out98; + Defs._IOwnership _out99; + (this).FromOwned(r, expectedOwnership, out _out98, out _out99); + r = _out98; + resultingOwnership = _out99; return ; } goto after_match0; @@ -5168,47 +5463,49 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SeqUpdate) { - DAST._IExpression _114_expr = _source0.dtor_expr; - DAST._IExpression _115_index = _source0.dtor_indexExpr; - DAST._IExpression _116_value = _source0.dtor_value; + DAST._IExpression _119_expr = _source0.dtor_expr; + DAST._IExpression _120_index = _source0.dtor_indexExpr; + DAST._IExpression _121_value = _source0.dtor_value; + DAST._IType _122_collectionType = _source0.dtor_collectionType; + DAST._IType _123_exprType = _source0.dtor_exprType; { - RAST._IExpr _117_exprR; - Defs._IOwnership _118___v103; - Dafny.ISet> _119_exprIdents; - RAST._IExpr _out98; - Defs._IOwnership _out99; - Dafny.ISet> _out100; - (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); - _117_exprR = _out98; - _118___v103 = _out99; - _119_exprIdents = _out100; - RAST._IExpr _120_indexR; - Defs._IOwnership _121_indexOwnership; - Dafny.ISet> _122_indexIdents; - RAST._IExpr _out101; - Defs._IOwnership _out102; - Dafny.ISet> _out103; - (this).GenExpr(_115_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out101, out _out102, out _out103); - _120_indexR = _out101; - _121_indexOwnership = _out102; - _122_indexIdents = _out103; - RAST._IExpr _123_valueR; - Defs._IOwnership _124_valueOwnership; - Dafny.ISet> _125_valueIdents; - RAST._IExpr _out104; - Defs._IOwnership _out105; - Dafny.ISet> _out106; - (this).GenExpr(_116_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out104, out _out105, out _out106); - _123_valueR = _out104; - _124_valueOwnership = _out105; - _125_valueIdents = _out106; - r = ((_117_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_120_indexR, _123_valueR)); - RAST._IExpr _out107; - Defs._IOwnership _out108; - (this).FromOwned(r, expectedOwnership, out _out107, out _out108); - r = _out107; - resultingOwnership = _out108; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_119_exprIdents, _122_indexIdents), _125_valueIdents); + RAST._IExpr _124_exprR; + Defs._IOwnership _125___v90; + Dafny.ISet> _126_exprIdents; + RAST._IExpr _out100; + Defs._IOwnership _out101; + Dafny.ISet> _out102; + (this).GenExpr(_119_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out100, out _out101, out _out102); + _124_exprR = _out100; + _125___v90 = _out101; + _126_exprIdents = _out102; + RAST._IExpr _127_indexR; + Defs._IOwnership _128_indexOwnership; + Dafny.ISet> _129_indexIdents; + RAST._IExpr _out103; + Defs._IOwnership _out104; + Dafny.ISet> _out105; + (this).GenExpr(_120_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out103, out _out104, out _out105); + _127_indexR = _out103; + _128_indexOwnership = _out104; + _129_indexIdents = _out105; + RAST._IExpr _130_valueR; + Defs._IOwnership _131_valueOwnership; + Dafny.ISet> _132_valueIdents; + RAST._IExpr _out106; + Defs._IOwnership _out107; + Dafny.ISet> _out108; + (this).GenExpr(_121_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out106, out _out107, out _out108); + _130_valueR = _out106; + _131_valueOwnership = _out107; + _132_valueIdents = _out108; + r = ((_124_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_127_indexR, _130_valueR)); + RAST._IExpr _out109; + Defs._IOwnership _out110; + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), _122_collectionType, _123_exprType, env, expectedOwnership, out _out109, out _out110); + r = _out109; + resultingOwnership = _out110; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_126_exprIdents, _129_indexIdents), _132_valueIdents); return ; } goto after_match0; @@ -5216,47 +5513,49 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapUpdate) { - DAST._IExpression _126_expr = _source0.dtor_expr; - DAST._IExpression _127_index = _source0.dtor_indexExpr; - DAST._IExpression _128_value = _source0.dtor_value; + DAST._IExpression _133_expr = _source0.dtor_expr; + DAST._IExpression _134_index = _source0.dtor_indexExpr; + DAST._IExpression _135_value = _source0.dtor_value; + DAST._IType _136_collectionType = _source0.dtor_collectionType; + DAST._IType _137_exprType = _source0.dtor_exprType; { - RAST._IExpr _129_exprR; - Defs._IOwnership _130___v104; - Dafny.ISet> _131_exprIdents; - RAST._IExpr _out109; - Defs._IOwnership _out110; - Dafny.ISet> _out111; - (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); - _129_exprR = _out109; - _130___v104 = _out110; - _131_exprIdents = _out111; - RAST._IExpr _132_indexR; - Defs._IOwnership _133_indexOwnership; - Dafny.ISet> _134_indexIdents; - RAST._IExpr _out112; - Defs._IOwnership _out113; - Dafny.ISet> _out114; - (this).GenExpr(_127_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out112, out _out113, out _out114); - _132_indexR = _out112; - _133_indexOwnership = _out113; - _134_indexIdents = _out114; - RAST._IExpr _135_valueR; - Defs._IOwnership _136_valueOwnership; - Dafny.ISet> _137_valueIdents; - RAST._IExpr _out115; - Defs._IOwnership _out116; - Dafny.ISet> _out117; - (this).GenExpr(_128_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out115, out _out116, out _out117); - _135_valueR = _out115; - _136_valueOwnership = _out116; - _137_valueIdents = _out117; - r = ((_129_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_132_indexR, _135_valueR)); - RAST._IExpr _out118; - Defs._IOwnership _out119; - (this).FromOwned(r, expectedOwnership, out _out118, out _out119); - r = _out118; - resultingOwnership = _out119; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_131_exprIdents, _134_indexIdents), _137_valueIdents); + RAST._IExpr _138_exprR; + Defs._IOwnership _139___v91; + Dafny.ISet> _140_exprIdents; + RAST._IExpr _out111; + Defs._IOwnership _out112; + Dafny.ISet> _out113; + (this).GenExpr(_133_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out111, out _out112, out _out113); + _138_exprR = _out111; + _139___v91 = _out112; + _140_exprIdents = _out113; + RAST._IExpr _141_indexR; + Defs._IOwnership _142_indexOwnership; + Dafny.ISet> _143_indexIdents; + RAST._IExpr _out114; + Defs._IOwnership _out115; + Dafny.ISet> _out116; + (this).GenExpr(_134_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out114, out _out115, out _out116); + _141_indexR = _out114; + _142_indexOwnership = _out115; + _143_indexIdents = _out116; + RAST._IExpr _144_valueR; + Defs._IOwnership _145_valueOwnership; + Dafny.ISet> _146_valueIdents; + RAST._IExpr _out117; + Defs._IOwnership _out118; + Dafny.ISet> _out119; + (this).GenExpr(_135_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out117, out _out118, out _out119); + _144_valueR = _out117; + _145_valueOwnership = _out118; + _146_valueIdents = _out119; + r = ((_138_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_141_indexR, _144_valueR)); + RAST._IExpr _out120; + Defs._IOwnership _out121; + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), _136_collectionType, _137_exprType, env, expectedOwnership, out _out120, out _out121); + r = _out120; + resultingOwnership = _out121; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_140_exprIdents, _143_indexIdents), _146_valueIdents); return ; } goto after_match0; @@ -5268,31 +5567,32 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Defs._ISelfInfo _source1 = selfIdent; { if (_source1.is_ThisTyped) { - Dafny.ISequence _138_id = _source1.dtor_rSelfName; - DAST._IType _139_dafnyType = _source1.dtor_dafnyType; + Dafny.ISequence _147_id = _source1.dtor_rSelfName; + DAST._IType _148_dafnyType = _source1.dtor_dafnyType; { - RAST._IExpr _out120; - Defs._IOwnership _out121; - Dafny.ISet> _out122; - (this).GenIdent(_138_id, selfIdent, env, expectedOwnership, out _out120, out _out121, out _out122); - r = _out120; - resultingOwnership = _out121; - readIdents = _out122; + RAST._IExpr _out122; + Defs._IOwnership _out123; + Dafny.ISet> _out124; + (this).GenIdent(_147_id, selfIdent, env, expectedOwnership, out _out122, out _out123, out _out124); + r = _out122; + resultingOwnership = _out123; + readIdents = _out124; + return ; } goto after_match1; } } { - Defs._ISelfInfo _140_None = _source1; + Defs._ISelfInfo _149_None = _source1; { - RAST._IExpr _out123; - _out123 = (this).Error(Dafny.Sequence.UnicodeFromString("this outside of a method"), (this).InitEmptyExpr()); - r = _out123; - RAST._IExpr _out124; - Defs._IOwnership _out125; - (this).FromOwned(r, expectedOwnership, out _out124, out _out125); - r = _out124; - resultingOwnership = _out125; + RAST._IExpr _out125; + _out125 = (this).Error(Dafny.Sequence.UnicodeFromString("this outside of a method"), (this).InitEmptyExpr()); + r = _out125; + RAST._IExpr _out126; + Defs._IOwnership _out127; + (this).FromOwned(r, expectedOwnership, out _out126, out _out127); + r = _out126; + resultingOwnership = _out127; readIdents = Dafny.Set>.FromElements(); } } @@ -5304,47 +5604,47 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Ite) { - DAST._IExpression _141_cond = _source0.dtor_cond; - DAST._IExpression _142_t = _source0.dtor_thn; - DAST._IExpression _143_f = _source0.dtor_els; + DAST._IExpression _150_cond = _source0.dtor_cond; + DAST._IExpression _151_t = _source0.dtor_thn; + DAST._IExpression _152_f = _source0.dtor_els; { - RAST._IExpr _144_cond; - Defs._IOwnership _145___v105; - Dafny.ISet> _146_recIdentsCond; - RAST._IExpr _out126; - Defs._IOwnership _out127; - Dafny.ISet> _out128; - (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); - _144_cond = _out126; - _145___v105 = _out127; - _146_recIdentsCond = _out128; - RAST._IExpr _147_fExpr; - Defs._IOwnership _148_fOwned; - Dafny.ISet> _149_recIdentsF; - RAST._IExpr _out129; - Defs._IOwnership _out130; - Dafny.ISet> _out131; - (this).GenExpr(_143_f, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out129, out _out130, out _out131); - _147_fExpr = _out129; - _148_fOwned = _out130; - _149_recIdentsF = _out131; - RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v106; - Dafny.ISet> _152_recIdentsT; - RAST._IExpr _out132; - Defs._IOwnership _out133; - Dafny.ISet> _out134; - (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); - _150_tExpr = _out132; - _151___v106 = _out133; - _152_recIdentsT = _out134; - r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); - RAST._IExpr _out135; - Defs._IOwnership _out136; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out135, out _out136); - r = _out135; - resultingOwnership = _out136; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_146_recIdentsCond, _152_recIdentsT), _149_recIdentsF); + RAST._IExpr _153_cond; + Defs._IOwnership _154___v92; + Dafny.ISet> _155_recIdentsCond; + RAST._IExpr _out128; + Defs._IOwnership _out129; + Dafny.ISet> _out130; + (this).GenExpr(_150_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out128, out _out129, out _out130); + _153_cond = _out128; + _154___v92 = _out129; + _155_recIdentsCond = _out130; + RAST._IExpr _156_fExpr; + Defs._IOwnership _157_fOwned; + Dafny.ISet> _158_recIdentsF; + RAST._IExpr _out131; + Defs._IOwnership _out132; + Dafny.ISet> _out133; + (this).GenExpr(_152_f, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out131, out _out132, out _out133); + _156_fExpr = _out131; + _157_fOwned = _out132; + _158_recIdentsF = _out133; + RAST._IExpr _159_tExpr; + Defs._IOwnership _160___v93; + Dafny.ISet> _161_recIdentsT; + RAST._IExpr _out134; + Defs._IOwnership _out135; + Dafny.ISet> _out136; + (this).GenExpr(_151_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out134, out _out135, out _out136); + _159_tExpr = _out134; + _160___v93 = _out135; + _161_recIdentsT = _out136; + r = RAST.Expr.create_IfExpr(_153_cond, _159_tExpr, _156_fExpr); + RAST._IExpr _out137; + Defs._IOwnership _out138; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out137, out _out138); + r = _out137; + resultingOwnership = _out138; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_155_recIdentsCond, _161_recIdentsT), _158_recIdentsF); return ; } goto after_match0; @@ -5354,26 +5654,26 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_UnOp) { DAST._IUnaryOp unOp0 = _source0.dtor_unOp; if (unOp0.is_Not) { - DAST._IExpression _153_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; + DAST._IExpression _162_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _163_format = _source0.dtor_format1; { - RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v107; - Dafny.ISet> _157_recIdents; - RAST._IExpr _out137; - Defs._IOwnership _out138; - Dafny.ISet> _out139; - (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); - _155_recursiveGen = _out137; - _156___v107 = _out138; - _157_recIdents = _out139; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); - RAST._IExpr _out140; - Defs._IOwnership _out141; - (this).FromOwned(r, expectedOwnership, out _out140, out _out141); - r = _out140; - resultingOwnership = _out141; - readIdents = _157_recIdents; + RAST._IExpr _164_recursiveGen; + Defs._IOwnership _165___v94; + Dafny.ISet> _166_recIdents; + RAST._IExpr _out139; + Defs._IOwnership _out140; + Dafny.ISet> _out141; + (this).GenExpr(_162_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out139, out _out140, out _out141); + _164_recursiveGen = _out139; + _165___v94 = _out140; + _166_recIdents = _out141; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _164_recursiveGen, _163_format); + RAST._IExpr _out142; + Defs._IOwnership _out143; + (this).FromOwned(r, expectedOwnership, out _out142, out _out143); + r = _out142; + resultingOwnership = _out143; + readIdents = _166_recIdents; return ; } goto after_match0; @@ -5384,26 +5684,26 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_UnOp) { DAST._IUnaryOp unOp1 = _source0.dtor_unOp; if (unOp1.is_BitwiseNot) { - DAST._IExpression _158_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; + DAST._IExpression _167_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _168_format = _source0.dtor_format1; { - RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v108; - Dafny.ISet> _162_recIdents; - RAST._IExpr _out142; - Defs._IOwnership _out143; - Dafny.ISet> _out144; - (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); - _160_recursiveGen = _out142; - _161___v108 = _out143; - _162_recIdents = _out144; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); - RAST._IExpr _out145; - Defs._IOwnership _out146; - (this).FromOwned(r, expectedOwnership, out _out145, out _out146); - r = _out145; - resultingOwnership = _out146; - readIdents = _162_recIdents; + RAST._IExpr _169_recursiveGen; + Defs._IOwnership _170___v95; + Dafny.ISet> _171_recIdents; + RAST._IExpr _out144; + Defs._IOwnership _out145; + Dafny.ISet> _out146; + (this).GenExpr(_167_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out144, out _out145, out _out146); + _169_recursiveGen = _out144; + _170___v95 = _out145; + _171_recIdents = _out146; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _169_recursiveGen, _168_format); + RAST._IExpr _out147; + Defs._IOwnership _out148; + (this).FromOwned(r, expectedOwnership, out _out147, out _out148); + r = _out147; + resultingOwnership = _out148; + readIdents = _171_recIdents; return ; } goto after_match0; @@ -5414,26 +5714,26 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_UnOp) { DAST._IUnaryOp unOp2 = _source0.dtor_unOp; if (unOp2.is_Cardinality) { - DAST._IExpression _163_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _164_format = _source0.dtor_format1; + DAST._IExpression _172_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _173_format = _source0.dtor_format1; { - RAST._IExpr _165_recursiveGen; - Defs._IOwnership _166_recOwned; - Dafny.ISet> _167_recIdents; - RAST._IExpr _out147; - Defs._IOwnership _out148; - Dafny.ISet> _out149; - (this).GenExpr(_163_e, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out147, out _out148, out _out149); - _165_recursiveGen = _out147; - _166_recOwned = _out148; - _167_recIdents = _out149; - r = ((_165_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply0(); - RAST._IExpr _out150; - Defs._IOwnership _out151; - (this).FromOwned(r, expectedOwnership, out _out150, out _out151); - r = _out150; - resultingOwnership = _out151; - readIdents = _167_recIdents; + RAST._IExpr _174_recursiveGen; + Defs._IOwnership _175_recOwned; + Dafny.ISet> _176_recIdents; + RAST._IExpr _out149; + Defs._IOwnership _out150; + Dafny.ISet> _out151; + (this).GenExpr(_172_e, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out149, out _out150, out _out151); + _174_recursiveGen = _out149; + _175_recOwned = _out150; + _176_recIdents = _out151; + r = ((_174_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply0(); + RAST._IExpr _out152; + Defs._IOwnership _out153; + (this).FromOwned(r, expectedOwnership, out _out152, out _out153); + r = _out152; + resultingOwnership = _out153; + readIdents = _176_recIdents; return ; } goto after_match0; @@ -5442,63 +5742,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_BinOp) { - RAST._IExpr _out152; - Defs._IOwnership _out153; - Dafny.ISet> _out154; - (this).GenExprBinary(e, selfIdent, env, expectedOwnership, out _out152, out _out153, out _out154); - r = _out152; - resultingOwnership = _out153; - readIdents = _out154; + RAST._IExpr _out154; + Defs._IOwnership _out155; + Dafny.ISet> _out156; + (this).GenExprBinary(e, selfIdent, env, expectedOwnership, out _out154, out _out155, out _out156); + r = _out154; + resultingOwnership = _out155; + readIdents = _out156; goto after_match0; } } { if (_source0.is_ArrayLen) { - DAST._IExpression _168_expr = _source0.dtor_expr; - DAST._IType _169_exprType = _source0.dtor_exprType; - BigInteger _170_dim = _source0.dtor_dim; - bool _171_native = _source0.dtor_native; + DAST._IExpression _177_expr = _source0.dtor_expr; + DAST._IType _178_exprType = _source0.dtor_exprType; + BigInteger _179_dim = _source0.dtor_dim; + bool _180_native = _source0.dtor_native; { - RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v113; - Dafny.ISet> _174_recIdents; - RAST._IExpr _out155; - Defs._IOwnership _out156; - Dafny.ISet> _out157; - (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); - _172_recursiveGen = _out155; - _173___v113 = _out156; - _174_recIdents = _out157; - RAST._IType _175_arrayType; - RAST._IType _out158; - _out158 = (this).GenType(_169_exprType, Defs.GenTypeContext.@default()); - _175_arrayType = _out158; - if (!((_175_arrayType).IsObjectOrPointer())) { - RAST._IExpr _out159; - _out159 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array length of something not an array but "), (_175_arrayType)._ToString(Defs.__default.IND)), (this).InitEmptyExpr()); - r = _out159; + RAST._IExpr _181_recursiveGen; + Defs._IOwnership _182___v100; + Dafny.ISet> _183_recIdents; + RAST._IExpr _out157; + Defs._IOwnership _out158; + Dafny.ISet> _out159; + (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out157, out _out158, out _out159); + _181_recursiveGen = _out157; + _182___v100 = _out158; + _183_recIdents = _out159; + RAST._IType _184_arrayType; + RAST._IType _out160; + _out160 = (this).GenType(_178_exprType, Defs.GenTypeContext.@default()); + _184_arrayType = _out160; + if (!((_184_arrayType).IsObjectOrPointer())) { + RAST._IExpr _out161; + _out161 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array length of something not an array but "), (_184_arrayType)._ToString(Defs.__default.IND)), (this).InitEmptyExpr()); + r = _out161; } else { - RAST._IType _176_underlying; - _176_underlying = (_175_arrayType).ObjectOrPointerUnderlying(); - if (((_170_dim).Sign == 0) && ((_176_underlying).is_Array)) { - r = ((((this).read__macro).Apply1(_172_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); + RAST._IType _185_underlying; + _185_underlying = (_184_arrayType).ObjectOrPointerUnderlying(); + if (((_179_dim).Sign == 0) && ((_185_underlying).is_Array)) { + r = ((((this).read__macro).Apply1(_181_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); } else { - if ((_170_dim).Sign == 0) { - r = (((((this).read__macro).Apply1(_172_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("data"))).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); + if ((_179_dim).Sign == 0) { + r = (((((this).read__macro).Apply1(_181_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("data"))).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); } else { - r = ((((this).read__macro).Apply1(_172_recursiveGen)).Sel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("length"), Std.Strings.__default.OfNat(_170_dim)), Dafny.Sequence.UnicodeFromString("_usize")))).Apply0(); + r = ((((this).read__macro).Apply1(_181_recursiveGen)).Sel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("length"), Std.Strings.__default.OfNat(_179_dim)), Dafny.Sequence.UnicodeFromString("_usize")))).Apply0(); } } - if (!(_171_native)) { + if (!(_180_native)) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(r); } } - RAST._IExpr _out160; - Defs._IOwnership _out161; - (this).FromOwned(r, expectedOwnership, out _out160, out _out161); - r = _out160; - resultingOwnership = _out161; - readIdents = _174_recIdents; + RAST._IExpr _out162; + Defs._IOwnership _out163; + (this).FromOwned(r, expectedOwnership, out _out162, out _out163); + r = _out162; + resultingOwnership = _out163; + readIdents = _183_recIdents; return ; } goto after_match0; @@ -5506,25 +5806,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapKeys) { - DAST._IExpression _177_expr = _source0.dtor_expr; + DAST._IExpression _186_expr = _source0.dtor_expr; { - RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v114; - Dafny.ISet> _180_recIdents; - RAST._IExpr _out162; - Defs._IOwnership _out163; - Dafny.ISet> _out164; - (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); - _178_recursiveGen = _out162; - _179___v114 = _out163; - _180_recIdents = _out164; - readIdents = _180_recIdents; - r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); - RAST._IExpr _out165; - Defs._IOwnership _out166; - (this).FromOwned(r, expectedOwnership, out _out165, out _out166); - r = _out165; - resultingOwnership = _out166; + RAST._IExpr _187_recursiveGen; + Defs._IOwnership _188___v101; + Dafny.ISet> _189_recIdents; + RAST._IExpr _out164; + Defs._IOwnership _out165; + Dafny.ISet> _out166; + (this).GenExpr(_186_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out164, out _out165, out _out166); + _187_recursiveGen = _out164; + _188___v101 = _out165; + _189_recIdents = _out166; + readIdents = _189_recIdents; + r = ((_187_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); + RAST._IExpr _out167; + Defs._IOwnership _out168; + (this).FromOwned(r, expectedOwnership, out _out167, out _out168); + r = _out167; + resultingOwnership = _out168; return ; } goto after_match0; @@ -5532,25 +5832,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapValues) { - DAST._IExpression _181_expr = _source0.dtor_expr; + DAST._IExpression _190_expr = _source0.dtor_expr; { - RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v115; - Dafny.ISet> _184_recIdents; - RAST._IExpr _out167; - Defs._IOwnership _out168; - Dafny.ISet> _out169; - (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); - _182_recursiveGen = _out167; - _183___v115 = _out168; - _184_recIdents = _out169; - readIdents = _184_recIdents; - r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); - RAST._IExpr _out170; - Defs._IOwnership _out171; - (this).FromOwned(r, expectedOwnership, out _out170, out _out171); - r = _out170; - resultingOwnership = _out171; + RAST._IExpr _191_recursiveGen; + Defs._IOwnership _192___v102; + Dafny.ISet> _193_recIdents; + RAST._IExpr _out169; + Defs._IOwnership _out170; + Dafny.ISet> _out171; + (this).GenExpr(_190_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out169, out _out170, out _out171); + _191_recursiveGen = _out169; + _192___v102 = _out170; + _193_recIdents = _out171; + readIdents = _193_recIdents; + r = ((_191_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); + RAST._IExpr _out172; + Defs._IOwnership _out173; + (this).FromOwned(r, expectedOwnership, out _out172, out _out173); + r = _out172; + resultingOwnership = _out173; return ; } goto after_match0; @@ -5558,25 +5858,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapItems) { - DAST._IExpression _185_expr = _source0.dtor_expr; + DAST._IExpression _194_expr = _source0.dtor_expr; { - RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v116; - Dafny.ISet> _188_recIdents; - RAST._IExpr _out172; - Defs._IOwnership _out173; - Dafny.ISet> _out174; - (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); - _186_recursiveGen = _out172; - _187___v116 = _out173; - _188_recIdents = _out174; - readIdents = _188_recIdents; - r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); - RAST._IExpr _out175; - Defs._IOwnership _out176; - (this).FromOwned(r, expectedOwnership, out _out175, out _out176); - r = _out175; - resultingOwnership = _out176; + RAST._IExpr _195_recursiveGen; + Defs._IOwnership _196___v103; + Dafny.ISet> _197_recIdents; + RAST._IExpr _out174; + Defs._IOwnership _out175; + Dafny.ISet> _out176; + (this).GenExpr(_194_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out174, out _out175, out _out176); + _195_recursiveGen = _out174; + _196___v103 = _out175; + _197_recIdents = _out176; + readIdents = _197_recIdents; + r = ((_195_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); + RAST._IExpr _out177; + Defs._IOwnership _out178; + (this).FromOwned(r, expectedOwnership, out _out177, out _out178); + r = _out177; + resultingOwnership = _out178; return ; } goto after_match0; @@ -5584,105 +5884,105 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SelectFn) { - DAST._IExpression _189_on = _source0.dtor_expr; - Dafny.ISequence _190_field = _source0.dtor_field; - bool _191_isDatatype = _source0.dtor_onDatatype; - bool _192_isStatic = _source0.dtor_isStatic; - bool _193_isConstant = _source0.dtor_isConstant; - Dafny.ISequence _194_arguments = _source0.dtor_arguments; + DAST._IExpression _198_on = _source0.dtor_expr; + Dafny.ISequence _199_field = _source0.dtor_field; + bool _200_isDatatype = _source0.dtor_onDatatype; + bool _201_isStatic = _source0.dtor_isStatic; + bool _202_isConstant = _source0.dtor_isConstant; + Dafny.ISequence _203_arguments = _source0.dtor_arguments; { - RAST._IExpr _195_onExpr; - Defs._IOwnership _196_onOwned; - Dafny.ISet> _197_recIdents; - RAST._IExpr _out177; - Defs._IOwnership _out178; - Dafny.ISet> _out179; - (this).GenExpr(_189_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out177, out _out178, out _out179); - _195_onExpr = _out177; - _196_onOwned = _out178; - _197_recIdents = _out179; - Defs._IEnvironment _198_lEnv; - _198_lEnv = env; - Dafny.ISequence<_System._ITuple2, RAST._IType>> _199_args; - _199_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(); - Dafny.ISequence _200_parameters; - _200_parameters = Dafny.Sequence.FromElements(); - BigInteger _hi7 = new BigInteger((_194_arguments).Count); - for (BigInteger _201_i = BigInteger.Zero; _201_i < _hi7; _201_i++) { - RAST._IType _202_ty; - RAST._IType _out180; - _out180 = (this).GenType((_194_arguments).Select(_201_i), Defs.GenTypeContext.@default()); - _202_ty = _out180; - RAST._IType _203_bTy; - _203_bTy = RAST.Type.create_Borrowed(_202_ty); - Dafny.ISequence _204_name; - _204_name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("x"), Std.Strings.__default.OfInt(_201_i)); - _198_lEnv = (_198_lEnv).AddAssigned(_204_name, _203_bTy); - _200_parameters = Dafny.Sequence.Concat(_200_parameters, Dafny.Sequence.FromElements(RAST.Formal.create(_204_name, _203_bTy))); - _199_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.Concat(_199_args, Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(_System.Tuple2, RAST._IType>.create(_204_name, _202_ty))); - } - RAST._IExpr _205_body = RAST.Expr.Default(); - if (_192_isStatic) { - _205_body = (_195_onExpr).FSel(Defs.__default.escapeVar(_190_field)); + RAST._IExpr _204_onExpr; + Defs._IOwnership _205_onOwned; + Dafny.ISet> _206_recIdents; + RAST._IExpr _out179; + Defs._IOwnership _out180; + Dafny.ISet> _out181; + (this).GenExpr(_198_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out179, out _out180, out _out181); + _204_onExpr = _out179; + _205_onOwned = _out180; + _206_recIdents = _out181; + Defs._IEnvironment _207_lEnv; + _207_lEnv = env; + Dafny.ISequence<_System._ITuple2, RAST._IType>> _208_args; + _208_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(); + Dafny.ISequence _209_parameters; + _209_parameters = Dafny.Sequence.FromElements(); + BigInteger _hi9 = new BigInteger((_203_arguments).Count); + for (BigInteger _210_i = BigInteger.Zero; _210_i < _hi9; _210_i++) { + RAST._IType _211_ty; + RAST._IType _out182; + _out182 = (this).GenType((_203_arguments).Select(_210_i), Defs.GenTypeContext.@default()); + _211_ty = _out182; + RAST._IType _212_bTy; + _212_bTy = RAST.Type.create_Borrowed(_211_ty); + Dafny.ISequence _213_name; + _213_name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("x"), Std.Strings.__default.OfInt(_210_i)); + _207_lEnv = (_207_lEnv).AddAssigned(_213_name, _212_bTy); + _209_parameters = Dafny.Sequence.Concat(_209_parameters, Dafny.Sequence.FromElements(RAST.Formal.create(_213_name, _212_bTy))); + _208_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.Concat(_208_args, Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(_System.Tuple2, RAST._IType>.create(_213_name, _211_ty))); + } + RAST._IExpr _214_body = RAST.Expr.Default(); + if (_201_isStatic) { + _214_body = (_204_onExpr).FSel(Defs.__default.escapeVar(_199_field)); } else { - _205_body = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("callTarget")); - if (!(_191_isDatatype)) { - _205_body = ((this).read__macro).Apply1(_205_body); + _214_body = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("callTarget")); + if (!(_200_isDatatype)) { + _214_body = ((this).read__macro).Apply1(_214_body); } - _205_body = (_205_body).Sel(Defs.__default.escapeVar(_190_field)); - } - if (_193_isConstant) { - _205_body = (_205_body).Apply0(); - } - Dafny.ISequence _206_onExprArgs; - _206_onExprArgs = Dafny.Sequence.FromElements(); - BigInteger _hi8 = new BigInteger((_199_args).Count); - for (BigInteger _207_i = BigInteger.Zero; _207_i < _hi8; _207_i++) { - _System._ITuple2, RAST._IType> _let_tmp_rhs1 = (_199_args).Select(_207_i); - Dafny.ISequence _208_name = _let_tmp_rhs1.dtor__0; - RAST._IType _209_ty = _let_tmp_rhs1.dtor__1; - RAST._IExpr _210_rIdent; - Defs._IOwnership _211___v117; - Dafny.ISet> _212___v118; - RAST._IExpr _out181; - Defs._IOwnership _out182; - Dafny.ISet> _out183; - (this).GenIdent(_208_name, selfIdent, _198_lEnv, (((!(_193_isConstant)) && ((_209_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); - _210_rIdent = _out181; - _211___v117 = _out182; - _212___v118 = _out183; - _206_onExprArgs = Dafny.Sequence.Concat(_206_onExprArgs, Dafny.Sequence.FromElements(_210_rIdent)); - } - _205_body = (_205_body).Apply(_206_onExprArgs); - r = RAST.Expr.create_Lambda(_200_parameters, Std.Wrappers.Option.create_None(), _205_body); - if (_192_isStatic) { + _214_body = (_214_body).Sel(Defs.__default.escapeVar(_199_field)); + } + if (_202_isConstant) { + _214_body = (_214_body).Apply0(); + } + Dafny.ISequence _215_onExprArgs; + _215_onExprArgs = Dafny.Sequence.FromElements(); + BigInteger _hi10 = new BigInteger((_208_args).Count); + for (BigInteger _216_i = BigInteger.Zero; _216_i < _hi10; _216_i++) { + _System._ITuple2, RAST._IType> _let_tmp_rhs1 = (_208_args).Select(_216_i); + Dafny.ISequence _217_name = _let_tmp_rhs1.dtor__0; + RAST._IType _218_ty = _let_tmp_rhs1.dtor__1; + RAST._IExpr _219_rIdent; + Defs._IOwnership _220___v104; + Dafny.ISet> _221___v105; + RAST._IExpr _out183; + Defs._IOwnership _out184; + Dafny.ISet> _out185; + (this).GenIdent(_217_name, selfIdent, _207_lEnv, (((!(_202_isConstant)) && ((_218_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out183, out _out184, out _out185); + _219_rIdent = _out183; + _220___v104 = _out184; + _221___v105 = _out185; + _215_onExprArgs = Dafny.Sequence.Concat(_215_onExprArgs, Dafny.Sequence.FromElements(_219_rIdent)); + } + _214_body = (_214_body).Apply(_215_onExprArgs); + r = RAST.Expr.create_Lambda(_209_parameters, Std.Wrappers.Option.create_None(), _214_body); + if (_201_isStatic) { } else { - RAST._IExpr _213_target; - if (object.Equals(_196_onOwned, Defs.Ownership.create_OwnershipOwned())) { - _213_target = _195_onExpr; + RAST._IExpr _222_target; + if (object.Equals(_205_onOwned, Defs.Ownership.create_OwnershipOwned())) { + _222_target = _204_onExpr; } else { - _213_target = (_195_onExpr).Clone(); + _222_target = (_204_onExpr).Clone(); } - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("callTarget"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_213_target))).Then(r)); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("callTarget"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_222_target))).Then(r)); } - Dafny.ISequence _214_typeShapeArgs; - _214_typeShapeArgs = Dafny.Sequence.FromElements(); - BigInteger _hi9 = new BigInteger((_194_arguments).Count); - for (BigInteger _215_i = BigInteger.Zero; _215_i < _hi9; _215_i++) { - _214_typeShapeArgs = Dafny.Sequence.Concat(_214_typeShapeArgs, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))); + Dafny.ISequence _223_typeShapeArgs; + _223_typeShapeArgs = Dafny.Sequence.FromElements(); + BigInteger _hi11 = new BigInteger((_203_arguments).Count); + for (BigInteger _224_i = BigInteger.Zero; _224_i < _hi11; _224_i++) { + _223_typeShapeArgs = Dafny.Sequence.Concat(_223_typeShapeArgs, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))); } - RAST._IType _216_typeShape; - _216_typeShape = RAST.Type.create_DynType(RAST.Type.create_FnType(_214_typeShapeArgs, RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_")))); + RAST._IType _225_typeShape; + _225_typeShape = RAST.Type.create_DynType(RAST.Type.create_FnType(_223_typeShapeArgs, RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_")))); if (((this).syncType).is_Sync) { - _216_typeShape = RAST.Type.create_IntersectionType(_216_typeShape, (this).SyncSendType); - } - r = RAST.Expr.create_TypeAscription(Dafny.Helpers.Id>((this).rcNew)(r), Dafny.Helpers.Id>((this).rc)(_216_typeShape)); - RAST._IExpr _out184; - Defs._IOwnership _out185; - (this).FromOwned(r, expectedOwnership, out _out184, out _out185); - r = _out184; - resultingOwnership = _out185; - readIdents = _197_recIdents; + _225_typeShape = RAST.Type.create_IntersectionType(_225_typeShape, (this).SyncSendType); + } + r = RAST.Expr.create_TypeAscription(Dafny.Helpers.Id>((this).rcNew)(r), Dafny.Helpers.Id>((this).rc)(_225_typeShape)); + RAST._IExpr _out186; + Defs._IOwnership _out187; + (this).FromOwned(r, expectedOwnership, out _out186, out _out187); + r = _out186; + resultingOwnership = _out187; + readIdents = _206_recIdents; return ; } goto after_match0; @@ -5690,46 +5990,46 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Select) { - DAST._IExpression _217_on = _source0.dtor_expr; - Dafny.ISequence _218_field = _source0.dtor_field; - DAST._IFieldMutability _219_fieldMutability = _source0.dtor_fieldMutability; - bool _220_isDatatype = _source0.dtor_isDatatype; - DAST._IType _221_fieldType = _source0.dtor_fieldType; + DAST._IExpression _226_on = _source0.dtor_expr; + Dafny.ISequence _227_field = _source0.dtor_field; + DAST._IFieldMutability _228_fieldMutability = _source0.dtor_fieldMutability; + DAST._ISelectContext _229_selectContext = _source0.dtor_selectContext; + DAST._IType _230_fieldType = _source0.dtor_isfieldType; { - if (((_217_on).is_Companion) || ((_217_on).is_ExternCompanion)) { - RAST._IExpr _222_onExpr; - Defs._IOwnership _223_onOwned; - Dafny.ISet> _224_recIdents; - RAST._IExpr _out186; - Defs._IOwnership _out187; - Dafny.ISet> _out188; - (this).GenExpr(_217_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out186, out _out187, out _out188); - _222_onExpr = _out186; - _223_onOwned = _out187; - _224_recIdents = _out188; - r = ((_222_onExpr).FSel(Defs.__default.escapeVar(_218_field))).Apply0(); - RAST._IExpr _out189; - Defs._IOwnership _out190; - (this).FromOwned(r, expectedOwnership, out _out189, out _out190); - r = _out189; - resultingOwnership = _out190; - readIdents = _224_recIdents; - return ; - } else if (_220_isDatatype) { - RAST._IExpr _225_onExpr; - Defs._IOwnership _226_onOwned; - Dafny.ISet> _227_recIdents; + if (((_226_on).is_Companion) || ((_226_on).is_ExternCompanion)) { + RAST._IExpr _231_onExpr; + Defs._IOwnership _232_onOwned; + Dafny.ISet> _233_recIdents; + RAST._IExpr _out188; + Defs._IOwnership _out189; + Dafny.ISet> _out190; + (this).GenExpr(_226_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out188, out _out189, out _out190); + _231_onExpr = _out188; + _232_onOwned = _out189; + _233_recIdents = _out190; + r = ((_231_onExpr).FSel(Defs.__default.escapeVar(_227_field))).Apply0(); RAST._IExpr _out191; Defs._IOwnership _out192; - Dafny.ISet> _out193; - (this).GenExpr(_217_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out191, out _out192, out _out193); - _225_onExpr = _out191; - _226_onOwned = _out192; - _227_recIdents = _out193; - r = ((_225_onExpr).Sel(Defs.__default.escapeVar(_218_field))).Apply0(); - Defs._IOwnership _228_originalMutability; - _228_originalMutability = Defs.Ownership.create_OwnershipOwned(); - DAST._IFieldMutability _source2 = _219_fieldMutability; + (this).FromOwned(r, expectedOwnership, out _out191, out _out192); + r = _out191; + resultingOwnership = _out192; + readIdents = _233_recIdents; + return ; + } else if ((_229_selectContext).is_SelectContextDatatype) { + RAST._IExpr _234_onExpr; + Defs._IOwnership _235_onOwned; + Dafny.ISet> _236_recIdents; + RAST._IExpr _out193; + Defs._IOwnership _out194; + Dafny.ISet> _out195; + (this).GenExpr(_226_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out193, out _out194, out _out195); + _234_onExpr = _out193; + _235_onOwned = _out194; + _236_recIdents = _out195; + r = ((_234_onExpr).Sel(Defs.__default.escapeVar(_227_field))).Apply0(); + Defs._IOwnership _237_originalMutability; + _237_originalMutability = Defs.Ownership.create_OwnershipOwned(); + DAST._IFieldMutability _source2 = _228_fieldMutability; { if (_source2.is_ConstantField) { goto after_match2; @@ -5737,40 +6037,67 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source2.is_InternalClassConstantFieldOrDatatypeDestructor) { - _228_originalMutability = Defs.Ownership.create_OwnershipBorrowed(); + _237_originalMutability = Defs.Ownership.create_OwnershipBorrowed(); goto after_match2; } } { - RAST._IExpr _out194; - _out194 = (this).Error(Dafny.Sequence.UnicodeFromString("datatypes don't have mutable fields"), (this).InitEmptyExpr()); - r = _out194; + RAST._IExpr _out196; + _out196 = (this).Error(Dafny.Sequence.UnicodeFromString("datatypes don't have mutable fields"), (this).InitEmptyExpr()); + r = _out196; } after_match2: ; - RAST._IType _229_typ; - RAST._IType _out195; - _out195 = (this).GenType(_221_fieldType, Defs.GenTypeContext.@default()); - _229_typ = _out195; - RAST._IExpr _out196; - Defs._IOwnership _out197; - (this).FromOwnership(r, _228_originalMutability, expectedOwnership, out _out196, out _out197); - r = _out196; - resultingOwnership = _out197; - readIdents = _227_recIdents; - } else { - RAST._IExpr _230_onExpr; - Defs._IOwnership _231_onOwned; - Dafny.ISet> _232_recIdents; + RAST._IType _238_typ; + RAST._IType _out197; + _out197 = (this).GenType(_230_fieldType, Defs.GenTypeContext.@default()); + _238_typ = _out197; RAST._IExpr _out198; Defs._IOwnership _out199; - Dafny.ISet> _out200; - (this).GenExpr(_217_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out198, out _out199, out _out200); - _230_onExpr = _out198; - _231_onOwned = _out199; - _232_recIdents = _out200; - r = _230_onExpr; - if (!object.Equals(_230_onExpr, RAST.__default.self)) { - RAST._IExpr _source3 = _230_onExpr; + (this).FromOwnership(r, _237_originalMutability, expectedOwnership, out _out198, out _out199); + r = _out198; + resultingOwnership = _out199; + readIdents = _236_recIdents; + } else if ((_229_selectContext).is_SelectContextGeneralTrait) { + Defs._IOwnership _239_onOwned = Defs.Ownership.Default(); + Dafny.ISet> _240_recIdents = Dafny.Set>.Empty; + readIdents = Dafny.Set>.FromElements(); + if ((_226_on).IsThisUpcast()) { + r = RAST.__default.self; + _240_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); + } else { + RAST._IExpr _out200; + Defs._IOwnership _out201; + Dafny.ISet> _out202; + (this).GenExpr(_226_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out200, out _out201, out _out202); + r = _out200; + _239_onOwned = _out201; + _240_recIdents = _out202; + if (!object.Equals(r, RAST.__default.self)) { + r = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(r); + } + } + readIdents = Dafny.Set>.Union(readIdents, _240_recIdents); + r = ((r).Sel(Defs.__default.escapeVar(_227_field))).Apply0(); + RAST._IExpr _out203; + Defs._IOwnership _out204; + (this).FromOwned(r, expectedOwnership, out _out203, out _out204); + r = _out203; + resultingOwnership = _out204; + readIdents = _240_recIdents; + } else { + RAST._IExpr _241_onExpr; + Defs._IOwnership _242_onOwned; + Dafny.ISet> _243_recIdents; + RAST._IExpr _out205; + Defs._IOwnership _out206; + Dafny.ISet> _out207; + (this).GenExpr(_226_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out205, out _out206, out _out207); + _241_onExpr = _out205; + _242_onOwned = _out206; + _243_recIdents = _out207; + r = _241_onExpr; + if (!object.Equals(_241_onExpr, RAST.__default.self)) { + RAST._IExpr _source3 = _241_onExpr; { if (_source3.is_UnaryOp) { Dafny.ISequence op10 = _source3.dtor_op1; @@ -5794,8 +6121,8 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } r = ((this).read__macro).Apply1(r); } - r = (r).Sel(Defs.__default.escapeVar(_218_field)); - DAST._IFieldMutability _source4 = _219_fieldMutability; + r = (r).Sel(Defs.__default.escapeVar(_227_field)); + DAST._IFieldMutability _source4 = _228_fieldMutability; { if (_source4.is_ConstantField) { r = (r).Apply0(); @@ -5813,12 +6140,12 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir r = ((this).read__mutable__field__macro).Apply1(r); } after_match4: ; - RAST._IExpr _out201; - Defs._IOwnership _out202; - (this).FromOwned(r, expectedOwnership, out _out201, out _out202); - r = _out201; - resultingOwnership = _out202; - readIdents = _232_recIdents; + RAST._IExpr _out208; + Defs._IOwnership _out209; + (this).FromOwned(r, expectedOwnership, out _out208, out _out209); + r = _out208; + resultingOwnership = _out209; + readIdents = _243_recIdents; } return ; } @@ -5827,70 +6154,70 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Index) { - DAST._IExpression _233_on = _source0.dtor_expr; - DAST._ICollKind _234_collKind = _source0.dtor_collKind; - Dafny.ISequence _235_indices = _source0.dtor_indices; + DAST._IExpression _244_on = _source0.dtor_expr; + DAST._ICollKind _245_collKind = _source0.dtor_collKind; + Dafny.ISequence _246_indices = _source0.dtor_indices; { - RAST._IExpr _236_onExpr; - Defs._IOwnership _237_onOwned; - Dafny.ISet> _238_recIdents; - RAST._IExpr _out203; - Defs._IOwnership _out204; - Dafny.ISet> _out205; - (this).GenExpr(_233_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out203, out _out204, out _out205); - _236_onExpr = _out203; - _237_onOwned = _out204; - _238_recIdents = _out205; - readIdents = _238_recIdents; - r = _236_onExpr; - bool _239_hadArray; - _239_hadArray = false; - if (object.Equals(_234_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _247_onExpr; + Defs._IOwnership _248_onOwned; + Dafny.ISet> _249_recIdents; + RAST._IExpr _out210; + Defs._IOwnership _out211; + Dafny.ISet> _out212; + (this).GenExpr(_244_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out210, out _out211, out _out212); + _247_onExpr = _out210; + _248_onOwned = _out211; + _249_recIdents = _out212; + readIdents = _249_recIdents; + r = _247_onExpr; + bool _250_hadArray; + _250_hadArray = false; + if (object.Equals(_245_collKind, DAST.CollKind.create_Array())) { r = ((this).read__macro).Apply1(r); - _239_hadArray = true; - if ((new BigInteger((_235_indices).Count)) > (BigInteger.One)) { + _250_hadArray = true; + if ((new BigInteger((_246_indices).Count)) > (BigInteger.One)) { r = (r).Sel(Dafny.Sequence.UnicodeFromString("data")); } } - BigInteger _hi10 = new BigInteger((_235_indices).Count); - for (BigInteger _240_i = BigInteger.Zero; _240_i < _hi10; _240_i++) { - if (object.Equals(_234_collKind, DAST.CollKind.create_Array())) { - RAST._IExpr _241_idx; - Defs._IOwnership _242_idxOwned; - Dafny.ISet> _243_recIdentsIdx; - RAST._IExpr _out206; - Defs._IOwnership _out207; - Dafny.ISet> _out208; - (this).GenExpr((_235_indices).Select(_240_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out206, out _out207, out _out208); - _241_idx = _out206; - _242_idxOwned = _out207; - _243_recIdentsIdx = _out208; - _241_idx = RAST.__default.IntoUsize(_241_idx); - r = RAST.Expr.create_SelectIndex(r, _241_idx); - readIdents = Dafny.Set>.Union(readIdents, _243_recIdentsIdx); + BigInteger _hi12 = new BigInteger((_246_indices).Count); + for (BigInteger _251_i = BigInteger.Zero; _251_i < _hi12; _251_i++) { + if (object.Equals(_245_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _252_idx; + Defs._IOwnership _253_idxOwned; + Dafny.ISet> _254_recIdentsIdx; + RAST._IExpr _out213; + Defs._IOwnership _out214; + Dafny.ISet> _out215; + (this).GenExpr((_246_indices).Select(_251_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out213, out _out214, out _out215); + _252_idx = _out213; + _253_idxOwned = _out214; + _254_recIdentsIdx = _out215; + _252_idx = RAST.__default.IntoUsize(_252_idx); + r = RAST.Expr.create_SelectIndex(r, _252_idx); + readIdents = Dafny.Set>.Union(readIdents, _254_recIdentsIdx); } else { - RAST._IExpr _244_idx; - Defs._IOwnership _245_idxOwned; - Dafny.ISet> _246_recIdentsIdx; - RAST._IExpr _out209; - Defs._IOwnership _out210; - Dafny.ISet> _out211; - (this).GenExpr((_235_indices).Select(_240_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out209, out _out210, out _out211); - _244_idx = _out209; - _245_idxOwned = _out210; - _246_recIdentsIdx = _out211; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_244_idx); - readIdents = Dafny.Set>.Union(readIdents, _246_recIdentsIdx); + RAST._IExpr _255_idx; + Defs._IOwnership _256_idxOwned; + Dafny.ISet> _257_recIdentsIdx; + RAST._IExpr _out216; + Defs._IOwnership _out217; + Dafny.ISet> _out218; + (this).GenExpr((_246_indices).Select(_251_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out216, out _out217, out _out218); + _255_idx = _out216; + _256_idxOwned = _out217; + _257_recIdentsIdx = _out218; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_255_idx); + readIdents = Dafny.Set>.Union(readIdents, _257_recIdentsIdx); } } - if (_239_hadArray) { + if (_250_hadArray) { r = (r).Clone(); } - RAST._IExpr _out212; - Defs._IOwnership _out213; - (this).FromOwned(r, expectedOwnership, out _out212, out _out213); - r = _out212; - resultingOwnership = _out213; + RAST._IExpr _out219; + Defs._IOwnership _out220; + (this).FromOwned(r, expectedOwnership, out _out219, out _out220); + r = _out219; + resultingOwnership = _out220; return ; } goto after_match0; @@ -5898,63 +6225,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IndexRange) { - DAST._IExpression _247_on = _source0.dtor_expr; - bool _248_isArray = _source0.dtor_isArray; - Std.Wrappers._IOption _249_low = _source0.dtor_low; - Std.Wrappers._IOption _250_high = _source0.dtor_high; + DAST._IExpression _258_on = _source0.dtor_expr; + bool _259_isArray = _source0.dtor_isArray; + Std.Wrappers._IOption _260_low = _source0.dtor_low; + Std.Wrappers._IOption _261_high = _source0.dtor_high; { - Defs._IOwnership _251_onExpectedOwnership; - if (_248_isArray) { + Defs._IOwnership _262_onExpectedOwnership; + if (_259_isArray) { if (((this).pointerType).is_Raw) { - _251_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); + _262_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); } else { - _251_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); + _262_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); } } else { - _251_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); - } - RAST._IExpr _252_onExpr; - Defs._IOwnership _253_onOwned; - Dafny.ISet> _254_recIdents; - RAST._IExpr _out214; - Defs._IOwnership _out215; - Dafny.ISet> _out216; - (this).GenExpr(_247_on, selfIdent, env, _251_onExpectedOwnership, out _out214, out _out215, out _out216); - _252_onExpr = _out214; - _253_onOwned = _out215; - _254_recIdents = _out216; - readIdents = _254_recIdents; - Dafny.ISequence _255_methodName; - if ((_249_low).is_Some) { - if ((_250_high).is_Some) { - _255_methodName = Dafny.Sequence.UnicodeFromString("slice"); + _262_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); + } + RAST._IExpr _263_onExpr; + Defs._IOwnership _264_onOwned; + Dafny.ISet> _265_recIdents; + RAST._IExpr _out221; + Defs._IOwnership _out222; + Dafny.ISet> _out223; + (this).GenExpr(_258_on, selfIdent, env, _262_onExpectedOwnership, out _out221, out _out222, out _out223); + _263_onExpr = _out221; + _264_onOwned = _out222; + _265_recIdents = _out223; + readIdents = _265_recIdents; + Dafny.ISequence _266_methodName; + if ((_260_low).is_Some) { + if ((_261_high).is_Some) { + _266_methodName = Dafny.Sequence.UnicodeFromString("slice"); } else { - _255_methodName = Dafny.Sequence.UnicodeFromString("drop"); + _266_methodName = Dafny.Sequence.UnicodeFromString("drop"); } - } else if ((_250_high).is_Some) { - _255_methodName = Dafny.Sequence.UnicodeFromString("take"); + } else if ((_261_high).is_Some) { + _266_methodName = Dafny.Sequence.UnicodeFromString("take"); } else { - _255_methodName = Dafny.Sequence.UnicodeFromString(""); + _266_methodName = Dafny.Sequence.UnicodeFromString(""); } - Dafny.ISequence _256_arguments; - _256_arguments = Dafny.Sequence.FromElements(); - Std.Wrappers._IOption _source5 = _249_low; + Dafny.ISequence _267_arguments; + _267_arguments = Dafny.Sequence.FromElements(); + Std.Wrappers._IOption _source5 = _260_low; { if (_source5.is_Some) { - DAST._IExpression _257_l = _source5.dtor_value; + DAST._IExpression _268_l = _source5.dtor_value; { - RAST._IExpr _258_lExpr; - Defs._IOwnership _259___v121; - Dafny.ISet> _260_recIdentsL; - RAST._IExpr _out217; - Defs._IOwnership _out218; - Dafny.ISet> _out219; - (this).GenExpr(_257_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out217, out _out218, out _out219); - _258_lExpr = _out217; - _259___v121 = _out218; - _260_recIdentsL = _out219; - _256_arguments = Dafny.Sequence.Concat(_256_arguments, Dafny.Sequence.FromElements(_258_lExpr)); - readIdents = Dafny.Set>.Union(readIdents, _260_recIdentsL); + RAST._IExpr _269_lExpr; + Defs._IOwnership _270___v108; + Dafny.ISet> _271_recIdentsL; + RAST._IExpr _out224; + Defs._IOwnership _out225; + Dafny.ISet> _out226; + (this).GenExpr(_268_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out224, out _out225, out _out226); + _269_lExpr = _out224; + _270___v108 = _out225; + _271_recIdentsL = _out226; + _267_arguments = Dafny.Sequence.Concat(_267_arguments, Dafny.Sequence.FromElements(_269_lExpr)); + readIdents = Dafny.Set>.Union(readIdents, _271_recIdentsL); } goto after_match5; } @@ -5962,23 +6289,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match5: ; - Std.Wrappers._IOption _source6 = _250_high; + Std.Wrappers._IOption _source6 = _261_high; { if (_source6.is_Some) { - DAST._IExpression _261_h = _source6.dtor_value; + DAST._IExpression _272_h = _source6.dtor_value; { - RAST._IExpr _262_hExpr; - Defs._IOwnership _263___v122; - Dafny.ISet> _264_recIdentsH; - RAST._IExpr _out220; - Defs._IOwnership _out221; - Dafny.ISet> _out222; - (this).GenExpr(_261_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out220, out _out221, out _out222); - _262_hExpr = _out220; - _263___v122 = _out221; - _264_recIdentsH = _out222; - _256_arguments = Dafny.Sequence.Concat(_256_arguments, Dafny.Sequence.FromElements(_262_hExpr)); - readIdents = Dafny.Set>.Union(readIdents, _264_recIdentsH); + RAST._IExpr _273_hExpr; + Defs._IOwnership _274___v109; + Dafny.ISet> _275_recIdentsH; + RAST._IExpr _out227; + Defs._IOwnership _out228; + Dafny.ISet> _out229; + (this).GenExpr(_272_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out227, out _out228, out _out229); + _273_hExpr = _out227; + _274___v109 = _out228; + _275_recIdentsH = _out229; + _267_arguments = Dafny.Sequence.Concat(_267_arguments, Dafny.Sequence.FromElements(_273_hExpr)); + readIdents = Dafny.Set>.Union(readIdents, _275_recIdentsH); } goto after_match6; } @@ -5986,30 +6313,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match6: ; - r = _252_onExpr; - if (_248_isArray) { - if (!(_255_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - _255_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _255_methodName); + r = _263_onExpr; + if (_259_isArray) { + if (!(_266_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + _266_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _266_methodName); } - Dafny.ISequence _265_object__suffix; + Dafny.ISequence _276_object__suffix; if (((this).pointerType).is_Raw) { - _265_object__suffix = Dafny.Sequence.UnicodeFromString(""); + _276_object__suffix = Dafny.Sequence.UnicodeFromString(""); } else { - _265_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); + _276_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); } - r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _255_methodName), _265_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_252_onExpr), _256_arguments)); + r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _266_methodName), _276_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_263_onExpr), _267_arguments)); } else { - if (!(_255_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - r = ((r).Sel(_255_methodName)).Apply(_256_arguments); + if (!(_266_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + r = ((r).Sel(_266_methodName)).Apply(_267_arguments); } else { r = (r).Clone(); } } - RAST._IExpr _out223; - Defs._IOwnership _out224; - (this).FromOwned(r, expectedOwnership, out _out223, out _out224); - r = _out223; - resultingOwnership = _out224; + RAST._IExpr _out230; + Defs._IOwnership _out231; + (this).FromOwned(r, expectedOwnership, out _out230, out _out231); + r = _out230; + resultingOwnership = _out231; return ; } goto after_match0; @@ -6017,28 +6344,28 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TupleSelect) { - DAST._IExpression _266_on = _source0.dtor_expr; - BigInteger _267_idx = _source0.dtor_index; - DAST._IType _268_fieldType = _source0.dtor_fieldType; + DAST._IExpression _277_on = _source0.dtor_expr; + BigInteger _278_idx = _source0.dtor_index; + DAST._IType _279_fieldType = _source0.dtor_fieldType; { - RAST._IExpr _269_onExpr; - Defs._IOwnership _270_onOwnership; - Dafny.ISet> _271_recIdents; - RAST._IExpr _out225; - Defs._IOwnership _out226; - Dafny.ISet> _out227; - (this).GenExpr(_266_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out225, out _out226, out _out227); - _269_onExpr = _out225; - _270_onOwnership = _out226; - _271_recIdents = _out227; - Dafny.ISequence _272_selName; - _272_selName = Std.Strings.__default.OfNat(_267_idx); - DAST._IType _source7 = _268_fieldType; + RAST._IExpr _280_onExpr; + Defs._IOwnership _281_onOwnership; + Dafny.ISet> _282_recIdents; + RAST._IExpr _out232; + Defs._IOwnership _out233; + Dafny.ISet> _out234; + (this).GenExpr(_277_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out232, out _out233, out _out234); + _280_onExpr = _out232; + _281_onOwnership = _out233; + _282_recIdents = _out234; + Dafny.ISequence _283_selName; + _283_selName = Std.Strings.__default.OfNat(_278_idx); + DAST._IType _source7 = _279_fieldType; { if (_source7.is_Tuple) { - Dafny.ISequence _273_tps = _source7.dtor_Tuple_a0; - if (((_268_fieldType).is_Tuple) && ((new BigInteger((_273_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { - _272_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _272_selName); + Dafny.ISequence _284_tps = _source7.dtor_Tuple_a0; + if (((_279_fieldType).is_Tuple) && ((new BigInteger((_284_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { + _283_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _283_selName); } goto after_match7; } @@ -6046,13 +6373,13 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match7: ; - r = ((_269_onExpr).Sel(_272_selName)).Clone(); - RAST._IExpr _out228; - Defs._IOwnership _out229; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out228, out _out229); - r = _out228; - resultingOwnership = _out229; - readIdents = _271_recIdents; + r = ((_280_onExpr).Sel(_283_selName)).Clone(); + RAST._IExpr _out235; + Defs._IOwnership _out236; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out235, out _out236); + r = _out235; + resultingOwnership = _out236; + readIdents = _282_recIdents; return ; } goto after_match0; @@ -6060,21 +6387,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Call) { - DAST._IExpression _274_on = _source0.dtor_on; - DAST._ICallName _275_name = _source0.dtor_callName; - Dafny.ISequence _276_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _277_args = _source0.dtor_args; + DAST._IExpression _285_on = _source0.dtor_on; + DAST._ICallName _286_name = _source0.dtor_callName; + Dafny.ISequence _287_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _288_args = _source0.dtor_args; { - RAST._IExpr _out230; - Dafny.ISet> _out231; - (this).GenOwnedCallPart(_274_on, selfIdent, _275_name, _276_typeArgs, _277_args, env, out _out230, out _out231); - r = _out230; - readIdents = _out231; - RAST._IExpr _out232; - Defs._IOwnership _out233; - (this).FromOwned(r, expectedOwnership, out _out232, out _out233); - r = _out232; - resultingOwnership = _out233; + RAST._IExpr _out237; + Dafny.ISet> _out238; + (this).GenCall(_285_on, selfIdent, _286_name, _287_typeArgs, _288_args, env, out _out237, out _out238); + r = _out237; + readIdents = _out238; + RAST._IExpr _out239; + Defs._IOwnership _out240; + (this).FromOwned(r, expectedOwnership, out _out239, out _out240); + r = _out239; + resultingOwnership = _out240; return ; } goto after_match0; @@ -6082,90 +6409,90 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Lambda) { - Dafny.ISequence _278_paramsDafny = _source0.dtor_params; - DAST._IType _279_retType = _source0.dtor_retType; - Dafny.ISequence _280_body = _source0.dtor_body; + Dafny.ISequence _289_paramsDafny = _source0.dtor_params; + DAST._IType _290_retType = _source0.dtor_retType; + Dafny.ISequence _291_body = _source0.dtor_body; { - Dafny.ISequence _281_params; - Dafny.ISequence _out234; - _out234 = (this).GenParams(_278_paramsDafny, true); - _281_params = _out234; - Dafny.ISequence> _282_paramNames; - _282_paramNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _283_paramTypesMap; - _283_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); - BigInteger _hi11 = new BigInteger((_281_params).Count); - for (BigInteger _284_i = BigInteger.Zero; _284_i < _hi11; _284_i++) { - Dafny.ISequence _285_name; - _285_name = ((_281_params).Select(_284_i)).dtor_name; - _282_paramNames = Dafny.Sequence>.Concat(_282_paramNames, Dafny.Sequence>.FromElements(_285_name)); - _283_paramTypesMap = Dafny.Map, RAST._IType>.Update(_283_paramTypesMap, _285_name, ((_281_params).Select(_284_i)).dtor_tpe); - } - Defs._IEnvironment _286_subEnv; - _286_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_282_paramNames, _283_paramTypesMap, Dafny.Set>.FromElements())); - RAST._IExpr _287_recursiveGen; - Dafny.ISet> _288_recIdents; - Defs._IEnvironment _289___v124; - RAST._IExpr _out235; - Dafny.ISet> _out236; - Defs._IEnvironment _out237; - (this).GenStmts(_280_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _286_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out235, out _out236, out _out237); - _287_recursiveGen = _out235; - _288_recIdents = _out236; - _289___v124 = _out237; + Dafny.ISequence _292_params; + Dafny.ISequence _out241; + _out241 = (this).GenParams(_289_paramsDafny, _289_paramsDafny, true); + _292_params = _out241; + Dafny.ISequence> _293_paramNames; + _293_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _294_paramTypesMap; + _294_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi13 = new BigInteger((_292_params).Count); + for (BigInteger _295_i = BigInteger.Zero; _295_i < _hi13; _295_i++) { + Dafny.ISequence _296_name; + _296_name = ((_292_params).Select(_295_i)).dtor_name; + _293_paramNames = Dafny.Sequence>.Concat(_293_paramNames, Dafny.Sequence>.FromElements(_296_name)); + _294_paramTypesMap = Dafny.Map, RAST._IType>.Update(_294_paramTypesMap, _296_name, ((_292_params).Select(_295_i)).dtor_tpe); + } + Defs._IEnvironment _297_subEnv; + _297_subEnv = ((env).ToOwned()).Merge(Defs.Environment.create(_293_paramNames, _294_paramTypesMap, Dafny.Set>.FromElements())); + RAST._IExpr _298_recursiveGen; + Dafny.ISet> _299_recIdents; + Defs._IEnvironment _300___v111; + RAST._IExpr _out242; + Dafny.ISet> _out243; + Defs._IEnvironment _out244; + (this).GenStmts(_291_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _297_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out242, out _out243, out _out244); + _298_recursiveGen = _out242; + _299_recIdents = _out243; + _300___v111 = _out244; readIdents = Dafny.Set>.FromElements(); - _288_recIdents = Dafny.Set>.Difference(_288_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_290_paramNames) => ((System.Func>>)(() => { + _299_recIdents = Dafny.Set>.Difference(_299_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_301_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (Dafny.ISequence _compr_0 in (_290_paramNames).CloneAsArray()) { - Dafny.ISequence _291_name = (Dafny.ISequence)_compr_0; - if ((_290_paramNames).Contains(_291_name)) { - _coll0.Add(_291_name); + foreach (Dafny.ISequence _compr_0 in (_301_paramNames).CloneAsArray()) { + Dafny.ISequence _302_name = (Dafny.ISequence)_compr_0; + if ((_301_paramNames).Contains(_302_name)) { + _coll0.Add(_302_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_282_paramNames)); - RAST._IExpr _292_allReadCloned; - _292_allReadCloned = (this).InitEmptyExpr(); - while (!(_288_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _293_next; - foreach (Dafny.ISequence _assign_such_that_1 in (_288_recIdents).Elements) { - _293_next = (Dafny.ISequence)_assign_such_that_1; - if ((_288_recIdents).Contains(_293_next)) { + }))())(_293_paramNames)); + RAST._IExpr _303_allReadCloned; + _303_allReadCloned = (this).InitEmptyExpr(); + while (!(_299_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _304_next; + foreach (Dafny.ISequence _assign_such_that_1 in (_299_recIdents).Elements) { + _304_next = (Dafny.ISequence)_assign_such_that_1; + if ((_299_recIdents).Contains(_304_next)) { goto after__ASSIGN_SUCH_THAT_1; } } throw new System.Exception("assign-such-that search produced no value"); after__ASSIGN_SUCH_THAT_1: ; - if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_293_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { - RAST._IExpr _294_selfCloned; - Defs._IOwnership _295___v125; - Dafny.ISet> _296___v126; - RAST._IExpr _out238; - Defs._IOwnership _out239; - Dafny.ISet> _out240; - (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out238, out _out239, out _out240); - _294_selfCloned = _out238; - _295___v125 = _out239; - _296___v126 = _out240; - _292_allReadCloned = (_292_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_294_selfCloned))); - } else if (!((_282_paramNames).Contains(_293_next))) { - RAST._IExpr _297_copy; - _297_copy = (RAST.Expr.create_Identifier(_293_next)).Clone(); - _292_allReadCloned = (_292_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _293_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_297_copy))); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_293_next)); + if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_304_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + RAST._IExpr _305_selfCloned; + Defs._IOwnership _306___v112; + Dafny.ISet> _307___v113; + RAST._IExpr _out245; + Defs._IOwnership _out246; + Dafny.ISet> _out247; + (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out245, out _out246, out _out247); + _305_selfCloned = _out245; + _306___v112 = _out246; + _307___v113 = _out247; + _303_allReadCloned = (_303_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_305_selfCloned))); + } else if (!((_293_paramNames).Contains(_304_next))) { + RAST._IExpr _308_copy; + _308_copy = (RAST.Expr.create_Identifier(_304_next)).Clone(); + _303_allReadCloned = (_303_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _304_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_308_copy))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_304_next)); } - _288_recIdents = Dafny.Set>.Difference(_288_recIdents, Dafny.Set>.FromElements(_293_next)); + _299_recIdents = Dafny.Set>.Difference(_299_recIdents, Dafny.Set>.FromElements(_304_next)); } - RAST._IType _298_retTypeGen; - RAST._IType _out241; - _out241 = (this).GenType(_279_retType, Defs.GenTypeContext.@default()); - _298_retTypeGen = _out241; - r = RAST.Expr.create_Block((_292_allReadCloned).Then(Dafny.Helpers.Id>((this).rcNew)(RAST.Expr.create_Lambda(_281_params, Std.Wrappers.Option.create_Some(_298_retTypeGen), RAST.Expr.create_Block(_287_recursiveGen))))); - RAST._IExpr _out242; - Defs._IOwnership _out243; - (this).FromOwned(r, expectedOwnership, out _out242, out _out243); - r = _out242; - resultingOwnership = _out243; + RAST._IType _309_retTypeGen; + RAST._IType _out248; + _out248 = (this).GenType(_290_retType, Defs.GenTypeContext.@default()); + _309_retTypeGen = _out248; + r = RAST.Expr.create_Block((_303_allReadCloned).Then(Dafny.Helpers.Id>((this).rcNew)(RAST.Expr.create_Lambda(_292_params, Std.Wrappers.Option.create_Some(_309_retTypeGen), RAST.Expr.create_Block(_298_recursiveGen))))); + RAST._IExpr _out249; + Defs._IOwnership _out250; + (this).FromOwned(r, expectedOwnership, out _out249, out _out250); + r = _out249; + resultingOwnership = _out250; return ; } goto after_match0; @@ -6173,72 +6500,74 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _299_values = _source0.dtor_values; - DAST._IType _300_retType = _source0.dtor_retType; - DAST._IExpression _301_expr = _source0.dtor_expr; + Dafny.ISequence<_System._ITuple2> _310_values = _source0.dtor_values; + DAST._IType _311_retType = _source0.dtor_retType; + DAST._IExpression _312_expr = _source0.dtor_expr; { - Dafny.ISequence> _302_paramNames; - _302_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISequence _303_paramFormals; - Dafny.ISequence _out244; - _out244 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_304_value) => { - return (_304_value).dtor__0; - })), _299_values), false); - _303_paramFormals = _out244; - Dafny.IMap,RAST._IType> _305_paramTypes; - _305_paramTypes = Dafny.Map, RAST._IType>.FromElements(); - Dafny.ISet> _306_paramNamesSet; - _306_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _hi12 = new BigInteger((_299_values).Count); - for (BigInteger _307_i = BigInteger.Zero; _307_i < _hi12; _307_i++) { - Dafny.ISequence _308_name; - _308_name = (((_299_values).Select(_307_i)).dtor__0).dtor_name; - Dafny.ISequence _309_rName; - _309_rName = Defs.__default.escapeVar(_308_name); - _302_paramNames = Dafny.Sequence>.Concat(_302_paramNames, Dafny.Sequence>.FromElements(_309_rName)); - _305_paramTypes = Dafny.Map, RAST._IType>.Update(_305_paramTypes, _309_rName, ((_303_paramFormals).Select(_307_i)).dtor_tpe); - _306_paramNamesSet = Dafny.Set>.Union(_306_paramNamesSet, Dafny.Set>.FromElements(_309_rName)); + Dafny.ISequence> _313_paramNames; + _313_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _314_paramFormals; + Dafny.ISequence _out251; + _out251 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_315_value) => { + return (_315_value).dtor__0; + })), _310_values), Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_315_value) => { + return (_315_value).dtor__0; + })), _310_values), false); + _314_paramFormals = _out251; + Dafny.IMap,RAST._IType> _316_paramTypes; + _316_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _317_paramNamesSet; + _317_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi14 = new BigInteger((_310_values).Count); + for (BigInteger _318_i = BigInteger.Zero; _318_i < _hi14; _318_i++) { + Dafny.ISequence _319_name; + _319_name = (((_310_values).Select(_318_i)).dtor__0).dtor_name; + Dafny.ISequence _320_rName; + _320_rName = Defs.__default.escapeVar(_319_name); + _313_paramNames = Dafny.Sequence>.Concat(_313_paramNames, Dafny.Sequence>.FromElements(_320_rName)); + _316_paramTypes = Dafny.Map, RAST._IType>.Update(_316_paramTypes, _320_rName, ((_314_paramFormals).Select(_318_i)).dtor_tpe); + _317_paramNamesSet = Dafny.Set>.Union(_317_paramNamesSet, Dafny.Set>.FromElements(_320_rName)); } readIdents = Dafny.Set>.FromElements(); r = (this).InitEmptyExpr(); - BigInteger _hi13 = new BigInteger((_299_values).Count); - for (BigInteger _310_i = BigInteger.Zero; _310_i < _hi13; _310_i++) { - RAST._IType _311_typeGen; - RAST._IType _out245; - _out245 = (this).GenType((((_299_values).Select(_310_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); - _311_typeGen = _out245; - RAST._IExpr _312_valueGen; - Defs._IOwnership _313___v127; - Dafny.ISet> _314_recIdents; - RAST._IExpr _out246; - Defs._IOwnership _out247; - Dafny.ISet> _out248; - (this).GenExpr(((_299_values).Select(_310_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out246, out _out247, out _out248); - _312_valueGen = _out246; - _313___v127 = _out247; - _314_recIdents = _out248; - r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_299_values).Select(_310_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_311_typeGen), Std.Wrappers.Option.create_Some(_312_valueGen))); - readIdents = Dafny.Set>.Union(readIdents, _314_recIdents); - } - Defs._IEnvironment _315_newEnv; - _315_newEnv = Defs.Environment.create(_302_paramNames, _305_paramTypes, Dafny.Set>.FromElements()); - RAST._IExpr _316_recGen; - Defs._IOwnership _317_recOwned; - Dafny.ISet> _318_recIdents; - RAST._IExpr _out249; - Defs._IOwnership _out250; - Dafny.ISet> _out251; - (this).GenExpr(_301_expr, selfIdent, _315_newEnv, expectedOwnership, out _out249, out _out250, out _out251); - _316_recGen = _out249; - _317_recOwned = _out250; - _318_recIdents = _out251; - readIdents = Dafny.Set>.Difference(_318_recIdents, _306_paramNamesSet); - r = RAST.Expr.create_Block((r).Then(_316_recGen)); - RAST._IExpr _out252; - Defs._IOwnership _out253; - (this).FromOwnership(r, _317_recOwned, expectedOwnership, out _out252, out _out253); - r = _out252; - resultingOwnership = _out253; + BigInteger _hi15 = new BigInteger((_310_values).Count); + for (BigInteger _321_i = BigInteger.Zero; _321_i < _hi15; _321_i++) { + RAST._IType _322_typeGen; + RAST._IType _out252; + _out252 = (this).GenType((((_310_values).Select(_321_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); + _322_typeGen = _out252; + RAST._IExpr _323_valueGen; + Defs._IOwnership _324___v114; + Dafny.ISet> _325_recIdents; + RAST._IExpr _out253; + Defs._IOwnership _out254; + Dafny.ISet> _out255; + (this).GenExpr(((_310_values).Select(_321_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out253, out _out254, out _out255); + _323_valueGen = _out253; + _324___v114 = _out254; + _325_recIdents = _out255; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_310_values).Select(_321_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_322_typeGen), Std.Wrappers.Option.create_Some(_323_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _325_recIdents); + } + Defs._IEnvironment _326_newEnv; + _326_newEnv = Defs.Environment.create(_313_paramNames, _316_paramTypes, Dafny.Set>.FromElements()); + RAST._IExpr _327_recGen; + Defs._IOwnership _328_recOwned; + Dafny.ISet> _329_recIdents; + RAST._IExpr _out256; + Defs._IOwnership _out257; + Dafny.ISet> _out258; + (this).GenExpr(_312_expr, selfIdent, _326_newEnv, expectedOwnership, out _out256, out _out257, out _out258); + _327_recGen = _out256; + _328_recOwned = _out257; + _329_recIdents = _out258; + readIdents = Dafny.Set>.Difference(_329_recIdents, _317_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_327_recGen)); + RAST._IExpr _out259; + Defs._IOwnership _out260; + (this).FromOwnership(r, _328_recOwned, expectedOwnership, out _out259, out _out260); + r = _out259; + resultingOwnership = _out260; return ; } goto after_match0; @@ -6246,45 +6575,45 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IIFE) { - Dafny.ISequence _319_name = _source0.dtor_ident; - DAST._IType _320_tpe = _source0.dtor_typ; - DAST._IExpression _321_value = _source0.dtor_value; - DAST._IExpression _322_iifeBody = _source0.dtor_iifeBody; + Dafny.ISequence _330_name = _source0.dtor_ident; + DAST._IType _331_tpe = _source0.dtor_typ; + DAST._IExpression _332_value = _source0.dtor_value; + DAST._IExpression _333_iifeBody = _source0.dtor_iifeBody; { - RAST._IExpr _323_valueGen; - Defs._IOwnership _324___v128; - Dafny.ISet> _325_recIdents; - RAST._IExpr _out254; - Defs._IOwnership _out255; - Dafny.ISet> _out256; - (this).GenExpr(_321_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out254, out _out255, out _out256); - _323_valueGen = _out254; - _324___v128 = _out255; - _325_recIdents = _out256; - readIdents = _325_recIdents; - RAST._IType _326_valueTypeGen; - RAST._IType _out257; - _out257 = (this).GenType(_320_tpe, Defs.GenTypeContext.@default()); - _326_valueTypeGen = _out257; - Dafny.ISequence _327_iifeVar; - _327_iifeVar = Defs.__default.escapeVar(_319_name); - RAST._IExpr _328_bodyGen; - Defs._IOwnership _329___v129; - Dafny.ISet> _330_bodyIdents; - RAST._IExpr _out258; - Defs._IOwnership _out259; - Dafny.ISet> _out260; - (this).GenExpr(_322_iifeBody, selfIdent, (env).AddAssigned(_327_iifeVar, _326_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out258, out _out259, out _out260); - _328_bodyGen = _out258; - _329___v129 = _out259; - _330_bodyIdents = _out260; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_330_bodyIdents, Dafny.Set>.FromElements(_327_iifeVar))); - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _327_iifeVar, Std.Wrappers.Option.create_Some(_326_valueTypeGen), Std.Wrappers.Option.create_Some(_323_valueGen))).Then(_328_bodyGen)); + RAST._IExpr _334_valueGen; + Defs._IOwnership _335___v115; + Dafny.ISet> _336_recIdents; RAST._IExpr _out261; Defs._IOwnership _out262; - (this).FromOwned(r, expectedOwnership, out _out261, out _out262); - r = _out261; - resultingOwnership = _out262; + Dafny.ISet> _out263; + (this).GenExpr(_332_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out261, out _out262, out _out263); + _334_valueGen = _out261; + _335___v115 = _out262; + _336_recIdents = _out263; + readIdents = _336_recIdents; + RAST._IType _337_valueTypeGen; + RAST._IType _out264; + _out264 = (this).GenType(_331_tpe, Defs.GenTypeContext.@default()); + _337_valueTypeGen = _out264; + Dafny.ISequence _338_iifeVar; + _338_iifeVar = Defs.__default.escapeVar(_330_name); + RAST._IExpr _339_bodyGen; + Defs._IOwnership _340___v116; + Dafny.ISet> _341_bodyIdents; + RAST._IExpr _out265; + Defs._IOwnership _out266; + Dafny.ISet> _out267; + (this).GenExpr(_333_iifeBody, selfIdent, (env).AddAssigned(_338_iifeVar, _337_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out265, out _out266, out _out267); + _339_bodyGen = _out265; + _340___v116 = _out266; + _341_bodyIdents = _out267; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_341_bodyIdents, Dafny.Set>.FromElements(_338_iifeVar))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _338_iifeVar, Std.Wrappers.Option.create_Some(_337_valueTypeGen), Std.Wrappers.Option.create_Some(_334_valueGen))).Then(_339_bodyGen)); + RAST._IExpr _out268; + Defs._IOwnership _out269; + (this).FromOwned(r, expectedOwnership, out _out268, out _out269); + r = _out268; + resultingOwnership = _out269; return ; } goto after_match0; @@ -6292,43 +6621,43 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Apply) { - DAST._IExpression _331_func = _source0.dtor_expr; - Dafny.ISequence _332_args = _source0.dtor_args; + DAST._IExpression _342_func = _source0.dtor_expr; + Dafny.ISequence _343_args = _source0.dtor_args; { - RAST._IExpr _333_funcExpr; - Defs._IOwnership _334___v130; - Dafny.ISet> _335_recIdents; - RAST._IExpr _out263; - Defs._IOwnership _out264; - Dafny.ISet> _out265; - (this).GenExpr(_331_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out263, out _out264, out _out265); - _333_funcExpr = _out263; - _334___v130 = _out264; - _335_recIdents = _out265; - readIdents = _335_recIdents; - Dafny.ISequence _336_rArgs; - _336_rArgs = Dafny.Sequence.FromElements(); - BigInteger _hi14 = new BigInteger((_332_args).Count); - for (BigInteger _337_i = BigInteger.Zero; _337_i < _hi14; _337_i++) { - RAST._IExpr _338_argExpr; - Defs._IOwnership _339_argOwned; - Dafny.ISet> _340_argIdents; - RAST._IExpr _out266; - Defs._IOwnership _out267; - Dafny.ISet> _out268; - (this).GenExpr((_332_args).Select(_337_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out266, out _out267, out _out268); - _338_argExpr = _out266; - _339_argOwned = _out267; - _340_argIdents = _out268; - _336_rArgs = Dafny.Sequence.Concat(_336_rArgs, Dafny.Sequence.FromElements(_338_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _340_argIdents); - } - r = (_333_funcExpr).Apply(_336_rArgs); - RAST._IExpr _out269; - Defs._IOwnership _out270; - (this).FromOwned(r, expectedOwnership, out _out269, out _out270); - r = _out269; - resultingOwnership = _out270; + RAST._IExpr _344_funcExpr; + Defs._IOwnership _345___v117; + Dafny.ISet> _346_recIdents; + RAST._IExpr _out270; + Defs._IOwnership _out271; + Dafny.ISet> _out272; + (this).GenExpr(_342_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out270, out _out271, out _out272); + _344_funcExpr = _out270; + _345___v117 = _out271; + _346_recIdents = _out272; + readIdents = _346_recIdents; + Dafny.ISequence _347_rArgs; + _347_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi16 = new BigInteger((_343_args).Count); + for (BigInteger _348_i = BigInteger.Zero; _348_i < _hi16; _348_i++) { + RAST._IExpr _349_argExpr; + Defs._IOwnership _350_argOwned; + Dafny.ISet> _351_argIdents; + RAST._IExpr _out273; + Defs._IOwnership _out274; + Dafny.ISet> _out275; + (this).GenExpr((_343_args).Select(_348_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out273, out _out274, out _out275); + _349_argExpr = _out273; + _350_argOwned = _out274; + _351_argIdents = _out275; + _347_rArgs = Dafny.Sequence.Concat(_347_rArgs, Dafny.Sequence.FromElements(_349_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _351_argIdents); + } + r = (_344_funcExpr).Apply(_347_rArgs); + RAST._IExpr _out276; + Defs._IOwnership _out277; + (this).FromOwned(r, expectedOwnership, out _out276, out _out277); + r = _out276; + resultingOwnership = _out277; return ; } goto after_match0; @@ -6336,31 +6665,31 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TypeTest) { - DAST._IExpression _341_on = _source0.dtor_on; - Dafny.ISequence> _342_dType = _source0.dtor_dType; - Dafny.ISequence _343_variant = _source0.dtor_variant; + DAST._IExpression _352_on = _source0.dtor_on; + Dafny.ISequence> _353_dType = _source0.dtor_dType; + Dafny.ISequence _354_variant = _source0.dtor_variant; { - RAST._IExpr _344_exprGen; - Defs._IOwnership _345___v131; - Dafny.ISet> _346_recIdents; - RAST._IExpr _out271; - Defs._IOwnership _out272; - Dafny.ISet> _out273; - (this).GenExpr(_341_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); - _344_exprGen = _out271; - _345___v131 = _out272; - _346_recIdents = _out273; - RAST._IExpr _347_variantExprPath; - RAST._IExpr _out274; - _out274 = (this).GenPathExpr(Dafny.Sequence>.Concat(_342_dType, Dafny.Sequence>.FromElements(_343_variant)), true); - _347_variantExprPath = _out274; - r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_344_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _347_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); - RAST._IExpr _out275; - Defs._IOwnership _out276; - (this).FromOwned(r, expectedOwnership, out _out275, out _out276); - r = _out275; - resultingOwnership = _out276; - readIdents = _346_recIdents; + RAST._IExpr _355_exprGen; + Defs._IOwnership _356___v118; + Dafny.ISet> _357_recIdents; + RAST._IExpr _out278; + Defs._IOwnership _out279; + Dafny.ISet> _out280; + (this).GenExpr(_352_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out278, out _out279, out _out280); + _355_exprGen = _out278; + _356___v118 = _out279; + _357_recIdents = _out280; + RAST._IExpr _358_variantExprPath; + RAST._IExpr _out281; + _out281 = (this).GenPathExpr(Dafny.Sequence>.Concat(_353_dType, Dafny.Sequence>.FromElements(_354_variant)), true); + _358_variantExprPath = _out281; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_355_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _358_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); + RAST._IExpr _out282; + Defs._IOwnership _out283; + (this).FromOwned(r, expectedOwnership, out _out282, out _out283); + r = _out282; + resultingOwnership = _out283; + readIdents = _357_recIdents; return ; } goto after_match0; @@ -6368,42 +6697,96 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Is) { - DAST._IExpression _348_expr = _source0.dtor_expr; - DAST._IType _349_fromType = _source0.dtor_fromType; - DAST._IType _350_toType = _source0.dtor_toType; + DAST._IExpression _359_expr = _source0.dtor_expr; + DAST._IType _360_fromTyp = _source0.dtor_fromType; + DAST._IType _361_toTyp = _source0.dtor_toType; { - RAST._IExpr _351_expr; - Defs._IOwnership _352_recOwned; - Dafny.ISet> _353_recIdents; - RAST._IExpr _out277; - Defs._IOwnership _out278; - Dafny.ISet> _out279; - (this).GenExpr(_348_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out277, out _out278, out _out279); - _351_expr = _out277; - _352_recOwned = _out278; - _353_recIdents = _out279; - RAST._IType _354_fromType; - RAST._IType _out280; - _out280 = (this).GenType(_349_fromType, Defs.GenTypeContext.@default()); - _354_fromType = _out280; - RAST._IType _355_toType; - RAST._IType _out281; - _out281 = (this).GenType(_350_toType, Defs.GenTypeContext.@default()); - _355_toType = _out281; - if (((_354_fromType).IsObjectOrPointer()) && ((_355_toType).IsObjectOrPointer())) { - r = (((_351_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_355_toType).ObjectOrPointerUnderlying()))).Apply0(); + RAST._IType _362_fromTpe; + RAST._IType _out284; + _out284 = (this).GenType(_360_fromTyp, Defs.GenTypeContext.@default()); + _362_fromTpe = _out284; + RAST._IType _363_toTpe; + RAST._IType _out285; + _out285 = (this).GenType(_361_toTyp, Defs.GenTypeContext.@default()); + _363_toTpe = _out285; + if (((_362_fromTpe).IsObjectOrPointer()) && ((_363_toTpe).IsObjectOrPointer())) { + RAST._IExpr _364_expr; + Defs._IOwnership _365_recOwned; + Dafny.ISet> _366_recIdents; + RAST._IExpr _out286; + Defs._IOwnership _out287; + Dafny.ISet> _out288; + (this).GenExpr(_359_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out286, out _out287, out _out288); + _364_expr = _out286; + _365_recOwned = _out287; + _366_recIdents = _out288; + r = (((_364_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_363_toTpe).ObjectOrPointerUnderlying()))).Apply0(); + RAST._IExpr _out289; + Defs._IOwnership _out290; + (this).FromOwnership(r, _365_recOwned, expectedOwnership, out _out289, out _out290); + r = _out289; + resultingOwnership = _out290; + readIdents = _366_recIdents; } else { - RAST._IExpr _out282; - _out282 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object or Ptr"), (this).InitEmptyExpr()); - r = _out282; - readIdents = Dafny.Set>.FromElements(); + RAST._IExpr _367_expr; + Defs._IOwnership _368_recOwned; + Dafny.ISet> _369_recIdents; + RAST._IExpr _out291; + Defs._IOwnership _out292; + Dafny.ISet> _out293; + (this).GenExpr(_359_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out291, out _out292, out _out293); + _367_expr = _out291; + _368_recOwned = _out292; + _369_recIdents = _out293; + bool _370_isDatatype; + _370_isDatatype = (_361_toTyp).IsDatatype(); + bool _371_isGeneralTrait; + _371_isGeneralTrait = (!(_370_isDatatype)) && ((_361_toTyp).IsGeneralTrait()); + if ((_370_isDatatype) || (_371_isGeneralTrait)) { + bool _372_isDowncast; + _372_isDowncast = (_361_toTyp).Extends(_360_fromTyp); + if (_372_isDowncast) { + DAST._IType _373_underlyingType; + if (_370_isDatatype) { + _373_underlyingType = (_361_toTyp).GetDatatypeType(); + } else { + _373_underlyingType = (_361_toTyp).GetGeneralTraitType(); + } + RAST._IType _374_toTpeRaw; + RAST._IType _out294; + _out294 = (this).GenType(_373_underlyingType, Defs.GenTypeContext.@default()); + _374_toTpeRaw = _out294; + Std.Wrappers._IOption _375_toTpeRawDowncastOpt; + _375_toTpeRawDowncastOpt = (_374_toTpeRaw).ToDowncastExpr(); + if ((_375_toTpeRawDowncastOpt).is_Some) { + _367_expr = (this).FromGeneralBorrowToSelfBorrow(_367_expr, Defs.Ownership.create_OwnershipBorrowed(), env); + if (_370_isDatatype) { + _367_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_367_expr); + } + r = (((_375_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_367_expr); + _368_recOwned = Defs.Ownership.create_OwnershipOwned(); + } else { + RAST._IExpr _out295; + _out295 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_374_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); + r = _out295; + } + } else { + RAST._IExpr _out296; + _out296 = (this).Error(Dafny.Sequence.UnicodeFromString("Needs support for upcasting general traits"), (this).InitEmptyExpr()); + r = _out296; + } + } else { + RAST._IExpr _out297; + _out297 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); + r = _out297; + } + RAST._IExpr _out298; + Defs._IOwnership _out299; + (this).FromOwnership(r, _368_recOwned, expectedOwnership, out _out298, out _out299); + r = _out298; + resultingOwnership = _out299; + readIdents = _369_recIdents; } - RAST._IExpr _out283; - Defs._IOwnership _out284; - (this).FromOwnership(r, _352_recOwned, expectedOwnership, out _out283, out _out284); - r = _out283; - resultingOwnership = _out284; - readIdents = _353_recIdents; return ; } goto after_match0; @@ -6413,11 +6796,11 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_BoolBoundedPool) { { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("[false, true]")); - RAST._IExpr _out285; - Defs._IOwnership _out286; - (this).FromOwned(r, expectedOwnership, out _out285, out _out286); - r = _out285; - resultingOwnership = _out286; + RAST._IExpr _out300; + Defs._IOwnership _out301; + (this).FromOwned(r, expectedOwnership, out _out300, out _out301); + r = _out300; + resultingOwnership = _out301; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6426,25 +6809,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBoundedPool) { - DAST._IExpression _356_of = _source0.dtor_of; + DAST._IExpression _376_of = _source0.dtor_of; { - RAST._IExpr _357_exprGen; - Defs._IOwnership _358___v132; - Dafny.ISet> _359_recIdents; - RAST._IExpr _out287; - Defs._IOwnership _out288; - Dafny.ISet> _out289; - (this).GenExpr(_356_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out287, out _out288, out _out289); - _357_exprGen = _out287; - _358___v132 = _out288; - _359_recIdents = _out289; - r = ((_357_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - RAST._IExpr _out290; - Defs._IOwnership _out291; - (this).FromOwned(r, expectedOwnership, out _out290, out _out291); - r = _out290; - resultingOwnership = _out291; - readIdents = _359_recIdents; + RAST._IExpr _377_exprGen; + Defs._IOwnership _378___v119; + Dafny.ISet> _379_recIdents; + RAST._IExpr _out302; + Defs._IOwnership _out303; + Dafny.ISet> _out304; + (this).GenExpr(_376_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); + _377_exprGen = _out302; + _378___v119 = _out303; + _379_recIdents = _out304; + r = ((_377_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + RAST._IExpr _out305; + Defs._IOwnership _out306; + (this).FromOwned(r, expectedOwnership, out _out305, out _out306); + r = _out305; + resultingOwnership = _out306; + readIdents = _379_recIdents; return ; } goto after_match0; @@ -6452,29 +6835,29 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SeqBoundedPool) { - DAST._IExpression _360_of = _source0.dtor_of; - bool _361_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _380_of = _source0.dtor_of; + bool _381_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _362_exprGen; - Defs._IOwnership _363___v133; - Dafny.ISet> _364_recIdents; - RAST._IExpr _out292; - Defs._IOwnership _out293; - Dafny.ISet> _out294; - (this).GenExpr(_360_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out292, out _out293, out _out294); - _362_exprGen = _out292; - _363___v133 = _out293; - _364_recIdents = _out294; - r = ((_362_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_361_includeDuplicates)) { + RAST._IExpr _382_exprGen; + Defs._IOwnership _383___v120; + Dafny.ISet> _384_recIdents; + RAST._IExpr _out307; + Defs._IOwnership _out308; + Dafny.ISet> _out309; + (this).GenExpr(_380_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out307, out _out308, out _out309); + _382_exprGen = _out307; + _383___v120 = _out308; + _384_recIdents = _out309; + r = ((_382_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_381_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } - RAST._IExpr _out295; - Defs._IOwnership _out296; - (this).FromOwned(r, expectedOwnership, out _out295, out _out296); - r = _out295; - resultingOwnership = _out296; - readIdents = _364_recIdents; + RAST._IExpr _out310; + Defs._IOwnership _out311; + (this).FromOwned(r, expectedOwnership, out _out310, out _out311); + r = _out310; + resultingOwnership = _out311; + readIdents = _384_recIdents; return ; } goto after_match0; @@ -6482,29 +6865,29 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MultisetBoundedPool) { - DAST._IExpression _365_of = _source0.dtor_of; - bool _366_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _385_of = _source0.dtor_of; + bool _386_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _367_exprGen; - Defs._IOwnership _368___v134; - Dafny.ISet> _369_recIdents; - RAST._IExpr _out297; - Defs._IOwnership _out298; - Dafny.ISet> _out299; - (this).GenExpr(_365_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out297, out _out298, out _out299); - _367_exprGen = _out297; - _368___v134 = _out298; - _369_recIdents = _out299; - r = ((_367_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_366_includeDuplicates)) { + RAST._IExpr _387_exprGen; + Defs._IOwnership _388___v121; + Dafny.ISet> _389_recIdents; + RAST._IExpr _out312; + Defs._IOwnership _out313; + Dafny.ISet> _out314; + (this).GenExpr(_385_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out312, out _out313, out _out314); + _387_exprGen = _out312; + _388___v121 = _out313; + _389_recIdents = _out314; + r = ((_387_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_386_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } - RAST._IExpr _out300; - Defs._IOwnership _out301; - (this).FromOwned(r, expectedOwnership, out _out300, out _out301); - r = _out300; - resultingOwnership = _out301; - readIdents = _369_recIdents; + RAST._IExpr _out315; + Defs._IOwnership _out316; + (this).FromOwned(r, expectedOwnership, out _out315, out _out316); + r = _out315; + resultingOwnership = _out316; + readIdents = _389_recIdents; return ; } goto after_match0; @@ -6512,99 +6895,99 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBoundedPool) { - DAST._IExpression _370_of = _source0.dtor_of; + DAST._IExpression _390_of = _source0.dtor_of; { - RAST._IExpr _371_exprGen; - Defs._IOwnership _372___v135; - Dafny.ISet> _373_recIdents; - RAST._IExpr _out302; - Defs._IOwnership _out303; - Dafny.ISet> _out304; - (this).GenExpr(_370_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); - _371_exprGen = _out302; - _372___v135 = _out303; - _373_recIdents = _out304; - r = ((((_371_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - readIdents = _373_recIdents; - RAST._IExpr _out305; - Defs._IOwnership _out306; - (this).FromOwned(r, expectedOwnership, out _out305, out _out306); - r = _out305; - resultingOwnership = _out306; + RAST._IExpr _391_exprGen; + Defs._IOwnership _392___v122; + Dafny.ISet> _393_recIdents; + RAST._IExpr _out317; + Defs._IOwnership _out318; + Dafny.ISet> _out319; + (this).GenExpr(_390_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out317, out _out318, out _out319); + _391_exprGen = _out317; + _392___v122 = _out318; + _393_recIdents = _out319; + r = ((((_391_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + readIdents = _393_recIdents; + RAST._IExpr _out320; + Defs._IOwnership _out321; + (this).FromOwned(r, expectedOwnership, out _out320, out _out321); + r = _out320; + resultingOwnership = _out321; } goto after_match0; } } { if (_source0.is_ExactBoundedPool) { - DAST._IExpression _374_of = _source0.dtor_of; + DAST._IExpression _394_of = _source0.dtor_of; { - RAST._IExpr _375_exprGen; - Defs._IOwnership _376___v136; - Dafny.ISet> _377_recIdents; - RAST._IExpr _out307; - Defs._IOwnership _out308; - Dafny.ISet> _out309; - (this).GenExpr(_374_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out307, out _out308, out _out309); - _375_exprGen = _out307; - _376___v136 = _out308; - _377_recIdents = _out309; - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_375_exprGen); - readIdents = _377_recIdents; - RAST._IExpr _out310; - Defs._IOwnership _out311; - (this).FromOwned(r, expectedOwnership, out _out310, out _out311); - r = _out310; - resultingOwnership = _out311; + RAST._IExpr _395_exprGen; + Defs._IOwnership _396___v123; + Dafny.ISet> _397_recIdents; + RAST._IExpr _out322; + Defs._IOwnership _out323; + Dafny.ISet> _out324; + (this).GenExpr(_394_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out322, out _out323, out _out324); + _395_exprGen = _out322; + _396___v123 = _out323; + _397_recIdents = _out324; + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_395_exprGen); + readIdents = _397_recIdents; + RAST._IExpr _out325; + Defs._IOwnership _out326; + (this).FromOwned(r, expectedOwnership, out _out325, out _out326); + r = _out325; + resultingOwnership = _out326; } goto after_match0; } } { if (_source0.is_IntRange) { - DAST._IType _378_typ = _source0.dtor_elemType; - DAST._IExpression _379_lo = _source0.dtor_lo; - DAST._IExpression _380_hi = _source0.dtor_hi; - bool _381_up = _source0.dtor_up; + DAST._IType _398_typ = _source0.dtor_elemType; + DAST._IExpression _399_lo = _source0.dtor_lo; + DAST._IExpression _400_hi = _source0.dtor_hi; + bool _401_up = _source0.dtor_up; { - RAST._IExpr _382_lo; - Defs._IOwnership _383___v137; - Dafny.ISet> _384_recIdentsLo; - RAST._IExpr _out312; - Defs._IOwnership _out313; - Dafny.ISet> _out314; - (this).GenExpr(_379_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out312, out _out313, out _out314); - _382_lo = _out312; - _383___v137 = _out313; - _384_recIdentsLo = _out314; - RAST._IExpr _385_hi; - Defs._IOwnership _386___v138; - Dafny.ISet> _387_recIdentsHi; - RAST._IExpr _out315; - Defs._IOwnership _out316; - Dafny.ISet> _out317; - (this).GenExpr(_380_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out315, out _out316, out _out317); - _385_hi = _out315; - _386___v138 = _out316; - _387_recIdentsHi = _out317; - if (_381_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_382_lo, _385_hi)); + RAST._IExpr _402_lo; + Defs._IOwnership _403___v124; + Dafny.ISet> _404_recIdentsLo; + RAST._IExpr _out327; + Defs._IOwnership _out328; + Dafny.ISet> _out329; + (this).GenExpr(_399_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out327, out _out328, out _out329); + _402_lo = _out327; + _403___v124 = _out328; + _404_recIdentsLo = _out329; + RAST._IExpr _405_hi; + Defs._IOwnership _406___v125; + Dafny.ISet> _407_recIdentsHi; + RAST._IExpr _out330; + Defs._IOwnership _out331; + Dafny.ISet> _out332; + (this).GenExpr(_400_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out330, out _out331, out _out332); + _405_hi = _out330; + _406___v125 = _out331; + _407_recIdentsHi = _out332; + if (_401_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_402_lo, _405_hi)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_385_hi, _382_lo)); - } - if (!((_378_typ).is_Primitive)) { - RAST._IType _388_tpe; - RAST._IType _out318; - _out318 = (this).GenType(_378_typ, Defs.GenTypeContext.@default()); - _388_tpe = _out318; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_388_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); - } - RAST._IExpr _out319; - Defs._IOwnership _out320; - (this).FromOwned(r, expectedOwnership, out _out319, out _out320); - r = _out319; - resultingOwnership = _out320; - readIdents = Dafny.Set>.Union(_384_recIdentsLo, _387_recIdentsHi); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_405_hi, _402_lo)); + } + if (!((_398_typ).is_Primitive)) { + RAST._IType _408_tpe; + RAST._IType _out333; + _out333 = (this).GenType(_398_typ, Defs.GenTypeContext.@default()); + _408_tpe = _out333; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_408_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); + } + RAST._IExpr _out334; + Defs._IOwnership _out335; + (this).FromOwned(r, expectedOwnership, out _out334, out _out335); + r = _out334; + resultingOwnership = _out335; + readIdents = Dafny.Set>.Union(_404_recIdentsLo, _407_recIdentsHi); return ; } goto after_match0; @@ -6612,30 +6995,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _389_start = _source0.dtor_start; - bool _390_up = _source0.dtor_up; + DAST._IExpression _409_start = _source0.dtor_start; + bool _410_up = _source0.dtor_up; { - RAST._IExpr _391_start; - Defs._IOwnership _392___v139; - Dafny.ISet> _393_recIdentStart; - RAST._IExpr _out321; - Defs._IOwnership _out322; - Dafny.ISet> _out323; - (this).GenExpr(_389_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out321, out _out322, out _out323); - _391_start = _out321; - _392___v139 = _out322; - _393_recIdentStart = _out323; - if (_390_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_391_start); + RAST._IExpr _411_start; + Defs._IOwnership _412___v126; + Dafny.ISet> _413_recIdentStart; + RAST._IExpr _out336; + Defs._IOwnership _out337; + Dafny.ISet> _out338; + (this).GenExpr(_409_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out336, out _out337, out _out338); + _411_start = _out336; + _412___v126 = _out337; + _413_recIdentStart = _out338; + if (_410_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_411_start); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_391_start); - } - RAST._IExpr _out324; - Defs._IOwnership _out325; - (this).FromOwned(r, expectedOwnership, out _out324, out _out325); - r = _out324; - resultingOwnership = _out325; - readIdents = _393_recIdentStart; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_411_start); + } + RAST._IExpr _out339; + Defs._IOwnership _out340; + (this).FromOwned(r, expectedOwnership, out _out339, out _out340); + r = _out339; + resultingOwnership = _out340; + readIdents = _413_recIdentStart; return ; } goto after_match0; @@ -6643,23 +7026,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBuilder) { - DAST._IType _394_keyType = _source0.dtor_keyType; - DAST._IType _395_valueType = _source0.dtor_valueType; + DAST._IType _414_keyType = _source0.dtor_keyType; + DAST._IType _415_valueType = _source0.dtor_valueType; { - RAST._IType _396_kType; - RAST._IType _out326; - _out326 = (this).GenType(_394_keyType, Defs.GenTypeContext.@default()); - _396_kType = _out326; - RAST._IType _397_vType; - RAST._IType _out327; - _out327 = (this).GenType(_395_valueType, Defs.GenTypeContext.@default()); - _397_vType = _out327; - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_396_kType, _397_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out328; - Defs._IOwnership _out329; - (this).FromOwned(r, expectedOwnership, out _out328, out _out329); - r = _out328; - resultingOwnership = _out329; + RAST._IType _416_kType; + RAST._IType _out341; + _out341 = (this).GenType(_414_keyType, Defs.GenTypeContext.@default()); + _416_kType = _out341; + RAST._IType _417_vType; + RAST._IType _out342; + _out342 = (this).GenType(_415_valueType, Defs.GenTypeContext.@default()); + _417_vType = _out342; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_416_kType, _417_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out343; + Defs._IOwnership _out344; + (this).FromOwned(r, expectedOwnership, out _out343, out _out344); + r = _out343; + resultingOwnership = _out344; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6668,93 +7051,93 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBuilder) { - DAST._IType _398_elemType = _source0.dtor_elemType; + DAST._IType _418_elemType = _source0.dtor_elemType; { - RAST._IType _399_eType; - RAST._IType _out330; - _out330 = (this).GenType(_398_elemType, Defs.GenTypeContext.@default()); - _399_eType = _out330; + RAST._IType _419_eType; + RAST._IType _out345; + _out345 = (this).GenType(_418_elemType, Defs.GenTypeContext.@default()); + _419_eType = _out345; readIdents = Dafny.Set>.FromElements(); - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_399_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out331; - Defs._IOwnership _out332; - (this).FromOwned(r, expectedOwnership, out _out331, out _out332); - r = _out331; - resultingOwnership = _out332; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_419_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out346; + Defs._IOwnership _out347; + (this).FromOwned(r, expectedOwnership, out _out346, out _out347); + r = _out346; + resultingOwnership = _out347; return ; } goto after_match0; } } { - DAST._IType _400_elemType = _source0.dtor_elemType; - DAST._IExpression _401_collection = _source0.dtor_collection; - bool _402_is__forall = _source0.dtor_is__forall; - DAST._IExpression _403_lambda = _source0.dtor_lambda; + DAST._IType _420_elemType = _source0.dtor_elemType; + DAST._IExpression _421_collection = _source0.dtor_collection; + bool _422_is__forall = _source0.dtor_is__forall; + DAST._IExpression _423_lambda = _source0.dtor_lambda; { - RAST._IType _404_tpe; - RAST._IType _out333; - _out333 = (this).GenType(_400_elemType, Defs.GenTypeContext.@default()); - _404_tpe = _out333; - RAST._IExpr _405_collectionGen; - Defs._IOwnership _406___v140; - Dafny.ISet> _407_recIdents; - RAST._IExpr _out334; - Defs._IOwnership _out335; - Dafny.ISet> _out336; - (this).GenExpr(_401_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); - _405_collectionGen = _out334; - _406___v140 = _out335; - _407_recIdents = _out336; - Dafny.ISequence _408_extraAttributes; - _408_extraAttributes = Dafny.Sequence.FromElements(); - if ((((((_401_collection).is_IntRange) || ((_401_collection).is_UnboundedIntRange)) || ((_401_collection).is_SeqBoundedPool)) || ((_401_collection).is_ExactBoundedPool)) || ((_401_collection).is_MultisetBoundedPool)) { - _408_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); - } - if ((_403_lambda).is_Lambda) { - Dafny.ISequence _409_formals; - _409_formals = (_403_lambda).dtor_params; - Dafny.ISequence _410_newFormals; - _410_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi15 = new BigInteger((_409_formals).Count); - for (BigInteger _411_i = BigInteger.Zero; _411_i < _hi15; _411_i++) { - var _pat_let_tv0 = _408_extraAttributes; - var _pat_let_tv1 = _409_formals; - _410_newFormals = Dafny.Sequence.Concat(_410_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_409_formals).Select(_411_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _412_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_411_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _413_dt__update_hattributes_h0 => DAST.Formal.create((_412_dt__update__tmp_h0).dtor_name, (_412_dt__update__tmp_h0).dtor_typ, _413_dt__update_hattributes_h0))))))); - } - DAST._IExpression _414_newLambda; - DAST._IExpression _415_dt__update__tmp_h1 = _403_lambda; - Dafny.ISequence _416_dt__update_hparams_h0 = _410_newFormals; - _414_newLambda = DAST.Expression.create_Lambda(_416_dt__update_hparams_h0, (_415_dt__update__tmp_h1).dtor_retType, (_415_dt__update__tmp_h1).dtor_body); - RAST._IExpr _417_lambdaGen; - Defs._IOwnership _418___v141; - Dafny.ISet> _419_recLambdaIdents; - RAST._IExpr _out337; - Defs._IOwnership _out338; - Dafny.ISet> _out339; - (this).GenExpr(_414_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); - _417_lambdaGen = _out337; - _418___v141 = _out338; - _419_recLambdaIdents = _out339; - Dafny.ISequence _420_fn; - if (_402_is__forall) { - _420_fn = Dafny.Sequence.UnicodeFromString("all"); + RAST._IType _424_tpe; + RAST._IType _out348; + _out348 = (this).GenType(_420_elemType, Defs.GenTypeContext.@default()); + _424_tpe = _out348; + RAST._IExpr _425_collectionGen; + Defs._IOwnership _426___v127; + Dafny.ISet> _427_recIdents; + RAST._IExpr _out349; + Defs._IOwnership _out350; + Dafny.ISet> _out351; + (this).GenExpr(_421_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out349, out _out350, out _out351); + _425_collectionGen = _out349; + _426___v127 = _out350; + _427_recIdents = _out351; + Dafny.ISequence _428_extraAttributes; + _428_extraAttributes = Dafny.Sequence.FromElements(); + if ((((((_421_collection).is_IntRange) || ((_421_collection).is_UnboundedIntRange)) || ((_421_collection).is_SeqBoundedPool)) || ((_421_collection).is_ExactBoundedPool)) || ((_421_collection).is_MultisetBoundedPool)) { + _428_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); + } + if ((_423_lambda).is_Lambda) { + Dafny.ISequence _429_formals; + _429_formals = (_423_lambda).dtor_params; + Dafny.ISequence _430_newFormals; + _430_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi17 = new BigInteger((_429_formals).Count); + for (BigInteger _431_i = BigInteger.Zero; _431_i < _hi17; _431_i++) { + var _pat_let_tv0 = _428_extraAttributes; + var _pat_let_tv1 = _429_formals; + _430_newFormals = Dafny.Sequence.Concat(_430_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_429_formals).Select(_431_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _432_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_431_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _433_dt__update_hattributes_h0 => DAST.Formal.create((_432_dt__update__tmp_h0).dtor_name, (_432_dt__update__tmp_h0).dtor_typ, _433_dt__update_hattributes_h0))))))); + } + DAST._IExpression _434_newLambda; + DAST._IExpression _435_dt__update__tmp_h1 = _423_lambda; + Dafny.ISequence _436_dt__update_hparams_h0 = _430_newFormals; + _434_newLambda = DAST.Expression.create_Lambda(_436_dt__update_hparams_h0, (_435_dt__update__tmp_h1).dtor_retType, (_435_dt__update__tmp_h1).dtor_body); + RAST._IExpr _437_lambdaGen; + Defs._IOwnership _438___v128; + Dafny.ISet> _439_recLambdaIdents; + RAST._IExpr _out352; + Defs._IOwnership _out353; + Dafny.ISet> _out354; + (this).GenExpr(_434_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out352, out _out353, out _out354); + _437_lambdaGen = _out352; + _438___v128 = _out353; + _439_recLambdaIdents = _out354; + Dafny.ISequence _440_fn; + if (_422_is__forall) { + _440_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _420_fn = Dafny.Sequence.UnicodeFromString("any"); + _440_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_405_collectionGen).Sel(_420_fn)).Apply1(((_417_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); - readIdents = Dafny.Set>.Union(_407_recIdents, _419_recLambdaIdents); + r = ((_425_collectionGen).Sel(_440_fn)).Apply1(((_437_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + readIdents = Dafny.Set>.Union(_427_recIdents, _439_recLambdaIdents); } else { - RAST._IExpr _out340; - _out340 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); - r = _out340; + RAST._IExpr _out355; + _out355 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); + r = _out355; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out341; - Defs._IOwnership _out342; - (this).FromOwned(r, expectedOwnership, out _out341, out _out342); - r = _out341; - resultingOwnership = _out342; + RAST._IExpr _out356; + Defs._IOwnership _out357; + (this).FromOwned(r, expectedOwnership, out _out356, out _out357); + r = _out356; + resultingOwnership = _out357; } } after_match0: ; @@ -6798,7 +7181,7 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul _0_externUseDecls = Dafny.Sequence.Concat(_0_externUseDecls, Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), ((RAST.__default.crate).MSel(_3_externalMod)).MSel(Dafny.Sequence.UnicodeFromString("*")))))); } if (!(_0_externUseDecls).Equals(Dafny.Sequence.FromElements())) { - s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, (RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("Flattens all imported externs so that they can be accessed from this module"), Dafny.Sequence>.FromElements(), Defs.__default.DAFNY__EXTERN__MODULE, _0_externUseDecls))._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\n")); + s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, (RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("Flattens all imported externs so that they can be accessed from this module"), Dafny.Sequence.FromElements(), Defs.__default.DAFNY__EXTERN__MODULE, _0_externUseDecls))._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\n")); } DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _5_allModules; _5_allModules = DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Empty(); @@ -6842,15 +7225,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v142; - Dafny.ISet> _2___v143; + Defs._IOwnership _1___v129; + Dafny.ISet> _2___v130; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v142 = _out1; - _2___v143 = _out2; + _1___v129 = _out1; + _2___v130 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); @@ -7033,6 +7416,14 @@ public RAST._IType AnyTrait { get { return RAST.Type.create_IntersectionType(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType(), (this).SyncSendType); } } } + public RAST._IExpr _rcDatatypeThis {get; set;} + public RAST._IExpr rcDatatypeThis { get { + return this._rcDatatypeThis; + } } + public RAST._IExpr _borrowedRcDatatypeThis {get; set;} + public RAST._IExpr borrowedRcDatatypeThis { get { + return this._borrowedRcDatatypeThis; + } } public RAST._IExpr read__mutable__field__macro { get { return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("read_field!"))).AsExpr(); } } diff --git a/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs b/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs index e83a87fbeb1..aa9af1da401 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs @@ -242,7 +242,7 @@ public DafnyCompilerRustUtils._IGatheringModule Merge(DafnyCompilerRustUtils._IG } } else { Dafny.ISequence _1_enclosingModule = (containingPath).Select(BigInteger.Zero); - return DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Single(_1_enclosingModule, DafnyCompilerRustUtils.GatheringModule.create_GatheringModule(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence>.FromElements(), _1_enclosingModule, Dafny.Sequence.FromElements()), DafnyCompilerRustUtils.GatheringModule.Wrap((containingPath).Drop(BigInteger.One), rawDecl))); + return DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Single(_1_enclosingModule, DafnyCompilerRustUtils.GatheringModule.create_GatheringModule(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(), _1_enclosingModule, Dafny.Sequence.FromElements()), DafnyCompilerRustUtils.GatheringModule.Wrap((containingPath).Drop(BigInteger.One), rawDecl))); } } public RAST._IMod ToRust() { @@ -254,13 +254,13 @@ public RAST._IMod ToRust() { })), ((this).dtor_submodules).dtor_keys); RAST._IMod _2_dt__update__tmp_h0 = (this).dtor_existingMod; Dafny.ISequence _3_dt__update_hbody_h0 = Dafny.Sequence.Concat(((this).dtor_existingMod).dtor_body, ((System.Func>) (() => { - BigInteger dim13 = new BigInteger((_0_keysWithContent).Count); - var arr13 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim13, "array size exceeds memory limit")]; - for (int i13 = 0; i13 < dim13; i13++) { - var _4_i = (BigInteger) i13; - arr13[(int)(_4_i)] = Dafny.Helpers.Let, RAST._IModDecl>((_0_keysWithContent).Select(_4_i), _pat_let23_0 => Dafny.Helpers.Let, RAST._IModDecl>(_pat_let23_0, _5_moduleName => Dafny.Helpers.Let((Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select(((this).dtor_submodules).dtor_values,_5_moduleName)).ToRust(), _pat_let24_0 => Dafny.Helpers.Let(_pat_let24_0, _6_submodule => RAST.ModDecl.create_ModDecl(_6_submodule))))); + BigInteger dim14 = new BigInteger((_0_keysWithContent).Count); + var arr14 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim14, "array size exceeds memory limit")]; + for (int i14 = 0; i14 < dim14; i14++) { + var _4_i = (BigInteger) i14; + arr14[(int)(_4_i)] = Dafny.Helpers.Let, RAST._IModDecl>((_0_keysWithContent).Select(_4_i), _pat_let23_0 => Dafny.Helpers.Let, RAST._IModDecl>(_pat_let23_0, _5_moduleName => Dafny.Helpers.Let((Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select(((this).dtor_submodules).dtor_values,_5_moduleName)).ToRust(), _pat_let24_0 => Dafny.Helpers.Let(_pat_let24_0, _6_submodule => RAST.ModDecl.create_ModDecl(_6_submodule))))); } - return Dafny.Sequence.FromArray(arr13); + return Dafny.Sequence.FromArray(arr14); }))()); return RAST.Mod.create_Mod((_2_dt__update__tmp_h0).dtor_docString, (_2_dt__update__tmp_h0).dtor_attributes, (_2_dt__update__tmp_h0).dtor_name, _3_dt__update_hbody_h0); } diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index fdbf98adedf..be5a14b77e7 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -169,6 +169,39 @@ public static bool is__idiomatic__rust__id(Dafny.ISequence i) { return Defs.__default.TraitTypeContainingMethodAux(_5_extendedTypes, dafnyName); } } + public static bool IsRcWrappedDatatypeRec(DAST._IType dafnyType) { + TAIL_CALL_START: ; + DAST._IType _source0 = dafnyType; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; + if (kind0.is_Datatype) { + Dafny.ISequence _0_attributes = resolved0.dtor_attributes; + return Defs.__default.IsRcWrapped(_0_attributes); + } + } + } + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved1 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind1 = resolved1.dtor_kind; + if (kind1.is_SynonymType) { + DAST._IType _1_tpe = kind1.dtor_baseType; + Dafny.ISequence _2_attributes = resolved1.dtor_attributes; + DAST._IType _in0 = _1_tpe; + dafnyType = _in0; + goto TAIL_CALL_START; + } + } + } + { + return false; + } + } + public static bool IsRcWrapped(Dafny.ISequence attributes) { + return ((!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("auto-nongrowing-size"), Dafny.Sequence>.FromElements()))) && (!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("false")))))) || ((attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("true"))))); + } public static Std.Wrappers._IOption OptExtern(DAST._IAttribute attr, Dafny.ISequence dafnyName) { if (((attr).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("extern"))) { @@ -458,14 +491,19 @@ public static bool BecomesRightCallsLeft(DAST._IBinOp op) { return false; } } + public static RAST._IExpr Panic(Dafny.ISequence optText) { + if ((optText).Equals(Dafny.Sequence.UnicodeFromString(""))) { + return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply0(); + } else { + return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply1(RAST.Expr.create_LiteralString(optText, false, false)); + } + } public static RAST._IExpr UnreachablePanicIfVerified(Defs._IPointerType pointerType, Dafny.ISequence optText) { if ((pointerType).is_Raw) { return RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unreachable_unchecked"))).Apply0())); - } else if ((optText).Equals(Dafny.Sequence.UnicodeFromString(""))) { - return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply0(); } else { - return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply1(RAST.Expr.create_LiteralString(optText, false, false)); + return Defs.__default.Panic(optText); } } public static RAST._IModDecl DefaultDatatypeImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, RAST._IExpr datatypeName, Dafny.ISequence structAssignments) @@ -485,17 +523,32 @@ public static RAST._IModDecl PrintImpl(Dafny.ISequence rTy { return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, RAST.__default.DafnyPrint, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Std.Wrappers.Option.create_Some(printImplBody)))))); } + public static Dafny.ISequence EqImpl(Dafny.ISequence rTypeParamsDeclsWithEq, RAST._IType datatypeType, Dafny.ISequence rTypeParams, RAST._IExpr eqImplBody) + { + return Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithEq, RAST.__default.PartialEq, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(eqImplBody)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithEq, RAST.__default.Eq, datatypeType, Dafny.Sequence.FromElements()))); + } public static RAST._IModDecl CoerceImpl(Func rc, Func rcNew, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence datatypeName, RAST._IType datatypeType, Dafny.ISequence rCoerceTypeParams, Dafny.ISequence coerceArguments, Dafny.ISequence coerceTypes, RAST._IExpr coerceImplBody) { return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Given type parameter conversions, returns a lambda to convert this structure"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), rCoerceTypeParams, coerceArguments, Std.Wrappers.Option.create_Some(Dafny.Helpers.Id>(rc)(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(datatypeType), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes))))), Std.Wrappers.Option.create_Some(Dafny.Helpers.Id>(rcNew)(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes)), coerceImplBody)))))))); } public static RAST._IModDecl SingletonsImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, RAST._IType instantiationType, Dafny.ISequence singletonConstructors) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Enumerates all possible values of "), (datatypeType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_AllSingletonConstructors"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SequenceIter"))).AsType()).Apply(Dafny.Sequence.FromElements(instantiationType))), Std.Wrappers.Option.create_Some((((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).AsExpr()).Apply(singletonConstructors)).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0())))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Enumerates all possible values of "), (datatypeType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_AllSingletonConstructors"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SequenceIter"))).AsType()).Apply(Dafny.Sequence.FromElements(instantiationType))), Std.Wrappers.Option.create_Some((((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).AsExpr()).Apply(singletonConstructors)).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0())))))); } public static RAST._IModDecl HashImpl(Dafny.ISequence rTypeParamsDeclsWithHash, RAST._IType datatypeOrNewtypeType, RAST._IExpr hashImplBody) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithHash, RAST.__default.Hash, datatypeOrNewtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Dafny.Sequence.FromElements(RAST.TypeParamDecl.create(Dafny.Sequence.UnicodeFromString("_H"), Dafny.Sequence.FromElements((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hasher"))).AsType()))), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_state"), RAST.Type.create_BorrowedMut(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_H"))))), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(hashImplBody)))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithHash, RAST.__default.Hash, datatypeOrNewtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(hashImplBody)))))); + } + public static RAST._IImplMember hasher__trait(bool supportsEquality, Defs._IPointerType pointerType) + { + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Std.Wrappers.Option.create_Some(((supportsEquality) ? ((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("hasher"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("DefaultHasher"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0()))).Then((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher")), DAST.Format.UnaryOpFormat.create_NoFormat()))).Then(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher"))).Sel(Dafny.Sequence.UnicodeFromString("finish"))).Apply0()))) : (Defs.__default.UnreachablePanicIfVerified(pointerType, Dafny.Sequence.UnicodeFromString("The type does not support equality"))))))); + } + public static RAST._IImplMember eq__trait(RAST._IType fullTraitPath, RAST._IExpr fullTraitExpr, bool supportsEquality, Defs._IPointerType pointerType) + { + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(((supportsEquality) ? ((((((((fullTraitExpr).FSel(Dafny.Sequence.UnicodeFromString("_as_any"))).Apply1(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(RAST.__default.SelfOwned))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("map_or"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralBool(false), RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("x"), RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("_")))), Std.Wrappers.Option.create_None(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), DAST.Format.BinaryOpFormat.create_NoFormat()))))) : (Defs.__default.UnreachablePanicIfVerified(pointerType, Dafny.Sequence.UnicodeFromString("The type does not support equality"))))))); + } + public static RAST._IImplMember clone__trait(RAST._IType fullTraitPath) { + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))); } public static RAST._IModDecl UnaryOpsImpl(Dafny.Rune op, Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) { @@ -540,6 +593,66 @@ public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("partial_cmp"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("option"))).MSel(Dafny.Sequence.UnicodeFromString("Option"))).AsType()).Apply1((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Ordering"))).AsType())), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("partial_cmp"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); } + public static Std.Wrappers._IOption DowncastTraitDeclFor(Dafny.ISequence rTypeParamsDecls, RAST._IType fullType) + { + Std.Wrappers._IOption _0_valueOrError0 = (fullType).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(RAST.__default.NoDoc, RAST.__default.NoAttr, rTypeParamsDecls, _1_downcast__type, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(fullType), Std.Wrappers.Option.create_None())))))); + } + } + public static Std.Wrappers._IOption DowncastImplFor(Func rcNew, Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType) + { + Std.Wrappers._IOption _0_valueOrError0 = (datatypeType).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); + bool _2_isRc = (datatypeType).IsRc(); + RAST._IType _3_datatypeTypeRaw = ((_2_isRc) ? ((datatypeType).RcUnderlying()) : (datatypeType)); + RAST._IExpr _4_isBody = (((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(_3_datatypeTypeRaw))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("is_some"))).Apply0(); + RAST._IExpr _5_asBody = (((((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(_3_datatypeTypeRaw))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0(); + RAST._IExpr _6_asBody = ((_2_isRc) ? (Dafny.Helpers.Id>(rcNew)(_5_asBody)) : (_5_asBody)); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, RAST.Type.create_DynType(RAST.__default.AnyTrait), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_4_isBody))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(datatypeType), Std.Wrappers.Option.create_Some(_6_asBody))))))); + } + } + public static Std.Wrappers._IOption DowncastNotImplFor(Dafny.ISequence rTypeParamsDecls, RAST._IType traitType, RAST._IType datatypeType) + { + Std.Wrappers._IOption _0_valueOrError0 = (traitType).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); + bool _2_isRc = (datatypeType).IsRc(); + RAST._IType _3_datatypeTypeRaw = ((_2_isRc) ? ((datatypeType).RcUnderlying()) : (datatypeType)); + RAST._IExpr _4_isBody = RAST.Expr.create_LiteralBool(false); + RAST._IExpr _5_asBody = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply0(); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, _3_datatypeTypeRaw, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat((_3_datatypeTypeRaw)._ToString(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString(" does not implement that trait")), RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_4_isBody))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(traitType), Std.Wrappers.Option.create_Some(_5_asBody))))))); + } + } + public static Std.Wrappers._IOption DowncastImplTraitFor(Dafny.ISequence rTypeParamsDecls, RAST._IType traitType, bool implementsTrait, RAST._IType datatypeType) + { + Std.Wrappers._IOption _0_valueOrError0 = (traitType).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); + bool _2_isRc = (datatypeType).IsRc(); + RAST._IType _3_forType = ((_2_isRc) ? ((datatypeType).RcUnderlying()) : (datatypeType)); + RAST._IType _4_resultType = traitType; + RAST._IExpr _5_isBody = RAST.Expr.create_LiteralBool(implementsTrait); + RAST._IExpr _6_asBody = RAST.__default.BoxNew((RAST.__default.self).Clone()); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, _3_forType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_5_isBody))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(_4_resultType), Std.Wrappers.Option.create_Some(_6_asBody))))))); + } + } + public static RAST._IModDecl UpcastDynTraitFor(Dafny.ISequence rTypeParamsDecls, RAST._IType forBoxedTraitType, RAST._IType superTraitType, RAST._IExpr superTraitExpr) + { + RAST._IType _0_superBoxedTraitType = RAST.__default.Box(RAST.Type.create_DynType(superTraitType)); + RAST._IExpr _1_body = ((superTraitExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(superTraitType))), forBoxedTraitType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(_0_superBoxedTraitType), Std.Wrappers.Option.create_Some(_1_body)))))); + } public static Defs._IAssignmentStatus DetectAssignmentStatus(Dafny.ISequence stmts__remainder, Dafny.ISequence dafny__name) { Defs._IAssignmentStatus _hresult = Defs.AssignmentStatus.Default(); @@ -657,6 +770,13 @@ public static Defs._IAssignmentStatus DetectAssignmentStatus(Dafny.ISequence prefixWith2(Dafny.ISequence s) { + if (((new BigInteger((s).Count)) >= (new BigInteger(2))) && (((s).Take(new BigInteger(2))).Equals(Dafny.Sequence.UnicodeFromString("r#")))) { + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), (s).Drop(new BigInteger(2))); + } else { + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), s); + } + } public static Dafny.ISet> reserved__rust { get { return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("as"), Dafny.Sequence.UnicodeFromString("async"), Dafny.Sequence.UnicodeFromString("await"), Dafny.Sequence.UnicodeFromString("break"), Dafny.Sequence.UnicodeFromString("const"), Dafny.Sequence.UnicodeFromString("continue"), Dafny.Sequence.UnicodeFromString("crate"), Dafny.Sequence.UnicodeFromString("dyn"), Dafny.Sequence.UnicodeFromString("else"), Dafny.Sequence.UnicodeFromString("enum"), Dafny.Sequence.UnicodeFromString("extern"), Dafny.Sequence.UnicodeFromString("false"), Dafny.Sequence.UnicodeFromString("fn"), Dafny.Sequence.UnicodeFromString("for"), Dafny.Sequence.UnicodeFromString("if"), Dafny.Sequence.UnicodeFromString("impl"), Dafny.Sequence.UnicodeFromString("in"), Dafny.Sequence.UnicodeFromString("let"), Dafny.Sequence.UnicodeFromString("loop"), Dafny.Sequence.UnicodeFromString("match"), Dafny.Sequence.UnicodeFromString("mod"), Dafny.Sequence.UnicodeFromString("move"), Dafny.Sequence.UnicodeFromString("mut"), Dafny.Sequence.UnicodeFromString("pub"), Dafny.Sequence.UnicodeFromString("ref"), Dafny.Sequence.UnicodeFromString("return"), Dafny.Sequence.UnicodeFromString("static"), Dafny.Sequence.UnicodeFromString("struct"), Dafny.Sequence.UnicodeFromString("super"), Dafny.Sequence.UnicodeFromString("trait"), Dafny.Sequence.UnicodeFromString("true"), Dafny.Sequence.UnicodeFromString("type"), Dafny.Sequence.UnicodeFromString("union"), Dafny.Sequence.UnicodeFromString("unsafe"), Dafny.Sequence.UnicodeFromString("use"), Dafny.Sequence.UnicodeFromString("where"), Dafny.Sequence.UnicodeFromString("while"), Dafny.Sequence.UnicodeFromString("Keywords"), Dafny.Sequence.UnicodeFromString("The"), Dafny.Sequence.UnicodeFromString("abstract"), Dafny.Sequence.UnicodeFromString("become"), Dafny.Sequence.UnicodeFromString("box"), Dafny.Sequence.UnicodeFromString("do"), Dafny.Sequence.UnicodeFromString("final"), Dafny.Sequence.UnicodeFromString("macro"), Dafny.Sequence.UnicodeFromString("override"), Dafny.Sequence.UnicodeFromString("priv"), Dafny.Sequence.UnicodeFromString("try"), Dafny.Sequence.UnicodeFromString("typeof"), Dafny.Sequence.UnicodeFromString("unsized"), Dafny.Sequence.UnicodeFromString("virtual"), Dafny.Sequence.UnicodeFromString("yield")); } } @@ -669,11 +789,26 @@ public static Dafny.ISet> reserved__vars { get { public static Dafny.ISequence ASSIGNED__PREFIX { get { return Dafny.Sequence.UnicodeFromString("_set"); } } + public static Dafny.ISequence hash__type__parameters { get { + return Dafny.Sequence.FromElements(RAST.TypeParamDecl.create(Dafny.Sequence.UnicodeFromString("_H"), Dafny.Sequence.FromElements((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hasher"))).AsType()))); + } } + public static Dafny.ISequence hash__parameters { get { + return Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_state"), RAST.Type.create_BorrowedMut(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_H"))))); + } } + public static Dafny.ISequence fmt__print__parameters { get { + return Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())); + } } + public static RAST._IType fmt__print__result { get { + return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType(); + } } + public static RAST._IImplMember print__trait { get { + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq"))))))); + } } public static Dafny.ISequence IND { get { return RAST.__default.IND; } } public static Dafny.ISet> builtin__trait__preferred__methods { get { - return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("le"), Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.UnicodeFromString("lt"), Dafny.Sequence.UnicodeFromString("ge"), Dafny.Sequence.UnicodeFromString("gt")); + return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("le"), Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.UnicodeFromString("lt"), Dafny.Sequence.UnicodeFromString("ge"), Dafny.Sequence.UnicodeFromString("gt"), Dafny.Sequence.UnicodeFromString("hash")); } } public static DAST._IAttribute AttributeOwned { get { return DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("owned"), Dafny.Sequence>.FromElements()); @@ -687,6 +822,12 @@ public static Dafny.ISequence DAFNY__EXTERN__MODULE { get { public static Dafny.IMap> OpTable { get { return Dafny.Map>.FromElements(new Dafny.Pair>(DAST.BinOp.create_Mod(), Dafny.Sequence.UnicodeFromString("%")), new Dafny.Pair>(DAST.BinOp.create_And(), Dafny.Sequence.UnicodeFromString("&&")), new Dafny.Pair>(DAST.BinOp.create_Or(), Dafny.Sequence.UnicodeFromString("||")), new Dafny.Pair>(DAST.BinOp.create_Div(false), Dafny.Sequence.UnicodeFromString("/")), new Dafny.Pair>(DAST.BinOp.create_Lt(), Dafny.Sequence.UnicodeFromString("<")), new Dafny.Pair>(DAST.BinOp.create_LtChar(), Dafny.Sequence.UnicodeFromString("<")), new Dafny.Pair>(DAST.BinOp.create_Plus(false), Dafny.Sequence.UnicodeFromString("+")), new Dafny.Pair>(DAST.BinOp.create_Minus(false), Dafny.Sequence.UnicodeFromString("-")), new Dafny.Pair>(DAST.BinOp.create_Times(false), Dafny.Sequence.UnicodeFromString("*")), new Dafny.Pair>(DAST.BinOp.create_BitwiseAnd(), Dafny.Sequence.UnicodeFromString("&")), new Dafny.Pair>(DAST.BinOp.create_BitwiseOr(), Dafny.Sequence.UnicodeFromString("|")), new Dafny.Pair>(DAST.BinOp.create_BitwiseXor(), Dafny.Sequence.UnicodeFromString("^")), new Dafny.Pair>(DAST.BinOp.create_BitwiseShiftRight(), Dafny.Sequence.UnicodeFromString(">>")), new Dafny.Pair>(DAST.BinOp.create_BitwiseShiftLeft(), Dafny.Sequence.UnicodeFromString("<<"))); } } + public static RAST._IExpr hash__function { get { + return ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("hash")); + } } + public static RAST._IImplMember as__any__trait { get { + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType(RAST.__default.AnyTrait))), Std.Wrappers.Option.create_Some(RAST.__default.self))); + } } } public interface _IOwnership { @@ -834,7 +975,8 @@ public interface _IEnvironment { bool NeedsAsRefForBorrow(Dafny.ISequence name); bool IsMaybePlacebo(Dafny.ISequence name); Defs._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IType tpe); - Defs._IEnvironment merge(Defs._IEnvironment other); + Defs._IEnvironment Merge(Defs._IEnvironment other); + Defs._IEnvironment Join(Defs._IEnvironment thenBranch, Defs._IEnvironment elseBranch); Defs._IEnvironment RemoveAssigned(Dafny.ISequence name); Defs._IEnvironment AddAssignmentStatus(Dafny.ISequence name, Defs._IAssignmentStatus assignmentStatus); bool IsAssignmentStatusKnown(Dafny.ISequence name); @@ -954,9 +1096,16 @@ public Defs._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IT { return Defs.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, Dafny.Sequence>.FromElements(name)), Dafny.Map, RAST._IType>.Update((this).dtor_types, name, tpe), Dafny.Set>.Difference((this).dtor_assignmentStatusKnown, Dafny.Set>.FromElements(name))); } - public Defs._IEnvironment merge(Defs._IEnvironment other) { + public Defs._IEnvironment Merge(Defs._IEnvironment other) { return Defs.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, (other).dtor_names), Dafny.Map, RAST._IType>.Merge((this).dtor_types, (other).dtor_types), Dafny.Set>.Union((this).dtor_assignmentStatusKnown, (other).dtor_assignmentStatusKnown)); } + public Defs._IEnvironment Join(Defs._IEnvironment thenBranch, Defs._IEnvironment elseBranch) + { + Dafny.ISet> _0_removed = Dafny.Set>.Difference(((this).dtor_types).Keys, Dafny.Set>.Union(((thenBranch).dtor_types).Keys, ((elseBranch).dtor_types).Keys)); + return Defs.Environment.create(Std.Collections.Seq.__default.Filter>(Dafny.Helpers.Id>, Func, bool>>>((_1_removed) => ((System.Func, bool>)((_2_name) => { + return !(_1_removed).Contains(_2_name); +})))(_0_removed), (this).dtor_names), Dafny.Map, RAST._IType>.Subtract((this).dtor_types, _0_removed), Dafny.Set>.Difference((this).dtor_assignmentStatusKnown, _0_removed)); + } public Defs._IEnvironment RemoveAssigned(Dafny.ISequence name) { BigInteger _0_indexInEnv = Std.Collections.Seq.__default.IndexOf>((this).dtor_names, name); return Defs.Environment.create(Dafny.Sequence>.Concat(((this).dtor_names).Subsequence(BigInteger.Zero, _0_indexInEnv), ((this).dtor_names).Drop((_0_indexInEnv) + (BigInteger.One))), Dafny.Map, RAST._IType>.Subtract((this).dtor_types, Dafny.Set>.FromElements(name)), Dafny.Set>.Difference((this).dtor_assignmentStatusKnown, Dafny.Set>.FromElements(name))); @@ -1341,6 +1490,9 @@ public interface _ISelfInfo { DAST._IType dtor_dafnyType { get; } _ISelfInfo DowncastClone(); bool IsSelf(); + bool IsGeneralTrait(); + bool IsClassOrObjectTrait(); + bool IsRcWrappedDatatype(); } public abstract class SelfInfo : _ISelfInfo { public SelfInfo() { @@ -1377,6 +1529,15 @@ public DAST._IType dtor_dafnyType { public bool IsSelf() { return ((this).is_ThisTyped) && (((this).dtor_rSelfName).Equals(Dafny.Sequence.UnicodeFromString("self"))); } + public bool IsGeneralTrait() { + return ((this).is_ThisTyped) && (((this).dtor_dafnyType).IsGeneralTrait()); + } + public bool IsClassOrObjectTrait() { + return ((this).is_ThisTyped) && (((this).dtor_dafnyType).IsClassOrObjectTrait()); + } + public bool IsRcWrappedDatatype() { + return ((this).is_ThisTyped) && (Defs.__default.IsRcWrappedDatatypeRec((this).dtor_dafnyType)); + } } public class SelfInfo_NoSelf : SelfInfo { public SelfInfo_NoSelf() : base() { diff --git a/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs b/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs index 6d755a587c1..ab42f022763 100644 --- a/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs +++ b/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs @@ -328,13 +328,13 @@ public FactorPathsOptimization._IMapping Add(Dafny.ISequence k, RAST return ((_1_finalReplacement).Contains(_3_key)) && (!object.Equals(Dafny.Map, RAST._IPath>.Select(_1_finalReplacement,_3_key), _2_SelfPath)); })))(finalReplacement, SelfPath), (this).dtor_keys); return ((System.Func>) (() => { - BigInteger dim12 = new BigInteger((_0_toUse).Count); - var arr12 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim12, "array size exceeds memory limit")]; - for (int i12 = 0; i12 < dim12; i12++) { - var _4_i = (BigInteger) i12; - arr12[(int)(_4_i)] = RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (Dafny.Map, RAST._IPath>.Select(finalReplacement,(_0_toUse).Select(_4_i))).MSel((_0_toUse).Select(_4_i)))); + BigInteger dim13 = new BigInteger((_0_toUse).Count); + var arr13 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim13, "array size exceeds memory limit")]; + for (int i13 = 0; i13 < dim13; i13++) { + var _4_i = (BigInteger) i13; + arr13[(int)(_4_i)] = RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (Dafny.Map, RAST._IPath>.Select(finalReplacement,(_0_toUse).Select(_4_i))).MSel((_0_toUse).Select(_4_i)))); } - return Dafny.Sequence.FromArray(arr12); + return Dafny.Sequence.FromArray(arr13); }))(); } } diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 18b44965fbc..e5047c62dc2 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -235,13 +235,13 @@ public static RAST._IType SystemTupleType(Dafny.ISequence elements) public static RAST._IExpr SystemTuple(Dafny.ISequence elements) { Dafny.ISequence _0_size = Std.Strings.__default.OfNat(new BigInteger((elements).Count)); return RAST.Expr.create_StructBuild(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("_System"))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Tuple"), _0_size))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), _0_size))).AsExpr(), ((System.Func>) (() => { - BigInteger dim10 = new BigInteger((elements).Count); - var arr10 = new RAST._IAssignIdentifier[Dafny.Helpers.ToIntChecked(dim10, "array size exceeds memory limit")]; - for (int i10 = 0; i10 < dim10; i10++) { - var _1_i = (BigInteger) i10; - arr10[(int)(_1_i)] = RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), Std.Strings.__default.OfNat(_1_i)), (elements).Select(_1_i)); + BigInteger dim11 = new BigInteger((elements).Count); + var arr11 = new RAST._IAssignIdentifier[Dafny.Helpers.ToIntChecked(dim11, "array size exceeds memory limit")]; + for (int i11 = 0; i11 < dim11; i11++) { + var _1_i = (BigInteger) i11; + arr11[(int)(_1_i)] = RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), Std.Strings.__default.OfNat(_1_i)), (elements).Select(_1_i)); } - return Dafny.Sequence.FromArray(arr10); + return Dafny.Sequence.FromArray(arr11); }))()); } public static RAST._IType MaybeUninitType(RAST._IType underlying) { @@ -320,6 +320,54 @@ public static RAST._IExpr MaybePlacebo(RAST._IExpr underlying) { public static RAST._IExpr IntoUsize(RAST._IExpr underlying) { return (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyUsize"))).FSel(Dafny.Sequence.UnicodeFromString("into_usize"))).Apply1(underlying); } + public static bool IsBorrowUpcastBox(RAST._IExpr r) { + RAST._IExpr _source0 = r; + { + if (_source0.is_UnaryOp) { + Dafny.ISequence op10 = _source0.dtor_op1; + if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { + RAST._IExpr underlying0 = _source0.dtor_underlying; + if (underlying0.is_Call) { + RAST._IExpr obj0 = underlying0.dtor_obj; + if (obj0.is_Call) { + RAST._IExpr obj1 = obj0.dtor_obj; + if (obj1.is_CallType) { + RAST._IExpr _0_name = obj1.dtor_obj; + Dafny.ISequence _1_targs0 = obj1.dtor_typeArguments; + Dafny.ISequence _2_args0 = obj0.dtor_arguments; + Dafny.ISequence _3_args1 = underlying0.dtor_arguments; + return (((object.Equals(_0_name, ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("upcast_box"))).AsExpr())) && ((new BigInteger((_2_args0).Count)).Sign == 0)) && ((new BigInteger((_3_args1).Count)) == (BigInteger.One))) && (((System.Func)(() => { + RAST._IExpr _source1 = (_3_args1).Select(BigInteger.Zero); + { + if (_source1.is_Call) { + RAST._IExpr obj2 = _source1.dtor_obj; + if (obj2.is_Select) { + RAST._IExpr obj3 = obj2.dtor_obj; + if (obj3.is_Identifier) { + Dafny.ISequence name0 = obj3.dtor_name; + if (object.Equals(name0, Dafny.Sequence.UnicodeFromString("self"))) { + Dafny.ISequence _4_clone = obj2.dtor_name; + Dafny.ISequence _5_args2 = _source1.dtor_arguments; + return (new BigInteger((_5_args2).Count)).Sign == 0; + } + } + } + } + } + { + return false; + } + }))()); + } + } + } + } + } + } + { + return false; + } + } public static Dafny.ISequence DocStringPrefix { get { return Dafny.Sequence.UnicodeFromString("/// "); } } @@ -365,6 +413,9 @@ public static RAST._IPath PtrPath { get { public static RAST._IPath BoxPath { get { return ((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("boxed"))).MSel(Dafny.Sequence.UnicodeFromString("Box")); } } + public static RAST._IType BoxType { get { + return (RAST.__default.BoxPath).AsType(); + } } public static RAST._IExpr Ptr { get { return (RAST.__default.PtrPath).AsExpr(); } } @@ -404,6 +455,9 @@ public static RAST._IType Eq { get { public static RAST._IType Hash { get { return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).AsType(); } } + public static RAST._IType PartialEq { get { + return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(); + } } public static RAST._IType DafnyInt { get { return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt"))).AsType(); } } @@ -458,8 +512,8 @@ public static RAST._IExpr dafny__runtime__Multiset__from__array { get { public static RAST._IExpr std__default__Default__default { get { return ((RAST.__default.std__default__Default).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0(); } } - public static Dafny.ISequence> NoAttr { get { - return Dafny.Sequence>.FromElements(); + public static Dafny.ISequence NoAttr { get { + return Dafny.Sequence.FromElements(); } } public static BigInteger MAX__TUPLE__SIZE { get { return new BigInteger(12); @@ -699,7 +753,7 @@ public T VisitTopFn(T acc, RAST._ITopFnDecl t) { RAST._ITopFnDecl _source0 = t; { - Dafny.ISequence> _0_attributes = _source0.dtor_attributes; + Dafny.ISequence _0_attributes = _source0.dtor_attributes; RAST._IVisibility _1_visibility = _source0.dtor_visibility; RAST._IFn _2_fn = _source0.dtor_fn; return (this).VisitFn(acc, _2_fn); @@ -756,7 +810,7 @@ public T VisitMember(T acc, RAST._IImplMember member) { if (_source0.is_FnDecl) { Dafny.ISequence _1_docString = _source0.dtor_docString; - Dafny.ISequence> _2_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_attributes = _source0.dtor_attributes; RAST._IVisibility _3_pub = _source0.dtor_pub; RAST._IFn _4_fun = _source0.dtor_fun; return (this).VisitFn(acc, _4_fun); @@ -958,7 +1012,7 @@ public RAST._IStruct ReplaceStruct(RAST._IStruct @struct) { RAST._IStruct _source0 = @struct; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_name = _source0.dtor_name; Dafny.ISequence _3_typeParams = _source0.dtor_typeParams; RAST._IFields _4_fields = _source0.dtor_fields; @@ -969,7 +1023,7 @@ public RAST._ITypeSynonym ReplaceTypeDecl(RAST._ITypeSynonym t) { RAST._ITypeSynonym _source0 = t; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_name = _source0.dtor_name; Dafny.ISequence _3_typeParams = _source0.dtor_typeParams; RAST._IType _4_tpe = _source0.dtor_tpe; @@ -980,7 +1034,7 @@ public RAST._IConstant ReplaceConst(RAST._IConstant t) { RAST._IConstant _source0 = t; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_name = _source0.dtor_name; RAST._IType _3_tpe = _source0.dtor_tpe; RAST._IExpr _4_value = _source0.dtor_value; @@ -991,7 +1045,7 @@ public RAST._IEnum ReplaceEnum(RAST._IEnum @enum) { RAST._IEnum _source0 = @enum; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_name = _source0.dtor_name; Dafny.ISequence _3_typeParams = _source0.dtor_typeParams; Dafny.ISequence _4_variants = _source0.dtor_variants; @@ -1031,7 +1085,7 @@ public RAST._ITrait ReplaceTrait(RAST._ITrait tr) { RAST._ITrait _source0 = tr; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_typeParams = _source0.dtor_typeParams; RAST._IType _3_tpe = _source0.dtor_tpe; Dafny.ISequence _4_parents = _source0.dtor_parents; @@ -1045,7 +1099,7 @@ public RAST._ITopFnDecl ReplaceTopFn(RAST._ITopFnDecl t) { RAST._ITopFnDecl _source0 = t; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; RAST._IVisibility _2_visibility = _source0.dtor_visibility; RAST._IFn _3_fn = _source0.dtor_fn; return RAST.TopFnDecl.create(_0_docString, _1_attributes, _2_visibility, (this).ReplaceFn(_3_fn)); @@ -1088,7 +1142,7 @@ public RAST._IImplMember ReplaceImplMember(RAST._IImplMember t) { { if (_source0.is_FnDecl) { Dafny.ISequence _1_docString = _source0.dtor_docString; - Dafny.ISequence> _2_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_attributes = _source0.dtor_attributes; RAST._IVisibility _3_pub = _source0.dtor_pub; RAST._IFn _4_fun = _source0.dtor_fun; return RAST.ImplMember.create_FnDecl(_1_docString, _2_attributes, _3_pub, (this).ReplaceFn(_4_fun)); @@ -1142,7 +1196,7 @@ public interface _IMod { bool is_Mod { get; } bool is_ExternMod { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_body { get; } _IMod DowncastClone(); @@ -1152,7 +1206,7 @@ public interface _IMod { public abstract class Mod : _IMod { public Mod() { } - private static readonly RAST._IMod theDefault = create_Mod(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly RAST._IMod theDefault = create_Mod(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._IMod Default() { return theDefault; } @@ -1160,7 +1214,7 @@ public static RAST._IMod Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IMod create_Mod(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence body) { + public static _IMod create_Mod(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence body) { return new Mod_Mod(docString, attributes, name, body); } public static _IMod create_ExternMod(Dafny.ISequence name) { @@ -1174,7 +1228,7 @@ public Dafny.ISequence dtor_docString { return ((Mod_Mod)d)._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { var d = this; return ((Mod_Mod)d)._attributes; @@ -1218,7 +1272,7 @@ public __T Fold<__T>(__T acc, Func<__T, RAST._IModDecl, __T> accBuilder) } { Dafny.ISequence _1_docString = _source0.dtor_docString; - Dafny.ISequence> _2_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_attributes = _source0.dtor_attributes; Dafny.ISequence _3_name = _source0.dtor_name; Dafny.ISequence _4_body = _source0.dtor_body; return Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.__default.ToDocstringPrefix(_1_docString, ind), RAST.Attribute.ToStringMultiple(_2_attributes, ind)), Dafny.Helpers.Let>(((new BigInteger((_4_body).Count)).Sign == 1) && (((_4_body).Select(BigInteger.Zero)).is_UseDecl), _pat_let13_0 => Dafny.Helpers.Let>(_pat_let13_0, _5_startWithUse => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv0), RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))), _pat_let14_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let14_0, _6_prefixIfNotUseDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.Concat(_pat_let_tv1, RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))), _pat_let15_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let15_0, _7_prefixIfUseDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.UnicodeFromString("\n")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n\n"), _pat_let_tv2), RAST.__default.IND))), _pat_let16_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let16_0, _8_infixDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(_pat_let_tv3, RAST.__default.IND))), _pat_let17_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let17_0, _9_initialIdent => Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("pub mod "), _3_name), Dafny.Sequence.UnicodeFromString(" {")), Dafny.Sequence.UnicodeFromString("\n")), _9_initialIdent), RAST.__default.SeqToString(_4_body, Dafny.Helpers.Id, Dafny.ISequence, Dafny.ISequence, Func>>>((_10_prefixIfUseDecl, _11_prefixIfNotUseDecl, _12_ind) => ((System.Func>)((_13_modDecl) => { @@ -1229,10 +1283,10 @@ public __T Fold<__T>(__T acc, Func<__T, RAST._IModDecl, __T> accBuilder) } public class Mod_Mod : Mod { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _body; - public Mod_Mod(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence body) : base() { + public Mod_Mod(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence body) : base() { this._docString = docString; this._attributes = attributes; this._name = name; @@ -1758,7 +1812,7 @@ public RAST._IPath dtor_path { public interface _ITopFnDecl { bool is_TopFn { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } RAST._IVisibility dtor_visibility { get; } RAST._IFn dtor_fn { get; } _ITopFnDecl DowncastClone(); @@ -1766,10 +1820,10 @@ public interface _ITopFnDecl { } public class TopFnDecl : _ITopFnDecl { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly RAST._IVisibility _visibility; public readonly RAST._IFn _fn; - public TopFnDecl(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + public TopFnDecl(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility visibility, RAST._IFn fn) { this._docString = docString; this._attributes = attributes; this._visibility = visibility; @@ -1805,7 +1859,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITopFnDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, RAST.Visibility.Default(), RAST.Fn.Default()); + private static readonly RAST._ITopFnDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Visibility.Default(), RAST.Fn.Default()); public static RAST._ITopFnDecl Default() { return theDefault; } @@ -1813,10 +1867,10 @@ public static RAST._ITopFnDecl Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITopFnDecl create(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + public static _ITopFnDecl create(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility visibility, RAST._IFn fn) { return new TopFnDecl(docString, attributes, visibility, fn); } - public static _ITopFnDecl create_TopFn(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + public static _ITopFnDecl create_TopFn(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility visibility, RAST._IFn fn) { return create(docString, attributes, visibility, fn); } public bool is_TopFn { get { return true; } } @@ -1825,7 +1879,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -1846,66 +1900,103 @@ public RAST._IFn dtor_fn { } public interface _IAttribute { - bool is_RawAttribute { get; } - Dafny.ISequence dtor_content { get; } + bool is_ApplyAttribute { get; } + Dafny.ISequence dtor_name { get; } + Dafny.ISequence> dtor_derived { get; } + _IAttribute DowncastClone(); + Dafny.ISequence _ToString(Dafny.ISequence ind); } public class Attribute : _IAttribute { - public readonly Dafny.ISequence _content; - public Attribute(Dafny.ISequence content) { - this._content = content; + public readonly Dafny.ISequence _name; + public readonly Dafny.ISequence> _derived; + public Attribute(Dafny.ISequence name, Dafny.ISequence> derived) { + this._name = name; + this._derived = derived; } - public static Dafny.ISequence DowncastClone(Dafny.ISequence _this) { - return _this; + public _IAttribute DowncastClone() { + if (this is _IAttribute dt) { return dt; } + return new Attribute(_name, _derived); } public override bool Equals(object other) { var oth = other as RAST.Attribute; - return oth != null && object.Equals(this._content, oth._content); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._derived, oth._derived); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._content)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._derived)); return (int) hash; } public override string ToString() { - string s = "RAST.Attribute.RawAttribute"; + string s = "RAST.Attribute.ApplyAttribute"; s += "("; - s += this._content.ToVerbatimString(true); + s += this._name.ToVerbatimString(true); + s += ", "; + s += Dafny.Helpers.ToString(this._derived); s += ")"; return s; } - private static readonly Dafny.ISequence theDefault = Dafny.Sequence.Empty; - public static Dafny.ISequence Default() { + private static readonly RAST._IAttribute theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty); + public static RAST._IAttribute Default() { return theDefault; } - private static readonly Dafny.TypeDescriptor> _TYPE = new Dafny.TypeDescriptor>(Dafny.Sequence.Empty); - public static Dafny.TypeDescriptor> _TypeDescriptor() { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.Attribute.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IAttribute create(Dafny.ISequence content) { - return new Attribute(content); + public static _IAttribute create(Dafny.ISequence name, Dafny.ISequence> derived) { + return new Attribute(name, derived); } - public static _IAttribute create_RawAttribute(Dafny.ISequence content) { - return create(content); + public static _IAttribute create_ApplyAttribute(Dafny.ISequence name, Dafny.ISequence> derived) { + return create(name, derived); } - public bool is_RawAttribute { get { return true; } } - public Dafny.ISequence dtor_content { + public bool is_ApplyAttribute { get { return true; } } + public Dafny.ISequence dtor_name { get { - return this._content; + return this._name; } } - public static Dafny.ISequence ToStringMultiple(Dafny.ISequence> attributes, Dafny.ISequence ind) + public Dafny.ISequence> dtor_derived { + get { + return this._derived; + } + } + public static RAST._IAttribute Name(Dafny.ISequence name) { + return RAST.Attribute.create(name, Dafny.Sequence>.FromElements()); + } + public Dafny.ISequence _ToString(Dafny.ISequence ind) { + RAST._IAttribute _source0 = this; + { + Dafny.ISequence _0_name = _source0.dtor_name; + Dafny.ISequence> _1_derived = _source0.dtor_derived; + Dafny.ISequence _2_arguments = (((new BigInteger((_1_derived).Count)).Sign != 0) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString>(_1_derived, ((System.Func, Dafny.ISequence>)((_3_derived) => { + return _3_derived; + })), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(")"))) : (Dafny.Sequence.UnicodeFromString(""))); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("#["), _0_name), _2_arguments), Dafny.Sequence.UnicodeFromString("]")); + } + } + public static Dafny.ISequence ToStringMultiple(Dafny.ISequence attributes, Dafny.ISequence ind) { - return RAST.__default.SeqToString>(attributes, Dafny.Helpers.Id, Func, Dafny.ISequence>>>((_0_ind) => ((System.Func, Dafny.ISequence>)((_1_attribute) => { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_1_attribute), Dafny.Sequence.UnicodeFromString("\n")), _0_ind); + return RAST.__default.SeqToString(attributes, Dafny.Helpers.Id, Func>>>((_0_ind) => ((System.Func>)((_1_attribute) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_1_attribute)._ToString(_0_ind), Dafny.Sequence.UnicodeFromString("\n")), _0_ind); })))(ind), Dafny.Sequence.UnicodeFromString("")); } + public static RAST._IAttribute DeriveClone { get { + return RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("derive"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("Clone"))); + } } + public static RAST._IAttribute DeriveCloneAndCopy { get { + return RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("derive"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("Clone"), Dafny.Sequence.UnicodeFromString("Copy"))); + } } + public static RAST._IAttribute CfgTest { get { + return RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("cfg"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("test"))); + } } } public interface _IStruct { bool is_Struct { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } RAST._IFields dtor_fields { get; } @@ -1914,11 +2005,11 @@ public interface _IStruct { } public class Struct : _IStruct { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly RAST._IFields _fields; - public Struct(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + public Struct(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { this._docString = docString; this._attributes = attributes; this._name = name; @@ -1958,7 +2049,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IStruct theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Fields.Default()); + private static readonly RAST._IStruct theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Fields.Default()); public static RAST._IStruct Default() { return theDefault; } @@ -1966,10 +2057,10 @@ public static RAST._IStruct Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IStruct create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + public static _IStruct create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { return new Struct(docString, attributes, name, typeParams, fields); } - public static _IStruct create_Struct(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + public static _IStruct create_Struct(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { return create(docString, attributes, name, typeParams, fields); } public bool is_Struct { get { return true; } } @@ -1978,7 +2069,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -2006,7 +2097,7 @@ public RAST._IFields dtor_fields { public interface _ITypeSynonym { bool is_TypeSynonym { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } RAST._IType dtor_tpe { get; } @@ -2015,11 +2106,11 @@ public interface _ITypeSynonym { } public class TypeSynonym : _ITypeSynonym { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly RAST._IType _tpe; - public TypeSynonym(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + public TypeSynonym(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { this._docString = docString; this._attributes = attributes; this._name = name; @@ -2059,7 +2150,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITypeSynonym theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default()); + private static readonly RAST._ITypeSynonym theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default()); public static RAST._ITypeSynonym Default() { return theDefault; } @@ -2067,10 +2158,10 @@ public static RAST._ITypeSynonym Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITypeSynonym create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + public static _ITypeSynonym create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { return new TypeSynonym(docString, attributes, name, typeParams, tpe); } - public static _ITypeSynonym create_TypeSynonym(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + public static _ITypeSynonym create_TypeSynonym(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { return create(docString, attributes, name, typeParams, tpe); } public bool is_TypeSynonym { get { return true; } } @@ -2079,7 +2170,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -2107,7 +2198,7 @@ public RAST._IType dtor_tpe { public interface _IConstant { bool is_Constant { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } RAST._IType dtor_tpe { get; } RAST._IExpr dtor_value { get; } @@ -2116,11 +2207,11 @@ public interface _IConstant { } public class Constant : _IConstant { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly RAST._IType _tpe; public readonly RAST._IExpr _value; - public Constant(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + public Constant(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { this._docString = docString; this._attributes = attributes; this._name = name; @@ -2160,7 +2251,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IConstant theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), RAST.Expr.Default()); + private static readonly RAST._IConstant theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), RAST.Expr.Default()); public static RAST._IConstant Default() { return theDefault; } @@ -2168,10 +2259,10 @@ public static RAST._IConstant Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IConstant create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + public static _IConstant create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { return new Constant(docString, attributes, name, tpe, @value); } - public static _IConstant create_Constant(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + public static _IConstant create_Constant(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { return create(docString, attributes, name, tpe, @value); } public bool is_Constant { get { return true; } } @@ -2180,7 +2271,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -2388,13 +2479,13 @@ public Dafny.ISequence dtor_types { public abstract _IFields DowncastClone(); public RAST._IFields ToNamelessFields() { return RAST.Fields.create_NamelessFields(((System.Func>) (() => { - BigInteger dim11 = new BigInteger(((this).dtor_fields).Count); - var arr11 = new RAST._INamelessField[Dafny.Helpers.ToIntChecked(dim11, "array size exceeds memory limit")]; - for (int i11 = 0; i11 < dim11; i11++) { - var _0_i = (BigInteger) i11; - arr11[(int)(_0_i)] = (((this).dtor_fields).Select(_0_i)).ToNamelessField(); + BigInteger dim12 = new BigInteger(((this).dtor_fields).Count); + var arr12 = new RAST._INamelessField[Dafny.Helpers.ToIntChecked(dim12, "array size exceeds memory limit")]; + for (int i12 = 0; i12 < dim12; i12++) { + var _0_i = (BigInteger) i12; + arr12[(int)(_0_i)] = (((this).dtor_fields).Select(_0_i)).ToNamelessField(); } - return Dafny.Sequence.FromArray(arr11); + return Dafny.Sequence.FromArray(arr12); }))()); } public Dafny.ISequence _ToString(Dafny.ISequence ind, bool newLine) @@ -2553,7 +2644,7 @@ public RAST._IFields dtor_fields { public interface _IEnum { bool is_Enum { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_variants { get; } @@ -2562,11 +2653,11 @@ public interface _IEnum { } public class Enum : _IEnum { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _variants; - public Enum(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + public Enum(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { this._docString = docString; this._attributes = attributes; this._name = name; @@ -2606,7 +2697,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IEnum theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly RAST._IEnum theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._IEnum Default() { return theDefault; } @@ -2614,10 +2705,10 @@ public static RAST._IEnum Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IEnum create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + public static _IEnum create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { return new Enum(docString, attributes, name, typeParams, variants); } - public static _IEnum create_Enum(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + public static _IEnum create_Enum(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { return create(docString, attributes, name, typeParams, variants); } public bool is_Enum { get { return true; } } @@ -2626,7 +2717,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -2762,6 +2853,7 @@ public interface _IPath { RAST._IPath dtor_base { get; } Dafny.ISequence dtor_name { get; } _IPath DowncastClone(); + RAST._IPath ToDowncast(); RAST._IPath MSel(Dafny.ISequence name); RAST._IPath MSels(Dafny.ISequence> names); RAST._IExpr FSel(Dafny.ISequence name); @@ -2810,6 +2902,19 @@ public Dafny.ISequence dtor_name { } } public abstract _IPath DowncastClone(); + public RAST._IPath ToDowncast() { + RAST._IPath _source0 = this; + { + if (_source0.is_PMemberSelect) { + RAST._IPath _0_base = _source0.dtor_base; + Dafny.ISequence _1_name = _source0.dtor_name; + return RAST.Path.create_PMemberSelect(_0_base, Dafny.Sequence.Concat(RAST.Path.DowncastPrefix, _1_name)); + } + } + { + return this; + } + } public RAST._IPath MSel(Dafny.ISequence name) { return RAST.Path.create_PMemberSelect(this, name); } @@ -2882,6 +2987,9 @@ public RAST._IExpr AsExpr() { return Std.Wrappers.Option>.create_Some(_1_name); } } + public static Dafny.ISequence DowncastPrefix { get { + return Dafny.Sequence.UnicodeFromString("_Downcast_"); + } } } public class Path_Global : Path { public Path_Global() : base() { @@ -3019,6 +3127,10 @@ public interface _IType { bool dtor_copySemantics { get; } bool dtor_overflow { get; } _IType DowncastClone(); + RAST._IType RemoveSynonyms(); + Std.Wrappers._IOption ToDowncast(); + Std.Wrappers._IOption ToDowncastExpr(); + Std.Wrappers._IOption ToExpr(); RAST._IType Expand(); bool EndsWithNameThatCanAcceptGenerics(); RAST._IType ReplaceMap(Dafny.IMap mapping); @@ -3051,6 +3163,8 @@ public interface _IType { RAST._IType GetBuiltinCollectionElement(); bool IsRc(); RAST._IType RcUnderlying(); + bool IsBoxDyn(); + RAST._IType BoxDynUnderlying(); } public abstract class Type : _IType { public Type() { @@ -3249,6 +3363,124 @@ public bool dtor_overflow { } } public abstract _IType DowncastClone(); + public RAST._IType RemoveSynonyms() { + _IType _this = this; + TAIL_CALL_START: ; + RAST._IType _source0 = _this; + { + if (_source0.is_TSynonym) { + RAST._IType _0_display = _source0.dtor_display; + RAST._IType _1_base = _source0.dtor_base; + RAST._IType _in0 = _0_display; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + { + if (_source0.is_TMetaData) { + RAST._IType _2_display = _source0.dtor_display; + RAST._IType _in1 = _2_display; + _this = _in1; + ; + goto TAIL_CALL_START; + } + } + { + return _this; + } + } + public Std.Wrappers._IOption ToDowncast() { + RAST._IType _0_t = (this).RemoveSynonyms(); + if ((_0_t).IsRc()) { + return ((_0_t).RcUnderlying()).ToDowncast(); + } else if ((_0_t).IsBoxDyn()) { + return ((_0_t).BoxDynUnderlying()).ToDowncast(); + } else { + RAST._IType _source0 = _0_t; + { + if (_source0.is_TypeFromPath) { + RAST._IPath _1_path = _source0.dtor_path; + return Std.Wrappers.Option.create_Some(RAST.Type.create_TypeFromPath((_1_path).ToDowncast())); + } + } + { + if (_source0.is_TypeApp) { + RAST._IType _2_baseName = _source0.dtor_baseName; + Dafny.ISequence _3_arguments = _source0.dtor_arguments; + Std.Wrappers._IOption _4_valueOrError0 = (_2_baseName).ToDowncast(); + if ((_4_valueOrError0).IsFailure()) { + return (_4_valueOrError0).PropagateFailure(); + } else { + RAST._IType _5_baseNameExpr = (_4_valueOrError0).Extract(); + return Std.Wrappers.Option.create_Some((_5_baseNameExpr).Apply(_3_arguments)); + } + } + } + { + if (_source0.is_TIdentifier) { + Dafny.ISequence _6_name = _source0.dtor_name; + return Std.Wrappers.Option.create_Some(RAST.Type.create_TIdentifier(Dafny.Sequence.Concat(RAST.Path.DowncastPrefix, _6_name))); + } + } + { + return Std.Wrappers.Option.create_None(); + } + } + } + public Std.Wrappers._IOption ToDowncastExpr() { + Std.Wrappers._IOption _0_valueOrError0 = (this).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_tpe = (_0_valueOrError0).Extract(); + return (_1_tpe).ToExpr(); + } + } + public Std.Wrappers._IOption ToExpr() { + RAST._IType _source0 = this; + { + if (_source0.is_TypeFromPath) { + RAST._IPath _0_path = _source0.dtor_path; + return Std.Wrappers.Option.create_Some(RAST.Expr.create_ExprFromPath(_0_path)); + } + } + { + if (_source0.is_TypeApp) { + RAST._IType _1_baseName = _source0.dtor_baseName; + Dafny.ISequence _2_arguments = _source0.dtor_arguments; + Std.Wrappers._IOption _3_valueOrError0 = (_1_baseName).ToExpr(); + if ((_3_valueOrError0).IsFailure()) { + return (_3_valueOrError0).PropagateFailure(); + } else { + RAST._IExpr _4_baseNameExpr = (_3_valueOrError0).Extract(); + return Std.Wrappers.Option.create_Some((_4_baseNameExpr).ApplyType(_2_arguments)); + } + } + } + { + if (_source0.is_TSynonym) { + RAST._IType _5_display = _source0.dtor_display; + RAST._IType _6_base = _source0.dtor_base; + return (_5_display).ToExpr(); + } + } + { + if (_source0.is_TMetaData) { + RAST._IType _7_display = _source0.dtor_display; + return (_7_display).ToExpr(); + } + } + { + if (_source0.is_TIdentifier) { + Dafny.ISequence _8_name = _source0.dtor_name; + return Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_8_name)); + } + } + { + return Std.Wrappers.Option.create_None(); + } + } public RAST._IType Expand() { _IType _this = this; TAIL_CALL_START: ; @@ -4038,6 +4270,12 @@ public bool IsRc() { public RAST._IType RcUnderlying() { return ((this).dtor_arguments).Select(BigInteger.Zero); } + public bool IsBoxDyn() { + return ((((this).is_TypeApp) && (object.Equals((this).dtor_baseName, RAST.__default.BoxType))) && ((new BigInteger(((this).dtor_arguments).Count)) == (BigInteger.One))) && ((((this).dtor_arguments).Select(BigInteger.Zero)).is_DynType); + } + public RAST._IType BoxDynUnderlying() { + return (((this).dtor_arguments).Select(BigInteger.Zero)).dtor_underlying; + } } public class Type_U8 : Type { public Type_U8() : base() { @@ -4681,7 +4919,7 @@ public override string ToString() { public interface _ITrait { bool is_Trait { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_typeParams { get; } RAST._IType dtor_tpe { get; } Dafny.ISequence dtor_parents { get; } @@ -4691,12 +4929,12 @@ public interface _ITrait { } public class Trait : _ITrait { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _typeParams; public readonly RAST._IType _tpe; public readonly Dafny.ISequence _parents; public readonly Dafny.ISequence _body; - public Trait(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + public Trait(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { this._docString = docString; this._attributes = attributes; this._typeParams = typeParams; @@ -4740,7 +4978,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly RAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._ITrait Default() { return theDefault; } @@ -4748,10 +4986,10 @@ public static RAST._ITrait Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITrait create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + public static _ITrait create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { return new Trait(docString, attributes, typeParams, tpe, parents, body); } - public static _ITrait create_Trait(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + public static _ITrait create_Trait(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { return create(docString, attributes, typeParams, tpe, parents, body); } public bool is_Trait { get { return true; } } @@ -4760,7 +4998,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -4954,7 +5192,7 @@ public interface _IImplMember { Dafny.ISequence dtor_name { get; } RAST._IType dtor_rhs { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } RAST._IVisibility dtor_pub { get; } RAST._IFn dtor_fun { get; } RAST._IExpr dtor_expr { get; } @@ -4978,7 +5216,7 @@ public static _IImplMember create_RawImplMember(Dafny.ISequence cont public static _IImplMember create_TypeDeclMember(Dafny.ISequence name, RAST._IType rhs) { return new ImplMember_TypeDeclMember(name, rhs); } - public static _IImplMember create_FnDecl(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility pub, RAST._IFn fun) { + public static _IImplMember create_FnDecl(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility pub, RAST._IFn fun) { return new ImplMember_FnDecl(docString, attributes, pub, fun); } public static _IImplMember create_ImplMemberMacro(RAST._IExpr expr) { @@ -5012,7 +5250,7 @@ public Dafny.ISequence dtor_docString { return ((ImplMember_FnDecl)d)._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { var d = this; return ((ImplMember_FnDecl)d)._attributes; @@ -5110,10 +5348,10 @@ public override string ToString() { } public class ImplMember_FnDecl : ImplMember { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly RAST._IVisibility _pub; public readonly RAST._IFn _fun; - public ImplMember_FnDecl(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility pub, RAST._IFn fun) : base() { + public ImplMember_FnDecl(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility pub, RAST._IFn fun) : base() { this._docString = docString; this._attributes = attributes; this._pub = pub; @@ -6224,6 +6462,8 @@ public interface _IExpr { _System._ITuple2, Dafny.ISequence> RightParentheses(RAST._IExpr right); Std.Wrappers._IOption> RightMostIdentifier(); Dafny.ISequence _ToString(Dafny.ISequence ind); + RAST._IExpr And(RAST._IExpr rhs2); + RAST._IExpr Equals(RAST._IExpr rhs2); RAST._IExpr Then(RAST._IExpr rhs2); RAST._IExpr Sel(Dafny.ISequence name); RAST._IExpr FSel(Dafny.ISequence name); @@ -7610,6 +7850,16 @@ public bool RightRequiresParentheses(RAST._IExpr right) { return RAST.__default.AddIndent((_128_r).dtor_content, ind); } } + public RAST._IExpr And(RAST._IExpr rhs2) { + if (object.Equals(this, RAST.Expr.create_LiteralBool(true))) { + return rhs2; + } else { + return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), this, rhs2, DAST.Format.BinaryOpFormat.create_NoFormat()); + } + } + public RAST._IExpr Equals(RAST._IExpr rhs2) { + return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), this, rhs2, DAST.Format.BinaryOpFormat.create_NoFormat()); + } public RAST._IExpr Then(RAST._IExpr rhs2) { if ((this).is_StmtExpr) { return RAST.Expr.create_StmtExpr((this).dtor_stmt, ((this).dtor_rhs).Then(rhs2)); @@ -7940,6 +8190,11 @@ public RAST._IPrintingInfo printingInfo { get { } } } + { + if (object.Equals(_source2, Dafny.Sequence.UnicodeFromString("=>"))) { + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(120), RAST.Associativity.create_RightToLeft()); + } + } { return RAST.PrintingInfo.create_PrecedenceAssociativity(BigInteger.Zero, RAST.Associativity.create_RequiresParentheses()); } diff --git a/Source/DafnyCore/Resolver/ModuleResolver.cs b/Source/DafnyCore/Resolver/ModuleResolver.cs index 4dbd0126236..d5d434cc9bd 100644 --- a/Source/DafnyCore/Resolver/ModuleResolver.cs +++ b/Source/DafnyCore/Resolver/ModuleResolver.cs @@ -2127,6 +2127,12 @@ void ResolveParentTraitTypes(TopLevelDeclWithMembers cl, Graph declarations, ErrorR } else if (d is DatatypeDecl dt) { foreach (var tp in dt.TypeArgs) { if (tp.Characteristics.EqualitySupport == TypeParameter.EqualitySupportValue.Unspecified) { - // here's our chance to infer the need for equality support - foreach (var ctor in dt.Ctors) { - foreach (var arg in ctor.Formals) { - if (InferAndSetEqualitySupport(tp, arg.Type, reporter)) { - inferredSomething = true; - goto DONE_DT; // break out of the doubly-nested loop - } - } - } - DONE_DT:; + inferredSomething = inferredSomething || dt.Ctors.Any(ctor => + ctor.Formals.Any(arg => + InferAndSetEqualitySupport(tp, arg.Type, reporter) + ) + ) || dt.Traits.Any(parentType => + InferAndSetEqualitySupport(tp, parentType, reporter) + ); } } } else if (d is TypeSynonymDecl syn) { diff --git a/Source/DafnyRuntime.Tests/DafnyRuntimeRustTest/Cargo.lock b/Source/DafnyRuntime.Tests/DafnyRuntimeRustTest/Cargo.lock index c1b0654506e..de7c7230ede 100644 --- a/Source/DafnyRuntime.Tests/DafnyRuntimeRustTest/Cargo.lock +++ b/Source/DafnyRuntime.Tests/DafnyRuntimeRustTest/Cargo.lock @@ -9,12 +9,6 @@ dependencies = [ "dafny_runtime", ] -[[package]] -name = "as-any" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a30a44e99a1c83ccb2a6298c563c888952a1c9134953db26876528f84c93a" - [[package]] name = "autocfg" version = "1.3.0" @@ -25,11 +19,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" name = "dafny_runtime" version = "0.1.0" dependencies = [ - "as-any", "itertools", "num", "once_cell", - "paste", ] [[package]] @@ -125,9 +117,3 @@ name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/Makefile b/Source/DafnyRuntime/DafnyRuntimeRust/Makefile index 3602a45d885..bca42243469 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/Makefile +++ b/Source/DafnyRuntime/DafnyRuntimeRust/Makefile @@ -8,7 +8,7 @@ GENERATED_SYSTEM_MODULE_TARGET=src/system/mod.rs all: check-system-module test build-system-module: - $(DAFNY) translate rs --no-verify --use-basename-for-filename --optimize-erasable-datatype-wrapper:false --system-module:OmitAllOtherModules ../systemModulePopulator.dfy --output:../obj/systemModulePopulator + $(DAFNY) translate rs --no-verify --enforce-determinism --use-basename-for-filename --optimize-erasable-datatype-wrapper:false --system-module:OmitAllOtherModules ../systemModulePopulator.dfy --output:../obj/systemModulePopulator python -c "import sys; data = sys.stdin.read(); sys.stdout.write(data.replace('::dafny_runtime', 'crate').replace('pub use ::std::rc::Rc;', '#[cfg(feature = \"sync\")] pub use ::std::sync::{Arc as Rc}; #[cfg(not(feature = \"sync\"))] pub use ::std::rc::Rc;'))" < $(GENERATED_SYSTEM_MODULE_SOURCE) > $(GENERATED_SYSTEM_MODULE_SOURCE).tmp && mv $(GENERATED_SYSTEM_MODULE_SOURCE).tmp $(GENERATED_SYSTEM_MODULE_SOURCE) check-system-module: build-system-module diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index 1598acc51d5..6e1606c5dc7 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -2077,7 +2077,7 @@ impl DafnyPrint for LazyFieldWrapper { // Convert the DafnyPrint above into a macro so that we can create it for functions of any input arity macro_rules! dafny_print_function { ($($n:tt)*) => { - impl $crate::DafnyPrint for $crate::Rc B + Send + Sync> { + impl $crate::DafnyPrint for $crate::Rc B + Send + Sync> { fn fmt_print(&self, f: &mut ::std::fmt::Formatter<'_>, _in_seq: bool) -> ::std::fmt::Result { write!(f, "") } @@ -2088,7 +2088,7 @@ macro_rules! dafny_print_function { // Convert the DafnyPrint above into a macro so that we can create it for functions of any input arity macro_rules! dafny_print_function { ($($n:tt)*) => { - impl $crate::DafnyPrint for $crate::Rc B> { + impl $crate::DafnyPrint for $crate::Rc B> { fn fmt_print(&self, f: &mut ::std::fmt::Formatter<'_>, _in_seq: bool) -> ::std::fmt::Result { write!(f, "") } @@ -3988,10 +3988,9 @@ where Rc::new(|x: A| UpcastBox::upcast(&x)) } pub fn upcast_box_box() -> Rc) -> Box> -where - Box: UpcastBox, + where A: UpcastBox, { - Rc::new(|x: Box| UpcastBox::upcast(&x)) + Rc::new(|x: Box| UpcastBox::upcast(x.as_ref())) } pub fn upcast_id() -> Rc A> { @@ -4039,6 +4038,24 @@ pub trait UpcastBox { fn upcast(&self) -> Box; } +impl UpcastBox for Rc + where U: UpcastBox +{ + fn upcast(&self) -> Box { + UpcastBox::upcast(AsRef::as_ref(self)) + } +} + +pub trait AnyRef { + fn as_any_ref(&self) -> &dyn Any; +} + +impl AnyRef for T { + fn as_any_ref(&self) -> &dyn Any { + self + } +} + #[macro_export] macro_rules! Extends { ($traitType: tt) => { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs index 582b3cc8214..13242934e75 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs @@ -12,15 +12,15 @@ pub mod _System { #[cfg(feature = "sync")] pub use ::std::sync::{Arc as Rc}; #[cfg(not(feature = "sync"))] pub use ::std::rc::Rc; pub use ::std::cmp::Eq; pub use ::std::hash::Hash; + pub use ::std::cmp::PartialEq; pub use ::std::hash::Hasher; - pub use ::std::default::Default; pub use ::std::convert::AsRef; pub use crate::SequenceIter; pub use crate::seq; pub type nat = DafnyInt; - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple2 { _T2 { _0: T0, @@ -82,7 +82,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple2 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple2::_T2{_0, _1, }, Tuple2::_T2{_0: _2__0, _1: _2__1, }) => { + _0 == _2__0 && _1 == _2__1 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple2 {} impl Hash @@ -97,16 +114,6 @@ pub mod _System { } } - impl Default - for Tuple2 { - fn default() -> Tuple2 { - Tuple2::_T2 { - _0: Default::default(), - _1: Default::default() - } - } - } - impl AsRef> for Tuple2 { fn as_ref(&self) -> &Self { @@ -114,7 +121,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple0 { _T0 {} } @@ -147,6 +154,23 @@ pub mod _System { } } + impl PartialEq + for Tuple0 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple0::_T0{}, Tuple0::_T0{}) => { + true + }, + _ => { + false + }, + } + } + } + impl Eq for Tuple0 {} @@ -161,13 +185,6 @@ pub mod _System { } } - impl Default - for Tuple0 { - fn default() -> Tuple0 { - Tuple0::_T0 {} - } - } - impl AsRef for Tuple0 { fn as_ref(&self) -> &Self { @@ -175,7 +192,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple1 { _T1 { _0: T0 @@ -227,7 +244,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple1 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple1::_T1{_0, }, Tuple1::_T1{_0: _2__0, }) => { + _0 == _2__0 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple1 {} impl Hash @@ -241,15 +275,6 @@ pub mod _System { } } - impl Default - for Tuple1 { - fn default() -> Tuple1 { - Tuple1::_T1 { - _0: Default::default() - } - } - } - impl AsRef> for Tuple1 { fn as_ref(&self) -> &Self { @@ -257,7 +282,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple3 { _T3 { _0: T0, @@ -329,7 +354,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple3 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple3::_T3{_0, _1, _2, }, Tuple3::_T3{_0: _2__0, _1: _2__1, _2: _2__2, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple3 {} impl Hash @@ -345,17 +387,6 @@ pub mod _System { } } - impl Default - for Tuple3 { - fn default() -> Tuple3 { - Tuple3::_T3 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default() - } - } - } - impl AsRef> for Tuple3 { fn as_ref(&self) -> &Self { @@ -363,7 +394,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple4 { _T4 { _0: T0, @@ -445,7 +476,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple4 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple4::_T4{_0, _1, _2, _3, }, Tuple4::_T4{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple4 {} impl Hash @@ -462,18 +510,6 @@ pub mod _System { } } - impl Default - for Tuple4 { - fn default() -> Tuple4 { - Tuple4::_T4 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default() - } - } - } - impl AsRef> for Tuple4 { fn as_ref(&self) -> &Self { @@ -481,7 +517,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple5 { _T5 { _0: T0, @@ -573,7 +609,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple5 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple5::_T5{_0, _1, _2, _3, _4, }, Tuple5::_T5{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple5 {} impl Hash @@ -591,19 +644,6 @@ pub mod _System { } } - impl Default - for Tuple5 { - fn default() -> Tuple5 { - Tuple5::_T5 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default() - } - } - } - impl AsRef> for Tuple5 { fn as_ref(&self) -> &Self { @@ -611,7 +651,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple6 { _T6 { _0: T0, @@ -713,7 +753,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple6 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple6::_T6{_0, _1, _2, _3, _4, _5, }, Tuple6::_T6{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple6 {} impl Hash @@ -732,20 +789,6 @@ pub mod _System { } } - impl Default - for Tuple6 { - fn default() -> Tuple6 { - Tuple6::_T6 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default() - } - } - } - impl AsRef> for Tuple6 { fn as_ref(&self) -> &Self { @@ -753,7 +796,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple7 { _T7 { _0: T0, @@ -865,7 +908,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple7 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, }, Tuple7::_T7{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple7 {} impl Hash @@ -885,21 +945,6 @@ pub mod _System { } } - impl Default - for Tuple7 { - fn default() -> Tuple7 { - Tuple7::_T7 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default() - } - } - } - impl AsRef> for Tuple7 { fn as_ref(&self) -> &Self { @@ -907,7 +952,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple8 { _T8 { _0: T0, @@ -1029,7 +1074,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple8 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, }, Tuple8::_T8{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple8 {} impl Hash @@ -1050,22 +1112,6 @@ pub mod _System { } } - impl Default - for Tuple8 { - fn default() -> Tuple8 { - Tuple8::_T8 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default() - } - } - } - impl AsRef> for Tuple8 { fn as_ref(&self) -> &Self { @@ -1073,7 +1119,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple9 { _T9 { _0: T0, @@ -1205,7 +1251,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple9 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, }, Tuple9::_T9{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple9 {} impl Hash @@ -1227,23 +1290,6 @@ pub mod _System { } } - impl Default - for Tuple9 { - fn default() -> Tuple9 { - Tuple9::_T9 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default() - } - } - } - impl AsRef> for Tuple9 { fn as_ref(&self) -> &Self { @@ -1251,7 +1297,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple10 { _T10 { _0: T0, @@ -1393,7 +1439,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple10 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, }, Tuple10::_T10{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple10 {} impl Hash @@ -1416,24 +1479,6 @@ pub mod _System { } } - impl Default - for Tuple10 { - fn default() -> Tuple10 { - Tuple10::_T10 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default() - } - } - } - impl AsRef> for Tuple10 { fn as_ref(&self) -> &Self { @@ -1441,7 +1486,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple11 { _T11 { _0: T0, @@ -1593,7 +1638,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple11 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, }, Tuple11::_T11{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple11 {} impl Hash @@ -1617,25 +1679,6 @@ pub mod _System { } } - impl Default - for Tuple11 { - fn default() -> Tuple11 { - Tuple11::_T11 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default() - } - } - } - impl AsRef> for Tuple11 { fn as_ref(&self) -> &Self { @@ -1643,7 +1686,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple12 { _T12 { _0: T0, @@ -1805,7 +1848,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple12 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, }, Tuple12::_T12{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple12 {} impl Hash @@ -1830,26 +1890,6 @@ pub mod _System { } } - impl Default - for Tuple12 { - fn default() -> Tuple12 { - Tuple12::_T12 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default() - } - } - } - impl AsRef> for Tuple12 { fn as_ref(&self) -> &Self { @@ -1857,7 +1897,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple13 { _T13 { _0: T0, @@ -2029,7 +2069,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple13 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, }, Tuple13::_T13{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple13 {} impl Hash @@ -2055,27 +2112,6 @@ pub mod _System { } } - impl Default - for Tuple13 { - fn default() -> Tuple13 { - Tuple13::_T13 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default() - } - } - } - impl AsRef> for Tuple13 { fn as_ref(&self) -> &Self { @@ -2083,7 +2119,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple14 { _T14 { _0: T0, @@ -2265,7 +2301,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple14 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, }, Tuple14::_T14{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple14 {} impl Hash @@ -2292,28 +2345,6 @@ pub mod _System { } } - impl Default - for Tuple14 { - fn default() -> Tuple14 { - Tuple14::_T14 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default() - } - } - } - impl AsRef> for Tuple14 { fn as_ref(&self) -> &Self { @@ -2321,7 +2352,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple15 { _T15 { _0: T0, @@ -2513,7 +2544,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple15 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, }, Tuple15::_T15{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple15 {} impl Hash @@ -2541,29 +2589,6 @@ pub mod _System { } } - impl Default - for Tuple15 { - fn default() -> Tuple15 { - Tuple15::_T15 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default() - } - } - } - impl AsRef> for Tuple15 { fn as_ref(&self) -> &Self { @@ -2571,7 +2596,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple16 { _T16 { _0: T0, @@ -2773,7 +2798,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple16 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, }, Tuple16::_T16{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple16 {} impl Hash @@ -2802,30 +2844,6 @@ pub mod _System { } } - impl Default - for Tuple16 { - fn default() -> Tuple16 { - Tuple16::_T16 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default() - } - } - } - impl AsRef> for Tuple16 { fn as_ref(&self) -> &Self { @@ -2833,7 +2851,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple17 { _T17 { _0: T0, @@ -3045,7 +3063,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple17 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, }, Tuple17::_T17{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple17 {} impl Hash @@ -3075,31 +3110,6 @@ pub mod _System { } } - impl Default - for Tuple17 { - fn default() -> Tuple17 { - Tuple17::_T17 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default(), - _16: Default::default() - } - } - } - impl AsRef> for Tuple17 { fn as_ref(&self) -> &Self { @@ -3107,7 +3117,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple18 { _T18 { _0: T0, @@ -3329,7 +3339,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple18 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, }, Tuple18::_T18{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple18 {} impl Hash @@ -3360,32 +3387,6 @@ pub mod _System { } } - impl Default - for Tuple18 { - fn default() -> Tuple18 { - Tuple18::_T18 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default(), - _16: Default::default(), - _17: Default::default() - } - } - } - impl AsRef> for Tuple18 { fn as_ref(&self) -> &Self { @@ -3393,7 +3394,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple19 { _T19 { _0: T0, @@ -3625,7 +3626,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple19 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, }, Tuple19::_T19{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, _18: _2__18, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 && _18 == _2__18 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple19 {} impl Hash @@ -3657,33 +3675,6 @@ pub mod _System { } } - impl Default - for Tuple19 { - fn default() -> Tuple19 { - Tuple19::_T19 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default(), - _16: Default::default(), - _17: Default::default(), - _18: Default::default() - } - } - } - impl AsRef> for Tuple19 { fn as_ref(&self) -> &Self { @@ -3691,7 +3682,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple20 { _T20 { _0: T0, @@ -3933,7 +3924,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple20 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, }, Tuple20::_T20{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, _18: _2__18, _19: _2__19, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 && _18 == _2__18 && _19 == _2__19 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple20 {} impl Hash @@ -3966,34 +3974,6 @@ pub mod _System { } } - impl Default - for Tuple20 { - fn default() -> Tuple20 { - Tuple20::_T20 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default(), - _16: Default::default(), - _17: Default::default(), - _18: Default::default(), - _19: Default::default() - } - } - } - impl AsRef> for Tuple20 { fn as_ref(&self) -> &Self { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index 4ac2fb26bfc..c3b9e528cee 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -673,9 +673,9 @@ mod tests { #[test] fn test_function_wrappers() { #[cfg(feature = "sync")] - let f: Rc i32 + Send + Sync> = Rc::new(|i: i32| i + 1); + let f: Rc i32 + Send + Sync> = Rc::new(|i: &i32| *i + 1); #[cfg(not(feature = "sync"))] - let f: Rc i32> = Rc::new(|i: i32| i + 1); + let f: Rc i32> = Rc::new(|i: &i32| *i + 1); let g = f.clone(); let _h = seq![g]; } @@ -1033,14 +1033,45 @@ mod tests { assert_eq!(resulting_message, message); } + /** Hierarchy implemented + * GeneralTraitSuper + * | \____________________, + * | | + * GeneralTraitSuper GeneralTraitSuperChild + * | | (via i32) + * GeneralTrait CDatatype + * | | + * ADatatype BDatatype + */ + + trait _Downcast_GeneralTrait { + fn _is(&self) -> bool; + fn _as(&self) -> Box; // For trait objects, Object or Ptr instead of Box + } + + + trait _Downcast_ADatatype { + fn _is(&self) -> bool; + fn _as(&self) -> ADatatype; // For trait objects, Object or Ptr instead of Box + } + trait _Downcast_CDatatype { + fn _is(&self) -> bool; + fn _as(&self) -> CDatatype; // For trait objects, Object or Ptr instead of Box + } + // Every general trait must declare how to clone a Box of itself - trait GeneralTraitSuper { + trait GeneralTraitSuper: _Downcast_GeneralTrait + AnyRef + _Downcast_GeneralTraitSuperChild { fn _clone(&self) -> Box>; - fn _is_GeneralTrait(&self) -> bool; - fn _as_GeneralTrait(&self) -> Box; - fn _is_Datatype(&self) -> bool; - fn _as_Datatype(&self) -> ADatatype; } + trait GeneralTraitSuperChild: GeneralTraitSuper { + fn _clone(&self) -> Box>; + } + + trait _Downcast_GeneralTraitSuperChild { + fn _is(&self) -> bool; + fn _as(&self) -> Box>; // For trait objects, Object or Ptr instead of Box + } + impl Clone for Box> { fn clone(&self) -> Self { GeneralTraitSuper::_clone(self.as_ref()) @@ -1055,11 +1086,6 @@ mod tests { trait GeneralTrait: GeneralTraitSuper + UpcastBox> { fn _clone(&self) -> Box; } - impl UpcastBox> for Box { - fn upcast(&self) -> ::std::boxed::Box> { - crate::tests::tests::GeneralTraitSuper::::_clone(self.as_ref()) - } - } impl Clone for Box { fn clone(&self) -> Self { GeneralTrait::_clone(self.as_ref()) @@ -1080,25 +1106,33 @@ mod tests { Box::new(self.clone()) as Box } } - impl GeneralTraitSuper for ADatatype { - fn _clone(&self) -> Box> { - Box::new(self.clone()) + impl _Downcast_ADatatype for dyn Any { + fn _is(&self) -> bool { + self.downcast_ref::().is_some() } - - fn _is_GeneralTrait(&self) -> bool { + fn _as(&self) -> ADatatype { + self.downcast_ref::().unwrap().clone() // Optimization: Could be unwrap_unchecked + } + } + impl _Downcast_GeneralTrait for T { + fn _is(&self) -> bool { true } - - fn _as_GeneralTrait(&self) -> Box { + fn _as(&self) -> Box { GeneralTrait::_clone(self) } - - fn _is_Datatype(&self) -> bool { - true + } + impl GeneralTraitSuper for ADatatype { + fn _clone(&self) -> Box> { + Box::new(self.clone()) } - - fn _as_Datatype(&self) -> ADatatype { - self.clone() + } + impl _Downcast_GeneralTraitSuperChild for ADatatype { + fn _is(&self) -> bool { + false + } + fn _as(&self) -> Box> { + panic!("cannot") } } impl UpcastBox for ADatatype { @@ -1111,26 +1145,82 @@ mod tests { GeneralTraitSuper::::_clone(self) } } + + #[derive(Clone, PartialEq, Debug)] + pub struct CDatatype { i: u32 } + impl _Downcast_CDatatype for dyn Any { + fn _is(&self) -> bool { + self.downcast_ref::().is_some() + } + fn _as(&self) -> CDatatype { + self.downcast_ref::().unwrap().clone() // Optimization: Could be unwrap_unchecked + } + } + impl UpcastBox> for CDatatype { + fn upcast(&self) -> ::std::boxed::Box> { + GeneralTraitSuper::::_clone(self) + } + } + impl UpcastBox> for CDatatype { + fn upcast(&self) -> ::std::boxed::Box> { + GeneralTraitSuperChild::::_clone(self) + } + } + + impl GeneralTraitSuper for CDatatype { + fn _clone(&self) -> Box> { + Box::new(self.clone()) + } + } + impl GeneralTraitSuperChild for CDatatype { + fn _clone(&self) -> Box> { + Box::new(self.clone()) + } + } + impl _Downcast_GeneralTraitSuperChild for CDatatype { + fn _is(&self) -> bool { + true + } + fn _as(&self) -> Box> { + GeneralTraitSuperChild::::_clone(self) + } + } + impl _Downcast_GeneralTrait for CDatatype { // CDatatype does not extend general trait + fn _is(&self) -> bool { + false + } + fn _as(&self) -> Box { + panic!("CDatatype does not extend GeneralTrait") + } + } #[test] fn test_general_traits() { let x = ADatatype { i: 3 }; let gt = upcast_box::()(x.clone()); let gts = upcast_box::>()(x.clone()); let gtgts = upcast_box_box::>()(gt.clone()); - assert!(gt._is_Datatype()); - assert!(gts._is_Datatype()); - assert!(gtgts._is_Datatype()); - assert!(gts._is_GeneralTrait()); - assert!(gtgts._is_GeneralTrait()); - assert_eq!(gt._as_Datatype(), x); - assert_eq!(gts._as_Datatype(), x); - assert_eq!(gtgts._as_Datatype(), x); - let gtsgt = gts._as_GeneralTrait(); - let gtgtsgt = gtgts._as_GeneralTrait(); - assert!(gtsgt._is_Datatype()); - assert!(gtgtsgt._is_Datatype()); - assert_eq!(gtsgt._as_Datatype(), x); - assert_eq!(gtsgt._as_Datatype(), x); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>)))); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>s)))); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>gts)))); + assert!(_Downcast_GeneralTrait::_is(AsRef::as_ref(>s))); + assert!(_Downcast_GeneralTrait::_is(AsRef::as_ref(>gts))); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>))), x); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>s))), x); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>gts))), x); + let gtsgt = _Downcast_GeneralTrait::_as(AsRef::as_ref(>s)); + let gtgtsgt = _Downcast_GeneralTrait::_as(AsRef::as_ref(>gts)); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>sgt)))); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>gtsgt)))); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>sgt))), x); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>sgt))), x); + let xc = CDatatype{i: 3}; + let gtc = upcast_box::>()(xc.clone()); + let gcsc = upcast_box::>()(xc.clone()); + let gtcsc = _Downcast_GeneralTraitSuperChild::::_as(AsRef::as_ref(>c)); + let xc1 = _Downcast_CDatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(&gcsc))); + let xc2 = _Downcast_CDatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>csc))); + assert_eq!(xc, xc1); + assert_eq!(xc, xc2); } #[test] diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arc/tokiouser.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arc/tokiouser.dfy index add2a31a9f0..8623ffe74c7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arc/tokiouser.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arc/tokiouser.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny translate rs --rust-module-name=tokiouser --include-runtime=true --rust-sync "%s" > "%t" +// RUN: %baredafny translate rs --enforce-determinism --rust-module-name=tokiouser --include-runtime=true --rust-sync "%s" > "%t" // RUN: "%S/tokiouser-rust/cargo" run >> "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy index 5f11c241c18..0d4e49fd99e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" module Origin.Imported { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy.expect index 2f22d47cee8..3e2cf8d0f69 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy.expect @@ -1,3 +1,3 @@ -Dafny program verifier finished with 3 verified, 0 errors +Dafny program verifier finished with 4 verified, 0 errors ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy index aae1bce74e3..29ed516831f 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Can't create class instances without constructors as Rust does not support Dafny defaults since subset types are erased -// RUN: %exits-with 3 %baredafny run --target=rs "%s" > "%t" +// RUN: %exits-with 2 %baredafny run %args --enforce-determinism --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" class Test { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect index 37c2ed71ea8..2d4b7485fd5 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect @@ -1,3 +1,2 @@ - -Dafny program verifier finished with 2 verified, 0 errors -(0,-1): Error: Microsoft.Dafny.UnsupportedInvalidOperationException: Creation of object of type Test requires a constructor +autoinit.dfy(5,6): Error: since fields are initialized arbitrarily, constructor-less classes are forbidden by the --enforce-determinism option +1 resolution/type errors detected in autoinit.dfy diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy index 2335ca7bd41..0c9cc1c045b 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy @@ -1,7 +1,7 @@ -// RUN: %baredafny build -t:rs "%s" +// RUN: %baredafny build -t:rs --enforce-determinism "%s" // RUN: "%S/avoid_soundness_mut-rust/cargo" run --release > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny build -t:rs --raw-pointers "%s" +// RUN: %baredafny build -t:rs --enforce-determinism --raw-pointers "%s" // RUN: "%S/avoid_soundness_mut-rust/cargo" run --release > "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy index e9759a8df57..b36d8fe3b56 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code "%s" > "%t" +// RUN: %baredafny run --target=rs --emit-uncompilable-code --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype U8 = x: int | 0 <= x <= 255 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy index 913b7d42298..6dfbf341c0a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargoreleasefailure.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargoreleasefailure.dfy index e247b923cfc..4b8fb20498c 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargoreleasefailure.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargoreleasefailure.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny build --target=rs "%s" +// RUN: %baredafny build --target=rs --enforce-determinism "%s" // If there is no '#[inline(never)]' in front of ::dafny_runtime::increment_strong_count // then the release will think it's safe to remove the strong count increment, resulting ins a segfault // RUN: "%S/cargoreleasefailure-rust/cargo" run --release diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargotest.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargotest.dfy index be2eee7921d..f977c83265e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargotest.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargotest.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test of cargo test to support Dafny tests -// RUN: %baredafny build --target=rs "%s" > "%t" +// RUN: %baredafny build --target=rs "%s" --enforce-determinism > "%t" // RUN: %exits-with 101 "%S/cargotest-rust/cargo" test >> "%t" // RUN: %OutputCheck --file-to-check "%t" "%S/cargotest1.check" // RUN: %OutputCheck --file-to-check "%t" "%S/cargotest2.check" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy new file mode 100644 index 00000000000..11aff7e12fc --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy @@ -0,0 +1,36 @@ +// NONUNIFORM: Rust does not support relaxed definite assignment +// RUN: %exits-with 3 %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.wrong.expect" "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +datatype D = D(value: int) + +class Y { + var c: int + const d: D + constructor(c: int) ensures this.c == c && d.value == c { + this.c := c; + if c == 1 { + this.d := D(1); + } else { + this.d := D(c); + } + } + + constructor Two(c: int, b: bool) ensures this.c == c && d.value == c + requires b + { + this.c := c; // d not assigned, compilation error. + if b { + this.d := D(c); + } + // This will emit a conditional panick but Dafny will prove it's unreachable + } +} + +method Main() { + var y := new Y(1); + var y2 := new Y.Two(1, true); + print "Instantiation successful"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.expect new file mode 100644 index 00000000000..ec136887e83 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 3 verified, 0 errors +Instantiation successful \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect new file mode 100644 index 00000000000..85b25e3a4d4 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 3 verified, 0 errors +(0,-1): Error: Microsoft.Dafny.UnsupportedInvalidOperationException: The Rust compiler requires `--enforce-determinism` diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy index 3bc5b6caeb3..00a660ca76a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy @@ -1,22 +1,28 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs "%s" --enforce-determinism > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %baredafny run --target=rs --raw-pointers --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" +datatype D = D(value: int) + class Y { var c: int ghost var Repr: set - const d: int - constructor(c: int) ensures this.c == c && d == c { + const d: D + constructor(c: int) ensures this.c == c && d.value == c { this.c := c; - this.d := c; + if c == 1 { + this.d := D(1); + } else { + this.d := D(c); + } this.Repr := {this}; } - constructor Two() ensures c == 2 == d { + constructor Two() ensures c == 2 == d.value { this.c := 2; - this.d := c; + this.d := D(c); this.Repr := {this}; } } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy index aa003792960..361abda170a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Tests that references to function constants are eta-expanded with an additional call and type annotations in Rust backend -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" const f: int -> int := x => x diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy index f964dbdb778..59f99839799 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %baredafny run --target=rs --raw-pointers --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" method Main() { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy index a655ada01ce..67ce2882e61 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype Uint8 = x: int | 0 <= x < 256 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-impl.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-impl.dfy index 643a2592ec0..7c084843d64 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-impl.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-impl.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Tests generation of print, and equality in Rust for function / non-(==) type members -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype F = F(i: nat, f: int -> int) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy index 4bde1628787..a4abdb8d3b5 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy @@ -1,9 +1,25 @@ // NONUNIFORM: Tests that datatype members like hash do not shadow those generated by Rust backend -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype Loop = Loop(loop: Loop) | Point() { function hash(): string { - "uh-oh!" + "This is Dafny Hash" } +} + +datatype Loop2 = Loop2(loop: Loop) { + method hash() { + print "\nThis is Dafny hash 2"; + } + + method doHash() { + hash(); + } +} + +method Main() { + var t := Loop(Point()); + print t.hash(); + Loop2(t).hash(); } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect index 012f5b99379..9f527b44866 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect @@ -1,2 +1,4 @@ -Dafny program verifier finished with 0 verified, 0 errors +Dafny program verifier finished with 2 verified, 0 errors +This is Dafny Hash +This is Dafny hash 2 \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy index ef835701c2e..9d22f5fc68d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Demonstration of the use of the external Rust Option<> type -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --raw-pointers "%s" > "%t" // RUN: %diff "%s.expect" "%t" module {:compile false} {:extern "::std::option"} RustStdOption { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.check index 729d2cd907b..3104041c564 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.check @@ -13,5 +13,6 @@ // CHECK: .*/// Docstring for module.* // CHECK: .*/// Docstring for classes 2.* // CHECK: .*/// Allocates an UNINITIALIZED instance. Only the Dafny compiler should use that.* +// CHECK: .*/// Docstring for class constructor.* // CHECK: .*/// Docstring for predicate.* -// CHECK: .*/// Docstring for const.* +// CHECK: .*/// Docstring for const.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy index fbe65714621..6b150021094 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test that the Rust generated code contains docstrings -// RUN: %baredafny build --target:rs "%s" > "%t" +// RUN: %baredafny build --target:rs --enforce-determinism "%s" > "%t" // RUN: %OutputCheck --file-to-check "%S/docstring-rust/src/docstring.rs" "%S/docstring.check" // RUN: "%S/docstring-rust/cargo" test --doc @@ -44,6 +44,10 @@ module SubModule { class TestClass { /** Docstring for const */ const testConst: bool + /** Docstring for class constructor */ + constructor() { + testConst := true; + } predicate SingleLineFunction() { true } // Docstring for predicate } } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy index ec117b68b5c..7b823dea94d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Tests generation of elephant assignment to shadowed variable -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype Option = Some(value: string) | None() { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy index ebec1203fcf..896ae8aac06 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %exits-with 3 %baredafny run --target=rs --input "%S/externalclasses.rs" "%s" > "%t" +// RUN: %exits-with 3 %baredafny run --target=rs --enforce-determinism --input "%S/externalclasses.rs" "%s" > "%t" // RUN: %diff "%s.expect" "%t" module {:extern} ExternalClassContainer { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy index c6d50772615..5392aa83f4a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy @@ -1,8 +1,11 @@ -// NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --input "%S/externalclasses.rs" "%s" > "%t" +// NONUNIFORM: Rust-specific tests. Extern abstract types only compile with the Rust compiler for now. +// RUN: %baredafny run --target=rs --enforce-determinism --input "%S/externalclasses.rs" "%s" > "%t" // RUN: %diff "%s.expect" "%t" module {:extern "External.Class.Container"} ExternalClassContainer { + @NativeUInt64 + newtype u64 = x : int | 0 <= x <= 0xFFFF_FFFF_FFFF_FFFF + class {:extern} ExternalClass { constructor {:extern} (i: int) } @@ -27,6 +30,13 @@ module {:extern "External.Class.Container"} ExternalClassContainer { print GetValue(); } } + + type {:extern "StringWrapper"} RustString { + ghost const s: string + static function from_char(s: char): RustString + function concat(other: RustString): RustString + function length_bytes(): u64 + } } module Dafny.FileIO { @@ -99,5 +109,9 @@ method Main() { n.Put("x"); expect n.Get() == "x"; expect n.GetOpt() == "Some(x)"; + var a := ExternalClassContainer.RustString.from_char('a'); + expect a.length_bytes() == 1; + a := a.concat(a); + expect a.length_bytes() == 2; print message; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect index 86c68713487..9fa90752819 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect @@ -1,3 +1,3 @@ -Dafny program verifier finished with 7 verified, 0 errors +Dafny program verifier finished with 8 verified, 0 errors 22Everything is ok. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs index e061478f099..b444323ef7a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs @@ -4,7 +4,25 @@ pub mod External { pub mod Class { pub mod Container { + use std::str::FromStr; + + use dafny_runtime::DafnyChar; + use crate::*; + pub struct StringWrapper(String); + impl StringWrapper { + pub(crate) fn from_char(c: &DafnyChar) -> StringWrapper { + StringWrapper(String::from(c.0)) + } + + pub(crate) fn length_bytes(&self) -> u64 { + self.0.len() as u64 + } + + pub(crate) fn concat(&self, a: &StringWrapper) -> StringWrapper { + StringWrapper(format!("{}{}", self.0, a.0)) + } + } pub struct ExternalClass {} impl ExternalClass { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy index 48c223f62e6..0fc3c6f25e0 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy @@ -1,4 +1,6 @@ -// RUN: %testDafnyForEachCompiler --refresh-exit-code=0 "%s" +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" +// RUN: %diff "%s.expect" "%t" newtype uint8 = x: int | 0 <= x < 256 @@ -19,5 +21,7 @@ predicate p'(b: seq) { if |b| > 0 then !b[0] else false } predicate X''() { F'(p') } method Main() { - print Fn((a: uint8, b: uint8) => a == b, 2 as uint8), "\n"; + var f := (a: uint8, b: uint8) => a == b; + print f, "\n"; + print Fn(f, 2 as uint8), "\n"; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect index 27ba77ddaf6..eb269495cdd 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect @@ -1 +1,4 @@ + +Dafny program verifier finished with 3 verified, 0 errors + true diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy index 4edda6ead2b..75ad3fccc79 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype u8 = x: int | 0 <= x < 10 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy.expect index 565ec0b036a..5740940b809 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy.expect @@ -1,4 +1,4 @@ -Dafny program verifier finished with 5 verified, 0 errors +Dafny program verifier finished with 6 verified, 0 errors hello world hello world{1} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy index 06db986522e..0d143414966 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --unicode-char=false "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --unicode-char=false "%s" > "%t" // RUN: %diff "%s.expect" "%t" function Map(m: map): map { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy index 816c9ca9f03..20ca04e23ca 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype NativeNotZero = x: int | 1 <= x < 255 witness 1 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/moduleordering.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/moduleordering.dfy index 543a05b0e48..e1d145a3473 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/moduleordering.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/moduleordering.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test of the Rust compiler to ensure it emits modules in a deterministic order. -// RUN: %baredafny translate rs "%s" > "%t" +// RUN: %baredafny translate rs --enforce-determinism "%s" > "%t" // RUN: %OutputCheck --file-to-check "%S/moduleordering-rust/src/moduleordering.rs" "%s" // CHECK-L: pub mod A { // CHECK-L: pub mod B { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy index c8284779462..432c56071a2 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" // Checks that, despite module B being prefixed with A, there will be a "mod B" somewhere // and not an encoding like "mod A_B". diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy index fe08c8d50e0..2471201a45e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Testing explicit newtype conversion of bounded ranges in Rust backend -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype uint8 = x: int | 0 <= x < 0x100 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy index 79f6a2ac4de..b83173b10b7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy @@ -1,6 +1,6 @@ // NONUNIFORM: Test of Rust's ability to support newtypes -// RUN: %baredafny run -t:rs "%s" -// RUN: %baredafny run -t:rs --unicode-char=false "%s" +// RUN: %baredafny run -t:rs --enforce-determinism "%s" +// RUN: %baredafny run -t:rs --unicode-char=false --enforce-determinism "%s" /// %testDafnyForEachCompiler --refresh-exit-code=0 "%s" newtype int2 = x: int | -2 <= x < 2 @@ -141,7 +141,7 @@ method Main(){ print [0, 1, 2][Zero], "\n"; print [0, 1, 2][Zero..INT2_MAX], "\n"; var f: CodeUnit -> byte := c => c as byte; - var arr := new bool[INT2_MAX]; + var arr := new bool[INT2_MAX](i => true); print arr.Length, "\n"; print DChar as uint32, "\n"; diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy index 572d54490b3..4adba11b7a4 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test of Rust's ability to support newtypes -// RUN: %baredafny run -t:rs --type-system-refresh --general-newtypes "%s" +// RUN: %baredafny run -t:rs --type-system-refresh --general-newtypes --enforce-determinism "%s" newtype BoolWrapper = bool { const n: int := if this then 1 else 0 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nomaybeplacebos.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nomaybeplacebos.dfy index c1e2d2101ca..d4e006b9ce1 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nomaybeplacebos.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nomaybeplacebos.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test of the output of the Rust translation -// RUN: %baredafny translate rs "%s" > "%t" +// RUN: %baredafny translate rs --enforce-determinism "%s" > "%t" // RUN: %OutputCheck --file-to-check "%S/nomaybeplacebos-rust/src/nomaybeplacebos.rs" "%S/nomaybeplacebos.check" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy index 663b59551c4..534372f50ec 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" ghost const TWO_TO_THE_8: int := 0x100 ghost const TWO_TO_THE_16: int := 0x10000 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy index e90b5bc69af..860de2db1d3 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Tests output of Rust translation from input Dafny that uses Rust reserved names -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype X = diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy new file mode 100644 index 00000000000..0480566e84e --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy @@ -0,0 +1,22 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function Compare(a: T, b: T): bool +} + +trait Sub extends Super { + function Compare(a: T, b: T): bool { + a == b + } +} + +datatype IntOps extends Sub = IntOps { +} + +method Main() { + expect IntOps().Compare(1, 1); + expect !IntOps().Compare(1, 2); + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect new file mode 100644 index 00000000000..d2b8ffb5439 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy new file mode 100644 index 00000000000..67452b91abc --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy @@ -0,0 +1,17 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function Get(): T +} + +datatype KeysValue extends Super = KeysValue(keys: set, value: V) { + function Get(): V { value } +} + +method Main() { + expect KeysValue({1}, 3).Get() == 3; + expect (KeysValue({1}, 5) as Super).Get() == 5; + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect new file mode 100644 index 00000000000..d2b8ffb5439 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy new file mode 100644 index 00000000000..9f856cad7ad --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy @@ -0,0 +1,29 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function get(d:D,ks:K):(r:int) +} +datatype ZeroComputation = ZeroComputation { + function top(): int { 0 } +} + +datatype ComputationWrapper extends Super = ComputationWrapper { + function Computation_():ZeroComputation { ZeroComputation } + const computation := Computation_() + function get(d:K,ks:K):(r:int) { + computation.top() + } + function Copy(): ComputationWrapper { + this + } + function AsSuper(): Super { + this as Super + } +} + +method Main() { + expect ComputationWrapper.ComputationWrapper().Copy().get(1, 2) == 0; + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect new file mode 100644 index 00000000000..d2b8ffb5439 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy new file mode 100644 index 00000000000..3293982cb3f --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy @@ -0,0 +1,28 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function AsSuper(): Super + function GetInt(): int + + function GetDoubleInt(): int { + GetInt() * 2 + } +} + +datatype Sub extends Super = Sub { + function AsSuper(): Super { + this + } + function GetInt(): int { + 3 + } + function Total(): int { + this.AsSuper().GetInt() + this.GetDoubleInt() + } +} + +method Main() { + expect Sub().Total() == 9; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect new file mode 100644 index 00000000000..ebe2328e072 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect @@ -0,0 +1,2 @@ + +Dafny program verifier finished with 2 verified, 0 errors diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy new file mode 100644 index 00000000000..cf535da2dce --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy @@ -0,0 +1,36 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Q { + function put():(r:OM) +} + +datatype Getter = Getter { + function get():(r:Single) { + Single + } +} + +datatype {:rust_rc false} Option = + | None + | Some(v:T) + +datatype Single_ = Single + +type Single = t:Single_ | true witness * + +type OM = Option> + +datatype ComplexCase extends Q = ComplexCase { + const getter := Getter + + function put():(r:OM) { + var xya := getter.get(); + None + } +} + +method Main() { + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect new file mode 100644 index 00000000000..2f22d47cee8 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 3 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy new file mode 100644 index 00000000000..0e26632e7b7 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy @@ -0,0 +1,45 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=datatype --general-newtypes "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait SuperTrait { + function toString(): string +} + +trait SubSuperTrait extends SuperTrait { +} + +method PrintTwice(k: K) { + print (k as SuperTrait).toString(); + print (k as SuperTrait).toString(); +} + +datatype TestPrintTwice extends SubSuperTrait = TestPrintTwice { + function toString(): string { "hello" } +} + +datatype NoSupportEquality extends SuperTrait = NoSupportEquality(ghost f: int -> int) { + function toString(): string { "Not a string" } +} + +newtype MapWrapper = x: map | true { + predicate Empty() { + |this| == 0 + } +} + +newtype SeqWrapper = x: seq | true { + predicate Empty() { + |this| == 0 + } +} + +method Main() { + expect (map[] as MapWrapper).Empty(); + expect !(map[1 := 2] as MapWrapper).Empty(); + expect ([] as SeqWrapper).Empty(); + expect !([1] as SeqWrapper).Empty(); + PrintTwice(TestPrintTwice()); + PrintTwice((TestPrintTwice() as SubSuperTrait)); + PrintTwice((TestPrintTwice() as SuperTrait)); +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect new file mode 100644 index 00000000000..6a661c1e0cb --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 5 verified, 0 errors +hellohellohellohellohellohello \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy new file mode 100644 index 00000000000..50ffe337230 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy @@ -0,0 +1,20 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function Compare(a: T, b: T, c: bool): bool + decreases a +} + +datatype BoolOps extends Super = BoolOps { + function Compare(a: bool, b: bool, c: bool): bool { + a == b + } +} + +method Main() { + expect BoolOps().Compare(true, true, true); + expect !BoolOps().Compare(true, false, true); + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect new file mode 100644 index 00000000000..d2b8ffb5439 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy new file mode 100644 index 00000000000..e345b09d519 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy @@ -0,0 +1,52 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Reversible { + function reverse():(r:Reversible) +} + +trait SubReversible extends Reversible { + function reverse():(r:Reversible) +} + +datatype {:rust_rc false} Ping extends Reversible, SubReversible = Ping { + function reverse():(r:Reversible) { Pong } +} + +datatype {:rust_rc false} Pong extends Reversible, SubReversible = Pong { + function reverse():(r:Reversible) { Ping } +} + + +trait Singleton { + function id():G +} + + +trait A { + function g():Singleton +} + + +trait F extends A { + function g():Singleton { Zero } +} + +datatype Zero extends Singleton = Zero { + function id(): int { 0 } +} + +datatype C extends F = C { +} + +trait RequiresEquality { +} +datatype TraitExtender extends RequiresEquality> = TraitExtender {} + +method Main() { + var x := Pong; + expect x.reverse() is Ping; + expect Ping().reverse() is Pong; + print "ping pong"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect new file mode 100644 index 00000000000..9a27c3259f3 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 5 verified, 0 errors +ping pong \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy new file mode 100644 index 00000000000..4b364514a33 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy @@ -0,0 +1,11 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --emit-uncompilable-code "%s" > "%t" + +datatype Super = Super + +datatype Test = Test { + static const cloud := Super.Super +} + +method Main() { +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy new file mode 100644 index 00000000000..0c57025a656 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy @@ -0,0 +1,59 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +datatype I_ = I_(t: T, u: U) + +type I = x: I_ | true witness * + +datatype {:rust_rc false} A = A(B: I) + +datatype {:rust_rc false} M_ = M_(m: map) + +type M = x: M_ | true witness * + +trait O {} + +datatype U = U(o: O) + +datatype G = G(m1: map, m2: map, m3: map) + +type F = g: G | true witness * + +datatype V = V(u: U>) + +datatype Phantom = Phantom() + +datatype WithGhost_ = WithGhost(i: int, ghost n: int) + +type WithGhost = x: WithGhost_ | true witness * + +datatype {:rust_rc false} WithGhostWrapper = WithGhostWrapper(r:WithGhost) + +type DoubleWithGhost = t:(WithGhostWrapper,WithGhostWrapper) | true witness * + +datatype {:rust_rc false} DoubleWithGhostWrapper = DoubleWithGhostWrapper( + dwg:DoubleWithGhost +) + +datatype Wrapper1 = Wrapper1(w1: T) +datatype Wrapper2 = Wrapper2(w2: T) +datatype Wrapper3 = Wrapper3(w21: Wrapper2>) { + function ReturnThis(f: Wrapper3 -> Wrapper3): Wrapper3 { + f(this) + } +} + +method Test() { +} + +method Main() { + Test>(); + Test>(); + Test>(); + Test>(); + Test, int>>(); + Test>(); + //Test int>>(); + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect new file mode 100644 index 00000000000..d2b8ffb5439 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy index 44b1a168f10..408f72063b8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy @@ -1,8 +1,8 @@ // NONUNIFORM: Test of the output of the Rust translation -// RUN: %baredafny run --target=rs --unicode-char=true "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --unicode-char=true "%s" > "%t" // RUN: %diff "%s.expect" "%t" // RUN: %OutputCheck --file-to-check "%S/strings-rust/src/strings.rs" "%S/strings-unicode.check" -// RUN: %baredafny run --target=rs --unicode-char=false "%s" +// RUN: %baredafny run --target=rs --enforce-determinism --unicode-char=false "%s" // RUN: %diff "%s.expect" "%t" // RUN: %OutputCheck --file-to-check "%S/strings-rust/src/strings.rs" "%S/strings-utf16.check" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy index cad15372a6b..6a5f5d3febd 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" // RUN: %OutputCheck --file-to-check "%S/subsetconstraints-rust/src/subsetconstraints.rs" "%S/subsetconstraints.check" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/tests.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/tests.dfy index e431975b417..c1214daeb0a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/tests.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/tests.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Test of the Dafny-to-Rust tests -// RUN: %baredafny test --target=rs "%s" > "%t" +// RUN: %baredafny test --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t -// RUN: %baredafny build --compile-suffix --target=rs "%s" > "%t" +// RUN: %baredafny build --compile-suffix --target=rs --enforce-determinism "%s" > "%t" // RUN: "%S/tests-rust/cargo" run -- Hello > "%t" // RUN: %diff "%s.main.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy index 0dace953dd9..ada5639be1f 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -1,14 +1,19 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --type-system-refresh --general-traits=datatype "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=datatype "%s" > "%t" // RUN: %diff "%s.expect" "%t" - -trait DatatypeOps { +trait SuperTrait { + function GetBool(): bool +} +trait SuperSubTrait extends SuperTrait { + const DecideOtherwise := !GetBool() +} +trait DatatypeOps extends SuperSubTrait { function GetInt(): int function GetBool(): bool { GetInt() % 2 == 0 } function ChooseAmong(a: T, b: T): T { - if GetBool() then a else b + if !DecideOtherwise then a else b } method ChooseAmongMethod(a: T, b: T) returns (c: T) { if GetBool() { @@ -26,7 +31,34 @@ datatype {:rust_rc false} ADatatype extends DatatypeOps = ADatatype(i: int) function GetInt(): int { i } } -method Main() { + +datatype BDatatype extends DatatypeOps = BDatatype(i: int) { + function AsDatatypeOps(): DatatypeOps { + this as DatatypeOps + } + function GetInt(): int { i } +} + +datatype CDatatype extends SuperTrait = CDatatype(i: int) { // But not superSubTrait + function GetBool(): bool { + i % 2 == 0 + } +} + +method StaticWithGenerics(c: bool, a: T, b: T) returns (t: T){ + if c { + t := a; + } else { + t := b; + } +} +function StaticWithGenericsFn(c: bool, a: T, b: T): (t: T){ + if c then a else b +} + +datatype TW = TW(d: DatatypeOps) {} + +method MainADatatype() { var x := ADatatype(2); expect x.GetInt() == 2; expect x.GetBool() == true; @@ -51,5 +83,94 @@ method Main() { expect y1.ChooseAmong(8, 9) == 9; var y1m := y1.ChooseAmongMethod(8, 9); expect y1m == 9; + var zy := y as SuperTrait; + var zx := x as SuperTrait; + expect zx.GetBool(); + expect !zy.GetBool(); + var xory1a := StaticWithGenerics(true, x1, y1); + var xory1b := StaticWithGenerics(false, x1, y1); + var xory1c := StaticWithGenericsFn(true, x1, y1); + var xory1d := StaticWithGenericsFn(false, x1, y1); + var tw := TW(x1); + expect tw.d.GetInt() == 2; + expect TW(xory1a) == TW(x1) == TW(xory1c) != TW(y1); // If not wrapped, Dafny complains + expect TW(xory1b) == TW(y1) == TW(xory1d) != TW(x1); + print x1, "\n"; // Ensure we can print even if behind trait + print TW(x1) == TW(x1), "\n"; // True + print TW(x1) == TW(y1), "\n"; // False + var sx := x1 as SuperTrait; + expect sx is SuperSubTrait; + var sx1 := sx as SuperSubTrait; + var sx1x := sx1 as SuperTrait; + expect sx is ADatatype; + expect !(sx is BDatatype); + var sxa := sx as ADatatype; +} + + +method MainBDatatype() { + var x := BDatatype(2); + expect x.GetInt() == 2; + expect x.GetBool() == true; + expect x.ChooseAmong(8, 9) == 8; + var xm := x.ChooseAmongMethod(8, 9); + expect xm == 8; + var y := BDatatype(3); + expect y.GetInt() == 3; + expect y.GetBool() == false; + expect y.ChooseAmong(8, 9) == 9; + var ym := y.ChooseAmongMethod(8, 9); + expect ym == 9; + var x1 := x.AsDatatypeOps(); // Dynamic dispatch now. + expect x1.GetInt() == 2; + expect x1.GetBool() == true; + expect x1.ChooseAmong(8, 9) == 8; + var x1m := x1.ChooseAmongMethod(8, 9); + expect x1m == 8; + var y1 := y.AsDatatypeOps(); + expect y1.GetInt() == 3; + expect y1.GetBool() == false; + expect y1.ChooseAmong(8, 9) == 9; + var y1m := y1.ChooseAmongMethod(8, 9); + expect y1m == 9; + var zy := y as SuperTrait; + var zx := x as SuperTrait; + expect zx.GetBool(); + expect !zy.GetBool(); + var xory1a := StaticWithGenerics(true, x1, y1); + var xory1b := StaticWithGenerics(false, x1, y1); + var xory1c := StaticWithGenericsFn(true, x1, y1); + var xory1d := StaticWithGenericsFn(false, x1, y1); + var tw := TW(x1); + expect tw.d.GetInt() == 2; + expect TW(xory1a) == TW(x1) == TW(xory1c) != TW(y1); // If not wrapped, Dafny complains + expect TW(xory1b) == TW(y1) == TW(xory1d) != TW(x1); + print x1, "\n"; // Ensure we can print even if behind trait + print TW(x1) == TW(x1), "\n"; // True + print TW(x1) == TW(y1), "\n"; // False + var sx := x1 as SuperTrait; + expect sx is SuperSubTrait; + var sx1 := sx as SuperSubTrait; + var sx1x := sx1 as SuperTrait; + expect sx is BDatatype; + expect !(sx is ADatatype); + var sxa := sx as BDatatype; +} + +method MainCDatatype() { + var c := CDatatype(1); + var s := c as SuperTrait; + expect c.GetBool() == s.GetBool(); + expect !(s is SuperSubTrait); + expect c is CDatatype; + expect !(s is ADatatype); + var d := s as CDatatype; + expect c == d; +} + +method Main() { + MainADatatype(); + MainBDatatype(); + MainCDatatype(); print "Main passed all the tests"; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect index f896bad9217..5cd1da2b7ff 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect @@ -1,3 +1,9 @@ -Dafny program verifier finished with 4 verified, 0 errors +Dafny program verifier finished with 12 verified, 0 errors +ADatatype.ADatatype(2) +true +false +BDatatype.BDatatype(2) +true +false Main passed all the tests \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy index bf9fa40f586..69dc1922d1d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" module InterfaceHolder { @@ -76,6 +76,7 @@ module All { const d: int := 2 constructor(c: int) { this.c := c; + this.z := 3; } method AddZ() modifies this diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect index 506e5ca1d4c..6dc0be4af2c 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect @@ -1,3 +1,3 @@ -Dafny program verifier finished with 21 verified, 0 errors +Dafny program verifier finished with 23 verified, 0 errors Main passed all the tests diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/translate-additional/more_dafny.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/translate-additional/more_dafny.dfy index c55fc26cb3f..f51583bc45b 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/translate-additional/more_dafny.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/translate-additional/more_dafny.dfy @@ -1,4 +1,4 @@ -// RUN: %baredafny translate rs --rust-module-name additional_module "%S/more_dafny_extern.rs" "%s" +// RUN: %baredafny translate rs --enforce-determinism --rust-module-name additional_module "%S/more_dafny_extern.rs" "%s" // RUN: %exits-with -any %rm -f "%S/project_depending_on_dafny/src/additional_module.rs" // RUN: %exits-with -any %rm -f "%S/project_depending_on_dafny/src/more_dafny_extern.rs" // RUN: %mv "%S/more_dafny-rust/src/more_dafny.rs" "%S/project_depending_on_dafny/src/additional_module.rs" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy index 75ee7a0c39c..7e84abc1143 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Tests that type tests work in the Rust backend -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --raw-pointers "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait T { } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Tooltips.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Tooltips.dfy.expect index db3d6ab324c..9ef12d2cb20 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Tooltips.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Tooltips.dfy.expect @@ -3,8 +3,8 @@ Tooltips.dfy(4,7): Info: (==) Tooltips.dfy(6,8): Info: (==) Tooltips.dfy(7,8): Info: (==) Tooltips.dfy(9,12): Info: (==) -Tooltips.dfy(10,13): Info: (==) Tooltips.dfy(12,12): Info: (==) +Tooltips.dfy(10,13): Info: (==) Tooltips.dfy(13,15): Info: (==) Tooltips.dfy(15,9): Info: (==) Tooltips.dfy(16,9): Info: (==) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy index 5be7c59ea24..c1acad3ecce 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy @@ -1,9 +1,8 @@ // NONUNIFORM: Testing robustness of Dafny/Rust backends wrt set comprehension -// RUN: %baredafny -noVerify -compileTarget:rs -compile:0 -functionSyntax:3 -spillTargetCode:3 "%s" > "%t" +// RUN: %baredafny build --function-syntax:3 --target:rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" module Spoo { - newtype uint8 = x: int | 0 <= x < 0x100 newtype uint16 = x: int | 0 <= x < 0x10000 function method UInt16ToSeq(x: uint16): (ret: seq) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect index 39be9965f21..ba00363fc08 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect @@ -1,5 +1,2 @@ -Warning: this way of using the CLI is deprecated. Use 'dafny --help' to see help for the new Dafny CLI format -Dafny program verifier did not attempt verification -Wrote textual form of target program to git-issue-5644-rust/src/git_issue_5644.rs -Additional output written to git-issue-5644-rust/src/git-issue-5644-rs.dtr +Dafny program verifier finished with 4 verified, 0 errors diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/InconsistentCompilerBehavior.dfy.testdafny.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/InconsistentCompilerBehavior.dfy.testdafny.expect index 7e24d9e430a..8a9c5026e3f 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/InconsistentCompilerBehavior.dfy.testdafny.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/InconsistentCompilerBehavior.dfy.testdafny.expect @@ -44,11 +44,4 @@ Diff (changing expected into actual): Executing on C++... Executing on Rust... -AssertEqualWithDiff() Failure -Diff (changing expected into actual): --Different than any output -+0 - - -(non-blocking) The Rust code generator is internal. Not having a '*.rs.check' file is acceptable for now. Executing on ResolvedDesugaredExecutableDafny... diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/TestBeyondVerifierExpect.dfy.testdafny.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/TestBeyondVerifierExpect.dfy.testdafny.expect index a881545e3bb..18486ce88ce 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/TestBeyondVerifierExpect.dfy.testdafny.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/TestBeyondVerifierExpect.dfy.testdafny.expect @@ -44,11 +44,4 @@ Diff (changing expected into actual): Executing on C++... Executing on Rust... -AssertEqualWithDiff() Failure -Diff (changing expected into actual): --good bye -+hello - - -(non-blocking) The Rust code generator is internal. Not having a '*.rs.check' file is acceptable for now. Executing on ResolvedDesugaredExecutableDafny... diff --git a/docs/DafnyRef/integration- rust/IntegrationRust.md b/docs/DafnyRef/integration- rust/IntegrationRust.md index 6eb44ff9d4b..e417cb84799 100644 --- a/docs/DafnyRef/integration- rust/IntegrationRust.md +++ b/docs/DafnyRef/integration- rust/IntegrationRust.md @@ -125,7 +125,50 @@ pub struct Ptr(pub Option>>); # Externs -You can provide additional `*.rs` files to `dafny translate`, `dafny build` and even `dafny run` (via the `--input` option) +You can provide additional `*.rs` files to `dafny translate`, `dafny build` and even `dafny run` (via the `--input` option). We recommend giving each extern file a suffix `_extern.rs` to avoid name collisions. To understand how to fill these extern files, consider the corresponding section. + +## Partial extern modules + +If a module is defined in Dafny, but has types defined as externs, make sure you mark your module with `{:extern }` where `` is typically the module name. +Then, in a file `_extern.rs` that you include with the build, put the following code: + +``` +pub mod { +} +``` + +and you've just got started with a skeleton to fill implementations for Dafny axioms. + +## Externally implemented traits and classes + +You can define an extern Dafny trait in your extern rust files. Consider the following Dafny general trait declaration: + +``` +trait {:extern} ForeignTrait {} +``` + +To implement this in your extern file, use the following template: +``` + pub trait ForeignTrait { + fn _clone(&self) -> Box; + } + + impl Clone for Box { + fn clone(&self) -> Self { + self._clone() + } + } + + impl ::dafny_runtime::DafnyPrint for Box { + fn fmt_print(&self, f: &mut std::fmt::Formatter<'_>, in_seq: bool) -> std::fmt::Result { + write!(f, "object") + } + } +``` + +For classes, make sure all your mutable fields are wrapped in a `::dafny_runtime::Field` so that it's always possible to share the reference. + +## Other externs The best way to see what you have to implement as an extern Rust file is to compile your code with extern attributes and adding an external Rust file. For extra methods or static methods, you would then define an additional implementation in the extern Rust file. For other class or struct types, you just need to define them without any `mod` wrapper, or using the module structure as defined in the `{:extern}` attribute. diff --git a/docs/HowToFAQ/Errors-Compiler.md b/docs/HowToFAQ/Errors-Compiler.md index da243df24e4..71b11482255 100644 --- a/docs/HowToFAQ/Errors-Compiler.md +++ b/docs/HowToFAQ/Errors-Compiler.md @@ -45,15 +45,6 @@ so the program will need to be revised to avoid this feature; The latter is an omission in the in-tool documentation. Please report this error message and the part of the program provoking it to the Dafny team's [issue tracker](https://github.com/dafny-lang/dafny/issues). -## **Error: Abstract type ('_type_') with extern attribute requires a compile hint. Expected {:extern _hint_}** {#c_abstract_type_needs_hint} - - -```dafny -type {:extern } T -``` - -The type needs a name given to know which type in the target language it is associated with. - ## **Error: Abstract type (_name_) cannot be compiled; perhaps make it a type synonym or use :extern.** {#c_abstract_type_cannot_be_compiled} diff --git a/docs/HowToFAQ/Errors-Compiler.template b/docs/HowToFAQ/Errors-Compiler.template index c6591bd1bce..0e4bec4dda4 100644 --- a/docs/HowToFAQ/Errors-Compiler.template +++ b/docs/HowToFAQ/Errors-Compiler.template @@ -24,15 +24,6 @@ -## **Error: Abstract type ('_type_') with extern attribute requires a compile hint. Expected {:extern _hint_}** {#c_abstract_type_needs_hint} - - -```dafny -type {:extern } T -``` - - - ## **Error: Abstract type (_name_) cannot be compiled; perhaps make it a type synonym or use :extern.** {#c_abstract_type_cannot_be_compiled} From cd5902f2562b0ffa33344d230f42749d38162298 Mon Sep 17 00:00:00 2001 From: Rustan Leino Date: Mon, 24 Feb 2025 11:23:05 -0800 Subject: [PATCH 2/2] fix: Fix crash when a simple forall statement was placed inside a match (#6121) Fixes #6120 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). --- .../AST/Statements/ControlFlow/ForallStmt.cs | 2 +- .../LitTests/LitTest/git-issues/git-issue-6120.dfy | 14 ++++++++++++++ .../LitTest/git-issues/git-issue-6120.dfy.expect | 2 ++ docs/dev/news/6121.fix | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-6120.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-6120.dfy.expect create mode 100644 docs/dev/news/6121.fix diff --git a/Source/DafnyCore/AST/Statements/ControlFlow/ForallStmt.cs b/Source/DafnyCore/AST/Statements/ControlFlow/ForallStmt.cs index 8e03cee1727..effd1971c13 100644 --- a/Source/DafnyCore/AST/Statements/ControlFlow/ForallStmt.cs +++ b/Source/DafnyCore/AST/Statements/ControlFlow/ForallStmt.cs @@ -57,7 +57,7 @@ public ForallStmt(Cloner cloner, ForallStmt original) : base(cloner, original) { Attributes = cloner.CloneAttributes(original.Attributes); if (cloner.CloneResolvedFields) { - Bounds = original.Bounds.ConvertAll(bp => bp.Clone(cloner)); + Bounds = original.Bounds.ConvertAll(bp => bp?.Clone(cloner)); Kind = original.Kind; EffectiveEnsuresClauses = original.EffectiveEnsuresClauses?.Select(cloner.CloneExpr).ToList(); } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-6120.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-6120.dfy new file mode 100644 index 00000000000..7ffe5a098c1 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-6120.dfy @@ -0,0 +1,14 @@ +// RUN: %testDafnyForEachResolver "%s" + + +datatype OnOff = On | Off + +lemma Test(t: OnOff) +{ + match t + case On => + case Off => + // The following once caused a crash + forall x: K {:trigger} { + } +} diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-6120.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-6120.dfy.expect new file mode 100644 index 00000000000..012f5b99379 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-6120.dfy.expect @@ -0,0 +1,2 @@ + +Dafny program verifier finished with 0 verified, 0 errors diff --git a/docs/dev/news/6121.fix b/docs/dev/news/6121.fix new file mode 100644 index 00000000000..aef330dbd84 --- /dev/null +++ b/docs/dev/news/6121.fix @@ -0,0 +1 @@ +Fix crash that could occur when a `forall` statement was used inside a `match` `case`