diff --git a/.gitignore b/.gitignore index beb07d34a9c..bb6f6c501c0 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,4 @@ Source/IntegrationTests/TestFiles/LitTests/LitTest/**/*.csproj /Source/IntegrationTests/TestFiles/LitTests/LitTest/pythonmodule/singlemodule/dafnysource/PythonModule1 /Source/DafnyCore/Prelude/DafnyPrelude.bpl /Source/DafnyCore/Prelude/Sequences.bpl +/venv diff --git a/Source/DafnyCore.Test/GeneratedDafnyTest.cs b/Source/DafnyCore.Test/GeneratedDafnyTest.cs index 58e73d0e958..8ae9b413006 100644 --- a/Source/DafnyCore.Test/GeneratedDafnyTest.cs +++ b/Source/DafnyCore.Test/GeneratedDafnyTest.cs @@ -6,7 +6,12 @@ namespace DafnyCore.Test; public class GeneratedDafnyTest { [Fact] public void TestDafnyCoverage() { - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestExpr(); + DafnyToRustCompilerCoverage.__default.TestIsCopy(); ; + } + + [Fact] + public void TestRustASTCoverage() { + RASTCoverage.__default.TestExpr(); } [Fact] diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage.cs b/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage.cs new file mode 100644 index 00000000000..fc783dccf8c --- /dev/null +++ b/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage.cs @@ -0,0 +1,32 @@ +// Dafny program the_program compiled into C# +// To recompile, you will need the libraries +// System.Runtime.Numerics.dll System.Collections.Immutable.dll +// but the 'dotnet' tool in net6.0 should pick those up automatically. +// Optionally, you may want to include compiler switches like +// /debug /nowarn:162,164,168,183,219,436,1717,1718 + +using System; +using System.Numerics; +using System.Collections; +#pragma warning disable CS0164 // This label has not been referenced +#pragma warning disable CS0162 // Unreachable code detected +#pragma warning disable CS1717 // Assignment made to same variable + +namespace DafnyToRustCompilerCoverage { + + public partial class __default { + public static void TestIsCopy() + { + if (!(Defs.__default.IsNewtypeCopy(DAST.NewtypeRange.create_Bool()))) { + throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-coverage.dfy(9,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} + if (!(Defs.__default.IsNewtypeCopy(DAST.NewtypeRange.create_U128(true)))) { + throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-coverage.dfy(10,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} + if (!(Defs.__default.IsNewtypeCopy(DAST.NewtypeRange.create_U128(false)))) { + throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-coverage.dfy(11,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} + if (!(!(Defs.__default.IsNewtypeCopy(DAST.NewtypeRange.create_BigInt())))) { + throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-coverage.dfy(12,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} + if (!(!(Defs.__default.IsNewtypeCopy(DAST.NewtypeRange.create_NoRange())))) { + throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-coverage.dfy(13,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} + } + } +} // end of namespace DafnyToRustCompilerCoverage \ No newline at end of file diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs b/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs deleted file mode 100644 index 9f23566b7a1..00000000000 --- a/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs +++ /dev/null @@ -1,165 +0,0 @@ -// Dafny program the_program compiled into C# -// To recompile, you will need the libraries -// System.Runtime.Numerics.dll System.Collections.Immutable.dll -// but the 'dotnet' tool in net6.0 should pick those up automatically. -// Optionally, you may want to include compiler switches like -// /debug /nowarn:162,164,168,183,219,436,1717,1718 - -using System; -using System.Numerics; -using System.Collections; -#pragma warning disable CS0164 // This label has not been referenced -#pragma warning disable CS0162 // Unreachable code detected -#pragma warning disable CS1717 // Assignment made to same variable - -namespace DafnyToRustCompilerCoverage.RASTCoverage { - - public partial class __default { - public static void AssertCoverage(bool x) - { - if (!(x)) { - throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-coverage.dfy(13,6): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} - } - public static void TestExpr() - { - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestOptimizeToString(); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestPrintingInfo(); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoExtraSemicolonAfter(); - } - public static void TestNoOptimize(RAST._IExpr e) - { - } - public static RAST._IExpr ConversionNum(RAST._IType t, RAST._IExpr x) - { - return RAST.Expr.create_Call(RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.Path.create_PMemberSelect(RAST.Path.create_Global(), Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("truncate!"))), Dafny.Sequence.FromElements(x, RAST.Expr.create_ExprFromType(t))); - } - public static RAST._IExpr DafnyIntLiteral(Dafny.ISequence s) { - return RAST.Expr.create_Call(RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.__default.dafny__runtime, Dafny.Sequence.UnicodeFromString("int!"))), Dafny.Sequence.FromElements(RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")))); - } - public static RAST._IExpr Optimize(RAST._IExpr e) { - return (ExpressionOptimization.__default.ExprSimplifier()).ReplaceExpr(e); - } - public static void TestOptimizeToString() - { - RAST._IExpr _0_x; - _0_x = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")); - RAST._IExpr _1_y; - _1_y = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), RAST.Expr.create_Call(RAST.Expr.create_Select(_0_x, Dafny.Sequence.UnicodeFromString("clone")), Dafny.Sequence.FromElements(_1_y)), DAST.Format.UnaryOpFormat.create_NoFormat())); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals(DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_NoFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_NoFormat()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals(DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_NoFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_NoFormat()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals(DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_ReverseFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1_y, _0_x, DAST.Format.BinaryOpFormat.create_NoFormat()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals(DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_I128(), DafnyToRustCompilerCoverage.RASTCoverage.__default.DafnyIntLiteral(Dafny.Sequence.UnicodeFromString("1")))), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_I128(), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals(DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("z"), _1_y), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_Some(_1_y)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("w"), _1_y), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(_0_x); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(_0_x, _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_Match(_0_x, Dafny.Sequence.FromElements()), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_StructBuild(_0_x, Dafny.Sequence.FromElements()), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements()), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat()), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), _0_x, _0_x, DAST.Format.BinaryOpFormat.create_NoFormat()), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_TypeAscription(_0_x, RAST.Type.create_I128()), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("2"), true, false), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("3"), false, true), _0_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals(DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("z"), _1_y), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_Some(_1_y)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); - Dafny.ISequence _2_coverageExpression; - _2_coverageExpression = Dafny.Sequence.FromElements(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("abc")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("abc"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))))), RAST.Expr.create_StmtExpr(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("panic!()")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("a"))), RAST.Expr.create_Block(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("abc"))), RAST.Expr.create_StructBuild(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dummy")), Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.UnicodeFromString("foo"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("bar"))))), RAST.Expr.create_StructBuild(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dummy")), Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.UnicodeFromString("foo"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("bar"))), RAST.AssignIdentifier.create(Dafny.Sequence.UnicodeFromString("foo2"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("bar"))))), RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")))), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("-"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), DAST.Format.UnaryOpFormat.create_NoFormat()), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")), DAST.Format.BinaryOpFormat.create_NoFormat()), RAST.Expr.create_TypeAscription(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Type.create_I128()), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("322")), RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("abc"), true, false), RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("abc"), false, true), RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")))), RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("abc"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_IfExpr(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_For(Dafny.Sequence.UnicodeFromString("abc"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("abc"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_Break(Std.Wrappers.Option>.create_None()), RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("l"))), RAST.Expr.create_Continue(Std.Wrappers.Option>.create_None()), RAST.Expr.create_Continue(Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("l"))), RAST.Expr.create_Return(Std.Wrappers.Option.create_None()), RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")))), RAST.Expr.create_Call(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.FromElements()), RAST.Expr.create_Call(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")))), RAST.Expr.create_CallType(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.FromElements(RAST.Type.create_I128(), RAST.Type.create_U32())), RAST.Expr.create_Select(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.UnicodeFromString("abc")), RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.Path.create_Crate(), Dafny.Sequence.UnicodeFromString("abc"))), RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.Path.create_Global(), Dafny.Sequence.UnicodeFromString("abc")))); - BigInteger _hi0 = new BigInteger((_2_coverageExpression).Count); - for (BigInteger _3_i = BigInteger.Zero; _3_i < _hi0; _3_i++) { - RAST._IExpr _4_c; - _4_c = (_2_coverageExpression).Select(_3_i); - RAST._IPrintingInfo _5___v0; - _5___v0 = (_4_c).printingInfo; - RAST._IExpr _6___v1; - _6___v1 = DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(_4_c); - Dafny.IMap> _7___v2; - _7___v2 = Dafny.Map>.FromElements(new Dafny.Pair>(_4_c, (_4_c)._ToString(Dafny.Sequence.UnicodeFromString("")))); - RAST._IExpr _8___v3; - _8___v3 = DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), _4_c)); - RAST._IExpr _9___v4; - _9___v4 = DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("abc"), _4_c), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString(""))))); - RAST._IExpr _10___v5; - _10___v5 = DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _4_c, DAST.Format.UnaryOpFormat.create_NoFormat())); - RAST._IExpr _11___v6; - _11___v6 = DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _4_c, DAST.Format.UnaryOpFormat.create_NoFormat())); - RAST._IExpr _12___v7; - _12___v7 = DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), _4_c)); - RAST._IExpr _13___v8; - _13___v8 = DafnyToRustCompilerCoverage.RASTCoverage.__default.Optimize(DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(_4_c, Dafny.Sequence.FromElements()))); - Std.Wrappers._IOption> _14___v9; - _14___v9 = (_4_c).RightMostIdentifier(); - } - } - public static void TestPrintingInfo() - { - RAST._IExpr _0_x; - _0_x = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")); - RAST._IExpr _1_y; - _1_y = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")); - DAST.Format._IBinaryOpFormat _2_bnf; - _2_bnf = DAST.Format.BinaryOpFormat.create_NoFormat(); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(((RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("x"))).printingInfo).is_UnknownPrecedence); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((_0_x).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("3"))).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("abc"), true, false)).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_SuffixPrecedence(new BigInteger(5)))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("-"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("*"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!!"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_UnknownPrecedence())); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_Select(_0_x, Dafny.Sequence.UnicodeFromString("name"))).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(2), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.Path.create_Global(), Dafny.Sequence.UnicodeFromString("name")))).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(2)))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_Call(_0_x, Dafny.Sequence.FromElements())).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(2), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_TypeAscription(_0_x, RAST.Type.create_I128())).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(10), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("*"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("/"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("%"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(30), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("-"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(30), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<<"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">>"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(50), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("^"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(60), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("|"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(70), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(90), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("||"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(100), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(".."), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("..="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("-="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("*="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("/="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("%="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("|="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("^="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<<="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">>="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("?!?"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(BigInteger.Zero, RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())).printingInfo, RAST.PrintingInfo.create_UnknownPrecedence())); - } - public static void TestNoExtraSemicolonAfter() - { - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString(";"))).NoExtraSemicolonAfter()); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(!((RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("a"))).NoExtraSemicolonAfter())); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_Return(Std.Wrappers.Option.create_None())).NoExtraSemicolonAfter()); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_Continue(Std.Wrappers.Option>.create_None())).NoExtraSemicolonAfter()); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())).NoExtraSemicolonAfter()); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("x"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")))).NoExtraSemicolonAfter()); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("x"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_None())).NoExtraSemicolonAfter()); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(!((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))).NoExtraSemicolonAfter())); - } - } -} // end of namespace DafnyToRustCompilerCoverage.RASTCoverage \ No newline at end of file diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/RASTCoverage.cs b/Source/DafnyCore.Test/GeneratedFromDafny/RASTCoverage.cs new file mode 100644 index 00000000000..8b8833e5adb --- /dev/null +++ b/Source/DafnyCore.Test/GeneratedFromDafny/RASTCoverage.cs @@ -0,0 +1,165 @@ +// Dafny program the_program compiled into C# +// To recompile, you will need the libraries +// System.Runtime.Numerics.dll System.Collections.Immutable.dll +// but the 'dotnet' tool in net6.0 should pick those up automatically. +// Optionally, you may want to include compiler switches like +// /debug /nowarn:162,164,168,183,219,436,1717,1718 + +using System; +using System.Numerics; +using System.Collections; +#pragma warning disable CS0164 // This label has not been referenced +#pragma warning disable CS0162 // Unreachable code detected +#pragma warning disable CS1717 // Assignment made to same variable + +namespace RASTCoverage { + + public partial class __default { + public static void AssertCoverage(bool x) + { + if (!(x)) { + throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-coverage.dfy(26,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} + } + public static void TestExpr() + { + RASTCoverage.__default.TestOptimizeToString(); + RASTCoverage.__default.TestPrintingInfo(); + RASTCoverage.__default.TestNoExtraSemicolonAfter(); + } + public static void TestNoOptimize(RAST._IExpr e) + { + } + public static RAST._IExpr ConversionNum(RAST._IType t, RAST._IExpr x) + { + return RAST.Expr.create_Call(RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.Path.create_PMemberSelect(RAST.Path.create_Global(), Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("truncate!"))), Dafny.Sequence.FromElements(x, RAST.Expr.create_ExprFromType(t))); + } + public static RAST._IExpr DafnyIntLiteral(Dafny.ISequence s) { + return RAST.Expr.create_Call(RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.__default.dafny__runtime, Dafny.Sequence.UnicodeFromString("int!"))), Dafny.Sequence.FromElements(RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")))); + } + public static RAST._IExpr Optimize(RAST._IExpr e) { + return (ExpressionOptimization.__default.ExprSimplifier()).ReplaceExpr(e); + } + public static void TestOptimizeToString() + { + RAST._IExpr _0_x; + _0_x = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")); + RAST._IExpr _1_y; + _1_y = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), RAST.Expr.create_Call(RAST.Expr.create_Select(_0_x, Dafny.Sequence.UnicodeFromString("clone")), Dafny.Sequence.FromElements(_1_y)), DAST.Format.UnaryOpFormat.create_NoFormat())); + RASTCoverage.__default.AssertCoverage(object.Equals(RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_NoFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_NoFormat()))); + RASTCoverage.__default.AssertCoverage(object.Equals(RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_NoFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_NoFormat()))); + RASTCoverage.__default.AssertCoverage(object.Equals(RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _0_x, _1_y, DAST.Format.BinaryOpFormat.create_ReverseFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1_y, _0_x, DAST.Format.BinaryOpFormat.create_NoFormat()))); + RASTCoverage.__default.AssertCoverage(object.Equals(RASTCoverage.__default.Optimize(RASTCoverage.__default.ConversionNum(RAST.Type.create_I128(), RASTCoverage.__default.DafnyIntLiteral(Dafny.Sequence.UnicodeFromString("1")))), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")))); + RASTCoverage.__default.TestNoOptimize(RASTCoverage.__default.ConversionNum(RAST.Type.create_I128(), _0_x)); + RASTCoverage.__default.AssertCoverage(object.Equals(RASTCoverage.__default.Optimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("z"), _1_y), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_Some(_1_y)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("w"), _1_y), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); + RASTCoverage.__default.TestNoOptimize(_0_x); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(_0_x, _0_x)); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_Match(_0_x, Dafny.Sequence.FromElements()), _0_x)); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_StructBuild(_0_x, Dafny.Sequence.FromElements()), _0_x)); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements()), _0_x)); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat()), _0_x)); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), _0_x, _0_x, DAST.Format.BinaryOpFormat.create_NoFormat()), _0_x)); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_TypeAscription(_0_x, RAST.Type.create_I128()), _0_x)); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")), _0_x)); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("2"), true, false), _0_x)); + RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("3"), false, true), _0_x)); + RASTCoverage.__default.AssertCoverage(object.Equals(RASTCoverage.__default.Optimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("z"), _1_y), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_Some(_1_y)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); + Dafny.ISequence _2_coverageExpression; + _2_coverageExpression = Dafny.Sequence.FromElements(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("abc")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("abc"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))))), RAST.Expr.create_StmtExpr(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("panic!()")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("a"))), RAST.Expr.create_Block(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("abc"))), RAST.Expr.create_StructBuild(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dummy")), Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.UnicodeFromString("foo"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("bar"))))), RAST.Expr.create_StructBuild(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dummy")), Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.UnicodeFromString("foo"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("bar"))), RAST.AssignIdentifier.create(Dafny.Sequence.UnicodeFromString("foo2"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("bar"))))), RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")))), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("-"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), DAST.Format.UnaryOpFormat.create_NoFormat()), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")), DAST.Format.BinaryOpFormat.create_NoFormat()), RAST.Expr.create_TypeAscription(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Type.create_I128()), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("322")), RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("abc"), true, false), RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("abc"), false, true), RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")))), RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("abc"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_IfExpr(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_For(Dafny.Sequence.UnicodeFromString("abc"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("abc"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_Break(Std.Wrappers.Option>.create_None()), RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("l"))), RAST.Expr.create_Continue(Std.Wrappers.Option>.create_None()), RAST.Expr.create_Continue(Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("l"))), RAST.Expr.create_Return(Std.Wrappers.Option.create_None()), RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")))), RAST.Expr.create_Call(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.FromElements()), RAST.Expr.create_Call(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")))), RAST.Expr.create_CallType(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.FromElements(RAST.Type.create_I128(), RAST.Type.create_U32())), RAST.Expr.create_Select(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.UnicodeFromString("abc")), RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.Path.create_Crate(), Dafny.Sequence.UnicodeFromString("abc"))), RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.Path.create_Global(), Dafny.Sequence.UnicodeFromString("abc")))); + BigInteger _hi0 = new BigInteger((_2_coverageExpression).Count); + for (BigInteger _3_i = BigInteger.Zero; _3_i < _hi0; _3_i++) { + RAST._IExpr _4_c; + _4_c = (_2_coverageExpression).Select(_3_i); + RAST._IPrintingInfo _5___v0; + _5___v0 = (_4_c).printingInfo; + RAST._IExpr _6___v1; + _6___v1 = RASTCoverage.__default.Optimize(_4_c); + Dafny.IMap> _7___v2; + _7___v2 = Dafny.Map>.FromElements(new Dafny.Pair>(_4_c, (_4_c)._ToString(Dafny.Sequence.UnicodeFromString("")))); + RAST._IExpr _8___v3; + _8___v3 = RASTCoverage.__default.Optimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), _4_c)); + RAST._IExpr _9___v4; + _9___v4 = RASTCoverage.__default.Optimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("abc"), _4_c), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString(""))))); + RAST._IExpr _10___v5; + _10___v5 = RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _4_c, DAST.Format.UnaryOpFormat.create_NoFormat())); + RAST._IExpr _11___v6; + _11___v6 = RASTCoverage.__default.Optimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _4_c, DAST.Format.UnaryOpFormat.create_NoFormat())); + RAST._IExpr _12___v7; + _12___v7 = RASTCoverage.__default.Optimize(RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), _4_c)); + RAST._IExpr _13___v8; + _13___v8 = RASTCoverage.__default.Optimize(RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(_4_c, Dafny.Sequence.FromElements()))); + Std.Wrappers._IOption> _14___v9; + _14___v9 = (_4_c).RightMostIdentifier(); + } + } + public static void TestPrintingInfo() + { + RAST._IExpr _0_x; + _0_x = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")); + RAST._IExpr _1_y; + _1_y = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")); + DAST.Format._IBinaryOpFormat _2_bnf; + _2_bnf = DAST.Format.BinaryOpFormat.create_NoFormat(); + RASTCoverage.__default.AssertCoverage(((RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("x"))).printingInfo).is_UnknownPrecedence); + RASTCoverage.__default.AssertCoverage(object.Equals((_0_x).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("3"))).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("abc"), true, false)).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_SuffixPrecedence(new BigInteger(5)))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("-"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("*"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!!"), _0_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_UnknownPrecedence())); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_Select(_0_x, Dafny.Sequence.UnicodeFromString("name"))).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(2), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_ExprFromPath(RAST.Path.create_PMemberSelect(RAST.Path.create_Global(), Dafny.Sequence.UnicodeFromString("name")))).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(2)))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_Call(_0_x, Dafny.Sequence.FromElements())).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(2), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_TypeAscription(_0_x, RAST.Type.create_I128())).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(10), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("*"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("/"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("%"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(30), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("-"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(30), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<<"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">>"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(50), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("^"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(60), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("|"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(70), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(90), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("||"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(100), RAST.Associativity.create_LeftToRight()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(".."), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RequiresParentheses()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("..="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RequiresParentheses()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("-="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("*="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("/="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("%="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("|="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("^="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<<="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">>="), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("?!?"), _0_x, _1_y, _2_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(BigInteger.Zero, RAST.Associativity.create_RequiresParentheses()))); + RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())).printingInfo, RAST.PrintingInfo.create_UnknownPrecedence())); + } + public static void TestNoExtraSemicolonAfter() + { + RASTCoverage.__default.AssertCoverage((RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString(";"))).NoExtraSemicolonAfter()); + RASTCoverage.__default.AssertCoverage(!((RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("a"))).NoExtraSemicolonAfter())); + RASTCoverage.__default.AssertCoverage((RAST.Expr.create_Return(Std.Wrappers.Option.create_None())).NoExtraSemicolonAfter()); + RASTCoverage.__default.AssertCoverage((RAST.Expr.create_Continue(Std.Wrappers.Option>.create_None())).NoExtraSemicolonAfter()); + RASTCoverage.__default.AssertCoverage((RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())).NoExtraSemicolonAfter()); + RASTCoverage.__default.AssertCoverage((RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("x"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")))).NoExtraSemicolonAfter()); + RASTCoverage.__default.AssertCoverage((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("x"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_None())).NoExtraSemicolonAfter()); + RASTCoverage.__default.AssertCoverage(!((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))).NoExtraSemicolonAfter())); + } + } +} // end of namespace RASTCoverage \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 4c0e1272daf..c315565ad99 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -115,6 +115,15 @@ module {:extern "DAST"} DAST { this } } + + predicate IsPrimitiveInt() { + match this { + case Primitive(Int) => true + case UserDefined(ResolvedType(_, _, SynonymType(typ), _, _, _)) => + typ.IsPrimitiveInt() + case _ => false + } + } } datatype Variance = @@ -130,10 +139,30 @@ module {:extern "DAST"} DAST { datatype Primitive = Int | Real | String | Bool | Char | Native - // USIZE is for whatever target considers that native arrays can be indexed with + datatype NewtypeRange = - | U8 | I8 | U16 | I16 | U32 | I32 | U64 | I64 | U128 | I128 | USIZE | BigInt + | U8(overflow: bool) // Whether arithmetic operations can overflow and wrap + | I8(overflow: bool) + | U16(overflow: bool) + | I16(overflow: bool) + | U32(overflow: bool) + | I32(overflow: bool) + | U64(overflow: bool) + | I64(overflow: bool) + | U128(overflow: bool) + | I128(overflow: bool) + | NativeArrayIndex + | BigInt + | Bool | 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. + } + } datatype Attribute = Attribute(name: string, args: seq) @@ -147,6 +176,7 @@ module {:extern "DAST"} DAST { | Class() | Datatype(variances: seq) | Trait() + | SynonymType(baseType: Type) | Newtype(baseType: Type, range: NewtypeRange, erase: bool) datatype ResolvedType = ResolvedType( @@ -190,7 +220,8 @@ module {:extern "DAST"} DAST { Newtype( name: Name, typeParams: seq, base: Type, range: NewtypeRange, constraint: Option, - witnessStmts: seq, witnessExpr: Option, attributes: seq) + witnessStmts: seq, witnessExpr: Option, attributes: seq, + classItems: seq) datatype NewtypeConstraint = NewtypeConstraint(variable: Formal, constraintStmts: seq) @@ -200,7 +231,7 @@ module {:extern "DAST"} DAST { datatype ClassItem = Method(Method) - datatype Field = Field(formal: Formal, isConstant: bool, defaultValue: Option) + datatype Field = Field(formal: Formal, isConstant: bool, defaultValue: Option, isStatic: bool) datatype Formal = Formal(name: VarName, typ: Type, attributes: seq) @@ -250,13 +281,16 @@ module {:extern "DAST"} DAST { datatype CollKind = Seq | Array | Map + datatype TypedBinOp = + TypedBinOp(op: BinOp, leftType: Type, rightType: Type, resultType: Type) + datatype BinOp = Eq(referential: bool) | - Div() | EuclidianDiv() | + Div(overflow: bool) | EuclidianDiv() | Mod() | EuclidianMod() | Lt() | // a <= b is !(b < a) LtChar() | - Plus() | Minus() | Times() | + Plus(overflow: bool) | Minus(overflow: bool) | Times(overflow: bool) | BitwiseAnd() | BitwiseOr() | BitwiseXor() | BitwiseShiftRight() | BitwiseShiftLeft() | And() | Or() | @@ -295,7 +329,7 @@ module {:extern "DAST"} DAST { This() | Ite(cond: Expression, thn: Expression, els: Expression) | UnOp(unOp: UnaryOp, expr: Expression, format1: Format.UnaryOpFormat) | - BinOp(op: BinOp, left: Expression, right: Expression, format2: Format.BinaryOpFormat) | + BinOp(op: TypedBinOp, left: Expression, right: Expression, format2: Format.BinaryOpFormat) | ArrayLen(expr: Expression, exprType: Type, dim: nat, native: bool) | MapKeys(expr: Expression) | MapValues(expr: Expression) | @@ -326,12 +360,15 @@ module {:extern "DAST"} DAST { // Since constant fields need to be set up in the constructor, // accessing constant fields is done in two ways: // - The internal field access (through the internal field that contains the value of the constant) - // it's not initialized at the beginning of the constructor + // it's not initialized at the beginning of the constructor. // - The external field access (through a function), which when accessed - // must always be initialized + // must always be initialized. // For Select expressions, it's important to know how the field is being accessed // For mutable fields, there is no wrapping function so only one way to access the mutable field - datatype FieldMutability = ConstantField | InternalClassConstantField | ClassMutableField + datatype FieldMutability = + | ConstantField // Access a class constant field after initialization, or a datatype constant field + | InternalClassConstantFieldOrDatatypeDestructor // Access a class internal field before initialization, or a datatype destructor + | ClassMutableField datatype UnaryOp = Not | BitwiseNot | Cardinality datatype Literal = diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index aa6e8068dba..29b36afbb3c 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -39,9 +39,14 @@ public ModuleBuilder Module(string name, Sequence attributes, bool re return new ModuleBuilder(this, name, attributes, requiresExterns); } - static public Module UnsupportedToModule(string why) { - return new Module(Sequence.UnicodeFromString(why), Sequence.FromElements((Attribute)Attribute.create_Attribute( - Sequence.UnicodeFromString(why), Sequence>.Empty)), false, + public static Module UnsupportedToModule(string why) { + return new Module( + Sequence.UnicodeFromString(why.Replace(".", ",")), + Sequence.FromElements( + (Attribute)Attribute.create_Attribute( + Sequence.UnicodeFromString("extern"), + Sequence>.FromElements( + (Sequence)Sequence.UnicodeFromString(why)))), false, Std.Wrappers.Option>.create_None()); } } @@ -133,8 +138,8 @@ public void AddMethod(DAST.Method item) { body.Add(item); } - public void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue) { - fields.Add((DAST.Field)DAST.Field.create_Field(item, isConstant, defaultValue)); + public void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue, bool isStatic) { + fields.Add((DAST.Field)DAST.Field.create_Field(item, isConstant, defaultValue, isStatic)); } public object Finish() { @@ -187,8 +192,8 @@ public void AddMethod(DAST.Method item) { body.Add(item); } - public void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue) { - throw new UnsupportedFeatureException(Token.NoToken, Feature.RunAllTests); + public void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue, bool isStatic) { + this.parent.AddUnsupported("Field " + item.ToString()); } public object Finish() { @@ -223,6 +228,7 @@ class NewtypeBuilder : ClassLike { readonly List witnessStmts; readonly DAST.Expression witness; private ISequence<_IAttribute> attributes; + private readonly List methods; public NewtypeBuilder(NewtypeContainer parent, string name, List typeParams, NewtypeRange newtypeRange, DAST.Type baseType, Option constraint, List statements, @@ -237,14 +243,15 @@ public NewtypeBuilder(NewtypeContainer parent, string name, List ty this.witnessStmts = statements; this.witness = witness; this.attributes = attributes; + this.methods = new(); } public void AddMethod(DAST.Method item) { - throw new UnsupportedFeatureException(Token.NoToken, Feature.RunAllTests); + methods.Add(item); } - public void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue) { - throw new UnsupportedFeatureException(Token.NoToken, Feature.RunAllTests); + public void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue, bool isStatic) { + parent.AddUnsupported("Datatype field " + item.ToString()); } public object Finish() { @@ -258,7 +265,8 @@ public object Finish() { this.witness == null ? Option.create_None() : Option.create_Some(this.witness), - attributes + attributes, + Sequence.FromArray(methods.ToArray()) )); return parent; } @@ -343,8 +351,8 @@ public void AddMethod(DAST.Method item) { body.Add(item); } - public void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue) { - throw new UnsupportedFeatureException(Token.NoToken, Feature.RunAllTests); + public void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue, bool isStatic) { + parent.AddUnsupported("Datatype field " + item.ToString()); } public object Finish() { @@ -363,7 +371,7 @@ public object Finish() { interface ClassLike { void AddMethod(DAST.Method item); - void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue); + void AddField(DAST.Formal item, bool isConstant, _IOption defaultValue, bool isStatic); public MethodBuilder Method(bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, ISequence> overridingPath, @@ -676,6 +684,8 @@ class IfElseBuilder : ExprContainer, StatementContainer, BuildableStatement { readonly List ifBody = new(); readonly List elseBody = new(); + public object Condition => condition; + public IfElseBuilder() { } public void AddExpr(DAST.Expression value) { @@ -777,6 +787,7 @@ public void AddUnsupported(string why) { class WhileBuilder : ExprContainer, StatementContainer, BuildableStatement { object condition = null; readonly List body = new(); + public object Condition => condition; public void AddExpr(DAST.Expression value) { if (condition != null) { @@ -1233,8 +1244,8 @@ ExprWrapper Wrapper(Func wrapper) { return ret; } - BinOpBuilder BinOp(DAST.BinOp op) { - var ret = new BinOpBuilder(op); + BinOpBuilder BinOp(DAST.BinOp op, DAST.Type leftType, DAST.Type rightType, DAST.Type resType) { + var ret = new BinOpBuilder(op, leftType, rightType, resType); AddBuildable(ret); return ret; } @@ -1385,9 +1396,10 @@ class BinOpBuilder : ExprContainer, BuildableExpr { readonly List operands = new(); private readonly string op; - public BinOpBuilder(DAST.BinOp op) { + public BinOpBuilder(DAST.BinOp op, DAST.Type leftType, DAST.Type rightType, DAST.Type resType) { this.internalBuilder = (DAST.Expression left, DAST.Expression right) => - (DAST.Expression)DAST.Expression.create_BinOp(op, left, right, new BinaryOpFormat_NoFormat()); + (DAST.Expression)DAST.Expression.create_BinOp( + DAST.TypedBinOp.create_TypedBinOp(op, leftType, rightType, resType), left, right, new BinaryOpFormat_NoFormat()); this.op = op.ToString(); } @@ -1816,7 +1828,7 @@ public static DAST.Expression ToNativeUsize(int number) { DAST.ResolvedType.create_ResolvedType( Sequence>.FromElements((Sequence)Sequence.UnicodeFromString("usize")), Sequence<_IType>.Empty, - DAST.ResolvedTypeBase.create_Newtype(origType, DAST.NewtypeRange.create_USIZE(), true), Sequence<_IAttribute>.Empty, + DAST.ResolvedTypeBase.create_Newtype(origType, DAST.NewtypeRange.create_NativeArrayIndex(), true), Sequence<_IAttribute>.Empty, Sequence>.Empty, Sequence<_IType>.Empty) )); } diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 5ad8399a099..0cc3c439777 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -115,8 +115,7 @@ public override void EmitCallToMain(Method mainMethod, string baseName, Concrete protected override ConcreteSyntaxTree CreateStaticMain(IClassWriter cw, string argsParameterName) { AddUnsupported("create static main"); - return new BuilderSyntaxTree( - new ExprBuffer(this), this); + return WrBuffer(out _); } private bool NeedsExternalImport(MemberDecl memberDecl) { @@ -307,17 +306,14 @@ from arg in ctor.Formals protected override IClassWriter DeclareNewtype(NewtypeDecl nt, ConcreteSyntaxTree wr) { if (currentBuilder is NewtypeContainer builder) { - var erasedType = EraseNewtypeLayers(nt); - List witnessStmts = new(); DAST.Expression witness = null; - var buf = new ExprBuffer(null); var statementBuf = new StatementBuffer(); if (nt.WitnessKind == SubsetTypeDecl.WKind.Compiled) { EmitExpr( nt.Witness, false, - EmitCoercionIfNecessary(nt.Witness.Type, erasedType, null, - new BuilderSyntaxTree(buf, this)), + EmitCoercionIfNecessary(nt.Witness.Type, nt.BaseType, nt.Witness.tok, + WrBuffer(out var buf)), new BuilderSyntaxTree(statementBuf, this) ); witness = buf.Finish(); @@ -343,7 +339,7 @@ protected override IClassWriter DeclareNewtype(NewtypeDecl nt, ConcreteSyntaxTre return new ClassWriter(this, false, builder.Newtype( nt.GetCompileName(Options), new(), - GenType(erasedType), NativeTypeToNewtypeRange(nt.NativeType), + GenType(nt.BaseType), NativeTypeToNewtypeRange(nt, false), constraint, witnessStmts, witness, ParseAttributes(nt.Attributes))); } else { throw new InvalidOperationException(); @@ -373,6 +369,7 @@ private DAST.Type GenType(Type typ) { return FullTypeNameAST(udt, null); } else if (AsNativeType(typ) != null) { + var overflows = typ is BitvectorType; var CreateNewtype = (string baseName, DAST._INewtypeRange newTypeRange) => DAST.Type.create_UserDefined( DAST.ResolvedType.create_ResolvedType( @@ -391,16 +388,16 @@ private DAST.Type GenType(Type typ) { ) ); return (DAST.Type)(AsNativeType(xType).Sel switch { - NativeType.Selection.Byte => CreateNewtype("u8", DAST.NewtypeRange.create_U8()), - NativeType.Selection.SByte => CreateNewtype("i8", DAST.NewtypeRange.create_I8()), - NativeType.Selection.Short => CreateNewtype("i16", DAST.NewtypeRange.create_I16()), - NativeType.Selection.UShort => CreateNewtype("u16", DAST.NewtypeRange.create_U16()), - NativeType.Selection.Int => CreateNewtype("i32", DAST.NewtypeRange.create_I32()), - NativeType.Selection.UInt => CreateNewtype("u32", DAST.NewtypeRange.create_U32()), - NativeType.Selection.Long => CreateNewtype("i64", DAST.NewtypeRange.create_I64()), - NativeType.Selection.ULong => CreateNewtype("u64", DAST.NewtypeRange.create_U64()), - NativeType.Selection.DoubleLong => CreateNewtype("i128", DAST.NewtypeRange.create_I128()), - NativeType.Selection.UDoubleLong => CreateNewtype("u128", DAST.NewtypeRange.create_U128()), + NativeType.Selection.Byte => CreateNewtype("u8", DAST.NewtypeRange.create_U8(overflows)), + NativeType.Selection.SByte => CreateNewtype("i8", DAST.NewtypeRange.create_I8(overflows)), + NativeType.Selection.Short => CreateNewtype("i16", DAST.NewtypeRange.create_I16(overflows)), + NativeType.Selection.UShort => CreateNewtype("u16", DAST.NewtypeRange.create_U16(overflows)), + NativeType.Selection.Int => CreateNewtype("i32", DAST.NewtypeRange.create_I32(overflows)), + NativeType.Selection.UInt => CreateNewtype("u32", DAST.NewtypeRange.create_U32(overflows)), + NativeType.Selection.Long => CreateNewtype("i64", DAST.NewtypeRange.create_I64(overflows)), + NativeType.Selection.ULong => CreateNewtype("u64", DAST.NewtypeRange.create_U64(overflows)), + NativeType.Selection.DoubleLong => CreateNewtype("i128", DAST.NewtypeRange.create_I128(overflows)), + NativeType.Selection.UDoubleLong => CreateNewtype("u128", DAST.NewtypeRange.create_U128(overflows)), _ => throw new InvalidOperationException(), }); } else if (xType is SeqType seq) { @@ -416,9 +413,6 @@ private DAST.Type GenType(Type typ) { var keyType = map.Domain; var valueType = map.Range; return (DAST.Type)DAST.Type.create_Map(GenType(keyType), GenType(valueType)); - } else if (xType is BitvectorType) { - AddUnsupported("Bitvector types"); - return (DAST.Type)DAST.Type.create_Passthrough(Sequence.UnicodeFromString("Missing feature: Bitvector types")); } else { var why = "Type name for " + xType + " (" + typ.GetType() + ")"; AddUnsupported(why); @@ -436,12 +430,11 @@ protected override void DeclareSubsetType(SubsetTypeDecl sst, ConcreteSyntaxTree List witnessStmts = new(); DAST.Expression witness = null; var statementBuf = new StatementBuffer(); - var buf = new ExprBuffer(null); if (sst.WitnessKind == SubsetTypeDecl.WKind.Compiled) { EmitExpr( sst.Witness, false, - EmitCoercionIfNecessary(sst.Witness.Type, erasedType, null, - new BuilderSyntaxTree(buf, this)), + EmitCoercionIfNecessary(sst.Witness.Type, erasedType, sst.Witness.tok, + WrBuffer(out var buf)), new BuilderSyntaxTree(statementBuf, this) ); witness = buf.Finish(); @@ -493,7 +486,7 @@ protected override void TrDividedBlockStmt(Constructor m, DividedBlockStmt divid , ParseAttributes(md.Attributes) ); return DAST.Field.create_Field(formal, md is ConstantField, - Std.Wrappers.Option.create_None()); + Std.Wrappers.Option.create_None(), md.HasStaticKeyword); } ).ToList(); builder.Builder.AddStatement((DAST.Statement)DAST.Statement.create_ConstructorNewSeparator( @@ -505,6 +498,10 @@ protected override void TrDividedBlockStmt(Constructor m, DividedBlockStmt divid TrStmtList(dividedBlockStmt.BodyProper, writer); } + protected override bool InstanceConstAreStatic() { + return false; + } + private class ClassWriter : IClassWriter { private readonly DafnyCodeGenerator compiler; private readonly ClassLike builder; @@ -674,7 +671,7 @@ public void DeclareField(string name, TopLevelDecl enclosingDecl, bool isStatic, Sequence.UnicodeFromString(name), compiler.GenType(type), compiler.ParseAttributes(field.Attributes) - ), isConst || field is ConstantField, rhsExpr); + ), isConst || field is ConstantField, rhsExpr, field.IsStatic); } public void InitializeField(Field field, Type instantiatedFieldType, TopLevelDeclWithMembers enclosingClass) { @@ -1120,19 +1117,17 @@ protected override ILvalue IdentLvalue(string var) { } protected override ILvalue SeqSelectLvalue(SeqSelectExpr ll, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { - var sourceBuf = new ExprBuffer(null); EmitExpr( ll.Seq, false, EmitCoercionIfNecessary( ll.Seq.Type, ll.Seq.Type.IsNonNullRefType || !ll.Seq.Type.IsRefType ? null : UserDefinedType.CreateNonNullType((UserDefinedType)ll.Seq.Type.NormalizeExpand()), - null, new BuilderSyntaxTree(sourceBuf, this) + ll.tok, WrBuffer(out var sourceBuf) ), wStmts ); - var indexBuf = new ExprBuffer(null); - EmitExpr(ll.E0, false, new BuilderSyntaxTree(indexBuf, this), wStmts); + EmitExpr(ll.E0, false, WrBuffer(out var indexBuf), wStmts); var source = sourceBuf.Finish(); var index = indexBuf.Finish(); @@ -1291,8 +1286,7 @@ protected override ConcreteSyntaxTree EmitForStmt(IToken tok, IVariable loopInde TrStmtList(body, bodyWr); BuilderSyntaxTree toReturn; if (goingUp) { - var loBuf = new ExprBuffer(null); - toReturn = new BuilderSyntaxTree(loBuf, this); + toReturn = WrBuffer(out var loBuf); loHiBuilder.AddBuildable(loBuf); } else { toReturn = new BuilderSyntaxTree(loHiBuilder, this); @@ -1407,8 +1401,7 @@ protected override void EmitNew(Type type, IToken tok, CallStmt initCall, Concre arguments = ctor.Ins.Select((f, i) => (f, i)) .Where(tp => !tp.f.IsGhost) .Select(tp => { - var buf = new ExprBuffer(null); - var localWriter = new BuilderSyntaxTree(buf, this); + var localWriter = WrBuffer(out var buf); EmitExpr(initCall.Args[tp.i], false, localWriter, wStmts); return buf.Finish(); }); @@ -1563,10 +1556,14 @@ protected override void EmitLiteralExpr(ConcreteSyntaxTree wr, LiteralExpr e) { break; } - if (e.Type.AsNewtype != null) { - baseExpr = (DAST.Expression)DAST.Expression.create_Convert(baseExpr, GenType(e.Type.AsNewtype.BaseType), GenType(e.Type)); - } else if (e.Type.AsSubsetType != null) { - baseExpr = (DAST.Expression)DAST.Expression.create_Convert(baseExpr, GenType(e.Type.AsSubsetType.Rhs), GenType(e.Type)); + if (e is not StaticReceiverExpr) { + if (e.Type.AsNewtype != null) { + baseExpr = (DAST.Expression)DAST.Expression.create_Convert(baseExpr, GenType(EraseNewtypeLayers(e.Type.AsNewtype)), + GenType(e.Type)); + } else if (e.Type.AsSubsetType != null) { + baseExpr = (DAST.Expression)DAST.Expression.create_Convert(baseExpr, GenType(e.Type), + GenType(e.Type)); + } } builder.Builder.AddExpr(baseExpr); @@ -1578,12 +1575,17 @@ protected override void EmitLiteralExpr(ConcreteSyntaxTree wr, LiteralExpr e) { } protected override void EmitStringLiteral(string str, bool isVerbatim, ConcreteSyntaxTree wr) { - throw new UnsupportedInvalidOperationException("EmitStringLiteral"); + AddUnsupported("EmitStringLiteral"); } protected override ConcreteSyntaxTree EmitBitvectorTruncation(BitvectorType bvType, [CanBeNull] NativeType nativeType, bool surroundByUnchecked, ConcreteSyntaxTree wr) { - throw new UnsupportedInvalidOperationException("EmitBitvectorTruncation"); + if (nativeType != null && bvType.NativeType.Name == nativeType.Name && bvType.NativeType.Bitwidth == nativeType.Bitwidth) { + return wr; + } + + AddUnsupported($"EmitBitvectorTruncation from {bvType} to {nativeType}"); + return wr; } protected override void EmitRotate(Expression e0, Expression e1, bool isRotateLeft, ConcreteSyntaxTree wr, @@ -1653,19 +1655,23 @@ private ISequence> PathFromTopLevel(TopLevelDecl topLevel) { return Sequence>.FromArray(path.ToArray()); } - private DAST.NewtypeRange NativeTypeToNewtypeRange(NativeType nativeType) { + private DAST.NewtypeRange NativeTypeToNewtypeRange(NewtypeDecl newtypeDecl, bool overflows) { + var nativeType = newtypeDecl.NativeType; return (DAST.NewtypeRange)(nativeType?.Sel switch { - NativeType.Selection.Byte => NewtypeRange.create_U8(), - NativeType.Selection.SByte => NewtypeRange.create_I8(), - NativeType.Selection.UShort => NewtypeRange.create_U16(), - NativeType.Selection.Short => NewtypeRange.create_I16(), - NativeType.Selection.UInt => NewtypeRange.create_U32(), - NativeType.Selection.Int => NewtypeRange.create_I32(), - NativeType.Selection.ULong => NewtypeRange.create_U64(), - NativeType.Selection.Long => NewtypeRange.create_I64(), - NativeType.Selection.UDoubleLong => NewtypeRange.create_U128(), - NativeType.Selection.DoubleLong => NewtypeRange.create_I128(), - _ => NewtypeRange.create_NoRange() + NativeType.Selection.Byte => NewtypeRange.create_U8(overflows), + NativeType.Selection.SByte => NewtypeRange.create_I8(overflows), + NativeType.Selection.UShort => NewtypeRange.create_U16(overflows), + NativeType.Selection.Short => NewtypeRange.create_I16(overflows), + NativeType.Selection.UInt => NewtypeRange.create_U32(overflows), + NativeType.Selection.Int => NewtypeRange.create_I32(overflows), + NativeType.Selection.ULong => NewtypeRange.create_U64(overflows), + NativeType.Selection.Long => NewtypeRange.create_I64(overflows), + NativeType.Selection.UDoubleLong => NewtypeRange.create_U128(overflows), + NativeType.Selection.DoubleLong => NewtypeRange.create_I128(overflows), + _ => + EraseNewtypeLayers(newtypeDecl) is BoolType + ? NewtypeRange.create_Bool() + : NewtypeRange.create_NoRange() }); } @@ -1698,6 +1704,16 @@ private DAST.NewtypeRange NativeTypeToNewtypeRange(NativeType nativeType) { return Sequence.FromArray(result.ToArray()); } + protected override bool IsNewtypeErased(NewtypeDecl newtypeDecl) { + var erasedIfNewtype = true; + if (!Attributes.ContainsBool(newtypeDecl.Attributes, "rust_erased", ref erasedIfNewtype)) { + var hasNoMember = !newtypeDecl.Members.Any(); + erasedIfNewtype = hasNoMember; + } + + return erasedIfNewtype; + } + private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List typeArgs) { var path = PathFromTopLevel(topLevel); @@ -1707,6 +1723,7 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type var properMethods = new List>(); var extendedTraits = new List(); + if (topLevel is TopLevelDeclWithMembers memberContainer) { foreach (var member in memberContainer.Members) { if (member.OverriddenMember == null) { @@ -1715,6 +1732,11 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type } } + var erasedIfNewtype = true; + if (topLevel is NewtypeDecl newtypeDecl) { + erasedIfNewtype = IsNewtypeErased(newtypeDecl); + } + foreach (var parentType in topLevel.ParentTypes(typeArgs, true)) { extendedTraits.Add(GenType(parentType)); } @@ -1726,12 +1748,13 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type DAST.ResolvedTypeBase resolvedTypeBase; if (topLevel is NewtypeDecl newType) { - var range = NativeTypeToNewtypeRange(newType.NativeType); + var range = NativeTypeToNewtypeRange(newType, false); + var newtypeBase = newType.BaseType; resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Newtype( - GenType(EraseNewtypeLayers(topLevel)), range, true); + GenType(newtypeBase), range, erasedIfNewtype); } else if (topLevel is TypeSynonymDecl typeSynonym) { // Also SubsetTypeDecl - resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Newtype( - GenType(typeSynonym.Rhs.Subst(typeSynonym.TypeArgs.Zip(typeArgs).ToDictionary(kv => kv.Item1, kv => kv.Item2)).NormalizeExpand()), NewtypeRange.create_NoRange(), true); + resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_SynonymType( + GenType(typeSynonym.Rhs.Subst(typeSynonym.TypeArgs.Zip(typeArgs).ToDictionary(kv => kv.Item1, kv => kv.Item2)).NormalizeExpand())); } else if (topLevel is TraitDecl) { resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Trait(); } else if (topLevel is DatatypeDecl dd) { @@ -1756,6 +1779,14 @@ private static Type EraseNewtypeLayers(TopLevelDecl topLevel) { return topLevelType.NormalizeToAncestorType(); } + // Contrary to other backends, we don't necessarily erase newtypes + public override Type GetRuntimeType(Type tpe) { + if (tpe.AsNewtype is { } newtypeDecl && !IsNewtypeErased(newtypeDecl)) { + return tpe; + } + return base.GetRuntimeType(tpe); + } + public override ConcreteSyntaxTree Expr(Expression expr, bool inLetExprBody, ConcreteSyntaxTree wStmts) { if (currentBuilder is ExprContainer container) { EmitExpr(expr, inLetExprBody, new BuilderSyntaxTree(container, this), wStmts); @@ -1771,6 +1802,11 @@ public override void EmitExpr(Expression expr, bool inLetExprBody, ConcreteSynta // the writers are not currently wired properly for DatatypeValue actualWr = new BuilderSyntaxTree(buf, this); } + if ( + actualWr is BuilderSyntaxTree { Builder: IfElseBuilder { Condition: null } or WhileBuilder { Condition: null } } builder && + expr.Type is not BoolType) { + actualWr = EmitConversion(builder, expr.Type, new BoolType()); + } if (expr is DatatypeValue) { ExprBuffer buffer = new(currentBuilder); @@ -1931,7 +1967,7 @@ protected override ILvalue EmitMemberSelect(Action obj, Type objExpr, Sequence.UnicodeFromString(compileName), FieldMutabilityOf(member), - member.EnclosingClass is DatatypeDecl, GenType(expectedType) + member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), @@ -1976,7 +2012,7 @@ member is ConstantField objExpr, Sequence.UnicodeFromString(compiledName), FieldMutabilityOf(member), - member.EnclosingClass is DatatypeDecl, GenType(expectedType) + member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(compiledName), @@ -2009,7 +2045,7 @@ member is ConstantField objExpr, Sequence.UnicodeFromString(InternalFieldPrefix + member.GetCompileName(Options)), FieldMutabilityOf(member, isInternal: true), - member.EnclosingClass is DatatypeDecl, GenType(expectedType) + member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(InternalFieldPrefix + member.GetCompileName(Options)), @@ -2020,7 +2056,7 @@ member is ConstantField objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), FieldMutabilityOf(member), - member.EnclosingClass is DatatypeDecl, GenType(expectedType) + member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), @@ -2031,9 +2067,9 @@ member is ConstantField } private static _IFieldMutability FieldMutabilityOf(MemberDecl member, bool isInternal = false) { - return member is ConstantField - ? isInternal - ? new FieldMutability_InternalClassConstantField() + return member is ConstantField or DatatypeDestructor + ? isInternal || member is DatatypeDestructor + ? new FieldMutability_InternalClassConstantFieldOrDatatypeDestructor() : new FieldMutability_ConstantField() : new FieldMutability_ClassMutableField(); } @@ -2106,7 +2142,7 @@ protected override void EmitIndexCollectionSelect(Expression source, Expression } var indexBuf = new ExprBuffer(null); - var indexWr = EmitCoercionIfNecessary(index.Type.NormalizeExpand(), indexType, null, new BuilderSyntaxTree(indexBuf, this)); + var indexWr = EmitCoercionIfNecessary(index.Type.NormalizeExpand(), indexType, source.tok, new BuilderSyntaxTree(indexBuf, this)); EmitExpr(index, inLetExprBody, indexWr, wStmts); if (GetExprBuilder(wr, out var builder)) { @@ -2197,7 +2233,7 @@ protected override void EmitSeqSelectRange(Expression source, Expression lo, Exp DAST.Expression loExpr = null; if (lo != null) { var loBuf = new ExprBuffer(null); - var loWr = EmitCoercionIfNecessary(lo.Type.NormalizeExpand(), Type.Int, null, new BuilderSyntaxTree(loBuf, this)); + var loWr = EmitCoercionIfNecessary(lo.Type.NormalizeExpand(), Type.Int, source.tok, new BuilderSyntaxTree(loBuf, this)); EmitExpr(lo, inLetExprBody, loWr, wStmts); loExpr = loBuf.Finish(); } @@ -2205,7 +2241,7 @@ protected override void EmitSeqSelectRange(Expression source, Expression lo, Exp DAST.Expression hiExpr = null; if (hi != null) { var hiBuf = new ExprBuffer(null); - var loWr = EmitCoercionIfNecessary(hi.Type.NormalizeExpand(), Type.Int, null, new BuilderSyntaxTree(hiBuf, this)); + var loWr = EmitCoercionIfNecessary(hi.Type.NormalizeExpand(), Type.Int, source.tok, new BuilderSyntaxTree(hiBuf, this)); EmitExpr(hi, inLetExprBody, loWr, wStmts); hiExpr = hiBuf.Finish(); } @@ -2301,7 +2337,7 @@ protected override void EmitDestructor(Action source, Formal builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_Select( sourceAST, Sequence.UnicodeFromString(compileName), - new FieldMutability_ConstantField(), + new FieldMutability_InternalClassConstantFieldOrDatatypeDestructor(), true, GenType(dtor.Type) )); } @@ -2379,9 +2415,8 @@ protected override ConcreteSyntaxTree EmitCallToIsMethod(RedirectingTypeDecl dec protected override ConcreteSyntaxTree EmitAnd(Action lhs, ConcreteSyntaxTree wr) { if (GetExprBuilder(wr, out var builder)) { - var binOp = builder.Builder.BinOp((DAST.BinOp)DAST.BinOp.create_Passthrough( - Sequence.UnicodeFromString("&&") - )); + var boolType = (DAST.Type)DAST.Type.create_Primitive(Primitive.create_Bool()); + var binOp = builder.Builder.BinOp((DAST.BinOp)DAST.BinOp.create_And(), boolType, boolType, boolType); lhs(new BuilderSyntaxTree(binOp, this)); return new BuilderSyntaxTree(binOp, this); @@ -2518,11 +2553,12 @@ protected override ConcreteSyntaxTree CreateIIFE1(int source, Type resultType, I protected override void EmitUnaryExpr(ResolvedUnaryOp op, Expression expr, bool inLetExprBody, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { if (GetExprConverter(wr, wStmts, out var container, out var convert)) { + var dastExpr = convert(expr); switch (op) { case ResolvedUnaryOp.BoolNot: { container.Builder.AddExpr((DAST.Expression)DAST.Expression.create_UnOp( UnaryOp.create_Not(), - convert(expr), + dastExpr, new UnaryOpFormat_NoFormat() )); break; @@ -2530,7 +2566,7 @@ protected override void EmitUnaryExpr(ResolvedUnaryOp op, Expression expr, bool case ResolvedUnaryOp.BitwiseNot: { container.Builder.AddExpr((DAST.Expression)DAST.Expression.create_UnOp( UnaryOp.create_BitwiseNot(), - convert(expr), + dastExpr, new UnaryOpFormat_NoFormat() )); break; @@ -2538,7 +2574,7 @@ protected override void EmitUnaryExpr(ResolvedUnaryOp op, Expression expr, bool case ResolvedUnaryOp.Cardinality: { container.Builder.AddExpr((DAST.Expression)DAST.Expression.create_UnOp( UnaryOp.create_Cardinality(), - convert(expr), + dastExpr, new UnaryOpFormat_NoFormat() )); break; @@ -2557,11 +2593,10 @@ private static DAST.Expression Not(_IExpression expr, bool mergeInner = true) { mergeInner ? new UnaryOpFormat_CombineFormat() : new UnaryOpFormat_NoFormat()); } - private static DAST.Expression BinaryOp(_IBinOp op, _IExpression left, _IExpression right, _IBinaryOpFormat format = null) { + private static DAST.Expression BinaryOp(_ITypedBinOp typedOp, _IExpression left, _IExpression right, _IBinaryOpFormat format = null) { format ??= new BinaryOpFormat_NoFormat(); - return (DAST.Expression)DAST.Expression.create_BinOp( - op, left, right, format + return (DAST.Expression)DAST.Expression.create_BinOp(typedOp, left, right, format ); } @@ -2587,6 +2622,7 @@ protected override void CompileBinOp(BinaryExpr.ResolvedOpcode op, truncateResult = false; convertE1_to_int = false; coerceE1 = false; + var overflows = e0Type is BitvectorType; opString = op switch { BinaryExpr.ResolvedOpcode.Iff => "==", @@ -2638,8 +2674,12 @@ protected override void CompileBinOp(BinaryExpr.ResolvedOpcode op, _ => null }; + var typeLeft = GenType(e0Type); + var typeRight = GenType(e1Type); + var typeResult = GenType(resultType); + object B(_IBinOp binOp) { - return builder.Builder.BinOp((DAST.BinOp)binOp); + return builder.Builder.BinOp((DAST.BinOp)binOp, typeLeft, typeRight, typeResult); } var opStringClosure = opString; @@ -2647,6 +2687,14 @@ object C(System.Func callback return builder.Builder.BinOp(opStringClosure, callback); } + TypedBinOp TypeOp(_IBinOp binOp) { + return (TypedBinOp)TypedBinOp.create_TypedBinOp(binOp, typeLeft, typeRight, typeResult); + } + + TypedBinOp TypeOpRev(_IBinOp binOp) { + return (TypedBinOp)TypedBinOp.create_TypedBinOp(binOp, typeRight, typeLeft, typeResult); + } + var newBuilder = op switch { BinaryExpr.ResolvedOpcode.EqCommon => B((BinOp)BinOp.create_Eq( e0Type.IsRefType @@ -2657,32 +2705,32 @@ object C(System.Func callback BinaryExpr.ResolvedOpcode.MultiSetEq => B((BinOp)BinOp.create_Eq(false)), BinaryExpr.ResolvedOpcode.NeqCommon => C((left, right) => Not(BinaryOp( - BinOp.create_Eq( + TypeOp(BinOp.create_Eq( e0Type.IsRefType - ), left, right))), + )), left, right))), BinaryExpr.ResolvedOpcode.SetNeq => C((left, right) => - Not(BinaryOp(BinOp.create_Eq(false), left, right))), + Not(BinaryOp(TypeOp(BinOp.create_Eq(false)), left, right))), BinaryExpr.ResolvedOpcode.SeqNeq => C((left, right) => - Not(BinaryOp(BinOp.create_Eq(false), left, right))), + Not(BinaryOp(TypeOp(BinOp.create_Eq(false)), left, right))), BinaryExpr.ResolvedOpcode.MapNeq => C((left, right) => - Not(BinaryOp(BinOp.create_Eq(false), left, right))), + Not(BinaryOp(TypeOp(BinOp.create_Eq(false)), left, right))), BinaryExpr.ResolvedOpcode.MultiSetNeq => C((left, right) => - Not(BinaryOp(BinOp.create_Eq(false), left, right))), + Not(BinaryOp(TypeOp(BinOp.create_Eq(false)), left, right))), BinaryExpr.ResolvedOpcode.Div => - B(NeedsEuclideanDivision(resultType) ? BinOp.create_EuclidianDiv() : BinOp.create_Div()), + B(NeedsEuclideanDivision(resultType) ? BinOp.create_EuclidianDiv() : BinOp.create_Div(overflows)), BinaryExpr.ResolvedOpcode.Mod => B(NeedsEuclideanDivision(resultType) ? BinOp.create_EuclidianMod() : BinOp.create_Mod()), BinaryExpr.ResolvedOpcode.Imp => C((left, right) => BinaryOp( - DAST.BinOp.create_Or(), + TypeOp(DAST.BinOp.create_Or()), Not(left, false), right, new BinaryOpFormat_ImpliesFormat() )), BinaryExpr.ResolvedOpcode.Iff => C((left, right) => BinaryOp( - BinOp.create_Eq(false), + TypeOp(BinOp.create_Eq(false)), left, right, new BinaryOpFormat_EquivalenceFormat() )), BinaryExpr.ResolvedOpcode.InSet => B(DAST.BinOp.create_In()), // TODO: Differentiate? @@ -2705,11 +2753,11 @@ object C(System.Func callback B(DAST.BinOp.create_Subset()), BinaryExpr.ResolvedOpcode.Superset => C((left, right) => - BinaryOp(new BinOp_Subset(), right, left, + BinaryOp(TypeOpRev(new BinOp_Subset()), right, left, new BinaryOpFormat_ReverseFormat())), BinaryExpr.ResolvedOpcode.ProperSuperset => C((left, right) => - BinaryOp(new BinOp_ProperSubset(), right, left, + BinaryOp(TypeOpRev(new BinOp_ProperSubset()), right, left, new BinaryOpFormat_ReverseFormat())), BinaryExpr.ResolvedOpcode.MultiSetUnion => @@ -2726,11 +2774,11 @@ object C(System.Func callback B(DAST.BinOp.create_Submultiset()), BinaryExpr.ResolvedOpcode.MultiSuperset => C((left, right) => - BinaryOp(new BinOp_Submultiset(), right, left, + BinaryOp(TypeOpRev(new BinOp_Submultiset()), right, left, new BinaryOpFormat_ReverseFormat())), BinaryExpr.ResolvedOpcode.ProperMultiSuperset => C((left, right) => - BinaryOp(new BinOp_ProperSubmultiset(), right, left, + BinaryOp(TypeOpRev(new BinOp_ProperSubmultiset()), right, left, new BinaryOpFormat_ReverseFormat())), BinaryExpr.ResolvedOpcode.MapMerge => @@ -2745,22 +2793,22 @@ object C(System.Func callback BinaryExpr.ResolvedOpcode.NotInMap => C((left, right) => - Not(BinaryOp(new BinOp_In(), left, right))), + Not(BinaryOp(TypeOp(new BinOp_In()), left, right))), BinaryExpr.ResolvedOpcode.NotInSet => C((left, right) => - Not(BinaryOp(new BinOp_In(), left, right))), + Not(BinaryOp(TypeOp(new BinOp_In()), left, right))), BinaryExpr.ResolvedOpcode.NotInSeq => C((left, right) => - Not(BinaryOp(new BinOp_In(), left, right))), + Not(BinaryOp(TypeOp(new BinOp_In()), left, right))), BinaryExpr.ResolvedOpcode.NotInMultiSet => C((left, right) => - Not(BinaryOp(new BinOp_In(), left, right))), + Not(BinaryOp(TypeOp(new BinOp_In()), left, right))), BinaryExpr.ResolvedOpcode.Concat => B(BinOp.create_Concat()), BinaryExpr.ResolvedOpcode.And => B(BinOp.create_And()), BinaryExpr.ResolvedOpcode.Or => B(BinOp.create_Or()), - BinaryExpr.ResolvedOpcode.Add => B(BinOp.create_Plus()), - BinaryExpr.ResolvedOpcode.Sub => B(BinOp.create_Minus()), - BinaryExpr.ResolvedOpcode.Mul => B(BinOp.create_Times()), + BinaryExpr.ResolvedOpcode.Add => B(BinOp.create_Plus(overflows)), + BinaryExpr.ResolvedOpcode.Sub => B(BinOp.create_Minus(overflows)), + BinaryExpr.ResolvedOpcode.Mul => B(BinOp.create_Times(overflows)), BinaryExpr.ResolvedOpcode.BitwiseAnd => B(BinOp.create_BitwiseAnd()), BinaryExpr.ResolvedOpcode.BitwiseOr => B(BinOp.create_BitwiseOr()), BinaryExpr.ResolvedOpcode.BitwiseXor => B(BinOp.create_BitwiseXor()), @@ -2772,24 +2820,24 @@ object C(System.Func callback B(BinOp.create_LtChar()), BinaryExpr.ResolvedOpcode.Le => C((left, right) => - Not(BinaryOp(new BinOp_Lt(), right, left, + Not(BinaryOp(TypeOpRev(new BinOp_Lt()), right, left, new BinaryOpFormat_ReverseFormat()))), BinaryExpr.ResolvedOpcode.LeChar => C((left, right) => - Not(BinaryOp(new BinOp_LtChar(), right, left, + Not(BinaryOp(TypeOpRev(new BinOp_LtChar()), right, left, new BinaryOpFormat_ReverseFormat()))), BinaryExpr.ResolvedOpcode.Gt => C((left, right) => - BinaryOp(new BinOp_Lt(), right, left, new BinaryOpFormat_ReverseFormat())), + BinaryOp(TypeOpRev(new BinOp_Lt()), right, left, new BinaryOpFormat_ReverseFormat())), BinaryExpr.ResolvedOpcode.GtChar => C((left, right) => - BinaryOp(new BinOp_LtChar(), right, left, new BinaryOpFormat_ReverseFormat())), + BinaryOp(TypeOpRev(new BinOp_LtChar()), right, left, new BinaryOpFormat_ReverseFormat())), BinaryExpr.ResolvedOpcode.Ge => C((left, right) => - Not(BinaryOp(new BinOp_Lt(), left, right))), + Not(BinaryOp(TypeOp(new BinOp_Lt()), left, right))), BinaryExpr.ResolvedOpcode.GeChar => C((left, right) => - Not(BinaryOp(new BinOp_LtChar(), left, right))), + Not(BinaryOp(TypeOp(new BinOp_LtChar()), left, right))), _ => B(DAST.BinOp.create_Passthrough(Sequence.UnicodeFromString($"Unsupported: Operator {op}"))), }; @@ -2803,10 +2851,25 @@ object C(System.Func callback } } + public BuilderSyntaxTree WrBuffer(out ExprBuffer buf) { + buf = new ExprBuffer(null); + var wGuard = new BuilderSyntaxTree(buf, this); + return wGuard; + } protected override void EmitITE(Expression guard, Expression thn, Expression els, Type resultType, bool inLetExprBody, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { if (GetExprConverter(wr, wStmts, out var builder, out var convert)) { + DAST.Expression convertedGuard; + if (guard.Type is BoolType) { + if (guard is UnaryOpExpr { ResolvedOp: UnaryOpExpr.ResolvedOpcode.BoolNot, E: var innerGuard } unaryOpExpr && innerGuard.Type is not BoolType) { + guard = unaryOpExpr.E; + } + convertedGuard = convert(guard); + } else { + EmitConversionExpr(guard, guard.Type, new BoolType(), inLetExprBody, WrBuffer(out var buf), wStmts); + convertedGuard = buf.Finish(); + } builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_Ite( - convert(guard), + convertedGuard, convert(thn), convert(els) )); @@ -2824,16 +2887,20 @@ protected override void EmitConversionExpr(Expression fromExpr, Type fromType, T if (toType.Equals(fromType)) { EmitExpr(fromExpr, inLetExprBody, builder, wStmts); } else { - EmitExpr(fromExpr, inLetExprBody, new BuilderSyntaxTree(builder.Builder.Convert( - GenType(fromType), - GenType(toType) - ), this), wStmts); + EmitExpr(fromExpr, inLetExprBody, EmitConversion(builder, fromType, toType), wStmts); } } else { throw new InvalidOperationException(); } } + private BuilderSyntaxTree EmitConversion(BuilderSyntaxTree builder, Type fromType, Type toType) { + return new BuilderSyntaxTree(builder.Builder.Convert( + GenType(fromType), + GenType(toType) + ), this); + } + protected override void EmitConstructorCheck(string source, DatatypeCtor ctor, ConcreteSyntaxTree wr) { if (GetExprBuilder(wr, out var builder)) { builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_TypeTest( @@ -2859,15 +2926,15 @@ protected override void EmitTypeTest(string localName, Type fromType, Type toTyp } protected override void EmitIsIntegerTest(Expression source, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { - throw new UnsupportedFeatureException(source.Tok, Feature.TypeTests); + AddUnsupportedFeature(source.Tok, Feature.TypeTests); } protected override void EmitIsUnicodeScalarValueTest(Expression source, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { - throw new UnsupportedFeatureException(source.Tok, Feature.TypeTests); + AddUnsupportedFeature(source.Tok, Feature.TypeTests); } protected override void EmitIsInIntegerRange(Expression source, BigInteger lo, BigInteger hi, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { - throw new UnsupportedFeatureException(source.Tok, Feature.TypeTests); + AddUnsupportedFeature(source.Tok, Feature.TypeTests); } protected override void EmitCollectionDisplay(CollectionType ct, IToken tok, List elements, @@ -2919,7 +2986,7 @@ protected override void EmitSetBuilder_New(ConcreteSyntaxTree wr, SetComprehensi if (GetStatementBuilder(wr, out var builder)) { var eType = e.Type.AsSetType; if (eType == null) {// dafny0/GeneralNewtypeCollections - throw new UnsupportedFeatureException(e.tok, Feature.NonNativeNewtypes); + AddUnsupportedFeature(e.tok, Feature.NonNativeNewtypes); } var elemType = GenType(eType.Arg); var setBuilderType = DAST.Type.create_SetBuilder(elemType); @@ -2974,8 +3041,7 @@ protected override void EmitSetBuilder_Add(CollectionType ct, string collName, E // Normally wStmt is a BuilderSyntaxTree but it might not while the compiler is being developed private DAST.Expression ConvertExpression(Expression term, ConcreteSyntaxTree wStmt) { - var buffer0 = new ExprBuffer(null); - EmitExpr(term, false, new BuilderSyntaxTree(buffer0, this), wStmt); + EmitExpr(term, false, WrBuffer(out var buffer0), wStmt); return buffer0.Finish(); } @@ -2986,9 +3052,7 @@ private DAST.Expression ConvertExpressionNoStatement(Expression term) { } private BuilderSyntaxTree CreateExprBuilder() { - var exprBuffer = new ExprBuffer(null); - var exprBuilder = new BuilderSyntaxTree(exprBuffer, this); - return exprBuilder; + return WrBuffer(out _); } protected override ConcreteSyntaxTree EmitMapBuilder_Add(MapType mt, IToken tok, string collName, Expression term, @@ -3006,8 +3070,7 @@ protected override ConcreteSyntaxTree EmitMapBuilder_Add(MapType mt, IToken tok, return keyBuilder; } else { AddUnsupported("EMitMapBuilder_Add"); - var buffer1 = new ExprBuffer(null); - return new BuilderSyntaxTree(buffer1, this); + return WrBuffer(out _); } } @@ -3027,13 +3090,18 @@ protected override Action GetSubtypeCondition(string tmpVarN if (boundVarType.IsNonNullRefType) { typeTest = wr => { if (GetExprBuilder(wr, out var builder)) { - builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_BinOp( - DAST.BinOp.create_Passthrough(Sequence.UnicodeFromString("&&")), + var boolType = DAST.Type.create_Primitive(Primitive.create_Bool()); + var tmpVarType = GenType(boundVarType); + var tmpVarNotNull = DAST.Expression.create_UnOp( + DAST.UnaryOp.create_Not(), DAST.Expression.create_BinOp( - DAST.BinOp.create_Passthrough(Sequence.UnicodeFromString("!=")), + TypedBinOp.create_TypedBinOp(DAST.BinOp.create_Eq(true), tmpVarType, tmpVarType, boolType), DAST.Expression.create_Ident(Sequence.UnicodeFromString(tmpVarName)), DAST.Expression.create_Literal(DAST.Literal.create_Null(GenType(boundVarType))), - new BinaryOpFormat_NoFormat()), + new BinaryOpFormat_NoFormat()), new UnaryOpFormat_CombineFormat()); + builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_BinOp( + TypedBinOp.create_TypedBinOp(BinOp.create_And(), boolType, boolType, boolType), + tmpVarNotNull, baseExpr, new BinaryOpFormat_NoFormat() )); @@ -3044,10 +3112,12 @@ protected override Action GetSubtypeCondition(string tmpVarN } else { typeTest = wr => { if (GetExprBuilder(wr, out var builder)) { + var boolType = DAST.Type.create_Primitive(Primitive.create_Bool()); + var tmpVarType = GenType(boundVarType); builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_BinOp( - DAST.BinOp.create_Passthrough(Sequence.UnicodeFromString("||")), + TypedBinOp.create_TypedBinOp(BinOp.create_Or(), boolType, boolType, boolType), DAST.Expression.create_BinOp( - DAST.BinOp.create_Passthrough(Sequence.UnicodeFromString("==")), + TypedBinOp.create_TypedBinOp(DAST.BinOp.create_Eq(true), tmpVarType, tmpVarType, boolType), DAST.Expression.create_Ident(Sequence.UnicodeFromString(tmpVarName)), DAST.Expression.create_Literal(DAST.Literal.create_Null(GenType(boundVarType))), new BinaryOpFormat_NoFormat() @@ -3095,10 +3165,8 @@ protected override (Type, Action) EmitIntegerRange(Type type } return (result, (wr) => { - var loBuf = new ExprBuffer(null); - wLo(new BuilderSyntaxTree(loBuf, this)); - var hiBuf = new ExprBuffer(null); - wHi(new BuilderSyntaxTree(hiBuf, this)); + wLo(WrBuffer(out var loBuf)); + wHi(WrBuffer(out var hiBuf)); if (GetExprBuilder(wr, out var builder)) { builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_IntRange( diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy index c2d94f0d3db..472b897393f 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy @@ -1,192 +1,204 @@ -/*This module exists to increase code coverage of the generated code +/*These modules exists to increase code coverage of the generated code and test it as well. All modules ending with "Coverage" will be compiled to DafnyCore.Test */ module DafnyToRustCompilerCoverage { - module RASTCoverage { - import opened RAST - import opened Std.Wrappers - import opened DAST.Format - import Strings = Std.Strings - import ExpressionOptimization + import opened DafnyToRustCompiler + import opened DAST + import opened DafnyToRustCompilerDefinitions - method AssertCoverage(x: bool) - { - expect x; - } + method TestIsCopy() { + expect IsNewtypeCopy(NewtypeRange.Bool); + expect IsNewtypeCopy(NewtypeRange.U128(true)); + expect IsNewtypeCopy(NewtypeRange.U128(false)); + expect !IsNewtypeCopy(NewtypeRange.BigInt); + expect !IsNewtypeCopy(NewtypeRange.NoRange); + } +} - method TestExpr() { - TestOptimizeToString(); - TestPrintingInfo(); - TestNoExtraSemicolonAfter(); - } +module RASTCoverage { + import opened RAST + import opened Std.Wrappers + import opened DAST.Format + import Strings = Std.Strings + import ExpressionOptimization - method TestNoOptimize(e: Expr) - //requires e.Optimize() == e // Too expensive - { - } + method AssertCoverage(x: bool) + { + expect x; + } + + method TestExpr() { + TestOptimizeToString(); + TestPrintingInfo(); + TestNoExtraSemicolonAfter(); + } + + method TestNoOptimize(e: Expr) + //requires e.Optimize() == e // Too expensive + { + } - function ConversionNum(t: Type, x: Expr): Expr { - Call( - ExprFromPath( + function ConversionNum(t: Type, x: Expr): Expr { + Call( + ExprFromPath( + PMemberSelect( PMemberSelect( - PMemberSelect( - Global(), - "dafny_runtime"), - "truncate!")), - [x, ExprFromType(t)]) - } + Global(), + "dafny_runtime"), + "truncate!")), + [x, ExprFromType(t)]) + } - function DafnyIntLiteral(s: string): Expr { - Call(ExprFromPath(PMemberSelect(dafny_runtime, "int!")), [LiteralInt("1")]) - } + function DafnyIntLiteral(s: string): Expr { + Call(ExprFromPath(PMemberSelect(dafny_runtime, "int!")), [LiteralInt("1")]) + } - function Optimize(e: Expr): Expr { - ExpressionOptimization.ExprSimplifier().ReplaceExpr(e) - } + function Optimize(e: Expr): Expr { + ExpressionOptimization.ExprSimplifier().ReplaceExpr(e) + } - method TestOptimizeToString() { - var x := Identifier("x"); - var y := Identifier("y"); - TestNoOptimize(UnaryOp("&", Call(Select(x, "clone"), [y]), UnaryOpFormat.NoFormat)); - AssertCoverage(Optimize(UnaryOp("!", BinaryOp("==", x, y, BinaryOpFormat.NoFormat), - CombineFormat())) == BinaryOp("!=", x, y, BinaryOpFormat.NoFormat)); - AssertCoverage(Optimize(UnaryOp("!", BinaryOp("<", x, y, BinaryOpFormat.NoFormat), - CombineFormat())) == BinaryOp(">=", x, y, BinaryOpFormat.NoFormat())); - AssertCoverage(Optimize(UnaryOp("!", BinaryOp("<", x, y, ReverseFormat()), - CombineFormat())) == BinaryOp("<=", y, x, BinaryOpFormat.NoFormat())); - AssertCoverage(Optimize(ConversionNum(I128, DafnyIntLiteral("1"))) == LiteralInt("1")); - TestNoOptimize(ConversionNum(I128, x)); - AssertCoverage(Optimize(StmtExpr(DeclareVar(MUT, "z", Some(I128), None), StmtExpr(AssignVar("z", y), RawExpr("return")))) - == StmtExpr(DeclareVar(MUT, "z", Some(I128), Some(y)), RawExpr("return"))); - TestNoOptimize(StmtExpr(DeclareVar(MUT, "z", Some(I128), None), StmtExpr(AssignVar("w", y), RawExpr("return")))); + method TestOptimizeToString() { + var x := Identifier("x"); + var y := Identifier("y"); + TestNoOptimize(UnaryOp("&", Call(Select(x, "clone"), [y]), UnaryOpFormat.NoFormat)); + AssertCoverage(Optimize(UnaryOp("!", BinaryOp("==", x, y, BinaryOpFormat.NoFormat), + CombineFormat())) == BinaryOp("!=", x, y, BinaryOpFormat.NoFormat)); + AssertCoverage(Optimize(UnaryOp("!", BinaryOp("<", x, y, BinaryOpFormat.NoFormat), + CombineFormat())) == BinaryOp(">=", x, y, BinaryOpFormat.NoFormat())); + AssertCoverage(Optimize(UnaryOp("!", BinaryOp("<", x, y, ReverseFormat()), + CombineFormat())) == BinaryOp("<=", y, x, BinaryOpFormat.NoFormat())); + AssertCoverage(Optimize(ConversionNum(I128, DafnyIntLiteral("1"))) == LiteralInt("1")); + TestNoOptimize(ConversionNum(I128, x)); + AssertCoverage(Optimize(StmtExpr(DeclareVar(MUT, "z", Some(I128), None), StmtExpr(AssignVar("z", y), RawExpr("return")))) + == StmtExpr(DeclareVar(MUT, "z", Some(I128), Some(y)), RawExpr("return"))); + TestNoOptimize(StmtExpr(DeclareVar(MUT, "z", Some(I128), None), StmtExpr(AssignVar("w", y), RawExpr("return")))); - TestNoOptimize(x); - TestNoOptimize(StmtExpr(x, x)); - TestNoOptimize(StmtExpr(Match(x, []), x)); - TestNoOptimize(StmtExpr(StructBuild(x, []), x)); - TestNoOptimize(StmtExpr(Tuple([]), x)); - TestNoOptimize(StmtExpr(UnaryOp("&", x, UnaryOpFormat.NoFormat), x)); - TestNoOptimize(StmtExpr(BinaryOp("&&", x, x, BinaryOpFormat.NoFormat), x)); - TestNoOptimize(StmtExpr(TypeAscription(x, I128), x)); - TestNoOptimize(StmtExpr(LiteralInt("1"), x)); - TestNoOptimize(StmtExpr(LiteralString("2", true, false), x)); - TestNoOptimize(StmtExpr(LiteralString("3", false, true), x)); - AssertCoverage(Optimize(StmtExpr(DeclareVar(MUT, "z", Some(I128), None), StmtExpr(AssignVar("z", y), RawExpr("return")))) - == StmtExpr(DeclareVar(MUT, "z", Some(I128), Some(y)), RawExpr("return"))); + TestNoOptimize(x); + TestNoOptimize(StmtExpr(x, x)); + TestNoOptimize(StmtExpr(Match(x, []), x)); + TestNoOptimize(StmtExpr(StructBuild(x, []), x)); + TestNoOptimize(StmtExpr(Tuple([]), x)); + TestNoOptimize(StmtExpr(UnaryOp("&", x, UnaryOpFormat.NoFormat), x)); + TestNoOptimize(StmtExpr(BinaryOp("&&", x, x, BinaryOpFormat.NoFormat), x)); + TestNoOptimize(StmtExpr(TypeAscription(x, I128), x)); + TestNoOptimize(StmtExpr(LiteralInt("1"), x)); + TestNoOptimize(StmtExpr(LiteralString("2", true, false), x)); + TestNoOptimize(StmtExpr(LiteralString("3", false, true), x)); + AssertCoverage(Optimize(StmtExpr(DeclareVar(MUT, "z", Some(I128), None), StmtExpr(AssignVar("z", y), RawExpr("return")))) + == StmtExpr(DeclareVar(MUT, "z", Some(I128), Some(y)), RawExpr("return"))); - var coverageExpression := [ - RawExpr("abc"), - Identifier("x"), - Match(Identifier("x"), [MatchCase(RawPattern("abc"), Identifier("x"))]), - StmtExpr(RawExpr("panic!()"), Identifier("a")), - Block(RawExpr("abc")), - StructBuild(Identifier("dummy"), [AssignIdentifier("foo", Identifier("bar"))]), - StructBuild(Identifier("dummy"), [AssignIdentifier("foo", Identifier("bar")), AssignIdentifier("foo2", Identifier("bar"))]), - Tuple([Identifier("x")]), - UnaryOp("-", Identifier("x"), UnaryOpFormat.NoFormat), - BinaryOp("+", Identifier("x"), Identifier("y"), BinaryOpFormat.NoFormat), - TypeAscription(Identifier("x"), I128), - LiteralInt("322"), - LiteralString("abc", true, false), - LiteralString("abc", false, true), - DeclareVar(MUT, "abc", Some(I128), None), - DeclareVar(CONST, "abc", None, Some(Identifier("x"))), - AssignVar("abc", Identifier("x")), - IfExpr(Identifier("x"), Identifier("x"), Identifier("x")), - Loop(Some(Identifier("x")), Identifier("x")), - For("abc", Identifier("x"), Identifier("x")), - Labelled("abc", Identifier("x")), - Break(None), - Break(Some("l")), - Continue(None), - Continue(Some("l")), - Return(None), - Return(Some(Identifier("x"))), - Call(Identifier("x"), []), - Call(Identifier("x"), [Identifier("x"), Identifier("y")]), - CallType(Identifier("x"), [I128, U32]), - Select(Identifier("x"), "abc"), - ExprFromPath(PMemberSelect(Crate(), "abc")), - ExprFromPath(PMemberSelect(Global(), "abc")) - ]; - for i := 0 to |coverageExpression| { - var c := coverageExpression[i]; - var _ := c.printingInfo; - var _ := Optimize(c); - var _ := map[c := c.ToString("")]; - var _ := Optimize(StmtExpr(DeclareVar(MUT, "abc", Some(I128), None), c)); - var _ := Optimize(StmtExpr(DeclareVar(MUT, "abc", Some(I128), None), StmtExpr(AssignVar("abc", c), RawExpr("")))); - var _ := Optimize(UnaryOp("&", c, UnaryOpFormat.NoFormat())); - var _ := Optimize(UnaryOp("!", c, UnaryOpFormat.NoFormat())); - var _ := Optimize(ConversionNum(U8, c)); - var _ := Optimize(ConversionNum(U8, Call(c, []))); - var _ := c.RightMostIdentifier(); + var coverageExpression := [ + RawExpr("abc"), + Identifier("x"), + Match(Identifier("x"), [MatchCase(RawPattern("abc"), Identifier("x"))]), + StmtExpr(RawExpr("panic!()"), Identifier("a")), + Block(RawExpr("abc")), + StructBuild(Identifier("dummy"), [AssignIdentifier("foo", Identifier("bar"))]), + StructBuild(Identifier("dummy"), [AssignIdentifier("foo", Identifier("bar")), AssignIdentifier("foo2", Identifier("bar"))]), + Tuple([Identifier("x")]), + UnaryOp("-", Identifier("x"), UnaryOpFormat.NoFormat), + BinaryOp("+", Identifier("x"), Identifier("y"), BinaryOpFormat.NoFormat), + TypeAscription(Identifier("x"), I128), + LiteralInt("322"), + LiteralString("abc", true, false), + LiteralString("abc", false, true), + DeclareVar(MUT, "abc", Some(I128), None), + DeclareVar(CONST, "abc", None, Some(Identifier("x"))), + AssignVar("abc", Identifier("x")), + IfExpr(Identifier("x"), Identifier("x"), Identifier("x")), + Loop(Some(Identifier("x")), Identifier("x")), + For("abc", Identifier("x"), Identifier("x")), + Labelled("abc", Identifier("x")), + Break(None), + Break(Some("l")), + Continue(None), + Continue(Some("l")), + Return(None), + Return(Some(Identifier("x"))), + Call(Identifier("x"), []), + Call(Identifier("x"), [Identifier("x"), Identifier("y")]), + CallType(Identifier("x"), [I128, U32]), + Select(Identifier("x"), "abc"), + ExprFromPath(PMemberSelect(Crate(), "abc")), + ExprFromPath(PMemberSelect(Global(), "abc")) + ]; + for i := 0 to |coverageExpression| { + var c := coverageExpression[i]; + var _ := c.printingInfo; + var _ := Optimize(c); + var _ := map[c := c.ToString("")]; + var _ := Optimize(StmtExpr(DeclareVar(MUT, "abc", Some(I128), None), c)); + var _ := Optimize(StmtExpr(DeclareVar(MUT, "abc", Some(I128), None), StmtExpr(AssignVar("abc", c), RawExpr("")))); + var _ := Optimize(UnaryOp("&", c, UnaryOpFormat.NoFormat())); + var _ := Optimize(UnaryOp("!", c, UnaryOpFormat.NoFormat())); + var _ := Optimize(ConversionNum(U8, c)); + var _ := Optimize(ConversionNum(U8, Call(c, []))); + var _ := c.RightMostIdentifier(); - } } + } - method TestPrintingInfo() { - var x := Identifier("x"); - var y := Identifier("y"); - var bnf := BinaryOpFormat.NoFormat; - AssertCoverage(RawExpr("x").printingInfo.UnknownPrecedence?); - AssertCoverage(x.printingInfo == Precedence(1)); - AssertCoverage(LiteralInt("3").printingInfo == Precedence(1)); - AssertCoverage(LiteralString("abc", true, false).printingInfo == Precedence(1)); - AssertCoverage(UnaryOp("?", x, UnaryOpFormat.NoFormat).printingInfo == SuffixPrecedence(5)); - AssertCoverage(UnaryOp("-", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); - AssertCoverage(UnaryOp("*", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); - AssertCoverage(UnaryOp("!", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); - AssertCoverage(UnaryOp("&", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); - AssertCoverage(UnaryOp("&mut", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); - AssertCoverage(UnaryOp("!!", x, UnaryOpFormat.NoFormat).printingInfo == UnknownPrecedence()); - AssertCoverage(Select(x, "name").printingInfo == PrecedenceAssociativity(2, LeftToRight)); - AssertCoverage(ExprFromPath(PMemberSelect(Global(), "name")).printingInfo == Precedence(2)); - AssertCoverage(Call(x, []).printingInfo == PrecedenceAssociativity(2, LeftToRight)); - AssertCoverage(TypeAscription(x, I128).printingInfo == PrecedenceAssociativity(10, LeftToRight)); - AssertCoverage(BinaryOp("*", x, y, bnf).printingInfo == PrecedenceAssociativity(20, LeftToRight)); - AssertCoverage(BinaryOp("/", x, y, bnf).printingInfo == PrecedenceAssociativity(20, LeftToRight)); - AssertCoverage(BinaryOp("%", x, y, bnf).printingInfo == PrecedenceAssociativity(20, LeftToRight)); - AssertCoverage(BinaryOp("+", x, y, bnf).printingInfo == PrecedenceAssociativity(30, LeftToRight)); - AssertCoverage(BinaryOp("-", x, y, bnf).printingInfo == PrecedenceAssociativity(30, LeftToRight)); - AssertCoverage(BinaryOp("<<", x, y, bnf).printingInfo == PrecedenceAssociativity(40, LeftToRight)); - AssertCoverage(BinaryOp(">>", x, y, bnf).printingInfo == PrecedenceAssociativity(40, LeftToRight)); - AssertCoverage(BinaryOp("&", x, y, bnf).printingInfo == PrecedenceAssociativity(50, LeftToRight)); - AssertCoverage(BinaryOp("^", x, y, bnf).printingInfo == PrecedenceAssociativity(60, LeftToRight)); - AssertCoverage(BinaryOp("|", x, y, bnf).printingInfo == PrecedenceAssociativity(70, LeftToRight)); - AssertCoverage(BinaryOp("==", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); - AssertCoverage(BinaryOp("!=", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); - AssertCoverage(BinaryOp("<", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); - AssertCoverage(BinaryOp(">", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); - AssertCoverage(BinaryOp("<=", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); - AssertCoverage(BinaryOp(">=", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); - AssertCoverage(BinaryOp("&&", x, y, bnf).printingInfo == PrecedenceAssociativity(90, LeftToRight)); - AssertCoverage(BinaryOp("||", x, y, bnf).printingInfo == PrecedenceAssociativity(100, LeftToRight)); - AssertCoverage(BinaryOp("..", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RequiresParentheses)); - AssertCoverage(BinaryOp("..=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RequiresParentheses)); - AssertCoverage(BinaryOp("=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("+=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("-=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("*=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("/=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("%=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("&=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("|=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("^=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("<<=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp(">>=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); - AssertCoverage(BinaryOp("?!?", x, y, bnf).printingInfo == PrecedenceAssociativity(0, RequiresParentheses)); - AssertCoverage(Break(None).printingInfo == UnknownPrecedence()); - } + method TestPrintingInfo() { + var x := Identifier("x"); + var y := Identifier("y"); + var bnf := BinaryOpFormat.NoFormat; + AssertCoverage(RawExpr("x").printingInfo.UnknownPrecedence?); + AssertCoverage(x.printingInfo == Precedence(1)); + AssertCoverage(LiteralInt("3").printingInfo == Precedence(1)); + AssertCoverage(LiteralString("abc", true, false).printingInfo == Precedence(1)); + AssertCoverage(UnaryOp("?", x, UnaryOpFormat.NoFormat).printingInfo == SuffixPrecedence(5)); + AssertCoverage(UnaryOp("-", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); + AssertCoverage(UnaryOp("*", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); + AssertCoverage(UnaryOp("!", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); + AssertCoverage(UnaryOp("&", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); + AssertCoverage(UnaryOp("&mut", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); + AssertCoverage(UnaryOp("!!", x, UnaryOpFormat.NoFormat).printingInfo == UnknownPrecedence()); + AssertCoverage(Select(x, "name").printingInfo == PrecedenceAssociativity(2, LeftToRight)); + AssertCoverage(ExprFromPath(PMemberSelect(Global(), "name")).printingInfo == Precedence(2)); + AssertCoverage(Call(x, []).printingInfo == PrecedenceAssociativity(2, LeftToRight)); + AssertCoverage(TypeAscription(x, I128).printingInfo == PrecedenceAssociativity(10, LeftToRight)); + AssertCoverage(BinaryOp("*", x, y, bnf).printingInfo == PrecedenceAssociativity(20, LeftToRight)); + AssertCoverage(BinaryOp("/", x, y, bnf).printingInfo == PrecedenceAssociativity(20, LeftToRight)); + AssertCoverage(BinaryOp("%", x, y, bnf).printingInfo == PrecedenceAssociativity(20, LeftToRight)); + AssertCoverage(BinaryOp("+", x, y, bnf).printingInfo == PrecedenceAssociativity(30, LeftToRight)); + AssertCoverage(BinaryOp("-", x, y, bnf).printingInfo == PrecedenceAssociativity(30, LeftToRight)); + AssertCoverage(BinaryOp("<<", x, y, bnf).printingInfo == PrecedenceAssociativity(40, LeftToRight)); + AssertCoverage(BinaryOp(">>", x, y, bnf).printingInfo == PrecedenceAssociativity(40, LeftToRight)); + AssertCoverage(BinaryOp("&", x, y, bnf).printingInfo == PrecedenceAssociativity(50, LeftToRight)); + AssertCoverage(BinaryOp("^", x, y, bnf).printingInfo == PrecedenceAssociativity(60, LeftToRight)); + AssertCoverage(BinaryOp("|", x, y, bnf).printingInfo == PrecedenceAssociativity(70, LeftToRight)); + AssertCoverage(BinaryOp("==", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); + AssertCoverage(BinaryOp("!=", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); + AssertCoverage(BinaryOp("<", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); + AssertCoverage(BinaryOp(">", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); + AssertCoverage(BinaryOp("<=", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); + AssertCoverage(BinaryOp(">=", x, y, bnf).printingInfo == PrecedenceAssociativity(80, RequiresParentheses)); + AssertCoverage(BinaryOp("&&", x, y, bnf).printingInfo == PrecedenceAssociativity(90, LeftToRight)); + AssertCoverage(BinaryOp("||", x, y, bnf).printingInfo == PrecedenceAssociativity(100, LeftToRight)); + AssertCoverage(BinaryOp("..", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RequiresParentheses)); + AssertCoverage(BinaryOp("..=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RequiresParentheses)); + AssertCoverage(BinaryOp("=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("+=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("-=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("*=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("/=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("%=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("&=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("|=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("^=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("<<=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp(">>=", x, y, bnf).printingInfo == PrecedenceAssociativity(110, RightToLeft)); + AssertCoverage(BinaryOp("?!?", x, y, bnf).printingInfo == PrecedenceAssociativity(0, RequiresParentheses)); + AssertCoverage(Break(None).printingInfo == UnknownPrecedence()); + } - method TestNoExtraSemicolonAfter() { - AssertCoverage(RawExpr(";").NoExtraSemicolonAfter()); - AssertCoverage(!RawExpr("a").NoExtraSemicolonAfter()); - AssertCoverage(Return(None).NoExtraSemicolonAfter()); - AssertCoverage(Continue(None).NoExtraSemicolonAfter()); - AssertCoverage(Break(None).NoExtraSemicolonAfter()); - AssertCoverage(AssignVar("x", Identifier("y")).NoExtraSemicolonAfter()); - AssertCoverage(DeclareVar(MUT, "x", None, None).NoExtraSemicolonAfter()); - AssertCoverage(!Identifier("x").NoExtraSemicolonAfter()); - } + method TestNoExtraSemicolonAfter() { + AssertCoverage(RawExpr(";").NoExtraSemicolonAfter()); + AssertCoverage(!RawExpr("a").NoExtraSemicolonAfter()); + AssertCoverage(Return(None).NoExtraSemicolonAfter()); + AssertCoverage(Continue(None).NoExtraSemicolonAfter()); + AssertCoverage(Break(None).NoExtraSemicolonAfter()); + AssertCoverage(AssignVar("x", Identifier("y")).NoExtraSemicolonAfter()); + AssertCoverage(DeclareVar(MUT, "x", None, None).NoExtraSemicolonAfter()); + AssertCoverage(!Identifier("x").NoExtraSemicolonAfter()); } } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 1ba1e84e853..edc5e8aba3e 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -335,12 +335,12 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { Mod() := "%", And() := "&&", Or() := "||", - Div() := "/", + Div(overflow := false) := "/", Lt() := "<", LtChar() := "<", - Plus() := "+", - Minus() := "-", - Times() := "*", + Plus(overflow := false) := "+", + Minus(overflow := false) := "-", + Times(overflow := false) := "*", BitwiseAnd() := "&", BitwiseOr() := "|", BitwiseXor() := "^", @@ -348,25 +348,78 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { BitwiseShiftLeft() := "<<" ] + function AddOverflow(tpe: R.Type, overflow: bool): R.Type { + if !overflow then tpe else R.TMetaData(tpe, copySemantics := true, overflow := true) + } + + // We use the range as the wrapped type only if the base is a Primitive + function NewtypeRangeToUnwrappedBoundedRustType(base: Type, range: NewtypeRange): Option { + if base.IsPrimitiveInt() then + NewtypeRangeToRustType(range) + else + None + } + function NewtypeRangeToRustType(range: NewtypeRange) : Option { match range { case NoRange() => None - case U8() => Some(R.Type.U8) - case U16() => Some(R.Type.U16) - case U32() => Some(R.Type.U32) - case U64() => Some(R.Type.U64) - case U128() => Some(R.Type.U128) - case I8() => Some(R.Type.I8) - case I16() => Some(R.Type.I16) - case I32() => Some(R.Type.I32) - case I64() => Some(R.Type.I64) - case I128() => Some(R.Type.I128) - case USIZE() => Some(R.Type.USIZE) + case U8(overflow) => Some(AddOverflow(R.Type.U8, overflow)) + case U16(overflow) => Some(AddOverflow(R.Type.U16, overflow)) + case U32(overflow) => Some(AddOverflow(R.Type.U32, overflow)) + case U64(overflow) => Some(AddOverflow(R.Type.U64, overflow)) + case U128(overflow) => Some(AddOverflow(R.Type.U128, overflow)) + case I8(overflow) => Some(AddOverflow(R.Type.I8, overflow)) + case I16(overflow) => Some(AddOverflow(R.Type.I16, overflow)) + case I32(overflow) => Some(AddOverflow(R.Type.I32, overflow)) + case I64(overflow) => Some(AddOverflow(R.Type.I64, overflow)) + case I128(overflow) => Some(AddOverflow(R.Type.I128, overflow)) + case NativeArrayIndex() => Some(R.Type.USIZE) + case Bool => Some(R.Bool) case _ => None } } + predicate IsBooleanOperator(op: BinOp) { + op.And? || op.Or? + } + + predicate IsComplexArithmetic(op: BinOp) { + op.EuclidianDiv? || op.EuclidianMod? + } + + function GetUnwrappedBoundedRustType(tpe: Type): Option { + match tpe { + case UserDefined(ResolvedType(path, typeArgs, Newtype(base, range, erase), _, _, _)) => + NewtypeRangeToUnwrappedBoundedRustType(base, range) + case _ => None + } + } + + predicate NeedsUnwrappingConversion(tpe: Type) { + match tpe { + case UserDefined(ResolvedType(path, typeArgs, Newtype(base, range, erase), _, _, _)) => + NewtypeRangeToUnwrappedBoundedRustType(base, range).None? + case _ => false + } + } + + predicate IsNewtype(tpe: Type) { + tpe.UserDefined? && tpe.resolved.kind.Newtype? + } + + lemma CoveredAllNewtypeCases(tpe: Type) + requires GetUnwrappedBoundedRustType(tpe).None? + requires !NeedsUnwrappingConversion(tpe) + ensures !IsNewtype(tpe) + { + } + + predicate IsNewtypeCopy(range: NewtypeRange) { + && NewtypeRangeToRustType(range).Some? + && (range.HasArithmeticOperations() || range.Bool?) + } + predicate OwnershipGuarantee(expectedOwnership: Ownership, resultingOwnership: Ownership) { && (expectedOwnership != OwnershipAutoBorrowed ==> resultingOwnership == expectedOwnership) @@ -517,4 +570,130 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { ) )])) } + + // Requires the hashImplBody to depend on the variable "_state" + function HashImpl( + rTypeParamsDeclsWithHash: seq, + datatypeOrNewtypeType: R.Type, + hashImplBody: R.Expr + ): R.ModDecl { + R.ImplDecl( + R.ImplFor( + rTypeParamsDeclsWithHash, + R.Hash, + datatypeOrNewtypeType, + "", + [R.FnDecl( + 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")))], + None, + "", + Some(hashImplBody)))] + )) + } + + function UnaryOpsImpl( + op: char, + rTypeParamsDecls: seq, + newtypeType: R.Type, + newtypeConstructor: string + ): R.ModDecl + requires op in "!" + { + var (traitName, methodName) := match op { + case '!' => ("Not", "not") + }; + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.std.MSel("ops").MSel(traitName).AsType(), + newtypeType, + "", + [ R.TypeDeclMember("Output", newtypeType), + R.FnDecl( + R.PRIV, + R.Fn( + methodName, [], + [R.Formal.selfOwned], + Some(R.SelfOwned), + "", + Some(R.Identifier(newtypeConstructor).Apply1( + R.UnaryOp( + [op], + R.self.Sel("0"), + Format.UnaryOpFormat.NoFormat + )))))] + )) + } + + function OpsImpl( + op: char, + rTypeParamsDecls: seq, + newtypeType: R.Type, + newtypeConstructor: string + ): R.ModDecl + requires op in "+-/*" + { + var (traitName, methodName) := match op { + case '+' => ("Add", "add") + case '-' => ("Sub", "sub") + case '/' => ("Div", "div") + case '*' => ("Mul", "mul") + }; + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.std.MSel("ops").MSel(traitName).AsType(), + newtypeType, + "", + [ R.TypeDeclMember("Output", newtypeType), + R.FnDecl( + R.PRIV, + R.Fn( + methodName, [], + [R.Formal.selfOwned, + R.Formal("other", R.SelfOwned)], + Some(R.SelfOwned), + "", + Some(R.Identifier(newtypeConstructor).Apply1( + R.BinaryOp( + [op], + R.self.Sel("0"), + R.Identifier("other").Sel("0"), + Format.BinaryOpFormat.NoFormat + )))))] + )) + } + + function PartialOrdImpl( + rTypeParamsDecls: seq, + newtypeType: R.Type, + newtypeConstructor: string + ): R.ModDecl + { + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.std.MSel("cmp").MSel("PartialOrd").AsType(), + newtypeType, + "", + [ R.FnDecl( + R.PRIV, + R.Fn( + "partial_cmp", [], + [R.Formal.selfBorrowed, + 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")) + ])) + )) + ])) + } } \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-expression-optimization.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-expression-optimization.dfy index 2c569966437..4894570f2cb 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-expression-optimization.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-expression-optimization.dfy @@ -39,8 +39,7 @@ module ExpressionOptimization { var tpeExpr := args[1]; if !tpeExpr.ExprFromType? then e else var tpe := tpeExpr.tpe; - if || tpe.U8? || tpe.U16? || tpe.U32? || tpe.U64? || tpe.U128? - || tpe.I8? || tpe.I16? || tpe.I32? || tpe.I64? || tpe.I128? || tpe.USIZE? then + if tpe.IsAutoSize() then match expr { case Call(ExprFromPath(PMemberSelect(base, "int!")), args) => if |args| == 1 && (base == dafny_runtime || base == global) then diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index dc57d82dd68..795027f71b7 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -136,6 +136,8 @@ module RAST case RawImplMember(content) => acc case FnDecl(pub, fun) => VisitFn(acc, fun) + case TypeDeclMember(name, tpe) => + VisitType(acc, tpe) case ImplMemberMacro(expr: Expr) => expr.Fold(acc, VisitExprSingle, VisitTypeSingle) } @@ -306,6 +308,8 @@ module RAST case RawImplMember(content) => t case FnDecl(pub, fun) => FnDecl(pub, ReplaceFn(fun)) + case TypeDeclMember(name, tpe) => + TypeDeclMember(name, ReplaceType(tpe)) case ImplMemberMacro(expr: Expr) => ImplMemberMacro(ReplaceExpr(expr)) } @@ -685,11 +689,13 @@ module RAST | IntersectionType(left: Type, right: Type) | Array(underlying: Type, size: Option) | TSynonym(display: Type, base: Type) + | TMetaData(display: Type, nameonly copySemantics: bool, nameonly overflow: bool) { function Expand(): (r: Type) - ensures !r.TSynonym? && (!TSynonym? ==> r == this) + ensures !r.TSynonym? && !r.TMetaData? && (!TSynonym? && !TMetaData? ==> r == this) { - if TSynonym? then base.Expand() else this + if TSynonym? then base.Expand() else + if TMetaData? then display.Expand() else this } predicate EndsWithNameThatCanAcceptGenerics() { || U8? || U16? || U32? || U64? || U128? || I8? || I16? || I32? || I64? || I128? @@ -699,7 +705,7 @@ module RAST || (ImplType? && underlying.EndsWithNameThatCanAcceptGenerics()) || (DynType? && underlying.EndsWithNameThatCanAcceptGenerics()) || (IntersectionType? && right.EndsWithNameThatCanAcceptGenerics()) - || (TSynonym? && display.EndsWithNameThatCanAcceptGenerics()) + || ((TSynonym? || TMetaData?) && display.EndsWithNameThatCanAcceptGenerics()) } function ReplaceMap(mapping: map): Type { Replace((t: Type) => if t in mapping then mapping[t] else t) @@ -732,6 +738,8 @@ module RAST this.(underlying := underlying.Replace(mapping)) case TSynonym(display, base) => this.(display := display.Replace(mapping), base := base.Replace(mapping)) + case TMetaData(display, copySemantics, overflow) => + this.(display := display.Replace(mapping)) }; mapping(r) } @@ -768,12 +776,21 @@ module RAST right.Fold(left.Fold(newAcc, f), f) case Array(underlying, size) => underlying.Fold(newAcc, f) case TSynonym(display, base) => display.Fold(newAcc, f) + case TMetaData(display, _, _) => display.Fold(newAcc, f) } } + predicate IsAutoSize() { + U8? || U16? || U32? || U64? || U128? || I8? || I16? || I32? || I64? || I128? || USIZE? + || (TSynonym? && base.IsAutoSize()) + || (TMetaData? && display.IsAutoSize()) + } + predicate CanReadWithoutClone() { - U8? || U16? || U32? || U64? || U128? || I8? || I16? || I32? || I64? || I128? || USIZE? || Bool? - || (TSynonym? && base.CanReadWithoutClone()) || IsPointer() + IsAutoSize() || Bool? + || IsPointer() + || (TSynonym? && base.CanReadWithoutClone()) + || (TMetaData? && (copySemantics || display.CanReadWithoutClone())) } predicate IsRcOrBorrowedRc() { (TypeApp? && baseName == RcType) || @@ -849,6 +866,7 @@ module RAST case USIZE() => "usize" case Array(underlying, size) => "[" + underlying.ToString(ind) + (if size.Some? then "; " + size.value else "") + "]" case TSynonym(display, base) => display.ToString(ind) + case TMetaData(display, _, _) => display.ToString(ind) } } @@ -1090,12 +1108,14 @@ module RAST } datatype ImplMember = | RawImplMember(content: string) + | TypeDeclMember(name: string, rhs: Type) // When implementing traits | FnDecl(pub: Visibility, fun: Fn) | ImplMemberMacro(expr: Expr) { function ToString(ind: string): string { if FnDecl? then pub.ToString() + fun.ToString(ind) else if ImplMemberMacro? then expr.ToString(ind) + ";" + else if TypeDeclMember? then "type " + name + " = " + rhs.ToString(ind) + ";" else assert RawImplMember?; content } } @@ -1118,7 +1138,7 @@ module RAST tpe.Fold(acc, ft) } function ToString(ind: string): string { - if name == "self" && tpe == SelfOwned then name + if name == "self" && tpe.Expand() == SelfOwned then name else if name == "self" && tpe == SelfBorrowed then "&" + name else if name == "self" && tpe == SelfBorrowedMut then "&mut " + name else if tpe.TIdentifier? && tpe.name == "_" then diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 633151d01cf..4d8df58e8dd 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -134,7 +134,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Trait(t) => generated := GenTrait(t, containingPath); case Newtype(n) => - generated := GenNewtype(n); + generated := GenNewtype(n, containingPath + [Ident.Ident(n.name)]); case SynonymType(s) => generated := GenSynonymType(s); case Datatype(d) => @@ -203,6 +203,39 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ) } + method GenField(field: Field) returns ( + rfield: R.Field, fieldInit: R.AssignIdentifier, usedTypeParams: set) + modifies this + { + usedTypeParams := {}; + var fieldType := GenType(field.formal.typ, GenTypeContext.default()); + if !field.isConstant { + fieldType := R.dafny_runtime.MSel("Field").AsType().Apply([fieldType]); + } + usedTypeParams := GatherTypeParamNames(usedTypeParams, fieldType); + var fieldRustName := escapeVar(field.formal.name); + rfield := R.Field(R.PUB, R.Formal(fieldRustName, fieldType)); + + match field.defaultValue { + case Some(e) => { + // TODO(mikael): Fields must be initialized before the code of the constructor if possible + var expr, _, _ := GenExpr(e, NoSelf, Environment.Empty(), OwnershipOwned); + + fieldInit := R.AssignIdentifier( + fieldRustName, expr); + } + case None => { + // TODO(mikael) Use type descriptors for default values if generics + var default := R.std_default_Default_default; + if fieldType.IsObjectOrPointer() { + default := fieldType.ToNullExpr(); + } + fieldInit := R.AssignIdentifier( + fieldRustName, default); + } + } + } + method GenClass(c: Class, path: seq) returns (s: seq) modifies this { @@ -214,34 +247,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var usedTypeParams: set := {}; for fieldI := 0 to |c.fields| { var field := c.fields[fieldI]; - var fieldType := GenType(field.formal.typ, GenTypeContext.default()); - if !field.isConstant { - fieldType := R.dafny_runtime.MSel("Field").AsType().Apply([fieldType]); - } - usedTypeParams := GatherTypeParamNames(usedTypeParams, fieldType); - var fieldRustName := escapeVar(field.formal.name); - fields := fields + [R.Field(R.PUB, R.Formal(fieldRustName, fieldType))]; - - match field.defaultValue { - case Some(e) => { - // TODO(mikael): Fields must be initialized before the code of the constructor if possible - var expr, _, _ := GenExpr(e, NoSelf, Environment.Empty(), OwnershipOwned); - - fieldInits := fieldInits + [ - R.AssignIdentifier( - fieldRustName, expr)]; - } - case None => { - // TODO(mikael) Use type descriptors for default values if generics - var default := R.std_default_Default_default; - if fieldType.IsObjectOrPointer() { - default := fieldType.ToNullExpr(); - } - fieldInits := fieldInits + [ - R.AssignIdentifier( - fieldRustName, default)]; - } - } + var rfield, fieldInit, fieldUsedTypeParams := GenField(field); + fields := fields + [rfield]; + fieldInits := fieldInits + [fieldInit]; + usedTypeParams := usedTypeParams + fieldUsedTypeParams; } // A phantom field is necessary to avoid Rust complaining about no reference to the type parameter. @@ -466,49 +475,56 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ))]; } - method GenNewtype(c: Newtype) returns (s: seq) + method GenNewtype(c: Newtype, path: seq) returns (s: seq) modifies this { var typeParamsSeq, rTypeParams, rTypeParamsDecls, whereConstraints := GenTypeParameters(c.typeParams); var constrainedTypeParams := R.TypeParamDecl.ToStringMultiple(rTypeParamsDecls, R.IND + R.IND); - var underlyingType; - match NewtypeRangeToRustType(c.range) { - case Some(v) => - underlyingType := v; - case None => - underlyingType := GenType(c.base, GenTypeContext.default()); + var wrappedType; + var rustType := NewtypeRangeToUnwrappedBoundedRustType(c.base, c.range); + if rustType.Some? { + wrappedType := rustType.value; + } else { + wrappedType := GenType(c.base, GenTypeContext.default()); } - var resultingType := + var newtypeType: Type := UserDefined( ResolvedType( - [], [], + path, typeParamsSeq, ResolvedTypeBase.Newtype(c.base, c.range, false), c.attributes, [], [])); var newtypeName := escapeName(c.name); + var resultingType := R.TypeApp(R.TIdentifier(newtypeName), rTypeParams); + var attributes: string; + if IsNewtypeCopy(c.range) { + attributes := "#[derive(Clone, PartialEq, Copy)]"; + } else { + attributes := "#[derive(Clone, PartialEq)]"; + } s := [ R.StructDecl( R.Struct( [ - R.RawAttribute("#[derive(Clone, PartialEq)]"), + R.RawAttribute(attributes), R.RawAttribute("#[repr(transparent)]") ], newtypeName, rTypeParamsDecls, - R.NamelessFields([R.NamelessField(R.PUB, underlyingType)]) + R.NamelessFields([R.NamelessField(R.PUB, wrappedType)]) ))]; - var fnBody := R.Identifier(newtypeName); + var fnBody; match c.witnessExpr { case Some(e) => { - var e := if c.base == resultingType then e else Convert(e, c.base, resultingType); + var e := Convert(e, c.base, newtypeType); // TODO(Mikael): generate statements if any - var eStr, _, _ := GenExpr(e, NoSelf, Environment.Empty(), OwnershipOwned); - fnBody := fnBody.Apply1(eStr); + var r, _, _ := GenExpr(e, NoSelf, Environment.Empty(), OwnershipOwned); + fnBody := r; } case None => { - fnBody := fnBody.Apply1(R.std_default_Default_default); + fnBody := R.Identifier(newtypeName).Apply1(R.std_default_Default_default); } } @@ -529,7 +545,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplDecl( R.Impl( rTypeParamsDecls, - R.TypeApp(R.TIdentifier(newtypeName), rTypeParams), + resultingType, whereConstraints, [ R.FnDecl( @@ -548,7 +564,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplFor( rTypeParamsDecls, R.DefaultTrait, - R.TypeApp(R.TIdentifier(newtypeName), rTypeParams), + resultingType, whereConstraints, [body]))]; s := s + [ @@ -556,7 +572,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplFor( rTypeParamsDecls, R.DafnyPrint, - R.TypeApp(R.TIdentifier(newtypeName), rTypeParams), + resultingType, "", [R.FnDecl( R.PRIV, @@ -575,16 +591,74 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplDecl( R.ImplFor( rTypeParamsDecls, - R.RawType("::std::ops::Deref"), - R.TypeApp(R.TIdentifier(newtypeName), rTypeParams), + R.std.MSel("ops").MSel("Deref").AsType(), + resultingType, "", - [R.RawImplMember("type Target = " + underlyingType.ToString(IND) + ";"), + [R.TypeDeclMember("Target", wrappedType), R.FnDecl( R.PRIV, R.Fn("deref", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.Self().MSel("Target").AsType())), "", Some(R.Borrow(R.self.Sel("0")))))]))]; + + // Convert a ref to the underlying type to a ref of the wrapped newtype + s := s + [ + R.ImplDecl( + R.Impl( + rTypeParamsDecls, + resultingType, + "", + [R.FnDecl( + R.PUB, + R.Fn( + "_from_ref", [], + [R.Formal("o", R.Borrowed(wrappedType))], + Some(R.Borrowed(R.Self().AsType())), + "", + Some( + R.Unsafe( + 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), + OpsImpl('-', rTypeParamsDecls, resultingType, newtypeName), + OpsImpl('*', rTypeParamsDecls, resultingType, newtypeName), + OpsImpl('/', rTypeParamsDecls, resultingType, newtypeName), + PartialOrdImpl(rTypeParamsDecls, resultingType, newtypeName) + ]; + } + if c.range.Bool? { + s := s + [ + UnaryOpsImpl('!', rTypeParamsDecls, resultingType, newtypeName) + ]; + } + var implementation, traitBodies := GenClassImplBody(c.classItems, false, newtypeType, typeParamsSeq); + if |traitBodies| > 0 { + error := Some("No support for trait in newtypes yet"); + } + if |implementation| > 0 { + s := s + [ + R.ImplDecl( + R.Impl( + rTypeParamsDecls, + R.TypeApp(R.TIdentifier(newtypeName), rTypeParams), + whereConstraints, + implementation + ) + )]; + } } method GenSynonymType(c: SynonymType) returns (s: seq) @@ -1046,23 +1120,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // Implementation of Hash trait s := s + [ - R.ImplDecl( - R.ImplFor( - rTypeParamsDeclsWithHash, - R.Hash, - R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), - "", - [R.FnDecl( - 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")))], - None, - "", - Some(hashImplBody)))] - ) - )]; + HashImpl( + rTypeParamsDeclsWithHash, + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), + hashImplBody)]; if |c.ctors| > 0 { var structName := R.Identifier(datatypeName).FSel(escapeName(c.ctors[0].name)); @@ -1201,7 +1262,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case UserDefined(resolved) => { var t := GenPathType(resolved.path); var typeArgs := GenTypeArgs(resolved.typeArgs, genTypeContext.(forTraitParents := false)); - s := R.TypeApp(t, typeArgs); + s := if |typeArgs| > 0 then R.TypeApp(t, typeArgs) else t; match resolved.kind { case Class() => { @@ -1220,15 +1281,21 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := Object(R.DynType(s)); } } + case SynonymType(base) => { + var underlying := GenType(base, GenTypeContext.default()); + s := R.TSynonym(s, underlying); + } case Newtype(base, range, erased) => { if erased { - match NewtypeRangeToRustType(range) { - case Some(v) => - s := v; - case None => - var underlying := GenType(base, GenTypeContext.default()); - s := R.TSynonym(s, underlying); + var unwrappedType := NewtypeRangeToUnwrappedBoundedRustType(base, range); + if unwrappedType.Some? { + s := unwrappedType.value; + } else { + var unwrappedType := GenType(base, GenTypeContext.default()); + s := unwrappedType; } + } else if IsNewtypeCopy(range) { + s := R.TMetaData(s, copySemantics := true, overflow := range.CanOverflow()); } } } @@ -1419,12 +1486,22 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if enclosingType.UserDefined? && enclosingType.resolved.kind.Datatype? && IsRcWrapped(enclosingType.resolved.attributes) { tpe := R.Borrowed(R.Rc(R.SelfOwned)); - } else { // For raw-defined datatypes, newtypes - tpe := R.Borrowed(R.SelfOwned); + } else if enclosingType.UserDefined? && enclosingType.resolved.kind.Newtype? + && IsNewtypeCopy(enclosingType.resolved.kind.range) { + tpe := R.TMetaData( + R.SelfOwned, + copySemantics := true, + overflow := enclosingType.resolved.kind.range.CanOverflow()); + } else { // For raw-defined datatypes, non-copy newtypes + tpe := R.SelfBorrowed; } } } - params := [R.Formal(selfId, tpe)] + params; + var formal := R.Formal(selfId, tpe); + params := [formal] + params; + var name := formal.name; + paramNames := [name] + paramNames; + paramTypes := paramTypes[name := formal.tpe]; } selfIdent := ThisTyped(selfId, instanceType); } @@ -1798,24 +1875,31 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // clone the parameters to make them mutable generated := InitEmptyExpr(); + var oldEnv := env; if selfIdent != NoSelf { var selfClone, _, _ := GenIdent(selfIdent.rSelfName, selfIdent, Environment.Empty(), OwnershipOwned); generated := generated.Then(R.DeclareVar(R.MUT, "_this", None, Some(selfClone))); + if selfIdent.rSelfName in oldEnv.names { + oldEnv := oldEnv.RemoveAssigned(selfIdent.rSelfName); + } } - newEnv := env; var loopBegin := R.RawExpr(""); - for paramI := 0 to |env.names| { - var param := env.names[paramI]; + newEnv := env; + for paramI := 0 to |oldEnv.names| { + var param := oldEnv.names[paramI]; if param == "_accumulator" { continue; // This is an already mutable variable handled by SinglePassCodeGenerator } - var paramInit, _, _ := GenIdent(param, selfIdent, env, OwnershipOwned); + if param in oldEnv.types && oldEnv.types[param].ExtractMaybePlacebo().Some? { + continue; // This is an output variable. Output variables don't need to be iterated on. + } + var paramInit, _, _ := GenIdent(param, selfIdent, oldEnv, OwnershipOwned); var recVar := TailRecursionPrefix + Strings.OfNat(paramI); generated := generated.Then(R.DeclareVar(R.MUT, recVar, None, Some(paramInit))); - if param in env.types { + if param in oldEnv.types { // We made the input type owned by the variable. // so we can remove borrow annotations. - var declaredType := env.types[param].ToOwned(); + var declaredType := oldEnv.types[param].ToOwned(); newEnv := newEnv.AddAssigned(param, declaredType); newEnv := newEnv.AddAssigned(recVar, declaredType); } @@ -2123,6 +2207,50 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + method ToPrimitive(r: R.Expr, typ: Type, primitiveType: Type) returns (out: R.Expr) + modifies this + { + out := r; + if typ != primitiveType { + var dummy; + out, dummy := GenExprConvertTo(r, OwnershipOwned, typ, primitiveType, OwnershipOwned); + } + } + + method ToBool(r: R.Expr, typ: Type) returns (out: R.Expr) + modifies this + { + out := ToPrimitive(r, typ, Primitive(Primitive.Bool)); + } + + method ToInt(r: R.Expr, typ: Type) returns (out: R.Expr) + modifies this + { + out := ToPrimitive(r, typ, Primitive(Primitive.Int)); + } + + method FromPrimitive(r: R.Expr, primitiveType: Type, typ: Type) returns (out: R.Expr) + modifies this + { + out := r; + if typ != primitiveType { + var dummy; + out, dummy := GenExprConvertTo(r, OwnershipOwned, primitiveType, typ, OwnershipOwned); + } + } + + method FromBool(r: R.Expr, typ: Type) returns (out: R.Expr) + modifies this + { + out := FromPrimitive(r, Primitive(Primitive.Bool), typ); + } + + method FromInt(r: R.Expr, typ: Type) returns (out: R.Expr) + modifies this + { + out := FromPrimitive(r, Primitive(Primitive.Int), typ); + } + method GenExprBinary( e: Expression, selfIdent: SelfInfo, @@ -2134,7 +2262,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 { - var BinOp(op, lExpr, rExpr, format) := e; + var BinOp(TypedBinOp(op, lType, rType, resType), lExpr, rExpr, format) := e; var becomesLeftCallsRight := BecomesLeftCallsRight(op); var becomesRightCallsLeft := BecomesRightCallsLeft(op); var expectedLeftOwnership := @@ -2202,14 +2330,24 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r := left.Sel("concat").Apply1(right); } case _ => { - if op in OpTable { + if IsBooleanOperator(op) { + left := ToBool(left, lType); + right := ToBool(right, rType); + } r := R.Expr.BinaryOp( OpTable[op], left, right, format); + if IsBooleanOperator(op) { + r := FromBool(r, resType); + } } else { + if IsComplexArithmetic(op) { + left := ToInt(left, lType); + right := ToInt(right, rType); + } match op { case Eq(referential) => { if (referential) { @@ -2226,19 +2364,33 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r := R.BinaryOp("==", R.LiteralInt("0"), right.Sel("to_array").Apply0().Sel("len").Apply0(), DAST.Format.BinaryOpFormat.NoFormat()); } else { r := R.BinaryOp("==", left, right, DAST.Format.BinaryOpFormat.NoFormat()); + if resType != Primitive(Primitive.Bool) { + r, resultingOwnership := GenExprConvertTo(r, OwnershipOwned, Primitive(Primitive.Bool), resType, OwnershipOwned); + } } } } + case Div(true) => + r := left.Sel("wrapping_div").Apply1(right); + case Plus(true) => + r := left.Sel("wrapping_add").Apply1(right); + case Times(true) => + r := left.Sel("wrapping_mul").Apply1(right); + case Minus(true) => + r := left.Sel("wrapping_sub").Apply1(right); case EuclidianDiv() => { - r := R.dafny_runtime.AsExpr().FSel("euclidian_division").Apply([left, right]); + r := R.dafny_runtime.MSel("euclidian_division").AsExpr().Apply([left, right]); } case EuclidianMod() => { - r := R.dafny_runtime.AsExpr().FSel("euclidian_modulo").Apply([left, right]); + r := R.dafny_runtime.MSel("euclidian_modulo").AsExpr().Apply([left, right]); } case Passthrough(op) => { r := R.Expr.BinaryOp(op, left, right, format); } } + if IsComplexArithmetic(op) { + r := FromInt(r, resType); + } } } } @@ -2247,115 +2399,189 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } - method GenExprConvertToNewtype( - e: Expression, - selfIdent: SelfInfo, - env: Environment, - expectedOwnership: Ownership - ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) - requires e.Convert? - requires e.from != e.typ - requires e.typ.UserDefined? && e.typ.resolved.kind.Newtype? - modifies this - ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) - decreases e, 0, 0 + // Given an expression that is a newtype, returns the underlying value + // Preserves ownership + method UnwrapNewtype( + expr: R.Expr, + exprOwnership: Ownership, + fromTpe: Type + ) returns (r: R.Expr) + requires IsNewtype(fromTpe) { - var Convert(expr, fromTpe, toTpe) := e; - var UserDefined(ResolvedType(path, typeArgs, Newtype(b, range, erase), _, _, _)) := toTpe; - var nativeToType := NewtypeRangeToRustType(range); - if fromTpe == b { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - readIdents := recIdents; - match nativeToType { - case Some(v) => - r := R.dafny_runtime.MSel("truncate!").AsExpr().Apply([recursiveGen, R.ExprFromType(v)]); - r, resultingOwnership := FromOwned(r, expectedOwnership); - case None => - if erase { - r := recursiveGen; - } else { - var rhsType := GenType(toTpe, GenTypeContext.default()); - r := R.ExprFromType(rhsType).Apply1(recursiveGen); - } - r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + r := expr; + if !fromTpe.resolved.kind.erase { + r := r.Sel("0"); + if exprOwnership == OwnershipBorrowed { + r := R.Borrow(r); } - } else { - if nativeToType.Some? { - // Conversion between any newtypes that can be expressed as a native Rust type - match fromTpe { - case UserDefined( - ResolvedType(_, _, Newtype(b0, range0, erase0), attributes0, _, _)) => { - var nativeFromType := NewtypeRangeToRustType(range0); - if nativeFromType.Some? { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - r, resultingOwnership := FromOwnership(R.TypeAscription(recursiveGen, nativeToType.value), recOwned, expectedOwnership); - readIdents := recIdents; - return; - } - } - case _ => - } - if fromTpe == Primitive(Char) { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - r, resultingOwnership := FromOwnership(R.TypeAscription(recursiveGen.Sel("0"), nativeToType.value), recOwned, expectedOwnership); - readIdents := recIdents; - return; - } + } + } + + // Given an expression that is the underlying value of a newtype, returns the newtype + // Preserves ownership + method WrapWithNewtype( + expr: R.Expr, + exprOwnership: Ownership, + toTpe: Type + ) returns (r: R.Expr) + requires IsNewtype(toTpe) + { + r := expr; + var toKind := toTpe.resolved.kind; + if !toKind.erase { + var fullPath := GenPathExpr(toTpe.resolved.path); + if exprOwnership == OwnershipOwned { + r := fullPath.Apply1(r); + } else { + r := fullPath.FSel("_from_ref").Apply1(r); // Keep borrowbility } - assume {:axiom} Convert(Convert(expr, fromTpe, b), b, toTpe) < e; // make termination go through - r, resultingOwnership, readIdents := GenExpr(Convert(Convert(expr, fromTpe, b), b, toTpe), selfIdent, env, expectedOwnership); } } - method GenExprConvertFromNewtype( - e: Expression, - selfIdent: SelfInfo, - env: Environment, + // To use when we know that the expression is a Convert(_, _, toTpe) + // and toTpe is a newtype + method GenExprConvertTo( + expr: R.Expr, + exprOwnership: Ownership, + fromTpe: Type, + toTpe: Type, expectedOwnership: Ownership - ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) - requires e.Convert? - requires e.from != e.typ - requires (!e.typ.UserDefined? || !e.typ.resolved.kind.Newtype?) - requires e.from.UserDefined? && e.from.resolved.kind.Newtype? + ) returns (r: R.Expr, resultingOwnership: Ownership) + requires exprOwnership != OwnershipAutoBorrowed modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) - decreases e, 0, 0 + decreases fromTpe, toTpe // We unwrap newtypes { - var Convert(expr, fromTpe, toTpe) := e; - var UserDefined( - ResolvedType(_, _, Newtype(b, range, erase), attributes, _, _)) := fromTpe; - var nativeFromType := NewtypeRangeToRustType(range); - if b == toTpe { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - readIdents := recIdents; - match nativeFromType { - case Some(v) => - var toTpeRust := GenType(toTpe, GenTypeContext.default()); - r := R.std.MSel("convert").MSel("Into").AsExpr().ApplyType([toTpeRust]).FSel("into").Apply([recursiveGen]); - r, resultingOwnership := FromOwned(r, expectedOwnership); - case None => - if erase { - r := recursiveGen; - } else { - r := recursiveGen.Sel("0"); + r := expr; + 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, expectedOwnership); + return; + } + if toTpe.UserDefined? && toTpe.resolved.kind.SynonymType? { + r, resultingOwnership := GenExprConvertTo(expr, exprOwnership, fromTpe, toTpe.resolved.kind.baseType, 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, expectedOwnership); + return; + } + if NeedsUnwrappingConversion(toTpe) { + var toKind := toTpe.resolved.kind; + r, resultingOwnership := + GenExprConvertTo(r, exprOwnership, fromTpe, toKind.baseType, expectedOwnership); + r := WrapWithNewtype(r, resultingOwnership, toTpe); + r, resultingOwnership := FromOwnership(r, resultingOwnership, expectedOwnership); + return; + } + // At this point, our newtypes are either primitives or we have other types. + var unwrappedFromType := GetUnwrappedBoundedRustType(fromTpe); + var unwrappedToType := GetUnwrappedBoundedRustType(toTpe); + if unwrappedToType.Some? { + var boundedToType := unwrappedToType.value; + if unwrappedFromType.Some? { + r := UnwrapNewtype(r, exprOwnership, fromTpe); + var inOwnership := exprOwnership; + if unwrappedFromType.value != unwrappedToType.value { + var asType := boundedToType; + if inOwnership == OwnershipBorrowed { + match r { + case UnaryOp("&", underlying, _) => + r := underlying; + case _ => r := r.Clone(); + } } - r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + r := R.TypeAscription(r, asType); + inOwnership := OwnershipOwned; + } + r := WrapWithNewtype(r, OwnershipOwned, toTpe); + r, resultingOwnership := FromOwnership(r, inOwnership, expectedOwnership); + return; } - } else { - if nativeFromType.Some? { - // The case where toTpe is a NewType which compiles to a native integer has already been handled. - if toTpe == Primitive(Char) { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); - r, resultingOwnership := FromOwnership( - R.dafny_runtime.MSel(DafnyChar).AsExpr().Apply1( - R.TypeAscription(recursiveGen, DafnyCharUnderlying) - ), recOwned, expectedOwnership); - readIdents := recIdents; - return; + assert !IsNewtype(fromTpe); + if fromTpe.IsPrimitiveInt() { + if exprOwnership == OwnershipBorrowed { + r := r.Clone(); + } + r := R.dafny_runtime.MSel("truncate!").AsExpr().Apply([r, R.ExprFromType(boundedToType)]); + r := WrapWithNewtype(r, OwnershipOwned, toTpe); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; + } + if fromTpe == Primitive(Char) { + r := R.TypeAscription(r.Sel("0"), boundedToType); + r := WrapWithNewtype(r, OwnershipOwned, toTpe); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; + } + var fromTpeRust := GenType(fromTpe, GenTypeContext.default()); + r := Error("No conversion available from "+fromTpeRust.ToString("")+" to " + boundedToType.ToString("")); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; + } + assert !IsNewtype(toTpe); + if unwrappedFromType.Some? { + if !fromTpe.resolved.kind.erase { + r := r.Sel("0"); + } + // Now r is of type unwrappedFromType.value + if toTpe == Primitive(Char) { + r, resultingOwnership := FromOwnership( + R.dafny_runtime.MSel(DafnyChar).AsExpr().Apply1( + R.TypeAscription(r, DafnyCharUnderlying) + ), exprOwnership, expectedOwnership); + return; + } + if toTpe.IsPrimitiveInt() { + r, resultingOwnership := FromOwnership(r, exprOwnership, OwnershipOwned); + r := R.dafny_runtime.MSel("int!").AsExpr().Apply1(r); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; + } + var toTpeRust := GenType(toTpe, GenTypeContext.default()); + r := Error("No conversion available from "+unwrappedFromType.value.ToString("")+" to " + toTpeRust.ToString("")); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; + } + assert !IsNewtype(fromTpe); + match (fromTpe, toTpe) { + case (Primitive(Int), Primitive(Real)) => { + r := R.RcNew(R.dafny_runtime.MSel("BigRational").AsExpr().FSel("from_integer").Apply1(r)); + r, resultingOwnership := FromOwned(r, expectedOwnership); + } + case (Primitive(Real), Primitive(Int)) => { + r := R.dafny_runtime.AsExpr().FSel("dafny_rational_to_int").Apply1(r); + r, resultingOwnership := FromOwned(r, expectedOwnership); + } + case (Primitive(Int), Primitive(Char)) => { + var rhsType := GenType(toTpe, GenTypeContext.default()); + var uType := if charType.UTF32? then R.U32 else R.U16; + if exprOwnership != OwnershipOwned { + r := r.Clone(); } + r := R.TraitCast(uType, R.dafny_runtime.MSel("NumCast").AsType()).FSel("from").Apply1( + r + ).Sel("unwrap").Apply0(); + if charType.UTF32? { + r := R.Identifier("char").FSel("from_u32").Apply1(r).Sel("unwrap").Apply0(); + } + r := R.dafny_runtime.MSel(DafnyChar).AsExpr().Apply1(r); + r, resultingOwnership := FromOwned(r, expectedOwnership); + } + case (Primitive(Char), Primitive(Int)) => { + var rhsType := GenType(fromTpe, GenTypeContext.default()); + r := R.dafny_runtime.MSel("int!").AsExpr().Apply1(r.Sel("0")); + r, resultingOwnership := FromOwned(r, expectedOwnership); + } + case _ => { + r, resultingOwnership := GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, expectedOwnership); } - assume {:axiom} Convert(Convert(expr, fromTpe, b), b, toTpe) < e; // make termination go through - r, resultingOwnership, readIdents := GenExpr(Convert(Convert(expr, fromTpe, b), b, toTpe), selfIdent, env, expectedOwnership); } } @@ -2482,40 +2708,40 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } method GenExprConvertOther( - e: Expression, - selfIdent: SelfInfo, - env: Environment, + expr: R.Expr, + exprOwnership: Ownership, + fromTpe: Type, + toTpe: Type, expectedOwnership: Ownership - ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) - requires e.Convert? + ) returns (r: R.Expr, resultingOwnership: Ownership) modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) - decreases e, 0, 0 { - var Convert(expr, fromTpe, toTpe) := e; + r := expr; var fromTpeGen := GenType(fromTpe, GenTypeContext.default()); var toTpeGen := GenType(toTpe, GenTypeContext.default()); var upcastConverter := UpcastConversionLambda(fromTpe, fromTpeGen, toTpe, toTpeGen, map[]); if upcastConverter.Success? { var conversionLambda := upcastConverter.value; - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - readIdents := recIdents; - r := conversionLambda.Apply1(recursiveGen); + if exprOwnership == OwnershipBorrowed { + match r { + case UnaryOp("&", underlying, _) => + r := underlying; + case _ => r := r.Clone(); + } + } + r := conversionLambda.Apply1(r); r, resultingOwnership := FromOwnership(r, OwnershipOwned, expectedOwnership); } else if IsDowncastConversion(fromTpeGen, toTpeGen) { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - readIdents := recIdents; assert toTpeGen.IsObjectOrPointer(); toTpeGen := toTpeGen.ObjectOrPointerUnderlying(); r := R.dafny_runtime - .MSel(downcast).AsExpr().Apply([recursiveGen, R.ExprFromType(toTpeGen)]); + .MSel(downcast).AsExpr().Apply([r, R.ExprFromType(toTpeGen)]); r, resultingOwnership := FromOwnership(r, OwnershipOwned, expectedOwnership); } else { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); - readIdents := recIdents; var Failure((fromType, fromTpeGen, toType, toTpeGen, m)) := upcastConverter; - r := Error("Coercion from " + fromTpeGen.ToString(IND) + " to " + toTpeGen.ToString(IND) + " not yet implemented", recursiveGen); - r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + r := Error("Coercion from " + fromTpeGen.ToString(IND) + " to " + toTpeGen.ToString(IND) + " not yet implemented", r); + r, resultingOwnership := FromOwned(r, expectedOwnership); } } @@ -2531,83 +2757,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { decreases e, 0 { var Convert(expr, fromTpe, toTpe) := e; - if fromTpe == toTpe { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); - r := recursiveGen; - r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); - readIdents := recIdents; - } else { - match (fromTpe, toTpe) { - case (_, UserDefined(ResolvedType(_, _, Newtype(b, range, erase), attributes, _, _))) => { - r, resultingOwnership, readIdents := GenExprConvertToNewtype(e, selfIdent, env, expectedOwnership); - } - case (UserDefined(ResolvedType(_, _, Newtype(b, range, erase), attributes, _, _)), _) => { - r, resultingOwnership, readIdents := GenExprConvertFromNewtype(e, selfIdent, env, expectedOwnership); - } - case (Primitive(Int), Primitive(Real)) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - r := R.RcNew(R.dafny_runtime.MSel("BigRational").AsExpr().FSel("from_integer").Apply1(recursiveGen)); - r, resultingOwnership := FromOwned(r, expectedOwnership); - readIdents := recIdents; - } - case (Primitive(Real), Primitive(Int)) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipBorrowed); - r := R.dafny_runtime.AsExpr().FSel("dafny_rational_to_int").Apply1(recursiveGen); - r, resultingOwnership := FromOwned(r, expectedOwnership); - readIdents := recIdents; - } - case (Primitive(Int), Passthrough(_)) => { - var rhsType := GenType(toTpe, GenTypeContext.default()); - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - r := R.TraitCast(rhsType, R.dafny_runtime.MSel("NumCast").AsType()).FSel("from").Apply1(recursiveGen).Sel("unwrap").Apply0(); - r, resultingOwnership := FromOwned(r, expectedOwnership); - readIdents := recIdents; - } - case (Passthrough(_), Primitive(Int)) => { - var rhsType := GenType(fromTpe, GenTypeContext.default()); - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - r := R.dafny_runtime.MSel("DafnyInt").AsExpr().FSel("new") - .Apply1(R.std.MSel("rc").MSel("Rc").AsExpr().FSel("new") - .Apply1(R.dafny_runtime.MSel("BigInt").AsExpr().FSel("from").Apply1(recursiveGen))); - r, resultingOwnership := FromOwned(r, expectedOwnership); - readIdents := recIdents; - } - case (Primitive(Int), Primitive(Char)) => { - var rhsType := GenType(toTpe, GenTypeContext.default()); - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - var uType := if charType.UTF32? then R.U32 else R.U16; - r := R.TraitCast(uType, R.dafny_runtime.MSel("NumCast").AsType()); - r := r.FSel("from").Apply1( - recursiveGen - ).Sel("unwrap").Apply0(); - if charType.UTF32? { - r := R.Identifier("char").FSel("from_u32").Apply1(r.Sel("unwrap").Apply0()); - } - r := R.dafny_runtime.MSel(DafnyChar).AsExpr().Apply1(r); - r, resultingOwnership := FromOwned(r, expectedOwnership); - readIdents := recIdents; - } - case (Primitive(Char), Primitive(Int)) => { - var rhsType := GenType(fromTpe, GenTypeContext.default()); - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - r := R.dafny_runtime.MSel("int!").AsExpr().Apply1(recursiveGen.Sel("0")); - r, resultingOwnership := FromOwned(r, expectedOwnership); - readIdents := recIdents; - } - case (Passthrough(_), Passthrough(_)) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - var toTpeGen := GenType(toTpe, GenTypeContext.default()); - - r := R.TypeAscription(recursiveGen, toTpeGen); - - r, resultingOwnership := FromOwned(r, expectedOwnership); - readIdents := recIdents; - } - case _ => { - r, resultingOwnership, readIdents := GenExprConvertOther(e, selfIdent, env, expectedOwnership); - } - } - } + var argumentOwnership := expectedOwnership; + if argumentOwnership == OwnershipAutoBorrowed { + argumentOwnership := OwnershipBorrowed; + // Otherwise we risk moving a value if it's not borrowed. + } + var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, argumentOwnership); + r := recursiveGen; + readIdents := recIdents; + r, resultingOwnership := GenExprConvertTo(r, recOwned, fromTpe, toTpe, expectedOwnership); assert OwnershipGuarantee(expectedOwnership, resultingOwnership); return; } @@ -2655,7 +2813,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case _ => false }; if needObjectFromRef { - r := R.dafny_runtime.MSel("Object").AsExpr().ApplyType([R.RawType("_")]).FSel("from_ref").Apply([r]); + r := R.dafny_runtime.MSel("Object").AsExpr().ApplyType([R.TIdentifier("_")]).FSel("from_ref").Apply([r]); } else { if !noNeedOfClone { r := r.Clone(); // We don't transfer the ownership of an identifier @@ -3016,8 +3174,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } r := R.dafny_runtime.MSel("seq!").AsExpr().Apply(args); if |args| == 0 { - r := R.TypeAscription(r, - R.dafny_runtime.MSel("Sequence").AsType().Apply1(genTpe)); + r := R.TypeAscription( + r, + R.dafny_runtime.MSel("Sequence").AsType().Apply1(genTpe)); } r, resultingOwnership := FromOwned(r, expectedOwnership); return; @@ -3143,7 +3302,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case UnOp(BitwiseNot, e, format) => { var recursiveGen, _, recIdents := GenExpr(e, selfIdent, env, OwnershipOwned); - r := R.UnaryOp("~", recursiveGen, format); + r := R.UnaryOp("!", recursiveGen, format); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; @@ -3232,7 +3391,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var onExprArgs := []; for i := 0 to |args| { var (name, ty) := args[i]; - var rIdent, _, _ := GenIdent(name, selfIdent, lEnv, if ty.CanReadWithoutClone() then OwnershipOwned else OwnershipBorrowed); + var rIdent, _, _ := GenIdent(name, selfIdent, lEnv, if !isConstant && ty.CanReadWithoutClone() then OwnershipOwned else OwnershipBorrowed); onExprArgs := onExprArgs + [rIdent]; } body := body.Apply(onExprArgs); @@ -3280,9 +3439,17 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); // onExpr.field() r := onExpr.Sel(escapeVar(field)).Apply0(); + var originalMutability := OwnershipOwned; + match fieldMutability { + case ConstantField() => // Good + case InternalClassConstantFieldOrDatatypeDestructor() => + originalMutability := OwnershipBorrowed; + case ClassMutableField() => + r := Error("datatypes don't have mutable fields"); + } var typ := GenType(fieldType, GenTypeContext.default()); // All fields are returned as addresses for now until we have something more clever - r, resultingOwnership := FromOwnership(r, OwnershipBorrowed, expectedOwnership); + r, resultingOwnership := FromOwnership(r, originalMutability, expectedOwnership); readIdents := recIdents; } else { var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); @@ -3303,7 +3470,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case ConstantField() => r := r.Apply0(); r := r.Clone(); - case InternalClassConstantField() => + case InternalClassConstantFieldOrDatatypeDestructor() => r := r.Clone(); case ClassMutableField() => r := read_mutable_field_macro.Apply1(r); // Already contains a clone. @@ -3553,7 +3720,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case Apply(func, args) => { - // TODO: Need the type of the input of Func to ensure we generate arguments with the right ownership var funcExpr, _, recIdents := GenExpr(func, selfIdent, env, OwnershipBorrowed); readIdents := recIdents; var rArgs := []; diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.Expression.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.Expression.cs index 9366be441ec..1ce24554813 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.Expression.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.Expression.cs @@ -19,6 +19,10 @@ namespace Microsoft.Dafny.Compilers { public abstract partial class SinglePassCodeGenerator { + public virtual Type GetRuntimeType(Type tpe) { + return tpe.GetRuntimeType(); + } + public virtual void EmitExpr(Expression expr, bool inLetExprBody, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { switch (expr) { @@ -287,8 +291,8 @@ void EmitExpr(Expression e2, ConcreteSyntaxTree wr2, bool inLetExpr, ConcreteSyn } case ConversionExpr conversionExpr: { var e = conversionExpr; - var fromType = e.E.Type.GetRuntimeType(); - var toType = e.ToType.GetRuntimeType(); + var fromType = GetRuntimeType(e.E.Type); + var toType = GetRuntimeType(e.ToType); Contract.Assert(Options.Get(CommonOptionBag.GeneralTraits) != CommonOptionBag.GeneralTraitsOptions.Legacy || toType.IsRefType == fromType.IsRefType || (fromType.IsTypeParameter && toType.IsTraitType)); @@ -615,7 +619,7 @@ private void EmitBinaryExpr(bool inLetExprBody, ConcreteSyntaxTree wr, wr.Write(negated ? " != " : " == "); wr.Write(sign.ToString()); } else { - CompileBinOp(binary.ResolvedOp, binary.E0.Type, binary.E1.Type, binary.tok, binary.Type.GetRuntimeType(), + CompileBinOp(binary.ResolvedOp, binary.E0.Type, binary.E1.Type, binary.tok, GetRuntimeType(binary.Type), out var opString, out var preOpString, out var postOpString, diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index b9a115b7c81..387bb43cd5e 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -1416,13 +1416,13 @@ protected virtual void CompileBinOp(BinaryExpr.ResolvedOpcode op, if (dualOp != BinaryExpr.ResolvedOpcode.Add) { // remember from above that Add stands for "there is no dual" Contract.Assert(negatedOp == BinaryExpr.ResolvedOpcode.Add); CompileBinOp(dualOp, - e1Type, e0Type, tok, resultType.GetRuntimeType(), + e1Type, e0Type, tok, GetRuntimeType(resultType), out opString, out preOpString, out postOpString, out callString, out staticCallString, out reverseArguments, out truncateResult, out convertE1_to_int, out coerceE1, errorWr); reverseArguments = !reverseArguments; } else if (negatedOp != BinaryExpr.ResolvedOpcode.Add) { // remember from above that Add stands for "there is no negated op" CompileBinOp(negatedOp, - e0Type, e1Type, tok, resultType.GetRuntimeType(), + e0Type, e1Type, tok, GetRuntimeType(resultType), out opString, out preOpString, out postOpString, out callString, out staticCallString, out reverseArguments, out truncateResult, out convertE1_to_int, out coerceE1, errorWr); preOpString = "!" + preOpString; @@ -2113,8 +2113,8 @@ public virtual bool NeedsCustomReceiverNotTrait(MemberDecl member) { return false; } else if (member.EnclosingClass is TraitDecl) { return false; - } else if (member.EnclosingClass is NewtypeDecl) { - return true; + } else if (member.EnclosingClass is NewtypeDecl newtypeDecl) { + return IsNewtypeErased(newtypeDecl); } else if (member.EnclosingClass is DatatypeDecl datatypeDecl) { // An undefined value "o" cannot use this o.F(...) form in most languages. // Also, an erasable wrapper type has a receiver that's not part of the enclosing target class. @@ -2124,6 +2124,14 @@ public virtual bool NeedsCustomReceiverNotTrait(MemberDecl member) { } } + protected virtual bool IsNewtypeErased(NewtypeDecl newtypeDecl) { + return true; + } + + protected virtual bool InstanceConstAreStatic() { + return true; + } + void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWriter classWriter) { Contract.Requires(c != null); Contract.Requires(classWriter != null); @@ -2247,7 +2255,7 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite // because a newtype value is always represented as some existing type. // Likewise, an instance const with a RHS in a trait needs to be modeled as a static function (in the companion class) // that takes a parameter, because trait-equivalents in target languages don't allow implementations. - wBody = classWriter.CreateFunction(IdName(cf), CombineAllTypeArguments(cf), new List(), cf.Type, cf.tok, true, true, cf, false, true); + wBody = classWriter.CreateFunction(IdName(cf), CombineAllTypeArguments(cf), new List(), cf.Type, cf.tok, InstanceConstAreStatic(), true, cf, false, true); Contract.Assert(wBody != null); // since the previous line asked for a body if (c is TraitDecl) { // also declare a function for the field in the interface diff --git a/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py b/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py index af5eadec414..8ed810683f8 100644 --- a/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py +++ b/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py @@ -17,7 +17,7 @@ # test if the file exists before opening it. If not, fail gracefully if not os.path.exists(output + '.cs'): - print(f"File {output} was not generated. Fix issues and re-run ./DafnyGeneratedFromDafny.sh") + print(f"File {output}.cs was not generated. Fix issues and re-run ./DafnyGeneratedFromDafny.sh") exit() with open(output + '.cs', 'r' ) as f: diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 2ba103165a0..42aeb9b108d 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -558,6 +558,7 @@ public interface _IType { Dafny.ISequence dtor_TypeArg_a0 { get; } _IType DowncastClone(); DAST._IType Replace(Dafny.IMap mapping); + bool IsPrimitiveInt(); } public abstract class Type : _IType { public Type() { @@ -777,6 +778,35 @@ public DAST._IType Replace(Dafny.IMap mapping) { } } } + public bool IsPrimitiveInt() { + _IType _this = this; + TAIL_CALL_START: ; + DAST._IType _source0 = _this; + { + if (_source0.is_Primitive) { + DAST._IPrimitive _h70 = _source0.dtor_Primitive_a0; + if (_h70.is_Int) { + return true; + } + } + } + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; + if (kind0.is_SynonymType) { + DAST._IType _0_typ = kind0.dtor_baseType; + DAST._IType _in0 = _0_typ; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + } + { + return false; + } + } } public class Type_UserDefined : Type { public readonly DAST._IResolvedType _resolved; @@ -1617,15 +1647,19 @@ public interface _INewtypeRange { bool is_I64 { get; } bool is_U128 { get; } bool is_I128 { get; } - bool is_USIZE { get; } + bool is_NativeArrayIndex { get; } bool is_BigInt { get; } + bool is_Bool { get; } bool is_NoRange { get; } + bool dtor_overflow { get; } _INewtypeRange DowncastClone(); + bool CanOverflow(); + bool HasArithmeticOperations(); } public abstract class NewtypeRange : _INewtypeRange { public NewtypeRange() { } - private static readonly DAST._INewtypeRange theDefault = create_U8(); + private static readonly DAST._INewtypeRange theDefault = create_U8(false); public static DAST._INewtypeRange Default() { return theDefault; } @@ -1633,42 +1667,45 @@ public static DAST._INewtypeRange Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _INewtypeRange create_U8() { - return new NewtypeRange_U8(); + public static _INewtypeRange create_U8(bool overflow) { + return new NewtypeRange_U8(overflow); } - public static _INewtypeRange create_I8() { - return new NewtypeRange_I8(); + public static _INewtypeRange create_I8(bool overflow) { + return new NewtypeRange_I8(overflow); } - public static _INewtypeRange create_U16() { - return new NewtypeRange_U16(); + public static _INewtypeRange create_U16(bool overflow) { + return new NewtypeRange_U16(overflow); } - public static _INewtypeRange create_I16() { - return new NewtypeRange_I16(); + public static _INewtypeRange create_I16(bool overflow) { + return new NewtypeRange_I16(overflow); } - public static _INewtypeRange create_U32() { - return new NewtypeRange_U32(); + public static _INewtypeRange create_U32(bool overflow) { + return new NewtypeRange_U32(overflow); } - public static _INewtypeRange create_I32() { - return new NewtypeRange_I32(); + public static _INewtypeRange create_I32(bool overflow) { + return new NewtypeRange_I32(overflow); } - public static _INewtypeRange create_U64() { - return new NewtypeRange_U64(); + public static _INewtypeRange create_U64(bool overflow) { + return new NewtypeRange_U64(overflow); } - public static _INewtypeRange create_I64() { - return new NewtypeRange_I64(); + public static _INewtypeRange create_I64(bool overflow) { + return new NewtypeRange_I64(overflow); } - public static _INewtypeRange create_U128() { - return new NewtypeRange_U128(); + public static _INewtypeRange create_U128(bool overflow) { + return new NewtypeRange_U128(overflow); } - public static _INewtypeRange create_I128() { - return new NewtypeRange_I128(); + public static _INewtypeRange create_I128(bool overflow) { + return new NewtypeRange_I128(overflow); } - public static _INewtypeRange create_USIZE() { - return new NewtypeRange_USIZE(); + public static _INewtypeRange create_NativeArrayIndex() { + return new NewtypeRange_NativeArrayIndex(); } public static _INewtypeRange create_BigInt() { return new NewtypeRange_BigInt(); } + public static _INewtypeRange create_Bool() { + return new NewtypeRange_Bool(); + } public static _INewtypeRange create_NoRange() { return new NewtypeRange_NoRange(); } @@ -1682,247 +1719,312 @@ public static _INewtypeRange create_NoRange() { public bool is_I64 { get { return this is NewtypeRange_I64; } } public bool is_U128 { get { return this is NewtypeRange_U128; } } public bool is_I128 { get { return this is NewtypeRange_I128; } } - public bool is_USIZE { get { return this is NewtypeRange_USIZE; } } + 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_NoRange { get { return this is NewtypeRange_NoRange; } } - public static System.Collections.Generic.IEnumerable<_INewtypeRange> AllSingletonConstructors { - get { - yield return NewtypeRange.create_U8(); - yield return NewtypeRange.create_I8(); - yield return NewtypeRange.create_U16(); - yield return NewtypeRange.create_I16(); - yield return NewtypeRange.create_U32(); - yield return NewtypeRange.create_I32(); - yield return NewtypeRange.create_U64(); - yield return NewtypeRange.create_I64(); - yield return NewtypeRange.create_U128(); - yield return NewtypeRange.create_I128(); - yield return NewtypeRange.create_USIZE(); - yield return NewtypeRange.create_BigInt(); - yield return NewtypeRange.create_NoRange(); + public bool dtor_overflow { + get { + var d = this; + if (d is NewtypeRange_U8) { return ((NewtypeRange_U8)d)._overflow; } + if (d is NewtypeRange_I8) { return ((NewtypeRange_I8)d)._overflow; } + if (d is NewtypeRange_U16) { return ((NewtypeRange_U16)d)._overflow; } + if (d is NewtypeRange_I16) { return ((NewtypeRange_I16)d)._overflow; } + if (d is NewtypeRange_U32) { return ((NewtypeRange_U32)d)._overflow; } + if (d is NewtypeRange_I32) { return ((NewtypeRange_I32)d)._overflow; } + if (d is NewtypeRange_U64) { return ((NewtypeRange_U64)d)._overflow; } + if (d is NewtypeRange_I64) { return ((NewtypeRange_I64)d)._overflow; } + if (d is NewtypeRange_U128) { return ((NewtypeRange_U128)d)._overflow; } + return ((NewtypeRange_I128)d)._overflow; } } public abstract _INewtypeRange DowncastClone(); + 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); + } } public class NewtypeRange_U8 : NewtypeRange { - public NewtypeRange_U8() : base() { + public readonly bool _overflow; + public NewtypeRange_U8(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_U8(); + return new NewtypeRange_U8(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_U8; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.U8"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class NewtypeRange_I8 : NewtypeRange { - public NewtypeRange_I8() : base() { + public readonly bool _overflow; + public NewtypeRange_I8(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_I8(); + return new NewtypeRange_I8(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_I8; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.I8"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class NewtypeRange_U16 : NewtypeRange { - public NewtypeRange_U16() : base() { + public readonly bool _overflow; + public NewtypeRange_U16(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_U16(); + return new NewtypeRange_U16(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_U16; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.U16"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class NewtypeRange_I16 : NewtypeRange { - public NewtypeRange_I16() : base() { + public readonly bool _overflow; + public NewtypeRange_I16(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_I16(); + return new NewtypeRange_I16(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_I16; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.I16"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class NewtypeRange_U32 : NewtypeRange { - public NewtypeRange_U32() : base() { + public readonly bool _overflow; + public NewtypeRange_U32(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_U32(); + return new NewtypeRange_U32(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_U32; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 4; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.U32"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class NewtypeRange_I32 : NewtypeRange { - public NewtypeRange_I32() : base() { + public readonly bool _overflow; + public NewtypeRange_I32(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_I32(); + return new NewtypeRange_I32(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_I32; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 5; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.I32"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class NewtypeRange_U64 : NewtypeRange { - public NewtypeRange_U64() : base() { + public readonly bool _overflow; + public NewtypeRange_U64(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_U64(); + return new NewtypeRange_U64(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_U64; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 6; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.U64"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class NewtypeRange_I64 : NewtypeRange { - public NewtypeRange_I64() : base() { + public readonly bool _overflow; + public NewtypeRange_I64(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_I64(); + return new NewtypeRange_I64(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_I64; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 7; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.I64"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class NewtypeRange_U128 : NewtypeRange { - public NewtypeRange_U128() : base() { + public readonly bool _overflow; + public NewtypeRange_U128(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_U128(); + return new NewtypeRange_U128(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_U128; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 8; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.U128"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class NewtypeRange_I128 : NewtypeRange { - public NewtypeRange_I128() : base() { + public readonly bool _overflow; + public NewtypeRange_I128(bool overflow) : base() { + this._overflow = overflow; } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_I128(); + return new NewtypeRange_I128(_overflow); } public override bool Equals(object other) { var oth = other as DAST.NewtypeRange_I128; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 9; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.NewtypeRange.I128"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } - public class NewtypeRange_USIZE : NewtypeRange { - public NewtypeRange_USIZE() : base() { + public class NewtypeRange_NativeArrayIndex : NewtypeRange { + public NewtypeRange_NativeArrayIndex() : base() { } public override _INewtypeRange DowncastClone() { if (this is _INewtypeRange dt) { return dt; } - return new NewtypeRange_USIZE(); + return new NewtypeRange_NativeArrayIndex(); } public override bool Equals(object other) { - var oth = other as DAST.NewtypeRange_USIZE; + var oth = other as DAST.NewtypeRange_NativeArrayIndex; return oth != null; } public override int GetHashCode() { @@ -1931,7 +2033,7 @@ public override int GetHashCode() { return (int) hash; } public override string ToString() { - string s = "DAST.NewtypeRange.USIZE"; + string s = "DAST.NewtypeRange.NativeArrayIndex"; return s; } } @@ -1956,6 +2058,27 @@ public override string ToString() { return s; } } + public class NewtypeRange_Bool : NewtypeRange { + public NewtypeRange_Bool() : base() { + } + public override _INewtypeRange DowncastClone() { + if (this is _INewtypeRange dt) { return dt; } + return new NewtypeRange_Bool(); + } + public override bool Equals(object other) { + var oth = other as DAST.NewtypeRange_Bool; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 12; + return (int) hash; + } + public override string ToString() { + string s = "DAST.NewtypeRange.Bool"; + return s; + } + } public class NewtypeRange_NoRange : NewtypeRange { public NewtypeRange_NoRange() : base() { } @@ -1969,7 +2092,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 12; + hash = ((hash << 5) + hash) + 13; return (int) hash; } public override string ToString() { @@ -2213,6 +2336,7 @@ 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._IType dtor_baseType { get; } @@ -2240,12 +2364,16 @@ public static _IResolvedTypeBase create_Datatype(Dafny.ISequence dtor_variances { get { @@ -2256,6 +2384,7 @@ public Dafny.ISequence dtor_variances { public DAST._IType dtor_baseType { get { var d = this; + if (d is ResolvedTypeBase_SynonymType) { return ((ResolvedTypeBase_SynonymType)d)._baseType; } return ((ResolvedTypeBase_Newtype)d)._baseType; } } @@ -2342,6 +2471,33 @@ public override string ToString() { return s; } } + public class ResolvedTypeBase_SynonymType : ResolvedTypeBase { + public readonly DAST._IType _baseType; + public ResolvedTypeBase_SynonymType(DAST._IType baseType) : base() { + this._baseType = baseType; + } + public override _IResolvedTypeBase DowncastClone() { + if (this is _IResolvedTypeBase dt) { return dt; } + return new ResolvedTypeBase_SynonymType(_baseType); + } + public override bool Equals(object other) { + var oth = other as DAST.ResolvedTypeBase_SynonymType; + return oth != null && object.Equals(this._baseType, oth._baseType); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._baseType)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.ResolvedTypeBase.SynonymType"; + s += "("; + s += Dafny.Helpers.ToString(this._baseType); + s += ")"; + return s; + } + } public class ResolvedTypeBase_Newtype : ResolvedTypeBase { public readonly DAST._IType _baseType; public readonly DAST._INewtypeRange _range; @@ -2361,7 +2517,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + 4; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._baseType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._range)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._erase)); @@ -3044,6 +3200,7 @@ public interface _INewtype { Dafny.ISequence dtor_witnessStmts { get; } Std.Wrappers._IOption dtor_witnessExpr { get; } Dafny.ISequence dtor_attributes { get; } + Dafny.ISequence dtor_classItems { get; } _INewtype DowncastClone(); } public class Newtype : _INewtype { @@ -3055,7 +3212,8 @@ public class Newtype : _INewtype { public readonly Dafny.ISequence _witnessStmts; public readonly Std.Wrappers._IOption _witnessExpr; public readonly Dafny.ISequence _attributes; - public Newtype(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes) { + public readonly Dafny.ISequence _classItems; + public Newtype(Dafny.ISequence name, 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) { this._name = name; this._typeParams = typeParams; this._base = @base; @@ -3064,14 +3222,15 @@ public Newtype(Dafny.ISequence name, Dafny.ISequence.Empty, Dafny.Sequence.Empty, DAST.Type.Default(), DAST.NewtypeRange.Default(), Std.Wrappers.Option.Default(), Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Dafny.Sequence.Empty); + private static readonly DAST._INewtype theDefault = create(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); public static DAST._INewtype Default() { return theDefault; } @@ -3115,11 +3277,11 @@ public static DAST._INewtype Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _INewtype create(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes) { - return new Newtype(name, typeParams, @base, range, constraint, witnessStmts, witnessExpr, attributes); + public static _INewtype create(Dafny.ISequence name, 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, typeParams, @base, range, constraint, witnessStmts, witnessExpr, attributes, classItems); } - public static _INewtype create_Newtype(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes) { - return create(name, typeParams, @base, range, constraint, witnessStmts, witnessExpr, attributes); + public static _INewtype create_Newtype(Dafny.ISequence name, 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, typeParams, @base, range, constraint, witnessStmts, witnessExpr, attributes, classItems); } public bool is_Newtype { get { return true; } } public Dafny.ISequence dtor_name { @@ -3162,6 +3324,11 @@ public Dafny.ISequence dtor_attributes { return this._attributes; } } + public Dafny.ISequence dtor_classItems { + get { + return this._classItems; + } + } } public interface _INewtypeConstraint { @@ -3392,24 +3559,27 @@ public interface _IField { DAST._IFormal dtor_formal { get; } bool dtor_isConstant { get; } Std.Wrappers._IOption dtor_defaultValue { get; } + bool dtor_isStatic { get; } _IField DowncastClone(); } public class Field : _IField { public readonly DAST._IFormal _formal; public readonly bool _isConstant; public readonly Std.Wrappers._IOption _defaultValue; - public Field(DAST._IFormal formal, bool isConstant, Std.Wrappers._IOption defaultValue) { + public readonly bool _isStatic; + public Field(DAST._IFormal formal, bool isConstant, Std.Wrappers._IOption defaultValue, bool isStatic) { this._formal = formal; this._isConstant = isConstant; this._defaultValue = defaultValue; + this._isStatic = isStatic; } public _IField DowncastClone() { if (this is _IField dt) { return dt; } - return new Field(_formal, _isConstant, _defaultValue); + return new Field(_formal, _isConstant, _defaultValue, _isStatic); } public override bool Equals(object other) { var oth = other as DAST.Field; - return oth != null && object.Equals(this._formal, oth._formal) && this._isConstant == oth._isConstant && object.Equals(this._defaultValue, oth._defaultValue); + return oth != null && object.Equals(this._formal, oth._formal) && this._isConstant == oth._isConstant && object.Equals(this._defaultValue, oth._defaultValue) && this._isStatic == oth._isStatic; } public override int GetHashCode() { ulong hash = 5381; @@ -3417,6 +3587,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._formal)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isConstant)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._defaultValue)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isStatic)); return (int) hash; } public override string ToString() { @@ -3427,10 +3598,12 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._isConstant); s += ", "; s += Dafny.Helpers.ToString(this._defaultValue); + s += ", "; + s += Dafny.Helpers.ToString(this._isStatic); s += ")"; return s; } - private static readonly DAST._IField theDefault = create(DAST.Formal.Default(), false, Std.Wrappers.Option.Default()); + private static readonly DAST._IField theDefault = create(DAST.Formal.Default(), false, Std.Wrappers.Option.Default(), false); public static DAST._IField Default() { return theDefault; } @@ -3438,11 +3611,11 @@ public static DAST._IField Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IField create(DAST._IFormal formal, bool isConstant, Std.Wrappers._IOption defaultValue) { - return new Field(formal, isConstant, defaultValue); + public static _IField create(DAST._IFormal formal, bool isConstant, Std.Wrappers._IOption defaultValue, bool isStatic) { + return new Field(formal, isConstant, defaultValue, isStatic); } - public static _IField create_Field(DAST._IFormal formal, bool isConstant, Std.Wrappers._IOption defaultValue) { - return create(formal, isConstant, defaultValue); + public static _IField create_Field(DAST._IFormal formal, bool isConstant, Std.Wrappers._IOption defaultValue, bool isStatic) { + return create(formal, isConstant, defaultValue, isStatic); } public bool is_Field { get { return true; } } public DAST._IFormal dtor_formal { @@ -3460,6 +3633,11 @@ public Std.Wrappers._IOption dtor_defaultValue { return this._defaultValue; } } + public bool dtor_isStatic { + get { + return this._isStatic; + } + } } public interface _IFormal { @@ -4943,6 +5121,92 @@ public override string ToString() { } } + public interface _ITypedBinOp { + bool is_TypedBinOp { get; } + DAST._IBinOp dtor_op { get; } + DAST._IType dtor_leftType { get; } + DAST._IType dtor_rightType { get; } + DAST._IType dtor_resultType { get; } + _ITypedBinOp DowncastClone(); + } + public class TypedBinOp : _ITypedBinOp { + public readonly DAST._IBinOp _op; + public readonly DAST._IType _leftType; + public readonly DAST._IType _rightType; + public readonly DAST._IType _resultType; + public TypedBinOp(DAST._IBinOp op, DAST._IType leftType, DAST._IType rightType, DAST._IType resultType) { + this._op = op; + this._leftType = leftType; + this._rightType = rightType; + this._resultType = resultType; + } + public _ITypedBinOp DowncastClone() { + if (this is _ITypedBinOp dt) { return dt; } + return new TypedBinOp(_op, _leftType, _rightType, _resultType); + } + public override bool Equals(object other) { + var oth = other as DAST.TypedBinOp; + return oth != null && object.Equals(this._op, oth._op) && object.Equals(this._leftType, oth._leftType) && object.Equals(this._rightType, oth._rightType) && object.Equals(this._resultType, oth._resultType); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._op)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._leftType)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._rightType)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._resultType)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.TypedBinOp.TypedBinOp"; + s += "("; + s += Dafny.Helpers.ToString(this._op); + s += ", "; + s += Dafny.Helpers.ToString(this._leftType); + s += ", "; + s += Dafny.Helpers.ToString(this._rightType); + s += ", "; + s += Dafny.Helpers.ToString(this._resultType); + s += ")"; + return s; + } + private static readonly DAST._ITypedBinOp theDefault = create(DAST.BinOp.Default(), DAST.Type.Default(), DAST.Type.Default(), DAST.Type.Default()); + public static DAST._ITypedBinOp Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.TypedBinOp.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _ITypedBinOp create(DAST._IBinOp op, DAST._IType leftType, DAST._IType rightType, DAST._IType resultType) { + return new TypedBinOp(op, leftType, rightType, resultType); + } + public static _ITypedBinOp create_TypedBinOp(DAST._IBinOp op, DAST._IType leftType, DAST._IType rightType, DAST._IType resultType) { + return create(op, leftType, rightType, resultType); + } + public bool is_TypedBinOp { get { return true; } } + public DAST._IBinOp dtor_op { + get { + return this._op; + } + } + public DAST._IType dtor_leftType { + get { + return this._leftType; + } + } + public DAST._IType dtor_rightType { + get { + return this._rightType; + } + } + public DAST._IType dtor_resultType { + get { + return this._resultType; + } + } + } + public interface _IBinOp { bool is_Eq { get; } bool is_Div { get; } @@ -4981,6 +5245,7 @@ public interface _IBinOp { bool is_Concat { get; } bool is_Passthrough { get; } bool dtor_referential { get; } + bool dtor_overflow { get; } Dafny.ISequence dtor_Passthrough_a0 { get; } _IBinOp DowncastClone(); } @@ -4998,8 +5263,8 @@ public static DAST._IBinOp Default() { public static _IBinOp create_Eq(bool referential) { return new BinOp_Eq(referential); } - public static _IBinOp create_Div() { - return new BinOp_Div(); + public static _IBinOp create_Div(bool overflow) { + return new BinOp_Div(overflow); } public static _IBinOp create_EuclidianDiv() { return new BinOp_EuclidianDiv(); @@ -5016,14 +5281,14 @@ public static _IBinOp create_Lt() { public static _IBinOp create_LtChar() { return new BinOp_LtChar(); } - public static _IBinOp create_Plus() { - return new BinOp_Plus(); + public static _IBinOp create_Plus(bool overflow) { + return new BinOp_Plus(overflow); } - public static _IBinOp create_Minus() { - return new BinOp_Minus(); + public static _IBinOp create_Minus(bool overflow) { + return new BinOp_Minus(overflow); } - public static _IBinOp create_Times() { - return new BinOp_Times(); + public static _IBinOp create_Times(bool overflow) { + return new BinOp_Times(overflow); } public static _IBinOp create_BitwiseAnd() { return new BinOp_BitwiseAnd(); @@ -5145,6 +5410,15 @@ public bool dtor_referential { return ((BinOp_Eq)d)._referential; } } + public bool dtor_overflow { + get { + var d = this; + if (d is BinOp_Div) { return ((BinOp_Div)d)._overflow; } + if (d is BinOp_Plus) { return ((BinOp_Plus)d)._overflow; } + if (d is BinOp_Minus) { return ((BinOp_Minus)d)._overflow; } + return ((BinOp_Times)d)._overflow; + } + } public Dafny.ISequence dtor_Passthrough_a0 { get { var d = this; @@ -5181,23 +5455,29 @@ public override string ToString() { } } public class BinOp_Div : BinOp { - public BinOp_Div() : base() { + public readonly bool _overflow; + public BinOp_Div(bool overflow) : base() { + this._overflow = overflow; } public override _IBinOp DowncastClone() { if (this is _IBinOp dt) { return dt; } - return new BinOp_Div(); + return new BinOp_Div(_overflow); } public override bool Equals(object other) { var oth = other as DAST.BinOp_Div; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.BinOp.Div"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } @@ -5307,65 +5587,83 @@ public override string ToString() { } } public class BinOp_Plus : BinOp { - public BinOp_Plus() : base() { + public readonly bool _overflow; + public BinOp_Plus(bool overflow) : base() { + this._overflow = overflow; } public override _IBinOp DowncastClone() { if (this is _IBinOp dt) { return dt; } - return new BinOp_Plus(); + return new BinOp_Plus(_overflow); } public override bool Equals(object other) { var oth = other as DAST.BinOp_Plus; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 7; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.BinOp.Plus"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class BinOp_Minus : BinOp { - public BinOp_Minus() : base() { + public readonly bool _overflow; + public BinOp_Minus(bool overflow) : base() { + this._overflow = overflow; } public override _IBinOp DowncastClone() { if (this is _IBinOp dt) { return dt; } - return new BinOp_Minus(); + return new BinOp_Minus(_overflow); } public override bool Equals(object other) { var oth = other as DAST.BinOp_Minus; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 8; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.BinOp.Minus"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } public class BinOp_Times : BinOp { - public BinOp_Times() : base() { + public readonly bool _overflow; + public BinOp_Times(bool overflow) : base() { + this._overflow = overflow; } public override _IBinOp DowncastClone() { if (this is _IBinOp dt) { return dt; } - return new BinOp_Times(); + return new BinOp_Times(_overflow); } public override bool Equals(object other) { var oth = other as DAST.BinOp_Times; - return oth != null; + return oth != null && this._overflow == oth._overflow; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 9; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); return (int) hash; } public override string ToString() { string s = "DAST.BinOp.Times"; + s += "("; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; return s; } } @@ -6005,7 +6303,7 @@ public interface _IExpression { DAST._IExpression dtor_els { get; } DAST._IUnaryOp dtor_unOp { get; } DAST.Format._IUnaryOpFormat dtor_format1 { get; } - DAST._IBinOp dtor_op { get; } + DAST._ITypedBinOp dtor_op { get; } DAST._IExpression dtor_left { get; } DAST._IExpression dtor_right { get; } DAST.Format._IBinaryOpFormat dtor_format2 { get; } @@ -6131,7 +6429,7 @@ public static _IExpression create_Ite(DAST._IExpression cond, DAST._IExpression public static _IExpression create_UnOp(DAST._IUnaryOp unOp, DAST._IExpression expr, DAST.Format._IUnaryOpFormat format1) { return new Expression_UnOp(unOp, expr, format1); } - public static _IExpression create_BinOp(DAST._IBinOp op, DAST._IExpression left, DAST._IExpression right, DAST.Format._IBinaryOpFormat format2) { + public static _IExpression create_BinOp(DAST._ITypedBinOp op, DAST._IExpression left, DAST._IExpression right, DAST.Format._IBinaryOpFormat format2) { return new Expression_BinOp(op, left, right, format2); } public static _IExpression create_ArrayLen(DAST._IExpression expr, DAST._IType exprType, BigInteger dim, bool native) { @@ -6484,7 +6782,7 @@ public DAST.Format._IUnaryOpFormat dtor_format1 { return ((Expression_UnOp)d)._format1; } } - public DAST._IBinOp dtor_op { + public DAST._ITypedBinOp dtor_op { get { var d = this; return ((Expression_BinOp)d)._op; @@ -7495,11 +7793,11 @@ public override string ToString() { } } public class Expression_BinOp : Expression { - public readonly DAST._IBinOp _op; + public readonly DAST._ITypedBinOp _op; public readonly DAST._IExpression _left; public readonly DAST._IExpression _right; public readonly DAST.Format._IBinaryOpFormat _format2; - public Expression_BinOp(DAST._IBinOp op, DAST._IExpression left, DAST._IExpression right, DAST.Format._IBinaryOpFormat format2) : base() { + public Expression_BinOp(DAST._ITypedBinOp op, DAST._IExpression left, DAST._IExpression right, DAST.Format._IBinaryOpFormat format2) : base() { this._op = op; this._left = left; this._right = right; @@ -8450,7 +8748,7 @@ public override string ToString() { public interface _IFieldMutability { bool is_ConstantField { get; } - bool is_InternalClassConstantField { get; } + bool is_InternalClassConstantFieldOrDatatypeDestructor { get; } bool is_ClassMutableField { get; } _IFieldMutability DowncastClone(); } @@ -8468,19 +8766,19 @@ public static DAST._IFieldMutability Default() { public static _IFieldMutability create_ConstantField() { return new FieldMutability_ConstantField(); } - public static _IFieldMutability create_InternalClassConstantField() { - return new FieldMutability_InternalClassConstantField(); + public static _IFieldMutability create_InternalClassConstantFieldOrDatatypeDestructor() { + return new FieldMutability_InternalClassConstantFieldOrDatatypeDestructor(); } public static _IFieldMutability create_ClassMutableField() { return new FieldMutability_ClassMutableField(); } public bool is_ConstantField { get { return this is FieldMutability_ConstantField; } } - public bool is_InternalClassConstantField { get { return this is FieldMutability_InternalClassConstantField; } } + public bool is_InternalClassConstantFieldOrDatatypeDestructor { get { return this is FieldMutability_InternalClassConstantFieldOrDatatypeDestructor; } } public bool is_ClassMutableField { get { return this is FieldMutability_ClassMutableField; } } public static System.Collections.Generic.IEnumerable<_IFieldMutability> AllSingletonConstructors { get { yield return FieldMutability.create_ConstantField(); - yield return FieldMutability.create_InternalClassConstantField(); + yield return FieldMutability.create_InternalClassConstantFieldOrDatatypeDestructor(); yield return FieldMutability.create_ClassMutableField(); } } @@ -8507,15 +8805,15 @@ public override string ToString() { return s; } } - public class FieldMutability_InternalClassConstantField : FieldMutability { - public FieldMutability_InternalClassConstantField() : base() { + public class FieldMutability_InternalClassConstantFieldOrDatatypeDestructor : FieldMutability { + public FieldMutability_InternalClassConstantFieldOrDatatypeDestructor() : base() { } public override _IFieldMutability DowncastClone() { if (this is _IFieldMutability dt) { return dt; } - return new FieldMutability_InternalClassConstantField(); + return new FieldMutability_InternalClassConstantFieldOrDatatypeDestructor(); } public override bool Equals(object other) { - var oth = other as DAST.FieldMutability_InternalClassConstantField; + var oth = other as DAST.FieldMutability_InternalClassConstantFieldOrDatatypeDestructor; return oth != null; } public override int GetHashCode() { @@ -8524,7 +8822,7 @@ public override int GetHashCode() { return (int) hash; } public override string ToString() { - string s = "DAST.FieldMutability.InternalClassConstantField"; + string s = "DAST.FieldMutability.InternalClassConstantFieldOrDatatypeDestructor"; return s; } } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 49f3c4219ce..f50e161fc1a 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -131,7 +131,7 @@ public void GenModuleBody(Dafny.ISequence body, Dafny.ISequen if (_source0.is_Newtype) { DAST._INewtype _6_n = _source0.dtor_Newtype_a0; Dafny.ISequence _out3; - _out3 = (this).GenNewtype(_6_n); + _out3 = (this).GenNewtype(_6_n, Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((_6_n).dtor_name))); _1_generated = _out3; goto after_match0; } @@ -217,6 +217,55 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) return (((_1_currentType).is_TIdentifier) ? (Dafny.Set>.Union(_0_types, Dafny.Set>.FromElements((_1_currentType).dtor_name))) : (_0_types)); }))); } + public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAssignIdentifier fieldInit, out Dafny.ISet> usedTypeParams) + { + rfield = RAST.Field.Default(); + fieldInit = RAST.AssignIdentifier.Default(); + usedTypeParams = Dafny.Set>.Empty; + usedTypeParams = Dafny.Set>.FromElements(); + RAST._IType _0_fieldType; + RAST._IType _out0; + _out0 = (this).GenType(((field).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); + _0_fieldType = _out0; + if (!((field).dtor_isConstant)) { + _0_fieldType = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Field"))).AsType()).Apply(Dafny.Sequence.FromElements(_0_fieldType)); + } + usedTypeParams = (this).GatherTypeParamNames(usedTypeParams, _0_fieldType); + Dafny.ISequence _1_fieldRustName; + _1_fieldRustName = Defs.__default.escapeVar(((field).dtor_formal).dtor_name); + rfield = RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(_1_fieldRustName, _0_fieldType)); + Std.Wrappers._IOption _source0 = (field).dtor_defaultValue; + { + if (_source0.is_Some) { + DAST._IExpression _2_e = _source0.dtor_value; + { + RAST._IExpr _3_expr; + Defs._IOwnership _4___v0; + Dafny.ISet> _5___v1; + RAST._IExpr _out1; + Defs._IOwnership _out2; + Dafny.ISet> _out3; + (this).GenExpr(_2_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); + _3_expr = _out1; + _4___v0 = _out2; + _5___v1 = _out3; + fieldInit = RAST.AssignIdentifier.create(_1_fieldRustName, _3_expr); + } + goto after_match0; + } + } + { + { + RAST._IExpr _6_default; + _6_default = RAST.__default.std__default__Default__default; + if ((_0_fieldType).IsObjectOrPointer()) { + _6_default = (_0_fieldType).ToNullExpr(); + } + fieldInit = RAST.AssignIdentifier.create(_1_fieldRustName, _6_default); + } + } + after_match0: ; + } public Dafny.ISequence GenClass(DAST._IClass c, Dafny.ISequence> path) { Dafny.ISequence s = Dafny.Sequence.Empty; @@ -245,196 +294,167 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) for (BigInteger _8_fieldI = BigInteger.Zero; _8_fieldI < _hi0; _8_fieldI++) { DAST._IField _9_field; _9_field = ((c).dtor_fields).Select(_8_fieldI); - RAST._IType _10_fieldType; - RAST._IType _out4; - _out4 = (this).GenType(((_9_field).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); - _10_fieldType = _out4; - if (!((_9_field).dtor_isConstant)) { - _10_fieldType = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Field"))).AsType()).Apply(Dafny.Sequence.FromElements(_10_fieldType)); - } - _7_usedTypeParams = (this).GatherTypeParamNames(_7_usedTypeParams, _10_fieldType); - Dafny.ISequence _11_fieldRustName; - _11_fieldRustName = Defs.__default.escapeVar(((_9_field).dtor_formal).dtor_name); - _5_fields = Dafny.Sequence.Concat(_5_fields, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(_11_fieldRustName, _10_fieldType)))); - Std.Wrappers._IOption _source0 = (_9_field).dtor_defaultValue; - { - if (_source0.is_Some) { - DAST._IExpression _12_e = _source0.dtor_value; - { - RAST._IExpr _13_expr; - Defs._IOwnership _14___v0; - Dafny.ISet> _15___v1; - RAST._IExpr _out5; - Defs._IOwnership _out6; - Dafny.ISet> _out7; - (this).GenExpr(_12_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); - _13_expr = _out5; - _14___v0 = _out6; - _15___v1 = _out7; - _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_11_fieldRustName, _13_expr))); - } - goto after_match0; - } - } - { - { - RAST._IExpr _16_default; - _16_default = RAST.__default.std__default__Default__default; - if ((_10_fieldType).IsObjectOrPointer()) { - _16_default = (_10_fieldType).ToNullExpr(); - } - _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_11_fieldRustName, _16_default))); - } - } - after_match0: ; + RAST._IField _10_rfield; + RAST._IAssignIdentifier _11_fieldInit; + Dafny.ISet> _12_fieldUsedTypeParams; + RAST._IField _out4; + RAST._IAssignIdentifier _out5; + Dafny.ISet> _out6; + (this).GenField(_9_field, out _out4, out _out5, out _out6); + _10_rfield = _out4; + _11_fieldInit = _out5; + _12_fieldUsedTypeParams = _out6; + _5_fields = Dafny.Sequence.Concat(_5_fields, Dafny.Sequence.FromElements(_10_rfield)); + _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(_11_fieldInit)); + _7_usedTypeParams = Dafny.Set>.Union(_7_usedTypeParams, _12_fieldUsedTypeParams); } BigInteger _hi1 = new BigInteger(((c).dtor_typeParams).Count); - for (BigInteger _17_typeParamI = BigInteger.Zero; _17_typeParamI < _hi1; _17_typeParamI++) { - DAST._IType _18_typeArg; - RAST._ITypeParamDecl _19_typeParam; - DAST._IType _out8; - RAST._ITypeParamDecl _out9; - (this).GenTypeParam(((c).dtor_typeParams).Select(_17_typeParamI), out _out8, out _out9); - _18_typeArg = _out8; - _19_typeParam = _out9; - RAST._IType _20_rTypeArg; - RAST._IType _out10; - _out10 = (this).GenType(_18_typeArg, Defs.GenTypeContext.@default()); - _20_rTypeArg = _out10; - if ((_7_usedTypeParams).Contains((_19_typeParam).dtor_name)) { + for (BigInteger _13_typeParamI = BigInteger.Zero; _13_typeParamI < _hi1; _13_typeParamI++) { + DAST._IType _14_typeArg; + RAST._ITypeParamDecl _15_typeParam; + DAST._IType _out7; + RAST._ITypeParamDecl _out8; + (this).GenTypeParam(((c).dtor_typeParams).Select(_13_typeParamI), out _out7, out _out8); + _14_typeArg = _out7; + _15_typeParam = _out8; + RAST._IType _16_rTypeArg; + RAST._IType _out9; + _out9 = (this).GenType(_14_typeArg, Defs.GenTypeContext.@default()); + _16_rTypeArg = _out9; + if ((_7_usedTypeParams).Contains((_15_typeParam).dtor_name)) { goto continue_0; } - _5_fields = Dafny.Sequence.Concat(_5_fields, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_17_typeParamI)), RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_20_rTypeArg)))))); - _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_17_typeParamI)), (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsExpr()))); + _5_fields = Dafny.Sequence.Concat(_5_fields, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_13_typeParamI)), RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_16_rTypeArg)))))); + _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_13_typeParamI)), (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsExpr()))); continue_0: ; } after_0: ; - Defs._IExternAttribute _21_extern; - _21_extern = Defs.__default.ExtractExtern((c).dtor_attributes, (c).dtor_name); - Dafny.ISequence _22_className = Dafny.Sequence.Empty; - if ((_21_extern).is_SimpleExtern) { - _22_className = (_21_extern).dtor_overrideName; + Defs._IExternAttribute _17_extern; + _17_extern = Defs.__default.ExtractExtern((c).dtor_attributes, (c).dtor_name); + Dafny.ISequence _18_className = Dafny.Sequence.Empty; + if ((_17_extern).is_SimpleExtern) { + _18_className = (_17_extern).dtor_overrideName; } else { - _22_className = Defs.__default.escapeName((c).dtor_name); - if ((_21_extern).is_AdvancedExtern) { + _18_className = Defs.__default.escapeName((c).dtor_name); + if ((_17_extern).is_AdvancedExtern) { (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("Multi-argument externs not supported for classes yet")); } } - RAST._IStruct _23_struct; - _23_struct = RAST.Struct.create(Dafny.Sequence>.FromElements(), _22_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_5_fields)); + RAST._IStruct _19_struct; + _19_struct = RAST.Struct.create(Dafny.Sequence>.FromElements(), _18_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_5_fields)); s = Dafny.Sequence.FromElements(); - if ((_21_extern).is_NoExtern) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_23_struct))); - } - Dafny.ISequence _24_implBody; - Dafny.IMap>,Dafny.ISequence> _25_traitBodies; - Dafny.ISequence _out11; - Dafny.IMap>,Dafny.ISequence> _out12; - (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(path, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Class(), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out11, out _out12); - _24_implBody = _out11; - _25_traitBodies = _out12; - if (((_21_extern).is_NoExtern) && (!(_22_className).Equals(Dafny.Sequence.UnicodeFromString("_default")))) { - _24_implBody = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create((this).allocate__fn, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((this).Object(RAST.__default.SelfOwned)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel((this).allocate)).AsExpr()).ApplyType1(RAST.__default.SelfOwned)).Apply0())))), _24_implBody); - } - RAST._IType _26_selfTypeForImpl = RAST.Type.Default(); - if (((_21_extern).is_NoExtern) || ((_21_extern).is_UnsupportedExtern)) { - _26_selfTypeForImpl = RAST.Type.create_TIdentifier(_22_className); - } else if ((_21_extern).is_AdvancedExtern) { - _26_selfTypeForImpl = (((RAST.__default.crate).MSels((_21_extern).dtor_enclosingModule)).MSel((_21_extern).dtor_overrideName)).AsType(); - } else if ((_21_extern).is_SimpleExtern) { - _26_selfTypeForImpl = RAST.Type.create_TIdentifier((_21_extern).dtor_overrideName); - } - if ((new BigInteger((_24_implBody).Count)).Sign == 1) { - RAST._IImpl _27_i; - _27_i = RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(_26_selfTypeForImpl, _1_rTypeParams), _3_whereConstraints, _24_implBody); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_27_i))); - } - Dafny.ISequence _28_testMethods; - _28_testMethods = Dafny.Sequence.FromElements(); - if ((_22_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { + if ((_17_extern).is_NoExtern) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_19_struct))); + } + Dafny.ISequence _20_implBody; + Dafny.IMap>,Dafny.ISequence> _21_traitBodies; + Dafny.ISequence _out10; + Dafny.IMap>,Dafny.ISequence> _out11; + (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(path, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Class(), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out10, out _out11); + _20_implBody = _out10; + _21_traitBodies = _out11; + if (((_17_extern).is_NoExtern) && (!(_18_className).Equals(Dafny.Sequence.UnicodeFromString("_default")))) { + _20_implBody = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create((this).allocate__fn, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((this).Object(RAST.__default.SelfOwned)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel((this).allocate)).AsExpr()).ApplyType1(RAST.__default.SelfOwned)).Apply0())))), _20_implBody); + } + RAST._IType _22_selfTypeForImpl = RAST.Type.Default(); + if (((_17_extern).is_NoExtern) || ((_17_extern).is_UnsupportedExtern)) { + _22_selfTypeForImpl = RAST.Type.create_TIdentifier(_18_className); + } else if ((_17_extern).is_AdvancedExtern) { + _22_selfTypeForImpl = (((RAST.__default.crate).MSels((_17_extern).dtor_enclosingModule)).MSel((_17_extern).dtor_overrideName)).AsType(); + } else if ((_17_extern).is_SimpleExtern) { + _22_selfTypeForImpl = RAST.Type.create_TIdentifier((_17_extern).dtor_overrideName); + } + if ((new BigInteger((_20_implBody).Count)).Sign == 1) { + RAST._IImpl _23_i; + _23_i = RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(_22_selfTypeForImpl, _1_rTypeParams), _3_whereConstraints, _20_implBody); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_23_i))); + } + Dafny.ISequence _24_testMethods; + _24_testMethods = Dafny.Sequence.FromElements(); + if ((_18_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { BigInteger _hi2 = new BigInteger(((c).dtor_body).Count); - for (BigInteger _29_i = BigInteger.Zero; _29_i < _hi2; _29_i++) { - DAST._IMethod _30_m; - DAST._IMethod _source1 = ((c).dtor_body).Select(_29_i); + for (BigInteger _25_i = BigInteger.Zero; _25_i < _hi2; _25_i++) { + DAST._IMethod _26_m; + DAST._IMethod _source0 = ((c).dtor_body).Select(_25_i); { - DAST._IMethod _31_m = _source1; - _30_m = _31_m; + DAST._IMethod _27_m = _source0; + _26_m = _27_m; } - after_match1: ; - if (((this).HasAttribute((_30_m).dtor_attributes, Dafny.Sequence.UnicodeFromString("test"))) && ((new BigInteger(((_30_m).dtor_params).Count)).Sign == 0)) { - Dafny.ISequence _32_fnName; - _32_fnName = Defs.__default.escapeName((_30_m).dtor_name); - _28_testMethods = Dafny.Sequence.Concat(_28_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[test]")), RAST.Visibility.create_PUB(), RAST.Fn.create(_32_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_32_fnName)).Apply(Dafny.Sequence.FromElements()))))))); + after_match0: ; + if (((this).HasAttribute((_26_m).dtor_attributes, Dafny.Sequence.UnicodeFromString("test"))) && ((new BigInteger(((_26_m).dtor_params).Count)).Sign == 0)) { + Dafny.ISequence _28_fnName; + _28_fnName = Defs.__default.escapeName((_26_m).dtor_name); + _24_testMethods = Dafny.Sequence.Concat(_24_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[test]")), RAST.Visibility.create_PUB(), RAST.Fn.create(_28_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_28_fnName)).Apply(Dafny.Sequence.FromElements()))))))); } } - s = Dafny.Sequence.Concat(s, _28_testMethods); + s = Dafny.Sequence.Concat(s, _24_testMethods); } - RAST._IType _33_genSelfPath; - RAST._IType _out13; - _out13 = (this).GenPathType(path); - _33_genSelfPath = _out13; - if (!(_22_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.__default.AnyTrait))), RAST.Type.create_TypeApp(_33_genSelfPath, _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(RAST.__default.AnyTrait))))))))); + RAST._IType _29_genSelfPath; + RAST._IType _out12; + _out12 = (this).GenPathType(path); + _29_genSelfPath = _out12; + if (!(_18_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.__default.AnyTrait))), RAST.Type.create_TypeApp(_29_genSelfPath, _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(RAST.__default.AnyTrait))))))))); } - Dafny.ISequence _34_superClasses; - if ((_22_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { - _34_superClasses = Dafny.Sequence.FromElements(); + Dafny.ISequence _30_superClasses; + if ((_18_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { + _30_superClasses = Dafny.Sequence.FromElements(); } else { - _34_superClasses = (c).dtor_superClasses; + _30_superClasses = (c).dtor_superClasses; } - BigInteger _hi3 = new BigInteger((_34_superClasses).Count); - for (BigInteger _35_i = BigInteger.Zero; _35_i < _hi3; _35_i++) { - DAST._IType _36_superClass; - _36_superClass = (_34_superClasses).Select(_35_i); - DAST._IType _source2 = _36_superClass; + BigInteger _hi3 = new BigInteger((_30_superClasses).Count); + for (BigInteger _31_i = BigInteger.Zero; _31_i < _hi3; _31_i++) { + DAST._IType _32_superClass; + _32_superClass = (_30_superClasses).Select(_31_i); + DAST._IType _source1 = _32_superClass; { - if (_source2.is_UserDefined) { - DAST._IResolvedType resolved0 = _source2.dtor_resolved; - Dafny.ISequence> _37_traitPath = resolved0.dtor_path; - Dafny.ISequence _38_typeArgs = resolved0.dtor_typeArgs; + if (_source1.is_UserDefined) { + DAST._IResolvedType resolved0 = _source1.dtor_resolved; + Dafny.ISequence> _33_traitPath = resolved0.dtor_path; + Dafny.ISequence _34_typeArgs = resolved0.dtor_typeArgs; DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; if (kind0.is_Trait) { - Dafny.ISequence> _39_properMethods = resolved0.dtor_properMethods; + Dafny.ISequence> _35_properMethods = resolved0.dtor_properMethods; { - RAST._IType _40_pathStr; - RAST._IType _out14; - _out14 = (this).GenPathType(_37_traitPath); - _40_pathStr = _out14; - Dafny.ISequence _41_typeArgs; - Dafny.ISequence _out15; - _out15 = (this).GenTypeArgs(_38_typeArgs, Defs.GenTypeContext.@default()); - _41_typeArgs = _out15; - Dafny.ISequence _42_body; - _42_body = Dafny.Sequence.FromElements(); - if ((_25_traitBodies).Contains(_37_traitPath)) { - _42_body = Dafny.Map>, Dafny.ISequence>.Select(_25_traitBodies,_37_traitPath); + RAST._IType _36_pathStr; + RAST._IType _out13; + _out13 = (this).GenPathType(_33_traitPath); + _36_pathStr = _out13; + Dafny.ISequence _37_typeArgs; + Dafny.ISequence _out14; + _out14 = (this).GenTypeArgs(_34_typeArgs, Defs.GenTypeContext.@default()); + _37_typeArgs = _out14; + Dafny.ISequence _38_body; + _38_body = Dafny.Sequence.FromElements(); + if ((_21_traitBodies).Contains(_33_traitPath)) { + _38_body = Dafny.Map>, Dafny.ISequence>.Select(_21_traitBodies,_33_traitPath); } - RAST._IType _43_traitType; - _43_traitType = RAST.Type.create_TypeApp(_40_pathStr, _41_typeArgs); - if (!((_21_extern).is_NoExtern)) { - if (((new BigInteger((_42_body).Count)).Sign == 0) && ((new BigInteger((_39_properMethods).Count)).Sign != 0)) { + RAST._IType _39_traitType; + _39_traitType = RAST.Type.create_TypeApp(_36_pathStr, _37_typeArgs); + if (!((_17_extern).is_NoExtern)) { + if (((new BigInteger((_38_body).Count)).Sign == 0) && ((new BigInteger((_35_properMethods).Count)).Sign != 0)) { goto continue_1; } - if ((new BigInteger((_42_body).Count)) != (new BigInteger((_39_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.UnicodeFromString("Error: In the class "), RAST.__default.SeqToString>(path, ((System.Func, Dafny.ISequence>)((_44_s) => { - return ((_44_s)); -})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_43_traitType)._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>(_39_properMethods, ((System.Func, Dafny.ISequence>)((_45_s) => { - return (_45_s); + if ((new BigInteger((_38_body).Count)) != (new BigInteger((_35_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.UnicodeFromString("Error: In the class "), RAST.__default.SeqToString>(path, ((System.Func, Dafny.ISequence>)((_40_s) => { + return ((_40_s)); +})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_39_traitType)._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>(_35_properMethods, ((System.Func, Dafny.ISequence>)((_41_s) => { + return (_41_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."))); } } - RAST._IModDecl _46_x; - _46_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, _43_traitType, RAST.Type.create_TypeApp(_33_genSelfPath, _1_rTypeParams), _3_whereConstraints, _42_body)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_46_x)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_43_traitType))), RAST.Type.create_TypeApp(_33_genSelfPath, _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_43_traitType))))))))); + RAST._IModDecl _42_x; + _42_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, _39_traitType, RAST.Type.create_TypeApp(_29_genSelfPath, _1_rTypeParams), _3_whereConstraints, _38_body)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_42_x)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_39_traitType))), RAST.Type.create_TypeApp(_29_genSelfPath, _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_39_traitType))))))))); } - goto after_match2; + goto after_match1; } } } { } - after_match2: ; + after_match1: ; continue_1: ; } after_1: ; @@ -492,7 +512,7 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_typeParamDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(Defs.__default.escapeName((t).dtor_name)), _2_typeParams), _11_parents, _9_implBody))); return s; } - public Dafny.ISequence GenNewtype(DAST._INewtype c) + public Dafny.ISequence GenNewtype(DAST._INewtype c, Dafny.ISequence> path) { Dafny.ISequence s = Dafny.Sequence.Empty; Dafny.ISequence _0_typeParamsSeq; @@ -510,92 +530,113 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) _3_whereConstraints = _out3; Dafny.ISequence _4_constrainedTypeParams; _4_constrainedTypeParams = RAST.TypeParamDecl.ToStringMultiple(_2_rTypeParamsDecls, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); - RAST._IType _5_underlyingType = RAST.Type.Default(); - Std.Wrappers._IOption _source0 = Defs.__default.NewtypeRangeToRustType((c).dtor_range); - { - if (_source0.is_Some) { - RAST._IType _6_v = _source0.dtor_value; - _5_underlyingType = _6_v; - goto after_match0; - } - } - { + RAST._IType _5_wrappedType = RAST.Type.Default(); + Std.Wrappers._IOption _6_rustType; + _6_rustType = Defs.__default.NewtypeRangeToUnwrappedBoundedRustType((c).dtor_base, (c).dtor_range); + if ((_6_rustType).is_Some) { + _5_wrappedType = (_6_rustType).dtor_value; + } else { RAST._IType _out4; _out4 = (this).GenType((c).dtor_base, Defs.GenTypeContext.@default()); - _5_underlyingType = _out4; + _5_wrappedType = _out4; } - after_match0: ; - DAST._IType _7_resultingType; - _7_resultingType = DAST.Type.create_UserDefined(DAST.ResolvedType.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Newtype((c).dtor_base, (c).dtor_range, false), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())); + DAST._IType _7_newtypeType; + _7_newtypeType = DAST.Type.create_UserDefined(DAST.ResolvedType.create(path, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Newtype((c).dtor_base, (c).dtor_range, false), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())); Dafny.ISequence _8_newtypeName; _8_newtypeName = Defs.__default.escapeName((c).dtor_name); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq)]"), Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), _8_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _5_underlyingType)))))); - RAST._IExpr _9_fnBody; - _9_fnBody = RAST.Expr.create_Identifier(_8_newtypeName); - Std.Wrappers._IOption _source1 = (c).dtor_witnessExpr; + RAST._IType _9_resultingType; + _9_resultingType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_8_newtypeName), _1_rTypeParams); + Dafny.ISequence _10_attributes = Dafny.Sequence.Empty; + if (Defs.__default.IsNewtypeCopy((c).dtor_range)) { + _10_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq, Copy)]"); + } else { + _10_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq)]"); + } + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(_10_attributes, Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), _8_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _5_wrappedType)))))); + RAST._IExpr _11_fnBody = RAST.Expr.Default(); + Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; { - if (_source1.is_Some) { - DAST._IExpression _10_e = _source1.dtor_value; + if (_source0.is_Some) { + DAST._IExpression _12_e = _source0.dtor_value; { - DAST._IExpression _11_e; - if (object.Equals((c).dtor_base, _7_resultingType)) { - _11_e = _10_e; - } else { - _11_e = DAST.Expression.create_Convert(_10_e, (c).dtor_base, _7_resultingType); - } - RAST._IExpr _12_eStr; - Defs._IOwnership _13___v6; - Dafny.ISet> _14___v7; + DAST._IExpression _13_e; + _13_e = DAST.Expression.create_Convert(_12_e, (c).dtor_base, _7_newtypeType); + RAST._IExpr _14_r; + Defs._IOwnership _15___v6; + Dafny.ISet> _16___v7; RAST._IExpr _out5; Defs._IOwnership _out6; Dafny.ISet> _out7; - (this).GenExpr(_11_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); - _12_eStr = _out5; - _13___v6 = _out6; - _14___v7 = _out7; - _9_fnBody = (_9_fnBody).Apply1(_12_eStr); + (this).GenExpr(_13_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); + _14_r = _out5; + _15___v6 = _out6; + _16___v7 = _out7; + _11_fnBody = _14_r; } - goto after_match1; + goto after_match0; } } { { - _9_fnBody = (_9_fnBody).Apply1(RAST.__default.std__default__Default__default); + _11_fnBody = (RAST.Expr.create_Identifier(_8_newtypeName)).Apply1(RAST.__default.std__default__Default__default); } } - after_match1: ; - RAST._IImplMember _15_body; - _15_body = RAST.ImplMember.create_FnDecl(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), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_9_fnBody))); - Std.Wrappers._IOption _source2 = (c).dtor_constraint; + after_match0: ; + RAST._IImplMember _17_body; + _17_body = RAST.ImplMember.create_FnDecl(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), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_11_fnBody))); + Std.Wrappers._IOption _source1 = (c).dtor_constraint; { - if (_source2.is_None) { - goto after_match2; + if (_source1.is_None) { + goto after_match1; } } { - DAST._INewtypeConstraint value0 = _source2.dtor_value; - DAST._IFormal _16_formal = value0.dtor_variable; - Dafny.ISequence _17_constraintStmts = value0.dtor_constraintStmts; - RAST._IExpr _18_rStmts; - Dafny.ISet> _19___v8; - Defs._IEnvironment _20_newEnv; + DAST._INewtypeConstraint value0 = _source1.dtor_value; + DAST._IFormal _18_formal = value0.dtor_variable; + Dafny.ISequence _19_constraintStmts = value0.dtor_constraintStmts; + RAST._IExpr _20_rStmts; + Dafny.ISet> _21___v8; + Defs._IEnvironment _22_newEnv; RAST._IExpr _out8; Dafny.ISet> _out9; Defs._IEnvironment _out10; - (this).GenStmts(_17_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out8, out _out9, out _out10); - _18_rStmts = _out8; - _19___v8 = _out9; - _20_newEnv = _out10; - Dafny.ISequence _21_rFormals; + (this).GenStmts(_19_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out8, out _out9, out _out10); + _20_rStmts = _out8; + _21___v8 = _out9; + _22_newEnv = _out10; + Dafny.ISequence _23_rFormals; Dafny.ISequence _out11; - _out11 = (this).GenParams(Dafny.Sequence.FromElements(_16_formal), false); - _21_rFormals = _out11; - 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(_8_newtypeName), _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _21_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_18_rStmts)))))))); - } - after_match2: ; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_8_newtypeName), _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(_15_body))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_8_newtypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(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()), Dafny.Sequence.UnicodeFromString(""), 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.RawType(Dafny.Sequence.UnicodeFromString("::std::ops::Deref")), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_8_newtypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_RawImplMember(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("type Target = "), (_5_underlyingType)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(";"))), RAST.ImplMember.create_FnDecl(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())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); + _out11 = (this).GenParams(Dafny.Sequence.FromElements(_18_formal), false); + _23_rFormals = _out11; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _9_resultingType, _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _23_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_20_rStmts)))))))); + } + after_match1: ; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _9_resultingType, _3_whereConstraints, Dafny.Sequence.FromElements(_17_body))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _9_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(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()), Dafny.Sequence.UnicodeFromString(""), 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(), _9_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _5_wrappedType), RAST.ImplMember.create_FnDecl(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())), Dafny.Sequence.UnicodeFromString(""), 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, _9_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(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(_5_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Dafny.Sequence.UnicodeFromString(""), 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 _24_rTypeParamsDeclsWithHash; + _24_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_24_rTypeParamsDeclsWithHash, _9_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, _9_resultingType, _8_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('-'), _2_rTypeParamsDecls, _9_resultingType, _8_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('*'), _2_rTypeParamsDecls, _9_resultingType, _8_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('/'), _2_rTypeParamsDecls, _9_resultingType, _8_newtypeName), Defs.__default.PartialOrdImpl(_2_rTypeParamsDecls, _9_resultingType, _8_newtypeName))); + } + if (((c).dtor_range).is_Bool) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.UnaryOpsImpl(new Dafny.Rune('!'), _2_rTypeParamsDecls, _9_resultingType, _8_newtypeName))); + } + Dafny.ISequence _25_implementation; + Dafny.IMap>,Dafny.ISequence> _26_traitBodies; + Dafny.ISequence _out12; + Dafny.IMap>,Dafny.ISequence> _out13; + (this).GenClassImplBody((c).dtor_classItems, false, _7_newtypeType, _0_typeParamsSeq, out _out12, out _out13); + _25_implementation = _out12; + _26_traitBodies = _out13; + if ((new BigInteger((_26_traitBodies).Count)).Sign == 1) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("No support for trait in newtypes yet")); + } + if ((new BigInteger((_25_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(_8_newtypeName), _1_rTypeParams), _3_whereConstraints, _25_implementation)))); + } return s; } public Dafny.ISequence GenSynonymType(DAST._ISynonymType c) @@ -1141,7 +1182,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) 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(_4_datatypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements())))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_95_rTypeParamsDeclsWithHash, RAST.__default.Hash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(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(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_97_hashImplBody)))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_95_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams), _97_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { RAST._IExpr _101_structName; _101_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); @@ -1260,7 +1301,11 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) Dafny.ISequence _out1; _out1 = (this).GenTypeArgs((_0_resolved).dtor_typeArgs, false); _2_typeArgs = _out1; - s = RAST.Type.create_TypeApp(_1_t, _2_typeArgs); + if ((new BigInteger((_2_typeArgs).Count)).Sign == 1) { + s = RAST.Type.create_TypeApp(_1_t, _2_typeArgs); + } else { + s = _1_t; + } DAST._IResolvedTypeBase _source1 = (_0_resolved).dtor_kind; { if (_source1.is_Class) { @@ -1294,27 +1339,37 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) } } { - DAST._IType _3_base = _source1.dtor_baseType; - DAST._INewtypeRange _4_range = _source1.dtor_range; - bool _5_erased = _source1.dtor_erase; + if (_source1.is_SynonymType) { + DAST._IType _3_base = _source1.dtor_baseType; + { + RAST._IType _4_underlying; + RAST._IType _out2; + _out2 = (this).GenType(_3_base, Defs.GenTypeContext.@default()); + _4_underlying = _out2; + s = RAST.Type.create_TSynonym(s, _4_underlying); + } + goto after_match1; + } + } + { + DAST._IType _5_base = _source1.dtor_baseType; + DAST._INewtypeRange _6_range = _source1.dtor_range; + bool _7_erased = _source1.dtor_erase; { - if (_5_erased) { - Std.Wrappers._IOption _source2 = Defs.__default.NewtypeRangeToRustType(_4_range); - { - if (_source2.is_Some) { - RAST._IType _6_v = _source2.dtor_value; - s = _6_v; - goto after_match2; - } - } - { - RAST._IType _7_underlying; - RAST._IType _out2; - _out2 = (this).GenType(_3_base, Defs.GenTypeContext.@default()); - _7_underlying = _out2; - s = RAST.Type.create_TSynonym(s, _7_underlying); + if (_7_erased) { + Std.Wrappers._IOption _8_unwrappedType; + _8_unwrappedType = Defs.__default.NewtypeRangeToUnwrappedBoundedRustType(_5_base, _6_range); + if ((_8_unwrappedType).is_Some) { + s = (_8_unwrappedType).dtor_value; + } else { + RAST._IType _9_unwrappedType; + RAST._IType _out3; + _out3 = (this).GenType(_5_base, Defs.GenTypeContext.@default()); + _9_unwrappedType = _out3; + s = _9_unwrappedType; } - after_match2: ; + } else if (Defs.__default.IsNewtypeCopy(_6_range)) { + s = RAST.Type.create_TMetaData(s, true, (_6_range).CanOverflow()); } } } @@ -1336,24 +1391,24 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) } { if (_source0.is_Tuple) { - Dafny.ISequence _8_types = _source0.dtor_Tuple_a0; + Dafny.ISequence _10_types = _source0.dtor_Tuple_a0; { - Dafny.ISequence _9_args; - _9_args = Dafny.Sequence.FromElements(); - BigInteger _10_i; - _10_i = BigInteger.Zero; - while ((_10_i) < (new BigInteger((_8_types).Count))) { - RAST._IType _11_generated; - RAST._IType _out3; - _out3 = (this).GenType((_8_types).Select(_10_i), false); - _11_generated = _out3; - _9_args = Dafny.Sequence.Concat(_9_args, Dafny.Sequence.FromElements(_11_generated)); - _10_i = (_10_i) + (BigInteger.One); - } - if ((new BigInteger((_8_types).Count)) <= (RAST.__default.MAX__TUPLE__SIZE)) { - s = RAST.Type.create_TupleType(_9_args); + Dafny.ISequence _11_args; + _11_args = Dafny.Sequence.FromElements(); + BigInteger _12_i; + _12_i = BigInteger.Zero; + while ((_12_i) < (new BigInteger((_10_types).Count))) { + RAST._IType _13_generated; + RAST._IType _out4; + _out4 = (this).GenType((_10_types).Select(_12_i), false); + _13_generated = _out4; + _11_args = Dafny.Sequence.Concat(_11_args, Dafny.Sequence.FromElements(_13_generated)); + _12_i = (_12_i) + (BigInteger.One); + } + if ((new BigInteger((_10_types).Count)) <= (RAST.__default.MAX__TUPLE__SIZE)) { + s = RAST.Type.create_TupleType(_11_args); } else { - s = RAST.__default.SystemTupleType(_9_args); + s = RAST.__default.SystemTupleType(_11_args); } } goto after_match0; @@ -1361,23 +1416,23 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) } { if (_source0.is_Array) { - DAST._IType _12_element = _source0.dtor_element; - BigInteger _13_dims = _source0.dtor_dims; + DAST._IType _14_element = _source0.dtor_element; + BigInteger _15_dims = _source0.dtor_dims; { - if ((_13_dims) > (new BigInteger(16))) { + if ((_15_dims) > (new BigInteger(16))) { s = RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("Array of dimensions greater than 16")); } else { - RAST._IType _14_elem; - RAST._IType _out4; - _out4 = (this).GenType(_12_element, false); - _14_elem = _out4; - if ((_13_dims) == (BigInteger.One)) { - s = RAST.Type.create_Array(_14_elem, Std.Wrappers.Option>.create_None()); + RAST._IType _16_elem; + RAST._IType _out5; + _out5 = (this).GenType(_14_element, false); + _16_elem = _out5; + if ((_15_dims) == (BigInteger.One)) { + s = RAST.Type.create_Array(_16_elem, Std.Wrappers.Option>.create_None()); s = (this).Object(s); } else { - Dafny.ISequence _15_n; - _15_n = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array"), Std.Strings.__default.OfNat(_13_dims)); - s = (((RAST.__default.dafny__runtime).MSel(_15_n)).AsType()).Apply(Dafny.Sequence.FromElements(_14_elem)); + Dafny.ISequence _17_n; + _17_n = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array"), Std.Strings.__default.OfNat(_15_dims)); + s = (((RAST.__default.dafny__runtime).MSel(_17_n)).AsType()).Apply(Dafny.Sequence.FromElements(_16_elem)); s = (this).Object(s); } } @@ -1387,114 +1442,114 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) } { if (_source0.is_Seq) { - DAST._IType _16_element = _source0.dtor_element; - { - RAST._IType _17_elem; - RAST._IType _out5; - _out5 = (this).GenType(_16_element, false); - _17_elem = _out5; - s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Sequence"))).AsType(), Dafny.Sequence.FromElements(_17_elem)); - } - goto after_match0; - } - } - { - if (_source0.is_Set) { DAST._IType _18_element = _source0.dtor_element; { RAST._IType _19_elem; RAST._IType _out6; _out6 = (this).GenType(_18_element, false); _19_elem = _out6; - s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Set"))).AsType(), Dafny.Sequence.FromElements(_19_elem)); + s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Sequence"))).AsType(), Dafny.Sequence.FromElements(_19_elem)); } goto after_match0; } } { - if (_source0.is_Multiset) { + if (_source0.is_Set) { DAST._IType _20_element = _source0.dtor_element; { RAST._IType _21_elem; RAST._IType _out7; _out7 = (this).GenType(_20_element, false); _21_elem = _out7; - s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Multiset"))).AsType(), Dafny.Sequence.FromElements(_21_elem)); + s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Set"))).AsType(), Dafny.Sequence.FromElements(_21_elem)); } goto after_match0; } } { - if (_source0.is_Map) { - DAST._IType _22_key = _source0.dtor_key; - DAST._IType _23_value = _source0.dtor_value; + if (_source0.is_Multiset) { + DAST._IType _22_element = _source0.dtor_element; { - RAST._IType _24_keyType; + RAST._IType _23_elem; RAST._IType _out8; - _out8 = (this).GenType(_22_key, false); - _24_keyType = _out8; - RAST._IType _25_valueType; + _out8 = (this).GenType(_22_element, false); + _23_elem = _out8; + s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Multiset"))).AsType(), Dafny.Sequence.FromElements(_23_elem)); + } + goto after_match0; + } + } + { + if (_source0.is_Map) { + DAST._IType _24_key = _source0.dtor_key; + DAST._IType _25_value = _source0.dtor_value; + { + RAST._IType _26_keyType; RAST._IType _out9; - _out9 = (this).GenType(_23_value, genTypeContext); - _25_valueType = _out9; - s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Map"))).AsType(), Dafny.Sequence.FromElements(_24_keyType, _25_valueType)); + _out9 = (this).GenType(_24_key, false); + _26_keyType = _out9; + RAST._IType _27_valueType; + RAST._IType _out10; + _out10 = (this).GenType(_25_value, genTypeContext); + _27_valueType = _out10; + s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Map"))).AsType(), Dafny.Sequence.FromElements(_26_keyType, _27_valueType)); } goto after_match0; } } { if (_source0.is_MapBuilder) { - DAST._IType _26_key = _source0.dtor_key; - DAST._IType _27_value = _source0.dtor_value; + DAST._IType _28_key = _source0.dtor_key; + DAST._IType _29_value = _source0.dtor_value; { - RAST._IType _28_keyType; - RAST._IType _out10; - _out10 = (this).GenType(_26_key, false); - _28_keyType = _out10; - RAST._IType _29_valueType; + RAST._IType _30_keyType; RAST._IType _out11; - _out11 = (this).GenType(_27_value, genTypeContext); - _29_valueType = _out11; - s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsType(), Dafny.Sequence.FromElements(_28_keyType, _29_valueType)); + _out11 = (this).GenType(_28_key, false); + _30_keyType = _out11; + RAST._IType _31_valueType; + RAST._IType _out12; + _out12 = (this).GenType(_29_value, genTypeContext); + _31_valueType = _out12; + s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsType(), Dafny.Sequence.FromElements(_30_keyType, _31_valueType)); } goto after_match0; } } { if (_source0.is_SetBuilder) { - DAST._IType _30_elem = _source0.dtor_element; + DAST._IType _32_elem = _source0.dtor_element; { - RAST._IType _31_elemType; - RAST._IType _out12; - _out12 = (this).GenType(_30_elem, false); - _31_elemType = _out12; - s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsType(), Dafny.Sequence.FromElements(_31_elemType)); + RAST._IType _33_elemType; + RAST._IType _out13; + _out13 = (this).GenType(_32_elem, false); + _33_elemType = _out13; + s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsType(), Dafny.Sequence.FromElements(_33_elemType)); } goto after_match0; } } { if (_source0.is_Arrow) { - Dafny.ISequence _32_args = _source0.dtor_args; - DAST._IType _33_result = _source0.dtor_result; + Dafny.ISequence _34_args = _source0.dtor_args; + DAST._IType _35_result = _source0.dtor_result; { - Dafny.ISequence _34_argTypes; - _34_argTypes = Dafny.Sequence.FromElements(); - BigInteger _35_i; - _35_i = BigInteger.Zero; - while ((_35_i) < (new BigInteger((_32_args).Count))) { - RAST._IType _36_generated; - RAST._IType _out13; - _out13 = (this).GenType((_32_args).Select(_35_i), false); - _36_generated = _out13; - _34_argTypes = Dafny.Sequence.Concat(_34_argTypes, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(_36_generated))); - _35_i = (_35_i) + (BigInteger.One); - } - RAST._IType _37_resultType; - RAST._IType _out14; - _out14 = (this).GenType(_33_result, Defs.GenTypeContext.@default()); - _37_resultType = _out14; - s = RAST.__default.Rc(RAST.Type.create_DynType(RAST.Type.create_FnType(_34_argTypes, _37_resultType))); + Dafny.ISequence _36_argTypes; + _36_argTypes = Dafny.Sequence.FromElements(); + BigInteger _37_i; + _37_i = BigInteger.Zero; + while ((_37_i) < (new BigInteger((_34_args).Count))) { + RAST._IType _38_generated; + RAST._IType _out14; + _out14 = (this).GenType((_34_args).Select(_37_i), false); + _38_generated = _out14; + _36_argTypes = Dafny.Sequence.Concat(_36_argTypes, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(_38_generated))); + _37_i = (_37_i) + (BigInteger.One); + } + RAST._IType _39_resultType; + RAST._IType _out15; + _out15 = (this).GenType(_35_result, Defs.GenTypeContext.@default()); + _39_resultType = _out15; + s = RAST.__default.Rc(RAST.Type.create_DynType(RAST.Type.create_FnType(_36_argTypes, _39_resultType))); } goto after_match0; } @@ -1502,57 +1557,57 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) { if (_source0.is_TypeArg) { Dafny.ISequence _h90 = _source0.dtor_TypeArg_a0; - Dafny.ISequence _38_name = _h90; - s = RAST.Type.create_TIdentifier(Defs.__default.escapeName(_38_name)); + Dafny.ISequence _40_name = _h90; + s = RAST.Type.create_TIdentifier(Defs.__default.escapeName(_40_name)); goto after_match0; } } { if (_source0.is_Primitive) { - DAST._IPrimitive _39_p = _source0.dtor_Primitive_a0; + DAST._IPrimitive _41_p = _source0.dtor_Primitive_a0; { - DAST._IPrimitive _source3 = _39_p; + DAST._IPrimitive _source2 = _41_p; { - if (_source3.is_Int) { + if (_source2.is_Int) { s = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt"))).AsType(); - goto after_match3; + goto after_match2; } } { - if (_source3.is_Real) { + if (_source2.is_Real) { s = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("BigRational"))).AsType(); - goto after_match3; + goto after_match2; } } { - if (_source3.is_String) { + if (_source2.is_String) { s = RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Sequence"))).AsType(), Dafny.Sequence.FromElements(((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsType())); - goto after_match3; + goto after_match2; } } { - if (_source3.is_Native) { + if (_source2.is_Native) { s = RAST.Type.create_USIZE(); - goto after_match3; + goto after_match2; } } { - if (_source3.is_Bool) { + if (_source2.is_Bool) { s = RAST.Type.create_Bool(); - goto after_match3; + goto after_match2; } } { s = ((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsType(); } - after_match3: ; + after_match2: ; } goto after_match0; } } { - Dafny.ISequence _40_v = _source0.dtor_Passthrough_a0; - s = RAST.__default.RawType(_40_v); + Dafny.ISequence _42_v = _source0.dtor_Passthrough_a0; + s = RAST.__default.RawType(_42_v); } after_match0: ; return s; @@ -1694,115 +1749,123 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e } 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(RAST.__default.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))) { + _15_tpe = RAST.Type.create_TMetaData(RAST.__default.SelfOwned, true, ((((enclosingType).dtor_resolved).dtor_kind).dtor_range).CanOverflow()); } else { - _15_tpe = RAST.Type.create_Borrowed(RAST.__default.SelfOwned); + _15_tpe = RAST.__default.SelfBorrowed; } } } - _0_params = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.Formal.create(_9_selfId, _15_tpe)), _0_params); + RAST._IFormal _16_formal; + _16_formal = RAST.Formal.create(_9_selfId, _15_tpe); + _0_params = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_16_formal), _0_params); + Dafny.ISequence _17_name; + _17_name = (_16_formal).dtor_name; + _1_paramNames = Dafny.Sequence>.Concat(Dafny.Sequence>.FromElements(_17_name), _1_paramNames); + _2_paramTypes = Dafny.Map, RAST._IType>.Update(_2_paramTypes, _17_name, (_16_formal).dtor_tpe); } _8_selfIdent = Defs.SelfInfo.create_ThisTyped(_9_selfId, _10_instanceType); } - Dafny.ISequence _16_retTypeArgs; - _16_retTypeArgs = Dafny.Sequence.FromElements(); - BigInteger _17_typeI; - _17_typeI = BigInteger.Zero; - while ((_17_typeI) < (new BigInteger(((m).dtor_outTypes).Count))) { - RAST._IType _18_typeExpr; + Dafny.ISequence _18_retTypeArgs; + _18_retTypeArgs = Dafny.Sequence.FromElements(); + BigInteger _19_typeI; + _19_typeI = BigInteger.Zero; + while ((_19_typeI) < (new BigInteger(((m).dtor_outTypes).Count))) { + RAST._IType _20_typeExpr; RAST._IType _out2; - _out2 = (this).GenType(((m).dtor_outTypes).Select(_17_typeI), Defs.GenTypeContext.@default()); - _18_typeExpr = _out2; - _16_retTypeArgs = Dafny.Sequence.Concat(_16_retTypeArgs, Dafny.Sequence.FromElements(_18_typeExpr)); - _17_typeI = (_17_typeI) + (BigInteger.One); + _out2 = (this).GenType(((m).dtor_outTypes).Select(_19_typeI), Defs.GenTypeContext.@default()); + _20_typeExpr = _out2; + _18_retTypeArgs = Dafny.Sequence.Concat(_18_retTypeArgs, Dafny.Sequence.FromElements(_20_typeExpr)); + _19_typeI = (_19_typeI) + (BigInteger.One); } - RAST._IVisibility _19_visibility; + RAST._IVisibility _21_visibility; if (forTrait) { - _19_visibility = RAST.Visibility.create_PRIV(); + _21_visibility = RAST.Visibility.create_PRIV(); } else { - _19_visibility = RAST.Visibility.create_PUB(); + _21_visibility = RAST.Visibility.create_PUB(); } - Dafny.ISequence _20_typeParamsFiltered; - _20_typeParamsFiltered = Dafny.Sequence.FromElements(); + Dafny.ISequence _22_typeParamsFiltered; + _22_typeParamsFiltered = Dafny.Sequence.FromElements(); BigInteger _hi1 = new BigInteger(((m).dtor_typeParams).Count); - for (BigInteger _21_typeParamI = BigInteger.Zero; _21_typeParamI < _hi1; _21_typeParamI++) { - DAST._ITypeArgDecl _22_typeParam; - _22_typeParam = ((m).dtor_typeParams).Select(_21_typeParamI); - if (!((enclosingTypeParams).Contains(DAST.Type.create_TypeArg((_22_typeParam).dtor_name)))) { - _20_typeParamsFiltered = Dafny.Sequence.Concat(_20_typeParamsFiltered, Dafny.Sequence.FromElements(_22_typeParam)); - } - } - Dafny.ISequence _23_typeParams; - _23_typeParams = Dafny.Sequence.FromElements(); - if ((new BigInteger((_20_typeParamsFiltered).Count)).Sign == 1) { - BigInteger _hi2 = new BigInteger((_20_typeParamsFiltered).Count); - for (BigInteger _24_i = BigInteger.Zero; _24_i < _hi2; _24_i++) { - DAST._IType _25_typeArg; - RAST._ITypeParamDecl _26_rTypeParamDecl; + for (BigInteger _23_typeParamI = BigInteger.Zero; _23_typeParamI < _hi1; _23_typeParamI++) { + DAST._ITypeArgDecl _24_typeParam; + _24_typeParam = ((m).dtor_typeParams).Select(_23_typeParamI); + if (!((enclosingTypeParams).Contains(DAST.Type.create_TypeArg((_24_typeParam).dtor_name)))) { + _22_typeParamsFiltered = Dafny.Sequence.Concat(_22_typeParamsFiltered, Dafny.Sequence.FromElements(_24_typeParam)); + } + } + Dafny.ISequence _25_typeParams; + _25_typeParams = Dafny.Sequence.FromElements(); + if ((new BigInteger((_22_typeParamsFiltered).Count)).Sign == 1) { + BigInteger _hi2 = new BigInteger((_22_typeParamsFiltered).Count); + for (BigInteger _26_i = BigInteger.Zero; _26_i < _hi2; _26_i++) { + DAST._IType _27_typeArg; + RAST._ITypeParamDecl _28_rTypeParamDecl; DAST._IType _out3; RAST._ITypeParamDecl _out4; - (this).GenTypeParam((_20_typeParamsFiltered).Select(_24_i), out _out3, out _out4); - _25_typeArg = _out3; - _26_rTypeParamDecl = _out4; - RAST._ITypeParamDecl _27_dt__update__tmp_h1 = _26_rTypeParamDecl; - Dafny.ISequence _28_dt__update_hconstraints_h0 = (_26_rTypeParamDecl).dtor_constraints; - _26_rTypeParamDecl = RAST.TypeParamDecl.create((_27_dt__update__tmp_h1).dtor_name, _28_dt__update_hconstraints_h0); - _23_typeParams = Dafny.Sequence.Concat(_23_typeParams, Dafny.Sequence.FromElements(_26_rTypeParamDecl)); - } - } - Std.Wrappers._IOption _29_fBody = Std.Wrappers.Option.Default(); - Defs._IEnvironment _30_env = Defs.Environment.Default(); - RAST._IExpr _31_preBody; - _31_preBody = (this).InitEmptyExpr(); - Dafny.ISequence> _32_preAssignNames; - _32_preAssignNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _33_preAssignTypes; - _33_preAssignTypes = Dafny.Map, RAST._IType>.FromElements(); + (this).GenTypeParam((_22_typeParamsFiltered).Select(_26_i), out _out3, out _out4); + _27_typeArg = _out3; + _28_rTypeParamDecl = _out4; + RAST._ITypeParamDecl _29_dt__update__tmp_h1 = _28_rTypeParamDecl; + Dafny.ISequence _30_dt__update_hconstraints_h0 = (_28_rTypeParamDecl).dtor_constraints; + _28_rTypeParamDecl = RAST.TypeParamDecl.create((_29_dt__update__tmp_h1).dtor_name, _30_dt__update_hconstraints_h0); + _25_typeParams = Dafny.Sequence.Concat(_25_typeParams, Dafny.Sequence.FromElements(_28_rTypeParamDecl)); + } + } + Std.Wrappers._IOption _31_fBody = Std.Wrappers.Option.Default(); + Defs._IEnvironment _32_env = Defs.Environment.Default(); + RAST._IExpr _33_preBody; + _33_preBody = (this).InitEmptyExpr(); + Dafny.ISequence> _34_preAssignNames; + _34_preAssignNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _35_preAssignTypes; + _35_preAssignTypes = Dafny.Map, RAST._IType>.FromElements(); if ((m).dtor_hasBody) { - Std.Wrappers._IOption>> _34_earlyReturn; - _34_earlyReturn = Std.Wrappers.Option>>.create_None(); + Std.Wrappers._IOption>> _36_earlyReturn; + _36_earlyReturn = Std.Wrappers.Option>>.create_None(); Std.Wrappers._IOption>> _source1 = (m).dtor_outVars; { if (_source1.is_Some) { - Dafny.ISequence> _35_outVars = _source1.dtor_value; + Dafny.ISequence> _37_outVars = _source1.dtor_value; { if ((m).dtor_outVarsAreUninitFieldsToAssign) { - _34_earlyReturn = Std.Wrappers.Option>>.create_Some(Dafny.Sequence>.FromElements()); - BigInteger _hi3 = new BigInteger((_35_outVars).Count); - for (BigInteger _36_outI = BigInteger.Zero; _36_outI < _hi3; _36_outI++) { - Dafny.ISequence _37_outVar; - _37_outVar = (_35_outVars).Select(_36_outI); - Dafny.ISequence _38_outName; - _38_outName = Defs.__default.escapeVar(_37_outVar); - Dafny.ISequence _39_tracker__name; - _39_tracker__name = Defs.__default.AddAssignedPrefix(_38_outName); - _32_preAssignNames = Dafny.Sequence>.Concat(_32_preAssignNames, Dafny.Sequence>.FromElements(_39_tracker__name)); - _33_preAssignTypes = Dafny.Map, RAST._IType>.Update(_33_preAssignTypes, _39_tracker__name, RAST.Type.create_Bool()); - _31_preBody = (_31_preBody).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _39_tracker__name, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(RAST.Expr.create_LiteralBool(false)))); + _36_earlyReturn = Std.Wrappers.Option>>.create_Some(Dafny.Sequence>.FromElements()); + BigInteger _hi3 = new BigInteger((_37_outVars).Count); + for (BigInteger _38_outI = BigInteger.Zero; _38_outI < _hi3; _38_outI++) { + Dafny.ISequence _39_outVar; + _39_outVar = (_37_outVars).Select(_38_outI); + Dafny.ISequence _40_outName; + _40_outName = Defs.__default.escapeVar(_39_outVar); + Dafny.ISequence _41_tracker__name; + _41_tracker__name = Defs.__default.AddAssignedPrefix(_40_outName); + _34_preAssignNames = Dafny.Sequence>.Concat(_34_preAssignNames, Dafny.Sequence>.FromElements(_41_tracker__name)); + _35_preAssignTypes = Dafny.Map, RAST._IType>.Update(_35_preAssignTypes, _41_tracker__name, RAST.Type.create_Bool()); + _33_preBody = (_33_preBody).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _41_tracker__name, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(RAST.Expr.create_LiteralBool(false)))); } } else { - Dafny.ISequence> _40_tupleArgs; - _40_tupleArgs = Dafny.Sequence>.FromElements(); - BigInteger _hi4 = new BigInteger((_35_outVars).Count); - for (BigInteger _41_outI = BigInteger.Zero; _41_outI < _hi4; _41_outI++) { - Dafny.ISequence _42_outVar; - _42_outVar = (_35_outVars).Select(_41_outI); - RAST._IType _43_outType; + Dafny.ISequence> _42_tupleArgs; + _42_tupleArgs = Dafny.Sequence>.FromElements(); + BigInteger _hi4 = new BigInteger((_37_outVars).Count); + for (BigInteger _43_outI = BigInteger.Zero; _43_outI < _hi4; _43_outI++) { + Dafny.ISequence _44_outVar; + _44_outVar = (_37_outVars).Select(_43_outI); + RAST._IType _45_outType; RAST._IType _out5; - _out5 = (this).GenType(((m).dtor_outTypes).Select(_41_outI), Defs.GenTypeContext.@default()); - _43_outType = _out5; - Dafny.ISequence _44_outName; - _44_outName = Defs.__default.escapeVar(_42_outVar); - _1_paramNames = Dafny.Sequence>.Concat(_1_paramNames, Dafny.Sequence>.FromElements(_44_outName)); - RAST._IType _45_outMaybeType; - if ((_43_outType).CanReadWithoutClone()) { - _45_outMaybeType = _43_outType; + _out5 = (this).GenType(((m).dtor_outTypes).Select(_43_outI), Defs.GenTypeContext.@default()); + _45_outType = _out5; + Dafny.ISequence _46_outName; + _46_outName = Defs.__default.escapeVar(_44_outVar); + _1_paramNames = Dafny.Sequence>.Concat(_1_paramNames, Dafny.Sequence>.FromElements(_46_outName)); + RAST._IType _47_outMaybeType; + if ((_45_outType).CanReadWithoutClone()) { + _47_outMaybeType = _45_outType; } else { - _45_outMaybeType = RAST.__default.MaybePlaceboType(_43_outType); + _47_outMaybeType = RAST.__default.MaybePlaceboType(_45_outType); } - _2_paramTypes = Dafny.Map, RAST._IType>.Update(_2_paramTypes, _44_outName, _45_outMaybeType); - _40_tupleArgs = Dafny.Sequence>.Concat(_40_tupleArgs, Dafny.Sequence>.FromElements(_44_outName)); + _2_paramTypes = Dafny.Map, RAST._IType>.Update(_2_paramTypes, _46_outName, _47_outMaybeType); + _42_tupleArgs = Dafny.Sequence>.Concat(_42_tupleArgs, Dafny.Sequence>.FromElements(_46_outName)); } - _34_earlyReturn = Std.Wrappers.Option>>.create_Some(_40_tupleArgs); + _36_earlyReturn = Std.Wrappers.Option>>.create_Some(_42_tupleArgs); } } goto after_match1; @@ -1811,23 +1874,23 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e { } after_match1: ; - _30_env = Defs.Environment.create(Dafny.Sequence>.Concat(_32_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_33_preAssignTypes, _2_paramTypes)); - RAST._IExpr _46_body; - Dafny.ISet> _47___v20; - Defs._IEnvironment _48___v21; + _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes)); + RAST._IExpr _48_body; + Dafny.ISet> _49___v20; + Defs._IEnvironment _50___v21; RAST._IExpr _out6; Dafny.ISet> _out7; Defs._IEnvironment _out8; - (this).GenStmts((m).dtor_body, _8_selfIdent, _30_env, true, _34_earlyReturn, out _out6, out _out7, out _out8); - _46_body = _out6; - _47___v20 = _out7; - _48___v21 = _out8; - _29_fBody = Std.Wrappers.Option.create_Some((_31_preBody).Then(_46_body)); + (this).GenStmts((m).dtor_body, _8_selfIdent, _32_env, true, _36_earlyReturn, out _out6, out _out7, out _out8); + _48_body = _out6; + _49___v20 = _out7; + _50___v21 = _out8; + _31_fBody = Std.Wrappers.Option.create_Some((_33_preBody).Then(_48_body)); } else { - _30_env = Defs.Environment.create(_1_paramNames, _2_paramTypes); - _29_fBody = Std.Wrappers.Option.create_None(); + _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes); + _31_fBody = Std.Wrappers.Option.create_None(); } - s = RAST.ImplMember.create_FnDecl(_19_visibility, RAST.Fn.create(_7_fnName, _23_typeParams, _0_params, Std.Wrappers.Option.create_Some((((new BigInteger((_16_retTypeArgs).Count)) == (BigInteger.One)) ? ((_16_retTypeArgs).Select(BigInteger.Zero)) : (RAST.Type.create_TupleType(_16_retTypeArgs)))), Dafny.Sequence.UnicodeFromString(""), _29_fBody)); + s = RAST.ImplMember.create_FnDecl(_21_visibility, RAST.Fn.create(_7_fnName, _25_typeParams, _0_params, Std.Wrappers.Option.create_Some((((new BigInteger((_18_retTypeArgs).Count)) == (BigInteger.One)) ? ((_18_retTypeArgs).Select(BigInteger.Zero)) : (RAST.Type.create_TupleType(_18_retTypeArgs)))), Dafny.Sequence.UnicodeFromString(""), _31_fBody)); return s; } public void GenStmts(Dafny.ISequence stmts, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, bool isLast, Std.Wrappers._IOption>> earlyReturn, out RAST._IExpr generated, out Dafny.ISet> readIdents, out Defs._IEnvironment newEnv) @@ -2427,64 +2490,72 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _75_body = _source0.dtor_body; { generated = (this).InitEmptyExpr(); + Defs._IEnvironment _76_oldEnv; + _76_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { - RAST._IExpr _76_selfClone; - Defs._IOwnership _77___v37; - Dafny.ISet> _78___v38; + RAST._IExpr _77_selfClone; + Defs._IOwnership _78___v37; + Dafny.ISet> _79___v38; RAST._IExpr _out43; Defs._IOwnership _out44; Dafny.ISet> _out45; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out43, out _out44, out _out45); - _76_selfClone = _out43; - _77___v37 = _out44; - _78___v38 = _out45; - 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))); + _77_selfClone = _out43; + _78___v37 = _out44; + _79___v38 = _out45; + 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(_77_selfClone))); + if (((_76_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { + _76_oldEnv = (_76_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); + } } + RAST._IExpr _80_loopBegin; + _80_loopBegin = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); newEnv = env; - RAST._IExpr _79_loopBegin; - _79_loopBegin = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); - BigInteger _hi1 = new BigInteger(((env).dtor_names).Count); - for (BigInteger _80_paramI = BigInteger.Zero; _80_paramI < _hi1; _80_paramI++) { - Dafny.ISequence _81_param; - _81_param = ((env).dtor_names).Select(_80_paramI); - if ((_81_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { + BigInteger _hi1 = new BigInteger(((_76_oldEnv).dtor_names).Count); + for (BigInteger _81_paramI = BigInteger.Zero; _81_paramI < _hi1; _81_paramI++) { + Dafny.ISequence _82_param; + _82_param = ((_76_oldEnv).dtor_names).Select(_81_paramI); + if ((_82_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { goto continue_4_0; } - RAST._IExpr _82_paramInit; - Defs._IOwnership _83___v39; - Dafny.ISet> _84___v40; + if ((((_76_oldEnv).dtor_types).Contains(_82_param)) && (((Dafny.Map, RAST._IType>.Select((_76_oldEnv).dtor_types,_82_param)).ExtractMaybePlacebo()).is_Some)) { + goto continue_4_0; + } + RAST._IExpr _83_paramInit; + Defs._IOwnership _84___v39; + Dafny.ISet> _85___v40; RAST._IExpr _out46; Defs._IOwnership _out47; Dafny.ISet> _out48; - (this).GenIdent(_81_param, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out46, out _out47, out _out48); - _82_paramInit = _out46; - _83___v39 = _out47; - _84___v40 = _out48; - 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 (((env).dtor_types).Contains(_81_param)) { - RAST._IType _86_declaredType; - _86_declaredType = (Dafny.Map, RAST._IType>.Select((env).dtor_types,_81_param)).ToOwned(); - newEnv = (newEnv).AddAssigned(_81_param, _86_declaredType); - newEnv = (newEnv).AddAssigned(_85_recVar, _86_declaredType); + (this).GenIdent(_82_param, selfIdent, _76_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out46, out _out47, out _out48); + _83_paramInit = _out46; + _84___v39 = _out47; + _85___v40 = _out48; + Dafny.ISequence _86_recVar; + _86_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_81_paramI)); + generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _86_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_83_paramInit))); + if (((_76_oldEnv).dtor_types).Contains(_82_param)) { + RAST._IType _87_declaredType; + _87_declaredType = (Dafny.Map, RAST._IType>.Select((_76_oldEnv).dtor_types,_82_param)).ToOwned(); + newEnv = (newEnv).AddAssigned(_82_param, _87_declaredType); + newEnv = (newEnv).AddAssigned(_86_recVar, _87_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)))); + _80_loopBegin = (_80_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _82_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_86_recVar)))); continue_4_0: ; } after_4_0: ; - RAST._IExpr _87_bodyExpr; - Dafny.ISet> _88_bodyIdents; - Defs._IEnvironment _89_bodyEnv; + RAST._IExpr _88_bodyExpr; + Dafny.ISet> _89_bodyIdents; + Defs._IEnvironment _90_bodyEnv; RAST._IExpr _out49; Dafny.ISet> _out50; Defs._IEnvironment _out51; (this).GenStmts(_75_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 _out49, out _out50, out _out51); - _87_bodyExpr = _out49; - _88_bodyIdents = _out50; - _89_bodyEnv = _out51; - 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)))); + _88_bodyExpr = _out49; + _89_bodyIdents = _out50; + _90_bodyEnv = _out51; + readIdents = _89_bodyIdents; + generated = (generated).Then(RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), (_80_loopBegin).Then(_88_bodyExpr)))); } goto after_match0; } @@ -2501,83 +2572,83 @@ 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 _91_on = _source0.dtor_on; + DAST._ICallName _92_name = _source0.dtor_callName; + Dafny.ISequence _93_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _94_args = _source0.dtor_args; + Std.Wrappers._IOption>> _95_maybeOutVars = _source0.dtor_outs; { - Dafny.ISequence _95_argExprs; - Dafny.ISet> _96_recIdents; - Dafny.ISequence _97_typeExprs; - Std.Wrappers._IOption _98_fullNameQualifier; + Dafny.ISequence _96_argExprs; + Dafny.ISet> _97_recIdents; + Dafny.ISequence _98_typeExprs; + Std.Wrappers._IOption _99_fullNameQualifier; Dafny.ISequence _out52; Dafny.ISet> _out53; Dafny.ISequence _out54; Std.Wrappers._IOption _out55; - (this).GenArgs(selfIdent, _91_name, _92_typeArgs, _93_args, env, out _out52, out _out53, out _out54, out _out55); - _95_argExprs = _out52; - _96_recIdents = _out53; - _97_typeExprs = _out54; - _98_fullNameQualifier = _out55; - readIdents = _96_recIdents; - Std.Wrappers._IOption _source2 = _98_fullNameQualifier; + (this).GenArgs(selfIdent, _92_name, _93_typeArgs, _94_args, env, out _out52, out _out53, out _out54, out _out55); + _96_argExprs = _out52; + _97_recIdents = _out53; + _98_typeExprs = _out54; + _99_fullNameQualifier = _out55; + readIdents = _97_recIdents; + Std.Wrappers._IOption _source2 = _99_fullNameQualifier; { if (_source2.is_Some) { DAST._IResolvedType value0 = _source2.dtor_value; - Dafny.ISequence> _99_path = value0.dtor_path; - Dafny.ISequence _100_onTypeArgs = value0.dtor_typeArgs; - DAST._IResolvedTypeBase _101_base = value0.dtor_kind; - RAST._IExpr _102_fullPath; + Dafny.ISequence> _100_path = value0.dtor_path; + Dafny.ISequence _101_onTypeArgs = value0.dtor_typeArgs; + DAST._IResolvedTypeBase _102_base = value0.dtor_kind; + RAST._IExpr _103_fullPath; RAST._IExpr _out56; - _out56 = (this).GenPathExpr(_99_path, true); - _102_fullPath = _out56; - Dafny.ISequence _103_onTypeExprs; + _out56 = (this).GenPathExpr(_100_path, true); + _103_fullPath = _out56; + Dafny.ISequence _104_onTypeExprs; Dafny.ISequence _out57; - _out57 = (this).GenTypeArgs(_100_onTypeArgs, Defs.GenTypeContext.@default()); - _103_onTypeExprs = _out57; - RAST._IExpr _104_onExpr = RAST.Expr.Default(); - Defs._IOwnership _105_recOwnership = Defs.Ownership.Default(); - Dafny.ISet> _106_recIdents = Dafny.Set>.Empty; - if (((_101_base).is_Trait) || ((_101_base).is_Class)) { + _out57 = (this).GenTypeArgs(_101_onTypeArgs, Defs.GenTypeContext.@default()); + _104_onTypeExprs = _out57; + RAST._IExpr _105_onExpr = RAST.Expr.Default(); + Defs._IOwnership _106_recOwnership = Defs.Ownership.Default(); + Dafny.ISet> _107_recIdents = Dafny.Set>.Empty; + if (((_102_base).is_Trait) || ((_102_base).is_Class)) { RAST._IExpr _out58; Defs._IOwnership _out59; Dafny.ISet> _out60; - (this).GenExpr(_90_on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); - _104_onExpr = _out58; - _105_recOwnership = _out59; - _106_recIdents = _out60; - _104_onExpr = ((this).modify__macro).Apply1(_104_onExpr); - readIdents = Dafny.Set>.Union(readIdents, _106_recIdents); + (this).GenExpr(_91_on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); + _105_onExpr = _out58; + _106_recOwnership = _out59; + _107_recIdents = _out60; + _105_onExpr = ((this).modify__macro).Apply1(_105_onExpr); + readIdents = Dafny.Set>.Union(readIdents, _107_recIdents); } else { RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; - (this).GenExpr(_90_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out61, out _out62, out _out63); - _104_onExpr = _out61; - _105_recOwnership = _out62; - _106_recIdents = _out63; - readIdents = Dafny.Set>.Union(readIdents, _106_recIdents); + (this).GenExpr(_91_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out61, out _out62, out _out63); + _105_onExpr = _out61; + _106_recOwnership = _out62; + _107_recIdents = _out63; + readIdents = Dafny.Set>.Union(readIdents, _107_recIdents); } - generated = ((((_102_fullPath).ApplyType(_103_onTypeExprs)).FSel(Defs.__default.escapeName((_91_name).dtor_name))).ApplyType(_97_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_104_onExpr), _95_argExprs)); + generated = ((((_103_fullPath).ApplyType(_104_onTypeExprs)).FSel(Defs.__default.escapeName((_92_name).dtor_name))).ApplyType(_98_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_105_onExpr), _96_argExprs)); goto after_match2; } } { - RAST._IExpr _107_onExpr; - Defs._IOwnership _108___v45; - Dafny.ISet> _109_enclosingIdents; + RAST._IExpr _108_onExpr; + Defs._IOwnership _109___v45; + Dafny.ISet> _110_enclosingIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; - (this).GenExpr(_90_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out64, out _out65, out _out66); - _107_onExpr = _out64; - _108___v45 = _out65; - _109_enclosingIdents = _out66; - readIdents = Dafny.Set>.Union(readIdents, _109_enclosingIdents); - Dafny.ISequence _110_renderedName; - _110_renderedName = (this).GetMethodName(_90_on, _91_name); - DAST._IExpression _source3 = _90_on; + (this).GenExpr(_91_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out64, out _out65, out _out66); + _108_onExpr = _out64; + _109___v45 = _out65; + _110_enclosingIdents = _out66; + readIdents = Dafny.Set>.Union(readIdents, _110_enclosingIdents); + Dafny.ISequence _111_renderedName; + _111_renderedName = (this).GetMethodName(_91_on, _92_name); + DAST._IExpression _source3 = _91_on; { bool disjunctiveMatch0 = false; if (_source3.is_Companion) { @@ -2588,26 +2659,26 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } if (disjunctiveMatch0) { { - _107_onExpr = (_107_onExpr).FSel(_110_renderedName); + _108_onExpr = (_108_onExpr).FSel(_111_renderedName); } goto after_match3; } } { { - if (!object.Equals(_107_onExpr, RAST.__default.self)) { - DAST._ICallName _source4 = _91_name; + if (!object.Equals(_108_onExpr, RAST.__default.self)) { + DAST._ICallName _source4 = _92_name; { if (_source4.is_CallName) { Std.Wrappers._IOption onType0 = _source4.dtor_onType; if (onType0.is_Some) { - DAST._IType _111_tpe = onType0.dtor_value; - RAST._IType _112_typ; + DAST._IType _112_tpe = onType0.dtor_value; + RAST._IType _113_typ; RAST._IType _out67; - _out67 = (this).GenType(_111_tpe, Defs.GenTypeContext.@default()); - _112_typ = _out67; - if (((_112_typ).IsObjectOrPointer()) && (!object.Equals(_107_onExpr, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))))) { - _107_onExpr = ((this).read__macro).Apply1(_107_onExpr); + _out67 = (this).GenType(_112_tpe, Defs.GenTypeContext.@default()); + _113_typ = _out67; + if (((_113_typ).IsObjectOrPointer()) && (!object.Equals(_108_onExpr, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))))) { + _108_onExpr = ((this).read__macro).Apply1(_108_onExpr); } goto after_match4; } @@ -2617,39 +2688,39 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } after_match4: ; } - _107_onExpr = (_107_onExpr).Sel(_110_renderedName); + _108_onExpr = (_108_onExpr).Sel(_111_renderedName); } } after_match3: ; - generated = ((_107_onExpr).ApplyType(_97_typeExprs)).Apply(_95_argExprs); + generated = ((_108_onExpr).ApplyType(_98_typeExprs)).Apply(_96_argExprs); } after_match2: ; - if (((_94_maybeOutVars).is_Some) && ((new BigInteger(((_94_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { - Dafny.ISequence _113_outVar; - _113_outVar = Defs.__default.escapeVar(((_94_maybeOutVars).dtor_value).Select(BigInteger.Zero)); - if (!((env).CanReadWithoutClone(_113_outVar))) { + if (((_95_maybeOutVars).is_Some) && ((new BigInteger(((_95_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { + Dafny.ISequence _114_outVar; + _114_outVar = Defs.__default.escapeVar(((_95_maybeOutVars).dtor_value).Select(BigInteger.Zero)); + if (!((env).CanReadWithoutClone(_114_outVar))) { generated = RAST.__default.MaybePlacebo(generated); } - generated = RAST.__default.AssignVar(_113_outVar, generated); - } else if (((_94_maybeOutVars).is_None) || ((new BigInteger(((_94_maybeOutVars).dtor_value).Count)).Sign == 0)) { + generated = RAST.__default.AssignVar(_114_outVar, generated); + } else if (((_95_maybeOutVars).is_None) || ((new BigInteger(((_95_maybeOutVars).dtor_value).Count)).Sign == 0)) { } else { - Dafny.ISequence _114_tmpVar; - _114_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); - RAST._IExpr _115_tmpId; - _115_tmpId = RAST.Expr.create_Identifier(_114_tmpVar); - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _114_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); - Dafny.ISequence> _116_outVars; - _116_outVars = (_94_maybeOutVars).dtor_value; - BigInteger _hi2 = new BigInteger((_116_outVars).Count); - for (BigInteger _117_outI = BigInteger.Zero; _117_outI < _hi2; _117_outI++) { - Dafny.ISequence _118_outVar; - _118_outVar = Defs.__default.escapeVar((_116_outVars).Select(_117_outI)); - RAST._IExpr _119_rhs; - _119_rhs = (_115_tmpId).Sel(Std.Strings.__default.OfNat(_117_outI)); - if (!((env).CanReadWithoutClone(_118_outVar))) { - _119_rhs = RAST.__default.MaybePlacebo(_119_rhs); + Dafny.ISequence _115_tmpVar; + _115_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); + RAST._IExpr _116_tmpId; + _116_tmpId = RAST.Expr.create_Identifier(_115_tmpVar); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _115_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); + Dafny.ISequence> _117_outVars; + _117_outVars = (_95_maybeOutVars).dtor_value; + BigInteger _hi2 = new BigInteger((_117_outVars).Count); + for (BigInteger _118_outI = BigInteger.Zero; _118_outI < _hi2; _118_outI++) { + Dafny.ISequence _119_outVar; + _119_outVar = Defs.__default.escapeVar((_117_outVars).Select(_118_outI)); + RAST._IExpr _120_rhs; + _120_rhs = (_116_tmpId).Sel(Std.Strings.__default.OfNat(_118_outI)); + if (!((env).CanReadWithoutClone(_119_outVar))) { + _120_rhs = RAST.__default.MaybePlacebo(_120_rhs); } - generated = (generated).Then(RAST.__default.AssignVar(_118_outVar, _119_rhs)); + generated = (generated).Then(RAST.__default.AssignVar(_119_outVar, _120_rhs)); } } newEnv = env; @@ -2659,23 +2730,23 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Return) { - DAST._IExpression _120_exprDafny = _source0.dtor_expr; + DAST._IExpression _121_exprDafny = _source0.dtor_expr; { - RAST._IExpr _121_expr; - Defs._IOwnership _122___v55; - Dafny.ISet> _123_recIdents; + RAST._IExpr _122_expr; + Defs._IOwnership _123___v55; + Dafny.ISet> _124_recIdents; RAST._IExpr _out68; Defs._IOwnership _out69; Dafny.ISet> _out70; - (this).GenExpr(_120_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out68, out _out69, out _out70); - _121_expr = _out68; - _122___v55 = _out69; - _123_recIdents = _out70; - readIdents = _123_recIdents; + (this).GenExpr(_121_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out68, out _out69, out _out70); + _122_expr = _out68; + _123___v55 = _out69; + _124_recIdents = _out70; + readIdents = _124_recIdents; if (isLast) { - generated = _121_expr; + generated = _122_expr; } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_121_expr)); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_122_expr)); } newEnv = env; } @@ -2693,27 +2764,27 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } } { - Dafny.ISequence> _124_rustIdents = _source5.dtor_value; - Dafny.ISequence _125_tupleArgs; - _125_tupleArgs = Dafny.Sequence.FromElements(); - BigInteger _hi3 = new BigInteger((_124_rustIdents).Count); - for (BigInteger _126_i = BigInteger.Zero; _126_i < _hi3; _126_i++) { - RAST._IExpr _127_rIdent; - Defs._IOwnership _128___v56; - Dafny.ISet> _129___v57; + Dafny.ISequence> _125_rustIdents = _source5.dtor_value; + Dafny.ISequence _126_tupleArgs; + _126_tupleArgs = Dafny.Sequence.FromElements(); + BigInteger _hi3 = new BigInteger((_125_rustIdents).Count); + for (BigInteger _127_i = BigInteger.Zero; _127_i < _hi3; _127_i++) { + RAST._IExpr _128_rIdent; + Defs._IOwnership _129___v56; + Dafny.ISet> _130___v57; RAST._IExpr _out71; Defs._IOwnership _out72; Dafny.ISet> _out73; - (this).GenIdent((_124_rustIdents).Select(_126_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out71, out _out72, out _out73); - _127_rIdent = _out71; - _128___v56 = _out72; - _129___v57 = _out73; - _125_tupleArgs = Dafny.Sequence.Concat(_125_tupleArgs, Dafny.Sequence.FromElements(_127_rIdent)); + (this).GenIdent((_125_rustIdents).Select(_127_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out71, out _out72, out _out73); + _128_rIdent = _out71; + _129___v56 = _out72; + _130___v57 = _out73; + _126_tupleArgs = Dafny.Sequence.Concat(_126_tupleArgs, Dafny.Sequence.FromElements(_128_rIdent)); } - if ((new BigInteger((_125_tupleArgs).Count)) == (BigInteger.One)) { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_125_tupleArgs).Select(BigInteger.Zero))); + if ((new BigInteger((_126_tupleArgs).Count)) == (BigInteger.One)) { + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_126_tupleArgs).Select(BigInteger.Zero))); } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_125_tupleArgs))); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_126_tupleArgs))); } } after_match5: ; @@ -2734,20 +2805,20 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } } { - DAST._IExpression _130_e = _source0.dtor_Print_a0; + DAST._IExpression _131_e = _source0.dtor_Print_a0; { - RAST._IExpr _131_printedExpr; - Defs._IOwnership _132_recOwnership; - Dafny.ISet> _133_recIdents; + RAST._IExpr _132_printedExpr; + Defs._IOwnership _133_recOwnership; + Dafny.ISet> _134_recIdents; RAST._IExpr _out74; Defs._IOwnership _out75; Dafny.ISet> _out76; - (this).GenExpr(_130_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out74, out _out75, out _out76); - _131_printedExpr = _out74; - _132_recOwnership = _out75; - _133_recIdents = _out76; - 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(_131_printedExpr))); - readIdents = _133_recIdents; + (this).GenExpr(_131_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out74, out _out75, out _out76); + _132_printedExpr = _out74; + _133_recOwnership = _out75; + _134_recIdents = _out76; + 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(_132_printedExpr))); + readIdents = _134_recIdents; newEnv = env; } } @@ -2824,9 +2895,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. DAST._IExpression _source0 = e; { if (_source0.is_Literal) { - DAST._ILiteral _h170 = _source0.dtor_Literal_a0; - if (_h170.is_BoolLiteral) { - bool _0_b = _h170.dtor_BoolLiteral_a0; + DAST._ILiteral _h230 = _source0.dtor_Literal_a0; + if (_h230.is_BoolLiteral) { + bool _0_b = _h230.dtor_BoolLiteral_a0; { RAST._IExpr _out0; Defs._IOwnership _out1; @@ -2842,10 +2913,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h171 = _source0.dtor_Literal_a0; - if (_h171.is_IntLiteral) { - Dafny.ISequence _1_i = _h171.dtor_IntLiteral_a0; - DAST._IType _2_t = _h171.dtor_IntLiteral_a1; + DAST._ILiteral _h231 = _source0.dtor_Literal_a0; + if (_h231.is_IntLiteral) { + Dafny.ISequence _1_i = _h231.dtor_IntLiteral_a0; + DAST._IType _2_t = _h231.dtor_IntLiteral_a1; { DAST._IType _source1 = _2_t; { @@ -2888,11 +2959,11 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h172 = _source0.dtor_Literal_a0; - if (_h172.is_DecLiteral) { - Dafny.ISequence _5_n = _h172.dtor_DecLiteral_a0; - Dafny.ISequence _6_d = _h172.dtor_DecLiteral_a1; - DAST._IType _7_t = _h172.dtor_DecLiteral_a2; + DAST._ILiteral _h232 = _source0.dtor_Literal_a0; + if (_h232.is_DecLiteral) { + Dafny.ISequence _5_n = _h232.dtor_DecLiteral_a0; + Dafny.ISequence _6_d = _h232.dtor_DecLiteral_a1; + DAST._IType _7_t = _h232.dtor_DecLiteral_a2; { DAST._IType _source2 = _7_t; { @@ -2931,10 +3002,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h173 = _source0.dtor_Literal_a0; - if (_h173.is_StringLiteral) { - Dafny.ISequence _10_l = _h173.dtor_StringLiteral_a0; - bool _11_verbatim = _h173.dtor_verbatim; + DAST._ILiteral _h233 = _source0.dtor_Literal_a0; + if (_h233.is_StringLiteral) { + Dafny.ISequence _10_l = _h233.dtor_StringLiteral_a0; + bool _11_verbatim = _h233.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; @@ -2951,9 +3022,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h174 = _source0.dtor_Literal_a0; - if (_h174.is_CharLiteralUTF16) { - BigInteger _12_c = _h174.dtor_CharLiteralUTF16_a0; + DAST._ILiteral _h234 = _source0.dtor_Literal_a0; + if (_h234.is_CharLiteralUTF16) { + BigInteger _12_c = _h234.dtor_CharLiteralUTF16_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(_12_c)); r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); @@ -2972,9 +3043,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h175 = _source0.dtor_Literal_a0; - if (_h175.is_CharLiteral) { - Dafny.Rune _13_c = _h175.dtor_CharLiteral_a0; + DAST._ILiteral _h235 = _source0.dtor_Literal_a0; + if (_h235.is_CharLiteral) { + Dafny.Rune _13_c = _h235.dtor_CharLiteral_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(new BigInteger((_13_c).Value))); if (!(((this).charType).is_UTF32)) { @@ -2996,8 +3067,8 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } } { - DAST._ILiteral _h176 = _source0.dtor_Literal_a0; - DAST._IType _14_tpe = _h176.dtor_Null_a0; + DAST._ILiteral _h236 = _source0.dtor_Literal_a0; + DAST._IType _14_tpe = _h236.dtor_Null_a0; { RAST._IType _15_tpeGen; RAST._IType _out14; @@ -3019,81 +3090,145 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } after_match0: ; } + public RAST._IExpr ToPrimitive(RAST._IExpr r, DAST._IType typ, DAST._IType primitiveType) + { + RAST._IExpr @out = RAST.Expr.Default(); + @out = r; + if (!object.Equals(typ, primitiveType)) { + Defs._IOwnership _0_dummy = Defs.Ownership.Default(); + RAST._IExpr _out0; + Defs._IOwnership _out1; + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), typ, primitiveType, Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1); + @out = _out0; + _0_dummy = _out1; + } + return @out; + } + public RAST._IExpr ToBool(RAST._IExpr r, DAST._IType typ) + { + RAST._IExpr @out = RAST.Expr.Default(); + RAST._IExpr _out0; + _out0 = (this).ToPrimitive(r, typ, DAST.Type.create_Primitive(DAST.Primitive.create_Bool())); + @out = _out0; + return @out; + } + public RAST._IExpr ToInt(RAST._IExpr r, DAST._IType typ) + { + RAST._IExpr @out = RAST.Expr.Default(); + RAST._IExpr _out0; + _out0 = (this).ToPrimitive(r, typ, DAST.Type.create_Primitive(DAST.Primitive.create_Int())); + @out = _out0; + return @out; + } + public RAST._IExpr FromPrimitive(RAST._IExpr r, DAST._IType primitiveType, DAST._IType typ) + { + RAST._IExpr @out = RAST.Expr.Default(); + @out = r; + if (!object.Equals(typ, primitiveType)) { + Defs._IOwnership _0_dummy = Defs.Ownership.Default(); + RAST._IExpr _out0; + Defs._IOwnership _out1; + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), primitiveType, typ, Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1); + @out = _out0; + _0_dummy = _out1; + } + return @out; + } + public RAST._IExpr FromBool(RAST._IExpr r, DAST._IType typ) + { + RAST._IExpr @out = RAST.Expr.Default(); + RAST._IExpr _out0; + _out0 = (this).FromPrimitive(r, DAST.Type.create_Primitive(DAST.Primitive.create_Bool()), typ); + @out = _out0; + return @out; + } + public RAST._IExpr FromInt(RAST._IExpr r, DAST._IType typ) + { + RAST._IExpr @out = RAST.Expr.Default(); + RAST._IExpr _out0; + _out0 = (this).FromPrimitive(r, DAST.Type.create_Primitive(DAST.Primitive.create_Int()), typ); + @out = _out0; + return @out; + } public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); readIdents = Dafny.Set>.Empty; DAST._IExpression _let_tmp_rhs0 = e; - DAST._IBinOp _0_op = _let_tmp_rhs0.dtor_op; - DAST._IExpression _1_lExpr = _let_tmp_rhs0.dtor_left; - DAST._IExpression _2_rExpr = _let_tmp_rhs0.dtor_right; - DAST.Format._IBinaryOpFormat _3_format = _let_tmp_rhs0.dtor_format2; - bool _4_becomesLeftCallsRight; - _4_becomesLeftCallsRight = Defs.__default.BecomesLeftCallsRight(_0_op); - bool _5_becomesRightCallsLeft; - _5_becomesRightCallsLeft = Defs.__default.BecomesRightCallsLeft(_0_op); - Defs._IOwnership _6_expectedLeftOwnership; - if (_4_becomesLeftCallsRight) { - _6_expectedLeftOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); - } else if (_5_becomesRightCallsLeft) { - _6_expectedLeftOwnership = Defs.Ownership.create_OwnershipBorrowed(); + DAST._ITypedBinOp _let_tmp_rhs1 = _let_tmp_rhs0.dtor_op; + DAST._IBinOp _0_op = _let_tmp_rhs1.dtor_op; + DAST._IType _1_lType = _let_tmp_rhs1.dtor_leftType; + DAST._IType _2_rType = _let_tmp_rhs1.dtor_rightType; + DAST._IType _3_resType = _let_tmp_rhs1.dtor_resultType; + DAST._IExpression _4_lExpr = _let_tmp_rhs0.dtor_left; + DAST._IExpression _5_rExpr = _let_tmp_rhs0.dtor_right; + DAST.Format._IBinaryOpFormat _6_format = _let_tmp_rhs0.dtor_format2; + bool _7_becomesLeftCallsRight; + _7_becomesLeftCallsRight = Defs.__default.BecomesLeftCallsRight(_0_op); + bool _8_becomesRightCallsLeft; + _8_becomesRightCallsLeft = Defs.__default.BecomesRightCallsLeft(_0_op); + Defs._IOwnership _9_expectedLeftOwnership; + if (_7_becomesLeftCallsRight) { + _9_expectedLeftOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); + } else if (_8_becomesRightCallsLeft) { + _9_expectedLeftOwnership = Defs.Ownership.create_OwnershipBorrowed(); } else { - _6_expectedLeftOwnership = Defs.Ownership.create_OwnershipOwned(); + _9_expectedLeftOwnership = Defs.Ownership.create_OwnershipOwned(); } - Defs._IOwnership _7_expectedRightOwnership; - if (_4_becomesLeftCallsRight) { - _7_expectedRightOwnership = Defs.Ownership.create_OwnershipBorrowed(); - } else if (_5_becomesRightCallsLeft) { - _7_expectedRightOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); + Defs._IOwnership _10_expectedRightOwnership; + if (_7_becomesLeftCallsRight) { + _10_expectedRightOwnership = Defs.Ownership.create_OwnershipBorrowed(); + } else if (_8_becomesRightCallsLeft) { + _10_expectedRightOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); } else { - _7_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); + _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } - RAST._IExpr _8_left; - Defs._IOwnership _9___v58; - Dafny.ISet> _10_recIdentsL; + RAST._IExpr _11_left; + Defs._IOwnership _12___v58; + Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; - (this).GenExpr(_1_lExpr, selfIdent, env, _6_expectedLeftOwnership, out _out0, out _out1, out _out2); - _8_left = _out0; - _9___v58 = _out1; - _10_recIdentsL = _out2; - RAST._IExpr _11_right; - Defs._IOwnership _12___v59; - Dafny.ISet> _13_recIdentsR; + (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); + _11_left = _out0; + _12___v58 = _out1; + _13_recIdentsL = _out2; + RAST._IExpr _14_right; + Defs._IOwnership _15___v59; + Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; - (this).GenExpr(_2_rExpr, selfIdent, env, _7_expectedRightOwnership, out _out3, out _out4, out _out5); - _11_right = _out3; - _12___v59 = _out4; - _13_recIdentsR = _out5; + (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); + _14_right = _out3; + _15___v59 = _out4; + _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { if (_source0.is_In) { { - r = ((_11_right).Sel(Dafny.Sequence.UnicodeFromString("contains"))).Apply1(_8_left); + r = ((_14_right).Sel(Dafny.Sequence.UnicodeFromString("contains"))).Apply1(_11_left); } goto after_match0; } } { if (_source0.is_SeqProperPrefix) { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _8_left, _11_right, _3_format); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _11_left, _14_right, _6_format); goto after_match0; } } { if (_source0.is_SeqPrefix) { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _8_left, _11_right, _3_format); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _11_left, _14_right, _6_format); goto after_match0; } } { if (_source0.is_SetMerge) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_14_right); } goto after_match0; } @@ -3101,7 +3236,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_SetSubtraction) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_14_right); } goto after_match0; } @@ -3109,7 +3244,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_SetIntersection) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("intersect"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("intersect"))).Apply1(_14_right); } goto after_match0; } @@ -3117,7 +3252,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_Subset) { { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _8_left, _11_right, _3_format); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _11_left, _14_right, _6_format); } goto after_match0; } @@ -3125,7 +3260,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_ProperSubset) { { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _8_left, _11_right, _3_format); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _11_left, _14_right, _6_format); } goto after_match0; } @@ -3133,7 +3268,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_SetDisjoint) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("disjoint"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("disjoint"))).Apply1(_14_right); } goto after_match0; } @@ -3141,7 +3276,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_MapMerge) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_14_right); } goto after_match0; } @@ -3149,7 +3284,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_MapSubtraction) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_14_right); } goto after_match0; } @@ -3157,7 +3292,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_MultisetMerge) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_14_right); } goto after_match0; } @@ -3165,7 +3300,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_MultisetSubtraction) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_14_right); } goto after_match0; } @@ -3173,7 +3308,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_MultisetIntersection) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("intersect"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("intersect"))).Apply1(_14_right); } goto after_match0; } @@ -3181,7 +3316,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_Submultiset) { { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _8_left, _11_right, _3_format); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _11_left, _14_right, _6_format); } goto after_match0; } @@ -3189,7 +3324,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_ProperSubmultiset) { { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _8_left, _11_right, _3_format); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _11_left, _14_right, _6_format); } goto after_match0; } @@ -3197,7 +3332,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_MultisetDisjoint) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("disjoint"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("disjoint"))).Apply1(_14_right); } goto after_match0; } @@ -3205,7 +3340,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source0.is_Concat) { { - r = ((_8_left).Sel(Dafny.Sequence.UnicodeFromString("concat"))).Apply1(_11_right); + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("concat"))).Apply1(_14_right); } goto after_match0; } @@ -3213,38 +3348,102 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { { if ((Defs.__default.OpTable).Contains(_0_op)) { - r = RAST.Expr.create_BinaryOp(Dafny.Map>.Select(Defs.__default.OpTable,_0_op), _8_left, _11_right, _3_format); + if (Defs.__default.IsBooleanOperator(_0_op)) { + RAST._IExpr _out6; + _out6 = (this).ToBool(_11_left, _1_lType); + _11_left = _out6; + RAST._IExpr _out7; + _out7 = (this).ToBool(_14_right, _2_rType); + _14_right = _out7; + } + r = RAST.Expr.create_BinaryOp(Dafny.Map>.Select(Defs.__default.OpTable,_0_op), _11_left, _14_right, _6_format); + if (Defs.__default.IsBooleanOperator(_0_op)) { + RAST._IExpr _out8; + _out8 = (this).FromBool(r, _3_resType); + r = _out8; + } } else { + if (Defs.__default.IsComplexArithmetic(_0_op)) { + RAST._IExpr _out9; + _out9 = (this).ToInt(_11_left, _1_lType); + _11_left = _out9; + RAST._IExpr _out10; + _out10 = (this).ToInt(_14_right, _2_rType); + _14_right = _out10; + } DAST._IBinOp _source1 = _0_op; { if (_source1.is_Eq) { - bool _14_referential = _source1.dtor_referential; + bool _17_referential = _source1.dtor_referential; { - if (_14_referential) { + if (_17_referential) { if (((this).pointerType).is_Raw) { - RAST._IExpr _out6; - _out6 = (this).Error(Dafny.Sequence.UnicodeFromString("Raw pointer comparison not properly implemented yet"), (this).InitEmptyExpr()); - r = _out6; + RAST._IExpr _out11; + _out11 = (this).Error(Dafny.Sequence.UnicodeFromString("Raw pointer comparison not properly implemented yet"), (this).InitEmptyExpr()); + r = _out11; } else { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _8_left, _11_right, DAST.Format.BinaryOpFormat.create_NoFormat()); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _11_left, _14_right, DAST.Format.BinaryOpFormat.create_NoFormat()); } } else { - if (((_2_rExpr).is_SeqValue) && ((new BigInteger(((_2_rExpr).dtor_elements).Count)).Sign == 0)) { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), ((((_8_left).Sel(Dafny.Sequence.UnicodeFromString("to_array"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.BinaryOpFormat.create_NoFormat()); - } else if (((_1_lExpr).is_SeqValue) && ((new BigInteger(((_1_lExpr).dtor_elements).Count)).Sign == 0)) { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0")), ((((_11_right).Sel(Dafny.Sequence.UnicodeFromString("to_array"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(), DAST.Format.BinaryOpFormat.create_NoFormat()); + if (((_5_rExpr).is_SeqValue) && ((new BigInteger(((_5_rExpr).dtor_elements).Count)).Sign == 0)) { + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), ((((_11_left).Sel(Dafny.Sequence.UnicodeFromString("to_array"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.BinaryOpFormat.create_NoFormat()); + } else if (((_4_lExpr).is_SeqValue) && ((new BigInteger(((_4_lExpr).dtor_elements).Count)).Sign == 0)) { + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0")), ((((_14_right).Sel(Dafny.Sequence.UnicodeFromString("to_array"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(), DAST.Format.BinaryOpFormat.create_NoFormat()); } else { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _8_left, _11_right, DAST.Format.BinaryOpFormat.create_NoFormat()); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _11_left, _14_right, DAST.Format.BinaryOpFormat.create_NoFormat()); + if (!object.Equals(_3_resType, DAST.Type.create_Primitive(DAST.Primitive.create_Bool()))) { + RAST._IExpr _out12; + Defs._IOwnership _out13; + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), DAST.Type.create_Primitive(DAST.Primitive.create_Bool()), _3_resType, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13); + r = _out12; + resultingOwnership = _out13; + } } } } goto after_match1; } } + { + if (_source1.is_Div) { + bool overflow0 = _source1.dtor_overflow; + if ((overflow0) == (true)) { + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("wrapping_div"))).Apply1(_14_right); + goto after_match1; + } + } + } + { + if (_source1.is_Plus) { + bool overflow1 = _source1.dtor_overflow; + if ((overflow1) == (true)) { + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("wrapping_add"))).Apply1(_14_right); + goto after_match1; + } + } + } + { + if (_source1.is_Times) { + bool overflow2 = _source1.dtor_overflow; + if ((overflow2) == (true)) { + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("wrapping_mul"))).Apply1(_14_right); + goto after_match1; + } + } + } + { + if (_source1.is_Minus) { + bool overflow3 = _source1.dtor_overflow; + if ((overflow3) == (true)) { + r = ((_11_left).Sel(Dafny.Sequence.UnicodeFromString("wrapping_sub"))).Apply1(_14_right); + goto after_match1; + } + } + } { if (_source1.is_EuclidianDiv) { { - r = (((RAST.__default.dafny__runtime).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("euclidian_division"))).Apply(Dafny.Sequence.FromElements(_8_left, _11_right)); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("euclidian_division"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_11_left, _14_right)); } goto after_match1; } @@ -3252,259 +3451,375 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ { if (_source1.is_EuclidianMod) { { - r = (((RAST.__default.dafny__runtime).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("euclidian_modulo"))).Apply(Dafny.Sequence.FromElements(_8_left, _11_right)); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("euclidian_modulo"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_11_left, _14_right)); } goto after_match1; } } { - Dafny.ISequence _15_op = _source1.dtor_Passthrough_a0; + Dafny.ISequence _18_op = _source1.dtor_Passthrough_a0; { - r = RAST.Expr.create_BinaryOp(_15_op, _8_left, _11_right, _3_format); + r = RAST.Expr.create_BinaryOp(_18_op, _11_left, _14_right, _6_format); } } after_match1: ; + if (Defs.__default.IsComplexArithmetic(_0_op)) { + RAST._IExpr _out14; + _out14 = (this).FromInt(r, _3_resType); + r = _out14; + } } } } after_match0: ; - RAST._IExpr _out7; - Defs._IOwnership _out8; - (this).FromOwned(r, expectedOwnership, out _out7, out _out8); - r = _out7; - resultingOwnership = _out8; - readIdents = Dafny.Set>.Union(_10_recIdentsL, _13_recIdentsR); + RAST._IExpr _out15; + Defs._IOwnership _out16; + (this).FromOwned(r, expectedOwnership, out _out15, out _out16); + r = _out15; + resultingOwnership = _out16; + readIdents = Dafny.Set>.Union(_13_recIdentsL, _16_recIdentsR); return ; } - public void GenExprConvertToNewtype(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public RAST._IExpr UnwrapNewtype(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe) + { + RAST._IExpr r = RAST.Expr.Default(); + r = expr; + if (!((((fromTpe).dtor_resolved).dtor_kind).dtor_erase)) { + r = (r).Sel(Dafny.Sequence.UnicodeFromString("0")); + if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipBorrowed())) { + r = RAST.__default.Borrow(r); + } + } + return r; + } + public RAST._IExpr WrapWithNewtype(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType toTpe) + { + RAST._IExpr r = RAST.Expr.Default(); + r = expr; + DAST._IResolvedTypeBase _0_toKind; + _0_toKind = ((toTpe).dtor_resolved).dtor_kind; + if (!((_0_toKind).dtor_erase)) { + RAST._IExpr _1_fullPath; + RAST._IExpr _out0; + _out0 = (this).GenPathExpr(((toTpe).dtor_resolved).dtor_path, true); + _1_fullPath = _out0; + if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipOwned())) { + r = (_1_fullPath).Apply1(r); + } else { + r = ((_1_fullPath).FSel(Dafny.Sequence.UnicodeFromString("_from_ref"))).Apply1(r); + } + } + return r; + } + public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) { r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); - readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs0 = e; - DAST._IExpression _0_expr = _let_tmp_rhs0.dtor_value; - DAST._IType _1_fromTpe = _let_tmp_rhs0.dtor_from; - DAST._IType _2_toTpe = _let_tmp_rhs0.dtor_typ; - DAST._IType _let_tmp_rhs1 = _2_toTpe; - DAST._IResolvedType _let_tmp_rhs2 = _let_tmp_rhs1.dtor_resolved; - Dafny.ISequence> _3_path = _let_tmp_rhs2.dtor_path; - Dafny.ISequence _4_typeArgs = _let_tmp_rhs2.dtor_typeArgs; - DAST._IResolvedTypeBase _let_tmp_rhs3 = _let_tmp_rhs2.dtor_kind; - DAST._IType _5_b = _let_tmp_rhs3.dtor_baseType; - DAST._INewtypeRange _6_range = _let_tmp_rhs3.dtor_range; - bool _7_erase = _let_tmp_rhs3.dtor_erase; - Dafny.ISequence _8___v61 = _let_tmp_rhs2.dtor_attributes; - Dafny.ISequence> _9___v62 = _let_tmp_rhs2.dtor_properMethods; - Dafny.ISequence _10___v63 = _let_tmp_rhs2.dtor_extendedTypes; - Std.Wrappers._IOption _11_nativeToType; - _11_nativeToType = Defs.__default.NewtypeRangeToRustType(_6_range); - if (object.Equals(_1_fromTpe, _5_b)) { - RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13_recOwned; - Dafny.ISet> _14_recIdents; + r = expr; + if (object.Equals(fromTpe, toTpe)) { RAST._IExpr _out0; Defs._IOwnership _out1; - Dafny.ISet> _out2; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); - _12_recursiveGen = _out0; - _13_recOwned = _out1; - _14_recIdents = _out2; - readIdents = _14_recIdents; - Std.Wrappers._IOption _source0 = _11_nativeToType; - { - if (_source0.is_Some) { - RAST._IType _15_v = _source0.dtor_value; - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("truncate!"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_12_recursiveGen, RAST.Expr.create_ExprFromType(_15_v))); - RAST._IExpr _out3; - Defs._IOwnership _out4; - (this).FromOwned(r, expectedOwnership, out _out3, out _out4); - r = _out3; - resultingOwnership = _out4; - goto after_match0; + (this).FromOwnership(r, exprOwnership, expectedOwnership, out _out0, out _out1); + r = _out0; + resultingOwnership = _out1; + return ; + } + if (((fromTpe).is_UserDefined) && ((((fromTpe).dtor_resolved).dtor_kind).is_SynonymType)) { + RAST._IExpr _out2; + Defs._IOwnership _out3; + (this).GenExprConvertTo(expr, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, expectedOwnership, out _out2, out _out3); + 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, 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, expectedOwnership, out _out7, out _out8); + r = _out7; + resultingOwnership = _out8; + 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, 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; + return ; + } + Std.Wrappers._IOption _1_unwrappedFromType; + _1_unwrappedFromType = Defs.__default.GetUnwrappedBoundedRustType(fromTpe); + Std.Wrappers._IOption _2_unwrappedToType; + _2_unwrappedToType = Defs.__default.GetUnwrappedBoundedRustType(toTpe); + if ((_2_unwrappedToType).is_Some) { + 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; + Defs._IOwnership _4_inOwnership; + _4_inOwnership = exprOwnership; + if (!object.Equals((_1_unwrappedFromType).dtor_value, (_2_unwrappedToType).dtor_value)) { + RAST._IType _5_asType; + _5_asType = _3_boundedToType; + if (object.Equals(_4_inOwnership, Defs.Ownership.create_OwnershipBorrowed())) { + RAST._IExpr _source0 = r; + { + if (_source0.is_UnaryOp) { + Dafny.ISequence op10 = _source0.dtor_op1; + if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { + RAST._IExpr _6_underlying = _source0.dtor_underlying; + r = _6_underlying; + goto after_match0; + } + } + } + { + r = (r).Clone(); + } + after_match0: ; + } + 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; + return ; } - { - if (_7_erase) { - r = _12_recursiveGen; - } else { - RAST._IType _16_rhsType; - RAST._IType _out5; - _out5 = (this).GenType(_2_toTpe, Defs.GenTypeContext.@default()); - _16_rhsType = _out5; - r = (RAST.Expr.create_ExprFromType(_16_rhsType)).Apply1(_12_recursiveGen); - } - RAST._IExpr _out6; - Defs._IOwnership _out7; - (this).FromOwnership(r, _13_recOwned, expectedOwnership, out _out6, out _out7); - r = _out6; - resultingOwnership = _out7; + if ((fromTpe).IsPrimitiveInt()) { + if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipBorrowed())) { + 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; + return ; } - after_match0: ; - } else { - if ((_11_nativeToType).is_Some) { - DAST._IType _source1 = _1_fromTpe; - { - if (_source1.is_UserDefined) { - DAST._IResolvedType resolved0 = _source1.dtor_resolved; - DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; - if (kind0.is_Newtype) { - DAST._IType _17_b0 = kind0.dtor_baseType; - DAST._INewtypeRange _18_range0 = kind0.dtor_range; - bool _19_erase0 = kind0.dtor_erase; - Dafny.ISequence _20_attributes0 = resolved0.dtor_attributes; + 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; + 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; + return ; + } + if ((_1_unwrappedFromType).is_Some) { + if (!((((fromTpe).dtor_resolved).dtor_kind).dtor_erase)) { + 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; + 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; + 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; + 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; + return ; + } + _System._ITuple2 _source1 = _System.Tuple2.create(fromTpe, toTpe); + { + DAST._IType _00 = _source1.dtor__0; + if (_00.is_Primitive) { + DAST._IPrimitive _h70 = _00.dtor_Primitive_a0; + if (_h70.is_Int) { + DAST._IType _10 = _source1.dtor__1; + if (_10.is_Primitive) { + DAST._IPrimitive _h71 = _10.dtor_Primitive_a0; + if (_h71.is_Real) { { - Std.Wrappers._IOption _21_nativeFromType; - _21_nativeFromType = Defs.__default.NewtypeRangeToRustType(_18_range0); - if ((_21_nativeFromType).is_Some) { - RAST._IExpr _22_recursiveGen; - Defs._IOwnership _23_recOwned; - Dafny.ISet> _24_recIdents; - RAST._IExpr _out8; - Defs._IOwnership _out9; - Dafny.ISet> _out10; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out8, out _out9, out _out10); - _22_recursiveGen = _out8; - _23_recOwned = _out9; - _24_recIdents = _out10; - RAST._IExpr _out11; - Defs._IOwnership _out12; - (this).FromOwnership(RAST.Expr.create_TypeAscription(_22_recursiveGen, (_11_nativeToType).dtor_value), _23_recOwned, expectedOwnership, out _out11, out _out12); - r = _out11; - resultingOwnership = _out12; - readIdents = _24_recIdents; - return ; - } + r = RAST.__default.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; } goto after_match1; } } } - { - } - after_match1: ; - if (object.Equals(_1_fromTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { - RAST._IExpr _25_recursiveGen; - Defs._IOwnership _26_recOwned; - Dafny.ISet> _27_recIdents; - RAST._IExpr _out13; - Defs._IOwnership _out14; - Dafny.ISet> _out15; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out13, out _out14, out _out15); - _25_recursiveGen = _out13; - _26_recOwned = _out14; - _27_recIdents = _out15; - RAST._IExpr _out16; - Defs._IOwnership _out17; - (this).FromOwnership(RAST.Expr.create_TypeAscription((_25_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("0")), (_11_nativeToType).dtor_value), _26_recOwned, expectedOwnership, out _out16, out _out17); - r = _out16; - resultingOwnership = _out17; - readIdents = _27_recIdents; - return ; - } } - RAST._IExpr _out18; - Defs._IOwnership _out19; - Dafny.ISet> _out20; - (this).GenExpr(DAST.Expression.create_Convert(DAST.Expression.create_Convert(_0_expr, _1_fromTpe, _5_b), _5_b, _2_toTpe), selfIdent, env, expectedOwnership, out _out18, out _out19, out _out20); - r = _out18; - resultingOwnership = _out19; - readIdents = _out20; } - } - public void GenExprConvertFromNewtype(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership, out Dafny.ISet> readIdents) - { - r = RAST.Expr.Default(); - resultingOwnership = Defs.Ownership.Default(); - readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs0 = e; - DAST._IExpression _0_expr = _let_tmp_rhs0.dtor_value; - DAST._IType _1_fromTpe = _let_tmp_rhs0.dtor_from; - DAST._IType _2_toTpe = _let_tmp_rhs0.dtor_typ; - DAST._IType _let_tmp_rhs1 = _1_fromTpe; - DAST._IResolvedType _let_tmp_rhs2 = _let_tmp_rhs1.dtor_resolved; - Dafny.ISequence> _3___v69 = _let_tmp_rhs2.dtor_path; - Dafny.ISequence _4___v70 = _let_tmp_rhs2.dtor_typeArgs; - DAST._IResolvedTypeBase _let_tmp_rhs3 = _let_tmp_rhs2.dtor_kind; - DAST._IType _5_b = _let_tmp_rhs3.dtor_baseType; - DAST._INewtypeRange _6_range = _let_tmp_rhs3.dtor_range; - bool _7_erase = _let_tmp_rhs3.dtor_erase; - Dafny.ISequence _8_attributes = _let_tmp_rhs2.dtor_attributes; - Dafny.ISequence> _9___v71 = _let_tmp_rhs2.dtor_properMethods; - Dafny.ISequence _10___v72 = _let_tmp_rhs2.dtor_extendedTypes; - Std.Wrappers._IOption _11_nativeFromType; - _11_nativeFromType = Defs.__default.NewtypeRangeToRustType(_6_range); - if (object.Equals(_5_b, _2_toTpe)) { - RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13_recOwned; - Dafny.ISet> _14_recIdents; - RAST._IExpr _out0; - Defs._IOwnership _out1; - Dafny.ISet> _out2; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); - _12_recursiveGen = _out0; - _13_recOwned = _out1; - _14_recIdents = _out2; - readIdents = _14_recIdents; - Std.Wrappers._IOption _source0 = _11_nativeFromType; - { - if (_source0.is_Some) { - RAST._IType _15_v = _source0.dtor_value; - RAST._IType _16_toTpeRust; - RAST._IType _out3; - _out3 = (this).GenType(_2_toTpe, Defs.GenTypeContext.@default()); - _16_toTpeRust = _out3; - r = ((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_16_toTpeRust))).FSel(Dafny.Sequence.UnicodeFromString("into"))).Apply(Dafny.Sequence.FromElements(_12_recursiveGen)); - RAST._IExpr _out4; - Defs._IOwnership _out5; - (this).FromOwned(r, expectedOwnership, out _out4, out _out5); - r = _out4; - resultingOwnership = _out5; - goto after_match0; + { + DAST._IType _01 = _source1.dtor__0; + if (_01.is_Primitive) { + DAST._IPrimitive _h72 = _01.dtor_Primitive_a0; + if (_h72.is_Real) { + DAST._IType _11 = _source1.dtor__1; + if (_11.is_Primitive) { + DAST._IPrimitive _h73 = _11.dtor_Primitive_a0; + 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; + } + goto after_match1; + } + } } } - { - if (_7_erase) { - r = _12_recursiveGen; - } else { - r = (_12_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("0")); + } + { + DAST._IType _02 = _source1.dtor__0; + if (_02.is_Primitive) { + DAST._IPrimitive _h74 = _02.dtor_Primitive_a0; + if (_h74.is_Int) { + DAST._IType _12 = _source1.dtor__1; + if (_12.is_Primitive) { + DAST._IPrimitive _h75 = _12.dtor_Primitive_a0; + if (_h75.is_Char) { + { + RAST._IType _9_rhsType; + RAST._IType _out42; + _out42 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); + _9_rhsType = _out42; + RAST._IType _10_uType; + if (((this).charType).is_UTF32) { + _10_uType = RAST.Type.create_U32(); + } else { + _10_uType = RAST.Type.create_U16(); + } + if (!object.Equals(exprOwnership, Defs.Ownership.create_OwnershipOwned())) { + r = (r).Clone(); + } + r = ((((RAST.Expr.create_TraitCast(_10_uType, ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("NumCast"))).AsType())).FSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); + if (((this).charType).is_UTF32) { + 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; + } + goto after_match1; + } + } } - RAST._IExpr _out6; - Defs._IOwnership _out7; - (this).FromOwnership(r, _13_recOwned, expectedOwnership, out _out6, out _out7); - r = _out6; - resultingOwnership = _out7; } - after_match0: ; - } else { - if ((_11_nativeFromType).is_Some) { - if (object.Equals(_2_toTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { - RAST._IExpr _17_recursiveGen; - Defs._IOwnership _18_recOwned; - Dafny.ISet> _19_recIdents; - RAST._IExpr _out8; - Defs._IOwnership _out9; - Dafny.ISet> _out10; - (this).GenExpr(_0_expr, selfIdent, env, expectedOwnership, out _out8, out _out9, out _out10); - _17_recursiveGen = _out8; - _18_recOwned = _out9; - _19_recIdents = _out10; - RAST._IExpr _out11; - Defs._IOwnership _out12; - (this).FromOwnership((((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(RAST.Expr.create_TypeAscription(_17_recursiveGen, (this).DafnyCharUnderlying)), _18_recOwned, expectedOwnership, out _out11, out _out12); - r = _out11; - resultingOwnership = _out12; - readIdents = _19_recIdents; - return ; + } + { + DAST._IType _03 = _source1.dtor__0; + if (_03.is_Primitive) { + DAST._IPrimitive _h76 = _03.dtor_Primitive_a0; + if (_h76.is_Char) { + DAST._IType _13 = _source1.dtor__1; + if (_13.is_Primitive) { + DAST._IPrimitive _h77 = _13.dtor_Primitive_a0; + if (_h77.is_Int) { + { + RAST._IType _11_rhsType; + RAST._IType _out45; + _out45 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); + _11_rhsType = _out45; + 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; + } + goto after_match1; + } + } } } - RAST._IExpr _out13; - Defs._IOwnership _out14; - Dafny.ISet> _out15; - (this).GenExpr(DAST.Expression.create_Convert(DAST.Expression.create_Convert(_0_expr, _1_fromTpe, _5_b), _5_b, _2_toTpe), selfIdent, env, expectedOwnership, out _out13, out _out14, out _out15); - r = _out13; - resultingOwnership = _out14; - readIdents = _out15; } + { + { + RAST._IExpr _out48; + Defs._IOwnership _out49; + (this).GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, expectedOwnership, out _out48, out _out49); + r = _out48; + resultingOwnership = _out49; + } + } + after_match1: ; } public bool IsBuiltinCollection(DAST._IType typ) { return ((((typ).is_Seq) || ((typ).is_Set)) || ((typ).is_Map)) || ((typ).is_Multiset); @@ -3647,91 +3962,71 @@ public bool IsDowncastConversion(RAST._IType fromTpe, RAST._IType toTpe) return false; } } - public void GenExprConvertOther(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) { r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); - readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs0 = e; - DAST._IExpression _0_expr = _let_tmp_rhs0.dtor_value; - DAST._IType _1_fromTpe = _let_tmp_rhs0.dtor_from; - DAST._IType _2_toTpe = _let_tmp_rhs0.dtor_typ; - RAST._IType _3_fromTpeGen; + r = expr; + RAST._IType _0_fromTpeGen; RAST._IType _out0; - _out0 = (this).GenType(_1_fromTpe, Defs.GenTypeContext.@default()); - _3_fromTpeGen = _out0; - RAST._IType _4_toTpeGen; + _out0 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); + _0_fromTpeGen = _out0; + RAST._IType _1_toTpeGen; RAST._IType _out1; - _out1 = (this).GenType(_2_toTpe, Defs.GenTypeContext.@default()); - _4_toTpeGen = _out1; - Std.Wrappers._IResult,RAST._IExpr>>> _5_upcastConverter; - _5_upcastConverter = (this).UpcastConversionLambda(_1_fromTpe, _3_fromTpeGen, _2_toTpe, _4_toTpeGen, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements()); - if ((_5_upcastConverter).is_Success) { - RAST._IExpr _6_conversionLambda; - _6_conversionLambda = (_5_upcastConverter).dtor_value; - RAST._IExpr _7_recursiveGen; - Defs._IOwnership _8_recOwned; - Dafny.ISet> _9_recIdents; + _out1 = (this).GenType(toTpe, 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; + if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipBorrowed())) { + RAST._IExpr _source0 = r; + { + if (_source0.is_UnaryOp) { + Dafny.ISequence op10 = _source0.dtor_op1; + if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { + RAST._IExpr _4_underlying = _source0.dtor_underlying; + r = _4_underlying; + goto after_match0; + } + } + } + { + r = (r).Clone(); + } + after_match0: ; + } + r = (_3_conversionLambda).Apply1(r); RAST._IExpr _out2; Defs._IOwnership _out3; - Dafny.ISet> _out4; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out2, out _out3, out _out4); - _7_recursiveGen = _out2; - _8_recOwned = _out3; - _9_recIdents = _out4; - readIdents = _9_recIdents; - r = (_6_conversionLambda).Apply1(_7_recursiveGen); - RAST._IExpr _out5; - Defs._IOwnership _out6; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out5, out _out6); - r = _out5; - resultingOwnership = _out6; - } else if ((this).IsDowncastConversion(_3_fromTpeGen, _4_toTpeGen)) { - RAST._IExpr _10_recursiveGen; - Defs._IOwnership _11_recOwned; - Dafny.ISet> _12_recIdents; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out2, out _out3); + r = _out2; + resultingOwnership = _out3; + } else if ((this).IsDowncastConversion(_0_fromTpeGen, _1_toTpeGen)) { + _1_toTpeGen = (_1_toTpeGen).ObjectOrPointerUnderlying(); + 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; + } else { + Std.Wrappers._IResult,RAST._IExpr>>> _let_tmp_rhs0 = _2_upcastConverter; + _System._ITuple5,RAST._IExpr>> _let_tmp_rhs1 = _let_tmp_rhs0.dtor_error; + DAST._IType _5_fromType = _let_tmp_rhs1.dtor__0; + RAST._IType _6_fromTpeGen = _let_tmp_rhs1.dtor__1; + DAST._IType _7_toType = _let_tmp_rhs1.dtor__2; + RAST._IType _8_toTpeGen = _let_tmp_rhs1.dtor__3; + Dafny.IMap<_System._ITuple2,RAST._IExpr> _9_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 "), (_6_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_8_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); + r = _out6; RAST._IExpr _out7; Defs._IOwnership _out8; - Dafny.ISet> _out9; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out7, out _out8, out _out9); - _10_recursiveGen = _out7; - _11_recOwned = _out8; - _12_recIdents = _out9; - readIdents = _12_recIdents; - _4_toTpeGen = (_4_toTpeGen).ObjectOrPointerUnderlying(); - r = (((RAST.__default.dafny__runtime).MSel((this).downcast)).AsExpr()).Apply(Dafny.Sequence.FromElements(_10_recursiveGen, RAST.Expr.create_ExprFromType(_4_toTpeGen))); - RAST._IExpr _out10; - Defs._IOwnership _out11; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out10, out _out11); - r = _out10; - resultingOwnership = _out11; - } else { - RAST._IExpr _13_recursiveGen; - Defs._IOwnership _14_recOwned; - Dafny.ISet> _15_recIdents; - RAST._IExpr _out12; - Defs._IOwnership _out13; - Dafny.ISet> _out14; - (this).GenExpr(_0_expr, selfIdent, env, expectedOwnership, out _out12, out _out13, out _out14); - _13_recursiveGen = _out12; - _14_recOwned = _out13; - _15_recIdents = _out14; - readIdents = _15_recIdents; - Std.Wrappers._IResult,RAST._IExpr>>> _let_tmp_rhs1 = _5_upcastConverter; - _System._ITuple5,RAST._IExpr>> _let_tmp_rhs2 = _let_tmp_rhs1.dtor_error; - DAST._IType _16_fromType = _let_tmp_rhs2.dtor__0; - RAST._IType _17_fromTpeGen = _let_tmp_rhs2.dtor__1; - DAST._IType _18_toType = _let_tmp_rhs2.dtor__2; - RAST._IType _19_toTpeGen = _let_tmp_rhs2.dtor__3; - Dafny.IMap<_System._ITuple2,RAST._IExpr> _20_m = _let_tmp_rhs2.dtor__4; - RAST._IExpr _out15; - _out15 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_17_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_19_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), _13_recursiveGen); - r = _out15; - RAST._IExpr _out16; - Defs._IOwnership _out17; - (this).FromOwnership(r, _14_recOwned, expectedOwnership, out _out16, out _out17); - r = _out16; - resultingOwnership = _out17; + (this).FromOwned(r, expectedOwnership, out _out7, out _out8); + r = _out7; + resultingOwnership = _out8; } } 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) @@ -3743,342 +4038,28 @@ public void GenExprConvert(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. DAST._IExpression _0_expr = _let_tmp_rhs0.dtor_value; DAST._IType _1_fromTpe = _let_tmp_rhs0.dtor_from; DAST._IType _2_toTpe = _let_tmp_rhs0.dtor_typ; - if (object.Equals(_1_fromTpe, _2_toTpe)) { - RAST._IExpr _3_recursiveGen; - Defs._IOwnership _4_recOwned; - Dafny.ISet> _5_recIdents; - RAST._IExpr _out0; - Defs._IOwnership _out1; - Dafny.ISet> _out2; - (this).GenExpr(_0_expr, selfIdent, env, expectedOwnership, out _out0, out _out1, out _out2); - _3_recursiveGen = _out0; - _4_recOwned = _out1; - _5_recIdents = _out2; - r = _3_recursiveGen; - RAST._IExpr _out3; - Defs._IOwnership _out4; - (this).FromOwnership(r, _4_recOwned, expectedOwnership, out _out3, out _out4); - r = _out3; - resultingOwnership = _out4; - readIdents = _5_recIdents; - } else { - _System._ITuple2 _source0 = _System.Tuple2.create(_1_fromTpe, _2_toTpe); - { - DAST._IType _10 = _source0.dtor__1; - if (_10.is_UserDefined) { - DAST._IResolvedType resolved0 = _10.dtor_resolved; - DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; - if (kind0.is_Newtype) { - DAST._IType _6_b = kind0.dtor_baseType; - DAST._INewtypeRange _7_range = kind0.dtor_range; - bool _8_erase = kind0.dtor_erase; - Dafny.ISequence _9_attributes = resolved0.dtor_attributes; - { - RAST._IExpr _out5; - Defs._IOwnership _out6; - Dafny.ISet> _out7; - (this).GenExprConvertToNewtype(e, selfIdent, env, expectedOwnership, out _out5, out _out6, out _out7); - r = _out5; - resultingOwnership = _out6; - readIdents = _out7; - } - goto after_match0; - } - } - } - { - DAST._IType _00 = _source0.dtor__0; - if (_00.is_UserDefined) { - DAST._IResolvedType resolved1 = _00.dtor_resolved; - DAST._IResolvedTypeBase kind1 = resolved1.dtor_kind; - if (kind1.is_Newtype) { - DAST._IType _10_b = kind1.dtor_baseType; - DAST._INewtypeRange _11_range = kind1.dtor_range; - bool _12_erase = kind1.dtor_erase; - Dafny.ISequence _13_attributes = resolved1.dtor_attributes; - { - RAST._IExpr _out8; - Defs._IOwnership _out9; - Dafny.ISet> _out10; - (this).GenExprConvertFromNewtype(e, selfIdent, env, expectedOwnership, out _out8, out _out9, out _out10); - r = _out8; - resultingOwnership = _out9; - readIdents = _out10; - } - goto after_match0; - } - } - } - { - DAST._IType _01 = _source0.dtor__0; - if (_01.is_Primitive) { - DAST._IPrimitive _h70 = _01.dtor_Primitive_a0; - if (_h70.is_Int) { - DAST._IType _11 = _source0.dtor__1; - if (_11.is_Primitive) { - DAST._IPrimitive _h71 = _11.dtor_Primitive_a0; - if (_h71.is_Real) { - { - RAST._IExpr _14_recursiveGen; - Defs._IOwnership _15___v83; - Dafny.ISet> _16_recIdents; - RAST._IExpr _out11; - Defs._IOwnership _out12; - Dafny.ISet> _out13; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out11, out _out12, out _out13); - _14_recursiveGen = _out11; - _15___v83 = _out12; - _16_recIdents = _out13; - r = RAST.__default.RcNew(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("BigRational"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("from_integer"))).Apply1(_14_recursiveGen)); - RAST._IExpr _out14; - Defs._IOwnership _out15; - (this).FromOwned(r, expectedOwnership, out _out14, out _out15); - r = _out14; - resultingOwnership = _out15; - readIdents = _16_recIdents; - } - goto after_match0; - } - } - } - } - } - { - DAST._IType _02 = _source0.dtor__0; - if (_02.is_Primitive) { - DAST._IPrimitive _h72 = _02.dtor_Primitive_a0; - if (_h72.is_Real) { - DAST._IType _12 = _source0.dtor__1; - if (_12.is_Primitive) { - DAST._IPrimitive _h73 = _12.dtor_Primitive_a0; - if (_h73.is_Int) { - { - RAST._IExpr _17_recursiveGen; - Defs._IOwnership _18___v84; - Dafny.ISet> _19_recIdents; - RAST._IExpr _out16; - Defs._IOwnership _out17; - Dafny.ISet> _out18; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out16, out _out17, out _out18); - _17_recursiveGen = _out16; - _18___v84 = _out17; - _19_recIdents = _out18; - r = (((RAST.__default.dafny__runtime).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("dafny_rational_to_int"))).Apply1(_17_recursiveGen); - RAST._IExpr _out19; - Defs._IOwnership _out20; - (this).FromOwned(r, expectedOwnership, out _out19, out _out20); - r = _out19; - resultingOwnership = _out20; - readIdents = _19_recIdents; - } - goto after_match0; - } - } - } - } - } - { - DAST._IType _03 = _source0.dtor__0; - if (_03.is_Primitive) { - DAST._IPrimitive _h74 = _03.dtor_Primitive_a0; - if (_h74.is_Int) { - DAST._IType _13 = _source0.dtor__1; - if (_13.is_Passthrough) { - { - RAST._IType _20_rhsType; - RAST._IType _out21; - _out21 = (this).GenType(_2_toTpe, Defs.GenTypeContext.@default()); - _20_rhsType = _out21; - RAST._IExpr _21_recursiveGen; - Defs._IOwnership _22___v86; - Dafny.ISet> _23_recIdents; - RAST._IExpr _out22; - Defs._IOwnership _out23; - Dafny.ISet> _out24; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out22, out _out23, out _out24); - _21_recursiveGen = _out22; - _22___v86 = _out23; - _23_recIdents = _out24; - r = ((((RAST.Expr.create_TraitCast(_20_rhsType, ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("NumCast"))).AsType())).FSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(_21_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); - RAST._IExpr _out25; - Defs._IOwnership _out26; - (this).FromOwned(r, expectedOwnership, out _out25, out _out26); - r = _out25; - resultingOwnership = _out26; - readIdents = _23_recIdents; - } - goto after_match0; - } - } - } - } - { - DAST._IType _04 = _source0.dtor__0; - if (_04.is_Passthrough) { - DAST._IType _14 = _source0.dtor__1; - if (_14.is_Primitive) { - DAST._IPrimitive _h75 = _14.dtor_Primitive_a0; - if (_h75.is_Int) { - { - RAST._IType _24_rhsType; - RAST._IType _out27; - _out27 = (this).GenType(_1_fromTpe, Defs.GenTypeContext.@default()); - _24_rhsType = _out27; - RAST._IExpr _25_recursiveGen; - Defs._IOwnership _26___v88; - Dafny.ISet> _27_recIdents; - RAST._IExpr _out28; - Defs._IOwnership _out29; - Dafny.ISet> _out30; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out28, out _out29, out _out30); - _25_recursiveGen = _out28; - _26___v88 = _out29; - _27_recIdents = _out30; - r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("rc"))).MSel(Dafny.Sequence.UnicodeFromString("Rc"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply1(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("BigInt"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(_25_recursiveGen))); - RAST._IExpr _out31; - Defs._IOwnership _out32; - (this).FromOwned(r, expectedOwnership, out _out31, out _out32); - r = _out31; - resultingOwnership = _out32; - readIdents = _27_recIdents; - } - goto after_match0; - } - } - } - } - { - DAST._IType _05 = _source0.dtor__0; - if (_05.is_Primitive) { - DAST._IPrimitive _h76 = _05.dtor_Primitive_a0; - if (_h76.is_Int) { - DAST._IType _15 = _source0.dtor__1; - if (_15.is_Primitive) { - DAST._IPrimitive _h77 = _15.dtor_Primitive_a0; - if (_h77.is_Char) { - { - RAST._IType _28_rhsType; - RAST._IType _out33; - _out33 = (this).GenType(_2_toTpe, Defs.GenTypeContext.@default()); - _28_rhsType = _out33; - RAST._IExpr _29_recursiveGen; - Defs._IOwnership _30___v89; - Dafny.ISet> _31_recIdents; - RAST._IExpr _out34; - Defs._IOwnership _out35; - Dafny.ISet> _out36; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out34, out _out35, out _out36); - _29_recursiveGen = _out34; - _30___v89 = _out35; - _31_recIdents = _out36; - RAST._IType _32_uType; - if (((this).charType).is_UTF32) { - _32_uType = RAST.Type.create_U32(); - } else { - _32_uType = RAST.Type.create_U16(); - } - r = RAST.Expr.create_TraitCast(_32_uType, ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("NumCast"))).AsType()); - r = ((((r).FSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(_29_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); - if (((this).charType).is_UTF32) { - 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 _out37; - Defs._IOwnership _out38; - (this).FromOwned(r, expectedOwnership, out _out37, out _out38); - r = _out37; - resultingOwnership = _out38; - readIdents = _31_recIdents; - } - goto after_match0; - } - } - } - } - } - { - DAST._IType _06 = _source0.dtor__0; - if (_06.is_Primitive) { - DAST._IPrimitive _h78 = _06.dtor_Primitive_a0; - if (_h78.is_Char) { - DAST._IType _16 = _source0.dtor__1; - if (_16.is_Primitive) { - DAST._IPrimitive _h79 = _16.dtor_Primitive_a0; - if (_h79.is_Int) { - { - RAST._IType _33_rhsType; - RAST._IType _out39; - _out39 = (this).GenType(_1_fromTpe, Defs.GenTypeContext.@default()); - _33_rhsType = _out39; - RAST._IExpr _34_recursiveGen; - Defs._IOwnership _35___v90; - Dafny.ISet> _36_recIdents; - RAST._IExpr _out40; - Defs._IOwnership _out41; - Dafny.ISet> _out42; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out40, out _out41, out _out42); - _34_recursiveGen = _out40; - _35___v90 = _out41; - _36_recIdents = _out42; - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1((_34_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("0"))); - RAST._IExpr _out43; - Defs._IOwnership _out44; - (this).FromOwned(r, expectedOwnership, out _out43, out _out44); - r = _out43; - resultingOwnership = _out44; - readIdents = _36_recIdents; - } - goto after_match0; - } - } - } - } - } - { - DAST._IType _07 = _source0.dtor__0; - if (_07.is_Passthrough) { - DAST._IType _17 = _source0.dtor__1; - if (_17.is_Passthrough) { - { - RAST._IExpr _37_recursiveGen; - Defs._IOwnership _38___v93; - Dafny.ISet> _39_recIdents; - RAST._IExpr _out45; - Defs._IOwnership _out46; - Dafny.ISet> _out47; - (this).GenExpr(_0_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out45, out _out46, out _out47); - _37_recursiveGen = _out45; - _38___v93 = _out46; - _39_recIdents = _out47; - RAST._IType _40_toTpeGen; - RAST._IType _out48; - _out48 = (this).GenType(_2_toTpe, Defs.GenTypeContext.@default()); - _40_toTpeGen = _out48; - r = RAST.Expr.create_TypeAscription(_37_recursiveGen, _40_toTpeGen); - RAST._IExpr _out49; - Defs._IOwnership _out50; - (this).FromOwned(r, expectedOwnership, out _out49, out _out50); - r = _out49; - resultingOwnership = _out50; - readIdents = _39_recIdents; - } - goto after_match0; - } - } - } - { - { - RAST._IExpr _out51; - Defs._IOwnership _out52; - Dafny.ISet> _out53; - (this).GenExprConvertOther(e, selfIdent, env, expectedOwnership, out _out51, out _out52, out _out53); - r = _out51; - resultingOwnership = _out52; - readIdents = _out53; - } - } - after_match0: ; - } + Defs._IOwnership _3_argumentOwnership; + _3_argumentOwnership = expectedOwnership; + if (object.Equals(_3_argumentOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())) { + _3_argumentOwnership = Defs.Ownership.create_OwnershipBorrowed(); + } + RAST._IExpr _4_recursiveGen; + Defs._IOwnership _5_recOwned; + Dafny.ISet> _6_recIdents; + RAST._IExpr _out0; + Defs._IOwnership _out1; + Dafny.ISet> _out2; + (this).GenExpr(_0_expr, selfIdent, env, _3_argumentOwnership, out _out0, out _out1, out _out2); + _4_recursiveGen = _out0; + _5_recOwned = _out1; + _6_recIdents = _out2; + r = _4_recursiveGen; + readIdents = _6_recIdents; + RAST._IExpr _out3; + Defs._IOwnership _out4; + (this).GenExprConvertTo(r, _5_recOwned, _1_fromTpe, _2_toTpe, expectedOwnership, out _out3, out _out4); + r = _out3; + resultingOwnership = _out4; return ; } public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership, out Dafny.ISet> readIdents) @@ -4139,7 +4120,7 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden } }))()); if (_4_needObjectFromRef) { - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("_"))))).FSel(Dafny.Sequence.UnicodeFromString("from_ref"))).Apply(Dafny.Sequence.FromElements(r)); + 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 (!(_3_noNeedOfClone)) { r = (r).Clone(); @@ -4205,14 +4186,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v100; + Defs._IOwnership _5___v71; 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___v100 = _out2; + _5___v71 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4414,14 +4395,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___v110; + Defs._IOwnership _13___v81; 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___v110 = _out17; + _13___v81 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4470,14 +4451,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___v111; + Defs._IOwnership _24___v82; 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___v111 = _out24; + _24___v82 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4515,14 +4496,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___v112; + Defs._IOwnership _32___v83; 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___v112 = _out31; + _32___v83 = _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); @@ -4549,14 +4530,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___v113; + Defs._IOwnership _37___v84; 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___v113 = _out36; + _37___v84 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -4579,14 +4560,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___v114; + Defs._IOwnership _43___v85; 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___v114 = _out42; + _43___v85 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -4652,14 +4633,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___v115; + Defs._IOwnership _60___v86; 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___v115 = _out51; + _60___v86 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -4682,14 +4663,14 @@ 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___v116; + Defs._IOwnership _66___v87; 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___v116 = _out54; + _66___v87 = _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); @@ -4729,24 +4710,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___v120; + Defs._IOwnership _71___v91; 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___v120 = _out62; + _71___v91 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v121; + Defs._IOwnership _74___v92; 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___v121 = _out65; + _74___v92 = _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; @@ -4785,14 +4766,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___v122; + Defs._IOwnership _84___v93; 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___v122 = _out71; + _84___v93 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -4823,14 +4804,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___v123; + Defs._IOwnership _90___v94; 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___v123 = _out76; + _90___v94 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -4858,14 +4839,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___v124; + Defs._IOwnership _96___v95; 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___v124 = _out81; + _96___v95 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -4887,14 +4868,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___v125; + Defs._IOwnership _100___v96; 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___v125 = _out86; + _100___v96 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -4919,24 +4900,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v126; + Defs._IOwnership _106___v97; Dafny.ISet> _107_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___v126 = _out91; + _106___v97 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v127; + Defs._IOwnership _109___v98; Dafny.ISet> _110_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___v127 = _out94; + _109___v98 = _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); @@ -4971,14 +4952,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v128; + Defs._IOwnership _118___v99; 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___v128 = _out99; + _118___v99 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5019,14 +5000,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v129; + Defs._IOwnership _130___v100; 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___v129 = _out110; + _130___v100 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5107,14 +5088,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v130; + Defs._IOwnership _145___v101; 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___v130 = _out127; + _145___v101 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5127,14 +5108,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v131; + Defs._IOwnership _151___v102; 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___v131 = _out133; + _151___v102 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5156,14 +5137,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v132; + Defs._IOwnership _156___v103; 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___v132 = _out138; + _156___v103 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5186,16 +5167,16 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v133; + Defs._IOwnership _161___v104; 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___v133 = _out143; + _161___v104 = _out143; _162_recIdents = _out144; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("~"), _160_recursiveGen, _159_format); + 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); @@ -5258,14 +5239,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v138; + Defs._IOwnership _173___v109; 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___v138 = _out156; + _173___v109 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5307,14 +5288,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v139; + Defs._IOwnership _179___v110; 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___v139 = _out163; + _179___v110 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5333,14 +5314,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v140; + Defs._IOwnership _183___v111; 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___v140 = _out168; + _183___v111 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5359,14 +5340,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v141; + Defs._IOwnership _187___v112; 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___v141 = _out173; + _187___v112 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5438,15 +5419,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v142; - Dafny.ISet> _213___v143; + Defs._IOwnership _212___v113; + Dafny.ISet> _213___v114; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; - (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((_210_ty).CanReadWithoutClone()) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); + (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v142 = _out182; - _213___v143 = _out183; + _212___v113 = _out182; + _213___v114 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -5520,40 +5501,60 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _227_onOwned = _out192; _228_recIdents = _out193; r = ((_226_onExpr).Sel(Defs.__default.escapeVar(_219_field))).Apply0(); - RAST._IType _229_typ; - RAST._IType _out194; - _out194 = (this).GenType(_222_fieldType, Defs.GenTypeContext.@default()); - _229_typ = _out194; - RAST._IExpr _out195; - Defs._IOwnership _out196; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipBorrowed(), expectedOwnership, out _out195, out _out196); - r = _out195; - resultingOwnership = _out196; + Defs._IOwnership _229_originalMutability; + _229_originalMutability = Defs.Ownership.create_OwnershipOwned(); + DAST._IFieldMutability _source2 = _220_fieldMutability; + { + if (_source2.is_ConstantField) { + goto after_match2; + } + } + { + if (_source2.is_InternalClassConstantFieldOrDatatypeDestructor) { + _229_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; + } + after_match2: ; + RAST._IType _230_typ; + RAST._IType _out195; + _out195 = (this).GenType(_222_fieldType, Defs.GenTypeContext.@default()); + _230_typ = _out195; + RAST._IExpr _out196; + Defs._IOwnership _out197; + (this).FromOwnership(r, _229_originalMutability, expectedOwnership, out _out196, out _out197); + r = _out196; + resultingOwnership = _out197; readIdents = _228_recIdents; } else { - RAST._IExpr _230_onExpr; - Defs._IOwnership _231_onOwned; - Dafny.ISet> _232_recIdents; - RAST._IExpr _out197; - Defs._IOwnership _out198; - Dafny.ISet> _out199; - (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out197, out _out198, out _out199); - _230_onExpr = _out197; - _231_onOwned = _out198; - _232_recIdents = _out199; - r = _230_onExpr; - if (!object.Equals(_230_onExpr, RAST.__default.self)) { - RAST._IExpr _source2 = _230_onExpr; + RAST._IExpr _231_onExpr; + Defs._IOwnership _232_onOwned; + Dafny.ISet> _233_recIdents; + RAST._IExpr _out198; + Defs._IOwnership _out199; + Dafny.ISet> _out200; + (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out198, out _out199, out _out200); + _231_onExpr = _out198; + _232_onOwned = _out199; + _233_recIdents = _out200; + r = _231_onExpr; + if (!object.Equals(_231_onExpr, RAST.__default.self)) { + RAST._IExpr _source3 = _231_onExpr; { - if (_source2.is_UnaryOp) { - Dafny.ISequence op10 = _source2.dtor_op1; + if (_source3.is_UnaryOp) { + Dafny.ISequence op10 = _source3.dtor_op1; if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { - RAST._IExpr underlying0 = _source2.dtor_underlying; + RAST._IExpr underlying0 = _source3.dtor_underlying; if (underlying0.is_Identifier) { Dafny.ISequence name0 = underlying0.dtor_name; if (object.Equals(name0, Dafny.Sequence.UnicodeFromString("this"))) { r = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")); - goto after_match2; + goto after_match3; } } } @@ -5561,37 +5562,37 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { } - after_match2: ; + after_match3: ; if (((this).pointerType).is_RcMut) { r = (r).Clone(); } r = ((this).read__macro).Apply1(r); } r = (r).Sel(Defs.__default.escapeVar(_219_field)); - DAST._IFieldMutability _source3 = _220_fieldMutability; + DAST._IFieldMutability _source4 = _220_fieldMutability; { - if (_source3.is_ConstantField) { + if (_source4.is_ConstantField) { r = (r).Apply0(); r = (r).Clone(); - goto after_match3; + goto after_match4; } } { - if (_source3.is_InternalClassConstantField) { + if (_source4.is_InternalClassConstantFieldOrDatatypeDestructor) { r = (r).Clone(); - goto after_match3; + goto after_match4; } } { r = ((this).read__mutable__field__macro).Apply1(r); } - after_match3: ; - RAST._IExpr _out200; - Defs._IOwnership _out201; - (this).FromOwned(r, expectedOwnership, out _out200, out _out201); - r = _out200; - resultingOwnership = _out201; - readIdents = _232_recIdents; + after_match4: ; + RAST._IExpr _out201; + Defs._IOwnership _out202; + (this).FromOwned(r, expectedOwnership, out _out201, out _out202); + r = _out201; + resultingOwnership = _out202; + readIdents = _233_recIdents; } return ; } @@ -5600,70 +5601,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 _234_on = _source0.dtor_expr; + DAST._ICollKind _235_collKind = _source0.dtor_collKind; + Dafny.ISequence _236_indices = _source0.dtor_indices; { - RAST._IExpr _236_onExpr; - Defs._IOwnership _237_onOwned; - Dafny.ISet> _238_recIdents; - RAST._IExpr _out202; - Defs._IOwnership _out203; - Dafny.ISet> _out204; - (this).GenExpr(_233_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out202, out _out203, out _out204); - _236_onExpr = _out202; - _237_onOwned = _out203; - _238_recIdents = _out204; - readIdents = _238_recIdents; - r = _236_onExpr; - bool _239_hadArray; - _239_hadArray = false; - if (object.Equals(_234_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _237_onExpr; + Defs._IOwnership _238_onOwned; + Dafny.ISet> _239_recIdents; + RAST._IExpr _out203; + Defs._IOwnership _out204; + Dafny.ISet> _out205; + (this).GenExpr(_234_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out203, out _out204, out _out205); + _237_onExpr = _out203; + _238_onOwned = _out204; + _239_recIdents = _out205; + readIdents = _239_recIdents; + r = _237_onExpr; + bool _240_hadArray; + _240_hadArray = false; + if (object.Equals(_235_collKind, DAST.CollKind.create_Array())) { r = ((this).read__macro).Apply1(r); - _239_hadArray = true; - if ((new BigInteger((_235_indices).Count)) > (BigInteger.One)) { + _240_hadArray = true; + if ((new BigInteger((_236_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 _out205; - Defs._IOwnership _out206; - Dafny.ISet> _out207; - (this).GenExpr((_235_indices).Select(_240_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out205, out _out206, out _out207); - _241_idx = _out205; - _242_idxOwned = _out206; - _243_recIdentsIdx = _out207; - _241_idx = RAST.__default.IntoUsize(_241_idx); - r = RAST.Expr.create_SelectIndex(r, _241_idx); - readIdents = Dafny.Set>.Union(readIdents, _243_recIdentsIdx); + BigInteger _hi10 = new BigInteger((_236_indices).Count); + for (BigInteger _241_i = BigInteger.Zero; _241_i < _hi10; _241_i++) { + if (object.Equals(_235_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _242_idx; + Defs._IOwnership _243_idxOwned; + Dafny.ISet> _244_recIdentsIdx; + RAST._IExpr _out206; + Defs._IOwnership _out207; + Dafny.ISet> _out208; + (this).GenExpr((_236_indices).Select(_241_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out206, out _out207, out _out208); + _242_idx = _out206; + _243_idxOwned = _out207; + _244_recIdentsIdx = _out208; + _242_idx = RAST.__default.IntoUsize(_242_idx); + r = RAST.Expr.create_SelectIndex(r, _242_idx); + readIdents = Dafny.Set>.Union(readIdents, _244_recIdentsIdx); } else { - RAST._IExpr _244_idx; - Defs._IOwnership _245_idxOwned; - Dafny.ISet> _246_recIdentsIdx; - RAST._IExpr _out208; - Defs._IOwnership _out209; - Dafny.ISet> _out210; - (this).GenExpr((_235_indices).Select(_240_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out208, out _out209, out _out210); - _244_idx = _out208; - _245_idxOwned = _out209; - _246_recIdentsIdx = _out210; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_244_idx); - readIdents = Dafny.Set>.Union(readIdents, _246_recIdentsIdx); + RAST._IExpr _245_idx; + Defs._IOwnership _246_idxOwned; + Dafny.ISet> _247_recIdentsIdx; + RAST._IExpr _out209; + Defs._IOwnership _out210; + Dafny.ISet> _out211; + (this).GenExpr((_236_indices).Select(_241_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out209, out _out210, out _out211); + _245_idx = _out209; + _246_idxOwned = _out210; + _247_recIdentsIdx = _out211; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_245_idx); + readIdents = Dafny.Set>.Union(readIdents, _247_recIdentsIdx); } } - if (_239_hadArray) { + if (_240_hadArray) { r = (r).Clone(); } - RAST._IExpr _out211; - Defs._IOwnership _out212; - (this).FromOwned(r, expectedOwnership, out _out211, out _out212); - r = _out211; - resultingOwnership = _out212; + RAST._IExpr _out212; + Defs._IOwnership _out213; + (this).FromOwned(r, expectedOwnership, out _out212, out _out213); + r = _out212; + resultingOwnership = _out213; return ; } goto after_match0; @@ -5671,118 +5672,118 @@ 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 _248_on = _source0.dtor_expr; + bool _249_isArray = _source0.dtor_isArray; + Std.Wrappers._IOption _250_low = _source0.dtor_low; + Std.Wrappers._IOption _251_high = _source0.dtor_high; { - Defs._IOwnership _251_onExpectedOwnership; - if (_248_isArray) { + Defs._IOwnership _252_onExpectedOwnership; + if (_249_isArray) { if (((this).pointerType).is_Raw) { - _251_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); + _252_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); } else { - _251_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); + _252_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 _out213; - Defs._IOwnership _out214; - Dafny.ISet> _out215; - (this).GenExpr(_247_on, selfIdent, env, _251_onExpectedOwnership, out _out213, out _out214, out _out215); - _252_onExpr = _out213; - _253_onOwned = _out214; - _254_recIdents = _out215; - readIdents = _254_recIdents; - Dafny.ISequence _255_methodName; - if ((_249_low).is_Some) { - if ((_250_high).is_Some) { - _255_methodName = Dafny.Sequence.UnicodeFromString("slice"); + _252_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); + } + RAST._IExpr _253_onExpr; + Defs._IOwnership _254_onOwned; + Dafny.ISet> _255_recIdents; + RAST._IExpr _out214; + Defs._IOwnership _out215; + Dafny.ISet> _out216; + (this).GenExpr(_248_on, selfIdent, env, _252_onExpectedOwnership, out _out214, out _out215, out _out216); + _253_onExpr = _out214; + _254_onOwned = _out215; + _255_recIdents = _out216; + readIdents = _255_recIdents; + Dafny.ISequence _256_methodName; + if ((_250_low).is_Some) { + if ((_251_high).is_Some) { + _256_methodName = Dafny.Sequence.UnicodeFromString("slice"); } else { - _255_methodName = Dafny.Sequence.UnicodeFromString("drop"); + _256_methodName = Dafny.Sequence.UnicodeFromString("drop"); } - } else if ((_250_high).is_Some) { - _255_methodName = Dafny.Sequence.UnicodeFromString("take"); + } else if ((_251_high).is_Some) { + _256_methodName = Dafny.Sequence.UnicodeFromString("take"); } else { - _255_methodName = Dafny.Sequence.UnicodeFromString(""); + _256_methodName = Dafny.Sequence.UnicodeFromString(""); } - Dafny.ISequence _256_arguments; - _256_arguments = Dafny.Sequence.FromElements(); - Std.Wrappers._IOption _source4 = _249_low; + Dafny.ISequence _257_arguments; + _257_arguments = Dafny.Sequence.FromElements(); + Std.Wrappers._IOption _source5 = _250_low; { - if (_source4.is_Some) { - DAST._IExpression _257_l = _source4.dtor_value; + if (_source5.is_Some) { + DAST._IExpression _258_l = _source5.dtor_value; { - RAST._IExpr _258_lExpr; - Defs._IOwnership _259___v146; - Dafny.ISet> _260_recIdentsL; - RAST._IExpr _out216; - Defs._IOwnership _out217; - Dafny.ISet> _out218; - (this).GenExpr(_257_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out216, out _out217, out _out218); - _258_lExpr = _out216; - _259___v146 = _out217; - _260_recIdentsL = _out218; - _256_arguments = Dafny.Sequence.Concat(_256_arguments, Dafny.Sequence.FromElements(_258_lExpr)); - readIdents = Dafny.Set>.Union(readIdents, _260_recIdentsL); + RAST._IExpr _259_lExpr; + Defs._IOwnership _260___v117; + Dafny.ISet> _261_recIdentsL; + RAST._IExpr _out217; + Defs._IOwnership _out218; + Dafny.ISet> _out219; + (this).GenExpr(_258_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out217, out _out218, out _out219); + _259_lExpr = _out217; + _260___v117 = _out218; + _261_recIdentsL = _out219; + _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_259_lExpr)); + readIdents = Dafny.Set>.Union(readIdents, _261_recIdentsL); } - goto after_match4; + goto after_match5; } } { } - after_match4: ; - Std.Wrappers._IOption _source5 = _250_high; + after_match5: ; + Std.Wrappers._IOption _source6 = _251_high; { - if (_source5.is_Some) { - DAST._IExpression _261_h = _source5.dtor_value; + if (_source6.is_Some) { + DAST._IExpression _262_h = _source6.dtor_value; { - RAST._IExpr _262_hExpr; - Defs._IOwnership _263___v147; - Dafny.ISet> _264_recIdentsH; - RAST._IExpr _out219; - Defs._IOwnership _out220; - Dafny.ISet> _out221; - (this).GenExpr(_261_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out219, out _out220, out _out221); - _262_hExpr = _out219; - _263___v147 = _out220; - _264_recIdentsH = _out221; - _256_arguments = Dafny.Sequence.Concat(_256_arguments, Dafny.Sequence.FromElements(_262_hExpr)); - readIdents = Dafny.Set>.Union(readIdents, _264_recIdentsH); + RAST._IExpr _263_hExpr; + Defs._IOwnership _264___v118; + Dafny.ISet> _265_recIdentsH; + RAST._IExpr _out220; + Defs._IOwnership _out221; + Dafny.ISet> _out222; + (this).GenExpr(_262_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out220, out _out221, out _out222); + _263_hExpr = _out220; + _264___v118 = _out221; + _265_recIdentsH = _out222; + _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_263_hExpr)); + readIdents = Dafny.Set>.Union(readIdents, _265_recIdentsH); } - goto after_match5; + goto after_match6; } } { } - after_match5: ; - r = _252_onExpr; - if (_248_isArray) { - if (!(_255_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - _255_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _255_methodName); + after_match6: ; + r = _253_onExpr; + if (_249_isArray) { + if (!(_256_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + _256_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _256_methodName); } - Dafny.ISequence _265_object__suffix; + Dafny.ISequence _266_object__suffix; if (((this).pointerType).is_Raw) { - _265_object__suffix = Dafny.Sequence.UnicodeFromString(""); + _266_object__suffix = Dafny.Sequence.UnicodeFromString(""); } else { - _265_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); + _266_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"), _256_methodName), _266_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_253_onExpr), _257_arguments)); } else { - if (!(_255_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - r = ((r).Sel(_255_methodName)).Apply(_256_arguments); + if (!(_256_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + r = ((r).Sel(_256_methodName)).Apply(_257_arguments); } else { r = (r).Clone(); } } - RAST._IExpr _out222; - Defs._IOwnership _out223; - (this).FromOwned(r, expectedOwnership, out _out222, out _out223); - r = _out222; - resultingOwnership = _out223; + RAST._IExpr _out223; + Defs._IOwnership _out224; + (this).FromOwned(r, expectedOwnership, out _out223, out _out224); + r = _out223; + resultingOwnership = _out224; return ; } goto after_match0; @@ -5790,42 +5791,42 @@ 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 _267_on = _source0.dtor_expr; + BigInteger _268_idx = _source0.dtor_index; + DAST._IType _269_fieldType = _source0.dtor_fieldType; { - RAST._IExpr _269_onExpr; - Defs._IOwnership _270_onOwnership; - Dafny.ISet> _271_recIdents; - RAST._IExpr _out224; - Defs._IOwnership _out225; - Dafny.ISet> _out226; - (this).GenExpr(_266_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out224, out _out225, out _out226); - _269_onExpr = _out224; - _270_onOwnership = _out225; - _271_recIdents = _out226; - Dafny.ISequence _272_selName; - _272_selName = Std.Strings.__default.OfNat(_267_idx); - DAST._IType _source6 = _268_fieldType; + RAST._IExpr _270_onExpr; + Defs._IOwnership _271_onOwnership; + Dafny.ISet> _272_recIdents; + RAST._IExpr _out225; + Defs._IOwnership _out226; + Dafny.ISet> _out227; + (this).GenExpr(_267_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out225, out _out226, out _out227); + _270_onExpr = _out225; + _271_onOwnership = _out226; + _272_recIdents = _out227; + Dafny.ISequence _273_selName; + _273_selName = Std.Strings.__default.OfNat(_268_idx); + DAST._IType _source7 = _269_fieldType; { - if (_source6.is_Tuple) { - Dafny.ISequence _273_tps = _source6.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); + if (_source7.is_Tuple) { + Dafny.ISequence _274_tps = _source7.dtor_Tuple_a0; + if (((_269_fieldType).is_Tuple) && ((new BigInteger((_274_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { + _273_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _273_selName); } - goto after_match6; + goto after_match7; } } { } - after_match6: ; - r = ((_269_onExpr).Sel(_272_selName)).Clone(); - RAST._IExpr _out227; - Defs._IOwnership _out228; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out227, out _out228); - r = _out227; - resultingOwnership = _out228; - readIdents = _271_recIdents; + after_match7: ; + r = ((_270_onExpr).Sel(_273_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 = _272_recIdents; return ; } goto after_match0; @@ -5833,229 +5834,229 @@ 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 _275_on = _source0.dtor_on; + DAST._ICallName _276_name = _source0.dtor_callName; + Dafny.ISequence _277_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _278_args = _source0.dtor_args; { - Dafny.ISequence _278_argExprs; - Dafny.ISet> _279_recIdents; - Dafny.ISequence _280_typeExprs; - Std.Wrappers._IOption _281_fullNameQualifier; - Dafny.ISequence _out229; - Dafny.ISet> _out230; - Dafny.ISequence _out231; - Std.Wrappers._IOption _out232; - (this).GenArgs(selfIdent, _275_name, _276_typeArgs, _277_args, env, out _out229, out _out230, out _out231, out _out232); - _278_argExprs = _out229; - _279_recIdents = _out230; - _280_typeExprs = _out231; - _281_fullNameQualifier = _out232; - readIdents = _279_recIdents; - Std.Wrappers._IOption _source7 = _281_fullNameQualifier; + Dafny.ISequence _279_argExprs; + Dafny.ISet> _280_recIdents; + Dafny.ISequence _281_typeExprs; + Std.Wrappers._IOption _282_fullNameQualifier; + Dafny.ISequence _out230; + Dafny.ISet> _out231; + Dafny.ISequence _out232; + Std.Wrappers._IOption _out233; + (this).GenArgs(selfIdent, _276_name, _277_typeArgs, _278_args, env, out _out230, out _out231, out _out232, out _out233); + _279_argExprs = _out230; + _280_recIdents = _out231; + _281_typeExprs = _out232; + _282_fullNameQualifier = _out233; + readIdents = _280_recIdents; + Std.Wrappers._IOption _source8 = _282_fullNameQualifier; { - if (_source7.is_Some) { - DAST._IResolvedType value0 = _source7.dtor_value; - Dafny.ISequence> _282_path = value0.dtor_path; - Dafny.ISequence _283_onTypeArgs = value0.dtor_typeArgs; - DAST._IResolvedTypeBase _284_base = value0.dtor_kind; - RAST._IExpr _285_fullPath; - RAST._IExpr _out233; - _out233 = (this).GenPathExpr(_282_path, true); - _285_fullPath = _out233; - Dafny.ISequence _286_onTypeExprs; - Dafny.ISequence _out234; - _out234 = (this).GenTypeArgs(_283_onTypeArgs, Defs.GenTypeContext.@default()); - _286_onTypeExprs = _out234; - RAST._IExpr _287_onExpr = RAST.Expr.Default(); - Defs._IOwnership _288_recOwnership = Defs.Ownership.Default(); - Dafny.ISet> _289_recIdents = Dafny.Set>.Empty; - if (((_284_base).is_Trait) || ((_284_base).is_Class)) { - RAST._IExpr _out235; - Defs._IOwnership _out236; - Dafny.ISet> _out237; - (this).GenExpr(_274_on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out235, out _out236, out _out237); - _287_onExpr = _out235; - _288_recOwnership = _out236; - _289_recIdents = _out237; - _287_onExpr = ((this).read__macro).Apply1(_287_onExpr); - readIdents = Dafny.Set>.Union(readIdents, _289_recIdents); + if (_source8.is_Some) { + DAST._IResolvedType value0 = _source8.dtor_value; + Dafny.ISequence> _283_path = value0.dtor_path; + Dafny.ISequence _284_onTypeArgs = value0.dtor_typeArgs; + DAST._IResolvedTypeBase _285_base = value0.dtor_kind; + RAST._IExpr _286_fullPath; + RAST._IExpr _out234; + _out234 = (this).GenPathExpr(_283_path, true); + _286_fullPath = _out234; + Dafny.ISequence _287_onTypeExprs; + Dafny.ISequence _out235; + _out235 = (this).GenTypeArgs(_284_onTypeArgs, Defs.GenTypeContext.@default()); + _287_onTypeExprs = _out235; + RAST._IExpr _288_onExpr = RAST.Expr.Default(); + Defs._IOwnership _289_recOwnership = Defs.Ownership.Default(); + Dafny.ISet> _290_recIdents = Dafny.Set>.Empty; + if (((_285_base).is_Trait) || ((_285_base).is_Class)) { + RAST._IExpr _out236; + Defs._IOwnership _out237; + Dafny.ISet> _out238; + (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out236, out _out237, out _out238); + _288_onExpr = _out236; + _289_recOwnership = _out237; + _290_recIdents = _out238; + _288_onExpr = ((this).read__macro).Apply1(_288_onExpr); + readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); } else { - RAST._IExpr _out238; - Defs._IOwnership _out239; - Dafny.ISet> _out240; - (this).GenExpr(_274_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out238, out _out239, out _out240); - _287_onExpr = _out238; - _288_recOwnership = _out239; - _289_recIdents = _out240; - readIdents = Dafny.Set>.Union(readIdents, _289_recIdents); + RAST._IExpr _out239; + Defs._IOwnership _out240; + Dafny.ISet> _out241; + (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out239, out _out240, out _out241); + _288_onExpr = _out239; + _289_recOwnership = _out240; + _290_recIdents = _out241; + readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); } - r = ((((_285_fullPath).ApplyType(_286_onTypeExprs)).FSel(Defs.__default.escapeName((_275_name).dtor_name))).ApplyType(_280_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_287_onExpr), _278_argExprs)); - RAST._IExpr _out241; - Defs._IOwnership _out242; - (this).FromOwned(r, expectedOwnership, out _out241, out _out242); - r = _out241; - resultingOwnership = _out242; - goto after_match7; + r = ((((_286_fullPath).ApplyType(_287_onTypeExprs)).FSel(Defs.__default.escapeName((_276_name).dtor_name))).ApplyType(_281_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_288_onExpr), _279_argExprs)); + RAST._IExpr _out242; + Defs._IOwnership _out243; + (this).FromOwned(r, expectedOwnership, out _out242, out _out243); + r = _out242; + resultingOwnership = _out243; + goto after_match8; } } { - RAST._IExpr _290_onExpr; - Defs._IOwnership _291___v153; - Dafny.ISet> _292_recIdents; - RAST._IExpr _out243; - Defs._IOwnership _out244; - Dafny.ISet> _out245; - (this).GenExpr(_274_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out243, out _out244, out _out245); - _290_onExpr = _out243; - _291___v153 = _out244; - _292_recIdents = _out245; - readIdents = Dafny.Set>.Union(readIdents, _292_recIdents); - Dafny.ISequence _293_renderedName; - _293_renderedName = (this).GetMethodName(_274_on, _275_name); - DAST._IExpression _source8 = _274_on; + RAST._IExpr _291_onExpr; + Defs._IOwnership _292___v124; + Dafny.ISet> _293_recIdents; + RAST._IExpr _out244; + Defs._IOwnership _out245; + Dafny.ISet> _out246; + (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out244, out _out245, out _out246); + _291_onExpr = _out244; + _292___v124 = _out245; + _293_recIdents = _out246; + readIdents = Dafny.Set>.Union(readIdents, _293_recIdents); + Dafny.ISequence _294_renderedName; + _294_renderedName = (this).GetMethodName(_275_on, _276_name); + DAST._IExpression _source9 = _275_on; { bool disjunctiveMatch0 = false; - if (_source8.is_Companion) { + if (_source9.is_Companion) { disjunctiveMatch0 = true; } - if (_source8.is_ExternCompanion) { + if (_source9.is_ExternCompanion) { disjunctiveMatch0 = true; } if (disjunctiveMatch0) { { - _290_onExpr = (_290_onExpr).FSel(_293_renderedName); + _291_onExpr = (_291_onExpr).FSel(_294_renderedName); } - goto after_match8; + goto after_match9; } } { { - if (!object.Equals(_290_onExpr, RAST.__default.self)) { - DAST._ICallName _source9 = _275_name; + if (!object.Equals(_291_onExpr, RAST.__default.self)) { + DAST._ICallName _source10 = _276_name; { - if (_source9.is_CallName) { - Std.Wrappers._IOption onType0 = _source9.dtor_onType; + if (_source10.is_CallName) { + Std.Wrappers._IOption onType0 = _source10.dtor_onType; if (onType0.is_Some) { - DAST._IType _294_tpe = onType0.dtor_value; - RAST._IType _295_typ; - RAST._IType _out246; - _out246 = (this).GenType(_294_tpe, Defs.GenTypeContext.@default()); - _295_typ = _out246; - if ((_295_typ).IsObjectOrPointer()) { - _290_onExpr = ((this).read__macro).Apply1(_290_onExpr); + DAST._IType _295_tpe = onType0.dtor_value; + RAST._IType _296_typ; + RAST._IType _out247; + _out247 = (this).GenType(_295_tpe, Defs.GenTypeContext.@default()); + _296_typ = _out247; + if ((_296_typ).IsObjectOrPointer()) { + _291_onExpr = ((this).read__macro).Apply1(_291_onExpr); } - goto after_match9; + goto after_match10; } } } { } - after_match9: ; + after_match10: ; } - _290_onExpr = (_290_onExpr).Sel(_293_renderedName); + _291_onExpr = (_291_onExpr).Sel(_294_renderedName); } } - after_match8: ; - r = ((_290_onExpr).ApplyType(_280_typeExprs)).Apply(_278_argExprs); - RAST._IExpr _out247; - Defs._IOwnership _out248; - (this).FromOwned(r, expectedOwnership, out _out247, out _out248); - r = _out247; - resultingOwnership = _out248; + after_match9: ; + r = ((_291_onExpr).ApplyType(_281_typeExprs)).Apply(_279_argExprs); + RAST._IExpr _out248; + Defs._IOwnership _out249; + (this).FromOwned(r, expectedOwnership, out _out248, out _out249); + r = _out248; + resultingOwnership = _out249; return ; } - after_match7: ; + after_match8: ; } goto after_match0; } } { if (_source0.is_Lambda) { - Dafny.ISequence _296_paramsDafny = _source0.dtor_params; - DAST._IType _297_retType = _source0.dtor_retType; - Dafny.ISequence _298_body = _source0.dtor_body; + Dafny.ISequence _297_paramsDafny = _source0.dtor_params; + DAST._IType _298_retType = _source0.dtor_retType; + Dafny.ISequence _299_body = _source0.dtor_body; { - Dafny.ISequence _299_params; - Dafny.ISequence _out249; - _out249 = (this).GenParams(_296_paramsDafny, true); - _299_params = _out249; - Dafny.ISequence> _300_paramNames; - _300_paramNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _301_paramTypesMap; - _301_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); - BigInteger _hi11 = new BigInteger((_299_params).Count); - for (BigInteger _302_i = BigInteger.Zero; _302_i < _hi11; _302_i++) { - Dafny.ISequence _303_name; - _303_name = ((_299_params).Select(_302_i)).dtor_name; - _300_paramNames = Dafny.Sequence>.Concat(_300_paramNames, Dafny.Sequence>.FromElements(_303_name)); - _301_paramTypesMap = Dafny.Map, RAST._IType>.Update(_301_paramTypesMap, _303_name, ((_299_params).Select(_302_i)).dtor_tpe); - } - Defs._IEnvironment _304_subEnv; - _304_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_300_paramNames, _301_paramTypesMap)); - RAST._IExpr _305_recursiveGen; - Dafny.ISet> _306_recIdents; - Defs._IEnvironment _307___v163; - RAST._IExpr _out250; - Dafny.ISet> _out251; - Defs._IEnvironment _out252; - (this).GenStmts(_298_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _304_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out250, out _out251, out _out252); - _305_recursiveGen = _out250; - _306_recIdents = _out251; - _307___v163 = _out252; + Dafny.ISequence _300_params; + Dafny.ISequence _out250; + _out250 = (this).GenParams(_297_paramsDafny, true); + _300_params = _out250; + Dafny.ISequence> _301_paramNames; + _301_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _302_paramTypesMap; + _302_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi11 = new BigInteger((_300_params).Count); + for (BigInteger _303_i = BigInteger.Zero; _303_i < _hi11; _303_i++) { + Dafny.ISequence _304_name; + _304_name = ((_300_params).Select(_303_i)).dtor_name; + _301_paramNames = Dafny.Sequence>.Concat(_301_paramNames, Dafny.Sequence>.FromElements(_304_name)); + _302_paramTypesMap = Dafny.Map, RAST._IType>.Update(_302_paramTypesMap, _304_name, ((_300_params).Select(_303_i)).dtor_tpe); + } + Defs._IEnvironment _305_subEnv; + _305_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_301_paramNames, _302_paramTypesMap)); + RAST._IExpr _306_recursiveGen; + Dafny.ISet> _307_recIdents; + Defs._IEnvironment _308___v134; + RAST._IExpr _out251; + Dafny.ISet> _out252; + Defs._IEnvironment _out253; + (this).GenStmts(_299_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _305_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out251, out _out252, out _out253); + _306_recursiveGen = _out251; + _307_recIdents = _out252; + _308___v134 = _out253; readIdents = Dafny.Set>.FromElements(); - _306_recIdents = Dafny.Set>.Difference(_306_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_308_paramNames) => ((System.Func>>)(() => { + _307_recIdents = Dafny.Set>.Difference(_307_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_309_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (Dafny.ISequence _compr_0 in (_308_paramNames).CloneAsArray()) { - Dafny.ISequence _309_name = (Dafny.ISequence)_compr_0; - if ((_308_paramNames).Contains(_309_name)) { - _coll0.Add(_309_name); + foreach (Dafny.ISequence _compr_0 in (_309_paramNames).CloneAsArray()) { + Dafny.ISequence _310_name = (Dafny.ISequence)_compr_0; + if ((_309_paramNames).Contains(_310_name)) { + _coll0.Add(_310_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_300_paramNames)); - RAST._IExpr _310_allReadCloned; - _310_allReadCloned = (this).InitEmptyExpr(); - while (!(_306_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _311_next; - foreach (Dafny.ISequence _assign_such_that_1 in (_306_recIdents).Elements) { - _311_next = (Dafny.ISequence)_assign_such_that_1; - if ((_306_recIdents).Contains(_311_next)) { + }))())(_301_paramNames)); + RAST._IExpr _311_allReadCloned; + _311_allReadCloned = (this).InitEmptyExpr(); + while (!(_307_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _312_next; + foreach (Dafny.ISequence _assign_such_that_1 in (_307_recIdents).Elements) { + _312_next = (Dafny.ISequence)_assign_such_that_1; + if ((_307_recIdents).Contains(_312_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())) && ((_311_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { - RAST._IExpr _312_selfCloned; - Defs._IOwnership _313___v164; - Dafny.ISet> _314___v165; - RAST._IExpr _out253; - Defs._IOwnership _out254; - Dafny.ISet> _out255; - (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out253, out _out254, out _out255); - _312_selfCloned = _out253; - _313___v164 = _out254; - _314___v165 = _out255; - _310_allReadCloned = (_310_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_312_selfCloned))); - } else if (!((_300_paramNames).Contains(_311_next))) { - RAST._IExpr _315_copy; - _315_copy = (RAST.Expr.create_Identifier(_311_next)).Clone(); - _310_allReadCloned = (_310_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _311_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_315_copy))); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_311_next)); + if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_312_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + RAST._IExpr _313_selfCloned; + Defs._IOwnership _314___v135; + Dafny.ISet> _315___v136; + RAST._IExpr _out254; + Defs._IOwnership _out255; + Dafny.ISet> _out256; + (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out254, out _out255, out _out256); + _313_selfCloned = _out254; + _314___v135 = _out255; + _315___v136 = _out256; + _311_allReadCloned = (_311_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_313_selfCloned))); + } else if (!((_301_paramNames).Contains(_312_next))) { + RAST._IExpr _316_copy; + _316_copy = (RAST.Expr.create_Identifier(_312_next)).Clone(); + _311_allReadCloned = (_311_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _312_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_316_copy))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_312_next)); } - _306_recIdents = Dafny.Set>.Difference(_306_recIdents, Dafny.Set>.FromElements(_311_next)); - } - RAST._IType _316_retTypeGen; - RAST._IType _out256; - _out256 = (this).GenType(_297_retType, Defs.GenTypeContext.@default()); - _316_retTypeGen = _out256; - r = RAST.Expr.create_Block((_310_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_299_params, Std.Wrappers.Option.create_Some(_316_retTypeGen), RAST.Expr.create_Block(_305_recursiveGen))))); - RAST._IExpr _out257; - Defs._IOwnership _out258; - (this).FromOwned(r, expectedOwnership, out _out257, out _out258); - r = _out257; - resultingOwnership = _out258; + _307_recIdents = Dafny.Set>.Difference(_307_recIdents, Dafny.Set>.FromElements(_312_next)); + } + RAST._IType _317_retTypeGen; + RAST._IType _out257; + _out257 = (this).GenType(_298_retType, Defs.GenTypeContext.@default()); + _317_retTypeGen = _out257; + r = RAST.Expr.create_Block((_311_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_300_params, Std.Wrappers.Option.create_Some(_317_retTypeGen), RAST.Expr.create_Block(_306_recursiveGen))))); + RAST._IExpr _out258; + Defs._IOwnership _out259; + (this).FromOwned(r, expectedOwnership, out _out258, out _out259); + r = _out258; + resultingOwnership = _out259; return ; } goto after_match0; @@ -6063,72 +6064,72 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _317_values = _source0.dtor_values; - DAST._IType _318_retType = _source0.dtor_retType; - DAST._IExpression _319_expr = _source0.dtor_expr; + Dafny.ISequence<_System._ITuple2> _318_values = _source0.dtor_values; + DAST._IType _319_retType = _source0.dtor_retType; + DAST._IExpression _320_expr = _source0.dtor_expr; { - Dafny.ISequence> _320_paramNames; - _320_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISequence _321_paramFormals; - Dafny.ISequence _out259; - _out259 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_322_value) => { - return (_322_value).dtor__0; - })), _317_values), false); - _321_paramFormals = _out259; - Dafny.IMap,RAST._IType> _323_paramTypes; - _323_paramTypes = Dafny.Map, RAST._IType>.FromElements(); - Dafny.ISet> _324_paramNamesSet; - _324_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _hi12 = new BigInteger((_317_values).Count); - for (BigInteger _325_i = BigInteger.Zero; _325_i < _hi12; _325_i++) { - Dafny.ISequence _326_name; - _326_name = (((_317_values).Select(_325_i)).dtor__0).dtor_name; - Dafny.ISequence _327_rName; - _327_rName = Defs.__default.escapeVar(_326_name); - _320_paramNames = Dafny.Sequence>.Concat(_320_paramNames, Dafny.Sequence>.FromElements(_327_rName)); - _323_paramTypes = Dafny.Map, RAST._IType>.Update(_323_paramTypes, _327_rName, ((_321_paramFormals).Select(_325_i)).dtor_tpe); - _324_paramNamesSet = Dafny.Set>.Union(_324_paramNamesSet, Dafny.Set>.FromElements(_327_rName)); + Dafny.ISequence> _321_paramNames; + _321_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _322_paramFormals; + Dafny.ISequence _out260; + _out260 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_323_value) => { + return (_323_value).dtor__0; + })), _318_values), false); + _322_paramFormals = _out260; + Dafny.IMap,RAST._IType> _324_paramTypes; + _324_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _325_paramNamesSet; + _325_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi12 = new BigInteger((_318_values).Count); + for (BigInteger _326_i = BigInteger.Zero; _326_i < _hi12; _326_i++) { + Dafny.ISequence _327_name; + _327_name = (((_318_values).Select(_326_i)).dtor__0).dtor_name; + Dafny.ISequence _328_rName; + _328_rName = Defs.__default.escapeVar(_327_name); + _321_paramNames = Dafny.Sequence>.Concat(_321_paramNames, Dafny.Sequence>.FromElements(_328_rName)); + _324_paramTypes = Dafny.Map, RAST._IType>.Update(_324_paramTypes, _328_rName, ((_322_paramFormals).Select(_326_i)).dtor_tpe); + _325_paramNamesSet = Dafny.Set>.Union(_325_paramNamesSet, Dafny.Set>.FromElements(_328_rName)); } readIdents = Dafny.Set>.FromElements(); r = (this).InitEmptyExpr(); - BigInteger _hi13 = new BigInteger((_317_values).Count); - for (BigInteger _328_i = BigInteger.Zero; _328_i < _hi13; _328_i++) { - RAST._IType _329_typeGen; - RAST._IType _out260; - _out260 = (this).GenType((((_317_values).Select(_328_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); - _329_typeGen = _out260; - RAST._IExpr _330_valueGen; - Defs._IOwnership _331___v166; - Dafny.ISet> _332_recIdents; - RAST._IExpr _out261; - Defs._IOwnership _out262; - Dafny.ISet> _out263; - (this).GenExpr(((_317_values).Select(_328_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out261, out _out262, out _out263); - _330_valueGen = _out261; - _331___v166 = _out262; - _332_recIdents = _out263; - r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_317_values).Select(_328_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_329_typeGen), Std.Wrappers.Option.create_Some(_330_valueGen))); - readIdents = Dafny.Set>.Union(readIdents, _332_recIdents); - } - Defs._IEnvironment _333_newEnv; - _333_newEnv = Defs.Environment.create(_320_paramNames, _323_paramTypes); - RAST._IExpr _334_recGen; - Defs._IOwnership _335_recOwned; - Dafny.ISet> _336_recIdents; - RAST._IExpr _out264; - Defs._IOwnership _out265; - Dafny.ISet> _out266; - (this).GenExpr(_319_expr, selfIdent, _333_newEnv, expectedOwnership, out _out264, out _out265, out _out266); - _334_recGen = _out264; - _335_recOwned = _out265; - _336_recIdents = _out266; - readIdents = Dafny.Set>.Difference(_336_recIdents, _324_paramNamesSet); - r = RAST.Expr.create_Block((r).Then(_334_recGen)); - RAST._IExpr _out267; - Defs._IOwnership _out268; - (this).FromOwnership(r, _335_recOwned, expectedOwnership, out _out267, out _out268); - r = _out267; - resultingOwnership = _out268; + BigInteger _hi13 = new BigInteger((_318_values).Count); + for (BigInteger _329_i = BigInteger.Zero; _329_i < _hi13; _329_i++) { + RAST._IType _330_typeGen; + RAST._IType _out261; + _out261 = (this).GenType((((_318_values).Select(_329_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); + _330_typeGen = _out261; + RAST._IExpr _331_valueGen; + Defs._IOwnership _332___v137; + Dafny.ISet> _333_recIdents; + RAST._IExpr _out262; + Defs._IOwnership _out263; + Dafny.ISet> _out264; + (this).GenExpr(((_318_values).Select(_329_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out262, out _out263, out _out264); + _331_valueGen = _out262; + _332___v137 = _out263; + _333_recIdents = _out264; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_318_values).Select(_329_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_330_typeGen), Std.Wrappers.Option.create_Some(_331_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _333_recIdents); + } + Defs._IEnvironment _334_newEnv; + _334_newEnv = Defs.Environment.create(_321_paramNames, _324_paramTypes); + RAST._IExpr _335_recGen; + Defs._IOwnership _336_recOwned; + Dafny.ISet> _337_recIdents; + RAST._IExpr _out265; + Defs._IOwnership _out266; + Dafny.ISet> _out267; + (this).GenExpr(_320_expr, selfIdent, _334_newEnv, expectedOwnership, out _out265, out _out266, out _out267); + _335_recGen = _out265; + _336_recOwned = _out266; + _337_recIdents = _out267; + readIdents = Dafny.Set>.Difference(_337_recIdents, _325_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_335_recGen)); + RAST._IExpr _out268; + Defs._IOwnership _out269; + (this).FromOwnership(r, _336_recOwned, expectedOwnership, out _out268, out _out269); + r = _out268; + resultingOwnership = _out269; return ; } goto after_match0; @@ -6136,45 +6137,45 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IIFE) { - Dafny.ISequence _337_name = _source0.dtor_ident; - DAST._IType _338_tpe = _source0.dtor_typ; - DAST._IExpression _339_value = _source0.dtor_value; - DAST._IExpression _340_iifeBody = _source0.dtor_iifeBody; + Dafny.ISequence _338_name = _source0.dtor_ident; + DAST._IType _339_tpe = _source0.dtor_typ; + DAST._IExpression _340_value = _source0.dtor_value; + DAST._IExpression _341_iifeBody = _source0.dtor_iifeBody; { - RAST._IExpr _341_valueGen; - Defs._IOwnership _342___v167; - Dafny.ISet> _343_recIdents; - RAST._IExpr _out269; - Defs._IOwnership _out270; - Dafny.ISet> _out271; - (this).GenExpr(_339_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out269, out _out270, out _out271); - _341_valueGen = _out269; - _342___v167 = _out270; - _343_recIdents = _out271; - readIdents = _343_recIdents; - RAST._IType _344_valueTypeGen; - RAST._IType _out272; - _out272 = (this).GenType(_338_tpe, Defs.GenTypeContext.@default()); - _344_valueTypeGen = _out272; - Dafny.ISequence _345_iifeVar; - _345_iifeVar = Defs.__default.escapeVar(_337_name); - RAST._IExpr _346_bodyGen; - Defs._IOwnership _347___v168; - Dafny.ISet> _348_bodyIdents; - RAST._IExpr _out273; - Defs._IOwnership _out274; - Dafny.ISet> _out275; - (this).GenExpr(_340_iifeBody, selfIdent, (env).AddAssigned(_345_iifeVar, _344_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out273, out _out274, out _out275); - _346_bodyGen = _out273; - _347___v168 = _out274; - _348_bodyIdents = _out275; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_348_bodyIdents, Dafny.Set>.FromElements(_345_iifeVar))); - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _345_iifeVar, Std.Wrappers.Option.create_Some(_344_valueTypeGen), Std.Wrappers.Option.create_Some(_341_valueGen))).Then(_346_bodyGen)); - RAST._IExpr _out276; - Defs._IOwnership _out277; - (this).FromOwned(r, expectedOwnership, out _out276, out _out277); - r = _out276; - resultingOwnership = _out277; + RAST._IExpr _342_valueGen; + Defs._IOwnership _343___v138; + Dafny.ISet> _344_recIdents; + RAST._IExpr _out270; + Defs._IOwnership _out271; + Dafny.ISet> _out272; + (this).GenExpr(_340_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out270, out _out271, out _out272); + _342_valueGen = _out270; + _343___v138 = _out271; + _344_recIdents = _out272; + readIdents = _344_recIdents; + RAST._IType _345_valueTypeGen; + RAST._IType _out273; + _out273 = (this).GenType(_339_tpe, Defs.GenTypeContext.@default()); + _345_valueTypeGen = _out273; + Dafny.ISequence _346_iifeVar; + _346_iifeVar = Defs.__default.escapeVar(_338_name); + RAST._IExpr _347_bodyGen; + Defs._IOwnership _348___v139; + Dafny.ISet> _349_bodyIdents; + RAST._IExpr _out274; + Defs._IOwnership _out275; + Dafny.ISet> _out276; + (this).GenExpr(_341_iifeBody, selfIdent, (env).AddAssigned(_346_iifeVar, _345_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out274, out _out275, out _out276); + _347_bodyGen = _out274; + _348___v139 = _out275; + _349_bodyIdents = _out276; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_349_bodyIdents, Dafny.Set>.FromElements(_346_iifeVar))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _346_iifeVar, Std.Wrappers.Option.create_Some(_345_valueTypeGen), Std.Wrappers.Option.create_Some(_342_valueGen))).Then(_347_bodyGen)); + RAST._IExpr _out277; + Defs._IOwnership _out278; + (this).FromOwned(r, expectedOwnership, out _out277, out _out278); + r = _out277; + resultingOwnership = _out278; return ; } goto after_match0; @@ -6182,43 +6183,43 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Apply) { - DAST._IExpression _349_func = _source0.dtor_expr; - Dafny.ISequence _350_args = _source0.dtor_args; + DAST._IExpression _350_func = _source0.dtor_expr; + Dafny.ISequence _351_args = _source0.dtor_args; { - RAST._IExpr _351_funcExpr; - Defs._IOwnership _352___v169; - Dafny.ISet> _353_recIdents; - RAST._IExpr _out278; - Defs._IOwnership _out279; - Dafny.ISet> _out280; - (this).GenExpr(_349_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out278, out _out279, out _out280); - _351_funcExpr = _out278; - _352___v169 = _out279; - _353_recIdents = _out280; - readIdents = _353_recIdents; - Dafny.ISequence _354_rArgs; - _354_rArgs = Dafny.Sequence.FromElements(); - BigInteger _hi14 = new BigInteger((_350_args).Count); - for (BigInteger _355_i = BigInteger.Zero; _355_i < _hi14; _355_i++) { - RAST._IExpr _356_argExpr; - Defs._IOwnership _357_argOwned; - Dafny.ISet> _358_argIdents; - RAST._IExpr _out281; - Defs._IOwnership _out282; - Dafny.ISet> _out283; - (this).GenExpr((_350_args).Select(_355_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out281, out _out282, out _out283); - _356_argExpr = _out281; - _357_argOwned = _out282; - _358_argIdents = _out283; - _354_rArgs = Dafny.Sequence.Concat(_354_rArgs, Dafny.Sequence.FromElements(_356_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _358_argIdents); - } - r = (_351_funcExpr).Apply(_354_rArgs); - RAST._IExpr _out284; - Defs._IOwnership _out285; - (this).FromOwned(r, expectedOwnership, out _out284, out _out285); - r = _out284; - resultingOwnership = _out285; + RAST._IExpr _352_funcExpr; + Defs._IOwnership _353___v140; + Dafny.ISet> _354_recIdents; + RAST._IExpr _out279; + Defs._IOwnership _out280; + Dafny.ISet> _out281; + (this).GenExpr(_350_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out279, out _out280, out _out281); + _352_funcExpr = _out279; + _353___v140 = _out280; + _354_recIdents = _out281; + readIdents = _354_recIdents; + Dafny.ISequence _355_rArgs; + _355_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi14 = new BigInteger((_351_args).Count); + for (BigInteger _356_i = BigInteger.Zero; _356_i < _hi14; _356_i++) { + RAST._IExpr _357_argExpr; + Defs._IOwnership _358_argOwned; + Dafny.ISet> _359_argIdents; + RAST._IExpr _out282; + Defs._IOwnership _out283; + Dafny.ISet> _out284; + (this).GenExpr((_351_args).Select(_356_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out282, out _out283, out _out284); + _357_argExpr = _out282; + _358_argOwned = _out283; + _359_argIdents = _out284; + _355_rArgs = Dafny.Sequence.Concat(_355_rArgs, Dafny.Sequence.FromElements(_357_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _359_argIdents); + } + r = (_352_funcExpr).Apply(_355_rArgs); + RAST._IExpr _out285; + Defs._IOwnership _out286; + (this).FromOwned(r, expectedOwnership, out _out285, out _out286); + r = _out285; + resultingOwnership = _out286; return ; } goto after_match0; @@ -6226,31 +6227,31 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TypeTest) { - DAST._IExpression _359_on = _source0.dtor_on; - Dafny.ISequence> _360_dType = _source0.dtor_dType; - Dafny.ISequence _361_variant = _source0.dtor_variant; + DAST._IExpression _360_on = _source0.dtor_on; + Dafny.ISequence> _361_dType = _source0.dtor_dType; + Dafny.ISequence _362_variant = _source0.dtor_variant; { - RAST._IExpr _362_exprGen; - Defs._IOwnership _363___v170; - Dafny.ISet> _364_recIdents; - RAST._IExpr _out286; - Defs._IOwnership _out287; - Dafny.ISet> _out288; - (this).GenExpr(_359_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out286, out _out287, out _out288); - _362_exprGen = _out286; - _363___v170 = _out287; - _364_recIdents = _out288; - RAST._IExpr _365_variantExprPath; - RAST._IExpr _out289; - _out289 = (this).GenPathExpr(Dafny.Sequence>.Concat(_360_dType, Dafny.Sequence>.FromElements(_361_variant)), true); - _365_variantExprPath = _out289; - r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_362_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _365_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); + RAST._IExpr _363_exprGen; + Defs._IOwnership _364___v141; + Dafny.ISet> _365_recIdents; + RAST._IExpr _out287; + Defs._IOwnership _out288; + Dafny.ISet> _out289; + (this).GenExpr(_360_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out287, out _out288, out _out289); + _363_exprGen = _out287; + _364___v141 = _out288; + _365_recIdents = _out289; + RAST._IExpr _366_variantExprPath; RAST._IExpr _out290; - Defs._IOwnership _out291; - (this).FromOwned(r, expectedOwnership, out _out290, out _out291); - r = _out290; - resultingOwnership = _out291; - readIdents = _364_recIdents; + _out290 = (this).GenPathExpr(Dafny.Sequence>.Concat(_361_dType, Dafny.Sequence>.FromElements(_362_variant)), true); + _366_variantExprPath = _out290; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_363_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _366_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); + RAST._IExpr _out291; + Defs._IOwnership _out292; + (this).FromOwned(r, expectedOwnership, out _out291, out _out292); + r = _out291; + resultingOwnership = _out292; + readIdents = _365_recIdents; return ; } goto after_match0; @@ -6258,42 +6259,42 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Is) { - DAST._IExpression _366_expr = _source0.dtor_expr; - DAST._IType _367_fromType = _source0.dtor_fromType; - DAST._IType _368_toType = _source0.dtor_toType; + DAST._IExpression _367_expr = _source0.dtor_expr; + DAST._IType _368_fromType = _source0.dtor_fromType; + DAST._IType _369_toType = _source0.dtor_toType; { - RAST._IExpr _369_expr; - Defs._IOwnership _370_recOwned; - Dafny.ISet> _371_recIdents; - RAST._IExpr _out292; - Defs._IOwnership _out293; - Dafny.ISet> _out294; - (this).GenExpr(_366_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out292, out _out293, out _out294); - _369_expr = _out292; - _370_recOwned = _out293; - _371_recIdents = _out294; - RAST._IType _372_fromType; - RAST._IType _out295; - _out295 = (this).GenType(_367_fromType, Defs.GenTypeContext.@default()); - _372_fromType = _out295; - RAST._IType _373_toType; + RAST._IExpr _370_expr; + Defs._IOwnership _371_recOwned; + Dafny.ISet> _372_recIdents; + RAST._IExpr _out293; + Defs._IOwnership _out294; + Dafny.ISet> _out295; + (this).GenExpr(_367_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out293, out _out294, out _out295); + _370_expr = _out293; + _371_recOwned = _out294; + _372_recIdents = _out295; + RAST._IType _373_fromType; RAST._IType _out296; - _out296 = (this).GenType(_368_toType, Defs.GenTypeContext.@default()); - _373_toType = _out296; - if (((_372_fromType).IsObjectOrPointer()) && ((_373_toType).IsObjectOrPointer())) { - r = (((_369_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_373_toType).ObjectOrPointerUnderlying()))).Apply0(); + _out296 = (this).GenType(_368_fromType, Defs.GenTypeContext.@default()); + _373_fromType = _out296; + RAST._IType _374_toType; + RAST._IType _out297; + _out297 = (this).GenType(_369_toType, Defs.GenTypeContext.@default()); + _374_toType = _out297; + if (((_373_fromType).IsObjectOrPointer()) && ((_374_toType).IsObjectOrPointer())) { + r = (((_370_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_374_toType).ObjectOrPointerUnderlying()))).Apply0(); } else { - RAST._IExpr _out297; - _out297 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object or Ptr"), (this).InitEmptyExpr()); - r = _out297; + RAST._IExpr _out298; + _out298 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object or Ptr"), (this).InitEmptyExpr()); + r = _out298; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out298; - Defs._IOwnership _out299; - (this).FromOwnership(r, _370_recOwned, expectedOwnership, out _out298, out _out299); - r = _out298; - resultingOwnership = _out299; - readIdents = _371_recIdents; + RAST._IExpr _out299; + Defs._IOwnership _out300; + (this).FromOwnership(r, _371_recOwned, expectedOwnership, out _out299, out _out300); + r = _out299; + resultingOwnership = _out300; + readIdents = _372_recIdents; return ; } goto after_match0; @@ -6303,11 +6304,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 _out300; - Defs._IOwnership _out301; - (this).FromOwned(r, expectedOwnership, out _out300, out _out301); - r = _out300; - resultingOwnership = _out301; + RAST._IExpr _out301; + Defs._IOwnership _out302; + (this).FromOwned(r, expectedOwnership, out _out301, out _out302); + r = _out301; + resultingOwnership = _out302; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6316,25 +6317,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBoundedPool) { - DAST._IExpression _374_of = _source0.dtor_of; + DAST._IExpression _375_of = _source0.dtor_of; { - RAST._IExpr _375_exprGen; - Defs._IOwnership _376___v171; - Dafny.ISet> _377_recIdents; - RAST._IExpr _out302; - Defs._IOwnership _out303; - Dafny.ISet> _out304; - (this).GenExpr(_374_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); - _375_exprGen = _out302; - _376___v171 = _out303; - _377_recIdents = _out304; - r = ((_375_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 = _377_recIdents; + RAST._IExpr _376_exprGen; + Defs._IOwnership _377___v142; + Dafny.ISet> _378_recIdents; + RAST._IExpr _out303; + Defs._IOwnership _out304; + Dafny.ISet> _out305; + (this).GenExpr(_375_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out303, out _out304, out _out305); + _376_exprGen = _out303; + _377___v142 = _out304; + _378_recIdents = _out305; + r = ((_376_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + RAST._IExpr _out306; + Defs._IOwnership _out307; + (this).FromOwned(r, expectedOwnership, out _out306, out _out307); + r = _out306; + resultingOwnership = _out307; + readIdents = _378_recIdents; return ; } goto after_match0; @@ -6342,29 +6343,29 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SeqBoundedPool) { - DAST._IExpression _378_of = _source0.dtor_of; - bool _379_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _379_of = _source0.dtor_of; + bool _380_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _380_exprGen; - Defs._IOwnership _381___v172; - Dafny.ISet> _382_recIdents; - RAST._IExpr _out307; - Defs._IOwnership _out308; - Dafny.ISet> _out309; - (this).GenExpr(_378_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out307, out _out308, out _out309); - _380_exprGen = _out307; - _381___v172 = _out308; - _382_recIdents = _out309; - r = ((_380_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_379_includeDuplicates)) { + RAST._IExpr _381_exprGen; + Defs._IOwnership _382___v143; + Dafny.ISet> _383_recIdents; + RAST._IExpr _out308; + Defs._IOwnership _out309; + Dafny.ISet> _out310; + (this).GenExpr(_379_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out308, out _out309, out _out310); + _381_exprGen = _out308; + _382___v143 = _out309; + _383_recIdents = _out310; + r = ((_381_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_380_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 _out310; - Defs._IOwnership _out311; - (this).FromOwned(r, expectedOwnership, out _out310, out _out311); - r = _out310; - resultingOwnership = _out311; - readIdents = _382_recIdents; + RAST._IExpr _out311; + Defs._IOwnership _out312; + (this).FromOwned(r, expectedOwnership, out _out311, out _out312); + r = _out311; + resultingOwnership = _out312; + readIdents = _383_recIdents; return ; } goto after_match0; @@ -6372,29 +6373,29 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MultisetBoundedPool) { - DAST._IExpression _383_of = _source0.dtor_of; - bool _384_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _384_of = _source0.dtor_of; + bool _385_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _385_exprGen; - Defs._IOwnership _386___v173; - Dafny.ISet> _387_recIdents; - RAST._IExpr _out312; - Defs._IOwnership _out313; - Dafny.ISet> _out314; - (this).GenExpr(_383_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out312, out _out313, out _out314); - _385_exprGen = _out312; - _386___v173 = _out313; - _387_recIdents = _out314; - r = ((_385_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_384_includeDuplicates)) { + RAST._IExpr _386_exprGen; + Defs._IOwnership _387___v144; + Dafny.ISet> _388_recIdents; + RAST._IExpr _out313; + Defs._IOwnership _out314; + Dafny.ISet> _out315; + (this).GenExpr(_384_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out313, out _out314, out _out315); + _386_exprGen = _out313; + _387___v144 = _out314; + _388_recIdents = _out315; + r = ((_386_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_385_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 _out315; - Defs._IOwnership _out316; - (this).FromOwned(r, expectedOwnership, out _out315, out _out316); - r = _out315; - resultingOwnership = _out316; - readIdents = _387_recIdents; + RAST._IExpr _out316; + Defs._IOwnership _out317; + (this).FromOwned(r, expectedOwnership, out _out316, out _out317); + r = _out316; + resultingOwnership = _out317; + readIdents = _388_recIdents; return ; } goto after_match0; @@ -6402,99 +6403,99 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBoundedPool) { - DAST._IExpression _388_of = _source0.dtor_of; + DAST._IExpression _389_of = _source0.dtor_of; { - RAST._IExpr _389_exprGen; - Defs._IOwnership _390___v174; - Dafny.ISet> _391_recIdents; - RAST._IExpr _out317; - Defs._IOwnership _out318; - Dafny.ISet> _out319; - (this).GenExpr(_388_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out317, out _out318, out _out319); - _389_exprGen = _out317; - _390___v174 = _out318; - _391_recIdents = _out319; - r = ((((_389_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - readIdents = _391_recIdents; - RAST._IExpr _out320; - Defs._IOwnership _out321; - (this).FromOwned(r, expectedOwnership, out _out320, out _out321); - r = _out320; - resultingOwnership = _out321; + RAST._IExpr _390_exprGen; + Defs._IOwnership _391___v145; + Dafny.ISet> _392_recIdents; + RAST._IExpr _out318; + Defs._IOwnership _out319; + Dafny.ISet> _out320; + (this).GenExpr(_389_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out318, out _out319, out _out320); + _390_exprGen = _out318; + _391___v145 = _out319; + _392_recIdents = _out320; + r = ((((_390_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + readIdents = _392_recIdents; + RAST._IExpr _out321; + Defs._IOwnership _out322; + (this).FromOwned(r, expectedOwnership, out _out321, out _out322); + r = _out321; + resultingOwnership = _out322; } goto after_match0; } } { if (_source0.is_ExactBoundedPool) { - DAST._IExpression _392_of = _source0.dtor_of; + DAST._IExpression _393_of = _source0.dtor_of; { - RAST._IExpr _393_exprGen; - Defs._IOwnership _394___v175; - Dafny.ISet> _395_recIdents; - RAST._IExpr _out322; - Defs._IOwnership _out323; - Dafny.ISet> _out324; - (this).GenExpr(_392_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out322, out _out323, out _out324); - _393_exprGen = _out322; - _394___v175 = _out323; - _395_recIdents = _out324; - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_393_exprGen); - readIdents = _395_recIdents; - RAST._IExpr _out325; - Defs._IOwnership _out326; - (this).FromOwned(r, expectedOwnership, out _out325, out _out326); - r = _out325; - resultingOwnership = _out326; + RAST._IExpr _394_exprGen; + Defs._IOwnership _395___v146; + Dafny.ISet> _396_recIdents; + RAST._IExpr _out323; + Defs._IOwnership _out324; + Dafny.ISet> _out325; + (this).GenExpr(_393_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out323, out _out324, out _out325); + _394_exprGen = _out323; + _395___v146 = _out324; + _396_recIdents = _out325; + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_394_exprGen); + readIdents = _396_recIdents; + RAST._IExpr _out326; + Defs._IOwnership _out327; + (this).FromOwned(r, expectedOwnership, out _out326, out _out327); + r = _out326; + resultingOwnership = _out327; } goto after_match0; } } { if (_source0.is_IntRange) { - DAST._IType _396_typ = _source0.dtor_elemType; - DAST._IExpression _397_lo = _source0.dtor_lo; - DAST._IExpression _398_hi = _source0.dtor_hi; - bool _399_up = _source0.dtor_up; + DAST._IType _397_typ = _source0.dtor_elemType; + DAST._IExpression _398_lo = _source0.dtor_lo; + DAST._IExpression _399_hi = _source0.dtor_hi; + bool _400_up = _source0.dtor_up; { - RAST._IExpr _400_lo; - Defs._IOwnership _401___v176; - Dafny.ISet> _402_recIdentsLo; - RAST._IExpr _out327; - Defs._IOwnership _out328; - Dafny.ISet> _out329; - (this).GenExpr(_397_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out327, out _out328, out _out329); - _400_lo = _out327; - _401___v176 = _out328; - _402_recIdentsLo = _out329; - RAST._IExpr _403_hi; - Defs._IOwnership _404___v177; - Dafny.ISet> _405_recIdentsHi; - RAST._IExpr _out330; - Defs._IOwnership _out331; - Dafny.ISet> _out332; - (this).GenExpr(_398_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out330, out _out331, out _out332); - _403_hi = _out330; - _404___v177 = _out331; - _405_recIdentsHi = _out332; - if (_399_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_400_lo, _403_hi)); + RAST._IExpr _401_lo; + Defs._IOwnership _402___v147; + Dafny.ISet> _403_recIdentsLo; + RAST._IExpr _out328; + Defs._IOwnership _out329; + Dafny.ISet> _out330; + (this).GenExpr(_398_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); + _401_lo = _out328; + _402___v147 = _out329; + _403_recIdentsLo = _out330; + RAST._IExpr _404_hi; + Defs._IOwnership _405___v148; + Dafny.ISet> _406_recIdentsHi; + RAST._IExpr _out331; + Defs._IOwnership _out332; + Dafny.ISet> _out333; + (this).GenExpr(_399_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out331, out _out332, out _out333); + _404_hi = _out331; + _405___v148 = _out332; + _406_recIdentsHi = _out333; + if (_400_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_401_lo, _404_hi)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_403_hi, _400_lo)); - } - if (!((_396_typ).is_Primitive)) { - RAST._IType _406_tpe; - RAST._IType _out333; - _out333 = (this).GenType(_396_typ, Defs.GenTypeContext.@default()); - _406_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(_406_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(_402_recIdentsLo, _405_recIdentsHi); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_404_hi, _401_lo)); + } + if (!((_397_typ).is_Primitive)) { + RAST._IType _407_tpe; + RAST._IType _out334; + _out334 = (this).GenType(_397_typ, Defs.GenTypeContext.@default()); + _407_tpe = _out334; + 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(_407_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); + } + RAST._IExpr _out335; + Defs._IOwnership _out336; + (this).FromOwned(r, expectedOwnership, out _out335, out _out336); + r = _out335; + resultingOwnership = _out336; + readIdents = Dafny.Set>.Union(_403_recIdentsLo, _406_recIdentsHi); return ; } goto after_match0; @@ -6502,30 +6503,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _407_start = _source0.dtor_start; - bool _408_up = _source0.dtor_up; + DAST._IExpression _408_start = _source0.dtor_start; + bool _409_up = _source0.dtor_up; { - RAST._IExpr _409_start; - Defs._IOwnership _410___v178; - Dafny.ISet> _411_recIdentStart; - RAST._IExpr _out336; - Defs._IOwnership _out337; - Dafny.ISet> _out338; - (this).GenExpr(_407_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out336, out _out337, out _out338); - _409_start = _out336; - _410___v178 = _out337; - _411_recIdentStart = _out338; - if (_408_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_409_start); + RAST._IExpr _410_start; + Defs._IOwnership _411___v149; + Dafny.ISet> _412_recIdentStart; + RAST._IExpr _out337; + Defs._IOwnership _out338; + Dafny.ISet> _out339; + (this).GenExpr(_408_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); + _410_start = _out337; + _411___v149 = _out338; + _412_recIdentStart = _out339; + if (_409_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_410_start); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_409_start); - } - RAST._IExpr _out339; - Defs._IOwnership _out340; - (this).FromOwned(r, expectedOwnership, out _out339, out _out340); - r = _out339; - resultingOwnership = _out340; - readIdents = _411_recIdentStart; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_410_start); + } + RAST._IExpr _out340; + Defs._IOwnership _out341; + (this).FromOwned(r, expectedOwnership, out _out340, out _out341); + r = _out340; + resultingOwnership = _out341; + readIdents = _412_recIdentStart; return ; } goto after_match0; @@ -6533,23 +6534,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBuilder) { - DAST._IType _412_keyType = _source0.dtor_keyType; - DAST._IType _413_valueType = _source0.dtor_valueType; + DAST._IType _413_keyType = _source0.dtor_keyType; + DAST._IType _414_valueType = _source0.dtor_valueType; { - RAST._IType _414_kType; - RAST._IType _out341; - _out341 = (this).GenType(_412_keyType, Defs.GenTypeContext.@default()); - _414_kType = _out341; - RAST._IType _415_vType; + RAST._IType _415_kType; RAST._IType _out342; - _out342 = (this).GenType(_413_valueType, Defs.GenTypeContext.@default()); - _415_vType = _out342; - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_414_kType, _415_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; + _out342 = (this).GenType(_413_keyType, Defs.GenTypeContext.@default()); + _415_kType = _out342; + RAST._IType _416_vType; + RAST._IType _out343; + _out343 = (this).GenType(_414_valueType, Defs.GenTypeContext.@default()); + _416_vType = _out343; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_415_kType, _416_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out344; + Defs._IOwnership _out345; + (this).FromOwned(r, expectedOwnership, out _out344, out _out345); + r = _out344; + resultingOwnership = _out345; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6558,93 +6559,93 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBuilder) { - DAST._IType _416_elemType = _source0.dtor_elemType; + DAST._IType _417_elemType = _source0.dtor_elemType; { - RAST._IType _417_eType; - RAST._IType _out345; - _out345 = (this).GenType(_416_elemType, Defs.GenTypeContext.@default()); - _417_eType = _out345; + RAST._IType _418_eType; + RAST._IType _out346; + _out346 = (this).GenType(_417_elemType, Defs.GenTypeContext.@default()); + _418_eType = _out346; readIdents = Dafny.Set>.FromElements(); - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_417_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; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_418_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out347; + Defs._IOwnership _out348; + (this).FromOwned(r, expectedOwnership, out _out347, out _out348); + r = _out347; + resultingOwnership = _out348; return ; } goto after_match0; } } { - DAST._IType _418_elemType = _source0.dtor_elemType; - DAST._IExpression _419_collection = _source0.dtor_collection; - bool _420_is__forall = _source0.dtor_is__forall; - DAST._IExpression _421_lambda = _source0.dtor_lambda; + DAST._IType _419_elemType = _source0.dtor_elemType; + DAST._IExpression _420_collection = _source0.dtor_collection; + bool _421_is__forall = _source0.dtor_is__forall; + DAST._IExpression _422_lambda = _source0.dtor_lambda; { - RAST._IType _422_tpe; - RAST._IType _out348; - _out348 = (this).GenType(_418_elemType, Defs.GenTypeContext.@default()); - _422_tpe = _out348; - RAST._IExpr _423_collectionGen; - Defs._IOwnership _424___v179; - Dafny.ISet> _425_recIdents; - RAST._IExpr _out349; - Defs._IOwnership _out350; - Dafny.ISet> _out351; - (this).GenExpr(_419_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out349, out _out350, out _out351); - _423_collectionGen = _out349; - _424___v179 = _out350; - _425_recIdents = _out351; - Dafny.ISequence _426_extraAttributes; - _426_extraAttributes = Dafny.Sequence.FromElements(); - if ((((((_419_collection).is_IntRange) || ((_419_collection).is_UnboundedIntRange)) || ((_419_collection).is_SeqBoundedPool)) || ((_419_collection).is_ExactBoundedPool)) || ((_419_collection).is_MultisetBoundedPool)) { - _426_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); - } - if ((_421_lambda).is_Lambda) { - Dafny.ISequence _427_formals; - _427_formals = (_421_lambda).dtor_params; - Dafny.ISequence _428_newFormals; - _428_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi15 = new BigInteger((_427_formals).Count); - for (BigInteger _429_i = BigInteger.Zero; _429_i < _hi15; _429_i++) { - var _pat_let_tv0 = _426_extraAttributes; - var _pat_let_tv1 = _427_formals; - _428_newFormals = Dafny.Sequence.Concat(_428_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_427_formals).Select(_429_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _430_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_429_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _431_dt__update_hattributes_h0 => DAST.Formal.create((_430_dt__update__tmp_h0).dtor_name, (_430_dt__update__tmp_h0).dtor_typ, _431_dt__update_hattributes_h0))))))); - } - DAST._IExpression _432_newLambda; - DAST._IExpression _433_dt__update__tmp_h1 = _421_lambda; - Dafny.ISequence _434_dt__update_hparams_h0 = _428_newFormals; - _432_newLambda = DAST.Expression.create_Lambda(_434_dt__update_hparams_h0, (_433_dt__update__tmp_h1).dtor_retType, (_433_dt__update__tmp_h1).dtor_body); - RAST._IExpr _435_lambdaGen; - Defs._IOwnership _436___v180; - Dafny.ISet> _437_recLambdaIdents; - RAST._IExpr _out352; - Defs._IOwnership _out353; - Dafny.ISet> _out354; - (this).GenExpr(_432_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out352, out _out353, out _out354); - _435_lambdaGen = _out352; - _436___v180 = _out353; - _437_recLambdaIdents = _out354; - Dafny.ISequence _438_fn; - if (_420_is__forall) { - _438_fn = Dafny.Sequence.UnicodeFromString("all"); + RAST._IType _423_tpe; + RAST._IType _out349; + _out349 = (this).GenType(_419_elemType, Defs.GenTypeContext.@default()); + _423_tpe = _out349; + RAST._IExpr _424_collectionGen; + Defs._IOwnership _425___v150; + Dafny.ISet> _426_recIdents; + RAST._IExpr _out350; + Defs._IOwnership _out351; + Dafny.ISet> _out352; + (this).GenExpr(_420_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); + _424_collectionGen = _out350; + _425___v150 = _out351; + _426_recIdents = _out352; + Dafny.ISequence _427_extraAttributes; + _427_extraAttributes = Dafny.Sequence.FromElements(); + if ((((((_420_collection).is_IntRange) || ((_420_collection).is_UnboundedIntRange)) || ((_420_collection).is_SeqBoundedPool)) || ((_420_collection).is_ExactBoundedPool)) || ((_420_collection).is_MultisetBoundedPool)) { + _427_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); + } + if ((_422_lambda).is_Lambda) { + Dafny.ISequence _428_formals; + _428_formals = (_422_lambda).dtor_params; + Dafny.ISequence _429_newFormals; + _429_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi15 = new BigInteger((_428_formals).Count); + for (BigInteger _430_i = BigInteger.Zero; _430_i < _hi15; _430_i++) { + var _pat_let_tv0 = _427_extraAttributes; + var _pat_let_tv1 = _428_formals; + _429_newFormals = Dafny.Sequence.Concat(_429_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_428_formals).Select(_430_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _431_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_430_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _432_dt__update_hattributes_h0 => DAST.Formal.create((_431_dt__update__tmp_h0).dtor_name, (_431_dt__update__tmp_h0).dtor_typ, _432_dt__update_hattributes_h0))))))); + } + DAST._IExpression _433_newLambda; + DAST._IExpression _434_dt__update__tmp_h1 = _422_lambda; + Dafny.ISequence _435_dt__update_hparams_h0 = _429_newFormals; + _433_newLambda = DAST.Expression.create_Lambda(_435_dt__update_hparams_h0, (_434_dt__update__tmp_h1).dtor_retType, (_434_dt__update__tmp_h1).dtor_body); + RAST._IExpr _436_lambdaGen; + Defs._IOwnership _437___v151; + Dafny.ISet> _438_recLambdaIdents; + RAST._IExpr _out353; + Defs._IOwnership _out354; + Dafny.ISet> _out355; + (this).GenExpr(_433_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out353, out _out354, out _out355); + _436_lambdaGen = _out353; + _437___v151 = _out354; + _438_recLambdaIdents = _out355; + Dafny.ISequence _439_fn; + if (_421_is__forall) { + _439_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _438_fn = Dafny.Sequence.UnicodeFromString("any"); + _439_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_423_collectionGen).Sel(_438_fn)).Apply1(((_435_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); - readIdents = Dafny.Set>.Union(_425_recIdents, _437_recLambdaIdents); + r = ((_424_collectionGen).Sel(_439_fn)).Apply1(((_436_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + readIdents = Dafny.Set>.Union(_426_recIdents, _438_recLambdaIdents); } else { - RAST._IExpr _out355; - _out355 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); - r = _out355; + RAST._IExpr _out356; + _out356 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); + r = _out356; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out356; - Defs._IOwnership _out357; - (this).FromOwned(r, expectedOwnership, out _out356, out _out357); - r = _out356; - resultingOwnership = _out357; + RAST._IExpr _out357; + Defs._IOwnership _out358; + (this).FromOwned(r, expectedOwnership, out _out357, out _out358); + r = _out357; + resultingOwnership = _out358; } } after_match0: ; @@ -6731,15 +6732,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v181; - Dafny.ISet> _2___v182; + Defs._IOwnership _1___v152; + Dafny.ISet> _2___v153; 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___v181 = _out1; - _2___v182 = _out2; + _1___v152 = _out1; + _2___v153 = _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")))); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index bf93664d1ef..103c0fd9324 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -249,6 +249,22 @@ public static Defs._IExternAttribute ExtractExternMod(DAST._IModule mod) { return Defs.__default.escapeName((_0_i)); })), containingPath); } + public static RAST._IType AddOverflow(RAST._IType tpe, bool overflow) + { + if (!(overflow)) { + return tpe; + } else { + return RAST.Type.create_TMetaData(tpe, true, true); + } + } + public static Std.Wrappers._IOption NewtypeRangeToUnwrappedBoundedRustType(DAST._IType @base, DAST._INewtypeRange range) + { + if ((@base).IsPrimitiveInt()) { + return Defs.__default.NewtypeRangeToRustType(range); + } else { + return Std.Wrappers.Option.create_None(); + } + } public static Std.Wrappers._IOption NewtypeRangeToRustType(DAST._INewtypeRange range) { DAST._INewtypeRange _source0 = range; { @@ -258,63 +274,130 @@ public static Defs._IExternAttribute ExtractExternMod(DAST._IModule mod) { } { if (_source0.is_U8) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_U8()); + bool _0_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_U8(), _0_overflow)); } } { if (_source0.is_U16) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_U16()); + bool _1_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_U16(), _1_overflow)); } } { if (_source0.is_U32) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_U32()); + bool _2_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_U32(), _2_overflow)); } } { if (_source0.is_U64) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_U64()); + bool _3_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_U64(), _3_overflow)); } } { if (_source0.is_U128) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_U128()); + bool _4_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_U128(), _4_overflow)); } } { if (_source0.is_I8) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_I8()); + bool _5_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_I8(), _5_overflow)); } } { if (_source0.is_I16) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_I16()); + bool _6_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_I16(), _6_overflow)); } } { if (_source0.is_I32) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_I32()); + bool _7_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_I32(), _7_overflow)); } } { if (_source0.is_I64) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_I64()); + bool _8_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_I64(), _8_overflow)); } } { if (_source0.is_I128) { - return Std.Wrappers.Option.create_Some(RAST.Type.create_I128()); + bool _9_overflow = _source0.dtor_overflow; + return Std.Wrappers.Option.create_Some(Defs.__default.AddOverflow(RAST.Type.create_I128(), _9_overflow)); } } { - if (_source0.is_USIZE) { + if (_source0.is_NativeArrayIndex) { return Std.Wrappers.Option.create_Some(RAST.Type.create_USIZE()); } } + { + if (_source0.is_Bool) { + return Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()); + } + } + { + return Std.Wrappers.Option.create_None(); + } + } + public static bool IsBooleanOperator(DAST._IBinOp op) { + return ((op).is_And) || ((op).is_Or); + } + public static bool IsComplexArithmetic(DAST._IBinOp op) { + return ((op).is_EuclidianDiv) || ((op).is_EuclidianMod); + } + public static Std.Wrappers._IOption GetUnwrappedBoundedRustType(DAST._IType tpe) { + DAST._IType _source0 = tpe; + { + 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 kind0 = resolved0.dtor_kind; + if (kind0.is_Newtype) { + DAST._IType _2_base = kind0.dtor_baseType; + DAST._INewtypeRange _3_range = kind0.dtor_range; + bool _4_erase = kind0.dtor_erase; + return Defs.__default.NewtypeRangeToUnwrappedBoundedRustType(_2_base, _3_range); + } + } + } { return Std.Wrappers.Option.create_None(); } } + public static bool NeedsUnwrappingConversion(DAST._IType tpe) { + DAST._IType _source0 = tpe; + { + 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 kind0 = resolved0.dtor_kind; + if (kind0.is_Newtype) { + DAST._IType _2_base = kind0.dtor_baseType; + DAST._INewtypeRange _3_range = kind0.dtor_range; + bool _4_erase = kind0.dtor_erase; + return (Defs.__default.NewtypeRangeToUnwrappedBoundedRustType(_2_base, _3_range)).is_None; + } + } + } + { + return false; + } + } + public static bool IsNewtype(DAST._IType tpe) { + return ((tpe).is_UserDefined) && ((((tpe).dtor_resolved).dtor_kind).is_Newtype); + } + public static bool IsNewtypeCopy(DAST._INewtypeRange range) { + return ((Defs.__default.NewtypeRangeToRustType(range)).is_Some) && (((range).HasArithmeticOperations()) || ((range).is_Bool)); + } public static bool OwnershipGuarantee(Defs._IOwnership expectedOwnership, Defs._IOwnership resultingOwnership) { return (!(!object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())) || (object.Equals(resultingOwnership, expectedOwnership))) && (!object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())); @@ -401,6 +484,53 @@ public static RAST._IModDecl SingletonsImpl(Dafny.ISequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(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))), Dafny.Sequence.UnicodeFromString(""), 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.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(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(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(hashImplBody)))))); + } + public static RAST._IModDecl UnaryOpsImpl(Dafny.Rune op, Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) + { + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs0 = ((System.Func<_System._ITuple2, Dafny.ISequence>>)(() => { + Dafny.Rune _source0 = op; + { + return _System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("Not"), Dafny.Sequence.UnicodeFromString("not")); + } + }))(); + Dafny.ISequence _0_traitName = _let_tmp_rhs0.dtor__0; + Dafny.ISequence _1_methodName = _let_tmp_rhs0.dtor__1; + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.UnaryOpFormat.create_NoFormat())))))))); + } + public static RAST._IModDecl OpsImpl(Dafny.Rune op, Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) + { + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs0 = ((System.Func<_System._ITuple2, Dafny.ISequence>>)(() => { + Dafny.Rune _source0 = op; + { + if ((_source0) == (new Dafny.Rune('+'))) { + return _System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("Add"), Dafny.Sequence.UnicodeFromString("add")); + } + } + { + if ((_source0) == (new Dafny.Rune('-'))) { + return _System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("Sub"), Dafny.Sequence.UnicodeFromString("sub")); + } + } + { + if ((_source0) == (new Dafny.Rune('/'))) { + return _System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("Div"), Dafny.Sequence.UnicodeFromString("div")); + } + } + { + return _System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("Mul"), Dafny.Sequence.UnicodeFromString("mul")); + } + }))(); + Dafny.ISequence _0_traitName = _let_tmp_rhs0.dtor__0; + Dafny.ISequence _1_methodName = _let_tmp_rhs0.dtor__1; + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_BinaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.BinaryOpFormat.create_NoFormat())))))))); + } + public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) + { + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsType(), newtypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(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())), Dafny.Sequence.UnicodeFromString(""), 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 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")); } } @@ -426,7 +556,7 @@ public static Dafny.ISequence DAFNY__EXTERN__MODULE { get { return Dafny.Sequence.UnicodeFromString("_dafny_externs"); } } 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(), 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(), Dafny.Sequence.UnicodeFromString("+")), new Dafny.Pair>(DAST.BinOp.create_Minus(), Dafny.Sequence.UnicodeFromString("-")), new Dafny.Pair>(DAST.BinOp.create_Times(), 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("<<"))); + 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("<<"))); } } } diff --git a/Source/DafnyCore/GeneratedFromDafny/ExpressionOptimization.cs b/Source/DafnyCore/GeneratedFromDafny/ExpressionOptimization.cs index 85c98391cc4..2b9201f0b84 100644 --- a/Source/DafnyCore/GeneratedFromDafny/ExpressionOptimization.cs +++ b/Source/DafnyCore/GeneratedFromDafny/ExpressionOptimization.cs @@ -82,7 +82,7 @@ public static RAST._IRASTBottomUpReplacer ExprSimplifier() { return _3_e; } else { RAST._IType _12_tpe = (_11_tpeExpr).dtor_tpe; - if ((((((((((((_12_tpe).is_U8) || ((_12_tpe).is_U16)) || ((_12_tpe).is_U32)) || ((_12_tpe).is_U64)) || ((_12_tpe).is_U128)) || ((_12_tpe).is_I8)) || ((_12_tpe).is_I16)) || ((_12_tpe).is_I32)) || ((_12_tpe).is_I64)) || ((_12_tpe).is_I128)) || ((_12_tpe).is_USIZE)) { + if ((_12_tpe).IsAutoSize()) { RAST._IExpr _source2 = _10_expr; { if (_source2.is_Call) { diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index efb368ea485..1d87cd6768f 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -593,8 +593,15 @@ public T VisitMember(T acc, RAST._IImplMember member) } } { - RAST._IExpr _3_expr = _source0.dtor_expr; - return (_3_expr).Fold(acc, (this).dtor_VisitExprSingle, (this).dtor_VisitTypeSingle); + if (_source0.is_TypeDeclMember) { + Dafny.ISequence _3_name = _source0.dtor_name; + RAST._IType _4_tpe = _source0.dtor_rhs; + return (this).VisitType(acc, _4_tpe); + } + } + { + RAST._IExpr _5_expr = _source0.dtor_expr; + return (_5_expr).Fold(acc, (this).dtor_VisitExprSingle, (this).dtor_VisitTypeSingle); } } public T VisitFn(T acc, RAST._IFn fn) @@ -912,8 +919,15 @@ public RAST._IImplMember ReplaceImplMember(RAST._IImplMember t) { } } { - RAST._IExpr _3_expr = _source0.dtor_expr; - return RAST.ImplMember.create_ImplMemberMacro((this).ReplaceExpr(_3_expr)); + if (_source0.is_TypeDeclMember) { + Dafny.ISequence _3_name = _source0.dtor_name; + RAST._IType _4_tpe = _source0.dtor_rhs; + return RAST.ImplMember.create_TypeDeclMember(_3_name, (this).ReplaceType(_4_tpe)); + } + } + { + RAST._IExpr _5_expr = _source0.dtor_expr; + return RAST.ImplMember.create_ImplMemberMacro((this).ReplaceExpr(_5_expr)); } } public RAST._IExpr ReplaceExpr(RAST._IExpr e) { @@ -2735,6 +2749,7 @@ public interface _IType { bool is_IntersectionType { get; } bool is_Array { get; } bool is_TSynonym { get; } + bool is_TMetaData { get; } Dafny.ISequence dtor_name { get; } RAST._IPath dtor_path { get; } RAST._IType dtor_baseName { get; } @@ -2746,12 +2761,15 @@ public interface _IType { Std.Wrappers._IOption> dtor_size { get; } RAST._IType dtor_display { get; } RAST._IType dtor_base { get; } + bool dtor_copySemantics { get; } + bool dtor_overflow { get; } _IType DowncastClone(); RAST._IType Expand(); bool EndsWithNameThatCanAcceptGenerics(); RAST._IType ReplaceMap(Dafny.IMap mapping); RAST._IType Replace(Func mapping); __T Fold<__T>(__T acc, Func<__T, RAST._IType, __T> f); + bool IsAutoSize(); bool CanReadWithoutClone(); bool IsRcOrBorrowedRc(); Std.Wrappers._IOption ExtractMaybePlacebo(); @@ -2859,6 +2877,9 @@ public static _IType create_Array(RAST._IType underlying, Std.Wrappers._IOption< public static _IType create_TSynonym(RAST._IType display, RAST._IType @base) { return new Type_TSynonym(display, @base); } + public static _IType create_TMetaData(RAST._IType display, bool copySemantics, bool overflow) { + return new Type_TMetaData(display, copySemantics, overflow); + } public bool is_U8 { get { return this is Type_U8; } } public bool is_U16 { get { return this is Type_U16; } } public bool is_U32 { get { return this is Type_U32; } } @@ -2883,6 +2904,7 @@ public static _IType create_TSynonym(RAST._IType display, RAST._IType @base) { public bool is_IntersectionType { get { return this is Type_IntersectionType; } } public bool is_Array { get { return this is Type_Array; } } public bool is_TSynonym { get { return this is Type_TSynonym; } } + public bool is_TMetaData { get { return this is Type_TMetaData; } } public Dafny.ISequence dtor_name { get { var d = this; @@ -2946,7 +2968,8 @@ public Std.Wrappers._IOption> dtor_size { public RAST._IType dtor_display { get { var d = this; - return ((Type_TSynonym)d)._display; + if (d is Type_TSynonym) { return ((Type_TSynonym)d)._display; } + return ((Type_TMetaData)d)._display; } } public RAST._IType dtor_base { @@ -2955,6 +2978,18 @@ public RAST._IType dtor_base { return ((Type_TSynonym)d)._base; } } + public bool dtor_copySemantics { + get { + var d = this; + return ((Type_TMetaData)d)._copySemantics; + } + } + public bool dtor_overflow { + get { + var d = this; + return ((Type_TMetaData)d)._overflow; + } + } public abstract _IType DowncastClone(); public RAST._IType Expand() { _IType _this = this; @@ -2964,12 +2999,17 @@ public RAST._IType Expand() { _this = _in0; ; goto TAIL_CALL_START; + } else if ((_this).is_TMetaData) { + RAST._IType _in1 = (_this).dtor_display; + _this = _in1; + ; + goto TAIL_CALL_START; } else { return _this; } } public bool EndsWithNameThatCanAcceptGenerics() { - return ((((((((((((((((((this).is_U8) || ((this).is_U16)) || ((this).is_U32)) || ((this).is_U64)) || ((this).is_U128)) || ((this).is_I8)) || ((this).is_I16)) || ((this).is_I32)) || ((this).is_I64)) || ((this).is_I128)) || ((this).is_TIdentifier)) || ((this).is_TypeFromPath)) || (((this).is_Borrowed) && (((this).dtor_underlying).EndsWithNameThatCanAcceptGenerics()))) || (((this).is_BorrowedMut) && (((this).dtor_underlying).EndsWithNameThatCanAcceptGenerics()))) || (((this).is_ImplType) && (((this).dtor_underlying).EndsWithNameThatCanAcceptGenerics()))) || (((this).is_DynType) && (((this).dtor_underlying).EndsWithNameThatCanAcceptGenerics()))) || (((this).is_IntersectionType) && (((this).dtor_right).EndsWithNameThatCanAcceptGenerics()))) || (((this).is_TSynonym) && (((this).dtor_display).EndsWithNameThatCanAcceptGenerics())); + return ((((((((((((((((((this).is_U8) || ((this).is_U16)) || ((this).is_U32)) || ((this).is_U64)) || ((this).is_U128)) || ((this).is_I8)) || ((this).is_I16)) || ((this).is_I32)) || ((this).is_I64)) || ((this).is_I128)) || ((this).is_TIdentifier)) || ((this).is_TypeFromPath)) || (((this).is_Borrowed) && (((this).dtor_underlying).EndsWithNameThatCanAcceptGenerics()))) || (((this).is_BorrowedMut) && (((this).dtor_underlying).EndsWithNameThatCanAcceptGenerics()))) || (((this).is_ImplType) && (((this).dtor_underlying).EndsWithNameThatCanAcceptGenerics()))) || (((this).is_DynType) && (((this).dtor_underlying).EndsWithNameThatCanAcceptGenerics()))) || (((this).is_IntersectionType) && (((this).dtor_right).EndsWithNameThatCanAcceptGenerics()))) || ((((this).is_TSynonym) || ((this).is_TMetaData)) && (((this).dtor_display).EndsWithNameThatCanAcceptGenerics())); } public RAST._IType ReplaceMap(Dafny.IMap mapping) { return (this).Replace(Dafny.Helpers.Id, Func>>((_0_mapping) => ((System.Func)((_1_t) => { @@ -3174,12 +3214,26 @@ public RAST._IType Replace(Func mapping) { } } { - RAST._IType _45_display = _source0.dtor_display; - RAST._IType _46_base = _source0.dtor_base; - RAST._IType _47_dt__update__tmp_h9 = this; - RAST._IType _48_dt__update_hbase_h0 = (_46_base).Replace(mapping); - RAST._IType _49_dt__update_hdisplay_h0 = (_45_display).Replace(mapping); - return RAST.Type.create_TSynonym(_49_dt__update_hdisplay_h0, _48_dt__update_hbase_h0); + if (_source0.is_TSynonym) { + RAST._IType _45_display = _source0.dtor_display; + RAST._IType _46_base = _source0.dtor_base; + RAST._IType _47_dt__update__tmp_h9 = this; + RAST._IType _48_dt__update_hbase_h0 = (_46_base).Replace(mapping); + RAST._IType _49_dt__update_hdisplay_h0 = (_45_display).Replace(mapping); + return RAST.Type.create_TSynonym(_49_dt__update_hdisplay_h0, _48_dt__update_hbase_h0); + } + } + { + RAST._IType _50_display = _source0.dtor_display; + bool _51_copySemantics = _source0.dtor_copySemantics; + bool _52_overflow = _source0.dtor_overflow; + RAST._IType _53_dt__update__tmp_h10 = this; + RAST._IType _54_dt__update_hdisplay_h1 = (_50_display).Replace(mapping); + if ((_53_dt__update__tmp_h10).is_TSynonym) { + return RAST.Type.create_TSynonym(_54_dt__update_hdisplay_h1, (_53_dt__update__tmp_h10).dtor_base); + } else { + return RAST.Type.create_TMetaData(_54_dt__update_hdisplay_h1, (_53_dt__update__tmp_h10).dtor_copySemantics, (_53_dt__update__tmp_h10).dtor_overflow); + } } }))(); return Dafny.Helpers.Id>(mapping)(_0_r); @@ -3307,13 +3361,22 @@ public __T Fold<__T>(__T acc, Func<__T, RAST._IType, __T> f) } } { - RAST._IType _28_display = _source0.dtor_display; - RAST._IType _29_base = _source0.dtor_base; - return (_28_display).Fold<__T>(_0_newAcc, f); + if (_source0.is_TSynonym) { + RAST._IType _28_display = _source0.dtor_display; + RAST._IType _29_base = _source0.dtor_base; + return (_28_display).Fold<__T>(_0_newAcc, f); + } + } + { + RAST._IType _30_display = _source0.dtor_display; + return (_30_display).Fold<__T>(_0_newAcc, f); } } + public bool IsAutoSize() { + return (((((((((((((this).is_U8) || ((this).is_U16)) || ((this).is_U32)) || ((this).is_U64)) || ((this).is_U128)) || ((this).is_I8)) || ((this).is_I16)) || ((this).is_I32)) || ((this).is_I64)) || ((this).is_I128)) || ((this).is_USIZE)) || (((this).is_TSynonym) && (((this).dtor_base).IsAutoSize()))) || (((this).is_TMetaData) && (((this).dtor_display).IsAutoSize())); + } public bool CanReadWithoutClone() { - return ((((((((((((((this).is_U8) || ((this).is_U16)) || ((this).is_U32)) || ((this).is_U64)) || ((this).is_U128)) || ((this).is_I8)) || ((this).is_I16)) || ((this).is_I32)) || ((this).is_I64)) || ((this).is_I128)) || ((this).is_USIZE)) || ((this).is_Bool)) || (((this).is_TSynonym) && (((this).dtor_base).CanReadWithoutClone()))) || ((this).IsPointer()); + return (((((this).IsAutoSize()) || ((this).is_Bool)) || ((this).IsPointer())) || (((this).is_TSynonym) && (((this).dtor_base).CanReadWithoutClone()))) || (((this).is_TMetaData) && (((this).dtor_copySemantics) || (((this).dtor_display).CanReadWithoutClone()))); } public bool IsRcOrBorrowedRc() { return ((((this).is_TypeApp) && (object.Equals((this).dtor_baseName, RAST.__default.RcType))) || (((this).is_Borrowed) && (((this).dtor_underlying).IsRcOrBorrowedRc()))) || (((this).is_TSynonym) && (((this).dtor_base).IsRcOrBorrowedRc())); @@ -3492,9 +3555,15 @@ public bool IsRcOrBorrowedRc() { } } { - RAST._IType _21_display = _source0.dtor_display; - RAST._IType _22_base = _source0.dtor_base; - return (_21_display)._ToString(ind); + if (_source0.is_TSynonym) { + RAST._IType _21_display = _source0.dtor_display; + RAST._IType _22_base = _source0.dtor_base; + return (_21_display)._ToString(ind); + } + } + { + RAST._IType _23_display = _source0.dtor_display; + return (_23_display)._ToString(ind); } } public RAST._IType Apply1(RAST._IType arg) { @@ -4281,6 +4350,43 @@ public override string ToString() { return s; } } + public class Type_TMetaData : Type { + public readonly RAST._IType _display; + public readonly bool _copySemantics; + public readonly bool _overflow; + public Type_TMetaData(RAST._IType display, bool copySemantics, bool overflow) : base() { + this._display = display; + this._copySemantics = copySemantics; + this._overflow = overflow; + } + public override _IType DowncastClone() { + if (this is _IType dt) { return dt; } + return new Type_TMetaData(_display, _copySemantics, _overflow); + } + public override bool Equals(object other) { + var oth = other as RAST.Type_TMetaData; + return oth != null && object.Equals(this._display, oth._display) && this._copySemantics == oth._copySemantics && this._overflow == oth._overflow; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 24; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._display)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._copySemantics)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overflow)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.Type.TMetaData"; + s += "("; + s += Dafny.Helpers.ToString(this._display); + s += ", "; + s += Dafny.Helpers.ToString(this._copySemantics); + s += ", "; + s += Dafny.Helpers.ToString(this._overflow); + s += ")"; + return s; + } + } public interface _ITrait { bool is_Trait { get; } @@ -4547,9 +4653,12 @@ public override string ToString() { public interface _IImplMember { bool is_RawImplMember { get; } + bool is_TypeDeclMember { get; } bool is_FnDecl { get; } bool is_ImplMemberMacro { get; } Dafny.ISequence dtor_content { get; } + Dafny.ISequence dtor_name { get; } + RAST._IType dtor_rhs { get; } RAST._IVisibility dtor_pub { get; } RAST._IFn dtor_fun { get; } RAST._IExpr dtor_expr { get; } @@ -4570,6 +4679,9 @@ public static RAST._IImplMember Default() { public static _IImplMember create_RawImplMember(Dafny.ISequence content) { return new ImplMember_RawImplMember(content); } + public static _IImplMember create_TypeDeclMember(Dafny.ISequence name, RAST._IType rhs) { + return new ImplMember_TypeDeclMember(name, rhs); + } public static _IImplMember create_FnDecl(RAST._IVisibility pub, RAST._IFn fun) { return new ImplMember_FnDecl(pub, fun); } @@ -4577,6 +4689,7 @@ public static _IImplMember create_ImplMemberMacro(RAST._IExpr expr) { return new ImplMember_ImplMemberMacro(expr); } public bool is_RawImplMember { get { return this is ImplMember_RawImplMember; } } + public bool is_TypeDeclMember { get { return this is ImplMember_TypeDeclMember; } } public bool is_FnDecl { get { return this is ImplMember_FnDecl; } } public bool is_ImplMemberMacro { get { return this is ImplMember_ImplMemberMacro; } } public Dafny.ISequence dtor_content { @@ -4585,6 +4698,18 @@ public Dafny.ISequence dtor_content { return ((ImplMember_RawImplMember)d)._content; } } + public Dafny.ISequence dtor_name { + get { + var d = this; + return ((ImplMember_TypeDeclMember)d)._name; + } + } + public RAST._IType dtor_rhs { + get { + var d = this; + return ((ImplMember_TypeDeclMember)d)._rhs; + } + } public RAST._IVisibility dtor_pub { get { var d = this; @@ -4609,6 +4734,8 @@ public RAST._IExpr dtor_expr { return Dafny.Sequence.Concat(((this).dtor_pub)._ToString(), ((this).dtor_fun)._ToString(ind)); } else if ((this).is_ImplMemberMacro) { return Dafny.Sequence.Concat(((this).dtor_expr)._ToString(ind), Dafny.Sequence.UnicodeFromString(";")); + } else if ((this).is_TypeDeclMember) { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("type "), (this).dtor_name), Dafny.Sequence.UnicodeFromString(" = ")), ((this).dtor_rhs)._ToString(ind)), Dafny.Sequence.UnicodeFromString(";")); } else { return (this).dtor_content; } @@ -4641,6 +4768,38 @@ public override string ToString() { return s; } } + public class ImplMember_TypeDeclMember : ImplMember { + public readonly Dafny.ISequence _name; + public readonly RAST._IType _rhs; + public ImplMember_TypeDeclMember(Dafny.ISequence name, RAST._IType rhs) : base() { + this._name = name; + this._rhs = rhs; + } + public override _IImplMember DowncastClone() { + if (this is _IImplMember dt) { return dt; } + return new ImplMember_TypeDeclMember(_name, _rhs); + } + public override bool Equals(object other) { + var oth = other as RAST.ImplMember_TypeDeclMember; + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._rhs, oth._rhs); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._rhs)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.ImplMember.TypeDeclMember"; + s += "("; + s += this._name.ToVerbatimString(true); + s += ", "; + s += Dafny.Helpers.ToString(this._rhs); + s += ")"; + return s; + } + } public class ImplMember_FnDecl : ImplMember { public readonly RAST._IVisibility _pub; public readonly RAST._IFn _fun; @@ -4658,7 +4817,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + 2; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._pub)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fun)); return (int) hash; @@ -4688,7 +4847,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + 3; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); return (int) hash; } @@ -4860,7 +5019,7 @@ public __T Fold<__T>(__T acc, Func<__T, RAST._IType, __T> ft) return ((this).dtor_tpe).Fold<__T>(acc, ft); } public Dafny.ISequence _ToString(Dafny.ISequence ind) { - if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("self"))) && (object.Equals((this).dtor_tpe, RAST.__default.SelfOwned))) { + if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("self"))) && (object.Equals(((this).dtor_tpe).Expand(), RAST.__default.SelfOwned))) { return (this).dtor_name; } else if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("self"))) && (object.Equals((this).dtor_tpe, RAST.__default.SelfBorrowed))) { return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&"), (this).dtor_name); diff --git a/Source/DafnyCore/Resolver/PreType/PreTypeResolve.Expressions.cs b/Source/DafnyCore/Resolver/PreType/PreTypeResolve.Expressions.cs index 71d3034f687..ea3cf770c04 100644 --- a/Source/DafnyCore/Resolver/PreType/PreTypeResolve.Expressions.cs +++ b/Source/DafnyCore/Resolver/PreType/PreTypeResolve.Expressions.cs @@ -722,7 +722,7 @@ resolutionContext.CodeContext is ConstantField || ResolveExpression(e.Test, resolutionContext); ResolveExpression(e.Thn, resolutionContext); ResolveExpression(e.Els, resolutionContext); - e.Test.PreType = ConstrainResultToBoolFamily(e.Test.tok, "if-then-else test", "guard condition in if-then-else expression must be a boolean (instead got {0})"); + ConstrainExpressionToBoolFamily(e.Test, "guard condition in if-then-else expression must be a boolean (instead got {0})"); iteExpr.PreType = CreatePreTypeProxy("if-then-else branches"); AddSubtypeConstraint(iteExpr.PreType, e.Thn.PreType, iteExpr.tok, "the two branches of an if-then-else expression must have the same type (got {0} and {1})"); AddSubtypeConstraint(iteExpr.PreType, e.Els.PreType, iteExpr.tok, "the two branches of an if-then-else expression must have the same type (got {0} and {1})"); diff --git a/Source/DafnyRuntime/DafnyRuntimeGo-gomod/dafny/dafny.go b/Source/DafnyRuntime/DafnyRuntimeGo-gomod/dafny/dafny.go index b6ed0bced5a..9dd9935ce67 100644 --- a/Source/DafnyRuntime/DafnyRuntimeGo-gomod/dafny/dafny.go +++ b/Source/DafnyRuntime/DafnyRuntimeGo-gomod/dafny/dafny.go @@ -3153,20 +3153,20 @@ type GoAtomicBox struct { value interface{} } -func (box GoAtomicBox) Get() interface{} { +func (box *GoAtomicBox) Get() interface{} { return box.value } -func (box GoAtomicBox) Put(value interface{}) { +func (box *GoAtomicBox) Put(value interface{}) { box.value = value } -func (box GoAtomicBox) String() string { +func (box *GoAtomicBox) String() string { return "dafny.GoAtomicBox" } func (CompanionStruct_AtomicBox_) Make(value interface{}) AtomicBox { - return GoAtomicBox{ + return &GoAtomicBox{ value: value, } } diff --git a/Source/DafnyRuntime/DafnyRuntimeGo/dafny/dafny.go b/Source/DafnyRuntime/DafnyRuntimeGo/dafny/dafny.go index a5a5af646c1..4016e2c22ca 100644 --- a/Source/DafnyRuntime/DafnyRuntimeGo/dafny/dafny.go +++ b/Source/DafnyRuntime/DafnyRuntimeGo/dafny/dafny.go @@ -3154,20 +3154,20 @@ type GoAtomicBox struct { value interface{} } -func (box GoAtomicBox) Get() interface{} { +func (box *GoAtomicBox) Get() interface{} { return box.value } -func (box GoAtomicBox) Put(value interface{}) { +func (box *GoAtomicBox) Put(value interface{}) { box.value = value } -func (box GoAtomicBox) String() string { +func (box *GoAtomicBox) String() string { return "dafny.GoAtomicBox" } func (CompanionStruct_AtomicBox_) Make(value interface{}) AtomicBox { - return GoAtomicBox{ + return &GoAtomicBox{ value: value, } } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/arrays.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/arrays.dfy.rs.check deleted file mode 100644 index 3d586af71fb..00000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/arrays.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0061]: this function takes 1 argument but 0 arguments were supplied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/SequenceConcatOptimization.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/SequenceConcatOptimization.dfy index 5b05bc628d0..a8f022b20c9 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/SequenceConcatOptimization.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/SequenceConcatOptimization.dfy @@ -13,9 +13,19 @@ module SequenceConcatOptimization { // but the others take much longer than I was willing to wait. method {:test} SirConcatsALot() { var s: seq := []; - for i := 0 to 1_000_000 { + var n := 1_000_000; + + for i := 0 to n + invariant |s| == i + { s := s + [i]; } - expect |s| == 1_000_000; + + for i := 0 to n + { + expect s[i] == i; + } + + expect |s| == n; } } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy index 080ec70510b..1032bc6f888 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy @@ -1,4 +1,7 @@ -// RUN: %testDafnyForEachCompiler --refresh-exit-code=0 "%s" +// NONUNIFORM: Test of Rust's ability to support newtypes +// RUN: %baredafny run -t:rs "%s" +// RUN: %baredafny run -t:rs --unicode-char=false "%s" +/// %testDafnyForEachCompiler --refresh-exit-code=0 "%s" newtype int2 = x: int | -2 <= x < 2 newtype int16 = x: int | -32768 <= x < 32768 @@ -11,6 +14,117 @@ const cu: CodeUnit := 0 newtype uint8 = x: int | 0 <= x < 0x100 type byte = uint8 newtype uint32 = x: int | 0 <= x < 0x1_00000000 +newtype {:nativeType "ulong"} NewNat = n:nat | n <= -(1 as bv64) as nat + +newtype {:rust_erase false} uint32_noterased = x: int | 0 <= x < 0x1_00000000 +newtype another_int = x: int | true + +newtype uint32WithMethods = x: int | 0 <= x < 0x1_00000000 { + static const zero: uint32WithMethods := 0 as uint32WithMethods + static const one: uint32WithMethods := zero + 1 + const n: int := this as int + static function ctor(x: int): uint32WithMethods { + if 0 <= x < 0x1_00000000 then + x as uint32WithMethods + else + zero + } + function plus(y: uint32WithMethods): uint32WithMethods + requires this as int + y as int < 0x1_00000000 + { + this + y + } + function plus_overflow(y: uint32WithMethods): uint32WithMethods + { + (this as bv32 + y as bv32) as uint32WithMethods + } + function minus_overflow(y: uint32WithMethods): uint32WithMethods + { + (this as bv32 - y as bv32) as uint32WithMethods + } + function times_overflow(y: uint32WithMethods): uint32WithMethods + { + (this as bv32 * y as bv32) as uint32WithMethods + } + function div_overflow(y: uint32WithMethods): uint32WithMethods + requires y != 0 + { + (this as bv32 / y as bv32) as uint32WithMethods + } +} + +newtype IntWrapper = int { + const zero := 0 as IntWrapper + const even := (this as int) % 2 == 0 + function len(): int + requires this >= 0 + { + if this == 0 then 0 else + 1 + (this / 2).len() + } + method firstTwoBits(maxDepth: uint32WithMethods) returns (output: int) { + if this <= 3 || maxDepth == 0 { + output := this as int; + } else { + output := (this / 2).firstTwoBits(maxDepth - 1); + } + } + function add(other: IntWrapper): IntWrapper { + this + other + } + function DoublePlus(plus: IntWrapper): IntWrapper { + this * 2 + plus + plus.zero.AddZero() + } + function AddZero(): IntWrapper { + this + } + + function less(other: IntWrapper): bool { + this < other + } +} + +newtype NestedIntWrapper = IntWrapper { + function DoubleMinus(other: NestedIntWrapper): IntWrapper { + (this * 47 - other) as IntWrapper + } +} + +// Ensuring the uint32 is hashable +datatype {:rust_rc false} UInt32Pair = + UInt32Pair(first: uint32WithMethods, second: uint32WithMethods) + + +type PairIntWrappers = (IntWrapper, IntWrapper) +datatype {:rust_rc false} PairInts = PairInts( + pair: PairIntWrappers +) { + static function build(i: IntWrapper, j: IntWrapper): PairInts { + PairInts((i, j)) + } + function add(other: PairInts): PairInts { + PairInts((this.pair.0 + other.pair.0, this.pair.1 + other.pair.1)) + } + + function second_(): IntWrapper { pair.1 } + const second := second_() +} + +datatype {:rust_rc false} TwoIntWrappers = TwoIntWrappers( + first:IntWrapper, + second:IntWrapper +) { + function PairIntsFirstZero():PairInts { PairInts.build(0, second) } + const firstZero := PairIntsFirstZero() + const secondZero := PairInts.build(first, 0) + const underlying := firstZero.add(secondZero) + static const origin := TwoIntWrappers(0,0) + const total := first + second + + function plus(a:TwoIntWrappers):(r:TwoIntWrappers) { + TwoIntWrappers(first.add(a.first), firstZero.add(a.firstZero).second) + } +} method Main(){ print INT2_MAX as int, "\n"; @@ -22,4 +136,52 @@ method Main(){ var arr := new bool[INT2_MAX]; print arr.Length, "\n"; print DChar as uint32, "\n"; + + var three := uint32WithMethods.ctor(3); + var six := three.plus(three); + var two := uint32WithMethods.ctor(2); + var almost_overflow := 0xFFFFFFFF as uint32WithMethods; + var almost_overflow2 := 0xFFFFFFFE as uint32WithMethods; + + // Non erased bounded newtype <--> non erased unbounded newtype + var two_int := two as IntWrapper; + var two_back := two_int as uint32WithMethods; + expect two == two_back; + + // Non erased bounded newtype forced <--> non erased unbounded newtype + var two_noterased := two as uint32_noterased; + var two_noterased_int := two_noterased as IntWrapper; + var two_noterased_int_back := two_noterased_int as uint32_noterased; + expect two_noterased == two_noterased_int_back; + + // erased bounded newtype <--> non erased unbounded newtype + var two_uint32 := two as uint32; + var two_uint32_int := two_uint32 as IntWrapper; + var two_uint32_int_back := two_uint32_int as uint32; + expect two_uint32 == two_uint32_int_back; + + // erased bounded newtype <--> erased unbounded newtype + var two_uint32_another_int := two_uint32 as another_int; + var two_uint32_another_int_back := two_uint32_another_int as uint32; + expect two_uint32 == two_uint32_another_int_back; + + expect two == three.plus_overflow(almost_overflow); + expect almost_overflow == two.minus_overflow(three); + expect six == three.times_overflow(two); + expect 0 as uint32WithMethods == two.div_overflow(three); + expect almost_overflow2 == almost_overflow.times_overflow(two); + expect (3 as IntWrapper).DoublePlus(1 as IntWrapper) == 7 as IntWrapper; + var i := 1; + expect !(i as IntWrapper).even; + var j := 2; + expect (j as IntWrapper).even; + expect (i as IntWrapper).less(j as IntWrapper); + expect (7 as IntWrapper).len() == 3; + expect (8 as IntWrapper).len() == 4; + var x := (8 as IntWrapper).firstTwoBits(100); + expect x == 2; + x := (7 as IntWrapper).firstTwoBits(100); + expect x == 3; + var bb := 1 as bv8; + expect !bb == 254; } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy new file mode 100644 index 00000000000..572d54490b3 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy @@ -0,0 +1,35 @@ +// NONUNIFORM: Test of Rust's ability to support newtypes +// RUN: %baredafny run -t:rs --type-system-refresh --general-newtypes "%s" + +newtype BoolWrapper = bool { + const n: int := if this then 1 else 0 + static function True(): BoolWrapper { + true as BoolWrapper + } + function Or(other: BoolWrapper): BoolWrapper { + if n == 1 then True() else other + } + static const OrFun: (BoolWrapper, BoolWrapper) -> BoolWrapper := + (a, b) => a || b + + static function ApplyFalseTrue(f: (BoolWrapper, BoolWrapper) -> BoolWrapper): BoolWrapper { + f(false as BoolWrapper, true as BoolWrapper) + } + + function xor(other: BoolWrapper): BoolWrapper { + this != other + } +} + +method Main(){ + expect (true as BoolWrapper).Or(false as BoolWrapper) == (true as BoolWrapper); + expect (false as BoolWrapper).Or(false as BoolWrapper) == (false as BoolWrapper); + expect (false as BoolWrapper).Or(true as BoolWrapper) == (true as BoolWrapper); + expect BoolWrapper.ApplyFalseTrue(BoolWrapper.OrFun) == (true as BoolWrapper); + var x := true as BoolWrapper; + if !x { + expect if !x then false else false; + } else if x { + expect if x then true else true; + } +} diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy.expect new file mode 100644 index 00000000000..e1ec30b7a61 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy.expect @@ -0,0 +1,7 @@ +1 +0 +'D' +0 +[0] +1 +68 diff --git a/docs/Gemfile.lock b/docs/Gemfile.lock index 1dfcd8efd8c..0256d191cdd 100644 --- a/docs/Gemfile.lock +++ b/docs/Gemfile.lock @@ -60,15 +60,13 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - rexml (3.3.6) - strscan + rexml (3.3.9) rouge (4.2.0) safe_yaml (1.0.5) sass-embedded (1.69.7-arm64-darwin) google-protobuf (~> 3.25) sass-embedded (1.69.7-x86_64-linux-gnu) google-protobuf (~> 3.25) - strscan (3.1.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) unicode-display_width (2.5.0)