diff --git a/.github/workflows/runtime-tests.yml b/.github/workflows/runtime-tests.yml index 08696e824b5..c3756189bd9 100644 --- a/.github/workflows/runtime-tests.yml +++ b/.github/workflows/runtime-tests.yml @@ -48,7 +48,7 @@ jobs: cd ./Source/DafnyCore make test make check-format - - name: Test DafnyRuntime (C#) + - name: Test DafnyRuntime (C#, Rust) run: | cd ./Source/DafnyRuntime make all @@ -72,3 +72,7 @@ jobs: run: | cd ./Source/DafnyRuntime/DafnyRuntimeJs make all + - name: Test DafnyRuntimeRust + run: | + cd ./Source/DafnyRuntime/DafnyRuntimeRust + make all diff --git a/Makefile b/Makefile index 273bd2dad69..d7e8959495e 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,10 @@ boogie: ${DIR}/boogie/Binaries/Boogie.exe tests: (cd "${DIR}"; dotnet test Source/IntegrationTests) +# make test name= +test: + (cd "${DIR}"; dotnet test Source/IntegrationTests --filter "DisplayName~${name}") + tests-verbose: (cd "${DIR}"; dotnet test --logger "console;verbosity=normal" Source/IntegrationTests ) @@ -87,12 +91,17 @@ clean: update-cs-module: (cd "${DIR}"; cd Source/DafnyRuntime; make update-system-module) +update-rs-module: + (cd "${DIR}"; cd Source/DafnyRuntime/DafnyRuntimeRust; make update-system-module) + update-go-module: (cd "${DIR}"; cd Source/DafnyRuntime/DafnyRuntimeGo; make update-system-module) update-runtime-dafny: (cd "${DIR}"; cd Source/DafnyRuntime/DafnyRuntimeDafny; make update-go) +pr-nogeneration: format-dfy format update-runtime-dafny update-cs-module update-rs-module update-go-module + update-standard-libraries: (cd "${DIR}"; cd Source/DafnyStandardLibraries; make update-binary) @@ -103,4 +112,7 @@ update-standard-libraries: # - Apply dafny format on all dfy files # - Apply dotnet format on all cs files except the generated ones # - Rebuild the Go and C# runtime modules as needed. -pr: exe dfy-to-cs-exe format-dfy format update-runtime-dafny update-cs-module update-go-module +pr: exe dfy-to-cs-exe pr-nogeneration + +# Same as `make pr` but useful when resolving conflicts, to take the last compiled version of Dafny first +pr-conflict: dfy-to-cs-exe dfy-to-cs-exe pr-nogeneration diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs b/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs index 8a4171f4809..8319b008012 100644 --- a/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs +++ b/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs @@ -15,15 +15,22 @@ namespace DafnyToRustCompilerCoverage.RASTCoverage { public partial class __default { + public static void TestExpr() + { + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestOptimizeToString(); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestPrintingInfo(); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoExtraSemicolonAfter(); + FactorPathsOptimizationTest.__default.TestApply(); + } 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_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("truncate!")), Dafny.Sequence.FromElements(x, RAST.Expr.create_ExprFromType(t))); + 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_MemberSelect(RAST.__default.dafny__runtime, Dafny.Sequence.UnicodeFromString("int!")), Dafny.Sequence.FromElements(RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")))); + 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 void TestOptimizeToString() { @@ -53,7 +60,7 @@ public static void TestOptimizeToString() 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((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"))))).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_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_MemberSelect(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.UnicodeFromString("abc"))); + _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; @@ -76,14 +83,8 @@ public static void TestOptimizeToString() _12___v7 = (DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), _4_c)).Optimize(); RAST._IExpr _13___v8; _13___v8 = (DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(_4_c, Dafny.Sequence.FromElements()))).Optimize(); - RAST._IExpr _14___v9; - _14___v9 = (DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(_4_c, Dafny.Sequence.UnicodeFromString("int!")), Dafny.Sequence.FromElements()))).Optimize(); - RAST._IExpr _15___v10; - _15___v10 = (DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(_4_c, Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("int!")), Dafny.Sequence.FromElements()))).Optimize(); - RAST._IExpr _16___v11; - _16___v11 = (DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("int!")), Dafny.Sequence.FromElements(_4_c)))).Optimize(); - Std.Wrappers._IOption> _17___v12; - _17___v12 = (_4_c).RightMostIdentifier(); + Std.Wrappers._IOption> _14___v9; + _14___v9 = (_4_c).RightMostIdentifier(); } } public static void TestPrintingInfo() @@ -106,7 +107,7 @@ public static void TestPrintingInfo() 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_MemberSelect(_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()))); @@ -143,12 +144,6 @@ public static void TestPrintingInfo() 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 TestExpr() - { - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestOptimizeToString(); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestPrintingInfo(); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoExtraSemicolonAfter(); - } public static void AssertCoverage(bool x) { } diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs b/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs new file mode 100644 index 00000000000..02b63cfbb13 --- /dev/null +++ b/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs @@ -0,0 +1,47 @@ +// 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 FactorPathsOptimizationTest { + + public partial class __default { + public static void ShouldBeEqual(RAST._IMod a, RAST._IMod b) + { + Dafny.ISequence _0_sA; + _0_sA = (a)._ToString(Dafny.Sequence.UnicodeFromString("")); + Dafny.ISequence _1_sB; + _1_sB = (b)._ToString(Dafny.Sequence.UnicodeFromString("")); + if (!(_0_sA).Equals(_1_sB)) { + Dafny.Helpers.Print((Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Got:\n"), _0_sA), Dafny.Sequence.UnicodeFromString("\n"))).ToVerbatimString(false)); + Dafny.Helpers.Print((Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Expected:\n"), _1_sB), Dafny.Sequence.UnicodeFromString("\n"))).ToVerbatimString(false)); + if (!((_0_sA).Equals(_1_sB))) { + throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-path-simplification.dfy(12,6): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} + } + } + public static void TestApply() + { + RAST._ITypeParamDecl _0_T__Decl; + _0_T__Decl = RAST.TypeParamDecl.create(Dafny.Sequence.UnicodeFromString("T"), Dafny.Sequence.FromElements(RAST.__default.DafnyType)); + RAST._ITypeParamDecl _1_T__Decl__simp; + _1_T__Decl__simp = RAST.TypeParamDecl.create(Dafny.Sequence.UnicodeFromString("T"), Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("DafnyType")))); + RAST._IType _2_T; + _2_T = RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("T")); + RAST._IPath _3_std__any__Any; + _3_std__any__Any = (((RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("std"))).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any")); + RAST._IType _4_Any; + _4_Any = RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Any")); + FactorPathsOptimizationTest.__default.ShouldBeEqual(FactorPathsOptimization.__default.apply(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_0_T__Decl), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), (_3_std__any__Any).AsType())))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_0_T__Decl), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (_3_std__any__Any).AsType(), ((((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("test"))).AsType()).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_1_T__Decl__simp), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), _4_Any)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), _4_Any, (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements()))))); + FactorPathsOptimizationTest.__default.ShouldBeEqual(FactorPathsOptimization.__default.apply(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject"))).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject")))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("UpcastObject"))).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements()))))); + } + } +} // end of namespace FactorPathsOptimizationTest \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 410ec735605..379456535d7 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -36,7 +36,11 @@ module {:extern "DAST"} DAST { // See issue https://github.com/dafny-lang/dafny/issues/5345 datatype Name = Name(dafny_name: string) - datatype Module = Module(name: Name, attributes: seq, body: Option>) + // A special Dafny name wrapper for variable names. + // For example, the identifier 'None' needs to be escaped in Rust, but not as a constructor. + datatype VarName = VarName(dafny_name: string) + + datatype Module = Module(name: Name, attributes: seq, requiresExterns: bool, body: Option>) datatype ModuleItem = | Module(Module) @@ -45,6 +49,28 @@ module {:extern "DAST"} DAST { | Newtype(Newtype) | SynonymType(SynonymType) | Datatype(Datatype) + { + function name(): Name { + match this { + case Module(m) => m.name + case Class(m) => m.name + case Trait(m) => m.name + case Newtype(m) => m.name + case SynonymType(m) => m.name + case Datatype(m) => m.name + } + } + function attributes(): seq { + match this { + case Module(m) => m.attributes + case Class(m) => m.attributes + case Trait(m) => m.attributes + case Newtype(m) => m.attributes + case SynonymType(m) => m.attributes + case Datatype(m) => m.attributes + } + } + } datatype Type = UserDefined(resolved: ResolvedType) | @@ -127,7 +153,7 @@ module {:extern "DAST"} DAST { typeArgs: seq, kind: ResolvedTypeBase, attributes: seq, - properMethods: seq, + properMethods: seq, extendedTypes: seq) { function Replace(mapping: map): ResolvedType { ResolvedType( @@ -175,7 +201,7 @@ module {:extern "DAST"} DAST { datatype Field = Field(formal: Formal, defaultValue: Option) - datatype Formal = Formal(name: Name, typ: Type, attributes: seq) + datatype Formal = Formal(name: VarName, typ: Type, attributes: seq) datatype Method = Method( isStatic: bool, @@ -188,22 +214,22 @@ module {:extern "DAST"} DAST { params: seq, body: seq, outTypes: seq, - outVars: Option>) + outVars: Option>) datatype CallSignature = CallSignature(parameters: seq) datatype CallName = - CallName(name: Name, onType: Option, receiverArgs: Option, signature: CallSignature) | + CallName(name: Name, onType: Option, receiverArg: Option, receiverAsArgument: bool, signature: CallSignature) | MapBuilderAdd | MapBuilderBuild | SetBuilderAdd | SetBuilderBuild datatype Statement = - DeclareVar(name: Name, typ: Type, maybeValue: Option) | + DeclareVar(name: VarName, typ: Type, maybeValue: Option) | Assign(lhs: AssignLhs, value: Expression) | If(cond: Expression, thn: seq, els: seq) | Labeled(lbl: string, body: seq) | While(cond: Expression, body: seq) | - Foreach(boundName: Name, boundType: Type, over: Expression, body: seq) | - Call(on: Expression, callName: CallName, typeArgs: seq, args: seq, outs: Option>) | + Foreach(boundName: VarName, boundType: Type, over: Expression, body: seq) | + Call(on: Expression, callName: CallName, typeArgs: seq, args: seq, outs: Option>) | Return(expr: Expression) | EarlyReturn() | Break(toLabel: Option) | @@ -216,8 +242,8 @@ module {:extern "DAST"} DAST { } datatype AssignLhs = - Ident(ident: Ident) | - Select(expr: Expression, field: Name) | + Ident(ident: VarName) | + Select(expr: Expression, field: VarName) | Index(expr: Expression, indices: seq) datatype CollKind = Seq | Array | Map @@ -244,14 +270,15 @@ module {:extern "DAST"} DAST { datatype Expression = Literal(Literal) | - Ident(name: Name) | + Ident(name: VarName) | Companion(seq, typeArgs: seq) | + ExternCompanion(seq) | Tuple(seq) | New(path: seq, typeArgs: seq, args: seq) | NewUninitArray(dims: seq, typ: Type) | ArrayIndexToInt(value: Expression) | FinalizeNewArray(value: Expression, typ: Type) | - DatatypeValue(datatypeType: ResolvedType, typeArgs: seq, variant: Name, isCo: bool, contents: seq<(string, Expression)>) | + DatatypeValue(datatypeType: ResolvedType, typeArgs: seq, variant: Name, isCo: bool, contents: seq<(VarName, Expression)>) | Convert(value: Expression, from: Type, typ: Type) | SeqConstruct(length: Expression, elem: Expression) | SeqValue(elements: seq, typ: Type) | @@ -270,23 +297,25 @@ module {:extern "DAST"} DAST { ArrayLen(expr: Expression, exprType: Type, dim: nat, native: bool) | MapKeys(expr: Expression) | MapValues(expr: Expression) | - Select(expr: Expression, field: Name, isConstant: bool, onDatatype: bool, fieldType: Type) | - SelectFn(expr: Expression, field: Name, onDatatype: bool, isStatic: bool, arity: nat) | + MapItems(expr: Expression) | + Select(expr: Expression, field: VarName, isConstant: bool, onDatatype: bool, fieldType: Type) | + SelectFn(expr: Expression, field: VarName, onDatatype: bool, isStatic: bool, isConstant: bool, arguments: seq) | Index(expr: Expression, collKind: CollKind, indices: seq) | IndexRange(expr: Expression, isArray: bool, low: Option, high: Option) | TupleSelect(expr: Expression, index: nat, fieldType: Type) | Call(on: Expression, callName: CallName, typeArgs: seq, args: seq) | Lambda(params: seq, retType: Type, body: seq) | BetaRedex(values: seq<(Formal, Expression)>, retType: Type, expr: Expression) | - IIFE(ident: Ident, typ: Type, value: Expression, iifeBody: Expression) | + IIFE(ident: VarName, typ: Type, value: Expression, iifeBody: Expression) | Apply(expr: Expression, args: seq) | TypeTest(on: Expression, dType: seq, variant: Name) | + Is(expr: Expression, fromType: Type, toType: Type) | InitializationValue(typ: Type) | BoolBoundedPool() | SetBoundedPool(of: Expression) | MapBoundedPool(of: Expression) | SeqBoundedPool(of: Expression, includeDuplicates: bool) | - IntRange(lo: Expression, hi: Expression, up: bool) | + IntRange(elemType: Type, lo: Expression, hi: Expression, up: bool) | UnboundedIntRange(start: Expression, up: bool) | Quantifier(elemType: Type, collection: Expression, is_forall: bool, lambda: Expression) diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index 0c4396a9d33..9e6e32ae148 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -35,13 +35,13 @@ public void AddUnsupported(string why) { interface ModuleContainer : Container { void AddModule(Module item); - public ModuleBuilder Module(string name, Sequence attributes) { - return new ModuleBuilder(this, name, attributes); + public ModuleBuilder Module(string name, Sequence attributes, bool requiresExterns) { + 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)), + Sequence.UnicodeFromString(why), Sequence>.Empty)), false, Std.Wrappers.Option>.create_None()); } } @@ -51,11 +51,13 @@ class ModuleBuilder : ClassContainer, TraitContainer, NewtypeContainer, Datatype readonly string name; readonly Sequence attributes; readonly List body = new(); + private readonly bool requiresExterns; - public ModuleBuilder(ModuleContainer parent, string name, Sequence attributes) { + public ModuleBuilder(ModuleContainer parent, string name, Sequence attributes, bool requiresExterns) { this.parent = parent; this.name = name; this.attributes = attributes; + this.requiresExterns = requiresExterns; } public void AddModule(Module item) { @@ -82,6 +84,7 @@ public object Finish() { parent.AddModule((Module)Module.create( Sequence.UnicodeFromString(this.name), attributes, + requiresExterns, Std.Wrappers.Option>.create_Some((Sequence)Sequence.FromArray(body.ToArray())) )); @@ -1834,6 +1837,7 @@ public DAST.Expression Build() { } return (DAST.Expression)DAST.Expression.create_IntRange( + DAST.Type.create_Primitive(DAST.Primitive.create_Int()), startExpr, endExpr, true); } diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index d865e0b72dc..9673908665c 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -92,6 +92,7 @@ public void AddUnsupportedFeature(IToken token, Feature feature) { Feature.ExternalConstructors, Feature.SubtypeConstraintsInQuantifiers, Feature.TuplesWiderThan20, + Feature.ArraysWithMoreThan16Dims, Feature.ForLoops, Feature.Traits, Feature.RuntimeCoverageReport, @@ -119,6 +120,11 @@ protected override ConcreteSyntaxTree CreateStaticMain(IClassWriter cw, string a new ExprBuffer(this), this); } + private bool NeedsExternalImport(MemberDecl memberDecl) { + return !memberDecl.IsGhost && memberDecl.HasExternAttribute && + memberDecl is Function { Body: null } or Method { Body: null }; + } + protected override ConcreteSyntaxTree CreateModule(string moduleName, bool isDefault, ModuleDefinition externModule, string libraryName, ConcreteSyntaxTree wr) { if (currentBuilder is ModuleContainer moduleBuilder) { @@ -126,7 +132,17 @@ protected override ConcreteSyntaxTree CreateModule(string moduleName, bool isDef if (externModule != null) { attributes = (Sequence)ParseAttributes(externModule.Attributes); } - currentBuilder = moduleBuilder.Module(moduleName, attributes); + + var requiresExternImport = enclosingModule.TopLevelDecls.Any((TopLevelDecl decl) => + (decl is DefaultClassDecl defaultClassDecl && + GetIsExternAndIncluded(defaultClassDecl) is (_, included: false) + && defaultClassDecl.Members.Exists(NeedsExternalImport) + ) || + (decl is ClassLikeDecl classLikeDecl && + GetIsExternAndIncluded(classLikeDecl) is (classIsExtern: true, _)) || + (decl is AbstractTypeDecl) + ); + currentBuilder = moduleBuilder.Module(moduleName, attributes, requiresExternImport); } else { throw new InvalidOperationException(); } @@ -357,17 +373,34 @@ private DAST.Type GenType(Type typ) { return FullTypeNameAST(udt, null); } else if (AsNativeType(typ) != null) { - return (DAST.Type)(AsNativeType(typ).Sel switch { - NativeType.Selection.Byte => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("u8")), - NativeType.Selection.SByte => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("i8")), - NativeType.Selection.Short => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("i16")), - NativeType.Selection.UShort => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("u16")), - NativeType.Selection.Int => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("i32")), - NativeType.Selection.UInt => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("u32")), - NativeType.Selection.Long => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("i64")), - NativeType.Selection.ULong => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("u64")), - NativeType.Selection.DoubleLong => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("i128")), - NativeType.Selection.UDoubleLong => DAST.Type.create_Passthrough(Sequence.UnicodeFromString("u128")), + var CreateNewtype = (string baseName, DAST._INewtypeRange newTypeRange) => + DAST.Type.create_UserDefined( + DAST.ResolvedType.create_ResolvedType( + Sequence>.FromElements( + Sequence.UnicodeFromString(baseName) + ), + Sequence.Empty, + DAST.ResolvedTypeBase.create_Newtype( + DAST.Type.create_Primitive(DAST.Primitive.create_Int()), + newTypeRange, + true + ), + Sequence.Empty, + Sequence>.Empty, + Sequence.Empty + ) + ); + 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()), _ => throw new InvalidOperationException(), }); } else if (xType is SeqType seq) { @@ -826,10 +859,10 @@ protected override void EmitNameAndActualTypeArgs(string protectedName, List.UnicodeFromString(protectedName), receiverType, receiverArg, signature)); + callExpr.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString(protectedName), receiverType, receiverArg, receiverAsArgument, signature)); } else if (GetExprBuilder(wr, out var st2) && st2.Builder is CallStmtBuilder callStmt) { var signature = callStmt.Signature; - callStmt.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString(protectedName), receiverType, receiverArg, signature)); + callStmt.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString(protectedName), receiverType, receiverArg, receiverAsArgument, signature)); } else { AddUnsupported("Builder issue: wr is as " + wr.GetType() + (GetExprBuilder(wr, out var st3) ? @@ -883,7 +916,7 @@ protected override void DeclareLocalVar(string name, Type type, IToken tok, bool var rhsValue = bufferedInitializationValue; bufferedInitializationValue = null; - if (bufferedInitializationStmts.is_Some) { + if (bufferedInitializationStmts is { is_Some: true }) { foreach (var stmt in bufferedInitializationStmts.dtor_value) { stmtContainer.Builder.AddStatement(stmt); } @@ -951,6 +984,19 @@ public override bool NeedsCustomReceiverNotTrait(MemberDecl member) { return member is Constructor || base.NeedsCustomReceiverNotTrait(member); } + protected override void EmitStaticExternMethodQualifier(string qual, ConcreteSyntaxTree wr) { + if (GetExprBuilder(wr, out var builder)) { + builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_ExternCompanion( + Sequence>.FromArray(new[] { + DCOMP.COMP.DAFNY__EXTERN__MODULE, + Sequence.UnicodeFromString(qual) + }) + )); + } else { + throw new InvalidOperationException(); + } + } + protected override void EmitCallToInheritedMethod(Method method, [CanBeNull] TopLevelDeclWithMembers heir, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts, ConcreteSyntaxTree wStmtsAfterCall) { if (wr is BuilderSyntaxTree stmtContainer) { var callBuilder = stmtContainer.Builder.Call(GenFormals(method.Ins)); @@ -966,8 +1012,13 @@ protected override void EmitMultiReturnTuple(List outs, List outTy protected override void CompileFunctionCallExpr(FunctionCallExpr e, ConcreteSyntaxTree wr, bool inLetExprBody, ConcreteSyntaxTree wStmts, FCE_Arg_Translator tr, bool alreadyCoerced) { - var toType = thisContext == null ? e.Type : e.Type.Subst(thisContext.ParentFormalTypeParametersToActuals); - wr = EmitCoercionIfNecessary(e.Function.Original.ResultType, toType, e.tok, wr); + var toType = e.Type.Subst(e.GetTypeArgumentSubstitutions()); + var fromType = e.Function.Original.ResultType.Subst(e.GetTypeArgumentSubstitutions()); + if (thisContext != null) { + toType = toType.Subst(thisContext.ParentFormalTypeParametersToActuals); + fromType = fromType.Subst(thisContext.ParentFormalTypeParametersToActuals); + } + wr = EmitCoercionIfNecessary(fromType, toType, e.tok, wr); if (wr is BuilderSyntaxTree builder) { var callBuilder = builder.Builder.Call(GenFormals(e.Function.Ins)); @@ -1208,16 +1259,21 @@ protected override ConcreteSyntaxTree EmitForStmt(IToken tok, IVariable loopInde start, goingUp )); - TrStmtList(body, new BuilderSyntaxTree(foreachBuilder, this)); + ConcreteSyntaxTree bodyWr = new BuilderSyntaxTree(foreachBuilder, this); + bodyWr = EmitContinueLabel(labels, bodyWr); + TrStmtList(body, bodyWr); return new BuilderSyntaxTree(startBuilder, this); } else { var loHiBuilder = ((ExprContainer)foreachBuilder).BinOp("int_range", (DAST.Expression lo, DAST.Expression hi) => (DAST.Expression)DAST.Expression.create_IntRange( + GenType(loopIndex.Type), lo, hi, goingUp )); - TrStmtList(body, new BuilderSyntaxTree(foreachBuilder, this)); + ConcreteSyntaxTree bodyWr = new BuilderSyntaxTree(foreachBuilder, this); + bodyWr = EmitContinueLabel(labels, bodyWr); + TrStmtList(body, bodyWr); BuilderSyntaxTree toReturn; if (goingUp) { var loBuf = new ExprBuffer(null); @@ -1343,6 +1399,10 @@ protected override void EmitNew(Type type, IToken tok, CallStmt initCall, Concre }); } + if (ctor == null) { + AddUnsupported("Creation of object of type " + type.ToString() + " requires a constructor"); + } + var typeArgs = type.TypeArgs.Select(GenType).ToArray(); builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_New( @@ -1383,6 +1443,28 @@ protected override void EmitIdentifier(string ident, ConcreteSyntaxTree wr) { } } + // Overriden from SinglePassCodeGenerator to return a BuilderSyntaxTree + // To avoid UnsupportedInvalidOperationException in EmitIdentifier by way of set comprehension (github issue 5644) + protected override ConcreteSyntaxTree MaybeEmitCallToIsMethod(RedirectingTypeDecl declWithConstraints, List typeArguments, ConcreteSyntaxTree wr) { + Contract.Requires(declWithConstraints is SubsetTypeDecl or NewtypeDecl); + Contract.Requires(declWithConstraints.TypeArgs.Count == typeArguments.Count); + Contract.Requires(declWithConstraints.ConstraintIsCompilable); + switch (declWithConstraints) { + case NonNullTypeDecl: + // Non-null types don't have a special target class, so we just do the non-null constraint check here. + return EmitNullTest(false, wr); + case NewtypeDecl { TargetTypeCoversAllBitPatterns: true }: { + EmitLiteralExpr(wr, Expression.CreateBoolLiteral(declWithConstraints.tok, true)); + return new BuilderSyntaxTree(new ExprBuffer(null), this); + } + default: { + // in mind that type parameters are not accessible in static methods in some target languages). + var type = UserDefinedType.FromTopLevelDecl(declWithConstraints.tok, (TopLevelDecl)declWithConstraints, typeArguments); + return EmitCallToIsMethod(declWithConstraints, type, wr); + } + } + } + protected override void EmitLiteralExpr(ConcreteSyntaxTree wr, LiteralExpr e) { if (GetExprBuilder(wr, out var builder)) { DAST.Expression baseExpr; @@ -1634,7 +1716,7 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type GenType(EraseNewtypeLayers(topLevel)), range, true); } else if (topLevel is TypeSynonymDecl typeSynonym) { // Also SubsetTypeDecl resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Newtype( - GenType(typeSynonym.Rhs.NormalizeExpand()), NewtypeRange.create_NoRange(), true); + GenType(typeSynonym.Rhs.Subst(typeSynonym.TypeArgs.Zip(typeArgs).ToDictionary(kv => kv.Item1, kv => kv.Item2)).NormalizeExpand()), NewtypeRange.create_NoRange(), true); } else if (topLevel is TraitDecl) { resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Trait(); } else if (topLevel is DatatypeDecl dd) { @@ -1797,6 +1879,8 @@ protected override void GetSpecialFieldInfo(SpecialField.ID id, object idParam, break; case SpecialField.ID.Values: break; + case SpecialField.ID.Items: + break; default: AddUnsupported("Special field: " + id + ""); break; @@ -1862,6 +1946,11 @@ protected override ILvalue EmitMemberSelect(Action obj, Type var objExpr = objReceiver.Finish(); return new ExprLvalue((DAST.Expression)DAST.Expression.create_MapValues( objExpr), null, this); + } else if (member is SpecialField { SpecialId: SpecialField.ID.Items }) { + obj(new BuilderSyntaxTree(objReceiver, this)); + var objExpr = objReceiver.Finish(); + return new ExprLvalue((DAST.Expression)DAST.Expression.create_MapItems( + objExpr), null, this); } else if (member is SpecialField sf && sf.SpecialId != SpecialField.ID.UseIdParam) { obj(new BuilderSyntaxTree(objReceiver, this)); var objExpr = objReceiver.Finish(); @@ -1895,7 +1984,8 @@ protected override ILvalue EmitMemberSelect(Action obj, Type Sequence.UnicodeFromString(member.GetCompileName(Options)), member.EnclosingClass is DatatypeDecl, member.IsStatic, - expectedType.AsArrowType.Arity + member.IsInstanceIndependentConstant, + Sequence.FromElements(expectedType.AsArrowType.Args.Select(GenType).ToArray()) ), null, this); } else if (internalAccess && (member is ConstantField || member.EnclosingClass is TraitDecl)) { return new ExprLvalue((DAST.Expression)DAST.Expression.create_Select( @@ -2232,12 +2322,28 @@ protected override ConcreteSyntaxTree EmitCallToIsMethod(RedirectingTypeDecl dec throw new InvalidOperationException(); } + if (declWithConstraints is SubsetTypeDecl subsetTypeDecl) { + // Since this type becomes a type synonym at run-time, we simply inline the condition + // We put it as a IIFE + var constraint = subsetTypeDecl.Constraint; + + var statementBuf = new NoStatementBuffer(); + ConcreteSyntaxTree sNoStmt = new BuilderSyntaxTree(statementBuf, this); + CreateIIFE(GetCompileNameNotProtected(subsetTypeDecl.Var), subsetTypeDecl.Var.Type, subsetTypeDecl.Var.tok, + Type.Bool, constraint.tok, wr, ref sNoStmt, out ConcreteSyntaxTree wrRhs, out ConcreteSyntaxTree wrBody); + if (!GetExprBuilder(wrBody, out var wrBodyBuilder)) { + throw new InvalidOperationException(); + } + wrBodyBuilder.Builder.AddExpr(ConvertExpression(constraint, sNoStmt)); + return wrRhs; + } + var signature = Sequence<_IFormal>.FromArray(new[] { new DAST.Formal(Sequence.UnicodeFromString("_dummy_"), GenType(type), Sequence.Empty) }); var c = builder.Builder.Call(signature); c.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString("is"), - Option<_IType>.create_None(), Option<_IFormal>.create_None(), signature)); + Option<_IType>.create_None(), Option<_IFormal>.create_None(), false, signature)); var wrc = new BuilderSyntaxTree(c, this); EmitTypeName_Companion(type, wrc, wr, declWithConstraints.tok, null); @@ -2694,7 +2800,15 @@ protected override void EmitConstructorCheck(string source, DatatypeCtor ctor, C } protected override void EmitTypeTest(string localName, Type fromType, Type toType, IToken tok, ConcreteSyntaxTree wr) { - AddUnsupportedFeature(tok, Feature.TypeTests); + if (GetExprBuilder(wr, out var builder)) { + builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_Is( + DAST.Expression.create_Ident(Sequence.UnicodeFromString(localName)), + GenType(fromType), + GenType(toType) + )); + } else { + throw new InvalidOperationException(); + } } protected override void EmitIsIntegerTest(Expression source, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { @@ -2941,6 +3055,7 @@ protected override (Type, Action) EmitIntegerRange(Type type if (GetExprBuilder(wr, out var builder)) { builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_IntRange( + GenType(result), loBuf.Finish(), hiBuf.Finish(), true diff --git a/Source/DafnyCore/Backends/DafnyExecutableBackend.cs b/Source/DafnyCore/Backends/DafnyExecutableBackend.cs index 19ed5bf777e..b3d74485093 100644 --- a/Source/DafnyCore/Backends/DafnyExecutableBackend.cs +++ b/Source/DafnyCore/Backends/DafnyExecutableBackend.cs @@ -1,4 +1,7 @@ +using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; +using System.Linq; using Dafny; namespace Microsoft.Dafny.Compilers; @@ -7,11 +10,14 @@ public abstract class DafnyExecutableBackend : ExecutableBackend { protected virtual bool PreventShadowing => true; protected virtual bool CanEmitUncompilableCode => true; + public override bool SupportsDatatypeWrapperErasure => false; protected virtual string InternalFieldPrefix => "_i_"; protected DafnyWrittenCodeGenerator DafnyCodeGenerator; + public List ImportedFiles = new(); + protected DafnyExecutableBackend(DafnyOptions options) : base(options) { } @@ -27,6 +33,20 @@ public override void OnPreCompile(ErrorReporter reporter, ReadOnlyCollection ImportFilesMapping(string dafnyProgramName) { + Dictionary importedFilesMapping = new(); + return importedFilesMapping; + } + + public IEnumerable ImportFiles(string dafnyProgramName) { + var result = ImportFilesMapping(dafnyProgramName).Values.ToList(); + result.Sort(); + return result; + } + public override void Compile(Program dafnyProgram, string dafnyProgramName, ConcreteSyntaxTree output) { ProcessTranslationRecords(dafnyProgram, dafnyProgramName, output); CheckInstantiationReplaceableModules(dafnyProgram); @@ -35,7 +55,12 @@ public override void Compile(Program dafnyProgram, string dafnyProgramName, Conc ((DafnyCodeGenerator)codeGenerator).Start(); codeGenerator.Compile(dafnyProgram, new ConcreteSyntaxTree()); var dast = ((DafnyCodeGenerator)codeGenerator).Build(); - var o = DafnyCodeGenerator.Compile((Sequence)Sequence.FromArray(dast.ToArray())); + var o = DafnyCodeGenerator.Compile( + (Sequence)Sequence.FromArray(dast.ToArray()), + (Sequence>)Sequence>.FromArray( + ImportFiles(dafnyProgramName).Select(fileName => + Sequence.UnicodeFromString(Path.GetFileName(fileName))).ToArray() + )); output.Write(o.ToVerbatimString(false)); } diff --git a/Source/DafnyCore/Backends/DafnyWrittenCodeGenerator.cs b/Source/DafnyCore/Backends/DafnyWrittenCodeGenerator.cs index 63c88d5d870..e2a67e13d7a 100644 --- a/Source/DafnyCore/Backends/DafnyWrittenCodeGenerator.cs +++ b/Source/DafnyCore/Backends/DafnyWrittenCodeGenerator.cs @@ -5,7 +5,7 @@ namespace Microsoft.Dafny.Compilers { public abstract class DafnyWrittenCodeGenerator { - public abstract ISequence Compile(Sequence program); + public abstract ISequence Compile(Sequence program, Sequence> otherFiles); public abstract ISequence EmitCallToMain(string fullName); diff --git a/Source/DafnyCore/Backends/ResolvedDesugaredExecutableDafny/ResolvedDesugaredExecutableDafnyCodeGenerator.cs b/Source/DafnyCore/Backends/ResolvedDesugaredExecutableDafny/ResolvedDesugaredExecutableDafnyCodeGenerator.cs index b27bd71b57b..6691d140b93 100644 --- a/Source/DafnyCore/Backends/ResolvedDesugaredExecutableDafny/ResolvedDesugaredExecutableDafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/ResolvedDesugaredExecutableDafny/ResolvedDesugaredExecutableDafnyCodeGenerator.cs @@ -8,7 +8,7 @@ namespace Microsoft.Dafny.Compilers; class ResolvedDesugaredExecutableDafnyCodeGenerator : DafnyWrittenCodeGenerator { - public override ISequence Compile(Sequence program) { + public override ISequence Compile(Sequence program, Sequence> otherFiles) { return COMP.Compile(program); } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy index 9e5877cf380..10177703d1e 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy @@ -6,6 +6,14 @@ module DafnyToRustCompilerCoverage { import opened Std.Wrappers import opened DAST.Format import Strings = Std.Strings + import FactorPathsOptimizationTest + + method TestExpr() { + TestOptimizeToString(); + TestPrintingInfo(); + TestNoExtraSemicolonAfter(); + FactorPathsOptimizationTest.TestApply(); + } method TestNoOptimize(e: Expr) //requires e.Optimize() == e // Too expensive @@ -14,16 +22,17 @@ module DafnyToRustCompilerCoverage { function ConversionNum(t: Type, x: Expr): Expr { Call( - MemberSelect( - MemberSelect( - Identifier(""), - "dafny_runtime"), - "truncate!"), + ExprFromPath( + PMemberSelect( + PMemberSelect( + Global(), + "dafny_runtime"), + "truncate!")), [x, ExprFromType(t)]) } function DafnyIntLiteral(s: string): Expr { - Call(MemberSelect(dafny_runtime, "int!"), [LiteralInt("1")]) + Call(ExprFromPath(PMemberSelect(dafny_runtime, "int!")), [LiteralInt("1")]) } method TestOptimizeToString() { @@ -90,7 +99,8 @@ module DafnyToRustCompilerCoverage { Call(Identifier("x"), [Identifier("x"), Identifier("y")]), CallType(Identifier("x"), [I128, U32]), Select(Identifier("x"), "abc"), - MemberSelect(Identifier("x"), "abc") + ExprFromPath(PMemberSelect(Crate(), "abc")), + ExprFromPath(PMemberSelect(Global(), "abc")) ]; for i := 0 to |coverageExpression| { var c := coverageExpression[i]; @@ -103,9 +113,6 @@ module DafnyToRustCompilerCoverage { var _ := UnaryOp("!", c, UnaryOpFormat.NoFormat()).Optimize(); var _ := ConversionNum(U8, c).Optimize(); var _ := ConversionNum(U8, Call(c, [])).Optimize(); - var _ := ConversionNum(U8, Call(MemberSelect(c, "int!"), [])).Optimize(); - var _ := ConversionNum(U8, Call(MemberSelect(MemberSelect(c, "dafny_runtime"), "int!"), [])).Optimize(); - var _ := ConversionNum(U8, Call(MemberSelect(MemberSelect(Identifier(""), "dafny_runtime"), "int!"), [c])).Optimize(); var _ := c.RightMostIdentifier(); } @@ -127,7 +134,7 @@ module DafnyToRustCompilerCoverage { 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(MemberSelect(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)); @@ -165,12 +172,6 @@ module DafnyToRustCompilerCoverage { AssertCoverage(Break(None).printingInfo == UnknownPrecedence()); } - method TestExpr() { - TestOptimizeToString(); - TestPrintingInfo(); - TestNoExtraSemicolonAfter(); - } - method AssertCoverage(x: bool) //requires x // Too expensive { diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy new file mode 100644 index 00000000000..e7dbab864f5 --- /dev/null +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy @@ -0,0 +1,275 @@ +module FactorPathsOptimizationTest { + export provides TestApply + import opened RAST + import opened FactorPathsOptimization + + method ShouldBeEqual(a: Mod, b: Mod) { + var sA := a.ToString(""); + var sB := b.ToString(""); + if sA != sB { + print "Got:\n" + sA + "\n"; + print "Expected:\n" + sB + "\n"; + expect sA == sB; + } + } + + method TestApply() { + var T_Decl := TypeParamDecl("T", [DafnyType]); + var T_Decl_simp := TypeParamDecl("T", [TIdentifier("DafnyType")]); + var T := TIdentifier("T"); + var std_any_Any := global.MSel("std").MSel("any").MSel("Any"); + var Any := TIdentifier("Any"); + ShouldBeEqual(apply( + Mod("onemodule", [ + StructDecl( + Struct([], "test", [T_Decl], + NamedFields([Field(PUB, Formal("a", std_any_Any.AsType()))]))), + // ::std::any::Any ==> Any + ImplDecl(Impl([T_Decl], TIdentifier("test").Apply([T]), "", [])), + ImplDecl( + ImplFor( + [T_Decl], std_any_Any.AsType(), crate.MSel("onemodule").MSel("test").AsType().Apply([T]), "", [])) + // ::std::any::Any ==> Any crate::onemodule::test ==> test + ])), + Mod("onemodule", [ + UseDecl(Use(PUB, dafny_runtime.MSel("DafnyType"))), + UseDecl(Use(PUB, std_any_Any)), + StructDecl( + Struct([], "test", [T_Decl_simp], + NamedFields([Field(PUB, Formal("a", Any))]))), + ImplDecl(Impl([T_Decl_simp], TIdentifier("test").Apply([T]), "", [])), + ImplDecl(ImplFor([T_Decl_simp], Any, TIdentifier("test").Apply([T]), "", [])) + ])); + ShouldBeEqual(apply( + Mod("onemodule", [ + ImplDecl( + ImplFor( + [T_Decl], dafny_runtime.MSel("UpcastObject").AsType().Apply([TIdentifier("x")]), + TIdentifier("test").Apply([T]), "", [])) + ])), + Mod("onemodule", [ + UseDecl(Use(PUB, dafny_runtime.MSel("DafnyType"))), + UseDecl(Use(PUB, dafny_runtime.MSel("UpcastObject"))), + ImplDecl( + ImplFor( + [T_Decl_simp], TIdentifier("UpcastObject").Apply([TIdentifier("x")]), + TIdentifier("test").Apply([T]), "", [])) + ])); + } +} + +module FactorPathsOptimization { + export provides apply, RAST + import Std + import opened RAST + export Std + + /*function Debug(s: T, msg: string): T { + s + } by method { + print msg, ":", s, "\n"; + return s; + }*/ + + function apply(mod: Mod): Mod { + applyPrefix(mod, crate.MSel(mod.name)) + } + + function applyPrefix(mod: Mod, SelfPath: Path): Mod { + if mod.ExternMod? then mod else + var initialMapping: Mapping := Mapping(map[], []); + var mappings: Mapping := + mod.Fold(initialMapping, (current, modDecl) => GatherModMapping(SelfPath, modDecl, current)); + //var _ := Debug(mappings, "Mappings"); + var pathsToRemove := mappings.ToFinalReplacement(); + var imports := mappings.ToUseStatements(pathsToRemove, SelfPath); + var rewrittenDeclarations := + mod.Fold([], (current, modDecl) requires modDecl < mod => + current + [ReplaceModDecl(modDecl, SelfPath, pathsToRemove)] + ); + mod.(body := imports + rewrittenDeclarations) + } + + opaque function UniqueElementOf(s: set): (r: T) + requires |s| == 1 + ensures r in s + { + assert forall e: T, e': T | e in s && e' in s :: e == e' by { + forall e: T, e': T | e in s && e' in s ensures e == e' { + if e != e' { + assert e' in (s - {e}); + assert |s - {e}| == 0; + } + } + } + var e :| e in s; + e + } + + datatype Mapping = Mapping( + provenance: map>, + keys: seq + ) { + function Add(k: string, path: Path): Mapping { + if k in provenance then + this.(provenance := provenance[k := provenance[k] + {path}]) + else + this.(provenance := provenance[k := {path}], keys := keys + [k]) + } + + function ToFinalReplacement(): FinalReplacement { + map identifier <- provenance, paths + | paths == provenance[identifier] && + (|| |paths| == 1 + || exists p <- paths :: p == dafny_runtime) + :: + identifier := if |paths| == 1 then UniqueElementOf(paths) else dafny_runtime + } + function ToUseStatements(finalReplacement: FinalReplacement, SelfPath: Path): seq + requires finalReplacement == ToFinalReplacement() + { + var toUse := Std.Collections.Seq.Filter( + (key: string) => key in finalReplacement && finalReplacement[key] != SelfPath, keys); + seq(|toUse|, i requires 0 <= i < |toUse| => + UseDecl(Use(PUB, finalReplacement[toUse[i]].MSel(toUse[i])))) + } + } + + type FinalReplacement = map + + function GatherTypeParams(typeParams: seq, current: Mapping): Mapping { + FoldLeft( (current: Mapping, t: TypeParamDecl) => + FoldLeft( (current: Mapping, t: Type) => + GatherTypeMapping(t, current), + current, t.constraints), + current, typeParams) + } + + function GatherFields(fields: Fields, current: Mapping): Mapping { + match fields { + case NamedFields(sFields) => + FoldLeft( (current: Mapping, f: Field) => + GatherTypeMapping(f.formal.tpe, current), + current, sFields) + case NamelessFields(sFields) => + FoldLeft( (current: Mapping, f: NamelessField) => + GatherTypeMapping(f.tpe, current), + current, sFields) + } + } + + function GatherModMapping(prefix: Path, modDecl: ModDecl, current: Mapping): Mapping { + match modDecl { + case ModDecl(mod) => + current.Add(mod.name, prefix) // Modules must be handled independently + case StructDecl(struct) => + GatherStructMapping(struct, current.Add(struct.name, prefix)) + case TypeDecl(tpe) => + current.Add(tpe.name, prefix) + case ConstDecl(c) => + current.Add(c.name, prefix) + case EnumDecl(enum) => + current.Add(enum.name, prefix) + case ImplDecl(impl) => + GatherImplMapping(impl, current) + case TraitDecl(tr) => + current + case TopFnDecl(fn) => + current.Add(fn.fn.name, prefix) + case UseDecl(use) => // Used for externs with *, we can't extract any name + current + } + } + + function GatherStructMapping(struct: Struct, current: Mapping): Mapping { + GatherTypeParams(struct.typeParams, current) + } + + function GatherTypeMapping(tpe: Type, current: Mapping): Mapping { + tpe.Fold(current, (current: Mapping, t: Type) => + match t { + case TypeFromPath(PMemberSelect(base, name)) => current.Add(name, base) + case _ => current + } + ) + } + + function GatherImplMapping(impl: Impl, current: Mapping): Mapping { + match impl { + case ImplFor(typeParams, tpe, forType, where, body) => + var current := GatherTypeParams(typeParams, current); + var current := GatherTypeMapping(tpe, current); + GatherTypeMapping(forType, current) + // TODO: Add body + case Impl(typeParams, tpe, where, body) => + GatherTypeMapping(tpe, current) + } + } + + function ReplaceModDecl(modDecl: ModDecl, SelfPath: Path, replacement: FinalReplacement): ModDecl { + match modDecl { + case ModDecl(mod) => + ModDecl(applyPrefix(mod, SelfPath.MSel(mod.name))) // We optimize independently submodules + case StructDecl(struct) => StructDecl(ReplaceStruct(struct, replacement)) + case TypeDecl(tpe) => modDecl // TODO + case ConstDecl(c) => modDecl // TODO + case EnumDecl(enum) => modDecl // TODO + case ImplDecl(impl) => ImplDecl(ReplaceImplDecl(impl, replacement)) + case TraitDecl(tr) => modDecl // TODO + case TopFnDecl(fn) => modDecl // TODO + case UseDecl(use) => modDecl + } + } + + function ReplaceType(t: Type, replacement: FinalReplacement): Type { + match t { + case TypeFromPath(PMemberSelect(base, id)) => + if id in replacement && replacement[id] == base then + TSynonym(TIdentifier(id), t) + else + t + case _ => t + } + } + + const typeReplacer: FinalReplacement -> Type -> Type := + (replacement: FinalReplacement) => (t: Type) => ReplaceType(t, replacement) + + function ReplaceTypeParams(typeParams: seq, replacement: FinalReplacement): seq { + Std.Collections.Seq.Map((t: TypeParamDecl) => + t.(constraints := Std.Collections.Seq.Map((constraint: Type) => + ReplaceType(constraint, replacement), t.constraints)), + typeParams) + } + + function ReplaceImplDecl(impl: Impl, replacement: FinalReplacement): Impl { + match impl { + case ImplFor(typeParams, tpe, forType, where, body) => + ImplFor(ReplaceTypeParams(typeParams, replacement), tpe.Replace(typeReplacer(replacement)), forType.Replace(typeReplacer(replacement)), where, body) + // TODO: Replace body + case Impl(typeParams, tpe, where, body) => + Impl(ReplaceTypeParams(typeParams, replacement), tpe.Replace(typeReplacer(replacement)), where, body) + } + } + + function ReplaceStruct(struct: Struct, replacement: FinalReplacement): Struct { + match struct { + case Struct(attributes, name, typeParams, fields) => + Struct(attributes, name, + ReplaceTypeParams(typeParams, replacement), + ReplaceFields(fields, replacement) + ) + } + } + function ReplaceFields(fields: Fields, replacement: FinalReplacement): Fields { + match fields { + case NamedFields(sFields) => + NamedFields(Std.Collections.Seq.Map((f: Field) => + f.(formal := f.formal.(tpe := ReplaceType(f.formal.tpe, replacement))), sFields + )) + case NamelessFields(sFields) => + NamelessFields(Std.Collections.Seq.Map((f: NamelessField) => + f.(tpe := ReplaceType(f.tpe, replacement)), sFields)) + } + } +} diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-utils.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-utils.dfy new file mode 100644 index 00000000000..32671420dd9 --- /dev/null +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-utils.dfy @@ -0,0 +1,101 @@ +module DafnyCompilerRustUtils { + import Std + import opened Std.Wrappers + import opened DAST + import R = RAST + + // Split a Dafny name along dots + function DafnyNameToContainingPathAndName(n: Name, acc: seq := []): (seq, Name) + decreases |n.dafny_name| + { + var s := n.dafny_name; + if |s| == 0 then + if |acc| == 0 then ([], Name("")) else (acc[0..|acc|-1], acc[|acc|-1].id) + else + if s[0] != '.' then + if |acc| == 0 then DafnyNameToContainingPathAndName(Name(s[1..]), [Ident.Ident(Name(s[0..1]))]) else + DafnyNameToContainingPathAndName(Name(s[1..]), acc[0..|acc|-1] + [Ident.Ident(Name(acc[|acc|-1].id.dafny_name + [s[0]]))]) + else + if |acc| == 0 then DafnyNameToContainingPathAndName(Name(s[1..]), []) else + DafnyNameToContainingPathAndName(Name(s[1..]), acc + [Ident.Ident(Name(""))]) + } + + type ModWithBody = x: R.Mod | x.Mod? witness * + type ExternMod = x: R.Mod | x.ExternMod? witness * + + datatype SeqMap = SeqMap(keys: seq, values: map) + { + static function Empty(): SeqMap { + SeqMap([], map[]) + } + static function Single(key: K, value: V): SeqMap { + SeqMap([key], map[key := value]) + } + } + + datatype GatheringModule = + GatheringModule( + existingMod: ModWithBody, + submodules: SeqMap + ) | + ExternMod(m: ExternMod) + { + + static function MergeSeqMap(m1: SeqMap, m2: SeqMap): SeqMap + decreases m1 + { + SeqMap( + m1.keys + Std.Collections.Seq.Filter((k: string) => k !in m1.keys, m2.keys), + map k <- m1.values.Keys + m2.values.Keys :: + if k in m1.values then + if k in m2.values then m1.values[k].Merge(m2.values[k]) else + m1.values[k] + else + m2.values[k]) + } + + + static function MergeSeqMapAll(m1: SeqMap, m2s: seq>): SeqMap + decreases |m2s| + { + if |m2s| == 0 then m1 else + MergeSeqMapAll(MergeSeqMap(m1, m2s[0]), m2s[1..]) + } + + function Merge(m2: GatheringModule): GatheringModule + decreases this + { + if !GatheringModule? then m2 else if !m2.GatheringModule? then this else + GatheringModule( + R.Mod(existingMod.name, existingMod.body + m2.existingMod.body), + MergeSeqMap(submodules, m2.submodules) + ) + } + + static function Wrap(containingPath: seq, rawDecl: R.Mod): SeqMap { + if |containingPath| == 0 then + var name := rawDecl.name; + if rawDecl.Mod? then + SeqMap.Single(name, GatheringModule(rawDecl, SeqMap.Empty())) + else + SeqMap.Single(name, ExternMod(rawDecl)) + else + var enclosingModule := containingPath[0]; + SeqMap.Single(enclosingModule, + GatheringModule(R.Mod(enclosingModule, []), Wrap(containingPath[1..], rawDecl))) + } + function ToRust(): R.Mod { + if ExternMod? then m else + var keysWithContent := Std.Collections.Seq.Filter(key => key in submodules.values, submodules.keys); + existingMod.(body := + existingMod.body + + seq(|keysWithContent|, i requires 0 <= i < |keysWithContent| => + var moduleName := keysWithContent[i]; + var submodule := submodules.values[moduleName].ToRust(); + R.ModDecl(submodule) + ) + ) + } + } + +} \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index c9c13cbd022..90f7a8dca0a 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -19,11 +19,24 @@ module RAST // Default Indentation const IND := " " + opaque function FoldLeft(f: (A, T) --> A, init: A, xs: seq): A + requires forall t: T <- xs, a: A :: f.requires(a, t) + { + if |xs| == 0 then init + else FoldLeft(f, f(init, xs[0]), xs[1..]) + } + datatype Mod = // Rust modules | Mod(name: string, body: seq) | ExternMod(name: string) { + function Fold(acc: T, accBuilder: (T, ModDecl) --> T): T + requires Mod? ==> forall modDecl: ModDecl <- body, t: T :: accBuilder.requires(t, modDecl) + { + if ExternMod? then acc else + FoldLeft(accBuilder, acc, body) + } function ToString(ind: string): string decreases this { @@ -31,11 +44,19 @@ module RAST case ExternMod(name) => "pub mod " + name + ";" case Mod(name, body) => - "pub mod " + name + " {" + "\n" + ind + IND + + /* If the module does not start with "use", just separate declarations by one blank line + If the module starts with "use", add blank lines only after use declarations */ + var startWithUse := |body| > 0 && body[0].UseDecl?; + var prefixIfNotUseDecl := if startWithUse then "\n" + ind + IND else ""; + var prefixIfUseDecl := if startWithUse then ind + IND else ""; + var infixDecl := if startWithUse then "\n" else "\n\n" + ind + IND; + var initialIdent := if startWithUse then "" else ind + IND; + "pub mod " + name + " {" + "\n" + initialIdent + SeqToString( body, (modDecl: ModDecl) requires modDecl < this => - modDecl.ToString(ind + IND), "\n\n" + ind + IND) + (if modDecl.UseDecl? then prefixIfUseDecl else prefixIfNotUseDecl) + + modDecl.ToString(ind + IND), infixDecl) + "\n" + ind + "}" } } @@ -47,7 +68,6 @@ module RAST f(s[0]) + (if |s| > 1 then separator + SeqToString(s[1..], f, separator) else "") } datatype ModDecl = - | RawDecl(body: string) | ModDecl(mod: Mod) | StructDecl(struct: Struct) | TypeDecl(tpe: TypeSynonym) @@ -56,6 +76,7 @@ module RAST | ImplDecl(impl: Impl) | TraitDecl(tr: Trait) | TopFnDecl(fn: TopFnDecl) + | UseDecl(use: Use) { function ToString(ind: string): string decreases this @@ -68,7 +89,12 @@ module RAST else if ConstDecl? then c.ToString(ind) else if TraitDecl? then tr.ToString(ind) else if TopFnDecl? then fn.ToString(ind) - else assert RawDecl?; body + else assert UseDecl?; use.ToString(ind) + } + } + datatype Use = Use(visibility: Visibility, path: Path) { + function ToString(ind: string): string { + visibility.ToString() + "use " + path.ToString() + ";" } } datatype TopFnDecl = TopFn(attributes: seq, visibility: Visibility, fn: Fn) { @@ -199,7 +225,7 @@ module RAST type TypeParamConstraint = Type datatype TypeParamDecl = - | TypeParamDecl(content: string, constraints: seq) + | TypeParamDecl(name: string, constraints: seq) { static function ToStringMultiple(typeParams: seq, ind: string): string { if |typeParams| == 0 then "" else @@ -216,7 +242,7 @@ module RAST this.(constraints := this.constraints + constraints) } function ToString(ind: string): string { - content + ( + name + ( if |constraints| == 0 then "" else @@ -228,24 +254,34 @@ module RAST const SelfBorrowedMut := BorrowedMut(SelfOwned) - const SelfPointer := Pointer(SelfOwned) + const RcPath := std.MSel("rc").MSel("Rc") - const SelfPointerMut := PointerMut(SelfOwned) + const RcType := RcPath.AsType() - const RcType := std_type.MSel("rc").MSel("Rc") + const ObjectPath: Path := dafny_runtime.MSel("Object") + + const Object := ObjectPath.AsExpr() function ObjectType(underlying: Type): Type { - dafny_runtime_type.MSel("Object").Apply([underlying]) + ObjectPath.AsType().Apply([underlying]) + } + + const PtrPath: Path := dafny_runtime.MSel("Ptr") + + const Ptr := PtrPath.AsExpr() + + function PtrType(underlying: Type): Type { + PtrPath.AsType().Apply([underlying]) } function Rc(underlying: Type): Type { TypeApp(RcType, [underlying]) } function RefCell(underlying: Type): Type { - TypeApp(std_type.MSel("cell").MSel("RefCell"), [underlying]) + TypeApp(RefcellType, [underlying]) } function Vec(underlying: Type): Type { - TypeApp(std_type.MSel("vec").MSel("Vec"), [underlying]) + TypeApp(std.MSel("vec").MSel("Vec").AsType(), [underlying]) } function NewVec(elements: seq): Expr { Identifier("vec!").Apply(elements) @@ -265,77 +301,160 @@ module RAST TypeApp(TIdentifier("Box"), [content]) } function BoxNew(content: Expr): Expr { - Identifier("Box").MSel("new").Apply([content]) + Identifier("Box").FSel("new").Apply([content]) + } + + datatype Path = + | Global() // ::... to access other crates + | Crate() // crate::... to access modules and imported modules in the same crate + | Self() // Self::... + | PMemberSelect(base: Path, name: string) + { + function MSel(name: string): Path { + PMemberSelect(this, name) + } + function FSel(name: string): Expr { + AsExpr().FSel(name) + } + function AsType(): Type { + TypeFromPath(this) + } + function AsExpr(): Expr { + ExprFromPath(this) + } + function ToString(): string { + match this { + case Global() => "" + case Crate() => "crate" + case Self() => "Self" + case PMemberSelect(base, name) => base.ToString() + "::" + name + } + } + function RightMostIdentifier(): Option { + match this { + case Global() => None + case Crate() => Some("crate") + case Self() => Some("Self") + case PMemberSelect(base, name) => Some(name) + } + } } + const SelfOwned := Self().AsType() + datatype Type = - | SelfOwned | U8 | U16 | U32 | U64 | U128 | I8 | I16 | I32 | I64 | I128 | Bool | TIdentifier(name: string) - | TMemberSelect(base: Type, name: string) + | TypeFromPath(path: Path) | TypeApp(baseName: Type, arguments: seq) | Borrowed(underlying: Type) | BorrowedMut(underlying: Type) - | Pointer(underlying: Type) - | PointerMut(underlying: Type) | ImplType(underlying: Type) | DynType(underlying: Type) | TupleType(arguments: seq) | FnType(arguments: seq, returnType: Type) | IntersectionType(left: Type, right: Type) | Array(underlying: Type, size: Option) + | TSynonym(display: Type, base: Type) { - function Replace(mapping: map): Type { - if this in mapping then mapping[this] else + function Expand(): (r: Type) + ensures !r.TSynonym? && (!TSynonym? ==> r == this) + { + if TSynonym? then base.Expand() else this + } + predicate EndsWithNameThatCanAcceptGenerics() { + || U8? || U16? || U32? || U64? || U128? || I8? || I16? || I32? || I64? || I128? + || TIdentifier? || TypeFromPath? + || (Borrowed? && underlying.EndsWithNameThatCanAcceptGenerics()) + || (BorrowedMut? && underlying.EndsWithNameThatCanAcceptGenerics()) + || (ImplType? && underlying.EndsWithNameThatCanAcceptGenerics()) + || (DynType? && underlying.EndsWithNameThatCanAcceptGenerics()) + || (IntersectionType? && right.EndsWithNameThatCanAcceptGenerics()) + || (TSynonym? && display.EndsWithNameThatCanAcceptGenerics()) + } + function ReplaceMap(mapping: map): Type { + Replace((t: Type) => if t in mapping then mapping[t] else t) + } + function Replace(mapping: Type -> Type): Type { + var r := + match this { + case U8 | U16 | U32 | U64 | U128 | I8 | I16 | I32 | I64 | I128 | Bool => this + case TIdentifier(_) => this + case TypeFromPath(path) => this + case TypeApp(baseName, arguments) => + this.(baseName := baseName.Replace(mapping), + arguments := Std.Collections.Seq.Map( + t requires t in arguments => t.Replace(mapping), arguments)) + case Borrowed(underlying) => this.(underlying := underlying.Replace(mapping)) + case BorrowedMut(underlying) => this.(underlying := underlying.Replace(mapping)) + case ImplType(underlying) => this.(underlying := underlying.Replace(mapping)) + case DynType(underlying) => this.(underlying := underlying.Replace(mapping)) + case TupleType(arguments) => + this.( + arguments := Std.Collections.Seq.Map( + t requires t in arguments => t.Replace(mapping), arguments)) + case FnType(arguments, returnType) => + this.(arguments := Std.Collections.Seq.Map( + t requires t in arguments => t.Replace(mapping), arguments), + returnType := returnType.Replace(mapping)) + case IntersectionType(left, right) => + this.(left := left.Replace(mapping), right := right.Replace(mapping)) + case Array(underlying, size) => + this.(underlying := underlying.Replace(mapping)) + case TSynonym(display, base) => + this.(display := display.Replace(mapping), base := base.Replace(mapping)) + }; + mapping(r) + } + + function Fold(acc: T, f: (T, Type) -> T): T + // Traverses all types in a random order + { + var newAcc := f(acc, this); match this { - case SelfOwned => this - case U8 | U16 | U32 | U64 | U128 | I8 | I16 | I32 | I64 | I128 | Bool => this - case TIdentifier(_) => this - case TMemberSelect(base, name) => - this.(base := base.Replace(mapping)) + case U8 | U16 | U32 | U64 | U128 | I8 | I16 | I32 | I64 | I128 | Bool => newAcc + case TIdentifier(_) => newAcc + case TypeFromPath(path) => newAcc case TypeApp(baseName, arguments) => - this.(baseName := baseName.Replace(mapping), - arguments := Std.Collections.Seq.Map( - t requires t in arguments => t.Replace(mapping), arguments)) - case Borrowed(underlying) => this.(underlying := underlying.Replace(mapping)) - case BorrowedMut(underlying) => this.(underlying := underlying.Replace(mapping)) - case Pointer(underlying) => this.(underlying := underlying.Replace(mapping)) - case PointerMut(underlying) => this.(underlying := underlying.Replace(mapping)) - case ImplType(underlying) => this.(underlying := underlying.Replace(mapping)) - case DynType(underlying) => this.(underlying := underlying.Replace(mapping)) + Std.Collections.Seq.FoldLeft( + (acc: T, argType: Type) => assume {:axiom} argType in arguments; argType.Fold(acc, f), + baseName.Fold(newAcc, f), + arguments) + case Borrowed(underlying) => underlying.Fold(newAcc, f) + case BorrowedMut(underlying) => underlying.Fold(newAcc, f) + case ImplType(underlying) => underlying.Fold(newAcc, f) + case DynType(underlying) => underlying.Fold(newAcc, f) case TupleType(arguments) => - this.( - arguments := Std.Collections.Seq.Map( - t requires t in arguments => t.Replace(mapping), arguments)) + Std.Collections.Seq.FoldLeft( + (acc: T, argType: Type) => assume {:axiom} argType in arguments; argType.Fold(acc, f), + newAcc, arguments) case FnType(arguments, returnType) => - this.(arguments := Std.Collections.Seq.Map( - t requires t in arguments => t.Replace(mapping), arguments), - returnType := returnType.Replace(mapping)) + returnType.Fold( + Std.Collections.Seq.FoldLeft( + (acc: T, argType: Type) => assume {:axiom} argType in arguments; argType.Fold(acc, f), + newAcc, arguments), + f) case IntersectionType(left, right) => - this.(left := left.Replace(mapping), right := right.Replace(mapping)) - case Array(underlying, size) => - this.(underlying := underlying.Replace(mapping)) + right.Fold(left.Fold(newAcc, f), f) + case Array(underlying, size) => underlying.Fold(newAcc, f) + case TSynonym(display, base) => display.Fold(newAcc, f) } } + predicate CanReadWithoutClone() { U8? || U16? || U32? || U64? || U128? || I8? || I16? || I32? || I64? || I128? || Bool? - || Pointer? || PointerMut? - } - predicate IsSelfPointer() { - || (Borrowed? && underlying.PointerMut? && underlying.underlying.SelfOwned?) - || (PointerMut? && underlying.SelfOwned?) - || (PointerMut? && underlying.TypeApp? && |underlying.arguments| == 0 && underlying.baseName.SelfOwned?) + || (TSynonym? && base.CanReadWithoutClone()) || IsPointer() } predicate IsRcOrBorrowedRc() { (TypeApp? && baseName == RcType) || - (Borrowed? && underlying.IsRcOrBorrowedRc()) + (Borrowed? && underlying.IsRcOrBorrowedRc()) || + (TSynonym? && base.IsRcOrBorrowedRc()) } function ExtractMaybePlacebo(): Option { match this { case TypeApp(wrapper, arguments) => - if (wrapper == TIdentifier("MaybePlacebo") - || wrapper == dafny_runtime_type.MSel("MaybePlacebo")) + if wrapper == TypeFromPath(MaybePlaceboPath) && |arguments| == 1 then Some(arguments[0]) @@ -360,11 +479,9 @@ module RAST match this { case Bool() => "bool" case TIdentifier(underlying) => underlying - case TMemberSelect(underlying, name) => underlying.ToString(ind) + "::" + name + case TypeFromPath(underlying) => underlying.ToString() case Borrowed(underlying) => "&" + underlying.ToString(ind) case BorrowedMut(underlying) => "&mut " + underlying.ToString(ind) - case Pointer(underlying) => "*const " + underlying.ToString(ind) - case PointerMut(underlying) => "*mut " + underlying.ToString(ind) case ImplType(underlying) => "impl " + underlying.ToString(ind) case DynType(underlying) => "dyn " + underlying.ToString(ind) case FnType(arguments, returnType) => @@ -390,7 +507,6 @@ module RAST SeqToString(args, (arg: Type) requires arg < this => arg.ToString(ind + IND), ", ") + ">") - case SelfOwned() => "Self" case U8() => "u8" case U16() => "u16" case U32() => "u32" @@ -402,13 +518,10 @@ module RAST case I64() => "i64" case I128() => "i128" case Array(underlying, size) => "[" + underlying.ToString(ind) + (if size.Some? then "; " + size.value else "") + "]" + case TSynonym(display, base) => display.ToString(ind) } } - function MSel(name: string): Type { - TMemberSelect(this, name) - } - function Apply1(arg: Type): Type { TypeApp(this, [arg]) } @@ -428,36 +541,34 @@ module RAST function ToNullExpr(): Expr requires IsObjectOrPointer() { - if IsObject() then dafny_runtime.MSel("Object").Apply1(std.MSel("option").MSel("Option").MSel("None")) else - var underlying := underlying; - var n := if PointerMut? then "null_mut" else "null"; - if underlying.Array? && underlying.size.None? then // dynamic arrays - // Fat null pointer have a special syntax - std.MSel("ptr").MSel(n).ApplyType([Array(underlying.underlying, Some("0"))]).Apply([]) + assert Expand().IsObject() || Expand().IsPointer(); + if Expand().IsObject() then + Object.FSel("null").Apply([]) else - std.MSel("ptr").MSel(n).Apply([]) + Ptr.FSel("null").Apply([]) } predicate IsMultiArray() { - this.TypeApp? && - var baseName := this.baseName; - var args := this.arguments; + var t := Expand(); + t.TypeApp? && + var baseName := t.baseName; + var args := t.arguments; |args| == 1 && - baseName.TMemberSelect? && - baseName.base == dafny_runtime_type && - |baseName.name| >= 5 && baseName.name[0..5] == "Array" + baseName.TypeFromPath? && baseName.path.PMemberSelect? && + baseName.path.base == dafny_runtime && + |baseName.path.name| >= 5 && baseName.path.name[0..5] == "Array" } function MultiArrayClass(): string requires IsMultiArray() { - this.baseName.name + this.Expand().baseName.path.name } function MultiArrayUnderlying(): Type requires IsMultiArray() { - arguments[0] + this.Expand().arguments[0] } // Given an array type like *mut [T], produces the type *mut[MaybeUninit] @@ -467,10 +578,10 @@ module RAST var s := this.ObjectOrPointerUnderlying(); if s.Array? && s.size.None? then var newUnderlying := Array(MaybeUninitType(s.underlying), None); - if this.IsObject() then ObjectType(newUnderlying) else PointerMut(newUnderlying) + if this.IsObject() then ObjectType(newUnderlying) else PtrType(newUnderlying) else if s.IsMultiArray() then - var newUnderlying := TypeApp(s.baseName, [MaybeUninitType(s.arguments[0])]); - if this.IsObject() then ObjectType(newUnderlying) else PointerMut(newUnderlying) + var newUnderlying := TypeApp(s.Expand().baseName, [MaybeUninitType(s.Expand().arguments[0])]); + if this.IsObject() then ObjectType(newUnderlying) else PtrType(newUnderlying) else this else @@ -478,12 +589,13 @@ module RAST } predicate IsMaybeUninit() { - this.TypeApp? && this.baseName == MaybeUninitPath && |this.arguments| == 1 + TypeApp? && baseName.TypeFromPath? + && baseName.path == MaybeUninitPath && |this.arguments| == 1 } predicate IsUninitArray() { - if this.IsObjectOrPointer() then - var s := this.ObjectOrPointerUnderlying(); + if IsObjectOrPointer() then + var s := ObjectOrPointerUnderlying().Expand(); if s.Array? && s.size.None? then s.underlying.IsMaybeUninit() else if s.IsMultiArray() then @@ -495,30 +607,38 @@ module RAST } predicate IsObject() { match this { - case TypeApp(TMemberSelect(TMemberSelect(TIdentifier(""), "dafny_runtime"), "Object"), elems1) => + case TypeApp(TypeFromPath(o), elems1) => + o == ObjectPath && |elems1| == 1 case _ => false } } predicate IsPointer() { - this.Pointer? || this.PointerMut? + match this { + case TypeApp(TypeFromPath(o), elems1) => + o == PtrPath && + |elems1| == 1 + case _ => false + } } predicate IsObjectOrPointer() { - IsPointer() || IsObject() + this.Expand().IsPointer() || this.Expand().IsObject() + } by method { + var t := this.Expand(); + return t.IsPointer() || t.IsObject(); } function ObjectOrPointerUnderlying(): Type requires IsObjectOrPointer() { - if this.PointerMut? || this.Pointer? then this.underlying else - match this { - case TypeApp(TMemberSelect(TMemberSelect(TIdentifier(""), "dafny_runtime"), _), elems1) => + match Expand() { + case TypeApp(_, elems1) => elems1[0] } } predicate IsBuiltinCollection() { - match this { - case TypeApp(TMemberSelect(TMemberSelect(TIdentifier(""), "dafny_runtime"), tpe), elems1) => + match this.Expand() { + case TypeApp(TypeFromPath(PMemberSelect(PMemberSelect(Global(), "dafny_runtime"), tpe)), elems1) => || ((tpe == "Set" || tpe == "Sequence" || tpe == "Multiset") && |elems1| == 1) || (tpe == "Map" && |elems1| == 2) case _ => false @@ -528,8 +648,8 @@ module RAST function GetBuiltinCollectionElement(): Type requires IsBuiltinCollection() { - match this { - case TypeApp(TMemberSelect(TMemberSelect(TIdentifier(""), "dafny_runtime"), tpe), elems) => + match this.Expand() { + case TypeApp(TypeFromPath(PMemberSelect(PMemberSelect(Global(), "dafny_runtime"), tpe)), elems) => if tpe == "Map" then elems[1] else elems[0] } } @@ -545,43 +665,44 @@ module RAST } function SystemTupleType(elements: seq): Type { - super_type.MSel("_System").MSel("Tuple" + Strings.OfNat(|elements|)).Apply(elements) + dafny_runtime.MSel("_System").MSel("Tuple" + Strings.OfNat(|elements|)).AsType().Apply(elements) } - const global_type := TIdentifier("") - const std_type: Type := global_type.MSel("std") - const super_type := TIdentifier("super") - const cell_type := std_type.MSel("cell") - const refcell_type := cell_type.MSel("RefCell") - const dafny_runtime_type: Type := global_type.MSel("dafny_runtime") - const CloneTrait := RawType("Clone") - const DefaultTrait := std_type.MSel("default").MSel("Default") + const global := Global() + const std: Path := global.MSel("std") + const cell := std.MSel("cell") + const RefcellType := cell.MSel("RefCell").AsType() + const dafny_runtime: Path := global.MSel("dafny_runtime") + const CloneTrait := std.MSel("clone").MSel("Clone").AsType() + const DefaultPath := std.MSel("default").MSel("Default") + const DefaultTrait := DefaultPath.AsType() + const AnyTrait := std.MSel("any").MSel("Any").AsType() const StaticTrait := RawType("'static") - const DafnyType := dafny_runtime_type.MSel("DafnyType") - const DafnyPrint := dafny_runtime_type.MSel("DafnyPrint") - const DafnyTypeEq := dafny_runtime_type.MSel("DafnyTypeEq") - const Eq := TIdentifier("Eq") - const Hash := std_type.MSel("hash").MSel("Hash") - const DafnyInt := dafny_runtime_type.MSel("DafnyInt") - - const super := Identifier("super") + const DafnyType := dafny_runtime.MSel("DafnyType").AsType() + const DafnyPrint := dafny_runtime.MSel("DafnyPrint").AsType() + const DafnyTypeEq := dafny_runtime.MSel("DafnyTypeEq").AsType() + const Eq := std.MSel("cmp").MSel("Eq").AsType() + const Hash := std.MSel("hash").MSel("Hash").AsType() + const DafnyInt := dafny_runtime.MSel("DafnyInt").AsType() function SystemTuple(elements: seq): Expr { var size := Strings.OfNat(|elements|); - StructBuild(super.MSel("_System").MSel("Tuple" + size).MSel("_T" + size), + StructBuild(dafny_runtime.MSel("_System").MSel("Tuple" + size).MSel("_T" + size).AsExpr(), seq(|elements|, i requires 0 <= i < |elements| => AssignIdentifier("_" + Strings.OfNat(i), elements[i]) ) ) } - const MaybeUninitPath := std_type.MSel("mem").MSel("MaybeUninit") + const MaybeUninitPath := std.MSel("mem").MSel("MaybeUninit") + const MaybeUninitPathType := MaybeUninitPath.AsType() + const MaybeUninitExpr := MaybeUninitPath.AsExpr() function MaybeUninitType(underlying: Type): Type { - MaybeUninitPath.Apply([underlying]) + MaybeUninitPathType.Apply([underlying]) } predicate IsMaybeUninitType(tpe: Type) { - tpe.TypeApp? && tpe.baseName == MaybeUninitPath && |tpe.arguments| == 1 + tpe.TypeApp? && tpe.baseName == MaybeUninitPathType && |tpe.arguments| == 1 } function MaybeUninitTypeUnderlying(tpe: Type): Type requires IsMaybeUninitType(tpe) @@ -589,11 +710,13 @@ module RAST tpe.arguments[0] } function MaybeUninitNew(underlying: Expr): Expr { - std.MSel("mem").MSel("MaybeUninit").MSel("new").Apply([underlying]) + MaybeUninitPath.FSel("new").Apply([underlying]) } + const MaybePlaceboPath := dafny_runtime.MSel("MaybePlacebo") + function MaybePlaceboType(underlying: Type): Type { - dafny_runtime_type.MSel("MaybePlacebo").Apply1(underlying) + MaybePlaceboPath.AsType().Apply1(underlying) } @@ -787,7 +910,7 @@ module RAST datatype Expr = RawExpr(content: string) | ExprFromType(tpe: Type) - | Identifier(name: string) // Can be empty for global in MemberSelect + | Identifier(name: string) // Never empty | Match(matchee: Expr, cases: seq) | StmtExpr(stmt: Expr, rhs: Expr) | Block(underlying: Expr) @@ -812,7 +935,8 @@ module RAST | Call(obj: Expr, arguments: seq) // obj(...arguments) | Select(obj: Expr, name: string) // obj.name | SelectIndex(obj: Expr, range: Expr) // obj[range] - | MemberSelect(obj: Expr, name: string) // obj::name + | ExprFromPath(path: Path) // ::dafny_runtime::int! for example + | FunctionSelect(obj: Expr, name: string) // objType::name | Lambda(params: seq, retType: Option, body: Expr) // move || -> retType { body } { predicate NoExtraSemicolonAfter() { @@ -840,7 +964,8 @@ module RAST } case Select(underlying, name) => PrecedenceAssociativity(2, LeftToRight) case SelectIndex(underlying, range) => PrecedenceAssociativity(2, LeftToRight) - case MemberSelect(underlying, name) => PrecedenceAssociativity(2, LeftToRight) + case ExprFromPath(underlying) => Precedence(2) + case FunctionSelect(underlying, name) => PrecedenceAssociativity(2, LeftToRight) case CallType(_, _) => PrecedenceAssociativity(2, LeftToRight) case Call(_, _) => PrecedenceAssociativity(2, LeftToRight) case TypeAscription(left, tpe) => @@ -849,16 +974,28 @@ module RAST match op2 { case "*" | "/" | "%" => PrecedenceAssociativity(20, LeftToRight) case "+" | "-" => PrecedenceAssociativity(30, LeftToRight) - case "<<" | ">>" => PrecedenceAssociativity(40, LeftToRight) + case "<<" | ">>" => + // x as u16 << 6 is parsed as x as u16<... and expect a generic argument + if op2 == "<<" && left.TypeAscription? && left.tpe.EndsWithNameThatCanAcceptGenerics() then + PrecedenceAssociativity(9, LeftToRight) + else + PrecedenceAssociativity(40, LeftToRight) case "&" => PrecedenceAssociativity(50, LeftToRight) case "^" => PrecedenceAssociativity(60, LeftToRight) case "|" => PrecedenceAssociativity(70, LeftToRight) - case "==" | "!=" | "<" | ">" | "<=" | ">=" => PrecedenceAssociativity(80, RequiresParentheses) + case "==" | "!=" | "<" | ">" | "<=" | ">=" => + if (op2 == "<" || op2 == "<=") && left.TypeAscription? && left.tpe.EndsWithNameThatCanAcceptGenerics() then + PrecedenceAssociativity(9, LeftToRight) + else + PrecedenceAssociativity(80, RequiresParentheses) case "&&" => PrecedenceAssociativity(90, LeftToRight) case "||" => PrecedenceAssociativity(100, LeftToRight) case ".." | "..=" => PrecedenceAssociativity(110, RequiresParentheses) case "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=" => - PrecedenceAssociativity(110, RightToLeft) + if op2 == "<<=" && left.TypeAscription? && left.tpe.EndsWithNameThatCanAcceptGenerics() then + PrecedenceAssociativity(9, LeftToRight) + else + PrecedenceAssociativity(110, RightToLeft) case _ => PrecedenceAssociativity(0, RequiresParentheses) } case Lambda(_, _, _) => PrecedenceAssociativity(300, LeftToRight) @@ -937,7 +1074,9 @@ module RAST 1 + expression.Height() case SelectIndex(expression, range) => 1 + max(expression.Height(), range.Height()) - case MemberSelect(expression, name) => + case ExprFromPath(underlying) => + 1 + case FunctionSelect(expression, name) => 1 + expression.Height() case Lambda(params, retType, body) => if body.Block? || retType.None? then 1 + body.Height() @@ -971,7 +1110,7 @@ module RAST assert BinaryOp("<=", right, left, BinaryOpFormat.NoFormat()).Height() == BinaryOp("<", left, right, BinaryOpFormat.ReverseFormat()).Height(); BinaryOp("<=", right, left, BinaryOpFormat.NoFormat()) - case Call(MemberSelect(r, "truncate!"), args) => + case Call(ExprFromPath(PMemberSelect(r, "truncate!")), args) => if (r != dafny_runtime && r != global) || |args| != 2 then this else @@ -982,8 +1121,7 @@ module RAST if || tpe.U8? || tpe.U16? || tpe.U32? || tpe.U64? || tpe.U128? || tpe.I8? || tpe.I16? || tpe.I32? || tpe.I64? || tpe.I128? then match expr { - case Call( - MemberSelect(base, "int!"), args) => + case Call(ExprFromPath(PMemberSelect(base, "int!")), args) => if |args| == 1 && (base == dafny_runtime || base == global) then match args[0] { case LiteralInt(number) => LiteralInt(number) @@ -1017,7 +1155,7 @@ module RAST } predicate LeftRequiresParentheses(left: Expr) { - printingInfo.NeedParenthesesForLeft(left.printingInfo) + printingInfo.NeedParenthesesForLeft(left.Optimize().printingInfo) } function LeftParentheses(left: Expr): (string, string) { if LeftRequiresParentheses(left) then @@ -1027,7 +1165,7 @@ module RAST } predicate RightRequiresParentheses(right: Expr) { - printingInfo.NeedParenthesesForRight(right.printingInfo) + printingInfo.NeedParenthesesForRight(right.Optimize().printingInfo) } @@ -1040,7 +1178,8 @@ module RAST function RightMostIdentifier(): Option { match this { - case MemberSelect(_, id) => Some(id) + case FunctionSelect(_, id) => Some(id) + case ExprFromPath(p) => p.RightMostIdentifier() case _ => None } } @@ -1112,7 +1251,7 @@ module RAST case UnaryOp(op, underlying, format) => var (leftP, rightP) := - if printingInfo.NeedParenthesesFor(underlying.printingInfo) then + if printingInfo.NeedParenthesesFor(underlying.Optimize().printingInfo) then ("(", ")") else ("", ""); @@ -1205,7 +1344,9 @@ module RAST var (leftP, rightP) := LeftParentheses(expression); var rangeStr := range.ToString(ind + IND); leftP + expression.ToString(ind) + rightP + "[" + rangeStr + "]" - case MemberSelect(expression, name) => + case ExprFromPath(path) => + path.ToString() + case FunctionSelect(expression, name) => var (leftP, rightP) := LeftParentheses(expression); leftP + expression.ToString(ind) + rightP + "::" + name case Lambda(params, retType, body) => @@ -1234,8 +1375,8 @@ module RAST function Sel(name: string): Expr { Select(this, name) } - function MSel(name: string): Expr { - MemberSelect(this, name) + function FSel(name: string): Expr { + FunctionSelect(this, name) } function ApplyType(typeParameters: seq): Expr { if |typeParameters| == 0 then this else @@ -1257,11 +1398,11 @@ module RAST || (&& this.Call? && (|| ( - && this.obj == dafny_runtime.MSel("modify!") + && this.obj.ExprFromPath? && this.obj.path == dafny_runtime.MSel("modify!") && |this.arguments| == 1 // modify!(self) && this.arguments[0].Identifier?) || ( - && this.obj == dafny_runtime.MSel("md!") + && this.obj.ExprFromPath? && this.obj.path == dafny_runtime.MSel("md!") && |this.arguments| == 1 // md!(identifier.clone()) && var lhs := this.arguments[0]; && lhs.Call? @@ -1272,7 +1413,7 @@ module RAST function LhsIdentifierName(): string requires IsLhsIdentifier() { if this.Identifier? then name - else if this.obj == dafny_runtime.MSel("modify!") then + else if this.obj.ExprFromPath? && obj.path == dafny_runtime.MSel("modify!") then this.arguments[0].name else this.arguments[0].obj.obj.name @@ -1285,36 +1426,34 @@ module RAST const self := Identifier("self") - const global := Identifier("") - const dafny_runtime := global.MSel("dafny_runtime") - const dafny_runtime_Set := dafny_runtime.MSel("Set") - const dafny_runtime_Set_from_array := dafny_runtime_Set.MSel("from_array") - const dafny_runtime_Sequence := dafny_runtime.MSel("Sequence") - const Sequence_from_array_owned := dafny_runtime_Sequence.MSel("from_array_owned") - const Sequence_from_array := dafny_runtime_Sequence.MSel("from_array") - const dafny_runtime_Multiset := dafny_runtime.MSel("Multiset") - const dafny_runtime_Multiset_from_array := dafny_runtime_Multiset.MSel("from_array") + const crate := Crate() + const dafny_runtime_Set := dafny_runtime.MSel("Set").AsExpr() + const dafny_runtime_Set_from_array := dafny_runtime_Set.FSel("from_array") + const dafny_runtime_Sequence := dafny_runtime.MSel("Sequence").AsExpr() + const Sequence_from_array_owned := dafny_runtime_Sequence.FSel("from_array_owned") + const Sequence_from_array := dafny_runtime_Sequence.FSel("from_array") + const dafny_runtime_Multiset := dafny_runtime.MSel("Multiset").AsExpr() + const dafny_runtime_Multiset_from_array := dafny_runtime_Multiset.FSel("from_array") + function MaybePlacebo(underlying: Expr): Expr { - dafny_runtime.MSel("MaybePlacebo").MSel("from").Apply1(underlying) + MaybePlaceboPath.FSel("from").Apply1(underlying) } - const std := global.MSel("std") - const std_rc := std.MSel("rc") const std_rc_Rc := std_rc.MSel("Rc") - const std_rc_Rc_new := std_rc_Rc.MSel("new") + const std_rc_Rc_new := std_rc_Rc.FSel("new") - const std_Default_default := std.MSel("default").MSel("Default").MSel("default").Apply([]) + const std_Default_default := DefaultPath.FSel("default").Apply([]) function RcNew(underlying: Expr): Expr { Call(std_rc_Rc_new, [underlying]) } function IntoUsize(underlying: Expr): Expr { - dafny_runtime.MSel("DafnyUsize").MSel("into_usize").Apply1(underlying) + dafny_runtime.MSel("DafnyUsize").FSel("into_usize").Apply1(underlying) } datatype Fn = @@ -1340,11 +1479,15 @@ module RAST } module {:extern "DCOMP"} DafnyToRustCompiler { + import FactorPathsOptimization + import opened DAST import Strings = Std.Strings import Std import opened Std.Wrappers import R = RAST + import opened DafnyCompilerRustUtils + const IND := R.IND type Type = DAST.Type type Formal = DAST.Formal @@ -1361,7 +1504,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { "box","do","final","macro","override","priv","try","typeof","unsized", "virtual","yield"} - const reserved_fields := { "None" } + const reserved_vars := { "None", "hash" } const reserved_rust_need_prefix := {"u8", "u16", "u32", "u64", "u128","i8", "i16", "i32", "i64", "i128"} @@ -1429,7 +1572,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { predicate is_idiomatic_rust_id(i: string) { 0 < |i| && !has_special(i) && i !in reserved_rust && i !in reserved_rust_need_prefix } - + // To be used when escaping class names, datatype constructors, externs, paths, function/method names, etc. + // Datatype destructors, variable names and field names all use escapeVar() function escapeName(n: Name): string { escapeIdent(n.dafny_name) } @@ -1452,18 +1596,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { "r#_" + r } - function escapeField(f: Name): string { - var r := f.dafny_name; - if r in reserved_fields then - "r#_" + r - else escapeName(f) - } - - function escapeDtor(f: Name): string { + // To be used when escaping variables + function escapeVar(f: VarName): string { var r := f.dafny_name; - if r in reserved_fields then - r + ": r#_" + r - else escapeName(f) + if r in reserved_vars then + "_" + r + else + escapeIdent(f.dafny_name) } datatype Ownership = @@ -1539,19 +1678,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { datatype ObjectType = RawPointers | RcMut datatype GenTypeContext = - GenTypeContext(inBinding: bool, inFn: bool, forTraitParents: bool) + GenTypeContext(forTraitParents: bool) { - static function InBinding(): GenTypeContext { - GenTypeContext(true, false, false) - } - static function InFn(): GenTypeContext { - GenTypeContext(false, true, false) - } static function ForTraitParents(): GenTypeContext { - GenTypeContext(false, false, true) + GenTypeContext(true) } static function default(): GenTypeContext { - GenTypeContext(false, false, false) + GenTypeContext(false) } } @@ -1580,7 +1713,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { attributes, properMethods, extendedTypes) := r; - if Ident.Ident(Name(dafnyName)) in properMethods then + if Name(dafnyName) in properMethods then Some(r) else TraitTypeContainingMethodAux(extendedTypes, dafnyName) @@ -1600,6 +1733,62 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + datatype ExternAttribute = + | NoExtern() + | SimpleExtern(overrideName: string) + | AdvancedExtern(enclosingModule: string, overrideName: string) + | UnsupportedExtern(reason: string) + + opaque function OptExtern(attr: Attribute, dafnyName: Name): Option { + if attr.name == "extern" then + Some( + if |attr.args| == 0 then SimpleExtern(escapeName(dafnyName)) else + if |attr.args| == 1 then SimpleExtern(attr.args[0]) else + if |attr.args| == 2 then AdvancedExtern(ReplaceDotByDoubleColon(attr.args[0]), attr.args[1]) else + UnsupportedExtern("{:extern} supports only 0, 1 or 2 attributes, got " + Std.Strings.OfNat(|attr.args|)) + ) + else + None + } + + // Dots are not valid identifier characters in Rust, so we replace them by double colons. + // We don't perform this replacement after any space occurs in an extern string + // because normally spaces don't occur in paths, so any use of space indicates something different. + function ReplaceDotByDoubleColon(s: string): string { + if |s| == 0 then "" else + if s[0] == ' ' then s else + (if s[0] == '.' then "::" else [s[0]]) + ReplaceDotByDoubleColon(s[1..]) + } + + function ExtractExtern(attributes: seq, dafnyName: Name): (res: ExternAttribute) { + if |attributes| == 0 then NoExtern() + else + var attr := OptExtern(attributes[0], dafnyName); + match attr + case Some(n) => n + case None => + ExtractExtern(attributes[1..], dafnyName) + } by method { + for i := 0 to |attributes| + invariant ExtractExtern(attributes, dafnyName) == ExtractExtern(attributes[i..], dafnyName) + { + var attr := OptExtern(attributes[i], dafnyName); + assert attributes[i] == attributes[i..][0]; + match attr { + case Some(n) => + res := n; + return; + case _ => + } + assert attributes[i..][1..] == attributes[i+1..]; + } + res := NoExtern(); + } + + function ExtractExternMod(mod: Module): ExternAttribute { + ExtractExtern(mod.attributes, mod.name) + } + class COMP { const UnicodeChars: bool const DafnyChar := if UnicodeChars then "DafnyChar" else "DafnyCharUTF16" @@ -1614,10 +1803,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if ObjectType.RawPointers? then R.Identifier("this") else R.Identifier("this").Clone() const array_construct := if ObjectType.RawPointers? then "construct" else "construct_object" - const modify_macro := R.dafny_runtime.MSel(if ObjectType.RawPointers? then "modify!" else "md!") - const read_macro := R.dafny_runtime.MSel(if ObjectType.RawPointers? then "read!" else "rd!") + const modify_macro := R.dafny_runtime.MSel(if ObjectType.RawPointers? then "modify!" else "md!").AsExpr() + const read_macro := R.dafny_runtime.MSel(if ObjectType.RawPointers? then "read!" else "rd!").AsExpr() function Object(underlying: R.Type): R.Type { - if ObjectType.RawPointers? then R.PointerMut(underlying) else R.ObjectType(underlying) + if ObjectType.RawPointers? then R.PtrType(underlying) else R.ObjectType(underlying) } const placebos_usize := if ObjectType.RawPointers? then "placebos_usize" else "placebos_usize_object" const update_field_if_uninit_macro := @@ -1641,43 +1830,67 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var error: Option + var optimizations: seq R.Mod> + + static const DAFNY_EXTERN_MODULE := "_dafny_externs" + constructor(unicodeChars: bool, objectType: ObjectType) { this.UnicodeChars := unicodeChars; this.ObjectType := objectType; this.error := None; // If error, then the generated code contains Unsupported: .* + this.optimizations := [FactorPathsOptimization.apply]; new; - if objectType.RawPointers? { - this.error := Some("Raw pointers need to be wrapped in a newtype so that their equality has the semantics of Dafny (e.g. a class pointer and a trait pointer are equal), not Rust."); - } } - method GenModule(mod: Module, containingPath: seq) returns (s: R.Mod) + static function ContainingPathToRust(containingPath: seq): seq { + Std.Collections.Seq.Map((i: Ident) => escapeName(i.id), containingPath) + } + + // Returns a top-level gathering module that can be merged with other gathering modules + method GenModule(mod: Module, containingPath: seq) returns (s: SeqMap) decreases mod, 1 modifies this { - var modName := escapeName(mod.name); + var (innerPath, innerName) := DafnyNameToContainingPathAndName(mod.name); + var containingPath := containingPath + innerPath; + var modName := escapeName(innerName); if mod.body.None? { - s := R.ExternMod(modName); + s := GatheringModule.Wrap(ContainingPathToRust(containingPath), R.ExternMod(modName)); } else { assume {:axiom} forall m: ModuleItem <- mod.body.value :: m < mod; - var body := GenModuleBody(mod, mod.body.value, containingPath + [Ident.Ident(mod.name)]); - s := R.Mod(modName, body); + var optExtern: ExternAttribute := ExtractExternMod(mod); + var body, allmodules := GenModuleBody(mod, mod.body.value, containingPath + [Ident.Ident(innerName)]); + if optExtern.SimpleExtern? { + if mod.requiresExterns { + body := [R.UseDecl(R.Use(R.PUB, R.crate.MSel(DAFNY_EXTERN_MODULE).MSel(ReplaceDotByDoubleColon(optExtern.overrideName)).MSel("*")))] + body; + } + } else if optExtern.AdvancedExtern? { + error := Some("Externs on modules can only have 1 string argument"); + } else if optExtern.UnsupportedExtern? { + error := Some(optExtern.reason); + } + s := GatheringModule.MergeSeqMap( + GatheringModule.Wrap(ContainingPathToRust(containingPath), R.Mod(modName, body)), + allmodules); } } - method GenModuleBody(ghost parent: Module, body: seq, containingPath: seq) returns (s: seq) + method GenModuleBody(ghost parent: Module, body: seq, containingPath: seq) + returns (s: seq, allmodules: SeqMap) requires forall m: ModuleItem <- body :: m < parent decreases parent, 0 modifies this { s := []; + allmodules := SeqMap.Empty(); for i := 0 to |body| { var generated; match body[i] { case Module(m) => assume {:axiom} m < parent; var mm := GenModule(m, containingPath); - generated := [R.ModDecl(mm)]; + allmodules := GatheringModule.MergeSeqMap(allmodules, mm); + generated := []; case Class(c) => generated := GenClass(c, containingPath + [Ident.Ident(c.name)]); case Trait(t) => @@ -1701,7 +1914,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { else [R.DafnyType]; if SupportsDefault in tp.bounds { - genTpConstraint := genTpConstraint + [R.std_type.MSel("default").MSel("Default")]; + genTpConstraint := genTpConstraint + [R.DefaultTrait]; } typeParam := R.TypeParamDecl(escapeName(tp.name.id), genTpConstraint); } @@ -1743,6 +1956,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { && r1.typeArgs == r2.typeArgs } + function GatherTypeParamNames(types: set, typ: R.Type): set { + typ.Fold(types, (types: set, currentType: R.Type) => + if currentType.TIdentifier? then + types + {currentType.name} + else + types + ) + } + method GenClass(c: Class, path: seq) returns (s: seq) modifies this { @@ -1751,10 +1973,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var fields: seq := []; var fieldInits: seq := []; + var usedTypeParams: set := {}; for fieldI := 0 to |c.fields| { var field := c.fields[fieldI]; var fieldType := GenType(field.formal.typ, GenTypeContext.default()); - var fieldRustName := escapeName(field.formal.name); + usedTypeParams := GatherTypeParamNames(usedTypeParams, fieldType); + var fieldRustName := escapeVar(field.formal.name); fields := fields + [R.Field(R.PUB, R.Formal(fieldRustName, fieldType))]; match field.defaultValue { @@ -1784,23 +2008,39 @@ module {:extern "DCOMP"} DafnyToRustCompiler { for typeParamI := 0 to |c.typeParams| { var typeArg, typeParam := GenTypeParam(c.typeParams[typeParamI]); var rTypeArg := GenType(typeArg, GenTypeContext.default()); + if typeParam.name in usedTypeParams { + continue; + } fields := fields + [ R.Field(R.PRIV, R.Formal("_phantom_type_param_" + Strings.OfNat(typeParamI), - R.TypeApp(R.std_type.MSel("marker").MSel("PhantomData"), [rTypeArg])))]; + R.TypeApp(R.std.MSel("marker").MSel("PhantomData").AsType(), [rTypeArg])))]; fieldInits := fieldInits + [ R.AssignIdentifier( "_phantom_type_param_" + Strings.OfNat(typeParamI), R.RawExpr("::std::marker::PhantomData"))]; } - var datatypeName := escapeName(c.name); + var extern := ExtractExtern(c.attributes, c.name); - var struct := R.Struct([], datatypeName, rTypeParamsDecls, R.NamedFields(fields)); + var className; + if extern.SimpleExtern? { + className := extern.overrideName; + } else { + className := escapeName(c.name); + if extern.AdvancedExtern? { + error := Some("Multi-argument externs not supported for classes yet"); + } + } - s := [R.StructDecl(struct)]; + var struct := R.Struct([], className, rTypeParamsDecls, R.NamedFields(fields)); + s := []; - var implBodyRaw, traitBodies := GenClassImplBody( + if extern.NoExtern? { + s := s + [R.StructDecl(struct)]; + } + + var implBody, traitBodies := GenClassImplBody( c.body, false, Type.UserDefined( ResolvedType( @@ -1810,48 +2050,64 @@ module {:extern "DCOMP"} DafnyToRustCompiler { c.attributes, [], [])), typeParamsSeq); - var implBody := [ - R.FnDecl( - R.PUB, - R.Fn(allocate_fn, - [], [], Some(Object(R.SelfOwned)), - "", - Some( - R.dafny_runtime.MSel(allocate).ApplyType1(R.SelfOwned).Apply([]) - )) - ) - ] + implBodyRaw; - var i := R.Impl( - rTypeParamsDecls, - R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), - whereConstraints, - implBody - ); - s := s + [R.ImplDecl(i)]; - var genSelfPath := GenPath(path); + if extern.NoExtern? && className != "_default" { + implBody := [ + R.FnDecl( + R.PUB, + R.Fn(allocate_fn, + [], [], Some(Object(R.SelfOwned)), + "", + Some( + R.dafny_runtime.MSel(allocate).AsExpr().ApplyType1(R.SelfOwned).Apply([]) + )) + ) + ] + implBody; + } + + var selfTypeForImpl; + if extern.NoExtern? || extern.UnsupportedExtern? { + selfTypeForImpl := R.TIdentifier(className); + } else if extern.AdvancedExtern? { + selfTypeForImpl := R.crate.MSel(extern.enclosingModule).MSel(extern.overrideName).AsType(); + } else if extern.SimpleExtern? { + selfTypeForImpl := R.TIdentifier(extern.overrideName); + } + if |implBody| > 0 { + var i := R.Impl( + rTypeParamsDecls, + R.TypeApp(selfTypeForImpl, rTypeParams), + whereConstraints, + implBody + ); + s := s + [R.ImplDecl(i)]; + } + var genSelfPath := GenPathType(path); // TODO: If general traits, check whether the trait extends object or not. - s := s + [ - R.ImplDecl( - R.ImplFor( - rTypeParamsDecls, - R.dafny_runtime_type.MSel(Upcast).Apply([R.DynType(R.std_type.MSel("any").MSel("Any"))]), - R.TypeApp(genSelfPath, rTypeParams), - whereConstraints, - [ - R.ImplMemberMacro( - R.dafny_runtime - .MSel(UpcastFnMacro) - .Apply1(R.ExprFromType(R.DynType(R.std_type.MSel("any").MSel("Any"))))) - ] + if className != "_default" { + s := s + [ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.dafny_runtime.MSel(Upcast).AsType().Apply([R.DynType(R.AnyTrait)]), + R.TypeApp(genSelfPath, rTypeParams), + whereConstraints, + [ + R.ImplMemberMacro( + R.dafny_runtime + .MSel(UpcastFnMacro).AsExpr() + .Apply1(R.ExprFromType(R.DynType(R.AnyTrait)))) + ] + ) ) - ) - ]; - for i := 0 to |c.superClasses| { - var superClass := c.superClasses[i]; + ]; + } + var superClasses := if className == "_default" then [] else c.superClasses; + for i := 0 to |superClasses| { + var superClass := superClasses[i]; match superClass { - case UserDefined(ResolvedType(traitPath, typeArgs, Trait(), _, _, _)) => { - var pathStr := GenPath(traitPath); + case UserDefined(ResolvedType(traitPath, typeArgs, Trait(), _, properMethods, _)) => { + var pathStr := GenPathType(traitPath); var typeArgs := GenTypeArgs(typeArgs, GenTypeContext.default()); var body: seq := []; if traitPath in traitBodies { @@ -1859,6 +2115,23 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var traitType := R.TypeApp(pathStr, typeArgs); + if !extern.NoExtern? { // An extern of some kind + // Either the Dafny code implements all the methods of the trait or none, + if |body| == 0 && |properMethods| != 0 { + continue; // We assume everything is implemented externally + } + if |body| != |properMethods| { + error := Some("Error: In the class " + R.SeqToString(path, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + + traitType.ToString("") + " are marked {:extern} and some are not." + + " For the Rust compiler, please make all methods (" + R.SeqToString(properMethods, (s: Name) => s.dafny_name, ", ") + + ") bodiless and mark as {:extern} and implement them in a Rust file, "+ + "or mark none of them as {:extern} and implement them in Dafny. " + + "Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."); + } + } + if |body| == 0 { + // Extern type, we assume + } var x := R.ImplDecl( R.ImplFor( rTypeParamsDecls, @@ -1873,13 +2146,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplDecl( R.ImplFor( rTypeParamsDecls, - R.dafny_runtime_type.MSel(Upcast).Apply([R.DynType(traitType)]), + R.dafny_runtime.MSel(Upcast).AsType().Apply([R.DynType(traitType)]), R.TypeApp(genSelfPath, rTypeParams), whereConstraints, [ R.ImplMemberMacro( R.dafny_runtime - .MSel(UpcastFnMacro) + .MSel(UpcastFnMacro).AsExpr() .Apply1(R.ExprFromType(R.DynType(traitType)))) ] ) @@ -1920,7 +2193,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var parents := []; for i := 0 to |t.parents| { var tpe := GenType(t.parents[i], GenTypeContext.ForTraitParents()); - parents := parents + [tpe] + [R.dafny_runtime_type.MSel(Upcast).Apply1(R.DynType(tpe))]; + parents := parents + [tpe] + [R.dafny_runtime.MSel(Upcast).AsType().Apply1(R.DynType(tpe))]; } s := [ R.TraitDecl( @@ -1938,7 +2211,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var constrainedTypeParams := R.TypeParamDecl.ToStringMultiple(rTypeParamsDecls, R.IND + R.IND); var underlyingType; - match NewtypeToRustType(c.base, c.range) { + match NewtypeRangeToRustType(c.range) { case Some(v) => underlyingType := v; case None => @@ -2042,7 +2315,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.FnDecl( R.PRIV, R.Fn("deref", [], - [R.Formal.selfBorrowed], Some(R.SelfBorrowed.MSel("Target")), + [R.Formal.selfBorrowed], Some(R.Borrowed(R.Self().MSel("Target").AsType())), "", Some(R.RawExpr("&self.0"))))]))]; } @@ -2051,7 +2324,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { modifies this { var typeParamsSeq, rTypeParams, rTypeParamsDecls, whereConstraints := GenTypeParameters(c.typeParams); - var constrainedTypeParams := R.TypeParamDecl.ToStringMultiple(rTypeParamsDecls, R.IND + R.IND); var synonymTypeName := escapeName(c.name); var resultingType := GenType(c.base, GenTypeContext.default()); @@ -2062,6 +2334,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { synonymTypeName, rTypeParamsDecls, resultingType ))]; + var defaultConstrainedTypeParams := R.TypeParamDecl.AddConstraintsMultiple( + rTypeParamsDecls, [R.DefaultTrait] + ); match c.witnessExpr { case Some(e) => { var rStmts, _, newEnv := GenStmts(c.witnessStmts, NoSelf, Environment.Empty(), false, None); @@ -2072,7 +2347,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.TopFn( [], R.PUB, R.Fn( - constantName, [], [], Some(resultingType), + constantName, defaultConstrainedTypeParams, [], Some(resultingType), "", Some(rStmts.Then(rExpr))) ) @@ -2114,6 +2389,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var datatypeName := escapeName(c.name); var ctors: seq := []; var variances := Std.Collections.Seq.Map((typeParamDecl: TypeArgDecl) => typeParamDecl.variance, c.typeParams); + var usedTypeParams: set := {}; for i := 0 to |c.ctors| { var ctor := c.ctors[i]; var ctorArgs: seq := []; @@ -2121,7 +2397,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { for j := 0 to |ctor.args| { var dtor := ctor.args[j]; var formalType := GenType(dtor.formal.typ, GenTypeContext.default()); - var formalName := escapeName(dtor.formal.name); + usedTypeParams := GatherTypeParamNames(usedTypeParams, formalType); + var formalName := escapeVar(dtor.formal.name); if j == 0 && "0" == formalName { isNumeric := true; } @@ -2133,7 +2410,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ctorArgs := ctorArgs + [ R.Field(R.PRIV, R.Formal(formalName, - R.TypeApp(R.dafny_runtime_type.MSel("LazyFieldWrapper"), [formalType])))]; + R.TypeApp(R.dafny_runtime.MSel("LazyFieldWrapper").AsType(), [formalType])))]; } else { ctorArgs := ctorArgs + [ R.Field(R.PRIV, @@ -2146,6 +2423,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } ctors := ctors + [R.EnumCase(escapeName(ctor.name), namedFields)]; } + var unusedTypeParams := (set tp <- rTypeParamsDecls :: tp.name) - usedTypeParams; var selfPath := [Ident.Ident(c.name)]; var implBodyRaw, traitBodies := @@ -2167,7 +2445,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var ctor := c.ctors[i]; for j := 0 to |ctor.args| { var dtor := ctor.args[j]; - var callName := dtor.callName.GetOr(escapeName(dtor.formal.name)); + var callName := dtor.callName.GetOr(escapeVar(dtor.formal.name)); if !(callName in emittedFields) { emittedFields := emittedFields + {callName}; @@ -2183,17 +2461,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var isNumeric := false; for l := 0 to |ctor2.args| { var dtor2 := ctor2.args[l]; - var patternName := escapeDtor(dtor2.formal.name); - var varName := escapeField(dtor2.formal.name); + var patternName := escapeVar(dtor2.formal.name); if l == 0 && patternName == "0" { isNumeric := true; } if isNumeric { patternName := dtor2.callName.GetOr("v" + Strings.OfNat(l)); - varName := patternName; } if dtor.formal.name == dtor2.formal.name { - hasMatchingField := Some(varName); + // Note: here, we use escapeVar because the corresponding destructor uses a non-punned name + hasMatchingField := Some(patternName); } patternInner := patternInner + patternName + ", "; } @@ -2216,7 +2493,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { cases := cases + [ctorMatch]; } - if |c.typeParams| > 0 { + if |c.typeParams| > 0 && |unusedTypeParams| > 0 { cases := cases + [ R.MatchCase(R.RawPattern(datatypeName + "::_PhantomVariant(..)"), R.RawExpr(UnreachablePanicIfVerified(""))) ]; @@ -2251,7 +2528,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var typeParam := c.typeParams[typeI]; var typeArg, rTypeParamDecl := GenTypeParam(typeParam); var rTypeArg := GenType(typeArg, GenTypeContext.default()); - types := types + [R.TypeApp(R.std_type.MSel("marker").MSel("PhantomData"), [rTypeArg])]; + types := types + [R.TypeApp(R.std.MSel("marker").MSel("PhantomData").AsType(), [rTypeArg])]; // Coercion arguments if typeI < |variances| && variances[typeI].Nonvariant? { coerceTypes := coerceTypes + [rTypeArg]; @@ -2274,13 +2551,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Rc(R.IntersectionType(R.ImplType(R.FnType([rTypeArg], rCoerceType)), R.StaticTrait))) ]; } - ctors := ctors + [ - R.EnumCase( - "_PhantomVariant", - R.NamelessFields( - Std.Collections.Seq.Map( - tpe => R.NamelessField(R.PRIV, tpe), types)) - )]; + if |unusedTypeParams| > 0 { + ctors := ctors + [ + R.EnumCase( + "_PhantomVariant", + R.NamelessFields( + Std.Collections.Seq.Map( + tpe => R.NamelessField(R.PRIV, tpe), types)) + )]; + } } var cIsEq := DatatypeIsEq(c); @@ -2327,22 +2606,21 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var ctorMatchInner := ""; for j := 0 to |ctor.args| { var dtor := ctor.args[j]; - var patternName := escapeDtor(dtor.formal.name); - var fieldName := escapeField(dtor.formal.name); + var patternName := escapeVar(dtor.formal.name); var formalType := dtor.formal.typ; - if j == 0 && fieldName == "0" { + if j == 0 && patternName == "0" { isNumeric := true; } if isNumeric { - fieldName := dtor.callName.GetOr("v" + Strings.OfNat(j)); + patternName := dtor.callName.GetOr("v" + Strings.OfNat(j)); } hashRhs := if formalType.Arrow? then hashRhs.Then(R.LiteralInt("0").Sel("hash").Apply1(R.Identifier("_state"))) else - hashRhs.Then(R.Identifier(fieldName).Sel("hash").Apply1(R.Identifier("_state"))); + hashRhs.Then(R.std.MSel("hash").MSel("Hash").MSel("hash").AsExpr().Apply([R.Identifier(patternName), R.Identifier("_state")])); - ctorMatchInner := ctorMatchInner + (if isNumeric then fieldName else patternName) + ", "; + ctorMatchInner := ctorMatchInner + patternName + ", "; if (j > 0) { printRhs := printRhs.Then(R.RawExpr("write!(_formatter, \", \")?")); @@ -2353,7 +2631,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if formalType.Arrow? then "write!(_formatter, \"\")?" else - "::dafny_runtime::DafnyPrint::fmt_print(" + fieldName + ", _formatter, false)?" + "::dafny_runtime::DafnyPrint::fmt_print(" + patternName + ", _formatter, false)?" )); var coerceRhsArg: R.Expr; @@ -2363,7 +2641,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var formalTpe := GenType(formalType, GenTypeContext.default()); var newFormalType := formalType.Replace(coerceMap); - var newFormalTpe := formalTpe.Replace(rCoerceMap); + var newFormalTpe := formalTpe.ReplaceMap(rCoerceMap); var upcastConverter := UpcastConversionLambda(formalType, formalTpe, newFormalType, newFormalTpe, coerceMapToArg); if upcastConverter.Success? { @@ -2376,7 +2654,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { coerceRhsArgs := coerceRhsArgs + [R.AssignIdentifier(patternName, coerceRhsArg)]; } - var coerceRhs := R.StructBuild(R.Identifier(datatypeName).MSel(escapeName(ctor.name)), + var coerceRhs := R.StructBuild(R.Identifier(datatypeName).FSel(escapeName(ctor.name)), coerceRhsArgs); if isNumeric { @@ -2405,7 +2683,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ]; } - if |c.typeParams| > 0 { + if |c.typeParams| > 0 && |unusedTypeParams| > 0 { var extraCases := [ R.MatchCase(R.RawPattern(datatypeName + "::_PhantomVariant(..)"), R.RawExpr("{"+UnreachablePanicIfVerified()+"}")) ]; @@ -2435,7 +2713,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplDecl( R.ImplFor( rTypeParamsDecls, - R.std_type.MSel("fmt").MSel("Debug"), + R.std.MSel("fmt").MSel("Debug").AsType(), R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), "", [ @@ -2444,12 +2722,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Fn( "fmt", [], [R.Formal.selfBorrowed, - R.Formal("f", R.BorrowedMut(R.std_type.MSel("fmt").MSel("Formatter")))], - Some(R.RawType("std::fmt::Result")), + R.Formal("f", R.BorrowedMut(R.std.MSel("fmt").MSel("Formatter").AsType()))], + Some(R.std.MSel("fmt").MSel("Result").AsType()), "", Some(R.dafny_runtime .MSel("DafnyPrint") .MSel("fmt_print") + .AsExpr() .Apply( [ R.self, R.Identifier("f"), @@ -2469,7 +2748,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Fn( "fmt_print", [], [R.Formal.selfBorrowed, - R.Formal("_formatter", R.BorrowedMut(R.std_type.MSel("fmt").MSel("Formatter"))), + R.Formal("_formatter", R.BorrowedMut(R.std.MSel("fmt").MSel("Formatter").AsType())), R.Formal("_in_seq", R.Type.Bool)], Some(R.RawType("std::fmt::Result")), "", @@ -2529,7 +2808,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [R.FnDecl( R.PRIV, R.Fn( - "hash", [R.TypeParamDecl("_H", [R.std_type.MSel("hash").MSel("Hasher")])], + "hash", [R.TypeParamDecl("_H", [R.std.MSel("hash").MSel("Hasher").AsType()])], [R.Formal.selfBorrowed, R.Formal("_state", R.BorrowedMut(R.TIdentifier("_H")))], None, @@ -2539,12 +2818,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )]; if |c.ctors| > 0 { - var structName := R.Identifier(datatypeName).MSel(escapeName(c.ctors[0].name)); + var structName := R.Identifier(datatypeName).FSel(escapeName(c.ctors[0].name)); var structAssignments: seq := []; for i := 0 to |c.ctors[0].args| { var dtor := c.ctors[0].args[i]; structAssignments := structAssignments + [ - R.AssignIdentifier(escapeName(dtor.formal.name), R.RawExpr("::std::default::Default::default()")) + R.AssignIdentifier(escapeVar(dtor.formal.name), R.RawExpr("::std::default::Default::default()")) ]; } var defaultConstrainedTypeParams := R.TypeParamDecl.AddConstraintsMultiple( @@ -2580,7 +2859,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplDecl( R.ImplFor( rTypeParamsDecls, - R.std_type.MSel("convert").MSel("AsRef").Apply1(fullType), + R.std.MSel("convert").MSel("AsRef").AsType().Apply1(fullType), R.Borrowed(fullType), "", [R.FnDecl( @@ -2593,39 +2872,44 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - static method GenPath(p: seq) returns (r: R.Type) { + static method GenPath(p: seq, escape: bool := true) returns (r: R.Path) { if |p| == 0 { - return R.SelfOwned; + return R.Self(); } else { - // TODO: Better distinction between Dafny modules and any module r := if p[0].id.dafny_name == "std" then - R.TIdentifier("") + R.Global() else if p[0].id.dafny_name == "_System" then - R.dafny_runtime_type + R.dafny_runtime else - R.TIdentifier("super"); + R.Crate(); for i := 0 to |p| { - r := r.MSel(escapeName(p[i].id)); + var name := p[i].id; + if escape { + var (modules, finalName) := DafnyNameToContainingPathAndName(name); + for j := 0 to |modules| { + r := r.MSel(escapeName(modules[j].id)); + } + r := r.MSel(escapeName(finalName)); + } else { + // TODO: Try removing this else branch and the escape test. + r := r.MSel(ReplaceDotByDoubleColon(name.dafny_name)); + } } } } - static method GenPathExpr(p: seq) returns (r: R.Expr) { + static method GenPathType(p: seq) returns (t: R.Type) { + var p := GenPath(p, true); + t := p.AsType(); + } + + static method GenPathExpr(p: seq, escape: bool := true) returns (e: R.Expr) { if |p| == 0 { return R.self; - } else { - r := - if p[0].id.dafny_name == "std" then - R.Identifier("") - else if p[0].id.dafny_name == "_System" then - R.dafny_runtime - else - R.Identifier("super"); - for i := 0 to |p| { - r := r.MSel(escapeName(p[i].id)); - } } + var p := GenPath(p, escape); + e := p.AsExpr(); } method GenTypeArgs(args: seq, genTypeContext: GenTypeContext) returns (s: seq) { @@ -2642,10 +2926,28 @@ module {:extern "DCOMP"} DafnyToRustCompiler { Attribute("rust_rc", ["true"]) in attributes } + /** The type context is useful in the case when we need to generate a type + in a position that requires a variant of the given type. + + For now, it makes it possible to ensure that: + GenType(UserDefined(ResolveType(["U"], Trait()), ForTrait()) == U + + but + + GenType(UserDefined(ResolveType(["U"], Trait()), default()) == Object + + so that we can generate U instead of Object in the following context: + + trait U: Any {} + trait T: Any + U {} + + The last U is obtained with GenType() with GenTypeContext(forTraitParents := true) + Otherwise, we would have had Object, which is not a trait type. + */ method GenType(c: Type, genTypeContext: GenTypeContext) returns (s: R.Type) { match c { case UserDefined(resolved) => { - var t := GenPath(resolved.path); + var t := GenPathType(resolved.path); var typeArgs := GenTypeArgs(resolved.typeArgs, genTypeContext.(forTraitParents := false)); s := R.TypeApp(t, typeArgs); @@ -2660,25 +2962,27 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } case Trait() => { if resolved.path == [Ident.Ident(Name("_System")), Ident.Ident(Name("object"))] { - s := R.std_type.MSel("any").MSel("Any"); + s := R.AnyTrait; } if !genTypeContext.forTraitParents { s := Object(R.DynType(s)); } } - case Newtype(t, range, erased) => { + case Newtype(base, range, erased) => { if erased { - match NewtypeToRustType(t, range) { + match NewtypeRangeToRustType(range) { case Some(v) => s := v; case None => + var underlying := GenType(base, GenTypeContext.default()); + s := R.TSynonym(s, underlying); } } } } } case Object() => { - s := R.std_type.MSel("any").MSel("Any"); + s := R.AnyTrait; if !genTypeContext.forTraitParents { s := Object(R.DynType(s)); } @@ -2703,66 +3007,60 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := Object(s); } else { var n := "Array" + Strings.OfNat(dims); - s := R.dafny_runtime_type.MSel(n).Apply([elem]); + s := R.dafny_runtime.MSel(n).AsType().Apply([elem]); s := Object(s); } } } case Seq(element) => { var elem := GenType(element, genTypeContext.(forTraitParents := false)); - s := R.TypeApp(R.dafny_runtime_type.MSel("Sequence"), [elem]); + s := R.TypeApp(R.dafny_runtime.MSel("Sequence").AsType(), [elem]); } case Set(element) => { var elem := GenType(element, genTypeContext.(forTraitParents := false)); - s := R.TypeApp(R.dafny_runtime_type.MSel("Set"), [elem]); + s := R.TypeApp(R.dafny_runtime.MSel("Set").AsType(), [elem]); } case Multiset(element) => { var elem := GenType(element, genTypeContext.(forTraitParents := false)); - s := R.TypeApp(R.dafny_runtime_type.MSel("Multiset"), [elem]); + s := R.TypeApp(R.dafny_runtime.MSel("Multiset").AsType(), [elem]); } case Map(key, value) => { var keyType := GenType(key, genTypeContext.(forTraitParents := false)); var valueType := GenType(value, genTypeContext); - s := R.TypeApp(R.dafny_runtime_type.MSel("Map"), [keyType, valueType]); + s := R.TypeApp(R.dafny_runtime.MSel("Map").AsType(), [keyType, valueType]); } case MapBuilder(key, value) => { var keyType := GenType(key, genTypeContext.(forTraitParents := false)); var valueType := GenType(value, genTypeContext); - s := R.TypeApp(R.dafny_runtime_type.MSel("MapBuilder"), [keyType, valueType]); + s := R.TypeApp(R.dafny_runtime.MSel("MapBuilder").AsType(), [keyType, valueType]); } case SetBuilder(elem) => { var elemType := GenType(elem, genTypeContext.(forTraitParents := false)); - s := R.TypeApp(R.dafny_runtime_type.MSel("SetBuilder"), [elemType]); + s := R.TypeApp(R.dafny_runtime.MSel("SetBuilder").AsType(), [elemType]); } case Arrow(args, result) => { var argTypes := []; var i := 0; while i < |args| { - var generated := GenType(args[i], genTypeContext.(inFn := true, forTraitParents := false)); + var generated := GenType(args[i], genTypeContext.(forTraitParents := false)); argTypes := argTypes + [R.Borrowed(generated)]; i := i + 1; } - var resultType := GenType(result, GenTypeContext(genTypeContext.inFn || genTypeContext.inBinding, false, false)); + var resultType := GenType(result, GenTypeContext.default()); s := R.Rc(R.DynType(R.FnType(argTypes, resultType))); - - // if inFn || inBinding { - //s := s + ") -> " + resultType + " + 'static>>"; - // } else { - // s := s + ") -> " + resultType + " + Clone + 'static>"; - // } } case TypeArg(Ident(name)) => s := R.TIdentifier(escapeName(name)); case Primitive(p) => { match p { - case Int => s := R.dafny_runtime_type.MSel("DafnyInt"); - case Real => s := R.dafny_runtime_type.MSel("BigRational"); - case String => s := R.TypeApp(R.dafny_runtime_type.MSel("Sequence"), - [R.dafny_runtime_type.MSel(DafnyChar)]); + case Int => s := R.dafny_runtime.MSel("DafnyInt").AsType(); + case Real => s := R.dafny_runtime.MSel("BigRational").AsType(); + case String => s := R.TypeApp(R.dafny_runtime.MSel("Sequence").AsType(), + [R.dafny_runtime.MSel(DafnyChar).AsType()]); case Bool => s := R.Type.Bool; - case Char => s := R.dafny_runtime_type.MSel(DafnyChar); + case Char => s := R.dafny_runtime.MSel(DafnyChar).AsType(); } } case Passthrough(v) => s := R.RawType(v); @@ -2809,17 +3107,17 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } // Transform DAST formals to Rust formals - method GenParams(params: seq) returns (s: seq) + method GenParams(params: seq, forLambda: bool := false) returns (s: seq) ensures |s| == |params| { s := []; for i := 0 to |params| invariant |s| == i && i <= |params| { var param := params[i]; var paramType := GenType(param.typ, GenTypeContext.default()); - if !paramType.CanReadWithoutClone() && AttributeOwned !in param.attributes { + if (!paramType.CanReadWithoutClone() || forLambda) && AttributeOwned !in param.attributes { paramType := R.Borrowed(paramType); } - s := s + [R.Formal(escapeName(param.name), paramType)]; + s := s + [R.Formal(escapeVar(param.name), paramType)]; } } @@ -2852,15 +3150,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case _ => enclosingType }; if (forTrait) { - var selfFormal := if m.wasFunction then R.Formal.selfBorrowed else R.Formal.selfBorrowedMut; + // Mutability is required when not using raw pointers, even for functione, because + // --release optimisations sometimes removes the code to increment the reference counting on upcasting + var selfFormal := if m.wasFunction && ObjectType.RawPointers? then R.Formal.selfBorrowed else R.Formal.selfBorrowedMut; params := [selfFormal] + params; } else { var tpe := GenType(instanceType, GenTypeContext.default()); if selfId == "this" { - tpe := R.Borrowed(tpe); + if ObjectType.RcMut? { + tpe := R.Borrowed(tpe); + } + // For raw pointers, no borrowing is necessary, because it implements the Copy type } else if selfId == "self" { - if tpe.IsObjectOrPointer() { // For classes. - if m.wasFunction { + if tpe.IsObjectOrPointer() { // For classes and traits + if m.wasFunction && ObjectType.RawPointers? { tpe := R.SelfBorrowed; } else { tpe := R.SelfBorrowedMut; @@ -2906,8 +3209,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if (|typeParamsFiltered| > 0) { for i := 0 to |typeParamsFiltered| { var typeArg, rTypeParamDecl := GenTypeParam(typeParamsFiltered[i]); - // TODO: Remove default once MaybePlacebos are implemented. - rTypeParamDecl := rTypeParamDecl.(constraints := rTypeParamDecl.constraints + [R.std_type.MSel("default").MSel("Default")]); + rTypeParamDecl := rTypeParamDecl.(constraints := rTypeParamDecl.constraints); typeParams := typeParams + [rTypeParamDecl]; } } @@ -2926,7 +3228,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { earlyReturn := Some([]); for outI := 0 to |outVars| { var outVar := outVars[outI]; - var outName := escapeName(outVar.id); + var outName := escapeVar(outVar); var tracker_name := AddAssignedPrefix(outName); preAssignNames := preAssignNames + [tracker_name]; preAssignTypes := preAssignTypes[tracker_name := R.Type.Bool]; @@ -2940,7 +3242,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { for outI := 0 to |outVars| { var outVar := outVars[outI]; var outType := GenType(m.outTypes[outI], GenTypeContext.default()); - var outName := escapeName(outVar.id); + var outName := escapeVar(outVar); paramNames := paramNames + [outName]; var outMaybeType := if outType.CanReadWithoutClone() then outType else R.MaybePlaceboType(outType); paramTypes := paramTypes[outName := outMaybeType]; @@ -2993,7 +3295,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case DeclareVar(name, optType, None) => if i + 1 < |stmts| { match stmts[i + 1] { - case Assign(Ident(Ident(name2)), rhs) => + case Assign(Ident(name2), rhs) => if name2 == name { stmts := stmts[0..i] + [DeclareVar(name, optType, Some(rhs))] + stmts[i+2..]; stmt := stmts[i]; @@ -3010,7 +3312,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { match stmt { case DeclareVar(name, _, _) => { - declarations := declarations + {escapeName(name)}; + declarations := declarations + {escapeVar(name)}; } case _ => {} } @@ -3030,8 +3332,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { { newEnv := env; match lhs { - case Ident(Ident(id)) => { - var idRust := escapeName(id); + case Ident(id) => { + var idRust := escapeVar(id); if env.IsBorrowed(idRust) || env.IsBorrowedMut(idRust) { generated := R.AssignVar("*" + idRust, rhs); } else { @@ -3043,7 +3345,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } case Select(on, field) => { - var fieldName := escapeName(field); + var fieldName := escapeVar(field); var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); match onExpr { // Particular case of the constructor, we don't want the previous value to be dropped if it's assigned the first time @@ -3052,7 +3354,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { | UnaryOp("&", Identifier("this"), _) => var isAssignedVar := AddAssignedPrefix(fieldName); if isAssignedVar in newEnv.names { - generated := R.dafny_runtime.MSel(update_field_uninit_macro).Apply( + generated := R.dafny_runtime.MSel(update_field_uninit_macro).AsExpr().Apply( [ thisInConstructor, R.Identifier(fieldName), R.Identifier(isAssignedVar), @@ -3100,14 +3402,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { onExpr := onExpr.Sel("data"); } - var rhs := rhs; - if && onExpr.IsLhsIdentifier() - && var name := onExpr.LhsIdentifierName(); - && var tpe := env.GetType(name); - && tpe.Some? && tpe.value.IsUninitArray() { - rhs := R.MaybeUninitNew(rhs); - } - generated := r.Then(R.Assign(Some(R.Index(onExpr, indicesExpr)), rhs)); needsIIFE := true; } @@ -3125,25 +3419,25 @@ module {:extern "DCOMP"} DafnyToRustCompiler { newEnv := env; for i := 0 to |fields| { var field := fields[i]; - var fieldName := escapeName(field.name); + var fieldName := escapeVar(field.name); var fieldTyp := GenType(field.typ, GenTypeContext.default()); var isAssignedVar := AddAssignedPrefix(fieldName); if isAssignedVar in newEnv.names { assume {:axiom} InitializationValue(field.typ) < stmt; // Needed for termination var rhs, _, _ := GenExpr(InitializationValue(field.typ), selfIdent, env, OwnershipOwned); readIdents := readIdents + {isAssignedVar}; - generated := generated.Then(R.dafny_runtime.MSel(update_field_if_uninit_macro).Apply([ - R.Identifier("this"), R.Identifier(fieldName), R.Identifier(isAssignedVar), rhs])); + generated := generated.Then(R.dafny_runtime.MSel(update_field_if_uninit_macro).AsExpr().Apply([ + R.Identifier("this"), R.Identifier(fieldName), R.Identifier(isAssignedVar), rhs])); newEnv := newEnv.RemoveAssigned(isAssignedVar); } } } case DeclareVar(name, typ, Some(expression)) => { - var tpe := GenType(typ, GenTypeContext.InBinding()); - var varName := escapeName(name); + var tpe := GenType(typ, GenTypeContext.default()); + var varName := escapeVar(name); var hasCopySemantics := tpe.CanReadWithoutClone(); if expression.InitializationValue? && !hasCopySemantics { - generated := R.DeclareVar(R.MUT, varName, None, Some(R.dafny_runtime.MSel("MaybePlacebo").ApplyType1(tpe).MSel("new").Apply([]))); + generated := R.DeclareVar(R.MUT, varName, None, Some(R.MaybePlaceboPath.AsExpr().ApplyType1(tpe).FSel("new").Apply([]))); readIdents := {}; newEnv := env.AddAssigned(varName, R.MaybePlaceboType(tpe)); } else { @@ -3158,8 +3452,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } readIdents := recIdents; tpe := if expression.NewUninitArray? then tpe.TypeAtInitialization() else tpe; - generated := R.DeclareVar(R.MUT, escapeName(name), Some(tpe), Some(expr)); - newEnv := env.AddAssigned(escapeName(name), tpe); + generated := R.DeclareVar(R.MUT, varName, Some(tpe), Some(expr)); + newEnv := env.AddAssigned(varName, tpe); } } case DeclareVar(name, typ, None) => { @@ -3170,14 +3464,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Assign(lhs, expression) => { var exprGen, _, exprIdents := GenExpr(expression, selfIdent, env, OwnershipOwned); if lhs.Ident? { - var rustId := escapeName(lhs.ident.id); + var rustId := escapeVar(lhs.ident); var tpe := env.GetType(rustId); if tpe.Some? && tpe.value.ExtractMaybePlacebo().Some? { exprGen := R.MaybePlacebo(exprGen); } } if lhs.Index? && lhs.expr.Ident? { - var rustId := escapeName(lhs.expr.name); + var rustId := escapeVar(lhs.expr.name); var tpe := env.GetType(rustId); if tpe.Some? && tpe.value.ExtractMaybeUninitArrayElement().Some? { exprGen := R.MaybeUninitNew(exprGen); @@ -3230,7 +3524,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var boundTpe := GenType(boundType, GenTypeContext.default()); readIdents := recIdents; - var boundRName: string := escapeName(boundName); + var boundRName: string := escapeVar(boundName); var bodyExpr, bodyIdents, bodyEnv := GenStmts(body, selfIdent, env.AddAssigned(boundRName, boundTpe), false, earlyReturn); readIdents := readIdents + bodyIdents - {boundRName}; newEnv := env; @@ -3298,23 +3592,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowedMut); readIdents := readIdents + recIdents; } - generated := fullPath.ApplyType(onTypeExprs).MSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); + generated := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); case _ => // Infix call on.name(args) var onExpr, _, enclosingIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); readIdents := readIdents + enclosingIdents; - var renderedName := match name { - case CallName(name, _, _, _) => escapeName(name) - case MapBuilderAdd() | SetBuilderAdd() => "add" - case MapBuilderBuild() | SetBuilderBuild() => "build" - }; + var renderedName := GetMethodName(on, name); match on { - case Companion(_, _) => { - onExpr := onExpr.MSel(renderedName); + case Companion(_, _) | ExternCompanion(_) => { + onExpr := onExpr.FSel(renderedName); } case _ => { if onExpr != R.self { // Self has the reference type already match name { - case CallName(_, Some(tpe), _, _) => + case CallName(_, Some(tpe), _, _, _) => var typ := GenType(tpe, GenTypeContext.default()); if typ.IsObjectOrPointer() && onExpr != R.Identifier("self") { onExpr := modify_macro.Apply1(onExpr); @@ -3329,7 +3619,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } if maybeOutVars.Some? && |maybeOutVars.value| == 1 { - var outVar := escapeName(maybeOutVars.value[0].id); + var outVar := escapeVar(maybeOutVars.value[0]); if !env.CanReadWithoutClone(outVar) { generated := R.MaybePlacebo(generated); } @@ -3343,7 +3633,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // We emit assignment to each receiver depending on its type, if it could be a placebo or not. var outVars := maybeOutVars.value; for outI := 0 to |outVars| { - var outVar := escapeName(outVars[outI].id); + var outVar := escapeVar(outVars[outI]); var rhs := tmpId.Sel(Strings.OfNat(outI)); if !env.CanReadWithoutClone(outVar) { rhs := R.MaybePlacebo(rhs); @@ -3392,7 +3682,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Print(e) => { var printedExpr, recOwnership, recIdents := GenExpr(e, selfIdent, env, OwnershipBorrowed); generated := R.Identifier("print!").Apply([R.LiteralString("{}", false, false), - R.dafny_runtime.MSel("DafnyPrintWrapper").Apply1(printedExpr)]); + R.dafny_runtime.MSel("DafnyPrintWrapper").AsExpr().Apply1(printedExpr)]); readIdents := recIdents; newEnv := env; } @@ -3417,7 +3707,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { BitwiseShiftLeft() := "<<" ] - static function NewtypeToRustType(base: Type, range: NewtypeRange) + static function NewtypeRangeToRustType(range: NewtypeRange) : Option { match range { case NoRange() => None @@ -3526,9 +3816,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { match t { case Primitive(Int) => { if |i| <= 4 { - r := R.dafny_runtime.MSel("int!").Apply1(R.LiteralInt(i)); + r := R.dafny_runtime.MSel("int!").AsExpr().Apply1(R.LiteralInt(i)); } else { - r := R.dafny_runtime.MSel("int!").Apply1( + r := R.dafny_runtime.MSel("int!").AsExpr().Apply1( R.LiteralString(i, binary := true, verbatim := false)); } } @@ -3557,7 +3847,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case Literal(StringLiteral(l, verbatim)) => { - r := R.dafny_runtime.MSel(string_of).Apply1(R.LiteralString(l, binary := false, verbatim := verbatim)); + r := R.dafny_runtime.MSel(string_of).AsExpr().Apply1(R.LiteralString(l, binary := false, verbatim := verbatim)); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := {}; return; @@ -3565,7 +3855,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Literal(CharLiteralUTF16(c)) => { r := R.LiteralInt(Strings.OfNat(c)); r := R.TypeAscription(r, R.U16); - r := R.dafny_runtime.MSel(DafnyChar).Apply1(r); + r := R.dafny_runtime.MSel(DafnyChar).AsExpr().Apply1(r); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := {}; return; @@ -3577,10 +3867,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else { r := R.global.MSel("std").MSel("primitive") - .MSel("char").MSel("from_u32") + .MSel("char").FSel("from_u32") .Apply1(r).Sel("unwrap").Apply([]); } - r := R.dafny_runtime.MSel(DafnyChar).Apply1(r); + r := R.dafny_runtime.MSel(DafnyChar).AsExpr().Apply1(r); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := {}; return; @@ -3588,9 +3878,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Literal(Null(tpe)) => { var tpeGen := GenType(tpe, GenTypeContext.default()); if ObjectType.RawPointers? { - r := R.std.MSel("ptr").MSel("null"); + r := R.std.MSel("ptr").FSel("null_mut"); } else { - r := R.TypeAscription(R.dafny_runtime.MSel("Object").Apply1(R.RawExpr("None")), tpeGen); + r := R.TypeAscription(R.dafny_runtime.MSel("Object").AsExpr().Apply1(R.RawExpr("None")), tpeGen); } r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := {}; @@ -3770,19 +4060,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { { var Convert(expr, fromTpe, toTpe) := e; var UserDefined(ResolvedType(path, typeArgs, Newtype(b, range, erase), _, _, _)) := toTpe; - var nativeToType := NewtypeToRustType(b, range); + 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!").Apply([recursiveGen, R.ExprFromType(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.InBinding()); + var rhsType := GenType(toTpe, GenTypeContext.default()); r := R.RawExpr(rhsType.ToString(IND) + "(" + recursiveGen.ToString(IND) + ")"); } r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); @@ -3793,7 +4083,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { match fromTpe { case UserDefined( ResolvedType(_, _, Newtype(b0, range0, erase0), attributes0, _, _)) => { - var nativeFromType := NewtypeToRustType(b0, range0); + 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); @@ -3832,14 +4122,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var Convert(expr, fromTpe, toTpe) := e; var UserDefined( ResolvedType(_, _, Newtype(b, range, erase), attributes, _, _)) := fromTpe; - var nativeFromType := NewtypeToRustType(b, range); + 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.Identifier("Into").ApplyType([toTpeRust]).MSel("into").Apply([recursiveGen]); + r := R.std.MSel("convert").MSel("Into").AsExpr().ApplyType([toTpeRust]).FSel("into").Apply([recursiveGen]); r, resultingOwnership := FromOwned(r, expectedOwnership); case None => if erase { @@ -3855,7 +4145,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if toTpe == Primitive(Char) { var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); r, resultingOwnership := FromOwnership( - R.dafny_runtime.MSel(DafnyChar).Apply1( + R.dafny_runtime.MSel(DafnyChar).AsExpr().Apply1( R.TypeAscription(recursiveGen, DafnyCharUnderlying) ), recOwned, expectedOwnership); readIdents := recIdents; @@ -3904,12 +4194,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { function UpcastConversionLambda(fromType: Type, fromTpe: R.Type, toType: Type, toTpe: R.Type, typeParams: map<(R.Type, R.Type), R.Expr>): Result)> { if fromTpe == toTpe then - Success(R.dafny_runtime.MSel("upcast_id").ApplyType([fromTpe]).Apply([])) + Success(R.dafny_runtime.MSel("upcast_id").AsExpr().ApplyType([fromTpe]).Apply([])) else if fromTpe.IsObjectOrPointer() && toTpe.IsObjectOrPointer() then if !toTpe.ObjectOrPointerUnderlying().DynType? then Failure((fromType, fromTpe, toType, toTpe, typeParams)) else var fromTpeUnderlying := fromTpe.ObjectOrPointerUnderlying(); var toTpeUnderlying := toTpe.ObjectOrPointerUnderlying(); - Success(R.dafny_runtime.MSel(upcast).ApplyType([fromTpeUnderlying, toTpeUnderlying]).Apply([])) + Success(R.dafny_runtime.MSel(upcast).AsExpr().ApplyType([fromTpeUnderlying, toTpeUnderlying]).Apply([])) else if (fromTpe, toTpe) in typeParams then Success(typeParams[(fromTpe, toTpe)]) else if fromTpe.IsRc() && toTpe.IsRc() then @@ -3917,20 +4207,33 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if fromType.Arrow? then Success(lambda) else - Success(R.dafny_runtime.MSel("rc_coerce").Apply1(lambda)) + Success(R.dafny_runtime.MSel("rc_coerce").AsExpr().Apply1(lambda)) else if SameTypesButDifferentTypeParameters(fromType, fromTpe, toType, toTpe) then - var lambdas :- SeqResultToResultSeq(seq(|fromTpe.arguments|, i requires 0 <= i < |fromTpe.arguments| => - UpcastConversionLambda( - fromType.resolved.typeArgs[i], - fromTpe.arguments[i], - toType.resolved.typeArgs[i], - toTpe.arguments[i], - typeParams - ))); + var indices := + if fromType.UserDefined? && fromType.resolved.kind.Datatype? then + Std.Collections.Seq.Filter(i => + if 0 <= i < |fromTpe.arguments| then + (0 <= i < |fromType.resolved.kind.variances| ==> + !fromType.resolved.kind.variances[i].Nonvariant?) + else + false + , seq(|fromTpe.arguments|, i => i)) + else + seq(|fromTpe.arguments|, i => i); + var lambdas :- SeqResultToResultSeq( + seq(|indices|, j requires 0 <= j < |indices| => + var i := indices[j]; + UpcastConversionLambda( + fromType.resolved.typeArgs[i], + fromTpe.arguments[i], + toType.resolved.typeArgs[i], + toTpe.arguments[i], + typeParams + ))); Success(R.ExprFromType(fromTpe.baseName).ApplyType( seq(|fromTpe.arguments|, i requires 0 <= i < |fromTpe.arguments| => fromTpe.arguments[i]) - ).MSel("coerce").Apply( + ).FSel("coerce").Apply( lambdas )) else if && fromTpe.IsBuiltinCollection() && toTpe.IsBuiltinCollection() @@ -3941,13 +4244,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var newToType := GetBuiltinCollectionElement(toType); var coerceArg :- UpcastConversionLambda(newFromType, newFromTpe, newToType, newToTpe, typeParams); - var collectionType := R.dafny_runtime.MSel(fromTpe.baseName.name); + var collectionType := R.dafny_runtime.MSel(fromTpe.Expand().baseName.path.name); var baseType := - if fromTpe.baseName.name == "Map" then - collectionType.ApplyType([fromTpe.arguments[0], newFromTpe]) + if fromTpe.Expand().baseName.path.name == "Map" then + collectionType.AsExpr().ApplyType([fromTpe.Expand().arguments[0], newFromTpe]) else - collectionType.ApplyType([newFromTpe]); - Success(baseType.MSel("coerce").Apply1(coerceArg)) + collectionType.AsExpr().ApplyType([newFromTpe]); + Success(baseType.FSel("coerce").Apply1(coerceArg)) else if && fromTpe.DynType? && fromTpe.underlying.FnType? && toTpe.DynType? && toTpe.underlying.FnType? && fromTpe.underlying.arguments == toTpe.underlying.arguments // TODO: Support contravariance @@ -3956,11 +4259,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { && fromTpe.underlying.arguments[0].Borrowed? then var lambda :- UpcastConversionLambda(fromType.result, fromTpe.underlying.returnType, toType.result, toTpe.underlying.returnType, typeParams); - Success(R.dafny_runtime.MSel("fn1_coerce").ApplyType([ - fromTpe.underlying.arguments[0].underlying, - fromTpe.underlying.returnType, - toTpe.underlying.returnType - ]).Apply1(lambda)) + Success( + R.dafny_runtime + .MSel("fn1_coerce") + .AsExpr() + .ApplyType([ + fromTpe.underlying.arguments[0].underlying, + fromTpe.underlying.returnType, + toTpe.underlying.returnType + ]).Apply1(lambda)) else Failure((fromType, fromTpe, toType, toTpe, typeParams)) } @@ -3984,8 +4291,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { decreases e, 0, 0 { var Convert(expr, fromTpe, toTpe) := e; - var fromTpeGen := GenType(fromTpe, GenTypeContext.InBinding()); - var toTpeGen := GenType(toTpe, GenTypeContext.InBinding()); + 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; @@ -3999,7 +4306,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { assert toTpeGen.IsObjectOrPointer(); toTpeGen := toTpeGen.ObjectOrPointerUnderlying(); r := R.dafny_runtime - .MSel(downcast).Apply([recursiveGen, R.ExprFromType(toTpeGen)]); + .MSel(downcast).AsExpr().Apply([recursiveGen, R.ExprFromType(toTpeGen)]); r, resultingOwnership := FromOwnership(r, OwnershipOwned, expectedOwnership); } else { var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); @@ -4050,36 +4357,36 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := recIdents; } case (Primitive(Int), Passthrough(_)) => { - var rhsType := GenType(toTpe, GenTypeContext.InBinding()); + var rhsType := GenType(toTpe, GenTypeContext.default()); var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); r := R.RawExpr("<" + rhsType.ToString(IND) + " as ::dafny_runtime::NumCast>::from(" + recursiveGen.ToString(IND) + ").unwrap()"); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; } case (Passthrough(_), Primitive(Int)) => { - var rhsType := GenType(fromTpe, GenTypeContext.InBinding()); + var rhsType := GenType(fromTpe, GenTypeContext.default()); var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); r := R.RawExpr("::dafny_runtime::DafnyInt::new(::std::rc::Rc::new(::dafny_runtime::BigInt::from(" + recursiveGen.ToString(IND) + ")))"); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; } case (Primitive(Int), Primitive(Char)) => { - var rhsType := GenType(toTpe, GenTypeContext.InBinding()); + var rhsType := GenType(toTpe, GenTypeContext.default()); var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); r := R.RawExpr("::dafny_runtime::" + DafnyChar + "(" + (if UnicodeChars then "char::from_u32(::from(" + recursiveGen.ToString(IND) + ").unwrap())" + if UnicodeChars then ".unwrap())" else ""); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; } case (Primitive(Char), Primitive(Int)) => { - var rhsType := GenType(fromTpe, GenTypeContext.InBinding()); + var rhsType := GenType(fromTpe, GenTypeContext.default()); var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - r := R.dafny_runtime.MSel("int!").Apply1(recursiveGen.Sel("0")); + 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.InBinding()); + var toTpeGen := GenType(toTpe, GenTypeContext.default()); r := R.RawExpr("((" + recursiveGen.ToString(IND) + ") as " + toTpeGen.ToString(IND) + ")"); @@ -4138,7 +4445,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case _ => false }; if needObjectFromRef { - r := R.dafny_runtime.MSel("Object").ApplyType([R.RawType("_")]).MSel("from_ref").Apply([r]); + r := R.dafny_runtime.MSel("Object").AsExpr().ApplyType([R.RawType("_")]).FSel("from_ref").Apply([r]); } else { if !noNeedOfClone { r := r.Clone(); // We don't transfer the ownership of an identifier @@ -4189,10 +4496,18 @@ module {:extern "DCOMP"} DafnyToRustCompiler { { argExprs := []; readIdents := {}; + var signature := + if name.CallName? then + if name.receiverArg.Some? && name.receiverAsArgument then + [name.receiverArg.value] + name.signature.parameters + else + name.signature.parameters + else + []; for i := 0 to |args| { var argOwnership := OwnershipBorrowed; - if name.CallName? && i < |name.signature.parameters| { - var tpe := GenType(name.signature.parameters[i].typ, GenTypeContext.default()); + if i < |signature| { + var tpe := GenType(signature[i].typ, GenTypeContext.default()); if tpe.CanReadWithoutClone() { argOwnership := OwnershipOwned; } @@ -4212,8 +4527,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { match name { // Calls on traits should be fully specified as we can't guarantee traits will be in context // Calls on non-traits should be also fully specified if the method is not found in the definition of that type - case CallName(nameIdent, Some(UserDefined(resolvedType)), _, _) => - if resolvedType.kind.Trait? || forall m <- resolvedType.properMethods :: m.id != nameIdent { + case CallName(nameIdent, Some(UserDefined(resolvedType)), _, _, _) => + if resolvedType.kind.Trait? || forall m <- resolvedType.properMethods :: m != nameIdent { fullNameQualifier := Some(TraitTypeContainingMethod(resolvedType, nameIdent.dafny_name).GetOr(resolvedType)); } else { fullNameQualifier := None; @@ -4234,6 +4549,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + function GetMethodName(on: Expression, name: CallName): string { + match name { + case CallName(ident, _, _, _, _) => + if on.ExternCompanion? then ident.dafny_name else escapeName(ident) + case MapBuilderAdd() | SetBuilderAdd() => "add" + case MapBuilderBuild() | SetBuilderBuild() => "build" + } + } + method GenExpr( e: Expression, selfIdent: SelfInfo, @@ -4248,7 +4572,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r, resultingOwnership, readIdents := GenExprLiteral(e, selfIdent, env, expectedOwnership); case Ident(name) => { - r, resultingOwnership, readIdents := GenIdent(escapeName(name), selfIdent, env, expectedOwnership); + r, resultingOwnership, readIdents := GenIdent(escapeVar(name), selfIdent, env, expectedOwnership); + } + case ExternCompanion(path) => { + r := GenPathExpr(path, false); + + if expectedOwnership == OwnershipBorrowed { + resultingOwnership := OwnershipBorrowed; + } else if expectedOwnership == OwnershipOwned { + resultingOwnership := OwnershipOwned; + } else { + r, resultingOwnership := FromOwned(r, expectedOwnership); + } + readIdents := {}; + return; } case Companion(path, typeArgs) => { r := GenPathExpr(path); @@ -4306,7 +4643,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } r := r.ApplyType(typeExprs); } - r := r.MSel(allocate_fn); + r := r.FSel(allocate_fn); readIdents := {}; var arguments := []; @@ -4320,9 +4657,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case NewUninitArray(dims, typ) => { - /* - let _result = Array3::::placebos_usize(_n0, _n1, _n2); // NewArray generates this, array initialization; - */ if 16 < |dims| { var msg := "Unsupported: Creation of arrays of more than 16 dimensions"; if this.error.None? { @@ -4342,16 +4676,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } if |dims| > 1 { var class_name := "Array" + Strings.OfNat(|dims|); - r := R.dafny_runtime.MSel(class_name).ApplyType([typeGen]).MSel(placebos_usize).Apply(dimExprs); + r := R.dafny_runtime.MSel(class_name).AsExpr().ApplyType([typeGen]).FSel(placebos_usize).Apply(dimExprs); } else { - r := R.dafny_runtime.MSel("array").MSel(placebos_usize).ApplyType([typeGen]).Apply(dimExprs); + r := R.dafny_runtime.MSel("array").AsExpr().FSel(placebos_usize).ApplyType([typeGen]).Apply(dimExprs); } } r, resultingOwnership := FromOwned(r, expectedOwnership); } case ArrayIndexToInt(underlying) => { var recursiveGen, _, recIdents := GenExpr(underlying, selfIdent, env, OwnershipOwned); - r := R.dafny_runtime.MSel("int!").Apply1(recursiveGen); + r := R.dafny_runtime.MSel("int!").AsExpr().Apply1(recursiveGen); readIdents := recIdents; r, resultingOwnership := FromOwned(r, expectedOwnership); } @@ -4362,10 +4696,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if tpe.IsObjectOrPointer() { var t := tpe.ObjectOrPointerUnderlying(); if t.Array? { - r := R.dafny_runtime.MSel("array").MSel(array_construct).Apply1(recursiveGen); + r := R.dafny_runtime.MSel("array").AsExpr().FSel(array_construct).Apply1(recursiveGen); } else if t.IsMultiArray() { var c := t.MultiArrayClass(); - r := R.dafny_runtime.MSel(c).MSel(array_construct).Apply1(recursiveGen); + r := R.dafny_runtime.MSel(c).AsExpr().FSel(array_construct).Apply1(recursiveGen); } else { error := Some("Finalize New Array with a pointer or object type to something that is not an array or a multi array: " + tpe.ToString(IND)); r := R.RawExpr(error.value); @@ -4386,7 +4720,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if |typeArgs| > 0 { r := r.ApplyType(genTypeArgs); } - r := r.MSel(escapeName(variant)); + r := r.FSel(escapeName(variant)); readIdents := {}; var assignments: seq := []; @@ -4404,11 +4738,11 @@ module {:extern "DCOMP"} DafnyToRustCompiler { recIdents := recIdents - {next}; } var wasAssigned: string := "::dafny_runtime::LazyFieldWrapper(::dafny_runtime::Lazy::new(::std::boxed::Box::new({\n" + allReadCloned + "move || (" + recursiveGen.ToString(IND) + ")})))"; - assignments := assignments + [R.AssignIdentifier(escapeIdent(name), R.RawExpr(wasAssigned))]; + assignments := assignments + [R.AssignIdentifier(escapeVar(name), R.RawExpr(wasAssigned))]; } else { var recursiveGen, _, recIdents := GenExpr(value, selfIdent, env, OwnershipOwned); - assignments := assignments + [R.AssignIdentifier(escapeIdent(name), recursiveGen)]; + assignments := assignments + [R.AssignIdentifier(escapeVar(name), recursiveGen)]; readIdents := readIdents + recIdents; } } @@ -4447,10 +4781,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { i := i + 1; } - r := R.dafny_runtime.MSel("seq!").Apply(args); + r := R.dafny_runtime.MSel("seq!").AsExpr().Apply(args); if |args| == 0 { r := R.TypeAscription(r, - R.dafny_runtime_type.MSel("Sequence").Apply1(genTpe)); + R.dafny_runtime.MSel("Sequence").AsType().Apply1(genTpe)); } r, resultingOwnership := FromOwned(r, expectedOwnership); return; @@ -4466,7 +4800,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := readIdents + recIdents; i := i + 1; } - r := R.dafny_runtime.MSel("set!").Apply(generatedValues); + r := R.dafny_runtime.MSel("set!").AsExpr().Apply(generatedValues); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } @@ -4481,7 +4815,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := readIdents + recIdents; i := i + 1; } - r := R.dafny_runtime.MSel("multiset!").Apply(generatedValues); + r := R.dafny_runtime.MSel("multiset!").AsExpr().Apply(generatedValues); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } @@ -4514,7 +4848,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { arguments := arguments + [R.BinaryOp("=>", genKey, genValue, DAST.Format.BinaryOpFormat.NoFormat())]; i := i + 1; } - r := R.dafny_runtime.MSel("map!").Apply(arguments); + r := R.dafny_runtime.MSel("map!").AsExpr().Apply(arguments); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } @@ -4612,7 +4946,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } if !native { - r := R.dafny_runtime.MSel("int!").Apply1(r); + r := R.dafny_runtime.MSel("int!").AsExpr().Apply1(r); } } r, resultingOwnership := FromOwned(r, expectedOwnership); @@ -4620,32 +4954,72 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case MapKeys(expr) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); readIdents := recIdents; r := recursiveGen.Sel("keys").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case MapValues(expr) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); readIdents := recIdents; r := recursiveGen.Sel("values").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } - case SelectFn(on, field, isDatatype, isStatic, arity) => { + case MapItems(expr) => { + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); + readIdents := recIdents; + r := recursiveGen.Sel("items").Apply([]); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; + } + case SelectFn(on, field, isDatatype, isStatic, isConstant, arguments) => { + // Transforms a function member into a lambda var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); var s: string; var onString := onExpr.ToString(IND); if isStatic { - s := onString + "::" + escapeName(field); + // Generates |x0: &tp0, ...xn: &tpn| on::field(x0, .... xn) (possibly with some .clone()) + var lEnv := env; + var args := []; + s := "|"; + for i := 0 to |arguments| { + if i > 0 { + s := s + ", "; + } + var ty := GenType(arguments[i], GenTypeContext.default()); + var bTy := R.Borrowed(ty); + var name := "x" + Strings.OfInt(i); + lEnv := lEnv.AddAssigned(name, bTy); + + args := args + [(name, ty)]; + s := s + name + ": " + bTy.ToString(IND); + } + s := s + "| " + onString + "::" + escapeVar(field) + (if isConstant then "()" else "") + "("; + for i := 0 to |args| { + if i > 0 { + s := s + ", "; + } + var (name, ty) := args[i]; + var rIdent, _, _ := GenIdent(name, selfIdent, lEnv, if ty.CanReadWithoutClone() then OwnershipOwned else OwnershipBorrowed); + s := s + rIdent.ToString(IND); + } + s := s + ")"; } else { + // Generates + // { + // let callTarget = (on); //or (on.clone()) if it was owned. + // move |arg0, ...argn| { + // callTarget.field(arg0, .... argn) (possibly with some .clone()) + // } + // } s := "{\n"; s := s + "let callTarget = (" + onString + (if onOwned == OwnershipOwned then ")" else ").clone()") + ";\n"; var args := ""; var i := 0; - while i < arity { + while i < |arguments| { if i > 0 { args := args + ", "; } @@ -4653,14 +5027,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { i := i + 1; } s := s + "move |" + args + "| {\n"; - s := s + "callTarget." + escapeName(field) + "(" + args + ")\n"; + s := s + "callTarget." + escapeVar(field) + + (if isConstant then "()" else "") + "(" + args + ")\n"; s := s + "}\n"; s := s + "}"; } var typeShape := "dyn ::std::ops::Fn("; var i := 0; - while i < arity { + while i < |arguments| { if i > 0 { typeShape := typeShape + ", "; } @@ -4676,19 +5051,18 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := recIdents; return; } - case Select(Companion(c, typeArgs), field, isConstant, isDatatype, fieldType) => { - var onExpr, onOwned, recIdents := GenExpr(Companion(c, typeArgs), selfIdent, env, OwnershipBorrowed); + case Select(on, field, isConstant, isDatatype, fieldType) => { + if on.Companion? || on.ExternCompanion? { + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); - r := onExpr.MSel(escapeName(field)).Apply([]); + r := onExpr.FSel(escapeVar(field)).Apply([]); - r, resultingOwnership := FromOwned(r, expectedOwnership); - readIdents := recIdents; - return; - } - case Select(on, field, isConstant, isDatatype, fieldType) => { - if isDatatype { + r, resultingOwnership := FromOwned(r, expectedOwnership); + readIdents := recIdents; + return; + } else if isDatatype { var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); - r := onExpr.Sel(escapeName(field)).Apply([]); + r := onExpr.Sel(escapeVar(field)).Apply([]); 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); @@ -4702,12 +5076,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r := R.Identifier("this"); case _ => } - if this.ObjectType.RcMut? { + if ObjectType.RcMut? { r := r.Clone(); } - r := read_macro.Apply1(r); + if ObjectType.RawPointers? { + r := read_macro.Apply1(r); + } else { + r := modify_macro.Apply1(r); // Functions have to take &mut because of upcasting + } } - r := r.Sel(escapeName(field)); + r := r.Sel(escapeVar(field)); if isConstant { r := r.Apply([]); } @@ -4737,7 +5115,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { idx := R.IntoUsize(idx); r := R.SelectIndex(r, idx); readIdents := readIdents + recIdentsIdx; - } else { + } else { // Sequence, Maps var idx, idxOwned, recIdentsIdx := GenExpr(indices[i], selfIdent, env, OwnershipBorrowed); r := r.Sel("get").Apply1(idx); readIdents := readIdents + recIdentsIdx; @@ -4750,7 +5128,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case IndexRange(on, isArray, low, high) => { - var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + var onExpectedOwnership := + if isArray then + if ObjectType.RawPointers? then + OwnershipOwned + else + OwnershipBorrowed + else + OwnershipAutoBorrowed; + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, onExpectedOwnership); readIdents := recIdents; var methodName := if low.Some? then @@ -4781,10 +5167,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if methodName != "" { methodName := "_" + methodName; } - r := R.dafny_runtime_Sequence.MSel("from_array"+methodName).Apply(arguments); + var object_suffix := + if ObjectType.RawPointers? then "" else "_object"; + r := R.dafny_runtime_Sequence.FSel("from_array"+methodName+object_suffix).Apply([onExpr] + arguments); } else { if methodName != "" { r := r.Sel(methodName).Apply(arguments); + } else { + r := r.Clone(); } } r, resultingOwnership := FromOwned(r, expectedOwnership); @@ -4818,34 +5208,39 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var onExpr, recOwnership, recIdents; if base.Trait? || base.Class? { onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); - onExpr := read_macro.Apply1(onExpr); + if ObjectType.RawPointers? { + onExpr := read_macro.Apply1(onExpr); + } else { + onExpr := modify_macro.Apply1(onExpr); + } readIdents := readIdents + recIdents; } else { - onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + var expectedOnOwnership := if ObjectType.RawPointers? then OwnershipBorrowed else OwnershipBorrowedMut; + onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, expectedOnOwnership); readIdents := readIdents + recIdents; } - r := fullPath.ApplyType(onTypeExprs).MSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); + r := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); r, resultingOwnership := FromOwned(r, expectedOwnership); case _ => // Infix call on.name(args) var onExpr, _, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); readIdents := readIdents + recIdents; - var renderedName := match name { - case CallName(ident, _, _, _) => escapeName(ident) - case MapBuilderAdd | SetBuilderAdd => "add" - case MapBuilderBuild | SetBuilderBuild => "build" - }; + var renderedName := GetMethodName(on, name); // Pointers in the role of "self" must be converted to borrowed versions. match on { - case Companion(_, _) => { - onExpr := onExpr.MSel(renderedName); + case Companion(_, _) | ExternCompanion(_) => { + onExpr := onExpr.FSel(renderedName); } case _ => { if onExpr != R.self { // Self has the reference type already match name { - case CallName(_, Some(tpe), _, _) => + case CallName(_, Some(tpe), _, _, _) => var typ := GenType(tpe, GenTypeContext.default()); if typ.IsObjectOrPointer() { - onExpr := read_macro.Apply1(onExpr); + if ObjectType.RawPointers? { + onExpr := read_macro.Apply1(onExpr); + } else { + onExpr := modify_macro.Apply1(onExpr); + } } case _ => } @@ -4859,7 +5254,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } case Lambda(paramsDafny, retType, body) => { - var params := GenParams(paramsDafny); + var params := GenParams(paramsDafny, true); var paramNames := []; var paramTypesMap := map[]; for i := 0 to |params| { @@ -4890,7 +5285,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { recIdents := recIdents - {next}; } - var retTypeGen := GenType(retType, GenTypeContext.InFn()); + var retTypeGen := GenType(retType, GenTypeContext.default()); r := R.Block( allReadCloned.Then( R.RcNew( @@ -4908,7 +5303,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var paramNamesSet := {}; for i := 0 to |values| { var name := values[i].0.name; - var rName := escapeName(name); + var rName := escapeVar(name); paramNames := paramNames + [rName]; paramTypes := paramTypes[rName := paramFormals[i].tpe]; paramNamesSet := paramNamesSet + {rName}; @@ -4918,10 +5313,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r := R.RawExpr(""); for i := 0 to |values| { - var typeGen := GenType(values[i].0.typ, GenTypeContext.InFn()); + var typeGen := GenType(values[i].0.typ, GenTypeContext.default()); var valueGen, _, recIdents := GenExpr(values[i].1, selfIdent, env, OwnershipOwned); - r := r.Then(R.DeclareVar(R.CONST, escapeName(values[i].0.name), Some(typeGen), Some(valueGen))); + r := r.Then(R.DeclareVar(R.CONST, escapeVar(values[i].0.name), Some(typeGen), Some(valueGen))); readIdents := readIdents + recIdents; } @@ -4937,11 +5332,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var valueGen, _, recIdents := GenExpr(value, selfIdent, env, OwnershipOwned); readIdents := recIdents; - var valueTypeGen := GenType(tpe, GenTypeContext.InFn()); - var bodyGen, _, bodyIdents := GenExpr(iifeBody, selfIdent, env, OwnershipOwned); - readIdents := readIdents + (bodyIdents - {escapeName(name.id)}); + var valueTypeGen := GenType(tpe, GenTypeContext.default()); + var iifeVar := escapeVar(name); + var bodyGen, _, bodyIdents := + GenExpr(iifeBody, selfIdent, env.AddAssigned(iifeVar, valueTypeGen), OwnershipOwned); + readIdents := readIdents + (bodyIdents - {iifeVar}); r := R.Block( - R.DeclareVar(R.CONST, escapeName(name.id), Some(valueTypeGen), Some(valueGen)) + R.DeclareVar(R.CONST, iifeVar, Some(valueTypeGen), Some(valueGen)) .Then(bodyGen)); r, resultingOwnership := FromOwned(r, expectedOwnership); return; @@ -4962,12 +5359,27 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } case TypeTest(on, dType, variant) => { var exprGen, _, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); - var dTypePath := GenPath(dType); - r := R.Identifier("matches!").Apply([exprGen.Sel("as_ref").Apply([]), R.RawExpr(dTypePath.MSel(escapeName(variant)).ToString(IND) + "{ .. }")]); + var dTypePath := GenPathType(dType + [Ident.Ident(variant)]); + r := R.Identifier("matches!").Apply([exprGen.Sel("as_ref").Apply([]), R.RawExpr(dTypePath.ToString(IND) + "{ .. }")]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; } + case Is(expr, fromType, toType) => { + var expr, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); + var fromType := GenType(fromType, GenTypeContext.default()); + var toType := GenType(toType, GenTypeContext.default()); + if fromType.IsObjectOrPointer() && toType.IsObjectOrPointer() { + r := expr.Sel("is_instance_of").ApplyType([toType.ObjectOrPointerUnderlying()]).Apply([]); + } else { + error := Some("Source and/or target types of type test is/are not Object or Ptr"); + r := R.RawExpr(error.value); + readIdents := {}; + } + r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + readIdents := recIdents; + return; + } case BoolBoundedPool() => { r := R.RawExpr("[false, true]"); r, resultingOwnership := FromOwned(r, expectedOwnership); @@ -4985,7 +5397,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var exprGen, _, recIdents := GenExpr(of, selfIdent, env, OwnershipBorrowed); r := exprGen.Sel("iter").Apply([]); if !includeDuplicates { - r := R.dafny_runtime.MSel("itertools").MSel("Itertools").MSel("unique").Apply1(r); + r := R.dafny_runtime.MSel("itertools").MSel("Itertools").MSel("unique").AsExpr().Apply1(r); } r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; @@ -4997,13 +5409,17 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := recIdents; r, resultingOwnership := FromOwned(r, expectedOwnership); } - case IntRange(lo, hi, up) => { + case IntRange(typ, lo, hi, up) => { var lo, _, recIdentsLo := GenExpr(lo, selfIdent, env, OwnershipOwned); var hi, _, recIdentsHi := GenExpr(hi, selfIdent, env, OwnershipOwned); if up { - r := R.dafny_runtime.MSel("integer_range").Apply([lo, hi]); + r := R.dafny_runtime.MSel("integer_range").AsExpr().Apply([lo, hi]); } else { - r := R.dafny_runtime.MSel("integer_range_down").Apply([hi, lo]); + r := R.dafny_runtime.MSel("integer_range_down").AsExpr().Apply([hi, lo]); + } + if !typ.Primitive? { + var tpe := GenType(typ, GenTypeContext.default()); + r := r.Sel("map").Apply1(R.std.MSel("convert").MSel("Into").AsExpr().ApplyType([tpe]).FSel("into")); } r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdentsLo + recIdentsHi; @@ -5012,9 +5428,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case UnboundedIntRange(start, up) => { var start, _, recIdentStart := GenExpr(start, selfIdent, env, OwnershipOwned); if up { - r := R.dafny_runtime.MSel("integer_range_unbounded").Apply1(start); + r := R.dafny_runtime.MSel("integer_range_unbounded").AsExpr().Apply1(start); } else { - r := R.dafny_runtime.MSel("integer_range_down_unbounded").Apply1(start); + r := R.dafny_runtime.MSel("integer_range_down_unbounded").AsExpr().Apply1(start); } r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdentStart; @@ -5023,7 +5439,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case MapBuilder(keyType, valueType) => { var kType := GenType(keyType, GenTypeContext.default()); var vType := GenType(valueType, GenTypeContext.default()); - r := R.dafny_runtime.MSel("MapBuilder").ApplyType([kType, vType]).MSel("new").Apply([]); + r := R.dafny_runtime.MSel("MapBuilder").AsExpr().ApplyType([kType, vType]).FSel("new").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := {}; return; @@ -5031,7 +5447,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case SetBuilder(elemType) => { var eType := GenType(elemType, GenTypeContext.default()); readIdents := {}; - r := R.dafny_runtime.MSel("SetBuilder").ApplyType([eType]).MSel("new").Apply([]); + r := R.dafny_runtime.MSel("SetBuilder").AsExpr().ApplyType([eType]).FSel("new").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } @@ -5071,24 +5487,49 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - method Compile(p: seq) returns (s: string) + method Compile(p: seq, externalFiles: seq) returns (s: string) modifies this { s := "#![allow(warnings, unconditional_panic)]\n"; s := s + "#![allow(nonstandard_style)]\n"; - var i := 0; - while i < |p| { - var generated: string; - var m := GenModule(p[i], []); - generated := m.ToString(""); + var externUseDecls := []; - if i > 0 { - s := s + "\n"; + for i := 0 to |externalFiles| { + var externalFile := externalFiles[i]; + var externalMod := externalFile; + if |externalFile| > 3 && externalFile[|externalFile|-3..] == ".rs" { + externalMod := externalFile[0..|externalFile|-3]; + } else { + error := Some("Unrecognized external file " + externalFile + ". External file must be *.rs files"); } + var externMod := R.ExternMod(externalMod); + s := s + externMod.ToString("") + "\n"; + externUseDecls := externUseDecls + [ + R.UseDecl(R.Use(R.PUB, R.crate.MSel(externalMod).MSel("*"))) + ]; + } + + if externUseDecls != [] { + s := s + R.Mod(DAFNY_EXTERN_MODULE, externUseDecls).ToString("") + "\n"; + } + + var allModules := SeqMap.Empty(); + for i := 0 to |p| { + var m := GenModule(p[i], []); + allModules := GatheringModule.MergeSeqMap(allModules, m); + } + for i := 0 to |allModules.keys| { + if allModules.keys[i] !in allModules.values { // Could be avoided with subset types + continue; + } + var m := allModules.values[allModules.keys[i]].ToRust(); + for j := 0 to |optimizations| { + m := optimizations[j](m); + } + s := s + "\n"; + s := s + m.ToString(""); - s := s + generated; - i := i + 1; } } @@ -5105,4 +5546,4 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := s + "();\n}"; } } -} +} \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Rust/RustBackend.cs b/Source/DafnyCore/Backends/Rust/RustBackend.cs index 1ca408dc7f3..b6f17bcec10 100644 --- a/Source/DafnyCore/Backends/Rust/RustBackend.cs +++ b/Source/DafnyCore/Backends/Rust/RustBackend.cs @@ -37,6 +37,57 @@ protected override DafnyWrittenCodeGenerator CreateDafnyWrittenCompiler() { return new RustCodeGenerator(Options); } + // Knowing that the result of the compilation will be placed in a dafnyProgramName.rs, + // and that Dafny needs to import all the OtherFileNames into the same folder, but does not really care about their names, + // this function returns a mapping from full paths of Rust files to a unique resulting name. + // + // For example, if OtherFiles == ["C:\Users\myextern.rs", "C:\Users\path\myextern.rs", "C:\Users\nonconflictextern.rs"] and dafnyProgramName == "myextern.dfy", it will create the dictionary + // new Dictionary() { + // { "C:\Users\myextern.rs", "myextern_1.rs" }, + // { "C:\Users\path\myextern.rs", "myextern_2.rs" }, + // { "C:\Users\myotherextern.rs", "nonconflictingextern.rs" } + // } + public override Dictionary ImportFilesMapping(string dafnyProgramName) { + Dictionary importedFilesMapping = new(); + var baseName = Path.GetFileNameWithoutExtension(dafnyProgramName); + importedFilesMapping["dummy"] = baseName + ".rs"; + var keyToRemove = "dummy to lower"; + importedFilesMapping[keyToRemove] = baseName.ToLower() + ".rs"; + var toRemove = new List { "dummy", keyToRemove }; + if (OtherFileNames != null) { + foreach (var otherFileFullPath in OtherFileNames) { + var otherFileName = Path.GetFileName(otherFileFullPath); + if (importedFilesMapping.ContainsValue(otherFileName) || importedFilesMapping.ContainsValue(otherFileName.ToLower())) { + var newOtherFileBase = Path.GetFileNameWithoutExtension(otherFileName); + var i = 0; + do { + i++; + otherFileName = newOtherFileBase + $"_{i}.rs"; + } while (importedFilesMapping.ContainsValue(otherFileName) || importedFilesMapping.ContainsValue(otherFileName.ToLower())); + } + // Ensures we don't have overwrites in case-insensitive systems such as Windows + importedFilesMapping[otherFileFullPath] = otherFileName; + importedFilesMapping["to lower " + otherFileFullPath] = otherFileName.ToLower(); + toRemove.Add("to lower " + otherFileFullPath); + } + } + + foreach (var path in toRemove) { + importedFilesMapping.Remove(path); + } + return importedFilesMapping; + } + + + public override async Task OnPostGenerate(string dafnyProgramName, string targetDirectory, TextWriter outputWriter) { + foreach (var keyValue in ImportFilesMapping(dafnyProgramName)) { + var fullRustExternName = keyValue.Key; + var expectedRustName = keyValue.Value; + File.Copy(fullRustExternName, Path.Combine(targetDirectory, expectedRustName), true); + } + return await base.OnPostGenerate(dafnyProgramName, targetDirectory, outputWriter); + } + private string ComputeExeName(string targetFilename) { var targetDirectory = Path.GetDirectoryName(Path.GetDirectoryName(targetFilename)); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { diff --git a/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs b/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs index 43dbbf73816..fb83b0a1859 100644 --- a/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs @@ -13,10 +13,11 @@ public RustCodeGenerator(DafnyOptions options) { this.Options = options; } - public override ISequence Compile(Sequence program) { + public override ISequence Compile(Sequence program, Sequence> otherFiles) { var c = new DCOMP.COMP(); - c.__ctor(Options.Get(CommonOptionBag.UnicodeCharacters), ObjectType.create_RcMut()); - var s = c.Compile(program); + c.__ctor(Options.Get(CommonOptionBag.UnicodeCharacters), + Options.Get(CommonOptionBag.RawPointers) ? ObjectType.create_RawPointers() : ObjectType.create_RcMut()); + var s = c.Compile(program, otherFiles); if (!Options.Get(CommonOptionBag.EmitUncompilableCode) && c.error.is_Some) { throw new UnsupportedInvalidOperationException(c.error.dtor_value.ToVerbatimString(false)); } diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.Statement.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.Statement.cs index 7551fe9fd3d..b51afc2021e 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.Statement.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.Statement.cs @@ -180,14 +180,67 @@ protected void TrStmt(Statement stmt, ConcreteSyntaxTree wr, ConcreteSyntaxTree break; } case ExpectStmt expectStmt: { - var s = expectStmt; // TODO there's potential here to use target-language specific features such as exceptions // to make it more target-language idiomatic and improve performance - ConcreteSyntaxTree bodyWriter = EmitIf(out var guardWriter, false, wr); - var negated = new UnaryOpExpr(s.Tok, UnaryOpExpr.Opcode.Not, s.Expr); - negated.Type = Type.Bool; - EmitExpr(negated, false, guardWriter, wStmts); - EmitHalt(s.Tok, s.Message, bodyWriter); + // For now, this code prints nicely only in the Rust code generator until we make it work for every code generator + var specialExpectEqualHandling = Options.Backend.TargetId == "rs"; + if ( + specialExpectEqualHandling && + expectStmt.Expr is BinaryExpr { Op: BinaryExpr.Opcode.Eq, ResolvedOp: var resolvedOp, E0: var e0, E1: var e1 }) { + // If it finds "expect a == b", it will rewrite the code to + // var _e0 = a; + // var _e1 = b; + // if _e0 != _e1 { + // print "\nLeft:\n" + // print _e0; + // print "\nRight:\n" + // print _e1; + // + // } + var e0Name = ProtectedFreshId("_e0"); + var e1Name = ProtectedFreshId("_e1"); + var e0Var = new LocalVariable(new RangeToken(Token.NoToken, Token.NoToken), e0Name, e0.Type, false); + var e1Var = new LocalVariable(new RangeToken(Token.NoToken, Token.NoToken), e1Name, e0.Type, false); + DeclareLocalVar(IdName(e0Var), null, e0.Tok, e0, false, wr); + DeclareLocalVar(IdName(e1Var), null, e1.tok, e1, false, wr); + var e0Ident = new IdentifierExpr(e0.tok, e0Name) { + Type = e0.Type, + Var = e0Var + }; + var e1Ident = new IdentifierExpr(e1.tok, e0Name) { + Type = e1.Type, + Var = e1Var + }; + + ConcreteSyntaxTree bodyWriter = EmitIf(out var guardWriter, false, wr); + var negated = new UnaryOpExpr(expectStmt.Tok, UnaryOpExpr.Opcode.Not, + new BinaryExpr(expectStmt.Expr.tok, BinaryExpr.Opcode.Eq, + e0Ident, + e1Ident) { + ResolvedOp = resolvedOp, + Type = Type.Bool + }) { + Type = Type.Bool + }; + EmitExpr(negated, false, guardWriter, wStmts); + EmitPrintStmt(bodyWriter, new StringLiteralExpr(e0.tok, @"\nLeft:\n", false) { + Type = new SeqType(new CharType()) + }); + EmitPrintStmt(bodyWriter, e0Ident); + EmitPrintStmt(bodyWriter, new StringLiteralExpr(e1.tok, @"\nRight:\n", false) { + Type = new SeqType(new CharType()) + }); + EmitPrintStmt(bodyWriter, e1Ident); + + EmitHalt(expectStmt.Tok, expectStmt.Message, bodyWriter); + } else { + ConcreteSyntaxTree bodyWriter = EmitIf(out var guardWriter, false, wr); + var negated = new UnaryOpExpr(expectStmt.Tok, UnaryOpExpr.Opcode.Not, expectStmt.Expr) { Type = Type.Bool }; + EmitExpr(negated, false, guardWriter, wStmts); + + EmitHalt(expectStmt.Tok, expectStmt.Message, bodyWriter); + } + break; } case CallStmt callStmt: { diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 2bcef3478f0..d807b4a42fa 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -1522,6 +1522,41 @@ public void Compile(Program program, ConcreteSyntaxTree wrx) { EmitFooter(program, wrx); } + protected (bool classIsExtern, bool included) GetIsExternAndIncluded(ClassLikeDecl cl) { + var include = true; + var classIsExtern = false; + if (include) { + classIsExtern = !Options.DisallowExterns && Attributes.Contains(cl.Attributes, "extern"); + if (classIsExtern && cl.Members.TrueForAll(member => + member.IsGhost || Attributes.Contains(member.Attributes, "extern"))) { + include = false; + } + } + + return (classIsExtern, include); + } + + protected bool HasCompilationMaterial(MemberDecl memberDecl) { + return !memberDecl.IsGhost && (Options.DisallowExterns || !Attributes.Contains(memberDecl.Attributes, "extern")); + } + + protected (bool classIsExtern, bool included) GetIsExternAndIncluded(DefaultClassDecl defaultClassDecl) { + var hasCompilationMaterial = defaultClassDecl.Members.Exists(HasCompilationMaterial); + var include = hasCompilationMaterial; + var classIsExtern = false; + if (include) { + classIsExtern = + (!Options.DisallowExterns && Attributes.Contains(defaultClassDecl.Attributes, "extern")) || + Attributes.Contains(defaultClassDecl.EnclosingModuleDefinition.Attributes, "extern"); + if (classIsExtern && defaultClassDecl.Members.TrueForAll(member => + member.IsGhost || Attributes.Contains(member.Attributes, "extern"))) { + include = false; + } + } + + return (classIsExtern, include); + } + private void EmitModule(Program program, ConcreteSyntaxTree programNode, ModuleDefinition module) { if (!module.CanCompile()) { // the purpose of an abstract module is to skip compilation @@ -1548,10 +1583,10 @@ private void EmitModule(Program program, ConcreteSyntaxTree programNode, ModuleD return; } - var wr = CreateModule(module.GetCompileName(Options), module.IsDefaultModule, externModule, libraryName, programNode); - var v = new CheckHasNoAssumes_Visitor(this, wr); Contract.Assert(enclosingModule == null); enclosingModule = module; + var wr = CreateModule(module.GetCompileName(Options), module.IsDefaultModule, externModule, libraryName, programNode); + var v = new CheckHasNoAssumes_Visitor(this, wr); foreach (TopLevelDecl d in module.TopLevelDecls) { if (!ProgramResolver.ShouldCompile(d)) { continue; @@ -1626,19 +1661,7 @@ private void EmitModule(Program program, ConcreteSyntaxTree programNode, ModuleD w.Finish(); } else if (d is DefaultClassDecl defaultClassDecl) { Contract.Assert(defaultClassDecl.InheritedMembers.Count == 0); - Predicate compilationMaterial = x => - !x.IsGhost && (Options.DisallowExterns || !Attributes.Contains(x.Attributes, "extern")); - var include = defaultClassDecl.Members.Exists(compilationMaterial); - var classIsExtern = false; - if (include) { - classIsExtern = - (!Options.DisallowExterns && Attributes.Contains(defaultClassDecl.Attributes, "extern")) || - Attributes.Contains(defaultClassDecl.EnclosingModuleDefinition.Attributes, "extern"); - if (classIsExtern && defaultClassDecl.Members.TrueForAll(member => - member.IsGhost || Attributes.Contains(member.Attributes, "extern"))) { - include = false; - } - } + var (classIsExtern, include) = GetIsExternAndIncluded(defaultClassDecl); if (include) { var cw = CreateClass(IdProtect(d.EnclosingModuleDefinition.GetCompileName(Options)), @@ -1654,15 +1677,7 @@ private void EmitModule(Program program, ConcreteSyntaxTree programNode, ModuleD CompileClassMembers(program, defaultClassDecl, abyss); } } else if (d is ClassLikeDecl cl) { - var include = true; - var classIsExtern = false; - if (include) { - classIsExtern = !Options.DisallowExterns && Attributes.Contains(cl.Attributes, "extern"); - if (classIsExtern && cl.Members.TrueForAll(member => - member.IsGhost || Attributes.Contains(member.Attributes, "extern"))) { - include = false; - } - } + var (classIsExtern, include) = GetIsExternAndIncluded(cl); if (include) { var cw = CreateClass(IdProtect(d.EnclosingModuleDefinition.GetCompileName(Options)), IdName(cl), @@ -4317,6 +4332,10 @@ private static Type TypeOfRhs(AssignmentRhs rhs) { } } + protected virtual void EmitStaticExternMethodQualifier(string qual, ConcreteSyntaxTree wr) { + wr.Write(qual); + } + /// /// Emit translation of a call statement. /// The "receiverReplacement" parameter is allowed to be "null". It must be null for tail recursive calls. @@ -4448,7 +4467,8 @@ protected virtual void TrCallStmt(CallStmt s, string receiverReplacement, Concre EmitExpr(s.Receiver, false, wReceiver, wStmts); wr.Write($"){InstanceClassAccessor}"); } else if (s.Method.IsExtern(Options, out var qual, out var compileName) && qual != null) { - wr.Write("{0}{1}", qual, StaticClassAccessor); + EmitStaticExternMethodQualifier(qual, wr); + wr.Write("{0}", StaticClassAccessor); protectedName = compileName; } else { EmitTypeName_Companion(s.Receiver.Type, wr, wr, s.Tok, s.Method); @@ -5035,7 +5055,7 @@ protected virtual ConcreteSyntaxTree EmitCallToIsMethod(RedirectingTypeDecl decl return wrArguments; } - protected ConcreteSyntaxTree MaybeEmitCallToIsMethod(RedirectingTypeDecl declWithConstraints, List typeArguments, ConcreteSyntaxTree wr) { + protected virtual ConcreteSyntaxTree MaybeEmitCallToIsMethod(RedirectingTypeDecl declWithConstraints, List typeArguments, ConcreteSyntaxTree wr) { Contract.Requires(declWithConstraints is SubsetTypeDecl or NewtypeDecl); Contract.Requires(declWithConstraints.TypeArgs.Count == typeArguments.Count); Contract.Requires(declWithConstraints.ConstraintIsCompilable); @@ -5221,7 +5241,8 @@ protected virtual void CompileFunctionCallExpr(FunctionCallExpr e, ConcreteSynta string qual = ""; string compileName = ""; if (f.IsExtern(Options, out qual, out compileName) && qual != null) { - wr.Write("{0}{1}", qual, ModuleSeparator); + EmitStaticExternMethodQualifier(qual, wr); + wr.Write("{1}", qual, ModuleSeparator); } else if (f.IsStatic || customReceiver) { wr.Write("{0}{1}", TypeName_Companion(e.Receiver.Type, wr, e.tok, f), StaticClassAccessor); compileName = customReceiver ? CompanionMemberIdName(f) : IdName(f); diff --git a/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py b/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py index f3d2fb0c4d6..5fb5b857544 100644 --- a/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py +++ b/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py @@ -57,7 +57,7 @@ # If the name of the namespace ends with "coverage", we move this test # to ../DafnyCore.Test/{output}/.... file_path_prefix = "" - if namespace_name.endswith("Coverage"): + if namespace_name.endswith("Coverage") or namespace_name.endswith("Test"): file_path_prefix = test_output # Write content to a file diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 57d24f8460a..395c24dc48f 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -66,35 +66,90 @@ public Dafny.ISequence dtor_dafny__name { } } + public interface _IVarName { + bool is_VarName { get; } + Dafny.ISequence dtor_dafny__name { get; } + } + public class VarName : _IVarName { + public readonly Dafny.ISequence _dafny__name; + public VarName(Dafny.ISequence dafny__name) { + this._dafny__name = dafny__name; + } + public static Dafny.ISequence DowncastClone(Dafny.ISequence _this) { + return _this; + } + public override bool Equals(object other) { + var oth = other as DAST.VarName; + return oth != null && object.Equals(this._dafny__name, oth._dafny__name); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._dafny__name)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.VarName.VarName"; + s += "("; + s += this._dafny__name.ToVerbatimString(true); + s += ")"; + return s; + } + private static readonly Dafny.ISequence theDefault = Dafny.Sequence.Empty; + public static Dafny.ISequence Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor> _TYPE = new Dafny.TypeDescriptor>(Dafny.Sequence.Empty); + public static Dafny.TypeDescriptor> _TypeDescriptor() { + return _TYPE; + } + public static _IVarName create(Dafny.ISequence dafny__name) { + return new VarName(dafny__name); + } + public static _IVarName create_VarName(Dafny.ISequence dafny__name) { + return create(dafny__name); + } + public bool is_VarName { get { return true; } } + public Dafny.ISequence dtor_dafny__name { + get { + return this._dafny__name; + } + } + } + public interface _IModule { bool is_Module { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_attributes { get; } + bool dtor_requiresExterns { get; } Std.Wrappers._IOption> dtor_body { get; } _IModule DowncastClone(); } public class Module : _IModule { public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _attributes; + public readonly bool _requiresExterns; public readonly Std.Wrappers._IOption> _body; - public Module(Dafny.ISequence name, Dafny.ISequence attributes, Std.Wrappers._IOption> body) { + public Module(Dafny.ISequence name, Dafny.ISequence attributes, bool requiresExterns, Std.Wrappers._IOption> body) { this._name = name; this._attributes = attributes; + this._requiresExterns = requiresExterns; this._body = body; } public _IModule DowncastClone() { if (this is _IModule dt) { return dt; } - return new Module(_name, _attributes, _body); + return new Module(_name, _attributes, _requiresExterns, _body); } public override bool Equals(object other) { var oth = other as DAST.Module; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._body, oth._body); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._attributes, oth._attributes) && this._requiresExterns == oth._requiresExterns && object.Equals(this._body, oth._body); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._requiresExterns)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); return (int) hash; } @@ -105,11 +160,13 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; + s += Dafny.Helpers.ToString(this._requiresExterns); + s += ", "; s += Dafny.Helpers.ToString(this._body); s += ")"; return s; } - private static readonly DAST._IModule theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option>.Default()); + private static readonly DAST._IModule theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, Std.Wrappers.Option>.Default()); public static DAST._IModule Default() { return theDefault; } @@ -117,11 +174,11 @@ public static DAST._IModule Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IModule create(Dafny.ISequence name, Dafny.ISequence attributes, Std.Wrappers._IOption> body) { - return new Module(name, attributes, body); + public static _IModule create(Dafny.ISequence name, Dafny.ISequence attributes, bool requiresExterns, Std.Wrappers._IOption> body) { + return new Module(name, attributes, requiresExterns, body); } - public static _IModule create_Module(Dafny.ISequence name, Dafny.ISequence attributes, Std.Wrappers._IOption> body) { - return create(name, attributes, body); + public static _IModule create_Module(Dafny.ISequence name, Dafny.ISequence attributes, bool requiresExterns, Std.Wrappers._IOption> body) { + return create(name, attributes, requiresExterns, body); } public bool is_Module { get { return true; } } public Dafny.ISequence dtor_name { @@ -134,6 +191,11 @@ public Dafny.ISequence dtor_attributes { return this._attributes; } } + public bool dtor_requiresExterns { + get { + return this._requiresExterns; + } + } public Std.Wrappers._IOption> dtor_body { get { return this._body; @@ -155,6 +217,8 @@ public interface _IModuleItem { DAST._ISynonymType dtor_SynonymType_a0 { get; } DAST._IDatatype dtor_Datatype_a0 { get; } _IModuleItem DowncastClone(); + Dafny.ISequence name(); + Dafny.ISequence attributes(); } public abstract class ModuleItem : _IModuleItem { public ModuleItem() { @@ -228,6 +292,80 @@ public DAST._IDatatype dtor_Datatype_a0 { } } public abstract _IModuleItem DowncastClone(); + public Dafny.ISequence name() { + DAST._IModuleItem _source0 = this; + { + if (_source0.is_Module) { + DAST._IModule _0_m = _source0.dtor_Module_a0; + return (_0_m).dtor_name; + } + } + { + if (_source0.is_Class) { + DAST._IClass _1_m = _source0.dtor_Class_a0; + return (_1_m).dtor_name; + } + } + { + if (_source0.is_Trait) { + DAST._ITrait _2_m = _source0.dtor_Trait_a0; + return (_2_m).dtor_name; + } + } + { + if (_source0.is_Newtype) { + DAST._INewtype _3_m = _source0.dtor_Newtype_a0; + return (_3_m).dtor_name; + } + } + { + if (_source0.is_SynonymType) { + DAST._ISynonymType _4_m = _source0.dtor_SynonymType_a0; + return (_4_m).dtor_name; + } + } + { + DAST._IDatatype _5_m = _source0.dtor_Datatype_a0; + return (_5_m).dtor_name; + } + } + public Dafny.ISequence attributes() { + DAST._IModuleItem _source0 = this; + { + if (_source0.is_Module) { + DAST._IModule _0_m = _source0.dtor_Module_a0; + return (_0_m).dtor_attributes; + } + } + { + if (_source0.is_Class) { + DAST._IClass _1_m = _source0.dtor_Class_a0; + return (_1_m).dtor_attributes; + } + } + { + if (_source0.is_Trait) { + DAST._ITrait _2_m = _source0.dtor_Trait_a0; + return (_2_m).dtor_attributes; + } + } + { + if (_source0.is_Newtype) { + DAST._INewtype _3_m = _source0.dtor_Newtype_a0; + return (_3_m).dtor_attributes; + } + } + { + if (_source0.is_SynonymType) { + DAST._ISynonymType _4_m = _source0.dtor_SynonymType_a0; + return (_4_m).dtor_attributes; + } + } + { + DAST._IDatatype _5_m = _source0.dtor_Datatype_a0; + return (_5_m).dtor_attributes; + } + } } public class ModuleItem_Module : ModuleItem { public readonly DAST._IModule _a0; @@ -3556,14 +3694,15 @@ public interface _ICallName { bool is_SetBuilderBuild { get; } Dafny.ISequence dtor_name { get; } Std.Wrappers._IOption dtor_onType { get; } - Std.Wrappers._IOption dtor_receiverArgs { get; } + Std.Wrappers._IOption dtor_receiverArg { get; } + bool dtor_receiverAsArgument { get; } Dafny.ISequence dtor_signature { get; } _ICallName DowncastClone(); } public abstract class CallName : _ICallName { public CallName() { } - private static readonly DAST._ICallName theDefault = create_CallName(Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Std.Wrappers.Option.Default(), Dafny.Sequence.Empty); + private static readonly DAST._ICallName theDefault = create_CallName(Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Std.Wrappers.Option.Default(), false, Dafny.Sequence.Empty); public static DAST._ICallName Default() { return theDefault; } @@ -3571,8 +3710,8 @@ public static DAST._ICallName Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ICallName create_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArgs, Dafny.ISequence signature) { - return new CallName_CallName(name, onType, receiverArgs, signature); + public static _ICallName create_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, Dafny.ISequence signature) { + return new CallName_CallName(name, onType, receiverArg, receiverAsArgument, signature); } public static _ICallName create_MapBuilderAdd() { return new CallName_MapBuilderAdd(); @@ -3603,10 +3742,16 @@ public Std.Wrappers._IOption dtor_onType { return ((CallName_CallName)d)._onType; } } - public Std.Wrappers._IOption dtor_receiverArgs { + public Std.Wrappers._IOption dtor_receiverArg { + get { + var d = this; + return ((CallName_CallName)d)._receiverArg; + } + } + public bool dtor_receiverAsArgument { get { var d = this; - return ((CallName_CallName)d)._receiverArgs; + return ((CallName_CallName)d)._receiverAsArgument; } } public Dafny.ISequence dtor_signature { @@ -3620,28 +3765,31 @@ public Dafny.ISequence dtor_signature { public class CallName_CallName : CallName { public readonly Dafny.ISequence _name; public readonly Std.Wrappers._IOption _onType; - public readonly Std.Wrappers._IOption _receiverArgs; + public readonly Std.Wrappers._IOption _receiverArg; + public readonly bool _receiverAsArgument; public readonly Dafny.ISequence _signature; - public CallName_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArgs, Dafny.ISequence signature) : base() { + public CallName_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, Dafny.ISequence signature) : base() { this._name = name; this._onType = onType; - this._receiverArgs = receiverArgs; + this._receiverArg = receiverArg; + this._receiverAsArgument = receiverAsArgument; this._signature = signature; } public override _ICallName DowncastClone() { if (this is _ICallName dt) { return dt; } - return new CallName_CallName(_name, _onType, _receiverArgs, _signature); + return new CallName_CallName(_name, _onType, _receiverArg, _receiverAsArgument, _signature); } public override bool Equals(object other) { var oth = other as DAST.CallName_CallName; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._onType, oth._onType) && object.Equals(this._receiverArgs, oth._receiverArgs) && object.Equals(this._signature, oth._signature); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._onType, oth._onType) && object.Equals(this._receiverArg, oth._receiverArg) && this._receiverAsArgument == oth._receiverAsArgument && object.Equals(this._signature, oth._signature); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._onType)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._receiverArgs)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._receiverArg)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._receiverAsArgument)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._signature)); return (int) hash; } @@ -3652,7 +3800,9 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._onType); s += ", "; - s += Dafny.Helpers.ToString(this._receiverArgs); + s += Dafny.Helpers.ToString(this._receiverArg); + s += ", "; + s += Dafny.Helpers.ToString(this._receiverAsArgument); s += ", "; s += Dafny.Helpers.ToString(this._signature); s += ")"; @@ -5688,6 +5838,7 @@ public interface _IExpression { bool is_Literal { get; } bool is_Ident { get; } bool is_Companion { get; } + bool is_ExternCompanion { get; } bool is_Tuple { get; } bool is_New { get; } bool is_NewUninitArray { get; } @@ -5712,6 +5863,7 @@ public interface _IExpression { bool is_ArrayLen { get; } bool is_MapKeys { get; } bool is_MapValues { get; } + bool is_MapItems { get; } bool is_Select { get; } bool is_SelectFn { get; } bool is_Index { get; } @@ -5723,6 +5875,7 @@ public interface _IExpression { bool is_IIFE { get; } bool is_Apply { get; } bool is_TypeTest { get; } + bool is_Is { get; } bool is_InitializationValue { get; } bool is_BoolBoundedPool { get; } bool is_SetBoundedPool { get; } @@ -5735,6 +5888,7 @@ public interface _IExpression { Dafny.ISequence dtor_name { get; } Dafny.ISequence> dtor_Companion_a0 { get; } Dafny.ISequence dtor_typeArgs { get; } + Dafny.ISequence> dtor_ExternCompanion_a0 { get; } Dafny.ISequence dtor_Tuple_a0 { get; } Dafny.ISequence> dtor_path { get; } Dafny.ISequence dtor_args { get; } @@ -5773,7 +5927,7 @@ public interface _IExpression { bool dtor_onDatatype { get; } DAST._IType dtor_fieldType { get; } bool dtor_isStatic { get; } - BigInteger dtor_arity { get; } + Dafny.ISequence dtor_arguments { get; } DAST._ICollKind dtor_collKind { get; } Dafny.ISequence dtor_indices { get; } bool dtor_isArray { get; } @@ -5789,6 +5943,8 @@ public interface _IExpression { Dafny.ISequence dtor_ident { get; } DAST._IExpression dtor_iifeBody { get; } Dafny.ISequence> dtor_dType { get; } + DAST._IType dtor_fromType { get; } + DAST._IType dtor_toType { get; } DAST._IExpression dtor_of { get; } bool dtor_includeDuplicates { get; } DAST._IExpression dtor_lo { get; } @@ -5820,6 +5976,9 @@ public static _IExpression create_Ident(Dafny.ISequence name) { public static _IExpression create_Companion(Dafny.ISequence> _a0, Dafny.ISequence typeArgs) { return new Expression_Companion(_a0, typeArgs); } + public static _IExpression create_ExternCompanion(Dafny.ISequence> _a0) { + return new Expression_ExternCompanion(_a0); + } public static _IExpression create_Tuple(Dafny.ISequence _a0) { return new Expression_Tuple(_a0); } @@ -5892,11 +6051,14 @@ public static _IExpression create_MapKeys(DAST._IExpression expr) { public static _IExpression create_MapValues(DAST._IExpression expr) { return new Expression_MapValues(expr); } + public static _IExpression create_MapItems(DAST._IExpression expr) { + return new Expression_MapItems(expr); + } public static _IExpression create_Select(DAST._IExpression expr, Dafny.ISequence field, bool isConstant, bool onDatatype, DAST._IType fieldType) { return new Expression_Select(expr, field, isConstant, onDatatype, fieldType); } - public static _IExpression create_SelectFn(DAST._IExpression expr, Dafny.ISequence field, bool onDatatype, bool isStatic, BigInteger arity) { - return new Expression_SelectFn(expr, field, onDatatype, isStatic, arity); + public static _IExpression create_SelectFn(DAST._IExpression expr, Dafny.ISequence field, bool onDatatype, bool isStatic, bool isConstant, Dafny.ISequence arguments) { + return new Expression_SelectFn(expr, field, onDatatype, isStatic, isConstant, arguments); } public static _IExpression create_Index(DAST._IExpression expr, DAST._ICollKind collKind, Dafny.ISequence indices) { return new Expression_Index(expr, collKind, indices); @@ -5925,6 +6087,9 @@ public static _IExpression create_Apply(DAST._IExpression expr, Dafny.ISequence< public static _IExpression create_TypeTest(DAST._IExpression @on, Dafny.ISequence> dType, Dafny.ISequence variant) { return new Expression_TypeTest(@on, dType, variant); } + public static _IExpression create_Is(DAST._IExpression expr, DAST._IType fromType, DAST._IType toType) { + return new Expression_Is(expr, fromType, toType); + } public static _IExpression create_InitializationValue(DAST._IType typ) { return new Expression_InitializationValue(typ); } @@ -5940,8 +6105,8 @@ public static _IExpression create_MapBoundedPool(DAST._IExpression of) { public static _IExpression create_SeqBoundedPool(DAST._IExpression of, bool includeDuplicates) { return new Expression_SeqBoundedPool(of, includeDuplicates); } - public static _IExpression create_IntRange(DAST._IExpression lo, DAST._IExpression hi, bool up) { - return new Expression_IntRange(lo, hi, up); + public static _IExpression create_IntRange(DAST._IType elemType, DAST._IExpression lo, DAST._IExpression hi, bool up) { + return new Expression_IntRange(elemType, lo, hi, up); } public static _IExpression create_UnboundedIntRange(DAST._IExpression start, bool up) { return new Expression_UnboundedIntRange(start, up); @@ -5952,6 +6117,7 @@ public static _IExpression create_Quantifier(DAST._IType elemType, DAST._IExpres public bool is_Literal { get { return this is Expression_Literal; } } public bool is_Ident { get { return this is Expression_Ident; } } public bool is_Companion { get { return this is Expression_Companion; } } + public bool is_ExternCompanion { get { return this is Expression_ExternCompanion; } } public bool is_Tuple { get { return this is Expression_Tuple; } } public bool is_New { get { return this is Expression_New; } } public bool is_NewUninitArray { get { return this is Expression_NewUninitArray; } } @@ -5976,6 +6142,7 @@ public static _IExpression create_Quantifier(DAST._IType elemType, DAST._IExpres public bool is_ArrayLen { get { return this is Expression_ArrayLen; } } public bool is_MapKeys { get { return this is Expression_MapKeys; } } public bool is_MapValues { get { return this is Expression_MapValues; } } + public bool is_MapItems { get { return this is Expression_MapItems; } } public bool is_Select { get { return this is Expression_Select; } } public bool is_SelectFn { get { return this is Expression_SelectFn; } } public bool is_Index { get { return this is Expression_Index; } } @@ -5987,6 +6154,7 @@ public static _IExpression create_Quantifier(DAST._IType elemType, DAST._IExpres public bool is_IIFE { get { return this is Expression_IIFE; } } public bool is_Apply { get { return this is Expression_Apply; } } public bool is_TypeTest { get { return this is Expression_TypeTest; } } + public bool is_Is { get { return this is Expression_Is; } } public bool is_InitializationValue { get { return this is Expression_InitializationValue; } } public bool is_BoolBoundedPool { get { return this is Expression_BoolBoundedPool; } } public bool is_SetBoundedPool { get { return this is Expression_SetBoundedPool; } } @@ -6022,6 +6190,12 @@ public Dafny.ISequence dtor_typeArgs { return ((Expression_Call)d)._typeArgs; } } + public Dafny.ISequence> dtor_ExternCompanion_a0 { + get { + var d = this; + return ((Expression_ExternCompanion)d)._a0; + } + } public Dafny.ISequence dtor_Tuple_a0 { get { var d = this; @@ -6148,13 +6322,15 @@ public DAST._IExpression dtor_expr { if (d is Expression_ArrayLen) { return ((Expression_ArrayLen)d)._expr; } if (d is Expression_MapKeys) { return ((Expression_MapKeys)d)._expr; } if (d is Expression_MapValues) { return ((Expression_MapValues)d)._expr; } + if (d is Expression_MapItems) { return ((Expression_MapItems)d)._expr; } if (d is Expression_Select) { return ((Expression_Select)d)._expr; } if (d is Expression_SelectFn) { return ((Expression_SelectFn)d)._expr; } if (d is Expression_Index) { return ((Expression_Index)d)._expr; } if (d is Expression_IndexRange) { return ((Expression_IndexRange)d)._expr; } if (d is Expression_TupleSelect) { return ((Expression_TupleSelect)d)._expr; } if (d is Expression_BetaRedex) { return ((Expression_BetaRedex)d)._expr; } - return ((Expression_Apply)d)._expr; + if (d is Expression_Apply) { return ((Expression_Apply)d)._expr; } + return ((Expression_Is)d)._expr; } } public DAST._IExpression dtor_indexExpr { @@ -6168,6 +6344,7 @@ public DAST._IType dtor_elemType { get { var d = this; if (d is Expression_SetBuilder) { return ((Expression_SetBuilder)d)._elemType; } + if (d is Expression_IntRange) { return ((Expression_IntRange)d)._elemType; } return ((Expression_Quantifier)d)._elemType; } } @@ -6259,7 +6436,8 @@ public Dafny.ISequence dtor_field { public bool dtor_isConstant { get { var d = this; - return ((Expression_Select)d)._isConstant; + if (d is Expression_Select) { return ((Expression_Select)d)._isConstant; } + return ((Expression_SelectFn)d)._isConstant; } } public bool dtor_onDatatype { @@ -6282,10 +6460,10 @@ public bool dtor_isStatic { return ((Expression_SelectFn)d)._isStatic; } } - public BigInteger dtor_arity { + public Dafny.ISequence dtor_arguments { get { var d = this; - return ((Expression_SelectFn)d)._arity; + return ((Expression_SelectFn)d)._arguments; } } public DAST._ICollKind dtor_collKind { @@ -6380,6 +6558,18 @@ public Dafny.ISequence> dtor_dType { return ((Expression_TypeTest)d)._dType; } } + public DAST._IType dtor_fromType { + get { + var d = this; + return ((Expression_Is)d)._fromType; + } + } + public DAST._IType dtor_toType { + get { + var d = this; + return ((Expression_Is)d)._toType; + } + } public DAST._IExpression dtor_of { get { var d = this; @@ -6525,6 +6715,33 @@ public override string ToString() { return s; } } + public class Expression_ExternCompanion : Expression { + public readonly Dafny.ISequence> _a0; + public Expression_ExternCompanion(Dafny.ISequence> _a0) : base() { + this._a0 = _a0; + } + public override _IExpression DowncastClone() { + if (this is _IExpression dt) { return dt; } + return new Expression_ExternCompanion(_a0); + } + public override bool Equals(object other) { + var oth = other as DAST.Expression_ExternCompanion; + return oth != null && object.Equals(this._a0, oth._a0); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._a0)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.Expression.ExternCompanion"; + s += "("; + s += Dafny.Helpers.ToString(this._a0); + s += ")"; + return s; + } + } public class Expression_Tuple : Expression { public readonly Dafny.ISequence _a0; public Expression_Tuple(Dafny.ISequence _a0) : base() { @@ -6540,7 +6757,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._a0)); return (int) hash; } @@ -6571,7 +6788,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 4; + hash = ((hash << 5) + hash) + 5; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._path)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeArgs)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._args)); @@ -6606,7 +6823,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 5; + hash = ((hash << 5) + hash) + 6; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._dims)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typ)); return (int) hash; @@ -6636,7 +6853,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 6; + hash = ((hash << 5) + hash) + 7; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); return (int) hash; } @@ -6665,7 +6882,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 7; + hash = ((hash << 5) + hash) + 8; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typ)); return (int) hash; @@ -6703,7 +6920,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 8; + hash = ((hash << 5) + hash) + 9; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._datatypeType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeArgs)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._variant)); @@ -6746,7 +6963,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 9; + hash = ((hash << 5) + hash) + 10; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._from)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typ)); @@ -6781,7 +6998,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 10; + hash = ((hash << 5) + hash) + 11; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._length)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._elem)); return (int) hash; @@ -6813,7 +7030,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 11; + hash = ((hash << 5) + hash) + 12; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._elements)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typ)); return (int) hash; @@ -6843,7 +7060,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 12; + hash = ((hash << 5) + hash) + 13; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._elements)); return (int) hash; } @@ -6870,7 +7087,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 13; + hash = ((hash << 5) + hash) + 14; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._elements)); return (int) hash; } @@ -6897,7 +7114,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 14; + hash = ((hash << 5) + hash) + 15; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._mapElems)); return (int) hash; } @@ -6926,7 +7143,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 15; + hash = ((hash << 5) + hash) + 16; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._keyType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._valueType)); return (int) hash; @@ -6960,7 +7177,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 16; + hash = ((hash << 5) + hash) + 17; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._indexExpr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); @@ -6997,7 +7214,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 17; + hash = ((hash << 5) + hash) + 18; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._indexExpr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); @@ -7030,7 +7247,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 18; + hash = ((hash << 5) + hash) + 19; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._elemType)); return (int) hash; } @@ -7057,7 +7274,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 19; + hash = ((hash << 5) + hash) + 20; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._a0)); return (int) hash; } @@ -7082,7 +7299,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 20; + hash = ((hash << 5) + hash) + 21; return (int) hash; } public override string ToString() { @@ -7109,7 +7326,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 21; + hash = ((hash << 5) + hash) + 22; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._cond)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._thn)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._els)); @@ -7146,7 +7363,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 22; + hash = ((hash << 5) + hash) + 23; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._unOp)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._format1)); @@ -7185,7 +7402,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 23; + hash = ((hash << 5) + hash) + 24; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._op)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._left)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._right)); @@ -7227,7 +7444,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 24; + hash = ((hash << 5) + hash) + 25; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._exprType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._dim)); @@ -7263,7 +7480,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 25; + hash = ((hash << 5) + hash) + 26; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); return (int) hash; } @@ -7290,7 +7507,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 26; + hash = ((hash << 5) + hash) + 27; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); return (int) hash; } @@ -7302,6 +7519,33 @@ public override string ToString() { return s; } } + public class Expression_MapItems : Expression { + public readonly DAST._IExpression _expr; + public Expression_MapItems(DAST._IExpression expr) : base() { + this._expr = expr; + } + public override _IExpression DowncastClone() { + if (this is _IExpression dt) { return dt; } + return new Expression_MapItems(_expr); + } + public override bool Equals(object other) { + var oth = other as DAST.Expression_MapItems; + return oth != null && object.Equals(this._expr, oth._expr); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 28; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.Expression.MapItems"; + s += "("; + s += Dafny.Helpers.ToString(this._expr); + s += ")"; + return s; + } + } public class Expression_Select : Expression { public readonly DAST._IExpression _expr; public readonly Dafny.ISequence _field; @@ -7325,7 +7569,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 27; + hash = ((hash << 5) + hash) + 29; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._field)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isConstant)); @@ -7354,30 +7598,33 @@ public class Expression_SelectFn : Expression { public readonly Dafny.ISequence _field; public readonly bool _onDatatype; public readonly bool _isStatic; - public readonly BigInteger _arity; - public Expression_SelectFn(DAST._IExpression expr, Dafny.ISequence field, bool onDatatype, bool isStatic, BigInteger arity) : base() { + public readonly bool _isConstant; + public readonly Dafny.ISequence _arguments; + public Expression_SelectFn(DAST._IExpression expr, Dafny.ISequence field, bool onDatatype, bool isStatic, bool isConstant, Dafny.ISequence arguments) : base() { this._expr = expr; this._field = field; this._onDatatype = onDatatype; this._isStatic = isStatic; - this._arity = arity; + this._isConstant = isConstant; + this._arguments = arguments; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_SelectFn(_expr, _field, _onDatatype, _isStatic, _arity); + return new Expression_SelectFn(_expr, _field, _onDatatype, _isStatic, _isConstant, _arguments); } public override bool Equals(object other) { var oth = other as DAST.Expression_SelectFn; - return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._field, oth._field) && this._onDatatype == oth._onDatatype && this._isStatic == oth._isStatic && this._arity == oth._arity; + return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._field, oth._field) && this._onDatatype == oth._onDatatype && this._isStatic == oth._isStatic && this._isConstant == oth._isConstant && object.Equals(this._arguments, oth._arguments); } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 28; + hash = ((hash << 5) + hash) + 30; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._field)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._onDatatype)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isStatic)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._arity)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isConstant)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._arguments)); return (int) hash; } public override string ToString() { @@ -7391,7 +7638,9 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._isStatic); s += ", "; - s += Dafny.Helpers.ToString(this._arity); + s += Dafny.Helpers.ToString(this._isConstant); + s += ", "; + s += Dafny.Helpers.ToString(this._arguments); s += ")"; return s; } @@ -7415,7 +7664,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 29; + hash = ((hash << 5) + hash) + 31; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._collKind)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._indices)); @@ -7454,7 +7703,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 30; + hash = ((hash << 5) + hash) + 32; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isArray)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._low)); @@ -7494,7 +7743,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 31; + hash = ((hash << 5) + hash) + 33; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._index)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fieldType)); @@ -7533,7 +7782,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 32; + hash = ((hash << 5) + hash) + 34; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._on)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._callName)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeArgs)); @@ -7573,7 +7822,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 33; + hash = ((hash << 5) + hash) + 35; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._params)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._retType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); @@ -7610,7 +7859,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 34; + hash = ((hash << 5) + hash) + 36; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._values)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._retType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); @@ -7649,7 +7898,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 35; + hash = ((hash << 5) + hash) + 37; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._ident)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typ)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); @@ -7687,7 +7936,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 36; + hash = ((hash << 5) + hash) + 38; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._args)); return (int) hash; @@ -7721,7 +7970,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 37; + hash = ((hash << 5) + hash) + 39; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._on)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._dType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._variant)); @@ -7739,6 +7988,43 @@ public override string ToString() { return s; } } + public class Expression_Is : Expression { + public readonly DAST._IExpression _expr; + public readonly DAST._IType _fromType; + public readonly DAST._IType _toType; + public Expression_Is(DAST._IExpression expr, DAST._IType fromType, DAST._IType toType) : base() { + this._expr = expr; + this._fromType = fromType; + this._toType = toType; + } + public override _IExpression DowncastClone() { + if (this is _IExpression dt) { return dt; } + return new Expression_Is(_expr, _fromType, _toType); + } + public override bool Equals(object other) { + var oth = other as DAST.Expression_Is; + return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._fromType, oth._fromType) && object.Equals(this._toType, oth._toType); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 40; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fromType)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._toType)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.Expression.Is"; + s += "("; + s += Dafny.Helpers.ToString(this._expr); + s += ", "; + s += Dafny.Helpers.ToString(this._fromType); + s += ", "; + s += Dafny.Helpers.ToString(this._toType); + s += ")"; + return s; + } + } public class Expression_InitializationValue : Expression { public readonly DAST._IType _typ; public Expression_InitializationValue(DAST._IType typ) : base() { @@ -7754,7 +8040,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 38; + hash = ((hash << 5) + hash) + 41; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typ)); return (int) hash; } @@ -7779,7 +8065,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 39; + hash = ((hash << 5) + hash) + 42; return (int) hash; } public override string ToString() { @@ -7802,7 +8088,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 40; + hash = ((hash << 5) + hash) + 43; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._of)); return (int) hash; } @@ -7829,7 +8115,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 41; + hash = ((hash << 5) + hash) + 44; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._of)); return (int) hash; } @@ -7858,7 +8144,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 42; + hash = ((hash << 5) + hash) + 45; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._of)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._includeDuplicates)); return (int) hash; @@ -7874,25 +8160,28 @@ public override string ToString() { } } public class Expression_IntRange : Expression { + public readonly DAST._IType _elemType; public readonly DAST._IExpression _lo; public readonly DAST._IExpression _hi; public readonly bool _up; - public Expression_IntRange(DAST._IExpression lo, DAST._IExpression hi, bool up) : base() { + public Expression_IntRange(DAST._IType elemType, DAST._IExpression lo, DAST._IExpression hi, bool up) : base() { + this._elemType = elemType; this._lo = lo; this._hi = hi; this._up = up; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_IntRange(_lo, _hi, _up); + return new Expression_IntRange(_elemType, _lo, _hi, _up); } public override bool Equals(object other) { var oth = other as DAST.Expression_IntRange; - return oth != null && object.Equals(this._lo, oth._lo) && object.Equals(this._hi, oth._hi) && this._up == oth._up; + return oth != null && object.Equals(this._elemType, oth._elemType) && object.Equals(this._lo, oth._lo) && object.Equals(this._hi, oth._hi) && this._up == oth._up; } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 43; + hash = ((hash << 5) + hash) + 46; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._elemType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._lo)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._hi)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._up)); @@ -7901,6 +8190,8 @@ public override int GetHashCode() { public override string ToString() { string s = "DAST.Expression.IntRange"; s += "("; + s += Dafny.Helpers.ToString(this._elemType); + s += ", "; s += Dafny.Helpers.ToString(this._lo); s += ", "; s += Dafny.Helpers.ToString(this._hi); @@ -7927,7 +8218,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 44; + hash = ((hash << 5) + hash) + 47; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._start)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._up)); return (int) hash; @@ -7963,7 +8254,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 45; + hash = ((hash << 5) + hash) + 48; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._elemType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._collection)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._is__forall)); diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index a05bc35aad0..b1c10c24617 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -111,20 +111,12 @@ public static bool is__idiomatic__rust__id(Dafny.ISequence i) { return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("r#_"), _0_r); } } - public static Dafny.ISequence escapeField(Dafny.ISequence f) { + public static Dafny.ISequence escapeVar(Dafny.ISequence f) { Dafny.ISequence _0_r = (f); - if ((DCOMP.__default.reserved__fields).Contains(_0_r)) { - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("r#_"), _0_r); + if ((DCOMP.__default.reserved__vars).Contains(_0_r)) { + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _0_r); } else { - return DCOMP.__default.escapeName(f); - } - } - public static Dafny.ISequence escapeDtor(Dafny.ISequence f) { - Dafny.ISequence _0_r = (f); - if ((DCOMP.__default.reserved__fields).Contains(_0_r)) { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(_0_r, Dafny.Sequence.UnicodeFromString(": r#_")), _0_r); - } else { - return DCOMP.__default.escapeName(f); + return DCOMP.__default.escapeIdent((f)); } } public static Dafny.ISequence AddAssignedPrefix(Dafny.ISequence rustName) { @@ -177,14 +169,62 @@ public static bool is__idiomatic__rust__id(Dafny.ISequence i) { return DCOMP.__default.TraitTypeContainingMethodAux(_5_extendedTypes, dafnyName); } } + public static Std.Wrappers._IOption OptExtern(DAST._IAttribute attr, Dafny.ISequence dafnyName) + { + if (((attr).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("extern"))) { + return Std.Wrappers.Option.create_Some((((new BigInteger(((attr).dtor_args).Count)).Sign == 0) ? (DCOMP.ExternAttribute.create_SimpleExtern(DCOMP.__default.escapeName(dafnyName))) : ((((new BigInteger(((attr).dtor_args).Count)) == (BigInteger.One)) ? (DCOMP.ExternAttribute.create_SimpleExtern(((attr).dtor_args).Select(BigInteger.Zero))) : ((((new BigInteger(((attr).dtor_args).Count)) == (new BigInteger(2))) ? (DCOMP.ExternAttribute.create_AdvancedExtern(DCOMP.__default.ReplaceDotByDoubleColon(((attr).dtor_args).Select(BigInteger.Zero)), ((attr).dtor_args).Select(BigInteger.One))) : (DCOMP.ExternAttribute.create_UnsupportedExtern(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("{:extern} supports only 0, 1 or 2 attributes, got "), Std.Strings.__default.OfNat(new BigInteger(((attr).dtor_args).Count))))))))))); + } else { + return Std.Wrappers.Option.create_None(); + } + } + public static Dafny.ISequence ReplaceDotByDoubleColon(Dafny.ISequence s) { + Dafny.ISequence _0___accumulator = Dafny.Sequence.FromElements(); + TAIL_CALL_START: ; + if ((new BigInteger((s).Count)).Sign == 0) { + return Dafny.Sequence.Concat(_0___accumulator, Dafny.Sequence.UnicodeFromString("")); + } else if (((s).Select(BigInteger.Zero)) == (new Dafny.Rune(' '))) { + return Dafny.Sequence.Concat(_0___accumulator, s); + } else { + _0___accumulator = Dafny.Sequence.Concat(_0___accumulator, ((((s).Select(BigInteger.Zero)) == (new Dafny.Rune('.'))) ? (Dafny.Sequence.UnicodeFromString("::")) : (Dafny.Sequence.FromElements((s).Select(BigInteger.Zero))))); + Dafny.ISequence _in0 = (s).Drop(BigInteger.One); + s = _in0; + goto TAIL_CALL_START; + } + } + public static DCOMP._IExternAttribute ExtractExtern(Dafny.ISequence attributes, Dafny.ISequence dafnyName) + { + DCOMP._IExternAttribute res = DCOMP.ExternAttribute.Default(); + BigInteger _hi0 = new BigInteger((attributes).Count); + for (BigInteger _0_i = BigInteger.Zero; _0_i < _hi0; _0_i++) { + Std.Wrappers._IOption _1_attr; + _1_attr = DCOMP.__default.OptExtern((attributes).Select(_0_i), dafnyName); + Std.Wrappers._IOption _source0 = _1_attr; + { + if (_source0.is_Some) { + DCOMP._IExternAttribute _2_n = _source0.dtor_value; + res = _2_n; + return res; + goto after_match0; + } + } + { + } + after_match0: ; + } + res = DCOMP.ExternAttribute.create_NoExtern(); + return res; + } + public static DCOMP._IExternAttribute ExtractExternMod(DAST._IModule mod) { + return DCOMP.__default.ExtractExtern((mod).dtor_attributes, (mod).dtor_name); + } 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")); } } public static Dafny.ISet> reserved__rust__need__prefix { get { return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("u8"), Dafny.Sequence.UnicodeFromString("u16"), Dafny.Sequence.UnicodeFromString("u32"), Dafny.Sequence.UnicodeFromString("u64"), Dafny.Sequence.UnicodeFromString("u128"), Dafny.Sequence.UnicodeFromString("i8"), Dafny.Sequence.UnicodeFromString("i16"), Dafny.Sequence.UnicodeFromString("i32"), Dafny.Sequence.UnicodeFromString("i64"), Dafny.Sequence.UnicodeFromString("i128")); } } - public static Dafny.ISet> reserved__fields { get { - return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("None")); + public static Dafny.ISet> reserved__vars { get { + return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("None"), Dafny.Sequence.UnicodeFromString("hash")); } } public static Dafny.ISequence ASSIGNED__PREFIX { get { return Dafny.Sequence.UnicodeFromString("_set"); @@ -550,88 +590,58 @@ public override string ToString() { public interface _IGenTypeContext { bool is_GenTypeContext { get; } - bool dtor_inBinding { get; } - bool dtor_inFn { get; } bool dtor_forTraitParents { get; } - _IGenTypeContext DowncastClone(); } public class GenTypeContext : _IGenTypeContext { - public readonly bool _inBinding; - public readonly bool _inFn; public readonly bool _forTraitParents; - public GenTypeContext(bool inBinding, bool inFn, bool forTraitParents) { - this._inBinding = inBinding; - this._inFn = inFn; + public GenTypeContext(bool forTraitParents) { this._forTraitParents = forTraitParents; } - public _IGenTypeContext DowncastClone() { - if (this is _IGenTypeContext dt) { return dt; } - return new GenTypeContext(_inBinding, _inFn, _forTraitParents); + public static bool DowncastClone(bool _this) { + return _this; } public override bool Equals(object other) { var oth = other as DCOMP.GenTypeContext; - return oth != null && this._inBinding == oth._inBinding && this._inFn == oth._inFn && this._forTraitParents == oth._forTraitParents; + return oth != null && this._forTraitParents == oth._forTraitParents; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._inBinding)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._inFn)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._forTraitParents)); return (int) hash; } public override string ToString() { string s = "DafnyToRustCompiler.GenTypeContext.GenTypeContext"; s += "("; - s += Dafny.Helpers.ToString(this._inBinding); - s += ", "; - s += Dafny.Helpers.ToString(this._inFn); - s += ", "; s += Dafny.Helpers.ToString(this._forTraitParents); s += ")"; return s; } - private static readonly DCOMP._IGenTypeContext theDefault = create(false, false, false); - public static DCOMP._IGenTypeContext Default() { + private static readonly bool theDefault = false; + public static bool Default() { return theDefault; } - private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DCOMP.GenTypeContext.Default()); - public static Dafny.TypeDescriptor _TypeDescriptor() { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(false); + public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IGenTypeContext create(bool inBinding, bool inFn, bool forTraitParents) { - return new GenTypeContext(inBinding, inFn, forTraitParents); + public static _IGenTypeContext create(bool forTraitParents) { + return new GenTypeContext(forTraitParents); } - public static _IGenTypeContext create_GenTypeContext(bool inBinding, bool inFn, bool forTraitParents) { - return create(inBinding, inFn, forTraitParents); + public static _IGenTypeContext create_GenTypeContext(bool forTraitParents) { + return create(forTraitParents); } public bool is_GenTypeContext { get { return true; } } - public bool dtor_inBinding { - get { - return this._inBinding; - } - } - public bool dtor_inFn { - get { - return this._inFn; - } - } public bool dtor_forTraitParents { get { return this._forTraitParents; } } - public static DCOMP._IGenTypeContext InBinding() { - return DCOMP.GenTypeContext.create(true, false, false); - } - public static DCOMP._IGenTypeContext InFn() { - return DCOMP.GenTypeContext.create(false, true, false); - } - public static DCOMP._IGenTypeContext ForTraitParents() { - return DCOMP.GenTypeContext.create(false, false, true); + public static bool ForTraitParents() { + return true; } - public static DCOMP._IGenTypeContext @default() { - return DCOMP.GenTypeContext.create(false, false, false); + public static bool @default() { + return false; } } @@ -733,15 +743,182 @@ public override string ToString() { } } + public interface _IExternAttribute { + bool is_NoExtern { get; } + bool is_SimpleExtern { get; } + bool is_AdvancedExtern { get; } + bool is_UnsupportedExtern { get; } + Dafny.ISequence dtor_overrideName { get; } + Dafny.ISequence dtor_enclosingModule { get; } + Dafny.ISequence dtor_reason { get; } + _IExternAttribute DowncastClone(); + } + public abstract class ExternAttribute : _IExternAttribute { + public ExternAttribute() { + } + private static readonly DCOMP._IExternAttribute theDefault = create_NoExtern(); + public static DCOMP._IExternAttribute Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DCOMP.ExternAttribute.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IExternAttribute create_NoExtern() { + return new ExternAttribute_NoExtern(); + } + public static _IExternAttribute create_SimpleExtern(Dafny.ISequence overrideName) { + return new ExternAttribute_SimpleExtern(overrideName); + } + public static _IExternAttribute create_AdvancedExtern(Dafny.ISequence enclosingModule, Dafny.ISequence overrideName) { + return new ExternAttribute_AdvancedExtern(enclosingModule, overrideName); + } + public static _IExternAttribute create_UnsupportedExtern(Dafny.ISequence reason) { + return new ExternAttribute_UnsupportedExtern(reason); + } + public bool is_NoExtern { get { return this is ExternAttribute_NoExtern; } } + public bool is_SimpleExtern { get { return this is ExternAttribute_SimpleExtern; } } + public bool is_AdvancedExtern { get { return this is ExternAttribute_AdvancedExtern; } } + public bool is_UnsupportedExtern { get { return this is ExternAttribute_UnsupportedExtern; } } + public Dafny.ISequence dtor_overrideName { + get { + var d = this; + if (d is ExternAttribute_SimpleExtern) { return ((ExternAttribute_SimpleExtern)d)._overrideName; } + return ((ExternAttribute_AdvancedExtern)d)._overrideName; + } + } + public Dafny.ISequence dtor_enclosingModule { + get { + var d = this; + return ((ExternAttribute_AdvancedExtern)d)._enclosingModule; + } + } + public Dafny.ISequence dtor_reason { + get { + var d = this; + return ((ExternAttribute_UnsupportedExtern)d)._reason; + } + } + public abstract _IExternAttribute DowncastClone(); + } + public class ExternAttribute_NoExtern : ExternAttribute { + public ExternAttribute_NoExtern() : base() { + } + public override _IExternAttribute DowncastClone() { + if (this is _IExternAttribute dt) { return dt; } + return new ExternAttribute_NoExtern(); + } + public override bool Equals(object other) { + var oth = other as DCOMP.ExternAttribute_NoExtern; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompiler.ExternAttribute.NoExtern"; + return s; + } + } + public class ExternAttribute_SimpleExtern : ExternAttribute { + public readonly Dafny.ISequence _overrideName; + public ExternAttribute_SimpleExtern(Dafny.ISequence overrideName) : base() { + this._overrideName = overrideName; + } + public override _IExternAttribute DowncastClone() { + if (this is _IExternAttribute dt) { return dt; } + return new ExternAttribute_SimpleExtern(_overrideName); + } + public override bool Equals(object other) { + var oth = other as DCOMP.ExternAttribute_SimpleExtern; + return oth != null && object.Equals(this._overrideName, oth._overrideName); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overrideName)); + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompiler.ExternAttribute.SimpleExtern"; + s += "("; + s += this._overrideName.ToVerbatimString(true); + s += ")"; + return s; + } + } + public class ExternAttribute_AdvancedExtern : ExternAttribute { + public readonly Dafny.ISequence _enclosingModule; + public readonly Dafny.ISequence _overrideName; + public ExternAttribute_AdvancedExtern(Dafny.ISequence enclosingModule, Dafny.ISequence overrideName) : base() { + this._enclosingModule = enclosingModule; + this._overrideName = overrideName; + } + public override _IExternAttribute DowncastClone() { + if (this is _IExternAttribute dt) { return dt; } + return new ExternAttribute_AdvancedExtern(_enclosingModule, _overrideName); + } + public override bool Equals(object other) { + var oth = other as DCOMP.ExternAttribute_AdvancedExtern; + return oth != null && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._overrideName, oth._overrideName); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._enclosingModule)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._overrideName)); + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompiler.ExternAttribute.AdvancedExtern"; + s += "("; + s += this._enclosingModule.ToVerbatimString(true); + s += ", "; + s += this._overrideName.ToVerbatimString(true); + s += ")"; + return s; + } + } + public class ExternAttribute_UnsupportedExtern : ExternAttribute { + public readonly Dafny.ISequence _reason; + public ExternAttribute_UnsupportedExtern(Dafny.ISequence reason) : base() { + this._reason = reason; + } + public override _IExternAttribute DowncastClone() { + if (this is _IExternAttribute dt) { return dt; } + return new ExternAttribute_UnsupportedExtern(_reason); + } + public override bool Equals(object other) { + var oth = other as DCOMP.ExternAttribute_UnsupportedExtern; + return oth != null && object.Equals(this._reason, oth._reason); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._reason)); + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompiler.ExternAttribute.UnsupportedExtern"; + s += "("; + s += this._reason.ToVerbatimString(true); + s += ")"; + return s; + } + } + public partial class COMP { public COMP() { this.error = Std.Wrappers.Option>.Default(); + this.optimizations = Dafny.Sequence>.Empty; this._UnicodeChars = false; this._ObjectType = DCOMP.ObjectType.Default(); } public RAST._IType Object(RAST._IType underlying) { if (((this).ObjectType).is_RawPointers) { - return RAST.Type.create_PointerMut(underlying); + return RAST.__default.PtrType(underlying); } else { return RAST.__default.ObjectType(underlying); } @@ -756,35 +933,60 @@ public RAST._IType Object(RAST._IType underlying) { } } public Std.Wrappers._IOption> error {get; set;} + public Dafny.ISequence> optimizations {get; set;} public void __ctor(bool unicodeChars, DCOMP._IObjectType objectType) { (this)._UnicodeChars = unicodeChars; (this)._ObjectType = objectType; (this).error = Std.Wrappers.Option>.create_None(); - if ((objectType).is_RawPointers) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("Raw pointers need to be wrapped in a newtype so that their equality has the semantics of Dafny (e.g. a class pointer and a trait pointer are equal), not Rust.")); - } + (this).optimizations = Dafny.Sequence>.FromElements(FactorPathsOptimization.__default.apply); } - public RAST._IMod GenModule(DAST._IModule mod, Dafny.ISequence> containingPath) + public static Dafny.ISequence> ContainingPathToRust(Dafny.ISequence> containingPath) { + return Std.Collections.Seq.__default.Map, Dafny.ISequence>(((System.Func, Dafny.ISequence>)((_0_i) => { + return DCOMP.__default.escapeName((_0_i)); + })), containingPath); + } + public DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> GenModule(DAST._IModule mod, Dafny.ISequence> containingPath) { - RAST._IMod s = RAST.Mod.Default(); - Dafny.ISequence _0_modName; - _0_modName = DCOMP.__default.escapeName((mod).dtor_name); + DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> s = DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Default(); + _System._ITuple2>, Dafny.ISequence> _let_tmp_rhs0 = DafnyCompilerRustUtils.__default.DafnyNameToContainingPathAndName((mod).dtor_name, Dafny.Sequence>.FromElements()); + Dafny.ISequence> _0_innerPath = _let_tmp_rhs0.dtor__0; + Dafny.ISequence _1_innerName = _let_tmp_rhs0.dtor__1; + Dafny.ISequence> _2_containingPath; + _2_containingPath = Dafny.Sequence>.Concat(containingPath, _0_innerPath); + Dafny.ISequence _3_modName; + _3_modName = DCOMP.__default.escapeName(_1_innerName); if (((mod).dtor_body).is_None) { - s = RAST.Mod.create_ExternMod(_0_modName); + s = DafnyCompilerRustUtils.GatheringModule.Wrap(DCOMP.COMP.ContainingPathToRust(_2_containingPath), RAST.Mod.create_ExternMod(_3_modName)); } else { - Dafny.ISequence _1_body; + DCOMP._IExternAttribute _4_optExtern; + _4_optExtern = DCOMP.__default.ExtractExternMod(mod); + Dafny.ISequence _5_body; + DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _6_allmodules; Dafny.ISequence _out0; - _out0 = (this).GenModuleBody(((mod).dtor_body).dtor_value, Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((mod).dtor_name))); - _1_body = _out0; - s = RAST.Mod.create_Mod(_0_modName, _1_body); + DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _out1; + (this).GenModuleBody(((mod).dtor_body).dtor_value, Dafny.Sequence>.Concat(_2_containingPath, Dafny.Sequence>.FromElements(_1_innerName)), out _out0, out _out1); + _5_body = _out0; + _6_allmodules = _out1; + if ((_4_optExtern).is_SimpleExtern) { + if ((mod).dtor_requiresExterns) { + _5_body = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (((RAST.__default.crate).MSel(DCOMP.COMP.DAFNY__EXTERN__MODULE)).MSel(DCOMP.__default.ReplaceDotByDoubleColon((_4_optExtern).dtor_overrideName))).MSel(Dafny.Sequence.UnicodeFromString("*"))))), _5_body); + } + } else if ((_4_optExtern).is_AdvancedExtern) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("Externs on modules can only have 1 string argument")); + } else if ((_4_optExtern).is_UnsupportedExtern) { + (this).error = Std.Wrappers.Option>.create_Some((_4_optExtern).dtor_reason); + } + s = DafnyCompilerRustUtils.GatheringModule.MergeSeqMap(DafnyCompilerRustUtils.GatheringModule.Wrap(DCOMP.COMP.ContainingPathToRust(_2_containingPath), RAST.Mod.create_Mod(_3_modName, _5_body)), _6_allmodules); } return s; } - public Dafny.ISequence GenModuleBody(Dafny.ISequence body, Dafny.ISequence> containingPath) + public void GenModuleBody(Dafny.ISequence body, Dafny.ISequence> containingPath, out Dafny.ISequence s, out DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> allmodules) { - Dafny.ISequence s = Dafny.Sequence.Empty; + s = Dafny.Sequence.Empty; + allmodules = DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Default(); s = Dafny.Sequence.FromElements(); + allmodules = DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Empty(); BigInteger _hi0 = new BigInteger((body).Count); for (BigInteger _0_i = BigInteger.Zero; _0_i < _hi0; _0_i++) { Dafny.ISequence _1_generated = Dafny.Sequence.Empty; @@ -792,11 +994,12 @@ public RAST._IMod GenModule(DAST._IModule mod, Dafny.ISequence, DafnyCompilerRustUtils._IGatheringModule> _3_mm; + DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _out0; _out0 = (this).GenModule(_2_m, containingPath); _3_mm = _out0; - _1_generated = Dafny.Sequence.FromElements(RAST.ModDecl.create_ModDecl(_3_mm)); + allmodules = DafnyCompilerRustUtils.GatheringModule.MergeSeqMap(allmodules, _3_mm); + _1_generated = Dafny.Sequence.FromElements(); goto after_match0; } } @@ -845,7 +1048,6 @@ public RAST._IMod GenModule(DAST._IModule mod, Dafny.ISequence.Concat(s, _1_generated); } - return s; } public void GenTypeParam(DAST._ITypeArgDecl tp, out DAST._IType typeArg, out RAST._ITypeParamDecl typeParam) { @@ -859,7 +1061,7 @@ public void GenTypeParam(DAST._ITypeArgDecl tp, out DAST._IType typeArg, out RAS _0_genTpConstraint = Dafny.Sequence.FromElements(RAST.__default.DafnyType); } if (((tp).dtor_bounds).Contains(DAST.TypeArgBound.create_SupportsDefault())) { - _0_genTpConstraint = Dafny.Sequence.Concat(_0_genTpConstraint, Dafny.Sequence.FromElements(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default")))); + _0_genTpConstraint = Dafny.Sequence.Concat(_0_genTpConstraint, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); } typeParam = RAST.TypeParamDecl.create(DCOMP.__default.escapeName(((tp).dtor_name)), _0_genTpConstraint); } @@ -903,6 +1105,12 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) { return ((this).IsSameResolvedTypeAnyArgs(r1, r2)) && (((r1).dtor_typeArgs).Equals((r2).dtor_typeArgs)); } + public Dafny.ISet> GatherTypeParamNames(Dafny.ISet> types, RAST._IType typ) + { + return (typ).Fold>>(types, ((System.Func>, RAST._IType, Dafny.ISet>>)((_0_types, _1_currentType) => { + return (((_1_currentType).is_TIdentifier) ? (Dafny.Set>.Union(_0_types, Dafny.Set>.FromElements((_1_currentType).dtor_name))) : (_0_types)); + }))); + } public Dafny.ISequence GenClass(DAST._IClass c, Dafny.ISequence> path) { Dafny.ISequence s = Dafny.Sequence.Empty; @@ -925,119 +1133,171 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) _5_fields = Dafny.Sequence.FromElements(); Dafny.ISequence _6_fieldInits; _6_fieldInits = Dafny.Sequence.FromElements(); + Dafny.ISet> _7_usedTypeParams; + _7_usedTypeParams = Dafny.Set>.FromElements(); BigInteger _hi0 = new BigInteger(((c).dtor_fields).Count); - for (BigInteger _7_fieldI = BigInteger.Zero; _7_fieldI < _hi0; _7_fieldI++) { - DAST._IField _8_field; - _8_field = ((c).dtor_fields).Select(_7_fieldI); - RAST._IType _9_fieldType; + 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(((_8_field).dtor_formal).dtor_typ, DCOMP.GenTypeContext.@default()); - _9_fieldType = _out4; - Dafny.ISequence _10_fieldRustName; - _10_fieldRustName = DCOMP.__default.escapeName(((_8_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(_10_fieldRustName, _9_fieldType)))); - Std.Wrappers._IOption _source0 = (_8_field).dtor_defaultValue; + _out4 = (this).GenType(((_9_field).dtor_formal).dtor_typ, DCOMP.GenTypeContext.@default()); + _10_fieldType = _out4; + _7_usedTypeParams = (this).GatherTypeParamNames(_7_usedTypeParams, _10_fieldType); + Dafny.ISequence _11_fieldRustName; + _11_fieldRustName = DCOMP.__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 _11_e = _source0.dtor_value; + DAST._IExpression _12_e = _source0.dtor_value; { - RAST._IExpr _12_expr; - DCOMP._IOwnership _13___v48; - Dafny.ISet> _14___v49; + RAST._IExpr _13_expr; + DCOMP._IOwnership _14___v51; + Dafny.ISet> _15___v52; RAST._IExpr _out5; DCOMP._IOwnership _out6; Dafny.ISet> _out7; - (this).GenExpr(_11_e, DCOMP.SelfInfo.create_NoSelf(), DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); - _12_expr = _out5; - _13___v48 = _out6; - _14___v49 = _out7; - _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_10_fieldRustName, _12_expr))); + (this).GenExpr(_12_e, DCOMP.SelfInfo.create_NoSelf(), DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); + _13_expr = _out5; + _14___v51 = _out6; + _15___v52 = _out7; + _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_11_fieldRustName, _13_expr))); } goto after_match0; } } { { - RAST._IExpr _15_default; - _15_default = RAST.__default.std__Default__default; - if ((_9_fieldType).IsObjectOrPointer()) { - _15_default = (_9_fieldType).ToNullExpr(); + RAST._IExpr _16_default; + _16_default = RAST.__default.std__Default__default; + if ((_10_fieldType).IsObjectOrPointer()) { + _16_default = (_10_fieldType).ToNullExpr(); } - _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_10_fieldRustName, _15_default))); + _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_11_fieldRustName, _16_default))); } } after_match0: ; } BigInteger _hi1 = new BigInteger(((c).dtor_typeParams).Count); - for (BigInteger _16_typeParamI = BigInteger.Zero; _16_typeParamI < _hi1; _16_typeParamI++) { - DAST._IType _17_typeArg; - RAST._ITypeParamDecl _18_typeParam; + 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(_16_typeParamI), out _out8, out _out9); - _17_typeArg = _out8; - _18_typeParam = _out9; - RAST._IType _19_rTypeArg; + (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(_17_typeArg, DCOMP.GenTypeContext.@default()); - _19_rTypeArg = _out10; - _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(_16_typeParamI)), RAST.Type.create_TypeApp(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData")), Dafny.Sequence.FromElements(_19_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(_16_typeParamI)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::marker::PhantomData"))))); - } - Dafny.ISequence _20_datatypeName; - _20_datatypeName = DCOMP.__default.escapeName((c).dtor_name); - RAST._IStruct _21_struct; - _21_struct = RAST.Struct.create(Dafny.Sequence>.FromElements(), _20_datatypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_5_fields)); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_21_struct)); - Dafny.ISequence _22_implBodyRaw; - Dafny.IMap>,Dafny.ISequence> _23_traitBodies; + _out10 = (this).GenType(_18_typeArg, DCOMP.GenTypeContext.@default()); + _20_rTypeArg = _out10; + if ((_7_usedTypeParams).Contains((_19_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.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::marker::PhantomData"))))); + continue_0: ; + } + after_0: ; + DCOMP._IExternAttribute _21_extern; + _21_extern = DCOMP.__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; + } else { + _22_className = DCOMP.__default.escapeName((c).dtor_name); + if ((_21_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)); + 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); - _22_implBodyRaw = _out11; - _23_traitBodies = _out12; - Dafny.ISequence _24_implBody; - _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.Type.create_SelfOwned())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel((this).allocate)).ApplyType1(RAST.Type.create_SelfOwned())).Apply(Dafny.Sequence.FromElements()))))), _22_implBodyRaw); - RAST._IImpl _25_i; - _25_i = RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_20_datatypeName), _1_rTypeParams), _3_whereConstraints, _24_implBody); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_25_i))); - RAST._IType _26_genSelfPath; + _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)).Apply(Dafny.Sequence.FromElements()))))), _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).MSel((_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))); + } + RAST._IType _28_genSelfPath; RAST._IType _out13; - _out13 = DCOMP.COMP.GenPath(path); - _26_genSelfPath = _out13; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((RAST.__default.dafny__runtime__type).MSel((this).Upcast)).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))))), RAST.Type.create_TypeApp(_26_genSelfPath, _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro(((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))))))))))); - BigInteger _hi2 = new BigInteger(((c).dtor_superClasses).Count); - for (BigInteger _27_i = BigInteger.Zero; _27_i < _hi2; _27_i++) { - DAST._IType _28_superClass; - _28_superClass = ((c).dtor_superClasses).Select(_27_i); - DAST._IType _source1 = _28_superClass; + _out13 = DCOMP.COMP.GenPathType(path); + _28_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(_28_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 _29_superClasses; + if ((_22_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { + _29_superClasses = Dafny.Sequence.FromElements(); + } else { + _29_superClasses = (c).dtor_superClasses; + } + BigInteger _hi2 = new BigInteger((_29_superClasses).Count); + for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi2; _30_i++) { + DAST._IType _31_superClass; + _31_superClass = (_29_superClasses).Select(_30_i); + DAST._IType _source1 = _31_superClass; { if (_source1.is_UserDefined) { DAST._IResolvedType resolved0 = _source1.dtor_resolved; - Dafny.ISequence> _29_traitPath = resolved0.dtor_path; - Dafny.ISequence _30_typeArgs = resolved0.dtor_typeArgs; + Dafny.ISequence> _32_traitPath = resolved0.dtor_path; + Dafny.ISequence _33_typeArgs = resolved0.dtor_typeArgs; DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; if (kind0.is_Trait) { + Dafny.ISequence> _34_properMethods = resolved0.dtor_properMethods; { - RAST._IType _31_pathStr; + RAST._IType _35_pathStr; RAST._IType _out14; - _out14 = DCOMP.COMP.GenPath(_29_traitPath); - _31_pathStr = _out14; - Dafny.ISequence _32_typeArgs; + _out14 = DCOMP.COMP.GenPathType(_32_traitPath); + _35_pathStr = _out14; + Dafny.ISequence _36_typeArgs; Dafny.ISequence _out15; - _out15 = (this).GenTypeArgs(_30_typeArgs, DCOMP.GenTypeContext.@default()); - _32_typeArgs = _out15; - Dafny.ISequence _33_body; - _33_body = Dafny.Sequence.FromElements(); - if ((_23_traitBodies).Contains(_29_traitPath)) { - _33_body = Dafny.Map>, Dafny.ISequence>.Select(_23_traitBodies,_29_traitPath); + _out15 = (this).GenTypeArgs(_33_typeArgs, DCOMP.GenTypeContext.@default()); + _36_typeArgs = _out15; + Dafny.ISequence _37_body; + _37_body = Dafny.Sequence.FromElements(); + if ((_25_traitBodies).Contains(_32_traitPath)) { + _37_body = Dafny.Map>, Dafny.ISequence>.Select(_25_traitBodies,_32_traitPath); } - RAST._IType _34_traitType; - _34_traitType = RAST.Type.create_TypeApp(_31_pathStr, _32_typeArgs); - RAST._IModDecl _35_x; - _35_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, _34_traitType, RAST.Type.create_TypeApp(_26_genSelfPath, _1_rTypeParams), _3_whereConstraints, _33_body)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_35_x)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((RAST.__default.dafny__runtime__type).MSel((this).Upcast)).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_34_traitType))), RAST.Type.create_TypeApp(_26_genSelfPath, _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro(((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_34_traitType))))))))); + RAST._IType _38_traitType; + _38_traitType = RAST.Type.create_TypeApp(_35_pathStr, _36_typeArgs); + if (!((_21_extern).is_NoExtern)) { + if (((new BigInteger((_37_body).Count)).Sign == 0) && ((new BigInteger((_34_properMethods).Count)).Sign != 0)) { + goto continue_1; + } + if ((new BigInteger((_37_body).Count)) != (new BigInteger((_34_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>)((_39_s) => { + return ((_39_s)); +})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_38_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>(_34_properMethods, ((System.Func, Dafny.ISequence>)((_40_s) => { + return (_40_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 _41_x; + _41_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, _38_traitType, RAST.Type.create_TypeApp(_28_genSelfPath, _1_rTypeParams), _3_whereConstraints, _37_body)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_41_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(_38_traitType))), RAST.Type.create_TypeApp(_28_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(_38_traitType))))))))); } goto after_match1; } @@ -1046,7 +1306,9 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) { } after_match1: ; + continue_1: ; } + after_1: ; return s; } public Dafny.ISequence GenTrait(DAST._ITrait t, Dafny.ISequence> containingPath) @@ -1082,12 +1344,12 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) Dafny.ISequence> _8_fullPath; _8_fullPath = Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((t).dtor_name)); Dafny.ISequence _9_implBody; - Dafny.IMap>,Dafny.ISequence> _10___v54; + Dafny.IMap>,Dafny.ISequence> _10___v56; Dafny.ISequence _out3; Dafny.IMap>,Dafny.ISequence> _out4; (this).GenClassImplBody((t).dtor_body, true, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_8_fullPath, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Trait(), (t).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out3, out _out4); _9_implBody = _out3; - _10___v54 = _out4; + _10___v56 = _out4; Dafny.ISequence _11_parents; _11_parents = Dafny.Sequence.FromElements(); BigInteger _hi1 = new BigInteger(((t).dtor_parents).Count); @@ -1096,7 +1358,7 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) RAST._IType _out5; _out5 = (this).GenType(((t).dtor_parents).Select(_12_i), DCOMP.GenTypeContext.ForTraitParents()); _13_tpe = _out5; - _11_parents = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_11_parents, Dafny.Sequence.FromElements(_13_tpe)), Dafny.Sequence.FromElements(((RAST.__default.dafny__runtime__type).MSel((this).Upcast)).Apply1(RAST.Type.create_DynType(_13_tpe)))); + _11_parents = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_11_parents, Dafny.Sequence.FromElements(_13_tpe)), Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply1(RAST.Type.create_DynType(_13_tpe)))); } s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_typeParamDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeName((t).dtor_name)), _2_typeParams), _11_parents, _9_implBody))); return s; @@ -1120,7 +1382,7 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) 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 = DCOMP.COMP.NewtypeToRustType((c).dtor_base, (c).dtor_range); + Std.Wrappers._IOption _source0 = DCOMP.COMP.NewtypeRangeToRustType((c).dtor_range); { if (_source0.is_Some) { RAST._IType _6_v = _source0.dtor_value; @@ -1153,15 +1415,15 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) _11_e = DAST.Expression.create_Convert(_10_e, (c).dtor_base, _7_resultingType); } RAST._IExpr _12_eStr; - DCOMP._IOwnership _13___v55; - Dafny.ISet> _14___v56; + DCOMP._IOwnership _13___v57; + Dafny.ISet> _14___v58; RAST._IExpr _out5; DCOMP._IOwnership _out6; Dafny.ISet> _out7; (this).GenExpr(_11_e, DCOMP.SelfInfo.create_NoSelf(), DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); _12_eStr = _out5; - _13___v55 = _out6; - _14___v56 = _out7; + _13___v57 = _out6; + _14___v58 = _out7; _9_fnBody = (_9_fnBody).Apply1(_12_eStr); } goto after_match1; @@ -1174,7 +1436,7 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) } 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.Type.create_SelfOwned()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_9_fnBody))); + _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; { if (_source2.is_None) { @@ -1186,25 +1448,25 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) DAST._IFormal _16_formal = value0.dtor_variable; Dafny.ISequence _17_constraintStmts = value0.dtor_constraintStmts; RAST._IExpr _18_rStmts; - Dafny.ISet> _19___v57; + Dafny.ISet> _19___v59; DCOMP._IEnvironment _20_newEnv; RAST._IExpr _out8; Dafny.ISet> _out9; DCOMP._IEnvironment _out10; (this).GenStmts(_17_constraintStmts, DCOMP.SelfInfo.create_NoSelf(), DCOMP.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out8, out _out9, out _out10); _18_rStmts = _out8; - _19___v57 = _out9; + _19___v59 = _out9; _20_newEnv = _out10; Dafny.ISequence _21_rFormals; Dafny.ISequence _out11; - _out11 = (this).GenParams(Dafny.Sequence.FromElements(_16_formal)); + _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.__default.RawType(Dafny.Sequence.UnicodeFromString("&mut ::std::fmt::Formatter"))), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("::std::fmt::Result"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyPrint::fmt_print(&self.0, _formatter, 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(DCOMP.__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.__default.SelfBorrowed).MSel(Dafny.Sequence.UnicodeFromString("Target"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("&self.0")))))))))); + 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(DCOMP.__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.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("&self.0")))))))))); return s; } public Dafny.ISequence GenSynonymType(DAST._ISynonymType c) @@ -1223,43 +1485,43 @@ public bool IsSameResolvedType(DAST._IResolvedType r1, DAST._IResolvedType r2) _1_rTypeParams = _out1; _2_rTypeParamsDecls = _out2; _3_whereConstraints = _out3; - Dafny.ISequence _4_constrainedTypeParams; - _4_constrainedTypeParams = RAST.TypeParamDecl.ToStringMultiple(_2_rTypeParamsDecls, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); - Dafny.ISequence _5_synonymTypeName; - _5_synonymTypeName = DCOMP.__default.escapeName((c).dtor_name); - RAST._IType _6_resultingType; + Dafny.ISequence _4_synonymTypeName; + _4_synonymTypeName = DCOMP.__default.escapeName((c).dtor_name); + RAST._IType _5_resultingType; RAST._IType _out4; _out4 = (this).GenType((c).dtor_base, DCOMP.GenTypeContext.@default()); - _6_resultingType = _out4; - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create(Dafny.Sequence>.FromElements(), _5_synonymTypeName, _2_rTypeParamsDecls, _6_resultingType))); + _5_resultingType = _out4; + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create(Dafny.Sequence>.FromElements(), _4_synonymTypeName, _2_rTypeParamsDecls, _5_resultingType))); + Dafny.ISequence _6_defaultConstrainedTypeParams; + _6_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; { if (_source0.is_Some) { DAST._IExpression _7_e = _source0.dtor_value; { RAST._IExpr _8_rStmts; - Dafny.ISet> _9___v58; + Dafny.ISet> _9___v60; DCOMP._IEnvironment _10_newEnv; RAST._IExpr _out5; Dafny.ISet> _out6; DCOMP._IEnvironment _out7; (this).GenStmts((c).dtor_witnessStmts, DCOMP.SelfInfo.create_NoSelf(), DCOMP.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out5, out _out6, out _out7); _8_rStmts = _out5; - _9___v58 = _out6; + _9___v60 = _out6; _10_newEnv = _out7; RAST._IExpr _11_rExpr; - DCOMP._IOwnership _12___v59; - Dafny.ISet> _13___v60; + DCOMP._IOwnership _12___v61; + Dafny.ISet> _13___v62; RAST._IExpr _out8; DCOMP._IOwnership _out9; Dafny.ISet> _out10; (this).GenExpr(_7_e, DCOMP.SelfInfo.create_NoSelf(), _10_newEnv, DCOMP.Ownership.create_OwnershipOwned(), out _out8, out _out9, out _out10); _11_rExpr = _out8; - _12___v59 = _out9; - _13___v60 = _out10; + _12___v61 = _out9; + _13___v62 = _out10; Dafny.ISequence _14_constantName; _14_constantName = DCOMP.__default.escapeName(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_init_"), ((c).dtor_name))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_14_constantName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_6_resultingType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((_8_rStmts).Then(_11_rExpr))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_14_constantName, _6_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_5_resultingType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((_8_rStmts).Then(_11_rExpr))))))); } goto after_match0; } @@ -1387,390 +1649,417 @@ public bool DatatypeIsEq(DAST._IDatatype c) { _6_variances = Std.Collections.Seq.__default.Map(((System.Func)((_7_typeParamDecl) => { return (_7_typeParamDecl).dtor_variance; })), (c).dtor_typeParams); + Dafny.ISet> _8_usedTypeParams; + _8_usedTypeParams = Dafny.Set>.FromElements(); BigInteger _hi0 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _8_i = BigInteger.Zero; _8_i < _hi0; _8_i++) { - DAST._IDatatypeCtor _9_ctor; - _9_ctor = ((c).dtor_ctors).Select(_8_i); - Dafny.ISequence _10_ctorArgs; - _10_ctorArgs = Dafny.Sequence.FromElements(); - bool _11_isNumeric; - _11_isNumeric = false; - BigInteger _hi1 = new BigInteger(((_9_ctor).dtor_args).Count); - for (BigInteger _12_j = BigInteger.Zero; _12_j < _hi1; _12_j++) { - DAST._IDatatypeDtor _13_dtor; - _13_dtor = ((_9_ctor).dtor_args).Select(_12_j); - RAST._IType _14_formalType; + for (BigInteger _9_i = BigInteger.Zero; _9_i < _hi0; _9_i++) { + DAST._IDatatypeCtor _10_ctor; + _10_ctor = ((c).dtor_ctors).Select(_9_i); + Dafny.ISequence _11_ctorArgs; + _11_ctorArgs = Dafny.Sequence.FromElements(); + bool _12_isNumeric; + _12_isNumeric = false; + BigInteger _hi1 = new BigInteger(((_10_ctor).dtor_args).Count); + for (BigInteger _13_j = BigInteger.Zero; _13_j < _hi1; _13_j++) { + DAST._IDatatypeDtor _14_dtor; + _14_dtor = ((_10_ctor).dtor_args).Select(_13_j); + RAST._IType _15_formalType; RAST._IType _out4; - _out4 = (this).GenType(((_13_dtor).dtor_formal).dtor_typ, DCOMP.GenTypeContext.@default()); - _14_formalType = _out4; - Dafny.ISequence _15_formalName; - _15_formalName = DCOMP.__default.escapeName(((_13_dtor).dtor_formal).dtor_name); - if (((_12_j).Sign == 0) && ((Dafny.Sequence.UnicodeFromString("0")).Equals(_15_formalName))) { - _11_isNumeric = true; - } - if ((((_12_j).Sign != 0) && (_11_isNumeric)) && (!(Std.Strings.__default.OfNat(_12_j)).Equals(_15_formalName))) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Formal extern names were supposed to be numeric but got "), _15_formalName), Dafny.Sequence.UnicodeFromString(" instead of ")), Std.Strings.__default.OfNat(_12_j))); - _11_isNumeric = false; + _out4 = (this).GenType(((_14_dtor).dtor_formal).dtor_typ, DCOMP.GenTypeContext.@default()); + _15_formalType = _out4; + _8_usedTypeParams = (this).GatherTypeParamNames(_8_usedTypeParams, _15_formalType); + Dafny.ISequence _16_formalName; + _16_formalName = DCOMP.__default.escapeVar(((_14_dtor).dtor_formal).dtor_name); + if (((_13_j).Sign == 0) && ((Dafny.Sequence.UnicodeFromString("0")).Equals(_16_formalName))) { + _12_isNumeric = true; + } + if ((((_13_j).Sign != 0) && (_12_isNumeric)) && (!(Std.Strings.__default.OfNat(_13_j)).Equals(_16_formalName))) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Formal extern names were supposed to be numeric but got "), _16_formalName), Dafny.Sequence.UnicodeFromString(" instead of ")), Std.Strings.__default.OfNat(_13_j))); + _12_isNumeric = false; } if ((c).dtor_isCo) { - _10_ctorArgs = Dafny.Sequence.Concat(_10_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_15_formalName, RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("LazyFieldWrapper")), Dafny.Sequence.FromElements(_14_formalType)))))); + _11_ctorArgs = Dafny.Sequence.Concat(_11_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_16_formalName, RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("LazyFieldWrapper"))).AsType(), Dafny.Sequence.FromElements(_15_formalType)))))); } else { - _10_ctorArgs = Dafny.Sequence.Concat(_10_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_15_formalName, _14_formalType)))); + _11_ctorArgs = Dafny.Sequence.Concat(_11_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_16_formalName, _15_formalType)))); } } - RAST._IFields _16_namedFields; - _16_namedFields = RAST.Fields.create_NamedFields(_10_ctorArgs); - if (_11_isNumeric) { - _16_namedFields = (_16_namedFields).ToNamelessFields(); + RAST._IFields _17_namedFields; + _17_namedFields = RAST.Fields.create_NamedFields(_11_ctorArgs); + if (_12_isNumeric) { + _17_namedFields = (_17_namedFields).ToNamelessFields(); } - _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(DCOMP.__default.escapeName((_9_ctor).dtor_name), _16_namedFields))); + _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(DCOMP.__default.escapeName((_10_ctor).dtor_name), _17_namedFields))); } - Dafny.ISequence> _17_selfPath; - _17_selfPath = Dafny.Sequence>.FromElements((c).dtor_name); - Dafny.ISequence _18_implBodyRaw; - Dafny.IMap>,Dafny.ISequence> _19_traitBodies; + Dafny.ISet> _18_unusedTypeParams; + _18_unusedTypeParams = Dafny.Set>.Difference(Dafny.Helpers.Id, Dafny.ISet>>>((_19_rTypeParamsDecls) => ((System.Func>>)(() => { + var _coll0 = new System.Collections.Generic.List>(); + foreach (RAST._ITypeParamDecl _compr_0 in (_19_rTypeParamsDecls).CloneAsArray()) { + RAST._ITypeParamDecl _20_tp = (RAST._ITypeParamDecl)_compr_0; + if ((_19_rTypeParamsDecls).Contains(_20_tp)) { + _coll0.Add((_20_tp).dtor_name); + } + } + return Dafny.Set>.FromCollection(_coll0); + }))())(_2_rTypeParamsDecls), _8_usedTypeParams); + Dafny.ISequence> _21_selfPath; + _21_selfPath = Dafny.Sequence>.FromElements((c).dtor_name); + Dafny.ISequence _22_implBodyRaw; + Dafny.IMap>,Dafny.ISequence> _23_traitBodies; Dafny.ISequence _out5; Dafny.IMap>,Dafny.ISequence> _out6; - (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_17_selfPath, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype(_6_variances), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out5, out _out6); - _18_implBodyRaw = _out5; - _19_traitBodies = _out6; - Dafny.ISequence _20_implBody; - _20_implBody = _18_implBodyRaw; - Dafny.ISet> _21_emittedFields; - _21_emittedFields = Dafny.Set>.FromElements(); + (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_21_selfPath, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype(_6_variances), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out5, out _out6); + _22_implBodyRaw = _out5; + _23_traitBodies = _out6; + Dafny.ISequence _24_implBody; + _24_implBody = _22_implBodyRaw; + Dafny.ISet> _25_emittedFields; + _25_emittedFields = Dafny.Set>.FromElements(); BigInteger _hi2 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi2; _22_i++) { - DAST._IDatatypeCtor _23_ctor; - _23_ctor = ((c).dtor_ctors).Select(_22_i); - BigInteger _hi3 = new BigInteger(((_23_ctor).dtor_args).Count); - for (BigInteger _24_j = BigInteger.Zero; _24_j < _hi3; _24_j++) { - DAST._IDatatypeDtor _25_dtor; - _25_dtor = ((_23_ctor).dtor_args).Select(_24_j); - Dafny.ISequence _26_callName; - _26_callName = Std.Wrappers.Option>.GetOr((_25_dtor).dtor_callName, DCOMP.__default.escapeName(((_25_dtor).dtor_formal).dtor_name)); - if (!((_21_emittedFields).Contains(_26_callName))) { - _21_emittedFields = Dafny.Set>.Union(_21_emittedFields, Dafny.Set>.FromElements(_26_callName)); - RAST._IType _27_formalType; + for (BigInteger _26_i = BigInteger.Zero; _26_i < _hi2; _26_i++) { + DAST._IDatatypeCtor _27_ctor; + _27_ctor = ((c).dtor_ctors).Select(_26_i); + BigInteger _hi3 = new BigInteger(((_27_ctor).dtor_args).Count); + for (BigInteger _28_j = BigInteger.Zero; _28_j < _hi3; _28_j++) { + DAST._IDatatypeDtor _29_dtor; + _29_dtor = ((_27_ctor).dtor_args).Select(_28_j); + Dafny.ISequence _30_callName; + _30_callName = Std.Wrappers.Option>.GetOr((_29_dtor).dtor_callName, DCOMP.__default.escapeVar(((_29_dtor).dtor_formal).dtor_name)); + if (!((_25_emittedFields).Contains(_30_callName))) { + _25_emittedFields = Dafny.Set>.Union(_25_emittedFields, Dafny.Set>.FromElements(_30_callName)); + RAST._IType _31_formalType; RAST._IType _out7; - _out7 = (this).GenType(((_25_dtor).dtor_formal).dtor_typ, DCOMP.GenTypeContext.@default()); - _27_formalType = _out7; - Dafny.ISequence _28_cases; - _28_cases = Dafny.Sequence.FromElements(); + _out7 = (this).GenType(((_29_dtor).dtor_formal).dtor_typ, DCOMP.GenTypeContext.@default()); + _31_formalType = _out7; + Dafny.ISequence _32_cases; + _32_cases = Dafny.Sequence.FromElements(); BigInteger _hi4 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _29_k = BigInteger.Zero; _29_k < _hi4; _29_k++) { - DAST._IDatatypeCtor _30_ctor2; - _30_ctor2 = ((c).dtor_ctors).Select(_29_k); - Dafny.ISequence _31_pattern; - _31_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeName((_30_ctor2).dtor_name)); - Dafny.ISequence _32_rhs = Dafny.Sequence.Empty; - Std.Wrappers._IOption> _33_hasMatchingField; - _33_hasMatchingField = Std.Wrappers.Option>.create_None(); - Dafny.ISequence _34_patternInner; - _34_patternInner = Dafny.Sequence.UnicodeFromString(""); - bool _35_isNumeric; - _35_isNumeric = false; - BigInteger _hi5 = new BigInteger(((_30_ctor2).dtor_args).Count); - for (BigInteger _36_l = BigInteger.Zero; _36_l < _hi5; _36_l++) { - DAST._IDatatypeDtor _37_dtor2; - _37_dtor2 = ((_30_ctor2).dtor_args).Select(_36_l); - Dafny.ISequence _38_patternName; - _38_patternName = DCOMP.__default.escapeDtor(((_37_dtor2).dtor_formal).dtor_name); - Dafny.ISequence _39_varName; - _39_varName = DCOMP.__default.escapeField(((_37_dtor2).dtor_formal).dtor_name); - if (((_36_l).Sign == 0) && ((_38_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _35_isNumeric = true; + for (BigInteger _33_k = BigInteger.Zero; _33_k < _hi4; _33_k++) { + DAST._IDatatypeCtor _34_ctor2; + _34_ctor2 = ((c).dtor_ctors).Select(_33_k); + Dafny.ISequence _35_pattern; + _35_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeName((_34_ctor2).dtor_name)); + Dafny.ISequence _36_rhs = Dafny.Sequence.Empty; + Std.Wrappers._IOption> _37_hasMatchingField; + _37_hasMatchingField = Std.Wrappers.Option>.create_None(); + Dafny.ISequence _38_patternInner; + _38_patternInner = Dafny.Sequence.UnicodeFromString(""); + bool _39_isNumeric; + _39_isNumeric = false; + BigInteger _hi5 = new BigInteger(((_34_ctor2).dtor_args).Count); + for (BigInteger _40_l = BigInteger.Zero; _40_l < _hi5; _40_l++) { + DAST._IDatatypeDtor _41_dtor2; + _41_dtor2 = ((_34_ctor2).dtor_args).Select(_40_l); + Dafny.ISequence _42_patternName; + _42_patternName = DCOMP.__default.escapeVar(((_41_dtor2).dtor_formal).dtor_name); + if (((_40_l).Sign == 0) && ((_42_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _39_isNumeric = true; } - if (_35_isNumeric) { - _38_patternName = Std.Wrappers.Option>.GetOr((_37_dtor2).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_36_l))); - _39_varName = _38_patternName; + if (_39_isNumeric) { + _42_patternName = Std.Wrappers.Option>.GetOr((_41_dtor2).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_40_l))); } - if (object.Equals(((_25_dtor).dtor_formal).dtor_name, ((_37_dtor2).dtor_formal).dtor_name)) { - _33_hasMatchingField = Std.Wrappers.Option>.create_Some(_39_varName); + if (object.Equals(((_29_dtor).dtor_formal).dtor_name, ((_41_dtor2).dtor_formal).dtor_name)) { + _37_hasMatchingField = Std.Wrappers.Option>.create_Some(_42_patternName); } - _34_patternInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_34_patternInner, _38_patternName), Dafny.Sequence.UnicodeFromString(", ")); + _38_patternInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_38_patternInner, _42_patternName), Dafny.Sequence.UnicodeFromString(", ")); } - if (_35_isNumeric) { - _31_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_31_pattern, Dafny.Sequence.UnicodeFromString("(")), _34_patternInner), Dafny.Sequence.UnicodeFromString(")")); + if (_39_isNumeric) { + _35_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_35_pattern, Dafny.Sequence.UnicodeFromString("(")), _38_patternInner), Dafny.Sequence.UnicodeFromString(")")); } else { - _31_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_31_pattern, Dafny.Sequence.UnicodeFromString("{")), _34_patternInner), Dafny.Sequence.UnicodeFromString("}")); + _35_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_35_pattern, Dafny.Sequence.UnicodeFromString("{")), _38_patternInner), Dafny.Sequence.UnicodeFromString("}")); } - if ((_33_hasMatchingField).is_Some) { + if ((_37_hasMatchingField).is_Some) { if ((c).dtor_isCo) { - _32_rhs = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Deref::deref(&"), (_33_hasMatchingField).dtor_value), Dafny.Sequence.UnicodeFromString(".0)")); + _36_rhs = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Deref::deref(&"), (_37_hasMatchingField).dtor_value), Dafny.Sequence.UnicodeFromString(".0)")); } else { - _32_rhs = Dafny.Sequence.Concat((_33_hasMatchingField).dtor_value, Dafny.Sequence.UnicodeFromString("")); + _36_rhs = Dafny.Sequence.Concat((_37_hasMatchingField).dtor_value, Dafny.Sequence.UnicodeFromString("")); } } else { - _32_rhs = (this).UnreachablePanicIfVerified(Dafny.Sequence.UnicodeFromString("field does not exist on this variant")); + _36_rhs = (this).UnreachablePanicIfVerified(Dafny.Sequence.UnicodeFromString("field does not exist on this variant")); } - RAST._IMatchCase _40_ctorMatch; - _40_ctorMatch = RAST.MatchCase.create(_31_pattern, RAST.Expr.create_RawExpr(_32_rhs)); - _28_cases = Dafny.Sequence.Concat(_28_cases, Dafny.Sequence.FromElements(_40_ctorMatch)); + RAST._IMatchCase _43_ctorMatch; + _43_ctorMatch = RAST.MatchCase.create(_35_pattern, RAST.Expr.create_RawExpr(_36_rhs)); + _32_cases = Dafny.Sequence.Concat(_32_cases, Dafny.Sequence.FromElements(_43_ctorMatch)); } - if ((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) { - _28_cases = Dafny.Sequence.Concat(_28_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_RawExpr((this).UnreachablePanicIfVerified(Dafny.Sequence.UnicodeFromString("")))))); + if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_18_unusedTypeParams).Count)).Sign == 1)) { + _32_cases = Dafny.Sequence.Concat(_32_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_RawExpr((this).UnreachablePanicIfVerified(Dafny.Sequence.UnicodeFromString("")))))); } - RAST._IExpr _41_methodBody; - _41_methodBody = RAST.Expr.create_Match(RAST.__default.self, _28_cases); - _20_implBody = Dafny.Sequence.Concat(_20_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(_26_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_27_formalType)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_41_methodBody))))); - } - } - } - Dafny.ISequence _42_coerceTypes; - _42_coerceTypes = Dafny.Sequence.FromElements(); - Dafny.ISequence _43_rCoerceTypeParams; - _43_rCoerceTypeParams = Dafny.Sequence.FromElements(); - Dafny.ISequence _44_coerceArguments; - _44_coerceArguments = Dafny.Sequence.FromElements(); - Dafny.IMap _45_coerceMap; - _45_coerceMap = Dafny.Map.FromElements(); - Dafny.IMap _46_rCoerceMap; - _46_rCoerceMap = Dafny.Map.FromElements(); - Dafny.IMap<_System._ITuple2,RAST._IExpr> _47_coerceMapToArg; - _47_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(); + RAST._IExpr _44_methodBody; + _44_methodBody = RAST.Expr.create_Match(RAST.__default.self, _32_cases); + _24_implBody = Dafny.Sequence.Concat(_24_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(_30_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_31_formalType)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_44_methodBody))))); + } + } + } + Dafny.ISequence _45_coerceTypes; + _45_coerceTypes = Dafny.Sequence.FromElements(); + Dafny.ISequence _46_rCoerceTypeParams; + _46_rCoerceTypeParams = Dafny.Sequence.FromElements(); + Dafny.ISequence _47_coerceArguments; + _47_coerceArguments = Dafny.Sequence.FromElements(); + Dafny.IMap _48_coerceMap; + _48_coerceMap = Dafny.Map.FromElements(); + Dafny.IMap _49_rCoerceMap; + _49_rCoerceMap = Dafny.Map.FromElements(); + Dafny.IMap<_System._ITuple2,RAST._IExpr> _50_coerceMapToArg; + _50_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(); if ((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) { - Dafny.ISequence _48_types; - _48_types = Dafny.Sequence.FromElements(); + Dafny.ISequence _51_types; + _51_types = Dafny.Sequence.FromElements(); BigInteger _hi6 = new BigInteger(((c).dtor_typeParams).Count); - for (BigInteger _49_typeI = BigInteger.Zero; _49_typeI < _hi6; _49_typeI++) { - DAST._ITypeArgDecl _50_typeParam; - _50_typeParam = ((c).dtor_typeParams).Select(_49_typeI); - DAST._IType _51_typeArg; - RAST._ITypeParamDecl _52_rTypeParamDecl; + for (BigInteger _52_typeI = BigInteger.Zero; _52_typeI < _hi6; _52_typeI++) { + DAST._ITypeArgDecl _53_typeParam; + _53_typeParam = ((c).dtor_typeParams).Select(_52_typeI); + DAST._IType _54_typeArg; + RAST._ITypeParamDecl _55_rTypeParamDecl; DAST._IType _out8; RAST._ITypeParamDecl _out9; - (this).GenTypeParam(_50_typeParam, out _out8, out _out9); - _51_typeArg = _out8; - _52_rTypeParamDecl = _out9; - RAST._IType _53_rTypeArg; + (this).GenTypeParam(_53_typeParam, out _out8, out _out9); + _54_typeArg = _out8; + _55_rTypeParamDecl = _out9; + RAST._IType _56_rTypeArg; RAST._IType _out10; - _out10 = (this).GenType(_51_typeArg, DCOMP.GenTypeContext.@default()); - _53_rTypeArg = _out10; - _48_types = Dafny.Sequence.Concat(_48_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData")), Dafny.Sequence.FromElements(_53_rTypeArg)))); - if (((_49_typeI) < (new BigInteger((_6_variances).Count))) && (((_6_variances).Select(_49_typeI)).is_Nonvariant)) { - _42_coerceTypes = Dafny.Sequence.Concat(_42_coerceTypes, Dafny.Sequence.FromElements(_53_rTypeArg)); + _out10 = (this).GenType(_54_typeArg, DCOMP.GenTypeContext.@default()); + _56_rTypeArg = _out10; + _51_types = Dafny.Sequence.Concat(_51_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_56_rTypeArg)))); + if (((_52_typeI) < (new BigInteger((_6_variances).Count))) && (((_6_variances).Select(_52_typeI)).is_Nonvariant)) { + _45_coerceTypes = Dafny.Sequence.Concat(_45_coerceTypes, Dafny.Sequence.FromElements(_56_rTypeArg)); goto continue_2_0; } - DAST._ITypeArgDecl _54_coerceTypeParam; - DAST._ITypeArgDecl _55_dt__update__tmp_h0 = _50_typeParam; - Dafny.ISequence _56_dt__update_hname_h0 = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), Std.Strings.__default.OfNat(_49_typeI)); - _54_coerceTypeParam = DAST.TypeArgDecl.create(_56_dt__update_hname_h0, (_55_dt__update__tmp_h0).dtor_bounds, (_55_dt__update__tmp_h0).dtor_variance); - DAST._IType _57_coerceTypeArg; - RAST._ITypeParamDecl _58_rCoerceTypeParamDecl; + DAST._ITypeArgDecl _57_coerceTypeParam; + DAST._ITypeArgDecl _58_dt__update__tmp_h0 = _53_typeParam; + Dafny.ISequence _59_dt__update_hname_h0 = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), Std.Strings.__default.OfNat(_52_typeI)); + _57_coerceTypeParam = DAST.TypeArgDecl.create(_59_dt__update_hname_h0, (_58_dt__update__tmp_h0).dtor_bounds, (_58_dt__update__tmp_h0).dtor_variance); + DAST._IType _60_coerceTypeArg; + RAST._ITypeParamDecl _61_rCoerceTypeParamDecl; DAST._IType _out11; RAST._ITypeParamDecl _out12; - (this).GenTypeParam(_54_coerceTypeParam, out _out11, out _out12); - _57_coerceTypeArg = _out11; - _58_rCoerceTypeParamDecl = _out12; - _45_coerceMap = Dafny.Map.Merge(_45_coerceMap, Dafny.Map.FromElements(new Dafny.Pair(_51_typeArg, _57_coerceTypeArg))); - RAST._IType _59_rCoerceType; + (this).GenTypeParam(_57_coerceTypeParam, out _out11, out _out12); + _60_coerceTypeArg = _out11; + _61_rCoerceTypeParamDecl = _out12; + _48_coerceMap = Dafny.Map.Merge(_48_coerceMap, Dafny.Map.FromElements(new Dafny.Pair(_54_typeArg, _60_coerceTypeArg))); + RAST._IType _62_rCoerceType; RAST._IType _out13; - _out13 = (this).GenType(_57_coerceTypeArg, DCOMP.GenTypeContext.@default()); - _59_rCoerceType = _out13; - _46_rCoerceMap = Dafny.Map.Merge(_46_rCoerceMap, Dafny.Map.FromElements(new Dafny.Pair(_53_rTypeArg, _59_rCoerceType))); - _42_coerceTypes = Dafny.Sequence.Concat(_42_coerceTypes, Dafny.Sequence.FromElements(_59_rCoerceType)); - _43_rCoerceTypeParams = Dafny.Sequence.Concat(_43_rCoerceTypeParams, Dafny.Sequence.FromElements(_58_rCoerceTypeParamDecl)); - Dafny.ISequence _60_coerceFormal; - _60_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_49_typeI)); - _47_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_47_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_53_rTypeArg, _59_rCoerceType), (RAST.Expr.create_Identifier(_60_coerceFormal)).Clone()))); - _44_coerceArguments = Dafny.Sequence.Concat(_44_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_60_coerceFormal, RAST.__default.Rc(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_53_rTypeArg), _59_rCoerceType)), RAST.__default.StaticTrait))))); + _out13 = (this).GenType(_60_coerceTypeArg, DCOMP.GenTypeContext.@default()); + _62_rCoerceType = _out13; + _49_rCoerceMap = Dafny.Map.Merge(_49_rCoerceMap, Dafny.Map.FromElements(new Dafny.Pair(_56_rTypeArg, _62_rCoerceType))); + _45_coerceTypes = Dafny.Sequence.Concat(_45_coerceTypes, Dafny.Sequence.FromElements(_62_rCoerceType)); + _46_rCoerceTypeParams = Dafny.Sequence.Concat(_46_rCoerceTypeParams, Dafny.Sequence.FromElements(_61_rCoerceTypeParamDecl)); + Dafny.ISequence _63_coerceFormal; + _63_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_52_typeI)); + _50_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_50_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_56_rTypeArg, _62_rCoerceType), (RAST.Expr.create_Identifier(_63_coerceFormal)).Clone()))); + _47_coerceArguments = Dafny.Sequence.Concat(_47_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_63_coerceFormal, RAST.__default.Rc(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_56_rTypeArg), _62_rCoerceType)), RAST.__default.StaticTrait))))); continue_2_0: ; } after_2_0: ; - _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_61_tpe) => { - return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _61_tpe); -})), _48_types))))); - } - bool _62_cIsEq; - _62_cIsEq = (this).DatatypeIsEq(c); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(((_62_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _4_datatypeName, _2_rTypeParamsDecls, _5_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams), _3_whereConstraints, _20_implBody))); - Dafny.ISequence _63_printImplBodyCases; - _63_printImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _64_hashImplBodyCases; - _64_hashImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _65_coerceImplBodyCases; - _65_coerceImplBodyCases = Dafny.Sequence.FromElements(); + if ((new BigInteger((_18_unusedTypeParams).Count)).Sign == 1) { + _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_64_tpe) => { + return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _64_tpe); +})), _51_types))))); + } + } + bool _65_cIsEq; + _65_cIsEq = (this).DatatypeIsEq(c); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(((_65_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _4_datatypeName, _2_rTypeParamsDecls, _5_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams), _3_whereConstraints, _24_implBody))); + Dafny.ISequence _66_printImplBodyCases; + _66_printImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _67_hashImplBodyCases; + _67_hashImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _68_coerceImplBodyCases; + _68_coerceImplBodyCases = Dafny.Sequence.FromElements(); BigInteger _hi7 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _66_i = BigInteger.Zero; _66_i < _hi7; _66_i++) { - DAST._IDatatypeCtor _67_ctor; - _67_ctor = ((c).dtor_ctors).Select(_66_i); - Dafny.ISequence _68_ctorMatch; - _68_ctorMatch = DCOMP.__default.escapeName((_67_ctor).dtor_name); - Dafny.ISequence _69_modulePrefix; + for (BigInteger _69_i = BigInteger.Zero; _69_i < _hi7; _69_i++) { + DAST._IDatatypeCtor _70_ctor; + _70_ctor = ((c).dtor_ctors).Select(_69_i); + Dafny.ISequence _71_ctorMatch; + _71_ctorMatch = DCOMP.__default.escapeName((_70_ctor).dtor_name); + Dafny.ISequence _72_modulePrefix; if (((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) { - _69_modulePrefix = Dafny.Sequence.UnicodeFromString(""); + _72_modulePrefix = Dafny.Sequence.UnicodeFromString(""); } else { - _69_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); - } - Dafny.ISequence _70_ctorName; - _70_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_69_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_67_ctor).dtor_name)); - if (((new BigInteger((_70_ctorName).Count)) >= (new BigInteger(13))) && (((_70_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { - _70_ctorName = Dafny.Sequence.UnicodeFromString(""); - } - RAST._IExpr _71_printRhs; - _71_printRhs = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("write!(_formatter, \""), _70_ctorName), (((_67_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(\")?")) : (Dafny.Sequence.UnicodeFromString("\")?"))))); - RAST._IExpr _72_hashRhs; - _72_hashRhs = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); - Dafny.ISequence _73_coerceRhsArgs; - _73_coerceRhsArgs = Dafny.Sequence.FromElements(); - bool _74_isNumeric; - _74_isNumeric = false; - Dafny.ISequence _75_ctorMatchInner; - _75_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); - BigInteger _hi8 = new BigInteger(((_67_ctor).dtor_args).Count); - for (BigInteger _76_j = BigInteger.Zero; _76_j < _hi8; _76_j++) { - DAST._IDatatypeDtor _77_dtor; - _77_dtor = ((_67_ctor).dtor_args).Select(_76_j); - Dafny.ISequence _78_patternName; - _78_patternName = DCOMP.__default.escapeDtor(((_77_dtor).dtor_formal).dtor_name); - Dafny.ISequence _79_fieldName; - _79_fieldName = DCOMP.__default.escapeField(((_77_dtor).dtor_formal).dtor_name); - DAST._IType _80_formalType; - _80_formalType = ((_77_dtor).dtor_formal).dtor_typ; - if (((_76_j).Sign == 0) && ((_79_fieldName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _74_isNumeric = true; - } - if (_74_isNumeric) { - _79_fieldName = Std.Wrappers.Option>.GetOr((_77_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_76_j))); - } - if ((_80_formalType).is_Arrow) { - _72_hashRhs = (_72_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _72_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); + } + Dafny.ISequence _73_ctorName; + _73_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_72_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_70_ctor).dtor_name)); + if (((new BigInteger((_73_ctorName).Count)) >= (new BigInteger(13))) && (((_73_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _73_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _74_printRhs; + _74_printRhs = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("write!(_formatter, \""), _73_ctorName), (((_70_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(\")?")) : (Dafny.Sequence.UnicodeFromString("\")?"))))); + RAST._IExpr _75_hashRhs; + _75_hashRhs = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); + Dafny.ISequence _76_coerceRhsArgs; + _76_coerceRhsArgs = Dafny.Sequence.FromElements(); + bool _77_isNumeric; + _77_isNumeric = false; + Dafny.ISequence _78_ctorMatchInner; + _78_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi8 = new BigInteger(((_70_ctor).dtor_args).Count); + for (BigInteger _79_j = BigInteger.Zero; _79_j < _hi8; _79_j++) { + DAST._IDatatypeDtor _80_dtor; + _80_dtor = ((_70_ctor).dtor_args).Select(_79_j); + Dafny.ISequence _81_patternName; + _81_patternName = DCOMP.__default.escapeVar(((_80_dtor).dtor_formal).dtor_name); + DAST._IType _82_formalType; + _82_formalType = ((_80_dtor).dtor_formal).dtor_typ; + if (((_79_j).Sign == 0) && ((_81_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _77_isNumeric = true; + } + if (_77_isNumeric) { + _81_patternName = Std.Wrappers.Option>.GetOr((_80_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_79_j))); + } + if ((_82_formalType).is_Arrow) { + _75_hashRhs = (_75_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _72_hashRhs = (_72_hashRhs).Then(((RAST.Expr.create_Identifier(_79_fieldName)).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _75_hashRhs = (_75_hashRhs).Then((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).MSel(Dafny.Sequence.UnicodeFromString("hash"))).AsExpr()).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_81_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); } - _75_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_75_ctorMatchInner, ((_74_isNumeric) ? (_79_fieldName) : (_78_patternName))), Dafny.Sequence.UnicodeFromString(", ")); - if ((_76_j).Sign == 1) { - _71_printRhs = (_71_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("write!(_formatter, \", \")?"))); + _78_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_78_ctorMatchInner, _81_patternName), Dafny.Sequence.UnicodeFromString(", ")); + if ((_79_j).Sign == 1) { + _74_printRhs = (_74_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("write!(_formatter, \", \")?"))); } - _71_printRhs = (_71_printRhs).Then(RAST.Expr.create_RawExpr((((_80_formalType).is_Arrow) ? (Dafny.Sequence.UnicodeFromString("write!(_formatter, \"\")?")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyPrint::fmt_print("), _79_fieldName), Dafny.Sequence.UnicodeFromString(", _formatter, false)?")))))); - RAST._IExpr _81_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _82_formalTpe; + _74_printRhs = (_74_printRhs).Then(RAST.Expr.create_RawExpr((((_82_formalType).is_Arrow) ? (Dafny.Sequence.UnicodeFromString("write!(_formatter, \"\")?")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyPrint::fmt_print("), _81_patternName), Dafny.Sequence.UnicodeFromString(", _formatter, false)?")))))); + RAST._IExpr _83_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _84_formalTpe; RAST._IType _out14; - _out14 = (this).GenType(_80_formalType, DCOMP.GenTypeContext.@default()); - _82_formalTpe = _out14; - DAST._IType _83_newFormalType; - _83_newFormalType = (_80_formalType).Replace(_45_coerceMap); - RAST._IType _84_newFormalTpe; - _84_newFormalTpe = (_82_formalTpe).Replace(_46_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _85_upcastConverter; - _85_upcastConverter = (this).UpcastConversionLambda(_80_formalType, _82_formalTpe, _83_newFormalType, _84_newFormalTpe, _47_coerceMapToArg); - if ((_85_upcastConverter).is_Success) { - RAST._IExpr _86_coercionFunction; - _86_coercionFunction = (_85_upcastConverter).dtor_value; - _81_coerceRhsArg = (_86_coercionFunction).Apply1(RAST.Expr.create_Identifier(_78_patternName)); + _out14 = (this).GenType(_82_formalType, DCOMP.GenTypeContext.@default()); + _84_formalTpe = _out14; + DAST._IType _85_newFormalType; + _85_newFormalType = (_82_formalType).Replace(_48_coerceMap); + RAST._IType _86_newFormalTpe; + _86_newFormalTpe = (_84_formalTpe).ReplaceMap(_49_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _87_upcastConverter; + _87_upcastConverter = (this).UpcastConversionLambda(_82_formalType, _84_formalTpe, _85_newFormalType, _86_newFormalTpe, _50_coerceMapToArg); + if ((_87_upcastConverter).is_Success) { + RAST._IExpr _88_coercionFunction; + _88_coercionFunction = (_87_upcastConverter).dtor_value; + _83_coerceRhsArg = (_88_coercionFunction).Apply1(RAST.Expr.create_Identifier(_81_patternName)); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_76_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); - _81_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_79_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + _83_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); } - _73_coerceRhsArgs = Dafny.Sequence.Concat(_73_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_78_patternName, _81_coerceRhsArg))); + _76_coerceRhsArgs = Dafny.Sequence.Concat(_76_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_81_patternName, _83_coerceRhsArg))); } - RAST._IExpr _87_coerceRhs; - _87_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).MSel(DCOMP.__default.escapeName((_67_ctor).dtor_name)), _73_coerceRhsArgs); - if (_74_isNumeric) { - _68_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_68_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _75_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + RAST._IExpr _89_coerceRhs; + _89_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(DCOMP.__default.escapeName((_70_ctor).dtor_name)), _76_coerceRhsArgs); + if (_77_isNumeric) { + _71_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_71_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _78_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); } else { - _68_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_68_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _75_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); - } - if ((_67_ctor).dtor_hasAnyArgs) { - _71_printRhs = (_71_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("write!(_formatter, \")\")?"))); - } - _71_printRhs = (_71_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("Ok(())"))); - _63_printImplBodyCases = Dafny.Sequence.Concat(_63_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _68_ctorMatch), RAST.Expr.create_Block(_71_printRhs)))); - _64_hashImplBodyCases = Dafny.Sequence.Concat(_64_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _68_ctorMatch), RAST.Expr.create_Block(_72_hashRhs)))); - _65_coerceImplBodyCases = Dafny.Sequence.Concat(_65_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _68_ctorMatch), RAST.Expr.create_Block(_87_coerceRhs)))); - } - if ((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) { - Dafny.ISequence _88_extraCases; - _88_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("{"), (this).UnreachablePanicIfVerified(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("}"))))); - _63_printImplBodyCases = Dafny.Sequence.Concat(_63_printImplBodyCases, _88_extraCases); - _64_hashImplBodyCases = Dafny.Sequence.Concat(_64_hashImplBodyCases, _88_extraCases); - _65_coerceImplBodyCases = Dafny.Sequence.Concat(_65_coerceImplBodyCases, _88_extraCases); - } - Dafny.ISequence _89_defaultConstrainedTypeParams; - _89_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - Dafny.ISequence _90_rTypeParamsDeclsWithEq; - _90_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); - Dafny.ISequence _91_rTypeParamsDeclsWithHash; - _91_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - RAST._IExpr _92_printImplBody; - _92_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _63_printImplBodyCases); - RAST._IExpr _93_hashImplBody; - _93_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _64_hashImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Debug")), 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("fmt"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("f"), RAST.Type.create_BorrowedMut(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))))), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).MSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("f")), RAST.Expr.create_LiteralBool(true))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, 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("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__type).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter")))), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_92_printImplBody)))))))); - if ((new BigInteger((_43_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _94_coerceImplBody; - _94_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _65_coerceImplBodyCases); - 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(_4_datatypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), _43_rCoerceTypeParams, _44_coerceArguments, Std.Wrappers.Option.create_Some(RAST.__default.Rc(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams)), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _42_coerceTypes))))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.RcNew(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.Type.create_SelfOwned())), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _42_coerceTypes)), _94_coerceImplBody)))))))))); - } - if (_62_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_90_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(_91_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__type).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hasher"))))), 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(_93_hashImplBody)))))))); + _71_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_71_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _78_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + } + if ((_70_ctor).dtor_hasAnyArgs) { + _74_printRhs = (_74_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("write!(_formatter, \")\")?"))); + } + _74_printRhs = (_74_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("Ok(())"))); + _66_printImplBodyCases = Dafny.Sequence.Concat(_66_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _71_ctorMatch), RAST.Expr.create_Block(_74_printRhs)))); + _67_hashImplBodyCases = Dafny.Sequence.Concat(_67_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _71_ctorMatch), RAST.Expr.create_Block(_75_hashRhs)))); + _68_coerceImplBodyCases = Dafny.Sequence.Concat(_68_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _71_ctorMatch), RAST.Expr.create_Block(_89_coerceRhs)))); + } + if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_18_unusedTypeParams).Count)).Sign == 1)) { + Dafny.ISequence _90_extraCases; + _90_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("{"), (this).UnreachablePanicIfVerified(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("}"))))); + _66_printImplBodyCases = Dafny.Sequence.Concat(_66_printImplBodyCases, _90_extraCases); + _67_hashImplBodyCases = Dafny.Sequence.Concat(_67_hashImplBodyCases, _90_extraCases); + _68_coerceImplBodyCases = Dafny.Sequence.Concat(_68_coerceImplBodyCases, _90_extraCases); + } + Dafny.ISequence _91_defaultConstrainedTypeParams; + _91_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + Dafny.ISequence _92_rTypeParamsDeclsWithEq; + _92_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); + Dafny.ISequence _93_rTypeParamsDeclsWithHash; + _93_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); + RAST._IExpr _94_printImplBody; + _94_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _66_printImplBodyCases); + RAST._IExpr _95_hashImplBody; + _95_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _67_hashImplBodyCases); + 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("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Debug"))).AsType(), 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("fmt"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("f"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType()))), 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"))).MSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).AsExpr()).Apply(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("f")), RAST.Expr.create_LiteralBool(true))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, 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("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_94_printImplBody)))))))); + if ((new BigInteger((_46_rCoerceTypeParams).Count)).Sign == 1) { + RAST._IExpr _96_coerceImplBody; + _96_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _68_coerceImplBodyCases); + 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(_4_datatypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), _46_rCoerceTypeParams, _47_coerceArguments, Std.Wrappers.Option.create_Some(RAST.__default.Rc(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams)), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _45_coerceTypes))))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.RcNew(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _45_coerceTypes)), _96_coerceImplBody)))))))))); + } + if (_65_cIsEq) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_92_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(_93_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(_95_hashImplBody)))))))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _95_structName; - _95_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).MSel(DCOMP.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _96_structAssignments; - _96_structAssignments = Dafny.Sequence.FromElements(); + RAST._IExpr _97_structName; + _97_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(DCOMP.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _98_structAssignments; + _98_structAssignments = Dafny.Sequence.FromElements(); BigInteger _hi9 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _97_i = BigInteger.Zero; _97_i < _hi9; _97_i++) { - DAST._IDatatypeDtor _98_dtor; - _98_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_97_i); - _96_structAssignments = Dafny.Sequence.Concat(_96_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeName(((_98_dtor).dtor_formal).dtor_name), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::default::Default::default()"))))); + for (BigInteger _99_i = BigInteger.Zero; _99_i < _hi9; _99_i++) { + DAST._IDatatypeDtor _100_dtor; + _100_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_99_i); + _98_structAssignments = Dafny.Sequence.Concat(_98_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeVar(((_100_dtor).dtor_formal).dtor_name), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::default::Default::default()"))))); } - Dafny.ISequence _99_defaultConstrainedTypeParams; - _99_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - RAST._IType _100_fullType; - _100_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams); - if (_62_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_99_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _100_fullType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(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(_100_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_95_structName, _96_structAssignments))))))))); + Dafny.ISequence _101_defaultConstrainedTypeParams; + _101_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IType _102_fullType; + _102_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams); + if (_65_cIsEq) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_101_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _102_fullType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(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(_102_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_97_structName, _98_structAssignments))))))))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).Apply1(_100_fullType), RAST.Type.create_Borrowed(_100_fullType), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_SelfOwned()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); + 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("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_102_fullType), RAST.Type.create_Borrowed(_102_fullType), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); } return s; } - public static RAST._IType GenPath(Dafny.ISequence> p) + public static RAST._IPath GenPath(Dafny.ISequence> p, bool escape) { - RAST._IType r = RAST.Type.Default(); + RAST._IPath r = RAST.Path.Default(); if ((new BigInteger((p).Count)).Sign == 0) { - r = RAST.Type.create_SelfOwned(); + r = RAST.Path.create_Self(); return r; } else { if (((((p).Select(BigInteger.Zero)))).Equals(Dafny.Sequence.UnicodeFromString("std"))) { - r = RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("")); + r = RAST.Path.create_Global(); } else if (((((p).Select(BigInteger.Zero)))).Equals(Dafny.Sequence.UnicodeFromString("_System"))) { - r = RAST.__default.dafny__runtime__type; + r = RAST.__default.dafny__runtime; } else { - r = RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("super")); + r = RAST.Path.create_Crate(); } BigInteger _hi0 = new BigInteger((p).Count); for (BigInteger _0_i = BigInteger.Zero; _0_i < _hi0; _0_i++) { - r = (r).MSel(DCOMP.__default.escapeName(((p).Select(_0_i)))); + Dafny.ISequence _1_name; + _1_name = ((p).Select(_0_i)); + if (escape) { + _System._ITuple2>, Dafny.ISequence> _let_tmp_rhs0 = DafnyCompilerRustUtils.__default.DafnyNameToContainingPathAndName(_1_name, Dafny.Sequence>.FromElements()); + Dafny.ISequence> _2_modules = _let_tmp_rhs0.dtor__0; + Dafny.ISequence _3_finalName = _let_tmp_rhs0.dtor__1; + BigInteger _hi1 = new BigInteger((_2_modules).Count); + for (BigInteger _4_j = BigInteger.Zero; _4_j < _hi1; _4_j++) { + r = (r).MSel(DCOMP.__default.escapeName(((_2_modules).Select(_4_j)))); + } + r = (r).MSel(DCOMP.__default.escapeName(_3_finalName)); + } else { + r = (r).MSel(DCOMP.__default.ReplaceDotByDoubleColon((_1_name))); + } } } return r; } - public static RAST._IExpr GenPathExpr(Dafny.ISequence> p) + public static RAST._IType GenPathType(Dafny.ISequence> p) { - RAST._IExpr r = RAST.Expr.Default(); + RAST._IType t = RAST.Type.Default(); + RAST._IPath _0_p; + RAST._IPath _out0; + _out0 = DCOMP.COMP.GenPath(p, true); + _0_p = _out0; + t = (_0_p).AsType(); + return t; + } + public static RAST._IExpr GenPathExpr(Dafny.ISequence> p, bool escape) + { + RAST._IExpr e = RAST.Expr.Default(); if ((new BigInteger((p).Count)).Sign == 0) { - r = RAST.__default.self; - return r; - } else { - if (((((p).Select(BigInteger.Zero)))).Equals(Dafny.Sequence.UnicodeFromString("std"))) { - r = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")); - } else if (((((p).Select(BigInteger.Zero)))).Equals(Dafny.Sequence.UnicodeFromString("_System"))) { - r = RAST.__default.dafny__runtime; - } else { - r = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("super")); - } - BigInteger _hi0 = new BigInteger((p).Count); - for (BigInteger _0_i = BigInteger.Zero; _0_i < _hi0; _0_i++) { - r = (r).MSel(DCOMP.__default.escapeName(((p).Select(_0_i)))); - } + e = RAST.__default.self; + return e; } - return r; + RAST._IPath _0_p; + RAST._IPath _out0; + _out0 = DCOMP.COMP.GenPath(p, escape); + _0_p = _out0; + e = (_0_p).AsExpr(); + return e; } - public Dafny.ISequence GenTypeArgs(Dafny.ISequence args, DCOMP._IGenTypeContext genTypeContext) + public Dafny.ISequence GenTypeArgs(Dafny.ISequence args, bool genTypeContext) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); @@ -1787,7 +2076,7 @@ public static RAST._IExpr GenPathExpr(Dafny.ISequence attributes) { return ((!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("auto-nongrowing-size"), Dafny.Sequence>.FromElements()))) && (!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("false")))))) || ((attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("true"))))); } - public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) + public RAST._IType GenType(DAST._IType c, bool genTypeContext) { RAST._IType s = RAST.Type.Default(); DAST._IType _source0 = c; @@ -1797,11 +2086,11 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) { RAST._IType _1_t; RAST._IType _out0; - _out0 = DCOMP.COMP.GenPath((_0_resolved).dtor_path); + _out0 = DCOMP.COMP.GenPathType((_0_resolved).dtor_path); _1_t = _out0; Dafny.ISequence _2_typeArgs; Dafny.ISequence _out1; - _out1 = (this).GenTypeArgs((_0_resolved).dtor_typeArgs, Dafny.Helpers.Let(genTypeContext, _pat_let9_0 => Dafny.Helpers.Let(_pat_let9_0, _3_dt__update__tmp_h0 => Dafny.Helpers.Let(false, _pat_let10_0 => Dafny.Helpers.Let(_pat_let10_0, _4_dt__update_hforTraitParents_h0 => DCOMP.GenTypeContext.create((_3_dt__update__tmp_h0).dtor_inBinding, (_3_dt__update__tmp_h0).dtor_inFn, _4_dt__update_hforTraitParents_h0)))))); + _out1 = (this).GenTypeArgs((_0_resolved).dtor_typeArgs, false); _2_typeArgs = _out1; s = RAST.Type.create_TypeApp(_1_t, _2_typeArgs); DAST._IResolvedTypeBase _source1 = (_0_resolved).dtor_kind; @@ -1827,9 +2116,9 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) if (_source1.is_Trait) { { if (((_0_resolved).dtor_path).Equals(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("_System"), Dafny.Sequence.UnicodeFromString("object")))) { - s = ((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any")); + s = RAST.__default.AnyTrait; } - if (!((genTypeContext).dtor_forTraitParents)) { + if (!((genTypeContext))) { s = (this).Object(RAST.Type.create_DynType(s)); } } @@ -1837,20 +2126,25 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) } } { - DAST._IType _5_t = _source1.dtor_baseType; - DAST._INewtypeRange _6_range = _source1.dtor_range; - bool _7_erased = _source1.dtor_erase; + DAST._IType _3_base = _source1.dtor_baseType; + DAST._INewtypeRange _4_range = _source1.dtor_range; + bool _5_erased = _source1.dtor_erase; { - if (_7_erased) { - Std.Wrappers._IOption _source2 = DCOMP.COMP.NewtypeToRustType(_5_t, _6_range); + if (_5_erased) { + Std.Wrappers._IOption _source2 = DCOMP.COMP.NewtypeRangeToRustType(_4_range); { if (_source2.is_Some) { - RAST._IType _8_v = _source2.dtor_value; - s = _8_v; + 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, DCOMP.GenTypeContext.@default()); + _7_underlying = _out2; + s = RAST.Type.create_TSynonym(s, _7_underlying); } after_match2: ; } @@ -1864,8 +2158,8 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) { if (_source0.is_Object) { { - s = ((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any")); - if (!((genTypeContext).dtor_forTraitParents)) { + s = RAST.__default.AnyTrait; + if (!((genTypeContext))) { s = (this).Object(RAST.Type.create_DynType(s)); } } @@ -1874,24 +2168,24 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) } { if (_source0.is_Tuple) { - Dafny.ISequence _9_types = _source0.dtor_Tuple_a0; + Dafny.ISequence _8_types = _source0.dtor_Tuple_a0; { - Dafny.ISequence _10_args; - _10_args = Dafny.Sequence.FromElements(); - BigInteger _11_i; - _11_i = BigInteger.Zero; - while ((_11_i) < (new BigInteger((_9_types).Count))) { - RAST._IType _12_generated; - RAST._IType _out2; - _out2 = (this).GenType((_9_types).Select(_11_i), Dafny.Helpers.Let(genTypeContext, _pat_let11_0 => Dafny.Helpers.Let(_pat_let11_0, _13_dt__update__tmp_h1 => Dafny.Helpers.Let(false, _pat_let12_0 => Dafny.Helpers.Let(_pat_let12_0, _14_dt__update_hforTraitParents_h1 => DCOMP.GenTypeContext.create((_13_dt__update__tmp_h1).dtor_inBinding, (_13_dt__update__tmp_h1).dtor_inFn, _14_dt__update_hforTraitParents_h1)))))); - _12_generated = _out2; - _10_args = Dafny.Sequence.Concat(_10_args, Dafny.Sequence.FromElements(_12_generated)); - _11_i = (_11_i) + (BigInteger.One); + 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((_9_types).Count)) <= (RAST.__default.MAX__TUPLE__SIZE)) { - s = RAST.Type.create_TupleType(_10_args); + if ((new BigInteger((_8_types).Count)) <= (RAST.__default.MAX__TUPLE__SIZE)) { + s = RAST.Type.create_TupleType(_9_args); } else { - s = RAST.__default.SystemTupleType(_10_args); + s = RAST.__default.SystemTupleType(_9_args); } } goto after_match0; @@ -1899,23 +2193,23 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) } { if (_source0.is_Array) { - DAST._IType _15_element = _source0.dtor_element; - BigInteger _16_dims = _source0.dtor_dims; + DAST._IType _12_element = _source0.dtor_element; + BigInteger _13_dims = _source0.dtor_dims; { - if ((_16_dims) > (new BigInteger(16))) { + if ((_13_dims) > (new BigInteger(16))) { s = RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("Array of dimensions greater than 16")); } else { - RAST._IType _17_elem; - RAST._IType _out3; - _out3 = (this).GenType(_15_element, Dafny.Helpers.Let(genTypeContext, _pat_let13_0 => Dafny.Helpers.Let(_pat_let13_0, _18_dt__update__tmp_h2 => Dafny.Helpers.Let(false, _pat_let14_0 => Dafny.Helpers.Let(_pat_let14_0, _19_dt__update_hforTraitParents_h2 => DCOMP.GenTypeContext.create((_18_dt__update__tmp_h2).dtor_inBinding, (_18_dt__update__tmp_h2).dtor_inFn, _19_dt__update_hforTraitParents_h2)))))); - _17_elem = _out3; - if ((_16_dims) == (BigInteger.One)) { - s = RAST.Type.create_Array(_17_elem, Std.Wrappers.Option>.create_None()); + 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()); s = (this).Object(s); } else { - Dafny.ISequence _20_n; - _20_n = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array"), Std.Strings.__default.OfNat(_16_dims)); - s = ((RAST.__default.dafny__runtime__type).MSel(_20_n)).Apply(Dafny.Sequence.FromElements(_17_elem)); + 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)); s = (this).Object(s); } } @@ -1925,114 +2219,114 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) } { if (_source0.is_Seq) { - DAST._IType _21_element = _source0.dtor_element; + DAST._IType _16_element = _source0.dtor_element; { - RAST._IType _22_elem; - RAST._IType _out4; - _out4 = (this).GenType(_21_element, Dafny.Helpers.Let(genTypeContext, _pat_let15_0 => Dafny.Helpers.Let(_pat_let15_0, _23_dt__update__tmp_h3 => Dafny.Helpers.Let(false, _pat_let16_0 => Dafny.Helpers.Let(_pat_let16_0, _24_dt__update_hforTraitParents_h3 => DCOMP.GenTypeContext.create((_23_dt__update__tmp_h3).dtor_inBinding, (_23_dt__update__tmp_h3).dtor_inFn, _24_dt__update_hforTraitParents_h3)))))); - _22_elem = _out4; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Sequence")), Dafny.Sequence.FromElements(_22_elem)); + 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 _25_element = _source0.dtor_element; + DAST._IType _18_element = _source0.dtor_element; { - RAST._IType _26_elem; - RAST._IType _out5; - _out5 = (this).GenType(_25_element, Dafny.Helpers.Let(genTypeContext, _pat_let17_0 => Dafny.Helpers.Let(_pat_let17_0, _27_dt__update__tmp_h4 => Dafny.Helpers.Let(false, _pat_let18_0 => Dafny.Helpers.Let(_pat_let18_0, _28_dt__update_hforTraitParents_h4 => DCOMP.GenTypeContext.create((_27_dt__update__tmp_h4).dtor_inBinding, (_27_dt__update__tmp_h4).dtor_inFn, _28_dt__update_hforTraitParents_h4)))))); - _26_elem = _out5; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Set")), Dafny.Sequence.FromElements(_26_elem)); + 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)); } goto after_match0; } } { if (_source0.is_Multiset) { - DAST._IType _29_element = _source0.dtor_element; + DAST._IType _20_element = _source0.dtor_element; { - RAST._IType _30_elem; - RAST._IType _out6; - _out6 = (this).GenType(_29_element, Dafny.Helpers.Let(genTypeContext, _pat_let19_0 => Dafny.Helpers.Let(_pat_let19_0, _31_dt__update__tmp_h5 => Dafny.Helpers.Let(false, _pat_let20_0 => Dafny.Helpers.Let(_pat_let20_0, _32_dt__update_hforTraitParents_h5 => DCOMP.GenTypeContext.create((_31_dt__update__tmp_h5).dtor_inBinding, (_31_dt__update__tmp_h5).dtor_inFn, _32_dt__update_hforTraitParents_h5)))))); - _30_elem = _out6; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Multiset")), Dafny.Sequence.FromElements(_30_elem)); + 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)); } goto after_match0; } } { if (_source0.is_Map) { - DAST._IType _33_key = _source0.dtor_key; - DAST._IType _34_value = _source0.dtor_value; + DAST._IType _22_key = _source0.dtor_key; + DAST._IType _23_value = _source0.dtor_value; { - RAST._IType _35_keyType; - RAST._IType _out7; - _out7 = (this).GenType(_33_key, Dafny.Helpers.Let(genTypeContext, _pat_let21_0 => Dafny.Helpers.Let(_pat_let21_0, _36_dt__update__tmp_h6 => Dafny.Helpers.Let(false, _pat_let22_0 => Dafny.Helpers.Let(_pat_let22_0, _37_dt__update_hforTraitParents_h6 => DCOMP.GenTypeContext.create((_36_dt__update__tmp_h6).dtor_inBinding, (_36_dt__update__tmp_h6).dtor_inFn, _37_dt__update_hforTraitParents_h6)))))); - _35_keyType = _out7; - RAST._IType _38_valueType; + RAST._IType _24_keyType; RAST._IType _out8; - _out8 = (this).GenType(_34_value, genTypeContext); - _38_valueType = _out8; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Map")), Dafny.Sequence.FromElements(_35_keyType, _38_valueType)); + _out8 = (this).GenType(_22_key, false); + _24_keyType = _out8; + RAST._IType _25_valueType; + 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)); } goto after_match0; } } { if (_source0.is_MapBuilder) { - DAST._IType _39_key = _source0.dtor_key; - DAST._IType _40_value = _source0.dtor_value; + DAST._IType _26_key = _source0.dtor_key; + DAST._IType _27_value = _source0.dtor_value; { - RAST._IType _41_keyType; - RAST._IType _out9; - _out9 = (this).GenType(_39_key, Dafny.Helpers.Let(genTypeContext, _pat_let23_0 => Dafny.Helpers.Let(_pat_let23_0, _42_dt__update__tmp_h7 => Dafny.Helpers.Let(false, _pat_let24_0 => Dafny.Helpers.Let(_pat_let24_0, _43_dt__update_hforTraitParents_h7 => DCOMP.GenTypeContext.create((_42_dt__update__tmp_h7).dtor_inBinding, (_42_dt__update__tmp_h7).dtor_inFn, _43_dt__update_hforTraitParents_h7)))))); - _41_keyType = _out9; - RAST._IType _44_valueType; + RAST._IType _28_keyType; RAST._IType _out10; - _out10 = (this).GenType(_40_value, genTypeContext); - _44_valueType = _out10; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder")), Dafny.Sequence.FromElements(_41_keyType, _44_valueType)); + _out10 = (this).GenType(_26_key, false); + _28_keyType = _out10; + RAST._IType _29_valueType; + 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)); } goto after_match0; } } { if (_source0.is_SetBuilder) { - DAST._IType _45_elem = _source0.dtor_element; + DAST._IType _30_elem = _source0.dtor_element; { - RAST._IType _46_elemType; - RAST._IType _out11; - _out11 = (this).GenType(_45_elem, Dafny.Helpers.Let(genTypeContext, _pat_let25_0 => Dafny.Helpers.Let(_pat_let25_0, _47_dt__update__tmp_h8 => Dafny.Helpers.Let(false, _pat_let26_0 => Dafny.Helpers.Let(_pat_let26_0, _48_dt__update_hforTraitParents_h8 => DCOMP.GenTypeContext.create((_47_dt__update__tmp_h8).dtor_inBinding, (_47_dt__update__tmp_h8).dtor_inFn, _48_dt__update_hforTraitParents_h8)))))); - _46_elemType = _out11; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder")), Dafny.Sequence.FromElements(_46_elemType)); + 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)); } goto after_match0; } } { if (_source0.is_Arrow) { - Dafny.ISequence _49_args = _source0.dtor_args; - DAST._IType _50_result = _source0.dtor_result; + Dafny.ISequence _32_args = _source0.dtor_args; + DAST._IType _33_result = _source0.dtor_result; { - Dafny.ISequence _51_argTypes; - _51_argTypes = Dafny.Sequence.FromElements(); - BigInteger _52_i; - _52_i = BigInteger.Zero; - while ((_52_i) < (new BigInteger((_49_args).Count))) { - RAST._IType _53_generated; - RAST._IType _out12; - _out12 = (this).GenType((_49_args).Select(_52_i), Dafny.Helpers.Let(genTypeContext, _pat_let27_0 => Dafny.Helpers.Let(_pat_let27_0, _54_dt__update__tmp_h9 => Dafny.Helpers.Let(false, _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _55_dt__update_hforTraitParents_h9 => Dafny.Helpers.Let(true, _pat_let29_0 => Dafny.Helpers.Let(_pat_let29_0, _56_dt__update_hinFn_h0 => DCOMP.GenTypeContext.create((_54_dt__update__tmp_h9).dtor_inBinding, _56_dt__update_hinFn_h0, _55_dt__update_hforTraitParents_h9)))))))); - _53_generated = _out12; - _51_argTypes = Dafny.Sequence.Concat(_51_argTypes, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(_53_generated))); - _52_i = (_52_i) + (BigInteger.One); + 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 _57_resultType; - RAST._IType _out13; - _out13 = (this).GenType(_50_result, DCOMP.GenTypeContext.create(((genTypeContext).dtor_inFn) || ((genTypeContext).dtor_inBinding), false, false)); - _57_resultType = _out13; - s = RAST.__default.Rc(RAST.Type.create_DynType(RAST.Type.create_FnType(_51_argTypes, _57_resultType))); + RAST._IType _37_resultType; + RAST._IType _out14; + _out14 = (this).GenType(_33_result, DCOMP.GenTypeContext.@default()); + _37_resultType = _out14; + s = RAST.__default.Rc(RAST.Type.create_DynType(RAST.Type.create_FnType(_34_argTypes, _37_resultType))); } goto after_match0; } @@ -2040,31 +2334,31 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) { if (_source0.is_TypeArg) { Dafny.ISequence _h90 = _source0.dtor_TypeArg_a0; - Dafny.ISequence _58_name = _h90; - s = RAST.Type.create_TIdentifier(DCOMP.__default.escapeName(_58_name)); + Dafny.ISequence _38_name = _h90; + s = RAST.Type.create_TIdentifier(DCOMP.__default.escapeName(_38_name)); goto after_match0; } } { if (_source0.is_Primitive) { - DAST._IPrimitive _59_p = _source0.dtor_Primitive_a0; + DAST._IPrimitive _39_p = _source0.dtor_Primitive_a0; { - DAST._IPrimitive _source3 = _59_p; + DAST._IPrimitive _source3 = _39_p; { if (_source3.is_Int) { - s = (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt")); + s = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt"))).AsType(); goto after_match3; } } { if (_source3.is_Real) { - s = (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("BigRational")); + s = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("BigRational"))).AsType(); goto after_match3; } } { if (_source3.is_String) { - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Sequence")), Dafny.Sequence.FromElements((RAST.__default.dafny__runtime__type).MSel((this).DafnyChar))); + 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; } } @@ -2075,7 +2369,7 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) } } { - s = (RAST.__default.dafny__runtime__type).MSel((this).DafnyChar); + s = ((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsType(); } after_match3: ; } @@ -2083,8 +2377,8 @@ public RAST._IType GenType(DAST._IType c, DCOMP._IGenTypeContext genTypeContext) } } { - Dafny.ISequence _60_v = _source0.dtor_Passthrough_a0; - s = RAST.__default.RawType(_60_v); + Dafny.ISequence _40_v = _source0.dtor_Passthrough_a0; + s = RAST.__default.RawType(_40_v); } after_match0: ; return s; @@ -2142,7 +2436,7 @@ public void GenClassImplBody(Dafny.ISequence body, bool forTrait, after_match0: ; } } - public Dafny.ISequence GenParams(Dafny.ISequence @params) + public Dafny.ISequence GenParams(Dafny.ISequence @params, bool forLambda) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); @@ -2154,10 +2448,10 @@ public void GenClassImplBody(Dafny.ISequence body, bool forTrait, RAST._IType _out0; _out0 = (this).GenType((_1_param).dtor_typ, DCOMP.GenTypeContext.@default()); _2_paramType = _out0; - if ((!((_2_paramType).CanReadWithoutClone())) && (!((_1_param).dtor_attributes).Contains(DCOMP.__default.AttributeOwned))) { + if (((!((_2_paramType).CanReadWithoutClone())) || (forLambda)) && (!((_1_param).dtor_attributes).Contains(DCOMP.__default.AttributeOwned))) { _2_paramType = RAST.Type.create_Borrowed(_2_paramType); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.Formal.create(DCOMP.__default.escapeName((_1_param).dtor_name), _2_paramType))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.Formal.create(DCOMP.__default.escapeVar((_1_param).dtor_name), _2_paramType))); } return s; } @@ -2166,7 +2460,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e RAST._IImplMember s = RAST.ImplMember.Default(); Dafny.ISequence _0_params; Dafny.ISequence _out0; - _out0 = (this).GenParams((m).dtor_params); + _out0 = (this).GenParams((m).dtor_params, false); _0_params = _out0; Dafny.ISequence> _1_paramNames; _1_paramNames = Dafny.Sequence>.FromElements(); @@ -2199,7 +2493,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e { if (_source0.is_UserDefined) { DAST._IResolvedType _11_r = _source0.dtor_resolved; - _10_instanceType = DAST.Type.create_UserDefined(Dafny.Helpers.Let(_11_r, _pat_let30_0 => Dafny.Helpers.Let(_pat_let30_0, _12_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let_tv0, _pat_let31_0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let31_0, _13_dt__update_htypeArgs_h0 => DAST.ResolvedType.create((_12_dt__update__tmp_h0).dtor_path, _13_dt__update_htypeArgs_h0, (_12_dt__update__tmp_h0).dtor_kind, (_12_dt__update__tmp_h0).dtor_attributes, (_12_dt__update__tmp_h0).dtor_properMethods, (_12_dt__update__tmp_h0).dtor_extendedTypes)))))); + _10_instanceType = DAST.Type.create_UserDefined(Dafny.Helpers.Let(_11_r, _pat_let20_0 => Dafny.Helpers.Let(_pat_let20_0, _12_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let_tv0, _pat_let21_0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let21_0, _13_dt__update_htypeArgs_h0 => DAST.ResolvedType.create((_12_dt__update__tmp_h0).dtor_path, _13_dt__update_htypeArgs_h0, (_12_dt__update__tmp_h0).dtor_kind, (_12_dt__update__tmp_h0).dtor_attributes, (_12_dt__update__tmp_h0).dtor_properMethods, (_12_dt__update__tmp_h0).dtor_extendedTypes)))))); goto after_match0; } } @@ -2209,7 +2503,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e after_match0: ; if (forTrait) { RAST._IFormal _14_selfFormal; - if ((m).dtor_wasFunction) { + if (((m).dtor_wasFunction) && (((this).ObjectType).is_RawPointers)) { _14_selfFormal = RAST.Formal.selfBorrowed; } else { _14_selfFormal = RAST.Formal.selfBorrowedMut; @@ -2221,19 +2515,21 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e _out1 = (this).GenType(_10_instanceType, DCOMP.GenTypeContext.@default()); _15_tpe = _out1; if ((_9_selfId).Equals(Dafny.Sequence.UnicodeFromString("this"))) { - _15_tpe = RAST.Type.create_Borrowed(_15_tpe); + if (((this).ObjectType).is_RcMut) { + _15_tpe = RAST.Type.create_Borrowed(_15_tpe); + } } else if ((_9_selfId).Equals(Dafny.Sequence.UnicodeFromString("self"))) { if ((_15_tpe).IsObjectOrPointer()) { - if ((m).dtor_wasFunction) { + if (((m).dtor_wasFunction) && (((this).ObjectType).is_RawPointers)) { _15_tpe = RAST.__default.SelfBorrowed; } else { _15_tpe = RAST.__default.SelfBorrowedMut; } } 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.Type.create_SelfOwned())); + _15_tpe = RAST.Type.create_Borrowed(RAST.__default.Rc(RAST.__default.SelfOwned)); } else { - _15_tpe = RAST.Type.create_Borrowed(RAST.Type.create_SelfOwned()); + _15_tpe = RAST.Type.create_Borrowed(RAST.__default.SelfOwned); } } } @@ -2282,8 +2578,8 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e _25_typeArg = _out3; _26_rTypeParamDecl = _out4; RAST._ITypeParamDecl _27_dt__update__tmp_h1 = _26_rTypeParamDecl; - Dafny.ISequence _28_dt__update_hconstraints_h0 = Dafny.Sequence.Concat((_26_rTypeParamDecl).dtor_constraints, Dafny.Sequence.FromElements(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default")))); - _26_rTypeParamDecl = RAST.TypeParamDecl.create((_27_dt__update__tmp_h1).dtor_content, _28_dt__update_hconstraints_h0); + 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)); } } @@ -2310,7 +2606,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e Dafny.ISequence _37_outVar; _37_outVar = (_35_outVars).Select(_36_outI); Dafny.ISequence _38_outName; - _38_outName = DCOMP.__default.escapeName((_37_outVar)); + _38_outName = DCOMP.__default.escapeVar(_37_outVar); Dafny.ISequence _39_tracker__name; _39_tracker__name = DCOMP.__default.AddAssignedPrefix(_38_outName); _32_preAssignNames = Dafny.Sequence>.Concat(_32_preAssignNames, Dafny.Sequence>.FromElements(_39_tracker__name)); @@ -2329,7 +2625,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e _out5 = (this).GenType(((m).dtor_outTypes).Select(_41_outI), DCOMP.GenTypeContext.@default()); _43_outType = _out5; Dafny.ISequence _44_outName; - _44_outName = DCOMP.__default.escapeName((_42_outVar)); + _44_outName = DCOMP.__default.escapeVar(_42_outVar); _1_paramNames = Dafny.Sequence>.Concat(_1_paramNames, Dafny.Sequence>.FromElements(_44_outName)); RAST._IType _45_outMaybeType; if ((_43_outType).CanReadWithoutClone()) { @@ -2351,15 +2647,15 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e after_match1: ; _30_env = DCOMP.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___v69; - DCOMP._IEnvironment _48___v70; + Dafny.ISet> _47___v71; + DCOMP._IEnvironment _48___v72; RAST._IExpr _out6; Dafny.ISet> _out7; DCOMP._IEnvironment _out8; (this).GenStmts((m).dtor_body, _8_selfIdent, _30_env, true, _34_earlyReturn, out _out6, out _out7, out _out8); _46_body = _out6; - _47___v69 = _out7; - _48___v70 = _out8; + _47___v71 = _out7; + _48___v72 = _out8; _29_fBody = Std.Wrappers.Option.create_Some((_31_preBody).Then(_46_body)); } else { _30_env = DCOMP.Environment.create(_1_paramNames, _2_paramTypes); @@ -2398,8 +2694,7 @@ public void GenStmts(Dafny.ISequence stmts, DCOMP._ISelfInfo s if (_source1.is_Assign) { DAST._IAssignLhs lhs0 = _source1.dtor_lhs; if (lhs0.is_Ident) { - Dafny.ISequence ident0 = lhs0.dtor_ident; - Dafny.ISequence _6_name2 = ident0; + Dafny.ISequence _6_name2 = lhs0.dtor_ident; DAST._IExpression _7_rhs = _source1.dtor_value; if (object.Equals(_6_name2, _4_name)) { _2_stmts = Dafny.Sequence.Concat(Dafny.Sequence.Concat((_2_stmts).Subsequence(BigInteger.Zero, _1_i), Dafny.Sequence.FromElements(DAST.Statement.create_DeclareVar(_4_name, _5_optType, Std.Wrappers.Option.create_Some(_7_rhs)))), (_2_stmts).Drop((_1_i) + (new BigInteger(2)))); @@ -2436,7 +2731,7 @@ public void GenStmts(Dafny.ISequence stmts, DCOMP._ISelfInfo s if (_source2.is_DeclareVar) { Dafny.ISequence _11_name = _source2.dtor_name; { - _0_declarations = Dafny.Set>.Union(_0_declarations, Dafny.Set>.FromElements(DCOMP.__default.escapeName(_11_name))); + _0_declarations = Dafny.Set>.Union(_0_declarations, Dafny.Set>.FromElements(DCOMP.__default.escapeVar(_11_name))); } goto after_match2; } @@ -2464,11 +2759,10 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, DCOMP._ISelfInfo DAST._IAssignLhs _source0 = lhs; { if (_source0.is_Ident) { - Dafny.ISequence ident0 = _source0.dtor_ident; - Dafny.ISequence _0_id = ident0; + Dafny.ISequence _0_id = _source0.dtor_ident; { Dafny.ISequence _1_idRust; - _1_idRust = DCOMP.__default.escapeName(_0_id); + _1_idRust = DCOMP.__default.escapeVar(_0_id); if (((env).IsBorrowed(_1_idRust)) || ((env).IsBorrowedMut(_1_idRust))) { generated = RAST.__default.AssignVar(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("*"), _1_idRust), rhs); } else { @@ -2486,7 +2780,7 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, DCOMP._ISelfInfo Dafny.ISequence _3_field = _source0.dtor_field; { Dafny.ISequence _4_fieldName; - _4_fieldName = DCOMP.__default.escapeName(_3_field); + _4_fieldName = DCOMP.__default.escapeVar(_3_field); RAST._IExpr _5_onExpr; DCOMP._IOwnership _6_onOwned; Dafny.ISet> _7_recIdents; @@ -2537,7 +2831,7 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, DCOMP._ISelfInfo Dafny.ISequence _8_isAssignedVar; _8_isAssignedVar = DCOMP.__default.AddAssignedPrefix(_4_fieldName); if (((newEnv).dtor_names).Contains(_8_isAssignedVar)) { - generated = ((RAST.__default.dafny__runtime).MSel((this).update__field__uninit__macro)).Apply(Dafny.Sequence.FromElements((this).thisInConstructor, RAST.Expr.create_Identifier(_4_fieldName), RAST.Expr.create_Identifier(_8_isAssignedVar), rhs)); + generated = (((RAST.__default.dafny__runtime).MSel((this).update__field__uninit__macro)).AsExpr()).Apply(Dafny.Sequence.FromElements((this).thisInConstructor, RAST.Expr.create_Identifier(_4_fieldName), RAST.Expr.create_Identifier(_8_isAssignedVar), rhs)); newEnv = (newEnv).RemoveAssigned(_8_isAssignedVar); } else { (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Unespected field to assign whose isAssignedVar is not in the environment: "), _8_isAssignedVar)); @@ -2582,14 +2876,14 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, DCOMP._ISelfInfo BigInteger _hi0 = new BigInteger((_10_indices).Count); for (BigInteger _16_i = BigInteger.Zero; _16_i < _hi0; _16_i++) { RAST._IExpr _17_idx; - DCOMP._IOwnership _18___v79; + DCOMP._IOwnership _18___v81; Dafny.ISet> _19_recIdentsIdx; RAST._IExpr _out6; DCOMP._IOwnership _out7; Dafny.ISet> _out8; (this).GenExpr((_10_indices).Select(_16_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); _17_idx = _out6; - _18___v79 = _out7; + _18___v81 = _out7; _19_recIdentsIdx = _out8; Dafny.ISequence _20_varName; _20_varName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("__idx"), Std.Strings.__default.OfNat(_16_i)); @@ -2600,13 +2894,7 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, DCOMP._ISelfInfo if ((new BigInteger((_10_indices).Count)) > (BigInteger.One)) { _11_onExpr = (_11_onExpr).Sel(Dafny.Sequence.UnicodeFromString("data")); } - RAST._IExpr _21_rhs; - _21_rhs = rhs; - var _pat_let_tv0 = env; - if (((_11_onExpr).IsLhsIdentifier()) && (Dafny.Helpers.Let, bool>((_11_onExpr).LhsIdentifierName(), _pat_let32_0 => Dafny.Helpers.Let, bool>(_pat_let32_0, _22_name => (true) && (Dafny.Helpers.Let, bool>((_pat_let_tv0).GetType(_22_name), _pat_let33_0 => Dafny.Helpers.Let, bool>(_pat_let33_0, _23_tpe => ((_23_tpe).is_Some) && (((_23_tpe).dtor_value).IsUninitArray())))))))) { - _21_rhs = RAST.__default.MaybeUninitNew(_21_rhs); - } - generated = (_14_r).Then(RAST.Expr.create_Assign(Std.Wrappers.Option.create_Some(RAST.AssignLhs.create_Index(_11_onExpr, _15_indicesExpr)), _21_rhs)); + generated = (_14_r).Then(RAST.Expr.create_Assign(Std.Wrappers.Option.create_Some(RAST.AssignLhs.create_Index(_11_onExpr, _15_indicesExpr)), rhs)); needsIIFE = true; } } @@ -2630,7 +2918,7 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE DAST._IFormal _2_field; _2_field = (_0_fields).Select(_1_i); Dafny.ISequence _3_fieldName; - _3_fieldName = DCOMP.__default.escapeName((_2_field).dtor_name); + _3_fieldName = DCOMP.__default.escapeVar((_2_field).dtor_name); RAST._IType _4_fieldTyp; RAST._IType _out0; _out0 = (this).GenType((_2_field).dtor_typ, DCOMP.GenTypeContext.@default()); @@ -2639,17 +2927,17 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE _5_isAssignedVar = DCOMP.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - DCOMP._IOwnership _7___v80; - Dafny.ISet> _8___v81; + DCOMP._IOwnership _7___v82; + Dafny.ISet> _8___v83; RAST._IExpr _out1; DCOMP._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue((_2_field).dtor_typ), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v80 = _out2; - _8___v81 = _out3; + _7___v82 = _out2; + _8___v83 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); - generated = (generated).Then(((RAST.__default.dafny__runtime).MSel((this).update__field__if__uninit__macro)).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), RAST.Expr.create_Identifier(_3_fieldName), RAST.Expr.create_Identifier(_5_isAssignedVar), _6_rhs))); + generated = (generated).Then((((RAST.__default.dafny__runtime).MSel((this).update__field__if__uninit__macro)).AsExpr()).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), RAST.Expr.create_Identifier(_3_fieldName), RAST.Expr.create_Identifier(_5_isAssignedVar), _6_rhs))); newEnv = (newEnv).RemoveAssigned(_5_isAssignedVar); } } @@ -2667,14 +2955,14 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE { RAST._IType _12_tpe; RAST._IType _out4; - _out4 = (this).GenType(_10_typ, DCOMP.GenTypeContext.InBinding()); + _out4 = (this).GenType(_10_typ, DCOMP.GenTypeContext.@default()); _12_tpe = _out4; Dafny.ISequence _13_varName; - _13_varName = DCOMP.__default.escapeName(_9_name); + _13_varName = DCOMP.__default.escapeVar(_9_name); bool _14_hasCopySemantics; _14_hasCopySemantics = (_12_tpe).CanReadWithoutClone(); if (((_11_expression).is_InitializationValue) && (!(_14_hasCopySemantics))) { - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _13_varName, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MaybePlacebo"))).ApplyType1(_12_tpe)).MSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements()))); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _13_varName, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((((RAST.__default.MaybePlaceboPath).AsExpr()).ApplyType1(_12_tpe)).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements()))); readIdents = Dafny.Set>.FromElements(); newEnv = (env).AddAssigned(_13_varName, RAST.__default.MaybePlaceboType(_12_tpe)); } else { @@ -2699,8 +2987,8 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE } else { _12_tpe = _12_tpe; } - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), DCOMP.__default.escapeName(_9_name), Std.Wrappers.Option.create_Some(_12_tpe), Std.Wrappers.Option.create_Some(_15_expr)); - newEnv = (env).AddAssigned(DCOMP.__default.escapeName(_9_name), _12_tpe); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _13_varName, Std.Wrappers.Option.create_Some(_12_tpe), Std.Wrappers.Option.create_Some(_15_expr)); + newEnv = (env).AddAssigned(_13_varName, _12_tpe); } } goto after_match0; @@ -2734,18 +3022,18 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE DAST._IExpression _22_expression = _source0.dtor_value; { RAST._IExpr _23_exprGen; - DCOMP._IOwnership _24___v82; + DCOMP._IOwnership _24___v84; Dafny.ISet> _25_exprIdents; RAST._IExpr _out11; DCOMP._IOwnership _out12; Dafny.ISet> _out13; (this).GenExpr(_22_expression, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out11, out _out12, out _out13); _23_exprGen = _out11; - _24___v82 = _out12; + _24___v84 = _out12; _25_exprIdents = _out13; if ((_21_lhs).is_Ident) { Dafny.ISequence _26_rustId; - _26_rustId = DCOMP.__default.escapeName(((_21_lhs).dtor_ident)); + _26_rustId = DCOMP.__default.escapeVar((_21_lhs).dtor_ident); Std.Wrappers._IOption _27_tpe; _27_tpe = (env).GetType(_26_rustId); if (((_27_tpe).is_Some) && ((((_27_tpe).dtor_value).ExtractMaybePlacebo()).is_Some)) { @@ -2754,7 +3042,7 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE } if (((_21_lhs).is_Index) && (((_21_lhs).dtor_expr).is_Ident)) { Dafny.ISequence _28_rustId; - _28_rustId = DCOMP.__default.escapeName(((_21_lhs).dtor_expr).dtor_name); + _28_rustId = DCOMP.__default.escapeVar(((_21_lhs).dtor_expr).dtor_name); Std.Wrappers._IOption _29_tpe; _29_tpe = (env).GetType(_28_rustId); if (((_29_tpe).is_Some) && ((((_29_tpe).dtor_value).ExtractMaybeUninitArrayElement()).is_Some)) { @@ -2791,14 +3079,14 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE Dafny.ISequence _36_elsDafny = _source0.dtor_els; { RAST._IExpr _37_cond; - DCOMP._IOwnership _38___v83; + DCOMP._IOwnership _38___v85; Dafny.ISet> _39_recIdents; RAST._IExpr _out18; DCOMP._IOwnership _out19; Dafny.ISet> _out20; (this).GenExpr(_34_cond, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out18, out _out19, out _out20); _37_cond = _out18; - _38___v83 = _out19; + _38___v85 = _out19; _39_recIdents = _out20; Dafny.ISequence _40_condString; _40_condString = (_37_cond)._ToString(DCOMP.__default.IND); @@ -2859,14 +3147,14 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE Dafny.ISequence _53_body = _source0.dtor_body; { RAST._IExpr _54_cond; - DCOMP._IOwnership _55___v84; + DCOMP._IOwnership _55___v86; Dafny.ISet> _56_recIdents; RAST._IExpr _out30; DCOMP._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr(_52_cond, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _54_cond = _out30; - _55___v84 = _out31; + _55___v86 = _out31; _56_recIdents = _out32; readIdents = _56_recIdents; RAST._IExpr _57_bodyExpr; @@ -2894,14 +3182,14 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE Dafny.ISequence _63_body = _source0.dtor_body; { RAST._IExpr _64_over; - DCOMP._IOwnership _65___v85; + DCOMP._IOwnership _65___v87; Dafny.ISet> _66_recIdents; RAST._IExpr _out36; DCOMP._IOwnership _out37; Dafny.ISet> _out38; (this).GenExpr(_62_overExpr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out36, out _out37, out _out38); _64_over = _out36; - _65___v85 = _out37; + _65___v87 = _out37; _66_recIdents = _out38; if (((_62_overExpr).is_MapBoundedPool) || ((_62_overExpr).is_SetBoundedPool)) { _64_over = ((_64_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply(Dafny.Sequence.FromElements()); @@ -2912,7 +3200,7 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE _67_boundTpe = _out39; readIdents = _66_recIdents; Dafny.ISequence _68_boundRName; - _68_boundRName = DCOMP.__default.escapeName(_60_boundName); + _68_boundRName = DCOMP.__default.escapeVar(_60_boundName); RAST._IExpr _69_bodyExpr; Dafny.ISet> _70_bodyIdents; DCOMP._IEnvironment _71_bodyEnv; @@ -2963,15 +3251,15 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE generated = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); if (!object.Equals(selfIdent, DCOMP.SelfInfo.create_NoSelf())) { RAST._IExpr _75_selfClone; - DCOMP._IOwnership _76___v86; - Dafny.ISet> _77___v87; + DCOMP._IOwnership _76___v88; + Dafny.ISet> _77___v89; RAST._IExpr _out43; DCOMP._IOwnership _out44; Dafny.ISet> _out45; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out43, out _out44, out _out45); _75_selfClone = _out43; - _76___v86 = _out44; - _77___v87 = _out45; + _76___v88 = _out44; + _77___v89 = _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(_75_selfClone))); } newEnv = env; @@ -2980,15 +3268,15 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE Dafny.ISequence _79_param; _79_param = ((env).dtor_names).Select(_78_paramI); RAST._IExpr _80_paramInit; - DCOMP._IOwnership _81___v88; - Dafny.ISet> _82___v89; + DCOMP._IOwnership _81___v90; + Dafny.ISet> _82___v91; RAST._IExpr _out46; DCOMP._IOwnership _out47; Dafny.ISet> _out48; (this).GenIdent(_79_param, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out46, out _out47, out _out48); _80_paramInit = _out46; - _81___v88 = _out47; - _82___v89 = _out48; + _81___v90 = _out47; + _82___v91 = _out48; generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _79_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_80_paramInit))); if (((env).dtor_types).Contains(_79_param)) { RAST._IType _83_declaredType; @@ -3053,7 +3341,7 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE DAST._IResolvedTypeBase _98_base = value0.dtor_kind; RAST._IExpr _99_fullPath; RAST._IExpr _out56; - _out56 = DCOMP.COMP.GenPathExpr(_96_path); + _out56 = DCOMP.COMP.GenPathExpr(_96_path, true); _99_fullPath = _out56; Dafny.ISequence _100_onTypeExprs; Dafny.ISequence _out57; @@ -3082,114 +3370,97 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE _103_recIdents = _out63; readIdents = Dafny.Set>.Union(readIdents, _103_recIdents); } - generated = ((((_99_fullPath).ApplyType(_100_onTypeExprs)).MSel(DCOMP.__default.escapeName((_88_name).dtor_name))).ApplyType(_94_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_101_onExpr), _92_argExprs)); + generated = ((((_99_fullPath).ApplyType(_100_onTypeExprs)).FSel(DCOMP.__default.escapeName((_88_name).dtor_name))).ApplyType(_94_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_101_onExpr), _92_argExprs)); goto after_match2; } } { RAST._IExpr _104_onExpr; - DCOMP._IOwnership _105___v94; + DCOMP._IOwnership _105___v96; Dafny.ISet> _106_enclosingIdents; RAST._IExpr _out64; DCOMP._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_87_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out64, out _out65, out _out66); _104_onExpr = _out64; - _105___v94 = _out65; + _105___v96 = _out65; _106_enclosingIdents = _out66; readIdents = Dafny.Set>.Union(readIdents, _106_enclosingIdents); Dafny.ISequence _107_renderedName; - DAST._ICallName _source3 = _88_name; - { - if (_source3.is_CallName) { - Dafny.ISequence _108_name = _source3.dtor_name; - _107_renderedName = DCOMP.__default.escapeName(_108_name); - goto after_match3; - } - } + _107_renderedName = (this).GetMethodName(_87_on, _88_name); + DAST._IExpression _source3 = _87_on; { bool disjunctiveMatch0 = false; - if (_source3.is_MapBuilderAdd) { + if (_source3.is_Companion) { disjunctiveMatch0 = true; } - if (_source3.is_SetBuilderAdd) { + if (_source3.is_ExternCompanion) { disjunctiveMatch0 = true; } if (disjunctiveMatch0) { - _107_renderedName = Dafny.Sequence.UnicodeFromString("add"); - goto after_match3; - } - } - { - _107_renderedName = Dafny.Sequence.UnicodeFromString("build"); - } - after_match3: ; - DAST._IExpression _source4 = _87_on; - { - if (_source4.is_Companion) { { - _104_onExpr = (_104_onExpr).MSel(_107_renderedName); + _104_onExpr = (_104_onExpr).FSel(_107_renderedName); } - goto after_match4; + goto after_match3; } } { { if (!object.Equals(_104_onExpr, RAST.__default.self)) { - DAST._ICallName _source5 = _88_name; + DAST._ICallName _source4 = _88_name; { - if (_source5.is_CallName) { - Std.Wrappers._IOption onType0 = _source5.dtor_onType; + if (_source4.is_CallName) { + Std.Wrappers._IOption onType0 = _source4.dtor_onType; if (onType0.is_Some) { - DAST._IType _109_tpe = onType0.dtor_value; - RAST._IType _110_typ; + DAST._IType _108_tpe = onType0.dtor_value; + RAST._IType _109_typ; RAST._IType _out67; - _out67 = (this).GenType(_109_tpe, DCOMP.GenTypeContext.@default()); - _110_typ = _out67; - if (((_110_typ).IsObjectOrPointer()) && (!object.Equals(_104_onExpr, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))))) { + _out67 = (this).GenType(_108_tpe, DCOMP.GenTypeContext.@default()); + _109_typ = _out67; + if (((_109_typ).IsObjectOrPointer()) && (!object.Equals(_104_onExpr, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))))) { _104_onExpr = ((this).modify__macro).Apply1(_104_onExpr); } - goto after_match5; + goto after_match4; } } } { } - after_match5: ; + after_match4: ; } _104_onExpr = (_104_onExpr).Sel(_107_renderedName); } } - after_match4: ; + after_match3: ; generated = ((_104_onExpr).ApplyType(_94_typeExprs)).Apply(_92_argExprs); } after_match2: ; if (((_91_maybeOutVars).is_Some) && ((new BigInteger(((_91_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { - Dafny.ISequence _111_outVar; - _111_outVar = DCOMP.__default.escapeName((((_91_maybeOutVars).dtor_value).Select(BigInteger.Zero))); - if (!((env).CanReadWithoutClone(_111_outVar))) { + Dafny.ISequence _110_outVar; + _110_outVar = DCOMP.__default.escapeVar(((_91_maybeOutVars).dtor_value).Select(BigInteger.Zero)); + if (!((env).CanReadWithoutClone(_110_outVar))) { generated = RAST.__default.MaybePlacebo(generated); } - generated = RAST.__default.AssignVar(_111_outVar, generated); + generated = RAST.__default.AssignVar(_110_outVar, generated); } else if (((_91_maybeOutVars).is_None) || ((new BigInteger(((_91_maybeOutVars).dtor_value).Count)).Sign == 0)) { } else { - Dafny.ISequence _112_tmpVar; - _112_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); - RAST._IExpr _113_tmpId; - _113_tmpId = RAST.Expr.create_Identifier(_112_tmpVar); - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _112_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); - Dafny.ISequence> _114_outVars; - _114_outVars = (_91_maybeOutVars).dtor_value; - BigInteger _hi2 = new BigInteger((_114_outVars).Count); - for (BigInteger _115_outI = BigInteger.Zero; _115_outI < _hi2; _115_outI++) { - Dafny.ISequence _116_outVar; - _116_outVar = DCOMP.__default.escapeName(((_114_outVars).Select(_115_outI))); - RAST._IExpr _117_rhs; - _117_rhs = (_113_tmpId).Sel(Std.Strings.__default.OfNat(_115_outI)); - if (!((env).CanReadWithoutClone(_116_outVar))) { - _117_rhs = RAST.__default.MaybePlacebo(_117_rhs); + Dafny.ISequence _111_tmpVar; + _111_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); + RAST._IExpr _112_tmpId; + _112_tmpId = RAST.Expr.create_Identifier(_111_tmpVar); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _111_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); + Dafny.ISequence> _113_outVars; + _113_outVars = (_91_maybeOutVars).dtor_value; + BigInteger _hi2 = new BigInteger((_113_outVars).Count); + for (BigInteger _114_outI = BigInteger.Zero; _114_outI < _hi2; _114_outI++) { + Dafny.ISequence _115_outVar; + _115_outVar = DCOMP.__default.escapeVar((_113_outVars).Select(_114_outI)); + RAST._IExpr _116_rhs; + _116_rhs = (_112_tmpId).Sel(Std.Strings.__default.OfNat(_114_outI)); + if (!((env).CanReadWithoutClone(_115_outVar))) { + _116_rhs = RAST.__default.MaybePlacebo(_116_rhs); } - generated = (generated).Then(RAST.__default.AssignVar(_116_outVar, _117_rhs)); + generated = (generated).Then(RAST.__default.AssignVar(_115_outVar, _116_rhs)); } } newEnv = env; @@ -3199,23 +3470,23 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE } { if (_source0.is_Return) { - DAST._IExpression _118_exprDafny = _source0.dtor_expr; + DAST._IExpression _117_exprDafny = _source0.dtor_expr; { - RAST._IExpr _119_expr; - DCOMP._IOwnership _120___v105; - Dafny.ISet> _121_recIdents; + RAST._IExpr _118_expr; + DCOMP._IOwnership _119___v106; + Dafny.ISet> _120_recIdents; RAST._IExpr _out68; DCOMP._IOwnership _out69; Dafny.ISet> _out70; - (this).GenExpr(_118_exprDafny, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out68, out _out69, out _out70); - _119_expr = _out68; - _120___v105 = _out69; - _121_recIdents = _out70; - readIdents = _121_recIdents; + (this).GenExpr(_117_exprDafny, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out68, out _out69, out _out70); + _118_expr = _out68; + _119___v106 = _out69; + _120_recIdents = _out70; + readIdents = _120_recIdents; if (isLast) { - generated = _119_expr; + generated = _118_expr; } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_119_expr)); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_118_expr)); } newEnv = env; } @@ -3225,38 +3496,38 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE { if (_source0.is_EarlyReturn) { { - Std.Wrappers._IOption>> _source6 = earlyReturn; + Std.Wrappers._IOption>> _source5 = earlyReturn; { - if (_source6.is_None) { + if (_source5.is_None) { generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_None()); - goto after_match6; + goto after_match5; } } { - Dafny.ISequence> _122_rustIdents = _source6.dtor_value; - Dafny.ISequence _123_tupleArgs; - _123_tupleArgs = Dafny.Sequence.FromElements(); - BigInteger _hi3 = new BigInteger((_122_rustIdents).Count); - for (BigInteger _124_i = BigInteger.Zero; _124_i < _hi3; _124_i++) { - RAST._IExpr _125_rIdent; - DCOMP._IOwnership _126___v106; - Dafny.ISet> _127___v107; + Dafny.ISequence> _121_rustIdents = _source5.dtor_value; + Dafny.ISequence _122_tupleArgs; + _122_tupleArgs = Dafny.Sequence.FromElements(); + BigInteger _hi3 = new BigInteger((_121_rustIdents).Count); + for (BigInteger _123_i = BigInteger.Zero; _123_i < _hi3; _123_i++) { + RAST._IExpr _124_rIdent; + DCOMP._IOwnership _125___v107; + Dafny.ISet> _126___v108; RAST._IExpr _out71; DCOMP._IOwnership _out72; Dafny.ISet> _out73; - (this).GenIdent((_122_rustIdents).Select(_124_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out71, out _out72, out _out73); - _125_rIdent = _out71; - _126___v106 = _out72; - _127___v107 = _out73; - _123_tupleArgs = Dafny.Sequence.Concat(_123_tupleArgs, Dafny.Sequence.FromElements(_125_rIdent)); + (this).GenIdent((_121_rustIdents).Select(_123_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out71, out _out72, out _out73); + _124_rIdent = _out71; + _125___v107 = _out72; + _126___v108 = _out73; + _122_tupleArgs = Dafny.Sequence.Concat(_122_tupleArgs, Dafny.Sequence.FromElements(_124_rIdent)); } - if ((new BigInteger((_123_tupleArgs).Count)) == (BigInteger.One)) { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_123_tupleArgs).Select(BigInteger.Zero))); + if ((new BigInteger((_122_tupleArgs).Count)) == (BigInteger.One)) { + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_122_tupleArgs).Select(BigInteger.Zero))); } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_123_tupleArgs))); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_122_tupleArgs))); } } - after_match6: ; + after_match5: ; readIdents = Dafny.Set>.FromElements(); newEnv = env; } @@ -3274,27 +3545,26 @@ public void GenStmt(DAST._IStatement stmt, DCOMP._ISelfInfo selfIdent, DCOMP._IE } } { - DAST._IExpression _128_e = _source0.dtor_Print_a0; + DAST._IExpression _127_e = _source0.dtor_Print_a0; { - RAST._IExpr _129_printedExpr; - DCOMP._IOwnership _130_recOwnership; - Dafny.ISet> _131_recIdents; + RAST._IExpr _128_printedExpr; + DCOMP._IOwnership _129_recOwnership; + Dafny.ISet> _130_recIdents; RAST._IExpr _out74; DCOMP._IOwnership _out75; Dafny.ISet> _out76; - (this).GenExpr(_128_e, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out74, out _out75, out _out76); - _129_printedExpr = _out74; - _130_recOwnership = _out75; - _131_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"))).Apply1(_129_printedExpr))); - readIdents = _131_recIdents; + (this).GenExpr(_127_e, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out74, out _out75, out _out76); + _128_printedExpr = _out74; + _129_recOwnership = _out75; + _130_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(_128_printedExpr))); + readIdents = _130_recIdents; newEnv = env; } } after_match0: ; } - public static Std.Wrappers._IOption NewtypeToRustType(DAST._IType @base, DAST._INewtypeRange range) - { + public static Std.Wrappers._IOption NewtypeRangeToRustType(DAST._INewtypeRange range) { DAST._INewtypeRange _source0 = range; { if (_source0.is_NoRange) { @@ -3457,9 +3727,9 @@ public void GenExprLiteral(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM if (_h70.is_Int) { { if ((new BigInteger((_1_i).Count)) <= (new BigInteger(4))) { - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).Apply1(RAST.Expr.create_LiteralInt(_1_i)); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(RAST.Expr.create_LiteralInt(_1_i)); } else { - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).Apply1(RAST.Expr.create_LiteralString(_1_i, true, false)); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(RAST.Expr.create_LiteralString(_1_i, true, false)); } } goto after_match1; @@ -3539,7 +3809,7 @@ public void GenExprLiteral(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM Dafny.ISequence _10_l = _h173.dtor_StringLiteral_a0; bool _11_verbatim = _h173.dtor_verbatim; { - r = ((RAST.__default.dafny__runtime).MSel((this).string__of)).Apply1(RAST.Expr.create_LiteralString(_10_l, false, _11_verbatim)); + r = (((RAST.__default.dafny__runtime).MSel((this).string__of)).AsExpr()).Apply1(RAST.Expr.create_LiteralString(_10_l, false, _11_verbatim)); RAST._IExpr _out8; DCOMP._IOwnership _out9; (this).FromOwned(r, expectedOwnership, out _out8, out _out9); @@ -3560,7 +3830,7 @@ public void GenExprLiteral(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(_12_c)); r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); - r = ((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).Apply1(r); + r = (((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(r); RAST._IExpr _out10; DCOMP._IOwnership _out11; (this).FromOwned(r, expectedOwnership, out _out10, out _out11); @@ -3583,9 +3853,9 @@ public void GenExprLiteral(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM if (!((this).UnicodeChars)) { r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); } else { - r = (((((((RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("std"))).MSel(Dafny.Sequence.UnicodeFromString("primitive"))).MSel(Dafny.Sequence.UnicodeFromString("char"))).MSel(Dafny.Sequence.UnicodeFromString("from_u32"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply(Dafny.Sequence.FromElements()); + r = (((((((RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("std"))).MSel(Dafny.Sequence.UnicodeFromString("primitive"))).MSel(Dafny.Sequence.UnicodeFromString("char"))).FSel(Dafny.Sequence.UnicodeFromString("from_u32"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply(Dafny.Sequence.FromElements()); } - r = ((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).Apply1(r); + r = (((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(r); RAST._IExpr _out12; DCOMP._IOwnership _out13; (this).FromOwned(r, expectedOwnership, out _out12, out _out13); @@ -3607,9 +3877,9 @@ public void GenExprLiteral(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM _out14 = (this).GenType(_14_tpe, DCOMP.GenTypeContext.@default()); _15_tpeGen = _out14; if (((this).ObjectType).is_RawPointers) { - r = ((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ptr"))).MSel(Dafny.Sequence.UnicodeFromString("null")); + r = ((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ptr"))).FSel(Dafny.Sequence.UnicodeFromString("null_mut")); } else { - r = RAST.Expr.create_TypeAscription(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).Apply1(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("None"))), _15_tpeGen); + r = RAST.Expr.create_TypeAscription((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).AsExpr()).Apply1(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("None"))), _15_tpeGen); } RAST._IExpr _out15; DCOMP._IOwnership _out16; @@ -3788,24 +4058,24 @@ public void GenExprBinary(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP _8_expectedRightOwnership = DCOMP.Ownership.create_OwnershipOwned(); } RAST._IExpr _9_left; - DCOMP._IOwnership _10___v112; + DCOMP._IOwnership _10___v113; Dafny.ISet> _11_recIdentsL; RAST._IExpr _out0; DCOMP._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_1_lExpr, selfIdent, env, _7_expectedLeftOwnership, out _out0, out _out1, out _out2); _9_left = _out0; - _10___v112 = _out1; + _10___v113 = _out1; _11_recIdentsL = _out2; RAST._IExpr _12_right; - DCOMP._IOwnership _13___v113; + DCOMP._IOwnership _13___v114; Dafny.ISet> _14_recIdentsR; RAST._IExpr _out3; DCOMP._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_2_rExpr, selfIdent, env, _8_expectedRightOwnership, out _out3, out _out4, out _out5); _12_right = _out3; - _13___v113 = _out4; + _13___v114 = _out4; _14_recIdentsR = _out5; DAST._IBinOp _source3 = _0_op; { @@ -4030,11 +4300,11 @@ public void GenExprConvertToNewtype(DAST._IExpression e, DCOMP._ISelfInfo selfId 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___v115 = _let_tmp_rhs2.dtor_attributes; - Dafny.ISequence> _9___v116 = _let_tmp_rhs2.dtor_properMethods; - Dafny.ISequence _10___v117 = _let_tmp_rhs2.dtor_extendedTypes; + Dafny.ISequence _8___v116 = _let_tmp_rhs2.dtor_attributes; + Dafny.ISequence> _9___v117 = _let_tmp_rhs2.dtor_properMethods; + Dafny.ISequence _10___v118 = _let_tmp_rhs2.dtor_extendedTypes; Std.Wrappers._IOption _11_nativeToType; - _11_nativeToType = DCOMP.COMP.NewtypeToRustType(_5_b, _6_range); + _11_nativeToType = DCOMP.COMP.NewtypeRangeToRustType(_6_range); if (object.Equals(_1_fromTpe, _5_b)) { RAST._IExpr _12_recursiveGen; DCOMP._IOwnership _13_recOwned; @@ -4051,7 +4321,7 @@ public void GenExprConvertToNewtype(DAST._IExpression e, DCOMP._ISelfInfo selfId { if (_source0.is_Some) { RAST._IType _15_v = _source0.dtor_value; - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("truncate!"))).Apply(Dafny.Sequence.FromElements(_12_recursiveGen, RAST.Expr.create_ExprFromType(_15_v))); + 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; DCOMP._IOwnership _out4; (this).FromOwned(r, expectedOwnership, out _out3, out _out4); @@ -4066,7 +4336,7 @@ public void GenExprConvertToNewtype(DAST._IExpression e, DCOMP._ISelfInfo selfId } else { RAST._IType _16_rhsType; RAST._IType _out5; - _out5 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.InBinding()); + _out5 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.@default()); _16_rhsType = _out5; r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_16_rhsType)._ToString(DCOMP.__default.IND), Dafny.Sequence.UnicodeFromString("(")), (_12_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); } @@ -4091,7 +4361,7 @@ public void GenExprConvertToNewtype(DAST._IExpression e, DCOMP._ISelfInfo selfId Dafny.ISequence _20_attributes0 = resolved0.dtor_attributes; { Std.Wrappers._IOption _21_nativeFromType; - _21_nativeFromType = DCOMP.COMP.NewtypeToRustType(_17_b0, _18_range0); + _21_nativeFromType = DCOMP.COMP.NewtypeRangeToRustType(_18_range0); if ((_21_nativeFromType).is_Some) { RAST._IExpr _22_recursiveGen; DCOMP._IOwnership _23_recOwned; @@ -4159,17 +4429,17 @@ public void GenExprConvertFromNewtype(DAST._IExpression e, DCOMP._ISelfInfo self 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___v123 = _let_tmp_rhs2.dtor_path; - Dafny.ISequence _4___v124 = _let_tmp_rhs2.dtor_typeArgs; + Dafny.ISequence> _3___v124 = _let_tmp_rhs2.dtor_path; + Dafny.ISequence _4___v125 = _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___v125 = _let_tmp_rhs2.dtor_properMethods; - Dafny.ISequence _10___v126 = _let_tmp_rhs2.dtor_extendedTypes; + Dafny.ISequence> _9___v126 = _let_tmp_rhs2.dtor_properMethods; + Dafny.ISequence _10___v127 = _let_tmp_rhs2.dtor_extendedTypes; Std.Wrappers._IOption _11_nativeFromType; - _11_nativeFromType = DCOMP.COMP.NewtypeToRustType(_5_b, _6_range); + _11_nativeFromType = DCOMP.COMP.NewtypeRangeToRustType(_6_range); if (object.Equals(_5_b, _2_toTpe)) { RAST._IExpr _12_recursiveGen; DCOMP._IOwnership _13_recOwned; @@ -4190,7 +4460,7 @@ public void GenExprConvertFromNewtype(DAST._IExpression e, DCOMP._ISelfInfo self RAST._IType _out3; _out3 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.@default()); _16_toTpeRust = _out3; - r = (((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Into"))).ApplyType(Dafny.Sequence.FromElements(_16_toTpeRust))).MSel(Dafny.Sequence.UnicodeFromString("into"))).Apply(Dafny.Sequence.FromElements(_12_recursiveGen)); + 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; DCOMP._IOwnership _out5; (this).FromOwned(r, expectedOwnership, out _out4, out _out5); @@ -4227,7 +4497,7 @@ public void GenExprConvertFromNewtype(DAST._IExpression e, DCOMP._ISelfInfo self _19_recIdents = _out10; RAST._IExpr _out11; DCOMP._IOwnership _out12; - (this).FromOwnership(((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).Apply1(RAST.Expr.create_TypeAscription(_17_recursiveGen, (this).DafnyCharUnderlying)), _18_recOwned, expectedOwnership, out _out11, out _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; @@ -4278,15 +4548,20 @@ public bool SameTypesButDifferentTypeParameters(DAST._IType fromType, RAST._ITyp } public Std.Wrappers._IResult,RAST._IExpr>>> UpcastConversionLambda(DAST._IType fromType, RAST._IType fromTpe, DAST._IType toType, RAST._IType toTpe, Dafny.IMap<_System._ITuple2,RAST._IExpr> typeParams) { + var _pat_let_tv0 = fromType; + var _pat_let_tv1 = fromTpe; + var _pat_let_tv2 = toType; + var _pat_let_tv3 = toTpe; + var _pat_let_tv4 = typeParams; if (object.Equals(fromTpe, toTpe)) { - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("upcast_id"))).ApplyType(Dafny.Sequence.FromElements(fromTpe))).Apply(Dafny.Sequence.FromElements())); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("upcast_id"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(fromTpe))).Apply(Dafny.Sequence.FromElements())); } else if (((fromTpe).IsObjectOrPointer()) && ((toTpe).IsObjectOrPointer())) { if (!(((toTpe).ObjectOrPointerUnderlying()).is_DynType)) { return Std.Wrappers.Result,RAST._IExpr>>>.create_Failure(_System.Tuple5,RAST._IExpr>>.create(fromType, fromTpe, toType, toTpe, typeParams)); } else { RAST._IType _0_fromTpeUnderlying = (fromTpe).ObjectOrPointerUnderlying(); RAST._IType _1_toTpeUnderlying = (toTpe).ObjectOrPointerUnderlying(); - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.__default.dafny__runtime).MSel((this).upcast)).ApplyType(Dafny.Sequence.FromElements(_0_fromTpeUnderlying, _1_toTpeUnderlying))).Apply(Dafny.Sequence.FromElements())); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel((this).upcast)).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_0_fromTpeUnderlying, _1_toTpeUnderlying))).Apply(Dafny.Sequence.FromElements())); } } else if ((typeParams).Contains(_System.Tuple2.create(fromTpe, toTpe))) { return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(Dafny.Map<_System._ITuple2, RAST._IExpr>.Select(typeParams,_System.Tuple2.create(fromTpe, toTpe))); @@ -4299,54 +4574,73 @@ public bool SameTypesButDifferentTypeParameters(DAST._IType fromType, RAST._ITyp if ((fromType).is_Arrow) { return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(_3_lambda); } else { - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rc_coerce"))).Apply1(_3_lambda)); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rc_coerce"))).AsExpr()).Apply1(_3_lambda)); } } } else if ((this).SameTypesButDifferentTypeParameters(fromType, fromTpe, toType, toTpe)) { - Std.Wrappers._IResult, _System._ITuple5,RAST._IExpr>>> _4_valueOrError1 = (this).SeqResultToResultSeq,RAST._IExpr>>>(((System.Func,RAST._IExpr>>>>>) (() => { - BigInteger dim12 = new BigInteger(((fromTpe).dtor_arguments).Count); - var arr12 = new Std.Wrappers._IResult,RAST._IExpr>>>[Dafny.Helpers.ToIntChecked(dim12, "array size exceeds memory limit")]; - for (int i12 = 0; i12 < dim12; i12++) { - var _5_i = (BigInteger) i12; - arr12[(int)(_5_i)] = (this).UpcastConversionLambda((((fromType).dtor_resolved).dtor_typeArgs).Select(_5_i), ((fromTpe).dtor_arguments).Select(_5_i), (((toType).dtor_resolved).dtor_typeArgs).Select(_5_i), ((toTpe).dtor_arguments).Select(_5_i), typeParams); - } - return Dafny.Sequence,RAST._IExpr>>>>.FromArray(arr12); + Dafny.ISequence _4_indices = ((((fromType).is_UserDefined) && ((((fromType).dtor_resolved).dtor_kind).is_Datatype)) ? (Std.Collections.Seq.__default.Filter(Dafny.Helpers.Id>>((_5_fromTpe, _6_fromType) => ((System.Func)((_7_i) => { + return ((((_7_i).Sign != -1) && ((_7_i) < (new BigInteger(((_5_fromTpe).dtor_arguments).Count)))) ? (!(((_7_i).Sign != -1) && ((_7_i) < (new BigInteger(((((_6_fromType).dtor_resolved).dtor_kind).dtor_variances).Count)))) || (!((((((_6_fromType).dtor_resolved).dtor_kind).dtor_variances).Select(_7_i)).is_Nonvariant))) : (false)); + })))(fromTpe, fromType), ((System.Func>) (() => { + BigInteger dim14 = new BigInteger(((fromTpe).dtor_arguments).Count); + var arr14 = new BigInteger[Dafny.Helpers.ToIntChecked(dim14, "array size exceeds memory limit")]; + for (int i14 = 0; i14 < dim14; i14++) { + var _8_i = (BigInteger) i14; + arr14[(int)(_8_i)] = _8_i; + } + return Dafny.Sequence.FromArray(arr14); + }))())) : (((System.Func>) (() => { + BigInteger dim15 = new BigInteger(((fromTpe).dtor_arguments).Count); + var arr15 = new BigInteger[Dafny.Helpers.ToIntChecked(dim15, "array size exceeds memory limit")]; + for (int i15 = 0; i15 < dim15; i15++) { + var _9_i = (BigInteger) i15; + arr15[(int)(_9_i)] = _9_i; + } + return Dafny.Sequence.FromArray(arr15); + }))())); + Std.Wrappers._IResult, _System._ITuple5,RAST._IExpr>>> _10_valueOrError1 = (this).SeqResultToResultSeq,RAST._IExpr>>>(((System.Func,RAST._IExpr>>>>>) (() => { + BigInteger dim16 = new BigInteger((_4_indices).Count); + var arr16 = new Std.Wrappers._IResult,RAST._IExpr>>>[Dafny.Helpers.ToIntChecked(dim16, "array size exceeds memory limit")]; + for (int i16 = 0; i16 < dim16; i16++) { + var _11_j = (BigInteger) i16; + arr16[(int)(_11_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_4_indices).Select(_11_j), _pat_let22_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let22_0, _12_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_12_i), ((_pat_let_tv1).dtor_arguments).Select(_12_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_12_i), ((_pat_let_tv3).dtor_arguments).Select(_12_i), _pat_let_tv4))); + } + return Dafny.Sequence,RAST._IExpr>>>>.FromArray(arr16); }))()); - if ((_4_valueOrError1).IsFailure()) { - return (_4_valueOrError1).PropagateFailure(); + if ((_10_valueOrError1).IsFailure()) { + return (_10_valueOrError1).PropagateFailure(); } else { - Dafny.ISequence _6_lambdas = (_4_valueOrError1).Extract(); + Dafny.ISequence _13_lambdas = (_10_valueOrError1).Extract(); return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.Expr.create_ExprFromType((fromTpe).dtor_baseName)).ApplyType(((System.Func>) (() => { - BigInteger dim13 = new BigInteger(((fromTpe).dtor_arguments).Count); - var arr13 = new RAST._IType[Dafny.Helpers.ToIntChecked(dim13, "array size exceeds memory limit")]; - for (int i13 = 0; i13 < dim13; i13++) { - var _7_i = (BigInteger) i13; - arr13[(int)(_7_i)] = ((fromTpe).dtor_arguments).Select(_7_i); + BigInteger dim17 = new BigInteger(((fromTpe).dtor_arguments).Count); + var arr17 = new RAST._IType[Dafny.Helpers.ToIntChecked(dim17, "array size exceeds memory limit")]; + for (int i17 = 0; i17 < dim17; i17++) { + var _14_i = (BigInteger) i17; + arr17[(int)(_14_i)] = ((fromTpe).dtor_arguments).Select(_14_i); } - return Dafny.Sequence.FromArray(arr13); -}))())).MSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply(_6_lambdas)); + return Dafny.Sequence.FromArray(arr17); +}))())).FSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply(_13_lambdas)); } } else if (((((fromTpe).IsBuiltinCollection()) && ((toTpe).IsBuiltinCollection())) && ((this).IsBuiltinCollection(fromType))) && ((this).IsBuiltinCollection(toType))) { - RAST._IType _8_newFromTpe = (fromTpe).GetBuiltinCollectionElement(); - RAST._IType _9_newToTpe = (toTpe).GetBuiltinCollectionElement(); - DAST._IType _10_newFromType = (this).GetBuiltinCollectionElement(fromType); - DAST._IType _11_newToType = (this).GetBuiltinCollectionElement(toType); - Std.Wrappers._IResult,RAST._IExpr>>> _12_valueOrError2 = (this).UpcastConversionLambda(_10_newFromType, _8_newFromTpe, _11_newToType, _9_newToTpe, typeParams); - if ((_12_valueOrError2).IsFailure()) { - return (_12_valueOrError2).PropagateFailure(); + RAST._IType _15_newFromTpe = (fromTpe).GetBuiltinCollectionElement(); + RAST._IType _16_newToTpe = (toTpe).GetBuiltinCollectionElement(); + DAST._IType _17_newFromType = (this).GetBuiltinCollectionElement(fromType); + DAST._IType _18_newToType = (this).GetBuiltinCollectionElement(toType); + Std.Wrappers._IResult,RAST._IExpr>>> _19_valueOrError2 = (this).UpcastConversionLambda(_17_newFromType, _15_newFromTpe, _18_newToType, _16_newToTpe, typeParams); + if ((_19_valueOrError2).IsFailure()) { + return (_19_valueOrError2).PropagateFailure(); } else { - RAST._IExpr _13_coerceArg = (_12_valueOrError2).Extract(); - RAST._IExpr _14_collectionType = (RAST.__default.dafny__runtime).MSel(((fromTpe).dtor_baseName).dtor_name); - RAST._IExpr _15_baseType = (((((fromTpe).dtor_baseName).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("Map"))) ? ((_14_collectionType).ApplyType(Dafny.Sequence.FromElements(((fromTpe).dtor_arguments).Select(BigInteger.Zero), _8_newFromTpe))) : ((_14_collectionType).ApplyType(Dafny.Sequence.FromElements(_8_newFromTpe)))); - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((_15_baseType).MSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply1(_13_coerceArg)); + RAST._IExpr _20_coerceArg = (_19_valueOrError2).Extract(); + RAST._IPath _21_collectionType = (RAST.__default.dafny__runtime).MSel(((((fromTpe).Expand()).dtor_baseName).dtor_path).dtor_name); + RAST._IExpr _22_baseType = (((((((fromTpe).Expand()).dtor_baseName).dtor_path).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("Map"))) ? (((_21_collectionType).AsExpr()).ApplyType(Dafny.Sequence.FromElements((((fromTpe).Expand()).dtor_arguments).Select(BigInteger.Zero), _15_newFromTpe))) : (((_21_collectionType).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_15_newFromTpe)))); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((_22_baseType).FSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply1(_20_coerceArg)); } } else if ((((((((((fromTpe).is_DynType) && (((fromTpe).dtor_underlying).is_FnType)) && ((toTpe).is_DynType)) && (((toTpe).dtor_underlying).is_FnType)) && ((((fromTpe).dtor_underlying).dtor_arguments).Equals(((toTpe).dtor_underlying).dtor_arguments))) && ((fromType).is_Arrow)) && ((toType).is_Arrow)) && ((new BigInteger((((fromTpe).dtor_underlying).dtor_arguments).Count)) == (BigInteger.One))) && (((((fromTpe).dtor_underlying).dtor_arguments).Select(BigInteger.Zero)).is_Borrowed)) { - Std.Wrappers._IResult,RAST._IExpr>>> _16_valueOrError3 = (this).UpcastConversionLambda((fromType).dtor_result, ((fromTpe).dtor_underlying).dtor_returnType, (toType).dtor_result, ((toTpe).dtor_underlying).dtor_returnType, typeParams); - if ((_16_valueOrError3).IsFailure()) { - return (_16_valueOrError3).PropagateFailure(); + Std.Wrappers._IResult,RAST._IExpr>>> _23_valueOrError3 = (this).UpcastConversionLambda((fromType).dtor_result, ((fromTpe).dtor_underlying).dtor_returnType, (toType).dtor_result, ((toTpe).dtor_underlying).dtor_returnType, typeParams); + if ((_23_valueOrError3).IsFailure()) { + return (_23_valueOrError3).PropagateFailure(); } else { - RAST._IExpr _17_lambda = (_16_valueOrError3).Extract(); - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("fn1_coerce"))).ApplyType(Dafny.Sequence.FromElements(((((fromTpe).dtor_underlying).dtor_arguments).Select(BigInteger.Zero)).dtor_underlying, ((fromTpe).dtor_underlying).dtor_returnType, ((toTpe).dtor_underlying).dtor_returnType))).Apply1(_17_lambda)); + RAST._IExpr _24_lambda = (_23_valueOrError3).Extract(); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("fn1_coerce"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(((((fromTpe).dtor_underlying).dtor_arguments).Select(BigInteger.Zero)).dtor_underlying, ((fromTpe).dtor_underlying).dtor_returnType, ((toTpe).dtor_underlying).dtor_returnType))).Apply1(_24_lambda)); } } else { return Std.Wrappers.Result,RAST._IExpr>>>.create_Failure(_System.Tuple5,RAST._IExpr>>.create(fromType, fromTpe, toType, toTpe, typeParams)); @@ -4371,11 +4665,11 @@ public void GenExprConvertOther(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DAST._IType _2_toTpe = _let_tmp_rhs0.dtor_typ; RAST._IType _3_fromTpeGen; RAST._IType _out0; - _out0 = (this).GenType(_1_fromTpe, DCOMP.GenTypeContext.InBinding()); + _out0 = (this).GenType(_1_fromTpe, DCOMP.GenTypeContext.@default()); _3_fromTpeGen = _out0; RAST._IType _4_toTpeGen; RAST._IType _out1; - _out1 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.InBinding()); + _out1 = (this).GenType(_2_toTpe, DCOMP.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()); @@ -4412,7 +4706,7 @@ public void GenExprConvertOther(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, _12_recIdents = _out9; readIdents = _12_recIdents; _4_toTpeGen = (_4_toTpeGen).ObjectOrPointerUnderlying(); - r = ((RAST.__default.dafny__runtime).MSel((this).downcast)).Apply(Dafny.Sequence.FromElements(_10_recursiveGen, RAST.Expr.create_ExprFromType(_4_toTpeGen))); + r = (((RAST.__default.dafny__runtime).MSel((this).downcast)).AsExpr()).Apply(Dafny.Sequence.FromElements(_10_recursiveGen, RAST.Expr.create_ExprFromType(_4_toTpeGen))); RAST._IExpr _out10; DCOMP._IOwnership _out11; (this).FromOwnership(r, DCOMP.Ownership.create_OwnershipOwned(), expectedOwnership, out _out10, out _out11); @@ -4534,14 +4828,14 @@ public void GenExprConvert(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM if (_h71.is_Real) { { RAST._IExpr _14_recursiveGen; - DCOMP._IOwnership _15___v137; + DCOMP._IOwnership _15___v138; Dafny.ISet> _16_recIdents; RAST._IExpr _out11; DCOMP._IOwnership _out12; Dafny.ISet> _out13; (this).GenExpr(_0_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out11, out _out12, out _out13); _14_recursiveGen = _out11; - _15___v137 = _out12; + _15___v138 = _out12; _16_recIdents = _out13; r = RAST.__default.RcNew(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::BigRational::from_integer("), (_14_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")))); RAST._IExpr _out14; @@ -4568,14 +4862,14 @@ public void GenExprConvert(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM if (_h73.is_Int) { { RAST._IExpr _17_recursiveGen; - DCOMP._IOwnership _18___v138; + DCOMP._IOwnership _18___v139; Dafny.ISet> _19_recIdents; RAST._IExpr _out16; DCOMP._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr(_0_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out16, out _out17, out _out18); _17_recursiveGen = _out16; - _18___v138 = _out17; + _18___v139 = _out17; _19_recIdents = _out18; r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::dafny_rational_to_int("), (_17_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); RAST._IExpr _out19; @@ -4601,17 +4895,17 @@ public void GenExprConvert(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM { RAST._IType _20_rhsType; RAST._IType _out21; - _out21 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.InBinding()); + _out21 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.@default()); _20_rhsType = _out21; RAST._IExpr _21_recursiveGen; - DCOMP._IOwnership _22___v140; + DCOMP._IOwnership _22___v141; Dafny.ISet> _23_recIdents; RAST._IExpr _out22; DCOMP._IOwnership _out23; Dafny.ISet> _out24; (this).GenExpr(_0_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out22, out _out23, out _out24); _21_recursiveGen = _out22; - _22___v140 = _out23; + _22___v141 = _out23; _23_recIdents = _out24; r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), (_20_rhsType)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as ::dafny_runtime::NumCast>::from(")), (_21_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap()"))); RAST._IExpr _out25; @@ -4636,17 +4930,17 @@ public void GenExprConvert(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM { RAST._IType _24_rhsType; RAST._IType _out27; - _out27 = (this).GenType(_1_fromTpe, DCOMP.GenTypeContext.InBinding()); + _out27 = (this).GenType(_1_fromTpe, DCOMP.GenTypeContext.@default()); _24_rhsType = _out27; RAST._IExpr _25_recursiveGen; - DCOMP._IOwnership _26___v142; + DCOMP._IOwnership _26___v143; Dafny.ISet> _27_recIdents; RAST._IExpr _out28; DCOMP._IOwnership _out29; Dafny.ISet> _out30; (this).GenExpr(_0_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out28, out _out29, out _out30); _25_recursiveGen = _out28; - _26___v142 = _out29; + _26___v143 = _out29; _27_recIdents = _out30; r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyInt::new(::std::rc::Rc::new(::dafny_runtime::BigInt::from("), (_25_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")))"))); RAST._IExpr _out31; @@ -4673,17 +4967,17 @@ public void GenExprConvert(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM { RAST._IType _28_rhsType; RAST._IType _out33; - _out33 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.InBinding()); + _out33 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.@default()); _28_rhsType = _out33; RAST._IExpr _29_recursiveGen; - DCOMP._IOwnership _30___v143; + DCOMP._IOwnership _30___v144; Dafny.ISet> _31_recIdents; RAST._IExpr _out34; DCOMP._IOwnership _out35; Dafny.ISet> _out36; (this).GenExpr(_0_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out34, out _out35, out _out36); _29_recursiveGen = _out34; - _30___v143 = _out35; + _30___v144 = _out35; _31_recIdents = _out36; r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::"), (this).DafnyChar), Dafny.Sequence.UnicodeFromString("(")), (((this).UnicodeChars) ? (Dafny.Sequence.UnicodeFromString("char::from_u32(.UnicodeFromString(".UnicodeFromString(" as ::dafny_runtime::NumCast>::from(")), (_29_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap())")), (((this).UnicodeChars) ? (Dafny.Sequence.UnicodeFromString(".unwrap())")) : (Dafny.Sequence.UnicodeFromString(""))))); RAST._IExpr _out37; @@ -4711,19 +5005,19 @@ public void GenExprConvert(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM { RAST._IType _32_rhsType; RAST._IType _out39; - _out39 = (this).GenType(_1_fromTpe, DCOMP.GenTypeContext.InBinding()); + _out39 = (this).GenType(_1_fromTpe, DCOMP.GenTypeContext.@default()); _32_rhsType = _out39; RAST._IExpr _33_recursiveGen; - DCOMP._IOwnership _34___v144; + DCOMP._IOwnership _34___v145; Dafny.ISet> _35_recIdents; RAST._IExpr _out40; DCOMP._IOwnership _out41; Dafny.ISet> _out42; (this).GenExpr(_0_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out40, out _out41, out _out42); _33_recursiveGen = _out40; - _34___v144 = _out41; + _34___v145 = _out41; _35_recIdents = _out42; - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).Apply1((_33_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("0"))); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1((_33_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("0"))); RAST._IExpr _out43; DCOMP._IOwnership _out44; (this).FromOwned(r, expectedOwnership, out _out43, out _out44); @@ -4744,18 +5038,18 @@ public void GenExprConvert(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOM if (_17.is_Passthrough) { { RAST._IExpr _36_recursiveGen; - DCOMP._IOwnership _37___v147; + DCOMP._IOwnership _37___v148; Dafny.ISet> _38_recIdents; RAST._IExpr _out45; DCOMP._IOwnership _out46; Dafny.ISet> _out47; (this).GenExpr(_0_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out45, out _out46, out _out47); _36_recursiveGen = _out45; - _37___v147 = _out46; + _37___v148 = _out46; _38_recIdents = _out47; RAST._IType _39_toTpeGen; RAST._IType _out48; - _out48 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.InBinding()); + _out48 = (this).GenType(_2_toTpe, DCOMP.GenTypeContext.@default()); _39_toTpeGen = _out48; r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("(("), (_36_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(") as ")), (_39_toTpeGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); RAST._IExpr _out49; @@ -4842,7 +5136,7 @@ public void GenIdent(Dafny.ISequence rName, DCOMP._ISelfInfo selfIde } }))()); if (_4_needObjectFromRef) { - r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).ApplyType(Dafny.Sequence.FromElements(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("_"))))).MSel(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.__default.RawType(Dafny.Sequence.UnicodeFromString("_"))))).FSel(Dafny.Sequence.UnicodeFromString("from_ref"))).Apply(Dafny.Sequence.FromElements(r)); } else { if (!(_3_noNeedOfClone)) { r = (r).Clone(); @@ -4884,55 +5178,65 @@ public void GenArgs(DCOMP._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISeq fullNameQualifier = Std.Wrappers.Option.Default(); argExprs = Dafny.Sequence.FromElements(); readIdents = Dafny.Set>.FromElements(); + Dafny.ISequence _0_signature; + if ((name).is_CallName) { + if ((((name).dtor_receiverArg).is_Some) && ((name).dtor_receiverAsArgument)) { + _0_signature = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((name).dtor_receiverArg).dtor_value), ((name).dtor_signature)); + } else { + _0_signature = ((name).dtor_signature); + } + } else { + _0_signature = Dafny.Sequence.FromElements(); + } BigInteger _hi0 = new BigInteger((args).Count); - for (BigInteger _0_i = BigInteger.Zero; _0_i < _hi0; _0_i++) { - DCOMP._IOwnership _1_argOwnership; - _1_argOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); - if (((name).is_CallName) && ((_0_i) < (new BigInteger((((name).dtor_signature)).Count)))) { - RAST._IType _2_tpe; + for (BigInteger _1_i = BigInteger.Zero; _1_i < _hi0; _1_i++) { + DCOMP._IOwnership _2_argOwnership; + _2_argOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); + if ((_1_i) < (new BigInteger((_0_signature).Count))) { + RAST._IType _3_tpe; RAST._IType _out0; - _out0 = (this).GenType(((((name).dtor_signature)).Select(_0_i)).dtor_typ, DCOMP.GenTypeContext.@default()); - _2_tpe = _out0; - if ((_2_tpe).CanReadWithoutClone()) { - _1_argOwnership = DCOMP.Ownership.create_OwnershipOwned(); + _out0 = (this).GenType(((_0_signature).Select(_1_i)).dtor_typ, DCOMP.GenTypeContext.@default()); + _3_tpe = _out0; + if ((_3_tpe).CanReadWithoutClone()) { + _2_argOwnership = DCOMP.Ownership.create_OwnershipOwned(); } } - RAST._IExpr _3_argExpr; - DCOMP._IOwnership _4___v154; - Dafny.ISet> _5_argIdents; + RAST._IExpr _4_argExpr; + DCOMP._IOwnership _5___v155; + Dafny.ISet> _6_argIdents; RAST._IExpr _out1; DCOMP._IOwnership _out2; Dafny.ISet> _out3; - (this).GenExpr((args).Select(_0_i), selfIdent, env, _1_argOwnership, out _out1, out _out2, out _out3); - _3_argExpr = _out1; - _4___v154 = _out2; - _5_argIdents = _out3; - argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_3_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _5_argIdents); + (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); + _4_argExpr = _out1; + _5___v155 = _out2; + _6_argIdents = _out3; + argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); } typeExprs = Dafny.Sequence.FromElements(); BigInteger _hi1 = new BigInteger((typeArgs).Count); - for (BigInteger _6_typeI = BigInteger.Zero; _6_typeI < _hi1; _6_typeI++) { - RAST._IType _7_typeExpr; + for (BigInteger _7_typeI = BigInteger.Zero; _7_typeI < _hi1; _7_typeI++) { + RAST._IType _8_typeExpr; RAST._IType _out4; - _out4 = (this).GenType((typeArgs).Select(_6_typeI), DCOMP.GenTypeContext.@default()); - _7_typeExpr = _out4; - typeExprs = Dafny.Sequence.Concat(typeExprs, Dafny.Sequence.FromElements(_7_typeExpr)); + _out4 = (this).GenType((typeArgs).Select(_7_typeI), DCOMP.GenTypeContext.@default()); + _8_typeExpr = _out4; + typeExprs = Dafny.Sequence.Concat(typeExprs, Dafny.Sequence.FromElements(_8_typeExpr)); } DAST._ICallName _source0 = name; { if (_source0.is_CallName) { - Dafny.ISequence _8_nameIdent = _source0.dtor_name; + Dafny.ISequence _9_nameIdent = _source0.dtor_name; Std.Wrappers._IOption onType0 = _source0.dtor_onType; if (onType0.is_Some) { DAST._IType value0 = onType0.dtor_value; if (value0.is_UserDefined) { - DAST._IResolvedType _9_resolvedType = value0.dtor_resolved; - if ((((_9_resolvedType).dtor_kind).is_Trait) || (Dafny.Helpers.Id, bool>>((_10_resolvedType, _11_nameIdent) => Dafny.Helpers.Quantifier>(((_10_resolvedType).dtor_properMethods).UniqueElements, true, (((_forall_var_0) => { - Dafny.ISequence _12_m = (Dafny.ISequence)_forall_var_0; - return !(((_10_resolvedType).dtor_properMethods).Contains(_12_m)) || (!object.Equals((_12_m), _11_nameIdent)); - }))))(_9_resolvedType, _8_nameIdent))) { - fullNameQualifier = Std.Wrappers.Option.create_Some(Std.Wrappers.Option.GetOr(DCOMP.__default.TraitTypeContainingMethod(_9_resolvedType, (_8_nameIdent)), _9_resolvedType)); + DAST._IResolvedType _10_resolvedType = value0.dtor_resolved; + if ((((_10_resolvedType).dtor_kind).is_Trait) || (Dafny.Helpers.Id, bool>>((_11_resolvedType, _12_nameIdent) => Dafny.Helpers.Quantifier>(Dafny.Helpers.SingleValue>(_12_nameIdent), true, (((_forall_var_0) => { + Dafny.ISequence _13_m = (Dafny.ISequence)_forall_var_0; + return !(((_11_resolvedType).dtor_properMethods).Contains(_13_m)) || (!object.Equals(_13_m, _12_nameIdent)); + }))))(_10_resolvedType, _9_nameIdent))) { + fullNameQualifier = Std.Wrappers.Option.create_Some(Std.Wrappers.Option.GetOr(DCOMP.__default.TraitTypeContainingMethod(_10_resolvedType, (_9_nameIdent)), _10_resolvedType)); } else { fullNameQualifier = Std.Wrappers.Option.create_None(); } @@ -4949,6 +5253,35 @@ public void GenArgs(DCOMP._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISeq fullNameQualifier = Std.Wrappers.Option.create_None(); } } + public Dafny.ISequence GetMethodName(DAST._IExpression @on, DAST._ICallName name) + { + DAST._ICallName _source0 = name; + { + if (_source0.is_CallName) { + Dafny.ISequence _0_ident = _source0.dtor_name; + if ((@on).is_ExternCompanion) { + return (_0_ident); + } else { + return DCOMP.__default.escapeName(_0_ident); + } + } + } + { + bool disjunctiveMatch0 = false; + if (_source0.is_MapBuilderAdd) { + disjunctiveMatch0 = true; + } + if (_source0.is_SetBuilderAdd) { + disjunctiveMatch0 = true; + } + if (disjunctiveMatch0) { + return Dafny.Sequence.UnicodeFromString("add"); + } + } + { + return Dafny.Sequence.UnicodeFromString("build"); + } + } public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); @@ -4974,7 +5307,7 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv RAST._IExpr _out3; DCOMP._IOwnership _out4; Dafny.ISet> _out5; - (this).GenIdent(DCOMP.__default.escapeName(_0_name), selfIdent, env, expectedOwnership, out _out3, out _out4, out _out5); + (this).GenIdent(DCOMP.__default.escapeVar(_0_name), selfIdent, env, expectedOwnership, out _out3, out _out4, out _out5); r = _out3; resultingOwnership = _out4; readIdents = _out5; @@ -4983,36 +5316,60 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } } { - if (_source0.is_Companion) { - Dafny.ISequence> _1_path = _source0.dtor_Companion_a0; - Dafny.ISequence _2_typeArgs = _source0.dtor_typeArgs; + if (_source0.is_ExternCompanion) { + Dafny.ISequence> _1_path = _source0.dtor_ExternCompanion_a0; { RAST._IExpr _out6; - _out6 = DCOMP.COMP.GenPathExpr(_1_path); + _out6 = DCOMP.COMP.GenPathExpr(_1_path, false); r = _out6; - if ((new BigInteger((_2_typeArgs).Count)).Sign == 1) { - Dafny.ISequence _3_typeExprs; - _3_typeExprs = Dafny.Sequence.FromElements(); - BigInteger _hi0 = new BigInteger((_2_typeArgs).Count); - for (BigInteger _4_i = BigInteger.Zero; _4_i < _hi0; _4_i++) { - RAST._IType _5_typeExpr; - RAST._IType _out7; - _out7 = (this).GenType((_2_typeArgs).Select(_4_i), DCOMP.GenTypeContext.@default()); - _5_typeExpr = _out7; - _3_typeExprs = Dafny.Sequence.Concat(_3_typeExprs, Dafny.Sequence.FromElements(_5_typeExpr)); + if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipBorrowed())) { + resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); + } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwned())) { + resultingOwnership = DCOMP.Ownership.create_OwnershipOwned(); + } else { + RAST._IExpr _out7; + DCOMP._IOwnership _out8; + (this).FromOwned(r, expectedOwnership, out _out7, out _out8); + r = _out7; + resultingOwnership = _out8; + } + readIdents = Dafny.Set>.FromElements(); + return ; + } + goto after_match0; + } + } + { + if (_source0.is_Companion) { + Dafny.ISequence> _2_path = _source0.dtor_Companion_a0; + Dafny.ISequence _3_typeArgs = _source0.dtor_typeArgs; + { + RAST._IExpr _out9; + _out9 = DCOMP.COMP.GenPathExpr(_2_path, true); + r = _out9; + if ((new BigInteger((_3_typeArgs).Count)).Sign == 1) { + Dafny.ISequence _4_typeExprs; + _4_typeExprs = Dafny.Sequence.FromElements(); + BigInteger _hi0 = new BigInteger((_3_typeArgs).Count); + for (BigInteger _5_i = BigInteger.Zero; _5_i < _hi0; _5_i++) { + RAST._IType _6_typeExpr; + RAST._IType _out10; + _out10 = (this).GenType((_3_typeArgs).Select(_5_i), DCOMP.GenTypeContext.@default()); + _6_typeExpr = _out10; + _4_typeExprs = Dafny.Sequence.Concat(_4_typeExprs, Dafny.Sequence.FromElements(_6_typeExpr)); } - r = (r).ApplyType(_3_typeExprs); + r = (r).ApplyType(_4_typeExprs); } if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipBorrowed())) { resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwned())) { resultingOwnership = DCOMP.Ownership.create_OwnershipOwned(); } else { - RAST._IExpr _out8; - DCOMP._IOwnership _out9; - (this).FromOwned(r, expectedOwnership, out _out8, out _out9); - r = _out8; - resultingOwnership = _out9; + RAST._IExpr _out11; + DCOMP._IOwnership _out12; + (this).FromOwned(r, expectedOwnership, out _out11, out _out12); + r = _out11; + resultingOwnership = _out12; } readIdents = Dafny.Set>.FromElements(); return ; @@ -5022,22 +5379,22 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_InitializationValue) { - DAST._IType _6_typ = _source0.dtor_typ; + DAST._IType _7_typ = _source0.dtor_typ; { - RAST._IType _7_typExpr; - RAST._IType _out10; - _out10 = (this).GenType(_6_typ, DCOMP.GenTypeContext.@default()); - _7_typExpr = _out10; - if ((_7_typExpr).IsObjectOrPointer()) { - r = (_7_typExpr).ToNullExpr(); + RAST._IType _8_typExpr; + RAST._IType _out13; + _out13 = (this).GenType(_7_typ, DCOMP.GenTypeContext.@default()); + _8_typExpr = _out13; + if ((_8_typExpr).IsObjectOrPointer()) { + r = (_8_typExpr).ToNullExpr(); } else { - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), (_7_typExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as std::default::Default>::default()"))); + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), (_8_typExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as std::default::Default>::default()"))); } - RAST._IExpr _out11; - DCOMP._IOwnership _out12; - (this).FromOwned(r, expectedOwnership, out _out11, out _out12); - r = _out11; - resultingOwnership = _out12; + RAST._IExpr _out14; + DCOMP._IOwnership _out15; + (this).FromOwned(r, expectedOwnership, out _out14, out _out15); + r = _out14; + resultingOwnership = _out15; readIdents = Dafny.Set>.FromElements(); return ; } @@ -5046,36 +5403,36 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_Tuple) { - Dafny.ISequence _8_values = _source0.dtor_Tuple_a0; + Dafny.ISequence _9_values = _source0.dtor_Tuple_a0; { - Dafny.ISequence _9_exprs; - _9_exprs = Dafny.Sequence.FromElements(); + Dafny.ISequence _10_exprs; + _10_exprs = Dafny.Sequence.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _hi1 = new BigInteger((_8_values).Count); - for (BigInteger _10_i = BigInteger.Zero; _10_i < _hi1; _10_i++) { - RAST._IExpr _11_recursiveGen; - DCOMP._IOwnership _12___v159; - Dafny.ISet> _13_recIdents; - RAST._IExpr _out13; - DCOMP._IOwnership _out14; - Dafny.ISet> _out15; - (this).GenExpr((_8_values).Select(_10_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out13, out _out14, out _out15); - _11_recursiveGen = _out13; - _12___v159 = _out14; - _13_recIdents = _out15; - _9_exprs = Dafny.Sequence.Concat(_9_exprs, Dafny.Sequence.FromElements(_11_recursiveGen)); - readIdents = Dafny.Set>.Union(readIdents, _13_recIdents); + BigInteger _hi1 = new BigInteger((_9_values).Count); + for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { + RAST._IExpr _12_recursiveGen; + DCOMP._IOwnership _13___v165; + Dafny.ISet> _14_recIdents; + RAST._IExpr _out16; + DCOMP._IOwnership _out17; + Dafny.ISet> _out18; + (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); + _12_recursiveGen = _out16; + _13___v165 = _out17; + _14_recIdents = _out18; + _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); + readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); } - if ((new BigInteger((_8_values).Count)) <= (RAST.__default.MAX__TUPLE__SIZE)) { - r = RAST.Expr.create_Tuple(_9_exprs); + if ((new BigInteger((_9_values).Count)) <= (RAST.__default.MAX__TUPLE__SIZE)) { + r = RAST.Expr.create_Tuple(_10_exprs); } else { - r = RAST.__default.SystemTuple(_9_exprs); + r = RAST.__default.SystemTuple(_10_exprs); } - RAST._IExpr _out16; - DCOMP._IOwnership _out17; - (this).FromOwned(r, expectedOwnership, out _out16, out _out17); - r = _out16; - resultingOwnership = _out17; + RAST._IExpr _out19; + DCOMP._IOwnership _out20; + (this).FromOwned(r, expectedOwnership, out _out19, out _out20); + r = _out19; + resultingOwnership = _out20; return ; } goto after_match0; @@ -5083,51 +5440,51 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_New) { - Dafny.ISequence> _14_path = _source0.dtor_path; - Dafny.ISequence _15_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _16_args = _source0.dtor_args; + Dafny.ISequence> _15_path = _source0.dtor_path; + Dafny.ISequence _16_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _17_args = _source0.dtor_args; { - RAST._IExpr _out18; - _out18 = DCOMP.COMP.GenPathExpr(_14_path); - r = _out18; - if ((new BigInteger((_15_typeArgs).Count)).Sign == 1) { - Dafny.ISequence _17_typeExprs; - _17_typeExprs = Dafny.Sequence.FromElements(); - BigInteger _hi2 = new BigInteger((_15_typeArgs).Count); - for (BigInteger _18_i = BigInteger.Zero; _18_i < _hi2; _18_i++) { - RAST._IType _19_typeExpr; - RAST._IType _out19; - _out19 = (this).GenType((_15_typeArgs).Select(_18_i), DCOMP.GenTypeContext.@default()); - _19_typeExpr = _out19; - _17_typeExprs = Dafny.Sequence.Concat(_17_typeExprs, Dafny.Sequence.FromElements(_19_typeExpr)); + RAST._IExpr _out21; + _out21 = DCOMP.COMP.GenPathExpr(_15_path, true); + r = _out21; + if ((new BigInteger((_16_typeArgs).Count)).Sign == 1) { + Dafny.ISequence _18_typeExprs; + _18_typeExprs = Dafny.Sequence.FromElements(); + BigInteger _hi2 = new BigInteger((_16_typeArgs).Count); + for (BigInteger _19_i = BigInteger.Zero; _19_i < _hi2; _19_i++) { + RAST._IType _20_typeExpr; + RAST._IType _out22; + _out22 = (this).GenType((_16_typeArgs).Select(_19_i), DCOMP.GenTypeContext.@default()); + _20_typeExpr = _out22; + _18_typeExprs = Dafny.Sequence.Concat(_18_typeExprs, Dafny.Sequence.FromElements(_20_typeExpr)); } - r = (r).ApplyType(_17_typeExprs); + r = (r).ApplyType(_18_typeExprs); } - r = (r).MSel((this).allocate__fn); + r = (r).FSel((this).allocate__fn); readIdents = Dafny.Set>.FromElements(); - Dafny.ISequence _20_arguments; - _20_arguments = Dafny.Sequence.FromElements(); - BigInteger _hi3 = new BigInteger((_16_args).Count); - for (BigInteger _21_i = BigInteger.Zero; _21_i < _hi3; _21_i++) { - RAST._IExpr _22_recursiveGen; - DCOMP._IOwnership _23___v160; - Dafny.ISet> _24_recIdents; - RAST._IExpr _out20; - DCOMP._IOwnership _out21; - Dafny.ISet> _out22; - (this).GenExpr((_16_args).Select(_21_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out20, out _out21, out _out22); - _22_recursiveGen = _out20; - _23___v160 = _out21; - _24_recIdents = _out22; - _20_arguments = Dafny.Sequence.Concat(_20_arguments, Dafny.Sequence.FromElements(_22_recursiveGen)); - readIdents = Dafny.Set>.Union(readIdents, _24_recIdents); + Dafny.ISequence _21_arguments; + _21_arguments = Dafny.Sequence.FromElements(); + BigInteger _hi3 = new BigInteger((_17_args).Count); + for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { + RAST._IExpr _23_recursiveGen; + DCOMP._IOwnership _24___v166; + Dafny.ISet> _25_recIdents; + RAST._IExpr _out23; + DCOMP._IOwnership _out24; + Dafny.ISet> _out25; + (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); + _23_recursiveGen = _out23; + _24___v166 = _out24; + _25_recIdents = _out25; + _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); + readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); } - r = (r).Apply(_20_arguments); - RAST._IExpr _out23; - DCOMP._IOwnership _out24; - (this).FromOwned(r, expectedOwnership, out _out23, out _out24); - r = _out23; - resultingOwnership = _out24; + r = (r).Apply(_21_arguments); + RAST._IExpr _out26; + DCOMP._IOwnership _out27; + (this).FromOwned(r, expectedOwnership, out _out26, out _out27); + r = _out26; + resultingOwnership = _out27; return ; } goto after_match0; @@ -5135,216 +5492,216 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_NewUninitArray) { - Dafny.ISequence _25_dims = _source0.dtor_dims; - DAST._IType _26_typ = _source0.dtor_typ; + Dafny.ISequence _26_dims = _source0.dtor_dims; + DAST._IType _27_typ = _source0.dtor_typ; { - if ((new BigInteger(16)) < (new BigInteger((_25_dims).Count))) { - Dafny.ISequence _27_msg; - _27_msg = Dafny.Sequence.UnicodeFromString("Unsupported: Creation of arrays of more than 16 dimensions"); + if ((new BigInteger(16)) < (new BigInteger((_26_dims).Count))) { + Dafny.ISequence _28_msg; + _28_msg = Dafny.Sequence.UnicodeFromString("Unsupported: Creation of arrays of more than 16 dimensions"); if ((this.error).is_None) { - (this).error = Std.Wrappers.Option>.create_Some(_27_msg); + (this).error = Std.Wrappers.Option>.create_Some(_28_msg); } - r = RAST.Expr.create_RawExpr(_27_msg); + r = RAST.Expr.create_RawExpr(_28_msg); readIdents = Dafny.Set>.FromElements(); } else { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); - RAST._IType _28_typeGen; - RAST._IType _out25; - _out25 = (this).GenType(_26_typ, DCOMP.GenTypeContext.@default()); - _28_typeGen = _out25; + RAST._IType _29_typeGen; + RAST._IType _out28; + _out28 = (this).GenType(_27_typ, DCOMP.GenTypeContext.@default()); + _29_typeGen = _out28; readIdents = Dafny.Set>.FromElements(); - Dafny.ISequence _29_dimExprs; - _29_dimExprs = Dafny.Sequence.FromElements(); - BigInteger _hi4 = new BigInteger((_25_dims).Count); - for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { - RAST._IExpr _31_recursiveGen; - DCOMP._IOwnership _32___v161; - Dafny.ISet> _33_recIdents; - RAST._IExpr _out26; - DCOMP._IOwnership _out27; - Dafny.ISet> _out28; - (this).GenExpr((_25_dims).Select(_30_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out26, out _out27, out _out28); - _31_recursiveGen = _out26; - _32___v161 = _out27; - _33_recIdents = _out28; - _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); - readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); + Dafny.ISequence _30_dimExprs; + _30_dimExprs = Dafny.Sequence.FromElements(); + BigInteger _hi4 = new BigInteger((_26_dims).Count); + for (BigInteger _31_i = BigInteger.Zero; _31_i < _hi4; _31_i++) { + RAST._IExpr _32_recursiveGen; + DCOMP._IOwnership _33___v167; + Dafny.ISet> _34_recIdents; + RAST._IExpr _out29; + DCOMP._IOwnership _out30; + Dafny.ISet> _out31; + (this).GenExpr((_26_dims).Select(_31_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out29, out _out30, out _out31); + _32_recursiveGen = _out29; + _33___v167 = _out30; + _34_recIdents = _out31; + _30_dimExprs = Dafny.Sequence.Concat(_30_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_32_recursiveGen))); + readIdents = Dafny.Set>.Union(readIdents, _34_recIdents); } - if ((new BigInteger((_25_dims).Count)) > (BigInteger.One)) { - Dafny.ISequence _34_class__name; - _34_class__name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array"), Std.Strings.__default.OfNat(new BigInteger((_25_dims).Count))); - r = ((((RAST.__default.dafny__runtime).MSel(_34_class__name)).ApplyType(Dafny.Sequence.FromElements(_28_typeGen))).MSel((this).placebos__usize)).Apply(_29_dimExprs); + if ((new BigInteger((_26_dims).Count)) > (BigInteger.One)) { + Dafny.ISequence _35_class__name; + _35_class__name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array"), Std.Strings.__default.OfNat(new BigInteger((_26_dims).Count))); + r = (((((RAST.__default.dafny__runtime).MSel(_35_class__name)).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_29_typeGen))).FSel((this).placebos__usize)).Apply(_30_dimExprs); } else { - r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("array"))).MSel((this).placebos__usize)).ApplyType(Dafny.Sequence.FromElements(_28_typeGen))).Apply(_29_dimExprs); + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("array"))).AsExpr()).FSel((this).placebos__usize)).ApplyType(Dafny.Sequence.FromElements(_29_typeGen))).Apply(_30_dimExprs); } } - RAST._IExpr _out29; - DCOMP._IOwnership _out30; - (this).FromOwned(r, expectedOwnership, out _out29, out _out30); - r = _out29; - resultingOwnership = _out30; + RAST._IExpr _out32; + DCOMP._IOwnership _out33; + (this).FromOwned(r, expectedOwnership, out _out32, out _out33); + r = _out32; + resultingOwnership = _out33; } goto after_match0; } } { if (_source0.is_ArrayIndexToInt) { - DAST._IExpression _35_underlying = _source0.dtor_value; + DAST._IExpression _36_underlying = _source0.dtor_value; { - RAST._IExpr _36_recursiveGen; - DCOMP._IOwnership _37___v162; - Dafny.ISet> _38_recIdents; - RAST._IExpr _out31; - DCOMP._IOwnership _out32; - Dafny.ISet> _out33; - (this).GenExpr(_35_underlying, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out31, out _out32, out _out33); - _36_recursiveGen = _out31; - _37___v162 = _out32; - _38_recIdents = _out33; - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).Apply1(_36_recursiveGen); - readIdents = _38_recIdents; + RAST._IExpr _37_recursiveGen; + DCOMP._IOwnership _38___v168; + Dafny.ISet> _39_recIdents; RAST._IExpr _out34; DCOMP._IOwnership _out35; - (this).FromOwned(r, expectedOwnership, out _out34, out _out35); - r = _out34; - resultingOwnership = _out35; + Dafny.ISet> _out36; + (this).GenExpr(_36_underlying, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out34, out _out35, out _out36); + _37_recursiveGen = _out34; + _38___v168 = _out35; + _39_recIdents = _out36; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_37_recursiveGen); + readIdents = _39_recIdents; + RAST._IExpr _out37; + DCOMP._IOwnership _out38; + (this).FromOwned(r, expectedOwnership, out _out37, out _out38); + r = _out37; + resultingOwnership = _out38; } goto after_match0; } } { if (_source0.is_FinalizeNewArray) { - DAST._IExpression _39_underlying = _source0.dtor_value; - DAST._IType _40_typ = _source0.dtor_typ; + DAST._IExpression _40_underlying = _source0.dtor_value; + DAST._IType _41_typ = _source0.dtor_typ; { - RAST._IType _41_tpe; - RAST._IType _out36; - _out36 = (this).GenType(_40_typ, DCOMP.GenTypeContext.@default()); - _41_tpe = _out36; - RAST._IExpr _42_recursiveGen; - DCOMP._IOwnership _43___v163; - Dafny.ISet> _44_recIdents; - RAST._IExpr _out37; - DCOMP._IOwnership _out38; - Dafny.ISet> _out39; - (this).GenExpr(_39_underlying, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out37, out _out38, out _out39); - _42_recursiveGen = _out37; - _43___v163 = _out38; - _44_recIdents = _out39; - readIdents = _44_recIdents; - if ((_41_tpe).IsObjectOrPointer()) { - RAST._IType _45_t; - _45_t = (_41_tpe).ObjectOrPointerUnderlying(); - if ((_45_t).is_Array) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("array"))).MSel((this).array__construct)).Apply1(_42_recursiveGen); - } else if ((_45_t).IsMultiArray()) { - Dafny.ISequence _46_c; - _46_c = (_45_t).MultiArrayClass(); - r = (((RAST.__default.dafny__runtime).MSel(_46_c)).MSel((this).array__construct)).Apply1(_42_recursiveGen); + RAST._IType _42_tpe; + RAST._IType _out39; + _out39 = (this).GenType(_41_typ, DCOMP.GenTypeContext.@default()); + _42_tpe = _out39; + RAST._IExpr _43_recursiveGen; + DCOMP._IOwnership _44___v169; + Dafny.ISet> _45_recIdents; + RAST._IExpr _out40; + DCOMP._IOwnership _out41; + Dafny.ISet> _out42; + (this).GenExpr(_40_underlying, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out40, out _out41, out _out42); + _43_recursiveGen = _out40; + _44___v169 = _out41; + _45_recIdents = _out42; + readIdents = _45_recIdents; + if ((_42_tpe).IsObjectOrPointer()) { + RAST._IType _46_t; + _46_t = (_42_tpe).ObjectOrPointerUnderlying(); + if ((_46_t).is_Array) { + r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("array"))).AsExpr()).FSel((this).array__construct)).Apply1(_43_recursiveGen); + } else if ((_46_t).IsMultiArray()) { + Dafny.ISequence _47_c; + _47_c = (_46_t).MultiArrayClass(); + r = ((((RAST.__default.dafny__runtime).MSel(_47_c)).AsExpr()).FSel((this).array__construct)).Apply1(_43_recursiveGen); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Finalize New Array with a pointer or object type to something that is not an array or a multi array: "), (_41_tpe)._ToString(DCOMP.__default.IND))); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Finalize New Array with a pointer or object type to something that is not an array or a multi array: "), (_42_tpe)._ToString(DCOMP.__default.IND))); r = RAST.Expr.create_RawExpr((this.error).dtor_value); } } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Finalize New Array with a type that is not a pointer or an object: "), (_41_tpe)._ToString(DCOMP.__default.IND))); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Finalize New Array with a type that is not a pointer or an object: "), (_42_tpe)._ToString(DCOMP.__default.IND))); r = RAST.Expr.create_RawExpr((this.error).dtor_value); } - RAST._IExpr _out40; - DCOMP._IOwnership _out41; - (this).FromOwned(r, expectedOwnership, out _out40, out _out41); - r = _out40; - resultingOwnership = _out41; + RAST._IExpr _out43; + DCOMP._IOwnership _out44; + (this).FromOwned(r, expectedOwnership, out _out43, out _out44); + r = _out43; + resultingOwnership = _out44; } goto after_match0; } } { if (_source0.is_DatatypeValue) { - DAST._IResolvedType _47_datatypeType = _source0.dtor_datatypeType; - Dafny.ISequence _48_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _49_variant = _source0.dtor_variant; - bool _50_isCo = _source0.dtor_isCo; - Dafny.ISequence<_System._ITuple2, DAST._IExpression>> _51_values = _source0.dtor_contents; + DAST._IResolvedType _48_datatypeType = _source0.dtor_datatypeType; + Dafny.ISequence _49_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _50_variant = _source0.dtor_variant; + bool _51_isCo = _source0.dtor_isCo; + Dafny.ISequence<_System._ITuple2, DAST._IExpression>> _52_values = _source0.dtor_contents; { - RAST._IExpr _out42; - _out42 = DCOMP.COMP.GenPathExpr((_47_datatypeType).dtor_path); - r = _out42; - Dafny.ISequence _52_genTypeArgs; - _52_genTypeArgs = Dafny.Sequence.FromElements(); - BigInteger _hi5 = new BigInteger((_48_typeArgs).Count); - for (BigInteger _53_i = BigInteger.Zero; _53_i < _hi5; _53_i++) { - RAST._IType _54_typeExpr; - RAST._IType _out43; - _out43 = (this).GenType((_48_typeArgs).Select(_53_i), DCOMP.GenTypeContext.@default()); - _54_typeExpr = _out43; - _52_genTypeArgs = Dafny.Sequence.Concat(_52_genTypeArgs, Dafny.Sequence.FromElements(_54_typeExpr)); + RAST._IExpr _out45; + _out45 = DCOMP.COMP.GenPathExpr((_48_datatypeType).dtor_path, true); + r = _out45; + Dafny.ISequence _53_genTypeArgs; + _53_genTypeArgs = Dafny.Sequence.FromElements(); + BigInteger _hi5 = new BigInteger((_49_typeArgs).Count); + for (BigInteger _54_i = BigInteger.Zero; _54_i < _hi5; _54_i++) { + RAST._IType _55_typeExpr; + RAST._IType _out46; + _out46 = (this).GenType((_49_typeArgs).Select(_54_i), DCOMP.GenTypeContext.@default()); + _55_typeExpr = _out46; + _53_genTypeArgs = Dafny.Sequence.Concat(_53_genTypeArgs, Dafny.Sequence.FromElements(_55_typeExpr)); } - if ((new BigInteger((_48_typeArgs).Count)).Sign == 1) { - r = (r).ApplyType(_52_genTypeArgs); + if ((new BigInteger((_49_typeArgs).Count)).Sign == 1) { + r = (r).ApplyType(_53_genTypeArgs); } - r = (r).MSel(DCOMP.__default.escapeName(_49_variant)); + r = (r).FSel(DCOMP.__default.escapeName(_50_variant)); readIdents = Dafny.Set>.FromElements(); - Dafny.ISequence _55_assignments; - _55_assignments = Dafny.Sequence.FromElements(); - BigInteger _hi6 = new BigInteger((_51_values).Count); - for (BigInteger _56_i = BigInteger.Zero; _56_i < _hi6; _56_i++) { - _System._ITuple2, DAST._IExpression> _let_tmp_rhs0 = (_51_values).Select(_56_i); - Dafny.ISequence _57_name = _let_tmp_rhs0.dtor__0; - DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; - if (_50_isCo) { - RAST._IExpr _59_recursiveGen; - DCOMP._IOwnership _60___v164; - Dafny.ISet> _61_recIdents; - RAST._IExpr _out44; - DCOMP._IOwnership _out45; - Dafny.ISet> _out46; - (this).GenExpr(_58_value, selfIdent, DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); - _59_recursiveGen = _out44; - _60___v164 = _out45; - _61_recIdents = _out46; - readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); - Dafny.ISequence _62_allReadCloned; - _62_allReadCloned = Dafny.Sequence.UnicodeFromString(""); - while (!(_61_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _63_next; - foreach (Dafny.ISequence _assign_such_that_0 in (_61_recIdents).Elements) { - _63_next = (Dafny.ISequence)_assign_such_that_0; - if ((_61_recIdents).Contains(_63_next)) { + Dafny.ISequence _56_assignments; + _56_assignments = Dafny.Sequence.FromElements(); + BigInteger _hi6 = new BigInteger((_52_values).Count); + for (BigInteger _57_i = BigInteger.Zero; _57_i < _hi6; _57_i++) { + _System._ITuple2, DAST._IExpression> _let_tmp_rhs0 = (_52_values).Select(_57_i); + Dafny.ISequence _58_name = _let_tmp_rhs0.dtor__0; + DAST._IExpression _59_value = _let_tmp_rhs0.dtor__1; + if (_51_isCo) { + RAST._IExpr _60_recursiveGen; + DCOMP._IOwnership _61___v170; + Dafny.ISet> _62_recIdents; + RAST._IExpr _out47; + DCOMP._IOwnership _out48; + Dafny.ISet> _out49; + (this).GenExpr(_59_value, selfIdent, DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out47, out _out48, out _out49); + _60_recursiveGen = _out47; + _61___v170 = _out48; + _62_recIdents = _out49; + readIdents = Dafny.Set>.Union(readIdents, _62_recIdents); + Dafny.ISequence _63_allReadCloned; + _63_allReadCloned = Dafny.Sequence.UnicodeFromString(""); + while (!(_62_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _64_next; + foreach (Dafny.ISequence _assign_such_that_0 in (_62_recIdents).Elements) { + _64_next = (Dafny.ISequence)_assign_such_that_0; + if ((_62_recIdents).Contains(_64_next)) { goto after__ASSIGN_SUCH_THAT_0; } } - throw new System.Exception("assign-such-that search produced no value (line 4402)"); + throw new System.Exception("assign-such-that search produced no value (line 4736)"); after__ASSIGN_SUCH_THAT_0: ; - _62_allReadCloned = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_62_allReadCloned, Dafny.Sequence.UnicodeFromString("let ")), _63_next), Dafny.Sequence.UnicodeFromString(" = ")), _63_next), Dafny.Sequence.UnicodeFromString(".clone();\n")); - _61_recIdents = Dafny.Set>.Difference(_61_recIdents, Dafny.Set>.FromElements(_63_next)); + _63_allReadCloned = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_63_allReadCloned, Dafny.Sequence.UnicodeFromString("let ")), _64_next), Dafny.Sequence.UnicodeFromString(" = ")), _64_next), Dafny.Sequence.UnicodeFromString(".clone();\n")); + _62_recIdents = Dafny.Set>.Difference(_62_recIdents, Dafny.Set>.FromElements(_64_next)); } - Dafny.ISequence _64_wasAssigned; - _64_wasAssigned = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::LazyFieldWrapper(::dafny_runtime::Lazy::new(::std::boxed::Box::new({\n"), _62_allReadCloned), Dafny.Sequence.UnicodeFromString("move || (")), (_59_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")})))")); - _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeIdent(_57_name), RAST.Expr.create_RawExpr(_64_wasAssigned)))); + Dafny.ISequence _65_wasAssigned; + _65_wasAssigned = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::LazyFieldWrapper(::dafny_runtime::Lazy::new(::std::boxed::Box::new({\n"), _63_allReadCloned), Dafny.Sequence.UnicodeFromString("move || (")), (_60_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")})))")); + _56_assignments = Dafny.Sequence.Concat(_56_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeVar(_58_name), RAST.Expr.create_RawExpr(_65_wasAssigned)))); } else { - RAST._IExpr _65_recursiveGen; - DCOMP._IOwnership _66___v165; - Dafny.ISet> _67_recIdents; - RAST._IExpr _out47; - DCOMP._IOwnership _out48; - Dafny.ISet> _out49; - (this).GenExpr(_58_value, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out47, out _out48, out _out49); - _65_recursiveGen = _out47; - _66___v165 = _out48; - _67_recIdents = _out49; - _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeIdent(_57_name), _65_recursiveGen))); - readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); + RAST._IExpr _66_recursiveGen; + DCOMP._IOwnership _67___v171; + Dafny.ISet> _68_recIdents; + RAST._IExpr _out50; + DCOMP._IOwnership _out51; + Dafny.ISet> _out52; + (this).GenExpr(_59_value, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); + _66_recursiveGen = _out50; + _67___v171 = _out51; + _68_recIdents = _out52; + _56_assignments = Dafny.Sequence.Concat(_56_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeVar(_58_name), _66_recursiveGen))); + readIdents = Dafny.Set>.Union(readIdents, _68_recIdents); } } - r = RAST.Expr.create_StructBuild(r, _55_assignments); - if ((this).IsRcWrapped((_47_datatypeType).dtor_attributes)) { + r = RAST.Expr.create_StructBuild(r, _56_assignments); + if ((this).IsRcWrapped((_48_datatypeType).dtor_attributes)) { r = RAST.__default.RcNew(r); } - RAST._IExpr _out50; - DCOMP._IOwnership _out51; - (this).FromOwned(r, expectedOwnership, out _out50, out _out51); - r = _out50; - resultingOwnership = _out51; + RAST._IExpr _out53; + DCOMP._IOwnership _out54; + (this).FromOwned(r, expectedOwnership, out _out53, out _out54); + r = _out53; + resultingOwnership = _out54; return ; } goto after_match0; @@ -5353,49 +5710,49 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv { if (_source0.is_Convert) { { - RAST._IExpr _out52; - DCOMP._IOwnership _out53; - Dafny.ISet> _out54; - (this).GenExprConvert(e, selfIdent, env, expectedOwnership, out _out52, out _out53, out _out54); - r = _out52; - resultingOwnership = _out53; - readIdents = _out54; + RAST._IExpr _out55; + DCOMP._IOwnership _out56; + Dafny.ISet> _out57; + (this).GenExprConvert(e, selfIdent, env, expectedOwnership, out _out55, out _out56, out _out57); + r = _out55; + resultingOwnership = _out56; + readIdents = _out57; } goto after_match0; } } { if (_source0.is_SeqConstruct) { - DAST._IExpression _68_length = _source0.dtor_length; - DAST._IExpression _69_expr = _source0.dtor_elem; + DAST._IExpression _69_length = _source0.dtor_length; + DAST._IExpression _70_expr = _source0.dtor_elem; { - RAST._IExpr _70_recursiveGen; - DCOMP._IOwnership _71___v169; - Dafny.ISet> _72_recIdents; - RAST._IExpr _out55; - DCOMP._IOwnership _out56; - Dafny.ISet> _out57; - (this).GenExpr(_69_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out55, out _out56, out _out57); - _70_recursiveGen = _out55; - _71___v169 = _out56; - _72_recIdents = _out57; - RAST._IExpr _73_lengthGen; - DCOMP._IOwnership _74___v170; - Dafny.ISet> _75_lengthIdents; + RAST._IExpr _71_recursiveGen; + DCOMP._IOwnership _72___v175; + Dafny.ISet> _73_recIdents; RAST._IExpr _out58; DCOMP._IOwnership _out59; Dafny.ISet> _out60; - (this).GenExpr(_68_length, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); - _73_lengthGen = _out58; - _74___v170 = _out59; - _75_lengthIdents = _out60; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("{\nlet _initializer = "), (_70_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(";\n::dafny_runtime::integer_range(::dafny_runtime::Zero::zero(), ")), (_73_lengthGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").map(|i| _initializer(&i)).collect::<::dafny_runtime::Sequence<_>>()\n}"))); - readIdents = Dafny.Set>.Union(_72_recIdents, _75_lengthIdents); + (this).GenExpr(_70_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); + _71_recursiveGen = _out58; + _72___v175 = _out59; + _73_recIdents = _out60; + RAST._IExpr _74_lengthGen; + DCOMP._IOwnership _75___v176; + Dafny.ISet> _76_lengthIdents; RAST._IExpr _out61; DCOMP._IOwnership _out62; - (this).FromOwned(r, expectedOwnership, out _out61, out _out62); - r = _out61; - resultingOwnership = _out62; + Dafny.ISet> _out63; + (this).GenExpr(_69_length, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); + _74_lengthGen = _out61; + _75___v176 = _out62; + _76_lengthIdents = _out63; + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("{\nlet _initializer = "), (_71_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(";\n::dafny_runtime::integer_range(::dafny_runtime::Zero::zero(), ")), (_74_lengthGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").map(|i| _initializer(&i)).collect::<::dafny_runtime::Sequence<_>>()\n}"))); + readIdents = Dafny.Set>.Union(_73_recIdents, _76_lengthIdents); + RAST._IExpr _out64; + DCOMP._IOwnership _out65; + (this).FromOwned(r, expectedOwnership, out _out64, out _out65); + r = _out64; + resultingOwnership = _out65; return ; } goto after_match0; @@ -5403,42 +5760,42 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_SeqValue) { - Dafny.ISequence _76_exprs = _source0.dtor_elements; - DAST._IType _77_typ = _source0.dtor_typ; + Dafny.ISequence _77_exprs = _source0.dtor_elements; + DAST._IType _78_typ = _source0.dtor_typ; { readIdents = Dafny.Set>.FromElements(); - RAST._IType _78_genTpe; - RAST._IType _out63; - _out63 = (this).GenType(_77_typ, DCOMP.GenTypeContext.@default()); - _78_genTpe = _out63; - BigInteger _79_i; - _79_i = BigInteger.Zero; - Dafny.ISequence _80_args; - _80_args = Dafny.Sequence.FromElements(); - while ((_79_i) < (new BigInteger((_76_exprs).Count))) { - RAST._IExpr _81_recursiveGen; - DCOMP._IOwnership _82___v171; - Dafny.ISet> _83_recIdents; - RAST._IExpr _out64; - DCOMP._IOwnership _out65; - Dafny.ISet> _out66; - (this).GenExpr((_76_exprs).Select(_79_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); - _81_recursiveGen = _out64; - _82___v171 = _out65; - _83_recIdents = _out66; - readIdents = Dafny.Set>.Union(readIdents, _83_recIdents); - _80_args = Dafny.Sequence.Concat(_80_args, Dafny.Sequence.FromElements(_81_recursiveGen)); - _79_i = (_79_i) + (BigInteger.One); + RAST._IType _79_genTpe; + RAST._IType _out66; + _out66 = (this).GenType(_78_typ, DCOMP.GenTypeContext.@default()); + _79_genTpe = _out66; + BigInteger _80_i; + _80_i = BigInteger.Zero; + Dafny.ISequence _81_args; + _81_args = Dafny.Sequence.FromElements(); + while ((_80_i) < (new BigInteger((_77_exprs).Count))) { + RAST._IExpr _82_recursiveGen; + DCOMP._IOwnership _83___v177; + Dafny.ISet> _84_recIdents; + RAST._IExpr _out67; + DCOMP._IOwnership _out68; + Dafny.ISet> _out69; + (this).GenExpr((_77_exprs).Select(_80_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out67, out _out68, out _out69); + _82_recursiveGen = _out67; + _83___v177 = _out68; + _84_recIdents = _out69; + readIdents = Dafny.Set>.Union(readIdents, _84_recIdents); + _81_args = Dafny.Sequence.Concat(_81_args, Dafny.Sequence.FromElements(_82_recursiveGen)); + _80_i = (_80_i) + (BigInteger.One); } - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).Apply(_80_args); - if ((new BigInteger((_80_args).Count)).Sign == 0) { - r = RAST.Expr.create_TypeAscription(r, ((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Sequence"))).Apply1(_78_genTpe)); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).AsExpr()).Apply(_81_args); + if ((new BigInteger((_81_args).Count)).Sign == 0) { + r = RAST.Expr.create_TypeAscription(r, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Sequence"))).AsType()).Apply1(_79_genTpe)); } - RAST._IExpr _out67; - DCOMP._IOwnership _out68; - (this).FromOwned(r, expectedOwnership, out _out67, out _out68); - r = _out67; - resultingOwnership = _out68; + RAST._IExpr _out70; + DCOMP._IOwnership _out71; + (this).FromOwned(r, expectedOwnership, out _out70, out _out71); + r = _out70; + resultingOwnership = _out71; return ; } goto after_match0; @@ -5446,34 +5803,34 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_SetValue) { - Dafny.ISequence _84_exprs = _source0.dtor_elements; + Dafny.ISequence _85_exprs = _source0.dtor_elements; { - Dafny.ISequence _85_generatedValues; - _85_generatedValues = Dafny.Sequence.FromElements(); + Dafny.ISequence _86_generatedValues; + _86_generatedValues = Dafny.Sequence.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _86_i; - _86_i = BigInteger.Zero; - while ((_86_i) < (new BigInteger((_84_exprs).Count))) { - RAST._IExpr _87_recursiveGen; - DCOMP._IOwnership _88___v172; - Dafny.ISet> _89_recIdents; - RAST._IExpr _out69; - DCOMP._IOwnership _out70; - Dafny.ISet> _out71; - (this).GenExpr((_84_exprs).Select(_86_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out69, out _out70, out _out71); - _87_recursiveGen = _out69; - _88___v172 = _out70; - _89_recIdents = _out71; - _85_generatedValues = Dafny.Sequence.Concat(_85_generatedValues, Dafny.Sequence.FromElements(_87_recursiveGen)); - readIdents = Dafny.Set>.Union(readIdents, _89_recIdents); - _86_i = (_86_i) + (BigInteger.One); + BigInteger _87_i; + _87_i = BigInteger.Zero; + while ((_87_i) < (new BigInteger((_85_exprs).Count))) { + RAST._IExpr _88_recursiveGen; + DCOMP._IOwnership _89___v178; + Dafny.ISet> _90_recIdents; + RAST._IExpr _out72; + DCOMP._IOwnership _out73; + Dafny.ISet> _out74; + (this).GenExpr((_85_exprs).Select(_87_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out72, out _out73, out _out74); + _88_recursiveGen = _out72; + _89___v178 = _out73; + _90_recIdents = _out74; + _86_generatedValues = Dafny.Sequence.Concat(_86_generatedValues, Dafny.Sequence.FromElements(_88_recursiveGen)); + readIdents = Dafny.Set>.Union(readIdents, _90_recIdents); + _87_i = (_87_i) + (BigInteger.One); } - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("set!"))).Apply(_85_generatedValues); - RAST._IExpr _out72; - DCOMP._IOwnership _out73; - (this).FromOwned(r, expectedOwnership, out _out72, out _out73); - r = _out72; - resultingOwnership = _out73; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("set!"))).AsExpr()).Apply(_86_generatedValues); + RAST._IExpr _out75; + DCOMP._IOwnership _out76; + (this).FromOwned(r, expectedOwnership, out _out75, out _out76); + r = _out75; + resultingOwnership = _out76; return ; } goto after_match0; @@ -5481,34 +5838,34 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_MultisetValue) { - Dafny.ISequence _90_exprs = _source0.dtor_elements; + Dafny.ISequence _91_exprs = _source0.dtor_elements; { - Dafny.ISequence _91_generatedValues; - _91_generatedValues = Dafny.Sequence.FromElements(); + Dafny.ISequence _92_generatedValues; + _92_generatedValues = Dafny.Sequence.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _92_i; - _92_i = BigInteger.Zero; - while ((_92_i) < (new BigInteger((_90_exprs).Count))) { - RAST._IExpr _93_recursiveGen; - DCOMP._IOwnership _94___v173; - Dafny.ISet> _95_recIdents; - RAST._IExpr _out74; - DCOMP._IOwnership _out75; - Dafny.ISet> _out76; - (this).GenExpr((_90_exprs).Select(_92_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out74, out _out75, out _out76); - _93_recursiveGen = _out74; - _94___v173 = _out75; - _95_recIdents = _out76; - _91_generatedValues = Dafny.Sequence.Concat(_91_generatedValues, Dafny.Sequence.FromElements(_93_recursiveGen)); - readIdents = Dafny.Set>.Union(readIdents, _95_recIdents); - _92_i = (_92_i) + (BigInteger.One); + BigInteger _93_i; + _93_i = BigInteger.Zero; + while ((_93_i) < (new BigInteger((_91_exprs).Count))) { + RAST._IExpr _94_recursiveGen; + DCOMP._IOwnership _95___v179; + Dafny.ISet> _96_recIdents; + RAST._IExpr _out77; + DCOMP._IOwnership _out78; + Dafny.ISet> _out79; + (this).GenExpr((_91_exprs).Select(_93_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out77, out _out78, out _out79); + _94_recursiveGen = _out77; + _95___v179 = _out78; + _96_recIdents = _out79; + _92_generatedValues = Dafny.Sequence.Concat(_92_generatedValues, Dafny.Sequence.FromElements(_94_recursiveGen)); + readIdents = Dafny.Set>.Union(readIdents, _96_recIdents); + _93_i = (_93_i) + (BigInteger.One); } - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("multiset!"))).Apply(_91_generatedValues); - RAST._IExpr _out77; - DCOMP._IOwnership _out78; - (this).FromOwned(r, expectedOwnership, out _out77, out _out78); - r = _out77; - resultingOwnership = _out78; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("multiset!"))).AsExpr()).Apply(_92_generatedValues); + RAST._IExpr _out80; + DCOMP._IOwnership _out81; + (this).FromOwned(r, expectedOwnership, out _out80, out _out81); + r = _out80; + resultingOwnership = _out81; return ; } goto after_match0; @@ -5516,25 +5873,25 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_ToMultiset) { - DAST._IExpression _96_expr = _source0.dtor_ToMultiset_a0; + DAST._IExpression _97_expr = _source0.dtor_ToMultiset_a0; { - RAST._IExpr _97_recursiveGen; - DCOMP._IOwnership _98___v174; - Dafny.ISet> _99_recIdents; - RAST._IExpr _out79; - DCOMP._IOwnership _out80; - Dafny.ISet> _out81; - (this).GenExpr(_96_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out79, out _out80, out _out81); - _97_recursiveGen = _out79; - _98___v174 = _out80; - _99_recIdents = _out81; - r = ((_97_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply(Dafny.Sequence.FromElements()); - readIdents = _99_recIdents; + RAST._IExpr _98_recursiveGen; + DCOMP._IOwnership _99___v180; + Dafny.ISet> _100_recIdents; RAST._IExpr _out82; DCOMP._IOwnership _out83; - (this).FromOwned(r, expectedOwnership, out _out82, out _out83); - r = _out82; - resultingOwnership = _out83; + Dafny.ISet> _out84; + (this).GenExpr(_97_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out82, out _out83, out _out84); + _98_recursiveGen = _out82; + _99___v180 = _out83; + _100_recIdents = _out84; + r = ((_98_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply(Dafny.Sequence.FromElements()); + readIdents = _100_recIdents; + RAST._IExpr _out85; + DCOMP._IOwnership _out86; + (this).FromOwned(r, expectedOwnership, out _out85, out _out86); + r = _out85; + resultingOwnership = _out86; return ; } goto after_match0; @@ -5542,55 +5899,55 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_MapValue) { - Dafny.ISequence<_System._ITuple2> _100_mapElems = _source0.dtor_mapElems; + Dafny.ISequence<_System._ITuple2> _101_mapElems = _source0.dtor_mapElems; { - Dafny.ISequence<_System._ITuple2> _101_generatedValues; - _101_generatedValues = Dafny.Sequence<_System._ITuple2>.FromElements(); + Dafny.ISequence<_System._ITuple2> _102_generatedValues; + _102_generatedValues = Dafny.Sequence<_System._ITuple2>.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _102_i; - _102_i = BigInteger.Zero; - while ((_102_i) < (new BigInteger((_100_mapElems).Count))) { - RAST._IExpr _103_recursiveGenKey; - DCOMP._IOwnership _104___v175; - Dafny.ISet> _105_recIdentsKey; - RAST._IExpr _out84; - DCOMP._IOwnership _out85; - Dafny.ISet> _out86; - (this).GenExpr(((_100_mapElems).Select(_102_i)).dtor__0, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out84, out _out85, out _out86); - _103_recursiveGenKey = _out84; - _104___v175 = _out85; - _105_recIdentsKey = _out86; - RAST._IExpr _106_recursiveGenValue; - DCOMP._IOwnership _107___v176; - Dafny.ISet> _108_recIdentsValue; + BigInteger _103_i; + _103_i = BigInteger.Zero; + while ((_103_i) < (new BigInteger((_101_mapElems).Count))) { + RAST._IExpr _104_recursiveGenKey; + DCOMP._IOwnership _105___v181; + Dafny.ISet> _106_recIdentsKey; RAST._IExpr _out87; DCOMP._IOwnership _out88; Dafny.ISet> _out89; - (this).GenExpr(((_100_mapElems).Select(_102_i)).dtor__1, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out87, out _out88, out _out89); - _106_recursiveGenValue = _out87; - _107___v176 = _out88; - _108_recIdentsValue = _out89; - _101_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_101_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_103_recursiveGenKey, _106_recursiveGenValue))); - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _105_recIdentsKey), _108_recIdentsValue); - _102_i = (_102_i) + (BigInteger.One); + (this).GenExpr(((_101_mapElems).Select(_103_i)).dtor__0, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out87, out _out88, out _out89); + _104_recursiveGenKey = _out87; + _105___v181 = _out88; + _106_recIdentsKey = _out89; + RAST._IExpr _107_recursiveGenValue; + DCOMP._IOwnership _108___v182; + Dafny.ISet> _109_recIdentsValue; + RAST._IExpr _out90; + DCOMP._IOwnership _out91; + Dafny.ISet> _out92; + (this).GenExpr(((_101_mapElems).Select(_103_i)).dtor__1, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); + _107_recursiveGenValue = _out90; + _108___v182 = _out91; + _109_recIdentsValue = _out92; + _102_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_102_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_104_recursiveGenKey, _107_recursiveGenValue))); + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _106_recIdentsKey), _109_recIdentsValue); + _103_i = (_103_i) + (BigInteger.One); } - _102_i = BigInteger.Zero; - Dafny.ISequence _109_arguments; - _109_arguments = Dafny.Sequence.FromElements(); - while ((_102_i) < (new BigInteger((_101_generatedValues).Count))) { - RAST._IExpr _110_genKey; - _110_genKey = ((_101_generatedValues).Select(_102_i)).dtor__0; - RAST._IExpr _111_genValue; - _111_genValue = ((_101_generatedValues).Select(_102_i)).dtor__1; - _109_arguments = Dafny.Sequence.Concat(_109_arguments, Dafny.Sequence.FromElements(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=>"), _110_genKey, _111_genValue, DAST.Format.BinaryOpFormat.create_NoFormat()))); - _102_i = (_102_i) + (BigInteger.One); + _103_i = BigInteger.Zero; + Dafny.ISequence _110_arguments; + _110_arguments = Dafny.Sequence.FromElements(); + while ((_103_i) < (new BigInteger((_102_generatedValues).Count))) { + RAST._IExpr _111_genKey; + _111_genKey = ((_102_generatedValues).Select(_103_i)).dtor__0; + RAST._IExpr _112_genValue; + _112_genValue = ((_102_generatedValues).Select(_103_i)).dtor__1; + _110_arguments = Dafny.Sequence.Concat(_110_arguments, Dafny.Sequence.FromElements(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=>"), _111_genKey, _112_genValue, DAST.Format.BinaryOpFormat.create_NoFormat()))); + _103_i = (_103_i) + (BigInteger.One); } - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("map!"))).Apply(_109_arguments); - RAST._IExpr _out90; - DCOMP._IOwnership _out91; - (this).FromOwned(r, expectedOwnership, out _out90, out _out91); - r = _out90; - resultingOwnership = _out91; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("map!"))).AsExpr()).Apply(_110_arguments); + RAST._IExpr _out93; + DCOMP._IOwnership _out94; + (this).FromOwned(r, expectedOwnership, out _out93, out _out94); + r = _out93; + resultingOwnership = _out94; return ; } goto after_match0; @@ -5598,47 +5955,47 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_SeqUpdate) { - DAST._IExpression _112_expr = _source0.dtor_expr; - DAST._IExpression _113_index = _source0.dtor_indexExpr; - DAST._IExpression _114_value = _source0.dtor_value; + DAST._IExpression _113_expr = _source0.dtor_expr; + DAST._IExpression _114_index = _source0.dtor_indexExpr; + DAST._IExpression _115_value = _source0.dtor_value; { - RAST._IExpr _115_exprR; - DCOMP._IOwnership _116___v177; - Dafny.ISet> _117_exprIdents; - RAST._IExpr _out92; - DCOMP._IOwnership _out93; - Dafny.ISet> _out94; - (this).GenExpr(_112_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out92, out _out93, out _out94); - _115_exprR = _out92; - _116___v177 = _out93; - _117_exprIdents = _out94; - RAST._IExpr _118_indexR; - DCOMP._IOwnership _119_indexOwnership; - Dafny.ISet> _120_indexIdents; + RAST._IExpr _116_exprR; + DCOMP._IOwnership _117___v183; + Dafny.ISet> _118_exprIdents; RAST._IExpr _out95; DCOMP._IOwnership _out96; Dafny.ISet> _out97; - (this).GenExpr(_113_index, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out95, out _out96, out _out97); - _118_indexR = _out95; - _119_indexOwnership = _out96; - _120_indexIdents = _out97; - RAST._IExpr _121_valueR; - DCOMP._IOwnership _122_valueOwnership; - Dafny.ISet> _123_valueIdents; + (this).GenExpr(_113_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out95, out _out96, out _out97); + _116_exprR = _out95; + _117___v183 = _out96; + _118_exprIdents = _out97; + RAST._IExpr _119_indexR; + DCOMP._IOwnership _120_indexOwnership; + Dafny.ISet> _121_indexIdents; RAST._IExpr _out98; DCOMP._IOwnership _out99; Dafny.ISet> _out100; - (this).GenExpr(_114_value, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out98, out _out99, out _out100); - _121_valueR = _out98; - _122_valueOwnership = _out99; - _123_valueIdents = _out100; - r = ((_115_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_118_indexR, _121_valueR)); + (this).GenExpr(_114_index, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out98, out _out99, out _out100); + _119_indexR = _out98; + _120_indexOwnership = _out99; + _121_indexIdents = _out100; + RAST._IExpr _122_valueR; + DCOMP._IOwnership _123_valueOwnership; + Dafny.ISet> _124_valueIdents; RAST._IExpr _out101; DCOMP._IOwnership _out102; - (this).FromOwned(r, expectedOwnership, out _out101, out _out102); - r = _out101; - resultingOwnership = _out102; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_117_exprIdents, _120_indexIdents), _123_valueIdents); + Dafny.ISet> _out103; + (this).GenExpr(_115_value, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out101, out _out102, out _out103); + _122_valueR = _out101; + _123_valueOwnership = _out102; + _124_valueIdents = _out103; + r = ((_116_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_119_indexR, _122_valueR)); + RAST._IExpr _out104; + DCOMP._IOwnership _out105; + (this).FromOwned(r, expectedOwnership, out _out104, out _out105); + r = _out104; + resultingOwnership = _out105; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_118_exprIdents, _121_indexIdents), _124_valueIdents); return ; } goto after_match0; @@ -5646,47 +6003,47 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_MapUpdate) { - DAST._IExpression _124_expr = _source0.dtor_expr; - DAST._IExpression _125_index = _source0.dtor_indexExpr; - DAST._IExpression _126_value = _source0.dtor_value; + DAST._IExpression _125_expr = _source0.dtor_expr; + DAST._IExpression _126_index = _source0.dtor_indexExpr; + DAST._IExpression _127_value = _source0.dtor_value; { - RAST._IExpr _127_exprR; - DCOMP._IOwnership _128___v178; - Dafny.ISet> _129_exprIdents; - RAST._IExpr _out103; - DCOMP._IOwnership _out104; - Dafny.ISet> _out105; - (this).GenExpr(_124_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out103, out _out104, out _out105); - _127_exprR = _out103; - _128___v178 = _out104; - _129_exprIdents = _out105; - RAST._IExpr _130_indexR; - DCOMP._IOwnership _131_indexOwnership; - Dafny.ISet> _132_indexIdents; + RAST._IExpr _128_exprR; + DCOMP._IOwnership _129___v184; + Dafny.ISet> _130_exprIdents; RAST._IExpr _out106; DCOMP._IOwnership _out107; Dafny.ISet> _out108; - (this).GenExpr(_125_index, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out106, out _out107, out _out108); - _130_indexR = _out106; - _131_indexOwnership = _out107; - _132_indexIdents = _out108; - RAST._IExpr _133_valueR; - DCOMP._IOwnership _134_valueOwnership; - Dafny.ISet> _135_valueIdents; + (this).GenExpr(_125_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out106, out _out107, out _out108); + _128_exprR = _out106; + _129___v184 = _out107; + _130_exprIdents = _out108; + RAST._IExpr _131_indexR; + DCOMP._IOwnership _132_indexOwnership; + Dafny.ISet> _133_indexIdents; RAST._IExpr _out109; DCOMP._IOwnership _out110; Dafny.ISet> _out111; - (this).GenExpr(_126_value, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out109, out _out110, out _out111); - _133_valueR = _out109; - _134_valueOwnership = _out110; - _135_valueIdents = _out111; - r = ((_127_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_130_indexR, _133_valueR)); + (this).GenExpr(_126_index, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out109, out _out110, out _out111); + _131_indexR = _out109; + _132_indexOwnership = _out110; + _133_indexIdents = _out111; + RAST._IExpr _134_valueR; + DCOMP._IOwnership _135_valueOwnership; + Dafny.ISet> _136_valueIdents; RAST._IExpr _out112; DCOMP._IOwnership _out113; - (this).FromOwned(r, expectedOwnership, out _out112, out _out113); - r = _out112; - resultingOwnership = _out113; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_129_exprIdents, _132_indexIdents), _135_valueIdents); + Dafny.ISet> _out114; + (this).GenExpr(_127_value, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out112, out _out113, out _out114); + _134_valueR = _out112; + _135_valueOwnership = _out113; + _136_valueIdents = _out114; + r = ((_128_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_131_indexR, _134_valueR)); + RAST._IExpr _out115; + DCOMP._IOwnership _out116; + (this).FromOwned(r, expectedOwnership, out _out115, out _out116); + r = _out115; + resultingOwnership = _out116; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_130_exprIdents, _133_indexIdents), _136_valueIdents); return ; } goto after_match0; @@ -5698,29 +6055,29 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv DCOMP._ISelfInfo _source1 = selfIdent; { if (_source1.is_ThisTyped) { - Dafny.ISequence _136_id = _source1.dtor_rSelfName; - DAST._IType _137_dafnyType = _source1.dtor_dafnyType; + Dafny.ISequence _137_id = _source1.dtor_rSelfName; + DAST._IType _138_dafnyType = _source1.dtor_dafnyType; { - RAST._IExpr _out114; - DCOMP._IOwnership _out115; - Dafny.ISet> _out116; - (this).GenIdent(_136_id, selfIdent, env, expectedOwnership, out _out114, out _out115, out _out116); - r = _out114; - resultingOwnership = _out115; - readIdents = _out116; + RAST._IExpr _out117; + DCOMP._IOwnership _out118; + Dafny.ISet> _out119; + (this).GenIdent(_137_id, selfIdent, env, expectedOwnership, out _out117, out _out118, out _out119); + r = _out117; + resultingOwnership = _out118; + readIdents = _out119; } goto after_match1; } } { - DCOMP._ISelfInfo _138_None = _source1; + DCOMP._ISelfInfo _139_None = _source1; { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("panic!(\"this outside of a method\")")); - RAST._IExpr _out117; - DCOMP._IOwnership _out118; - (this).FromOwned(r, expectedOwnership, out _out117, out _out118); - r = _out117; - resultingOwnership = _out118; + RAST._IExpr _out120; + DCOMP._IOwnership _out121; + (this).FromOwned(r, expectedOwnership, out _out120, out _out121); + r = _out120; + resultingOwnership = _out121; readIdents = Dafny.Set>.FromElements(); } } @@ -5732,47 +6089,47 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_Ite) { - DAST._IExpression _139_cond = _source0.dtor_cond; - DAST._IExpression _140_t = _source0.dtor_thn; - DAST._IExpression _141_f = _source0.dtor_els; + DAST._IExpression _140_cond = _source0.dtor_cond; + DAST._IExpression _141_t = _source0.dtor_thn; + DAST._IExpression _142_f = _source0.dtor_els; { - RAST._IExpr _142_cond; - DCOMP._IOwnership _143___v179; - Dafny.ISet> _144_recIdentsCond; - RAST._IExpr _out119; - DCOMP._IOwnership _out120; - Dafny.ISet> _out121; - (this).GenExpr(_139_cond, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out119, out _out120, out _out121); - _142_cond = _out119; - _143___v179 = _out120; - _144_recIdentsCond = _out121; - RAST._IExpr _145_fExpr; - DCOMP._IOwnership _146_fOwned; - Dafny.ISet> _147_recIdentsF; + RAST._IExpr _143_cond; + DCOMP._IOwnership _144___v185; + Dafny.ISet> _145_recIdentsCond; RAST._IExpr _out122; DCOMP._IOwnership _out123; Dafny.ISet> _out124; - (this).GenExpr(_141_f, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out122, out _out123, out _out124); - _145_fExpr = _out122; - _146_fOwned = _out123; - _147_recIdentsF = _out124; - RAST._IExpr _148_tExpr; - DCOMP._IOwnership _149___v180; - Dafny.ISet> _150_recIdentsT; + (this).GenExpr(_140_cond, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out122, out _out123, out _out124); + _143_cond = _out122; + _144___v185 = _out123; + _145_recIdentsCond = _out124; + RAST._IExpr _146_fExpr; + DCOMP._IOwnership _147_fOwned; + Dafny.ISet> _148_recIdentsF; RAST._IExpr _out125; DCOMP._IOwnership _out126; Dafny.ISet> _out127; - (this).GenExpr(_140_t, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out125, out _out126, out _out127); - _148_tExpr = _out125; - _149___v180 = _out126; - _150_recIdentsT = _out127; - r = RAST.Expr.create_IfExpr(_142_cond, _148_tExpr, _145_fExpr); + (this).GenExpr(_142_f, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out125, out _out126, out _out127); + _146_fExpr = _out125; + _147_fOwned = _out126; + _148_recIdentsF = _out127; + RAST._IExpr _149_tExpr; + DCOMP._IOwnership _150___v186; + Dafny.ISet> _151_recIdentsT; RAST._IExpr _out128; DCOMP._IOwnership _out129; - (this).FromOwnership(r, DCOMP.Ownership.create_OwnershipOwned(), expectedOwnership, out _out128, out _out129); - r = _out128; - resultingOwnership = _out129; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_144_recIdentsCond, _150_recIdentsT), _147_recIdentsF); + Dafny.ISet> _out130; + (this).GenExpr(_141_t, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out128, out _out129, out _out130); + _149_tExpr = _out128; + _150___v186 = _out129; + _151_recIdentsT = _out130; + r = RAST.Expr.create_IfExpr(_143_cond, _149_tExpr, _146_fExpr); + RAST._IExpr _out131; + DCOMP._IOwnership _out132; + (this).FromOwnership(r, DCOMP.Ownership.create_OwnershipOwned(), expectedOwnership, out _out131, out _out132); + r = _out131; + resultingOwnership = _out132; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_145_recIdentsCond, _151_recIdentsT), _148_recIdentsF); return ; } goto after_match0; @@ -5782,26 +6139,26 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv if (_source0.is_UnOp) { DAST._IUnaryOp unOp0 = _source0.dtor_unOp; if (unOp0.is_Not) { - DAST._IExpression _151_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _152_format = _source0.dtor_format1; + DAST._IExpression _152_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _153_format = _source0.dtor_format1; { - RAST._IExpr _153_recursiveGen; - DCOMP._IOwnership _154___v181; - Dafny.ISet> _155_recIdents; - RAST._IExpr _out130; - DCOMP._IOwnership _out131; - Dafny.ISet> _out132; - (this).GenExpr(_151_e, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out130, out _out131, out _out132); - _153_recursiveGen = _out130; - _154___v181 = _out131; - _155_recIdents = _out132; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _153_recursiveGen, _152_format); + RAST._IExpr _154_recursiveGen; + DCOMP._IOwnership _155___v187; + Dafny.ISet> _156_recIdents; RAST._IExpr _out133; DCOMP._IOwnership _out134; - (this).FromOwned(r, expectedOwnership, out _out133, out _out134); - r = _out133; - resultingOwnership = _out134; - readIdents = _155_recIdents; + Dafny.ISet> _out135; + (this).GenExpr(_152_e, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out133, out _out134, out _out135); + _154_recursiveGen = _out133; + _155___v187 = _out134; + _156_recIdents = _out135; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _154_recursiveGen, _153_format); + RAST._IExpr _out136; + DCOMP._IOwnership _out137; + (this).FromOwned(r, expectedOwnership, out _out136, out _out137); + r = _out136; + resultingOwnership = _out137; + readIdents = _156_recIdents; return ; } goto after_match0; @@ -5812,26 +6169,26 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv if (_source0.is_UnOp) { DAST._IUnaryOp unOp1 = _source0.dtor_unOp; if (unOp1.is_BitwiseNot) { - DAST._IExpression _156_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _157_format = _source0.dtor_format1; + DAST._IExpression _157_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _158_format = _source0.dtor_format1; { - RAST._IExpr _158_recursiveGen; - DCOMP._IOwnership _159___v182; - Dafny.ISet> _160_recIdents; - RAST._IExpr _out135; - DCOMP._IOwnership _out136; - Dafny.ISet> _out137; - (this).GenExpr(_156_e, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out135, out _out136, out _out137); - _158_recursiveGen = _out135; - _159___v182 = _out136; - _160_recIdents = _out137; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("~"), _158_recursiveGen, _157_format); + RAST._IExpr _159_recursiveGen; + DCOMP._IOwnership _160___v188; + Dafny.ISet> _161_recIdents; RAST._IExpr _out138; DCOMP._IOwnership _out139; - (this).FromOwned(r, expectedOwnership, out _out138, out _out139); - r = _out138; - resultingOwnership = _out139; - readIdents = _160_recIdents; + Dafny.ISet> _out140; + (this).GenExpr(_157_e, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out138, out _out139, out _out140); + _159_recursiveGen = _out138; + _160___v188 = _out139; + _161_recIdents = _out140; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("~"), _159_recursiveGen, _158_format); + RAST._IExpr _out141; + DCOMP._IOwnership _out142; + (this).FromOwned(r, expectedOwnership, out _out141, out _out142); + r = _out141; + resultingOwnership = _out142; + readIdents = _161_recIdents; return ; } goto after_match0; @@ -5842,26 +6199,26 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv if (_source0.is_UnOp) { DAST._IUnaryOp unOp2 = _source0.dtor_unOp; if (unOp2.is_Cardinality) { - DAST._IExpression _161_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _162_format = _source0.dtor_format1; + DAST._IExpression _162_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _163_format = _source0.dtor_format1; { - RAST._IExpr _163_recursiveGen; - DCOMP._IOwnership _164_recOwned; - Dafny.ISet> _165_recIdents; - RAST._IExpr _out140; - DCOMP._IOwnership _out141; - Dafny.ISet> _out142; - (this).GenExpr(_161_e, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out140, out _out141, out _out142); - _163_recursiveGen = _out140; - _164_recOwned = _out141; - _165_recIdents = _out142; - r = ((_163_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _164_recursiveGen; + DCOMP._IOwnership _165_recOwned; + Dafny.ISet> _166_recIdents; RAST._IExpr _out143; DCOMP._IOwnership _out144; - (this).FromOwned(r, expectedOwnership, out _out143, out _out144); - r = _out143; - resultingOwnership = _out144; - readIdents = _165_recIdents; + Dafny.ISet> _out145; + (this).GenExpr(_162_e, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out143, out _out144, out _out145); + _164_recursiveGen = _out143; + _165_recOwned = _out144; + _166_recIdents = _out145; + r = ((_164_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out146; + DCOMP._IOwnership _out147; + (this).FromOwned(r, expectedOwnership, out _out146, out _out147); + r = _out146; + resultingOwnership = _out147; + readIdents = _166_recIdents; return ; } goto after_match0; @@ -5870,64 +6227,64 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_BinOp) { - RAST._IExpr _out145; - DCOMP._IOwnership _out146; - Dafny.ISet> _out147; - (this).GenExprBinary(e, selfIdent, env, expectedOwnership, out _out145, out _out146, out _out147); - r = _out145; - resultingOwnership = _out146; - readIdents = _out147; + RAST._IExpr _out148; + DCOMP._IOwnership _out149; + Dafny.ISet> _out150; + (this).GenExprBinary(e, selfIdent, env, expectedOwnership, out _out148, out _out149, out _out150); + r = _out148; + resultingOwnership = _out149; + readIdents = _out150; goto after_match0; } } { if (_source0.is_ArrayLen) { - DAST._IExpression _166_expr = _source0.dtor_expr; - DAST._IType _167_exprType = _source0.dtor_exprType; - BigInteger _168_dim = _source0.dtor_dim; - bool _169_native = _source0.dtor_native; + DAST._IExpression _167_expr = _source0.dtor_expr; + DAST._IType _168_exprType = _source0.dtor_exprType; + BigInteger _169_dim = _source0.dtor_dim; + bool _170_native = _source0.dtor_native; { - RAST._IExpr _170_recursiveGen; - DCOMP._IOwnership _171___v187; - Dafny.ISet> _172_recIdents; - RAST._IExpr _out148; - DCOMP._IOwnership _out149; - Dafny.ISet> _out150; - (this).GenExpr(_166_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out148, out _out149, out _out150); - _170_recursiveGen = _out148; - _171___v187 = _out149; - _172_recIdents = _out150; - RAST._IType _173_arrayType; - RAST._IType _out151; - _out151 = (this).GenType(_167_exprType, DCOMP.GenTypeContext.@default()); - _173_arrayType = _out151; - if (!((_173_arrayType).IsObjectOrPointer())) { - Dafny.ISequence _174_msg; - _174_msg = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array length of something not an array but "), (_173_arrayType)._ToString(DCOMP.__default.IND)); - (this).error = Std.Wrappers.Option>.create_Some(_174_msg); - r = RAST.Expr.create_RawExpr(_174_msg); + RAST._IExpr _171_recursiveGen; + DCOMP._IOwnership _172___v193; + Dafny.ISet> _173_recIdents; + RAST._IExpr _out151; + DCOMP._IOwnership _out152; + Dafny.ISet> _out153; + (this).GenExpr(_167_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out151, out _out152, out _out153); + _171_recursiveGen = _out151; + _172___v193 = _out152; + _173_recIdents = _out153; + RAST._IType _174_arrayType; + RAST._IType _out154; + _out154 = (this).GenType(_168_exprType, DCOMP.GenTypeContext.@default()); + _174_arrayType = _out154; + if (!((_174_arrayType).IsObjectOrPointer())) { + Dafny.ISequence _175_msg; + _175_msg = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array length of something not an array but "), (_174_arrayType)._ToString(DCOMP.__default.IND)); + (this).error = Std.Wrappers.Option>.create_Some(_175_msg); + r = RAST.Expr.create_RawExpr(_175_msg); } else { - RAST._IType _175_underlying; - _175_underlying = (_173_arrayType).ObjectOrPointerUnderlying(); - if (((_168_dim).Sign == 0) && ((_175_underlying).is_Array)) { - r = ((((this).read__macro).Apply1(_170_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply(Dafny.Sequence.FromElements()); + RAST._IType _176_underlying; + _176_underlying = (_174_arrayType).ObjectOrPointerUnderlying(); + if (((_169_dim).Sign == 0) && ((_176_underlying).is_Array)) { + r = ((((this).read__macro).Apply1(_171_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply(Dafny.Sequence.FromElements()); } else { - if ((_168_dim).Sign == 0) { - r = (((((this).read__macro).Apply1(_170_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("data"))).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply(Dafny.Sequence.FromElements()); + if ((_169_dim).Sign == 0) { + r = (((((this).read__macro).Apply1(_171_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("data"))).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply(Dafny.Sequence.FromElements()); } else { - r = ((((this).read__macro).Apply1(_170_recursiveGen)).Sel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("length"), Std.Strings.__default.OfNat(_168_dim)), Dafny.Sequence.UnicodeFromString("_usize")))).Apply(Dafny.Sequence.FromElements()); + r = ((((this).read__macro).Apply1(_171_recursiveGen)).Sel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("length"), Std.Strings.__default.OfNat(_169_dim)), Dafny.Sequence.UnicodeFromString("_usize")))).Apply(Dafny.Sequence.FromElements()); } } - if (!(_169_native)) { - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).Apply1(r); + if (!(_170_native)) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(r); } } - RAST._IExpr _out152; - DCOMP._IOwnership _out153; - (this).FromOwned(r, expectedOwnership, out _out152, out _out153); - r = _out152; - resultingOwnership = _out153; - readIdents = _172_recIdents; + RAST._IExpr _out155; + DCOMP._IOwnership _out156; + (this).FromOwned(r, expectedOwnership, out _out155, out _out156); + r = _out155; + resultingOwnership = _out156; + readIdents = _173_recIdents; return ; } goto after_match0; @@ -5935,25 +6292,25 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_MapKeys) { - DAST._IExpression _176_expr = _source0.dtor_expr; + DAST._IExpression _177_expr = _source0.dtor_expr; { - RAST._IExpr _177_recursiveGen; - DCOMP._IOwnership _178___v188; - Dafny.ISet> _179_recIdents; - RAST._IExpr _out154; - DCOMP._IOwnership _out155; - Dafny.ISet> _out156; - (this).GenExpr(_176_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out154, out _out155, out _out156); - _177_recursiveGen = _out154; - _178___v188 = _out155; - _179_recIdents = _out156; - readIdents = _179_recIdents; - r = ((_177_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _178_recursiveGen; + DCOMP._IOwnership _179___v194; + Dafny.ISet> _180_recIdents; RAST._IExpr _out157; DCOMP._IOwnership _out158; - (this).FromOwned(r, expectedOwnership, out _out157, out _out158); - r = _out157; - resultingOwnership = _out158; + Dafny.ISet> _out159; + (this).GenExpr(_177_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out157, out _out158, out _out159); + _178_recursiveGen = _out157; + _179___v194 = _out158; + _180_recIdents = _out159; + readIdents = _180_recIdents; + r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out160; + DCOMP._IOwnership _out161; + (this).FromOwned(r, expectedOwnership, out _out160, out _out161); + r = _out160; + resultingOwnership = _out161; return ; } goto after_match0; @@ -5961,175 +6318,230 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_MapValues) { - DAST._IExpression _180_expr = _source0.dtor_expr; + DAST._IExpression _181_expr = _source0.dtor_expr; { - RAST._IExpr _181_recursiveGen; - DCOMP._IOwnership _182___v189; - Dafny.ISet> _183_recIdents; - RAST._IExpr _out159; - DCOMP._IOwnership _out160; - Dafny.ISet> _out161; - (this).GenExpr(_180_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out159, out _out160, out _out161); - _181_recursiveGen = _out159; - _182___v189 = _out160; - _183_recIdents = _out161; - readIdents = _183_recIdents; - r = ((_181_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _182_recursiveGen; + DCOMP._IOwnership _183___v195; + Dafny.ISet> _184_recIdents; RAST._IExpr _out162; DCOMP._IOwnership _out163; - (this).FromOwned(r, expectedOwnership, out _out162, out _out163); - r = _out162; - resultingOwnership = _out163; + Dafny.ISet> _out164; + (this).GenExpr(_181_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); + _182_recursiveGen = _out162; + _183___v195 = _out163; + _184_recIdents = _out164; + readIdents = _184_recIdents; + r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out165; + DCOMP._IOwnership _out166; + (this).FromOwned(r, expectedOwnership, out _out165, out _out166); + r = _out165; + resultingOwnership = _out166; return ; } goto after_match0; } } { - if (_source0.is_SelectFn) { - DAST._IExpression _184_on = _source0.dtor_expr; - Dafny.ISequence _185_field = _source0.dtor_field; - bool _186_isDatatype = _source0.dtor_onDatatype; - bool _187_isStatic = _source0.dtor_isStatic; - BigInteger _188_arity = _source0.dtor_arity; + if (_source0.is_MapItems) { + DAST._IExpression _185_expr = _source0.dtor_expr; { - RAST._IExpr _189_onExpr; - DCOMP._IOwnership _190_onOwned; - Dafny.ISet> _191_recIdents; - RAST._IExpr _out164; - DCOMP._IOwnership _out165; - Dafny.ISet> _out166; - (this).GenExpr(_184_on, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out164, out _out165, out _out166); - _189_onExpr = _out164; - _190_onOwned = _out165; - _191_recIdents = _out166; - Dafny.ISequence _192_s = Dafny.Sequence.Empty; - Dafny.ISequence _193_onString; - _193_onString = (_189_onExpr)._ToString(DCOMP.__default.IND); - if (_187_isStatic) { - _192_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_193_onString, Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeName(_185_field)); - } else { - _192_s = Dafny.Sequence.UnicodeFromString("{\n"); - _192_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_192_s, Dafny.Sequence.UnicodeFromString("let callTarget = (")), _193_onString), ((object.Equals(_190_onOwned, DCOMP.Ownership.create_OwnershipOwned())) ? (Dafny.Sequence.UnicodeFromString(")")) : (Dafny.Sequence.UnicodeFromString(").clone()")))), Dafny.Sequence.UnicodeFromString(";\n")); - Dafny.ISequence _194_args; - _194_args = Dafny.Sequence.UnicodeFromString(""); - BigInteger _195_i; - _195_i = BigInteger.Zero; - while ((_195_i) < (_188_arity)) { - if ((_195_i).Sign == 1) { - _194_args = Dafny.Sequence.Concat(_194_args, Dafny.Sequence.UnicodeFromString(", ")); - } - _194_args = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_194_args, Dafny.Sequence.UnicodeFromString("arg")), Std.Strings.__default.OfNat(_195_i)); - _195_i = (_195_i) + (BigInteger.One); - } - _192_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_192_s, Dafny.Sequence.UnicodeFromString("move |")), _194_args), Dafny.Sequence.UnicodeFromString("| {\n")); - _192_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_192_s, Dafny.Sequence.UnicodeFromString("callTarget.")), DCOMP.__default.escapeName(_185_field)), Dafny.Sequence.UnicodeFromString("(")), _194_args), Dafny.Sequence.UnicodeFromString(")\n")); - _192_s = Dafny.Sequence.Concat(_192_s, Dafny.Sequence.UnicodeFromString("}\n")); - _192_s = Dafny.Sequence.Concat(_192_s, Dafny.Sequence.UnicodeFromString("}")); - } - Dafny.ISequence _196_typeShape; - _196_typeShape = Dafny.Sequence.UnicodeFromString("dyn ::std::ops::Fn("); - BigInteger _197_i; - _197_i = BigInteger.Zero; - while ((_197_i) < (_188_arity)) { - if ((_197_i).Sign == 1) { - _196_typeShape = Dafny.Sequence.Concat(_196_typeShape, Dafny.Sequence.UnicodeFromString(", ")); - } - _196_typeShape = Dafny.Sequence.Concat(_196_typeShape, Dafny.Sequence.UnicodeFromString("&_")); - _197_i = (_197_i) + (BigInteger.One); - } - _196_typeShape = Dafny.Sequence.Concat(_196_typeShape, Dafny.Sequence.UnicodeFromString(") -> _")); - _192_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::rc::Rc::new("), _192_s), Dafny.Sequence.UnicodeFromString(") as ::std::rc::Rc<")), _196_typeShape), Dafny.Sequence.UnicodeFromString(">")); - r = RAST.Expr.create_RawExpr(_192_s); + RAST._IExpr _186_recursiveGen; + DCOMP._IOwnership _187___v196; + Dafny.ISet> _188_recIdents; RAST._IExpr _out167; DCOMP._IOwnership _out168; - (this).FromOwned(r, expectedOwnership, out _out167, out _out168); - r = _out167; - resultingOwnership = _out168; - readIdents = _191_recIdents; + Dafny.ISet> _out169; + (this).GenExpr(_185_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); + _186_recursiveGen = _out167; + _187___v196 = _out168; + _188_recIdents = _out169; + readIdents = _188_recIdents; + r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out170; + DCOMP._IOwnership _out171; + (this).FromOwned(r, expectedOwnership, out _out170, out _out171); + r = _out170; + resultingOwnership = _out171; return ; } goto after_match0; } } { - if (_source0.is_Select) { - DAST._IExpression expr0 = _source0.dtor_expr; - if (expr0.is_Companion) { - Dafny.ISequence> _198_c = expr0.dtor_Companion_a0; - Dafny.ISequence _199_typeArgs = expr0.dtor_typeArgs; - Dafny.ISequence _200_field = _source0.dtor_field; - bool _201_isConstant = _source0.dtor_isConstant; - bool _202_isDatatype = _source0.dtor_onDatatype; - DAST._IType _203_fieldType = _source0.dtor_fieldType; - { - RAST._IExpr _204_onExpr; - DCOMP._IOwnership _205_onOwned; - Dafny.ISet> _206_recIdents; - RAST._IExpr _out169; - DCOMP._IOwnership _out170; - Dafny.ISet> _out171; - (this).GenExpr(DAST.Expression.create_Companion(_198_c, _199_typeArgs), selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out169, out _out170, out _out171); - _204_onExpr = _out169; - _205_onOwned = _out170; - _206_recIdents = _out171; - r = ((_204_onExpr).MSel(DCOMP.__default.escapeName(_200_field))).Apply(Dafny.Sequence.FromElements()); - RAST._IExpr _out172; - DCOMP._IOwnership _out173; - (this).FromOwned(r, expectedOwnership, out _out172, out _out173); - r = _out172; - resultingOwnership = _out173; - readIdents = _206_recIdents; - return ; + if (_source0.is_SelectFn) { + DAST._IExpression _189_on = _source0.dtor_expr; + Dafny.ISequence _190_field = _source0.dtor_field; + bool _191_isDatatype = _source0.dtor_onDatatype; + bool _192_isStatic = _source0.dtor_isStatic; + bool _193_isConstant = _source0.dtor_isConstant; + Dafny.ISequence _194_arguments = _source0.dtor_arguments; + { + RAST._IExpr _195_onExpr; + DCOMP._IOwnership _196_onOwned; + Dafny.ISet> _197_recIdents; + RAST._IExpr _out172; + DCOMP._IOwnership _out173; + Dafny.ISet> _out174; + (this).GenExpr(_189_on, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out172, out _out173, out _out174); + _195_onExpr = _out172; + _196_onOwned = _out173; + _197_recIdents = _out174; + Dafny.ISequence _198_s = Dafny.Sequence.Empty; + Dafny.ISequence _199_onString; + _199_onString = (_195_onExpr)._ToString(DCOMP.__default.IND); + if (_192_isStatic) { + DCOMP._IEnvironment _200_lEnv; + _200_lEnv = env; + Dafny.ISequence<_System._ITuple2, RAST._IType>> _201_args; + _201_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(); + _198_s = Dafny.Sequence.UnicodeFromString("|"); + BigInteger _hi7 = new BigInteger((_194_arguments).Count); + for (BigInteger _202_i = BigInteger.Zero; _202_i < _hi7; _202_i++) { + if ((_202_i).Sign == 1) { + _198_s = Dafny.Sequence.Concat(_198_s, Dafny.Sequence.UnicodeFromString(", ")); + } + RAST._IType _203_ty; + RAST._IType _out175; + _out175 = (this).GenType((_194_arguments).Select(_202_i), DCOMP.GenTypeContext.@default()); + _203_ty = _out175; + RAST._IType _204_bTy; + _204_bTy = RAST.Type.create_Borrowed(_203_ty); + Dafny.ISequence _205_name; + _205_name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("x"), Std.Strings.__default.OfInt(_202_i)); + _200_lEnv = (_200_lEnv).AddAssigned(_205_name, _204_bTy); + _201_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.Concat(_201_args, Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(_System.Tuple2, RAST._IType>.create(_205_name, _203_ty))); + _198_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_198_s, _205_name), Dafny.Sequence.UnicodeFromString(": ")), (_204_bTy)._ToString(DCOMP.__default.IND)); + } + _198_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_198_s, Dafny.Sequence.UnicodeFromString("| ")), _199_onString), Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeVar(_190_field)), ((_193_isConstant) ? (Dafny.Sequence.UnicodeFromString("()")) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString("(")); + BigInteger _hi8 = new BigInteger((_201_args).Count); + for (BigInteger _206_i = BigInteger.Zero; _206_i < _hi8; _206_i++) { + if ((_206_i).Sign == 1) { + _198_s = Dafny.Sequence.Concat(_198_s, Dafny.Sequence.UnicodeFromString(", ")); + } + _System._ITuple2, RAST._IType> _let_tmp_rhs1 = (_201_args).Select(_206_i); + Dafny.ISequence _207_name = _let_tmp_rhs1.dtor__0; + RAST._IType _208_ty = _let_tmp_rhs1.dtor__1; + RAST._IExpr _209_rIdent; + DCOMP._IOwnership _210___v197; + Dafny.ISet> _211___v198; + RAST._IExpr _out176; + DCOMP._IOwnership _out177; + Dafny.ISet> _out178; + (this).GenIdent(_207_name, selfIdent, _200_lEnv, (((_208_ty).CanReadWithoutClone()) ? (DCOMP.Ownership.create_OwnershipOwned()) : (DCOMP.Ownership.create_OwnershipBorrowed())), out _out176, out _out177, out _out178); + _209_rIdent = _out176; + _210___v197 = _out177; + _211___v198 = _out178; + _198_s = Dafny.Sequence.Concat(_198_s, (_209_rIdent)._ToString(DCOMP.__default.IND)); + } + _198_s = Dafny.Sequence.Concat(_198_s, Dafny.Sequence.UnicodeFromString(")")); + } else { + _198_s = Dafny.Sequence.UnicodeFromString("{\n"); + _198_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_198_s, Dafny.Sequence.UnicodeFromString("let callTarget = (")), _199_onString), ((object.Equals(_196_onOwned, DCOMP.Ownership.create_OwnershipOwned())) ? (Dafny.Sequence.UnicodeFromString(")")) : (Dafny.Sequence.UnicodeFromString(").clone()")))), Dafny.Sequence.UnicodeFromString(";\n")); + Dafny.ISequence _212_args; + _212_args = Dafny.Sequence.UnicodeFromString(""); + BigInteger _213_i; + _213_i = BigInteger.Zero; + while ((_213_i) < (new BigInteger((_194_arguments).Count))) { + if ((_213_i).Sign == 1) { + _212_args = Dafny.Sequence.Concat(_212_args, Dafny.Sequence.UnicodeFromString(", ")); + } + _212_args = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_212_args, Dafny.Sequence.UnicodeFromString("arg")), Std.Strings.__default.OfNat(_213_i)); + _213_i = (_213_i) + (BigInteger.One); + } + _198_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_198_s, Dafny.Sequence.UnicodeFromString("move |")), _212_args), Dafny.Sequence.UnicodeFromString("| {\n")); + _198_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_198_s, Dafny.Sequence.UnicodeFromString("callTarget.")), DCOMP.__default.escapeVar(_190_field)), ((_193_isConstant) ? (Dafny.Sequence.UnicodeFromString("()")) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString("(")), _212_args), Dafny.Sequence.UnicodeFromString(")\n")); + _198_s = Dafny.Sequence.Concat(_198_s, Dafny.Sequence.UnicodeFromString("}\n")); + _198_s = Dafny.Sequence.Concat(_198_s, Dafny.Sequence.UnicodeFromString("}")); } - goto after_match0; + Dafny.ISequence _214_typeShape; + _214_typeShape = Dafny.Sequence.UnicodeFromString("dyn ::std::ops::Fn("); + BigInteger _215_i; + _215_i = BigInteger.Zero; + while ((_215_i) < (new BigInteger((_194_arguments).Count))) { + if ((_215_i).Sign == 1) { + _214_typeShape = Dafny.Sequence.Concat(_214_typeShape, Dafny.Sequence.UnicodeFromString(", ")); + } + _214_typeShape = Dafny.Sequence.Concat(_214_typeShape, Dafny.Sequence.UnicodeFromString("&_")); + _215_i = (_215_i) + (BigInteger.One); + } + _214_typeShape = Dafny.Sequence.Concat(_214_typeShape, Dafny.Sequence.UnicodeFromString(") -> _")); + _198_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::rc::Rc::new("), _198_s), Dafny.Sequence.UnicodeFromString(") as ::std::rc::Rc<")), _214_typeShape), Dafny.Sequence.UnicodeFromString(">")); + r = RAST.Expr.create_RawExpr(_198_s); + RAST._IExpr _out179; + DCOMP._IOwnership _out180; + (this).FromOwned(r, expectedOwnership, out _out179, out _out180); + r = _out179; + resultingOwnership = _out180; + readIdents = _197_recIdents; + return ; } + goto after_match0; } } { if (_source0.is_Select) { - DAST._IExpression _207_on = _source0.dtor_expr; - Dafny.ISequence _208_field = _source0.dtor_field; - bool _209_isConstant = _source0.dtor_isConstant; - bool _210_isDatatype = _source0.dtor_onDatatype; - DAST._IType _211_fieldType = _source0.dtor_fieldType; + DAST._IExpression _216_on = _source0.dtor_expr; + Dafny.ISequence _217_field = _source0.dtor_field; + bool _218_isConstant = _source0.dtor_isConstant; + bool _219_isDatatype = _source0.dtor_onDatatype; + DAST._IType _220_fieldType = _source0.dtor_fieldType; { - if (_210_isDatatype) { - RAST._IExpr _212_onExpr; - DCOMP._IOwnership _213_onOwned; - Dafny.ISet> _214_recIdents; - RAST._IExpr _out174; - DCOMP._IOwnership _out175; - Dafny.ISet> _out176; - (this).GenExpr(_207_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out174, out _out175, out _out176); - _212_onExpr = _out174; - _213_onOwned = _out175; - _214_recIdents = _out176; - r = ((_212_onExpr).Sel(DCOMP.__default.escapeName(_208_field))).Apply(Dafny.Sequence.FromElements()); - RAST._IType _215_typ; - RAST._IType _out177; - _out177 = (this).GenType(_211_fieldType, DCOMP.GenTypeContext.@default()); - _215_typ = _out177; - RAST._IExpr _out178; - DCOMP._IOwnership _out179; - (this).FromOwnership(r, DCOMP.Ownership.create_OwnershipBorrowed(), expectedOwnership, out _out178, out _out179); - r = _out178; - resultingOwnership = _out179; - readIdents = _214_recIdents; + if (((_216_on).is_Companion) || ((_216_on).is_ExternCompanion)) { + RAST._IExpr _221_onExpr; + DCOMP._IOwnership _222_onOwned; + Dafny.ISet> _223_recIdents; + RAST._IExpr _out181; + DCOMP._IOwnership _out182; + Dafny.ISet> _out183; + (this).GenExpr(_216_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out181, out _out182, out _out183); + _221_onExpr = _out181; + _222_onOwned = _out182; + _223_recIdents = _out183; + r = ((_221_onExpr).FSel(DCOMP.__default.escapeVar(_217_field))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out184; + DCOMP._IOwnership _out185; + (this).FromOwned(r, expectedOwnership, out _out184, out _out185); + r = _out184; + resultingOwnership = _out185; + readIdents = _223_recIdents; + return ; + } else if (_219_isDatatype) { + RAST._IExpr _224_onExpr; + DCOMP._IOwnership _225_onOwned; + Dafny.ISet> _226_recIdents; + RAST._IExpr _out186; + DCOMP._IOwnership _out187; + Dafny.ISet> _out188; + (this).GenExpr(_216_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out186, out _out187, out _out188); + _224_onExpr = _out186; + _225_onOwned = _out187; + _226_recIdents = _out188; + r = ((_224_onExpr).Sel(DCOMP.__default.escapeVar(_217_field))).Apply(Dafny.Sequence.FromElements()); + RAST._IType _227_typ; + RAST._IType _out189; + _out189 = (this).GenType(_220_fieldType, DCOMP.GenTypeContext.@default()); + _227_typ = _out189; + RAST._IExpr _out190; + DCOMP._IOwnership _out191; + (this).FromOwnership(r, DCOMP.Ownership.create_OwnershipBorrowed(), expectedOwnership, out _out190, out _out191); + r = _out190; + resultingOwnership = _out191; + readIdents = _226_recIdents; } else { - RAST._IExpr _216_onExpr; - DCOMP._IOwnership _217_onOwned; - Dafny.ISet> _218_recIdents; - RAST._IExpr _out180; - DCOMP._IOwnership _out181; - Dafny.ISet> _out182; - (this).GenExpr(_207_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out180, out _out181, out _out182); - _216_onExpr = _out180; - _217_onOwned = _out181; - _218_recIdents = _out182; - r = _216_onExpr; - if (!object.Equals(_216_onExpr, RAST.__default.self)) { - RAST._IExpr _source2 = _216_onExpr; + RAST._IExpr _228_onExpr; + DCOMP._IOwnership _229_onOwned; + Dafny.ISet> _230_recIdents; + RAST._IExpr _out192; + DCOMP._IOwnership _out193; + Dafny.ISet> _out194; + (this).GenExpr(_216_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out192, out _out193, out _out194); + _228_onExpr = _out192; + _229_onOwned = _out193; + _230_recIdents = _out194; + r = _228_onExpr; + if (!object.Equals(_228_onExpr, RAST.__default.self)) { + RAST._IExpr _source2 = _228_onExpr; { if (_source2.is_UnaryOp) { Dafny.ISequence op10 = _source2.dtor_op1; @@ -6151,19 +6563,23 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv if (((this).ObjectType).is_RcMut) { r = (r).Clone(); } - r = ((this).read__macro).Apply1(r); + if (((this).ObjectType).is_RawPointers) { + r = ((this).read__macro).Apply1(r); + } else { + r = ((this).modify__macro).Apply1(r); + } } - r = (r).Sel(DCOMP.__default.escapeName(_208_field)); - if (_209_isConstant) { + r = (r).Sel(DCOMP.__default.escapeVar(_217_field)); + if (_218_isConstant) { r = (r).Apply(Dafny.Sequence.FromElements()); } r = (r).Clone(); - RAST._IExpr _out183; - DCOMP._IOwnership _out184; - (this).FromOwned(r, expectedOwnership, out _out183, out _out184); - r = _out183; - resultingOwnership = _out184; - readIdents = _218_recIdents; + RAST._IExpr _out195; + DCOMP._IOwnership _out196; + (this).FromOwned(r, expectedOwnership, out _out195, out _out196); + r = _out195; + resultingOwnership = _out196; + readIdents = _230_recIdents; } return ; } @@ -6172,70 +6588,70 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_Index) { - DAST._IExpression _219_on = _source0.dtor_expr; - DAST._ICollKind _220_collKind = _source0.dtor_collKind; - Dafny.ISequence _221_indices = _source0.dtor_indices; + DAST._IExpression _231_on = _source0.dtor_expr; + DAST._ICollKind _232_collKind = _source0.dtor_collKind; + Dafny.ISequence _233_indices = _source0.dtor_indices; { - RAST._IExpr _222_onExpr; - DCOMP._IOwnership _223_onOwned; - Dafny.ISet> _224_recIdents; - RAST._IExpr _out185; - DCOMP._IOwnership _out186; - Dafny.ISet> _out187; - (this).GenExpr(_219_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out185, out _out186, out _out187); - _222_onExpr = _out185; - _223_onOwned = _out186; - _224_recIdents = _out187; - readIdents = _224_recIdents; - r = _222_onExpr; - bool _225_hadArray; - _225_hadArray = false; - if (object.Equals(_220_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _234_onExpr; + DCOMP._IOwnership _235_onOwned; + Dafny.ISet> _236_recIdents; + RAST._IExpr _out197; + DCOMP._IOwnership _out198; + Dafny.ISet> _out199; + (this).GenExpr(_231_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out197, out _out198, out _out199); + _234_onExpr = _out197; + _235_onOwned = _out198; + _236_recIdents = _out199; + readIdents = _236_recIdents; + r = _234_onExpr; + bool _237_hadArray; + _237_hadArray = false; + if (object.Equals(_232_collKind, DAST.CollKind.create_Array())) { r = ((this).read__macro).Apply1(r); - _225_hadArray = true; - if ((new BigInteger((_221_indices).Count)) > (BigInteger.One)) { + _237_hadArray = true; + if ((new BigInteger((_233_indices).Count)) > (BigInteger.One)) { r = (r).Sel(Dafny.Sequence.UnicodeFromString("data")); } } - BigInteger _hi7 = new BigInteger((_221_indices).Count); - for (BigInteger _226_i = BigInteger.Zero; _226_i < _hi7; _226_i++) { - if (object.Equals(_220_collKind, DAST.CollKind.create_Array())) { - RAST._IExpr _227_idx; - DCOMP._IOwnership _228_idxOwned; - Dafny.ISet> _229_recIdentsIdx; - RAST._IExpr _out188; - DCOMP._IOwnership _out189; - Dafny.ISet> _out190; - (this).GenExpr((_221_indices).Select(_226_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out188, out _out189, out _out190); - _227_idx = _out188; - _228_idxOwned = _out189; - _229_recIdentsIdx = _out190; - _227_idx = RAST.__default.IntoUsize(_227_idx); - r = RAST.Expr.create_SelectIndex(r, _227_idx); - readIdents = Dafny.Set>.Union(readIdents, _229_recIdentsIdx); + BigInteger _hi9 = new BigInteger((_233_indices).Count); + for (BigInteger _238_i = BigInteger.Zero; _238_i < _hi9; _238_i++) { + if (object.Equals(_232_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _239_idx; + DCOMP._IOwnership _240_idxOwned; + Dafny.ISet> _241_recIdentsIdx; + RAST._IExpr _out200; + DCOMP._IOwnership _out201; + Dafny.ISet> _out202; + (this).GenExpr((_233_indices).Select(_238_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out200, out _out201, out _out202); + _239_idx = _out200; + _240_idxOwned = _out201; + _241_recIdentsIdx = _out202; + _239_idx = RAST.__default.IntoUsize(_239_idx); + r = RAST.Expr.create_SelectIndex(r, _239_idx); + readIdents = Dafny.Set>.Union(readIdents, _241_recIdentsIdx); } else { - RAST._IExpr _230_idx; - DCOMP._IOwnership _231_idxOwned; - Dafny.ISet> _232_recIdentsIdx; - RAST._IExpr _out191; - DCOMP._IOwnership _out192; - Dafny.ISet> _out193; - (this).GenExpr((_221_indices).Select(_226_i), selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out191, out _out192, out _out193); - _230_idx = _out191; - _231_idxOwned = _out192; - _232_recIdentsIdx = _out193; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_230_idx); - readIdents = Dafny.Set>.Union(readIdents, _232_recIdentsIdx); + RAST._IExpr _242_idx; + DCOMP._IOwnership _243_idxOwned; + Dafny.ISet> _244_recIdentsIdx; + RAST._IExpr _out203; + DCOMP._IOwnership _out204; + Dafny.ISet> _out205; + (this).GenExpr((_233_indices).Select(_238_i), selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out203, out _out204, out _out205); + _242_idx = _out203; + _243_idxOwned = _out204; + _244_recIdentsIdx = _out205; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_242_idx); + readIdents = Dafny.Set>.Union(readIdents, _244_recIdentsIdx); } } - if (_225_hadArray) { + if (_237_hadArray) { r = (r).Clone(); } - RAST._IExpr _out194; - DCOMP._IOwnership _out195; - (this).FromOwned(r, expectedOwnership, out _out194, out _out195); - r = _out194; - resultingOwnership = _out195; + RAST._IExpr _out206; + DCOMP._IOwnership _out207; + (this).FromOwned(r, expectedOwnership, out _out206, out _out207); + r = _out206; + resultingOwnership = _out207; return ; } goto after_match0; @@ -6243,53 +6659,63 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_IndexRange) { - DAST._IExpression _233_on = _source0.dtor_expr; - bool _234_isArray = _source0.dtor_isArray; - Std.Wrappers._IOption _235_low = _source0.dtor_low; - Std.Wrappers._IOption _236_high = _source0.dtor_high; + DAST._IExpression _245_on = _source0.dtor_expr; + bool _246_isArray = _source0.dtor_isArray; + Std.Wrappers._IOption _247_low = _source0.dtor_low; + Std.Wrappers._IOption _248_high = _source0.dtor_high; { - RAST._IExpr _237_onExpr; - DCOMP._IOwnership _238_onOwned; - Dafny.ISet> _239_recIdents; - RAST._IExpr _out196; - DCOMP._IOwnership _out197; - Dafny.ISet> _out198; - (this).GenExpr(_233_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out196, out _out197, out _out198); - _237_onExpr = _out196; - _238_onOwned = _out197; - _239_recIdents = _out198; - readIdents = _239_recIdents; - Dafny.ISequence _240_methodName; - if ((_235_low).is_Some) { - if ((_236_high).is_Some) { - _240_methodName = Dafny.Sequence.UnicodeFromString("slice"); + DCOMP._IOwnership _249_onExpectedOwnership; + if (_246_isArray) { + if (((this).ObjectType).is_RawPointers) { + _249_onExpectedOwnership = DCOMP.Ownership.create_OwnershipOwned(); } else { - _240_methodName = Dafny.Sequence.UnicodeFromString("drop"); + _249_onExpectedOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); } - } else if ((_236_high).is_Some) { - _240_methodName = Dafny.Sequence.UnicodeFromString("take"); } else { - _240_methodName = Dafny.Sequence.UnicodeFromString(""); + _249_onExpectedOwnership = DCOMP.Ownership.create_OwnershipAutoBorrowed(); } - Dafny.ISequence _241_arguments; - _241_arguments = Dafny.Sequence.FromElements(); - Std.Wrappers._IOption _source3 = _235_low; + RAST._IExpr _250_onExpr; + DCOMP._IOwnership _251_onOwned; + Dafny.ISet> _252_recIdents; + RAST._IExpr _out208; + DCOMP._IOwnership _out209; + Dafny.ISet> _out210; + (this).GenExpr(_245_on, selfIdent, env, _249_onExpectedOwnership, out _out208, out _out209, out _out210); + _250_onExpr = _out208; + _251_onOwned = _out209; + _252_recIdents = _out210; + readIdents = _252_recIdents; + Dafny.ISequence _253_methodName; + if ((_247_low).is_Some) { + if ((_248_high).is_Some) { + _253_methodName = Dafny.Sequence.UnicodeFromString("slice"); + } else { + _253_methodName = Dafny.Sequence.UnicodeFromString("drop"); + } + } else if ((_248_high).is_Some) { + _253_methodName = Dafny.Sequence.UnicodeFromString("take"); + } else { + _253_methodName = Dafny.Sequence.UnicodeFromString(""); + } + Dafny.ISequence _254_arguments; + _254_arguments = Dafny.Sequence.FromElements(); + Std.Wrappers._IOption _source3 = _247_low; { if (_source3.is_Some) { - DAST._IExpression _242_l = _source3.dtor_value; + DAST._IExpression _255_l = _source3.dtor_value; { - RAST._IExpr _243_lExpr; - DCOMP._IOwnership _244___v192; - Dafny.ISet> _245_recIdentsL; - RAST._IExpr _out199; - DCOMP._IOwnership _out200; - Dafny.ISet> _out201; - (this).GenExpr(_242_l, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out199, out _out200, out _out201); - _243_lExpr = _out199; - _244___v192 = _out200; - _245_recIdentsL = _out201; - _241_arguments = Dafny.Sequence.Concat(_241_arguments, Dafny.Sequence.FromElements(_243_lExpr)); - readIdents = Dafny.Set>.Union(readIdents, _245_recIdentsL); + RAST._IExpr _256_lExpr; + DCOMP._IOwnership _257___v201; + Dafny.ISet> _258_recIdentsL; + RAST._IExpr _out211; + DCOMP._IOwnership _out212; + Dafny.ISet> _out213; + (this).GenExpr(_255_l, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out211, out _out212, out _out213); + _256_lExpr = _out211; + _257___v201 = _out212; + _258_recIdentsL = _out213; + _254_arguments = Dafny.Sequence.Concat(_254_arguments, Dafny.Sequence.FromElements(_256_lExpr)); + readIdents = Dafny.Set>.Union(readIdents, _258_recIdentsL); } goto after_match3; } @@ -6297,23 +6723,23 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv { } after_match3: ; - Std.Wrappers._IOption _source4 = _236_high; + Std.Wrappers._IOption _source4 = _248_high; { if (_source4.is_Some) { - DAST._IExpression _246_h = _source4.dtor_value; + DAST._IExpression _259_h = _source4.dtor_value; { - RAST._IExpr _247_hExpr; - DCOMP._IOwnership _248___v193; - Dafny.ISet> _249_recIdentsH; - RAST._IExpr _out202; - DCOMP._IOwnership _out203; - Dafny.ISet> _out204; - (this).GenExpr(_246_h, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out202, out _out203, out _out204); - _247_hExpr = _out202; - _248___v193 = _out203; - _249_recIdentsH = _out204; - _241_arguments = Dafny.Sequence.Concat(_241_arguments, Dafny.Sequence.FromElements(_247_hExpr)); - readIdents = Dafny.Set>.Union(readIdents, _249_recIdentsH); + RAST._IExpr _260_hExpr; + DCOMP._IOwnership _261___v202; + Dafny.ISet> _262_recIdentsH; + RAST._IExpr _out214; + DCOMP._IOwnership _out215; + Dafny.ISet> _out216; + (this).GenExpr(_259_h, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out214, out _out215, out _out216); + _260_hExpr = _out214; + _261___v202 = _out215; + _262_recIdentsH = _out216; + _254_arguments = Dafny.Sequence.Concat(_254_arguments, Dafny.Sequence.FromElements(_260_hExpr)); + readIdents = Dafny.Set>.Union(readIdents, _262_recIdentsH); } goto after_match4; } @@ -6321,22 +6747,30 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv { } after_match4: ; - r = _237_onExpr; - if (_234_isArray) { - if (!(_240_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - _240_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _240_methodName); + r = _250_onExpr; + if (_246_isArray) { + if (!(_253_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + _253_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _253_methodName); + } + Dafny.ISequence _263_object__suffix; + if (((this).ObjectType).is_RawPointers) { + _263_object__suffix = Dafny.Sequence.UnicodeFromString(""); + } else { + _263_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); } - r = ((RAST.__default.dafny__runtime__Sequence).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _240_methodName))).Apply(_241_arguments); + r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _253_methodName), _263_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_250_onExpr), _254_arguments)); } else { - if (!(_240_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - r = ((r).Sel(_240_methodName)).Apply(_241_arguments); + if (!(_253_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + r = ((r).Sel(_253_methodName)).Apply(_254_arguments); + } else { + r = (r).Clone(); } } - RAST._IExpr _out205; - DCOMP._IOwnership _out206; - (this).FromOwned(r, expectedOwnership, out _out205, out _out206); - r = _out205; - resultingOwnership = _out206; + RAST._IExpr _out217; + DCOMP._IOwnership _out218; + (this).FromOwned(r, expectedOwnership, out _out217, out _out218); + r = _out217; + resultingOwnership = _out218; return ; } goto after_match0; @@ -6344,28 +6778,28 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_TupleSelect) { - DAST._IExpression _250_on = _source0.dtor_expr; - BigInteger _251_idx = _source0.dtor_index; - DAST._IType _252_fieldType = _source0.dtor_fieldType; + DAST._IExpression _264_on = _source0.dtor_expr; + BigInteger _265_idx = _source0.dtor_index; + DAST._IType _266_fieldType = _source0.dtor_fieldType; { - RAST._IExpr _253_onExpr; - DCOMP._IOwnership _254_onOwnership; - Dafny.ISet> _255_recIdents; - RAST._IExpr _out207; - DCOMP._IOwnership _out208; - Dafny.ISet> _out209; - (this).GenExpr(_250_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out207, out _out208, out _out209); - _253_onExpr = _out207; - _254_onOwnership = _out208; - _255_recIdents = _out209; - Dafny.ISequence _256_selName; - _256_selName = Std.Strings.__default.OfNat(_251_idx); - DAST._IType _source5 = _252_fieldType; + RAST._IExpr _267_onExpr; + DCOMP._IOwnership _268_onOwnership; + Dafny.ISet> _269_recIdents; + RAST._IExpr _out219; + DCOMP._IOwnership _out220; + Dafny.ISet> _out221; + (this).GenExpr(_264_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out219, out _out220, out _out221); + _267_onExpr = _out219; + _268_onOwnership = _out220; + _269_recIdents = _out221; + Dafny.ISequence _270_selName; + _270_selName = Std.Strings.__default.OfNat(_265_idx); + DAST._IType _source5 = _266_fieldType; { if (_source5.is_Tuple) { - Dafny.ISequence _257_tps = _source5.dtor_Tuple_a0; - if (((_252_fieldType).is_Tuple) && ((new BigInteger((_257_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { - _256_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _256_selName); + Dafny.ISequence _271_tps = _source5.dtor_Tuple_a0; + if (((_266_fieldType).is_Tuple) && ((new BigInteger((_271_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { + _270_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _270_selName); } goto after_match5; } @@ -6373,13 +6807,13 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv { } after_match5: ; - r = ((_253_onExpr).Sel(_256_selName)).Clone(); - RAST._IExpr _out210; - DCOMP._IOwnership _out211; - (this).FromOwnership(r, DCOMP.Ownership.create_OwnershipOwned(), expectedOwnership, out _out210, out _out211); - r = _out210; - resultingOwnership = _out211; - readIdents = _255_recIdents; + r = ((_267_onExpr).Sel(_270_selName)).Clone(); + RAST._IExpr _out222; + DCOMP._IOwnership _out223; + (this).FromOwnership(r, DCOMP.Ownership.create_OwnershipOwned(), expectedOwnership, out _out222, out _out223); + r = _out222; + resultingOwnership = _out223; + readIdents = _269_recIdents; return ; } goto after_match0; @@ -6387,153 +6821,150 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_Call) { - DAST._IExpression _258_on = _source0.dtor_on; - DAST._ICallName _259_name = _source0.dtor_callName; - Dafny.ISequence _260_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _261_args = _source0.dtor_args; + DAST._IExpression _272_on = _source0.dtor_on; + DAST._ICallName _273_name = _source0.dtor_callName; + Dafny.ISequence _274_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _275_args = _source0.dtor_args; { - Dafny.ISequence _262_argExprs; - Dafny.ISet> _263_recIdents; - Dafny.ISequence _264_typeExprs; - Std.Wrappers._IOption _265_fullNameQualifier; - Dafny.ISequence _out212; - Dafny.ISet> _out213; - Dafny.ISequence _out214; - Std.Wrappers._IOption _out215; - (this).GenArgs(selfIdent, _259_name, _260_typeArgs, _261_args, env, out _out212, out _out213, out _out214, out _out215); - _262_argExprs = _out212; - _263_recIdents = _out213; - _264_typeExprs = _out214; - _265_fullNameQualifier = _out215; - readIdents = _263_recIdents; - Std.Wrappers._IOption _source6 = _265_fullNameQualifier; + Dafny.ISequence _276_argExprs; + Dafny.ISet> _277_recIdents; + Dafny.ISequence _278_typeExprs; + Std.Wrappers._IOption _279_fullNameQualifier; + Dafny.ISequence _out224; + Dafny.ISet> _out225; + Dafny.ISequence _out226; + Std.Wrappers._IOption _out227; + (this).GenArgs(selfIdent, _273_name, _274_typeArgs, _275_args, env, out _out224, out _out225, out _out226, out _out227); + _276_argExprs = _out224; + _277_recIdents = _out225; + _278_typeExprs = _out226; + _279_fullNameQualifier = _out227; + readIdents = _277_recIdents; + Std.Wrappers._IOption _source6 = _279_fullNameQualifier; { if (_source6.is_Some) { DAST._IResolvedType value0 = _source6.dtor_value; - Dafny.ISequence> _266_path = value0.dtor_path; - Dafny.ISequence _267_onTypeArgs = value0.dtor_typeArgs; - DAST._IResolvedTypeBase _268_base = value0.dtor_kind; - RAST._IExpr _269_fullPath; - RAST._IExpr _out216; - _out216 = DCOMP.COMP.GenPathExpr(_266_path); - _269_fullPath = _out216; - Dafny.ISequence _270_onTypeExprs; - Dafny.ISequence _out217; - _out217 = (this).GenTypeArgs(_267_onTypeArgs, DCOMP.GenTypeContext.@default()); - _270_onTypeExprs = _out217; - RAST._IExpr _271_onExpr = RAST.Expr.Default(); - DCOMP._IOwnership _272_recOwnership = DCOMP.Ownership.Default(); - Dafny.ISet> _273_recIdents = Dafny.Set>.Empty; - if (((_268_base).is_Trait) || ((_268_base).is_Class)) { - RAST._IExpr _out218; - DCOMP._IOwnership _out219; - Dafny.ISet> _out220; - (this).GenExpr(_258_on, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out218, out _out219, out _out220); - _271_onExpr = _out218; - _272_recOwnership = _out219; - _273_recIdents = _out220; - _271_onExpr = ((this).read__macro).Apply1(_271_onExpr); - readIdents = Dafny.Set>.Union(readIdents, _273_recIdents); + Dafny.ISequence> _280_path = value0.dtor_path; + Dafny.ISequence _281_onTypeArgs = value0.dtor_typeArgs; + DAST._IResolvedTypeBase _282_base = value0.dtor_kind; + RAST._IExpr _283_fullPath; + RAST._IExpr _out228; + _out228 = DCOMP.COMP.GenPathExpr(_280_path, true); + _283_fullPath = _out228; + Dafny.ISequence _284_onTypeExprs; + Dafny.ISequence _out229; + _out229 = (this).GenTypeArgs(_281_onTypeArgs, DCOMP.GenTypeContext.@default()); + _284_onTypeExprs = _out229; + RAST._IExpr _285_onExpr = RAST.Expr.Default(); + DCOMP._IOwnership _286_recOwnership = DCOMP.Ownership.Default(); + Dafny.ISet> _287_recIdents = Dafny.Set>.Empty; + if (((_282_base).is_Trait) || ((_282_base).is_Class)) { + RAST._IExpr _out230; + DCOMP._IOwnership _out231; + Dafny.ISet> _out232; + (this).GenExpr(_272_on, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out230, out _out231, out _out232); + _285_onExpr = _out230; + _286_recOwnership = _out231; + _287_recIdents = _out232; + if (((this).ObjectType).is_RawPointers) { + _285_onExpr = ((this).read__macro).Apply1(_285_onExpr); + } else { + _285_onExpr = ((this).modify__macro).Apply1(_285_onExpr); + } + readIdents = Dafny.Set>.Union(readIdents, _287_recIdents); } else { - RAST._IExpr _out221; - DCOMP._IOwnership _out222; - Dafny.ISet> _out223; - (this).GenExpr(_258_on, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out221, out _out222, out _out223); - _271_onExpr = _out221; - _272_recOwnership = _out222; - _273_recIdents = _out223; - readIdents = Dafny.Set>.Union(readIdents, _273_recIdents); + DCOMP._IOwnership _288_expectedOnOwnership; + if (((this).ObjectType).is_RawPointers) { + _288_expectedOnOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); + } else { + _288_expectedOnOwnership = DCOMP.Ownership.create_OwnershipBorrowedMut(); + } + RAST._IExpr _out233; + DCOMP._IOwnership _out234; + Dafny.ISet> _out235; + (this).GenExpr(_272_on, selfIdent, env, _288_expectedOnOwnership, out _out233, out _out234, out _out235); + _285_onExpr = _out233; + _286_recOwnership = _out234; + _287_recIdents = _out235; + readIdents = Dafny.Set>.Union(readIdents, _287_recIdents); } - r = ((((_269_fullPath).ApplyType(_270_onTypeExprs)).MSel(DCOMP.__default.escapeName((_259_name).dtor_name))).ApplyType(_264_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_271_onExpr), _262_argExprs)); - RAST._IExpr _out224; - DCOMP._IOwnership _out225; - (this).FromOwned(r, expectedOwnership, out _out224, out _out225); - r = _out224; - resultingOwnership = _out225; + r = ((((_283_fullPath).ApplyType(_284_onTypeExprs)).FSel(DCOMP.__default.escapeName((_273_name).dtor_name))).ApplyType(_278_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_285_onExpr), _276_argExprs)); + RAST._IExpr _out236; + DCOMP._IOwnership _out237; + (this).FromOwned(r, expectedOwnership, out _out236, out _out237); + r = _out236; + resultingOwnership = _out237; goto after_match6; } } { - RAST._IExpr _274_onExpr; - DCOMP._IOwnership _275___v199; - Dafny.ISet> _276_recIdents; - RAST._IExpr _out226; - DCOMP._IOwnership _out227; - Dafny.ISet> _out228; - (this).GenExpr(_258_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out226, out _out227, out _out228); - _274_onExpr = _out226; - _275___v199 = _out227; - _276_recIdents = _out228; - readIdents = Dafny.Set>.Union(readIdents, _276_recIdents); - Dafny.ISequence _277_renderedName; - DAST._ICallName _source7 = _259_name; - { - if (_source7.is_CallName) { - Dafny.ISequence _278_ident = _source7.dtor_name; - _277_renderedName = DCOMP.__default.escapeName(_278_ident); - goto after_match7; - } - } + RAST._IExpr _289_onExpr; + DCOMP._IOwnership _290___v208; + Dafny.ISet> _291_recIdents; + RAST._IExpr _out238; + DCOMP._IOwnership _out239; + Dafny.ISet> _out240; + (this).GenExpr(_272_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out238, out _out239, out _out240); + _289_onExpr = _out238; + _290___v208 = _out239; + _291_recIdents = _out240; + readIdents = Dafny.Set>.Union(readIdents, _291_recIdents); + Dafny.ISequence _292_renderedName; + _292_renderedName = (this).GetMethodName(_272_on, _273_name); + DAST._IExpression _source7 = _272_on; { bool disjunctiveMatch0 = false; - if (_source7.is_MapBuilderAdd) { + if (_source7.is_Companion) { disjunctiveMatch0 = true; } - if (_source7.is_SetBuilderAdd) { + if (_source7.is_ExternCompanion) { disjunctiveMatch0 = true; } if (disjunctiveMatch0) { - _277_renderedName = Dafny.Sequence.UnicodeFromString("add"); - goto after_match7; - } - } - { - _277_renderedName = Dafny.Sequence.UnicodeFromString("build"); - } - after_match7: ; - DAST._IExpression _source8 = _258_on; - { - if (_source8.is_Companion) { { - _274_onExpr = (_274_onExpr).MSel(_277_renderedName); + _289_onExpr = (_289_onExpr).FSel(_292_renderedName); } - goto after_match8; + goto after_match7; } } { { - if (!object.Equals(_274_onExpr, RAST.__default.self)) { - DAST._ICallName _source9 = _259_name; + if (!object.Equals(_289_onExpr, RAST.__default.self)) { + DAST._ICallName _source8 = _273_name; { - if (_source9.is_CallName) { - Std.Wrappers._IOption onType0 = _source9.dtor_onType; + if (_source8.is_CallName) { + Std.Wrappers._IOption onType0 = _source8.dtor_onType; if (onType0.is_Some) { - DAST._IType _279_tpe = onType0.dtor_value; - RAST._IType _280_typ; - RAST._IType _out229; - _out229 = (this).GenType(_279_tpe, DCOMP.GenTypeContext.@default()); - _280_typ = _out229; - if ((_280_typ).IsObjectOrPointer()) { - _274_onExpr = ((this).read__macro).Apply1(_274_onExpr); + DAST._IType _293_tpe = onType0.dtor_value; + RAST._IType _294_typ; + RAST._IType _out241; + _out241 = (this).GenType(_293_tpe, DCOMP.GenTypeContext.@default()); + _294_typ = _out241; + if ((_294_typ).IsObjectOrPointer()) { + if (((this).ObjectType).is_RawPointers) { + _289_onExpr = ((this).read__macro).Apply1(_289_onExpr); + } else { + _289_onExpr = ((this).modify__macro).Apply1(_289_onExpr); + } } - goto after_match9; + goto after_match8; } } } { } - after_match9: ; + after_match8: ; } - _274_onExpr = (_274_onExpr).Sel(_277_renderedName); + _289_onExpr = (_289_onExpr).Sel(_292_renderedName); } } - after_match8: ; - r = ((_274_onExpr).ApplyType(_264_typeExprs)).Apply(_262_argExprs); - RAST._IExpr _out230; - DCOMP._IOwnership _out231; - (this).FromOwned(r, expectedOwnership, out _out230, out _out231); - r = _out230; - resultingOwnership = _out231; + after_match7: ; + r = ((_289_onExpr).ApplyType(_278_typeExprs)).Apply(_276_argExprs); + RAST._IExpr _out242; + DCOMP._IOwnership _out243; + (this).FromOwned(r, expectedOwnership, out _out242, out _out243); + r = _out242; + resultingOwnership = _out243; return ; } after_match6: ; @@ -6543,90 +6974,90 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_Lambda) { - Dafny.ISequence _281_paramsDafny = _source0.dtor_params; - DAST._IType _282_retType = _source0.dtor_retType; - Dafny.ISequence _283_body = _source0.dtor_body; + Dafny.ISequence _295_paramsDafny = _source0.dtor_params; + DAST._IType _296_retType = _source0.dtor_retType; + Dafny.ISequence _297_body = _source0.dtor_body; { - Dafny.ISequence _284_params; - Dafny.ISequence _out232; - _out232 = (this).GenParams(_281_paramsDafny); - _284_params = _out232; - Dafny.ISequence> _285_paramNames; - _285_paramNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _286_paramTypesMap; - _286_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); - BigInteger _hi8 = new BigInteger((_284_params).Count); - for (BigInteger _287_i = BigInteger.Zero; _287_i < _hi8; _287_i++) { - Dafny.ISequence _288_name; - _288_name = ((_284_params).Select(_287_i)).dtor_name; - _285_paramNames = Dafny.Sequence>.Concat(_285_paramNames, Dafny.Sequence>.FromElements(_288_name)); - _286_paramTypesMap = Dafny.Map, RAST._IType>.Update(_286_paramTypesMap, _288_name, ((_284_params).Select(_287_i)).dtor_tpe); + Dafny.ISequence _298_params; + Dafny.ISequence _out244; + _out244 = (this).GenParams(_295_paramsDafny, true); + _298_params = _out244; + Dafny.ISequence> _299_paramNames; + _299_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _300_paramTypesMap; + _300_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi10 = new BigInteger((_298_params).Count); + for (BigInteger _301_i = BigInteger.Zero; _301_i < _hi10; _301_i++) { + Dafny.ISequence _302_name; + _302_name = ((_298_params).Select(_301_i)).dtor_name; + _299_paramNames = Dafny.Sequence>.Concat(_299_paramNames, Dafny.Sequence>.FromElements(_302_name)); + _300_paramTypesMap = Dafny.Map, RAST._IType>.Update(_300_paramTypesMap, _302_name, ((_298_params).Select(_301_i)).dtor_tpe); } - DCOMP._IEnvironment _289_subEnv; - _289_subEnv = ((env).ToOwned()).merge(DCOMP.Environment.create(_285_paramNames, _286_paramTypesMap)); - RAST._IExpr _290_recursiveGen; - Dafny.ISet> _291_recIdents; - DCOMP._IEnvironment _292___v210; - RAST._IExpr _out233; - Dafny.ISet> _out234; - DCOMP._IEnvironment _out235; - (this).GenStmts(_283_body, ((!object.Equals(selfIdent, DCOMP.SelfInfo.create_NoSelf())) ? (DCOMP.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (DCOMP.SelfInfo.create_NoSelf())), _289_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out233, out _out234, out _out235); - _290_recursiveGen = _out233; - _291_recIdents = _out234; - _292___v210 = _out235; + DCOMP._IEnvironment _303_subEnv; + _303_subEnv = ((env).ToOwned()).merge(DCOMP.Environment.create(_299_paramNames, _300_paramTypesMap)); + RAST._IExpr _304_recursiveGen; + Dafny.ISet> _305_recIdents; + DCOMP._IEnvironment _306___v218; + RAST._IExpr _out245; + Dafny.ISet> _out246; + DCOMP._IEnvironment _out247; + (this).GenStmts(_297_body, ((!object.Equals(selfIdent, DCOMP.SelfInfo.create_NoSelf())) ? (DCOMP.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (DCOMP.SelfInfo.create_NoSelf())), _303_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out245, out _out246, out _out247); + _304_recursiveGen = _out245; + _305_recIdents = _out246; + _306___v218 = _out247; readIdents = Dafny.Set>.FromElements(); - _291_recIdents = Dafny.Set>.Difference(_291_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_293_paramNames) => ((System.Func>>)(() => { + _305_recIdents = Dafny.Set>.Difference(_305_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_307_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (Dafny.ISequence _compr_0 in (_293_paramNames).CloneAsArray()) { - Dafny.ISequence _294_name = (Dafny.ISequence)_compr_0; - if ((_293_paramNames).Contains(_294_name)) { - _coll0.Add(_294_name); + foreach (Dafny.ISequence _compr_0 in (_307_paramNames).CloneAsArray()) { + Dafny.ISequence _308_name = (Dafny.ISequence)_compr_0; + if ((_307_paramNames).Contains(_308_name)) { + _coll0.Add(_308_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_285_paramNames)); - RAST._IExpr _295_allReadCloned; - _295_allReadCloned = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); - while (!(_291_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _296_next; - foreach (Dafny.ISequence _assign_such_that_1 in (_291_recIdents).Elements) { - _296_next = (Dafny.ISequence)_assign_such_that_1; - if ((_291_recIdents).Contains(_296_next)) { + }))())(_299_paramNames)); + RAST._IExpr _309_allReadCloned; + _309_allReadCloned = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); + while (!(_305_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _310_next; + foreach (Dafny.ISequence _assign_such_that_1 in (_305_recIdents).Elements) { + _310_next = (Dafny.ISequence)_assign_such_that_1; + if ((_305_recIdents).Contains(_310_next)) { goto after__ASSIGN_SUCH_THAT_1; } } - throw new System.Exception("assign-such-that search produced no value (line 4877)"); + throw new System.Exception("assign-such-that search produced no value (line 5272)"); after__ASSIGN_SUCH_THAT_1: ; - if ((!object.Equals(selfIdent, DCOMP.SelfInfo.create_NoSelf())) && ((_296_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { - RAST._IExpr _297_selfCloned; - DCOMP._IOwnership _298___v211; - Dafny.ISet> _299___v212; - RAST._IExpr _out236; - DCOMP._IOwnership _out237; - Dafny.ISet> _out238; - (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out236, out _out237, out _out238); - _297_selfCloned = _out236; - _298___v211 = _out237; - _299___v212 = _out238; - _295_allReadCloned = (_295_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_297_selfCloned))); - } else if (!((_285_paramNames).Contains(_296_next))) { - RAST._IExpr _300_copy; - _300_copy = (RAST.Expr.create_Identifier(_296_next)).Clone(); - _295_allReadCloned = (_295_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _296_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_300_copy))); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_296_next)); + if ((!object.Equals(selfIdent, DCOMP.SelfInfo.create_NoSelf())) && ((_310_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + RAST._IExpr _311_selfCloned; + DCOMP._IOwnership _312___v219; + Dafny.ISet> _313___v220; + RAST._IExpr _out248; + DCOMP._IOwnership _out249; + Dafny.ISet> _out250; + (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out248, out _out249, out _out250); + _311_selfCloned = _out248; + _312___v219 = _out249; + _313___v220 = _out250; + _309_allReadCloned = (_309_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_311_selfCloned))); + } else if (!((_299_paramNames).Contains(_310_next))) { + RAST._IExpr _314_copy; + _314_copy = (RAST.Expr.create_Identifier(_310_next)).Clone(); + _309_allReadCloned = (_309_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _310_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_314_copy))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_310_next)); } - _291_recIdents = Dafny.Set>.Difference(_291_recIdents, Dafny.Set>.FromElements(_296_next)); + _305_recIdents = Dafny.Set>.Difference(_305_recIdents, Dafny.Set>.FromElements(_310_next)); } - RAST._IType _301_retTypeGen; - RAST._IType _out239; - _out239 = (this).GenType(_282_retType, DCOMP.GenTypeContext.InFn()); - _301_retTypeGen = _out239; - r = RAST.Expr.create_Block((_295_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_284_params, Std.Wrappers.Option.create_Some(_301_retTypeGen), RAST.Expr.create_Block(_290_recursiveGen))))); - RAST._IExpr _out240; - DCOMP._IOwnership _out241; - (this).FromOwned(r, expectedOwnership, out _out240, out _out241); - r = _out240; - resultingOwnership = _out241; + RAST._IType _315_retTypeGen; + RAST._IType _out251; + _out251 = (this).GenType(_296_retType, DCOMP.GenTypeContext.@default()); + _315_retTypeGen = _out251; + r = RAST.Expr.create_Block((_309_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_298_params, Std.Wrappers.Option.create_Some(_315_retTypeGen), RAST.Expr.create_Block(_304_recursiveGen))))); + RAST._IExpr _out252; + DCOMP._IOwnership _out253; + (this).FromOwned(r, expectedOwnership, out _out252, out _out253); + r = _out252; + resultingOwnership = _out253; return ; } goto after_match0; @@ -6634,72 +7065,72 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _302_values = _source0.dtor_values; - DAST._IType _303_retType = _source0.dtor_retType; - DAST._IExpression _304_expr = _source0.dtor_expr; + Dafny.ISequence<_System._ITuple2> _316_values = _source0.dtor_values; + DAST._IType _317_retType = _source0.dtor_retType; + DAST._IExpression _318_expr = _source0.dtor_expr; { - Dafny.ISequence> _305_paramNames; - _305_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISequence _306_paramFormals; - Dafny.ISequence _out242; - _out242 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_307_value) => { - return (_307_value).dtor__0; - })), _302_values)); - _306_paramFormals = _out242; - Dafny.IMap,RAST._IType> _308_paramTypes; - _308_paramTypes = Dafny.Map, RAST._IType>.FromElements(); - Dafny.ISet> _309_paramNamesSet; - _309_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _hi9 = new BigInteger((_302_values).Count); - for (BigInteger _310_i = BigInteger.Zero; _310_i < _hi9; _310_i++) { - Dafny.ISequence _311_name; - _311_name = (((_302_values).Select(_310_i)).dtor__0).dtor_name; - Dafny.ISequence _312_rName; - _312_rName = DCOMP.__default.escapeName(_311_name); - _305_paramNames = Dafny.Sequence>.Concat(_305_paramNames, Dafny.Sequence>.FromElements(_312_rName)); - _308_paramTypes = Dafny.Map, RAST._IType>.Update(_308_paramTypes, _312_rName, ((_306_paramFormals).Select(_310_i)).dtor_tpe); - _309_paramNamesSet = Dafny.Set>.Union(_309_paramNamesSet, Dafny.Set>.FromElements(_312_rName)); + Dafny.ISequence> _319_paramNames; + _319_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _320_paramFormals; + Dafny.ISequence _out254; + _out254 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_321_value) => { + return (_321_value).dtor__0; + })), _316_values), false); + _320_paramFormals = _out254; + Dafny.IMap,RAST._IType> _322_paramTypes; + _322_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _323_paramNamesSet; + _323_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi11 = new BigInteger((_316_values).Count); + for (BigInteger _324_i = BigInteger.Zero; _324_i < _hi11; _324_i++) { + Dafny.ISequence _325_name; + _325_name = (((_316_values).Select(_324_i)).dtor__0).dtor_name; + Dafny.ISequence _326_rName; + _326_rName = DCOMP.__default.escapeVar(_325_name); + _319_paramNames = Dafny.Sequence>.Concat(_319_paramNames, Dafny.Sequence>.FromElements(_326_rName)); + _322_paramTypes = Dafny.Map, RAST._IType>.Update(_322_paramTypes, _326_rName, ((_320_paramFormals).Select(_324_i)).dtor_tpe); + _323_paramNamesSet = Dafny.Set>.Union(_323_paramNamesSet, Dafny.Set>.FromElements(_326_rName)); } readIdents = Dafny.Set>.FromElements(); r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); - BigInteger _hi10 = new BigInteger((_302_values).Count); - for (BigInteger _313_i = BigInteger.Zero; _313_i < _hi10; _313_i++) { - RAST._IType _314_typeGen; - RAST._IType _out243; - _out243 = (this).GenType((((_302_values).Select(_313_i)).dtor__0).dtor_typ, DCOMP.GenTypeContext.InFn()); - _314_typeGen = _out243; - RAST._IExpr _315_valueGen; - DCOMP._IOwnership _316___v213; - Dafny.ISet> _317_recIdents; - RAST._IExpr _out244; - DCOMP._IOwnership _out245; - Dafny.ISet> _out246; - (this).GenExpr(((_302_values).Select(_313_i)).dtor__1, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out244, out _out245, out _out246); - _315_valueGen = _out244; - _316___v213 = _out245; - _317_recIdents = _out246; - r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), DCOMP.__default.escapeName((((_302_values).Select(_313_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_314_typeGen), Std.Wrappers.Option.create_Some(_315_valueGen))); - readIdents = Dafny.Set>.Union(readIdents, _317_recIdents); + BigInteger _hi12 = new BigInteger((_316_values).Count); + for (BigInteger _327_i = BigInteger.Zero; _327_i < _hi12; _327_i++) { + RAST._IType _328_typeGen; + RAST._IType _out255; + _out255 = (this).GenType((((_316_values).Select(_327_i)).dtor__0).dtor_typ, DCOMP.GenTypeContext.@default()); + _328_typeGen = _out255; + RAST._IExpr _329_valueGen; + DCOMP._IOwnership _330___v221; + Dafny.ISet> _331_recIdents; + RAST._IExpr _out256; + DCOMP._IOwnership _out257; + Dafny.ISet> _out258; + (this).GenExpr(((_316_values).Select(_327_i)).dtor__1, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out256, out _out257, out _out258); + _329_valueGen = _out256; + _330___v221 = _out257; + _331_recIdents = _out258; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), DCOMP.__default.escapeVar((((_316_values).Select(_327_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_328_typeGen), Std.Wrappers.Option.create_Some(_329_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _331_recIdents); } - DCOMP._IEnvironment _318_newEnv; - _318_newEnv = DCOMP.Environment.create(_305_paramNames, _308_paramTypes); - RAST._IExpr _319_recGen; - DCOMP._IOwnership _320_recOwned; - Dafny.ISet> _321_recIdents; - RAST._IExpr _out247; - DCOMP._IOwnership _out248; - Dafny.ISet> _out249; - (this).GenExpr(_304_expr, selfIdent, _318_newEnv, expectedOwnership, out _out247, out _out248, out _out249); - _319_recGen = _out247; - _320_recOwned = _out248; - _321_recIdents = _out249; - readIdents = Dafny.Set>.Difference(_321_recIdents, _309_paramNamesSet); - r = RAST.Expr.create_Block((r).Then(_319_recGen)); - RAST._IExpr _out250; - DCOMP._IOwnership _out251; - (this).FromOwnership(r, _320_recOwned, expectedOwnership, out _out250, out _out251); - r = _out250; - resultingOwnership = _out251; + DCOMP._IEnvironment _332_newEnv; + _332_newEnv = DCOMP.Environment.create(_319_paramNames, _322_paramTypes); + RAST._IExpr _333_recGen; + DCOMP._IOwnership _334_recOwned; + Dafny.ISet> _335_recIdents; + RAST._IExpr _out259; + DCOMP._IOwnership _out260; + Dafny.ISet> _out261; + (this).GenExpr(_318_expr, selfIdent, _332_newEnv, expectedOwnership, out _out259, out _out260, out _out261); + _333_recGen = _out259; + _334_recOwned = _out260; + _335_recIdents = _out261; + readIdents = Dafny.Set>.Difference(_335_recIdents, _323_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_333_recGen)); + RAST._IExpr _out262; + DCOMP._IOwnership _out263; + (this).FromOwnership(r, _334_recOwned, expectedOwnership, out _out262, out _out263); + r = _out262; + resultingOwnership = _out263; return ; } goto after_match0; @@ -6707,43 +7138,45 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_IIFE) { - Dafny.ISequence _322_name = _source0.dtor_ident; - DAST._IType _323_tpe = _source0.dtor_typ; - DAST._IExpression _324_value = _source0.dtor_value; - DAST._IExpression _325_iifeBody = _source0.dtor_iifeBody; + Dafny.ISequence _336_name = _source0.dtor_ident; + DAST._IType _337_tpe = _source0.dtor_typ; + DAST._IExpression _338_value = _source0.dtor_value; + DAST._IExpression _339_iifeBody = _source0.dtor_iifeBody; { - RAST._IExpr _326_valueGen; - DCOMP._IOwnership _327___v214; - Dafny.ISet> _328_recIdents; - RAST._IExpr _out252; - DCOMP._IOwnership _out253; - Dafny.ISet> _out254; - (this).GenExpr(_324_value, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out252, out _out253, out _out254); - _326_valueGen = _out252; - _327___v214 = _out253; - _328_recIdents = _out254; - readIdents = _328_recIdents; - RAST._IType _329_valueTypeGen; - RAST._IType _out255; - _out255 = (this).GenType(_323_tpe, DCOMP.GenTypeContext.InFn()); - _329_valueTypeGen = _out255; - RAST._IExpr _330_bodyGen; - DCOMP._IOwnership _331___v215; - Dafny.ISet> _332_bodyIdents; - RAST._IExpr _out256; - DCOMP._IOwnership _out257; - Dafny.ISet> _out258; - (this).GenExpr(_325_iifeBody, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out256, out _out257, out _out258); - _330_bodyGen = _out256; - _331___v215 = _out257; - _332_bodyIdents = _out258; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_332_bodyIdents, Dafny.Set>.FromElements(DCOMP.__default.escapeName((_322_name))))); - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), DCOMP.__default.escapeName((_322_name)), Std.Wrappers.Option.create_Some(_329_valueTypeGen), Std.Wrappers.Option.create_Some(_326_valueGen))).Then(_330_bodyGen)); - RAST._IExpr _out259; - DCOMP._IOwnership _out260; - (this).FromOwned(r, expectedOwnership, out _out259, out _out260); - r = _out259; - resultingOwnership = _out260; + RAST._IExpr _340_valueGen; + DCOMP._IOwnership _341___v222; + Dafny.ISet> _342_recIdents; + RAST._IExpr _out264; + DCOMP._IOwnership _out265; + Dafny.ISet> _out266; + (this).GenExpr(_338_value, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out264, out _out265, out _out266); + _340_valueGen = _out264; + _341___v222 = _out265; + _342_recIdents = _out266; + readIdents = _342_recIdents; + RAST._IType _343_valueTypeGen; + RAST._IType _out267; + _out267 = (this).GenType(_337_tpe, DCOMP.GenTypeContext.@default()); + _343_valueTypeGen = _out267; + Dafny.ISequence _344_iifeVar; + _344_iifeVar = DCOMP.__default.escapeVar(_336_name); + RAST._IExpr _345_bodyGen; + DCOMP._IOwnership _346___v223; + Dafny.ISet> _347_bodyIdents; + RAST._IExpr _out268; + DCOMP._IOwnership _out269; + Dafny.ISet> _out270; + (this).GenExpr(_339_iifeBody, selfIdent, (env).AddAssigned(_344_iifeVar, _343_valueTypeGen), DCOMP.Ownership.create_OwnershipOwned(), out _out268, out _out269, out _out270); + _345_bodyGen = _out268; + _346___v223 = _out269; + _347_bodyIdents = _out270; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_347_bodyIdents, Dafny.Set>.FromElements(_344_iifeVar))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _344_iifeVar, Std.Wrappers.Option.create_Some(_343_valueTypeGen), Std.Wrappers.Option.create_Some(_340_valueGen))).Then(_345_bodyGen)); + RAST._IExpr _out271; + DCOMP._IOwnership _out272; + (this).FromOwned(r, expectedOwnership, out _out271, out _out272); + r = _out271; + resultingOwnership = _out272; return ; } goto after_match0; @@ -6751,43 +7184,43 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_Apply) { - DAST._IExpression _333_func = _source0.dtor_expr; - Dafny.ISequence _334_args = _source0.dtor_args; + DAST._IExpression _348_func = _source0.dtor_expr; + Dafny.ISequence _349_args = _source0.dtor_args; { - RAST._IExpr _335_funcExpr; - DCOMP._IOwnership _336___v216; - Dafny.ISet> _337_recIdents; - RAST._IExpr _out261; - DCOMP._IOwnership _out262; - Dafny.ISet> _out263; - (this).GenExpr(_333_func, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out261, out _out262, out _out263); - _335_funcExpr = _out261; - _336___v216 = _out262; - _337_recIdents = _out263; - readIdents = _337_recIdents; - Dafny.ISequence _338_rArgs; - _338_rArgs = Dafny.Sequence.FromElements(); - BigInteger _hi11 = new BigInteger((_334_args).Count); - for (BigInteger _339_i = BigInteger.Zero; _339_i < _hi11; _339_i++) { - RAST._IExpr _340_argExpr; - DCOMP._IOwnership _341_argOwned; - Dafny.ISet> _342_argIdents; - RAST._IExpr _out264; - DCOMP._IOwnership _out265; - Dafny.ISet> _out266; - (this).GenExpr((_334_args).Select(_339_i), selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out264, out _out265, out _out266); - _340_argExpr = _out264; - _341_argOwned = _out265; - _342_argIdents = _out266; - _338_rArgs = Dafny.Sequence.Concat(_338_rArgs, Dafny.Sequence.FromElements(_340_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _342_argIdents); + RAST._IExpr _350_funcExpr; + DCOMP._IOwnership _351___v224; + Dafny.ISet> _352_recIdents; + RAST._IExpr _out273; + DCOMP._IOwnership _out274; + Dafny.ISet> _out275; + (this).GenExpr(_348_func, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out273, out _out274, out _out275); + _350_funcExpr = _out273; + _351___v224 = _out274; + _352_recIdents = _out275; + readIdents = _352_recIdents; + Dafny.ISequence _353_rArgs; + _353_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi13 = new BigInteger((_349_args).Count); + for (BigInteger _354_i = BigInteger.Zero; _354_i < _hi13; _354_i++) { + RAST._IExpr _355_argExpr; + DCOMP._IOwnership _356_argOwned; + Dafny.ISet> _357_argIdents; + RAST._IExpr _out276; + DCOMP._IOwnership _out277; + Dafny.ISet> _out278; + (this).GenExpr((_349_args).Select(_354_i), selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out276, out _out277, out _out278); + _355_argExpr = _out276; + _356_argOwned = _out277; + _357_argIdents = _out278; + _353_rArgs = Dafny.Sequence.Concat(_353_rArgs, Dafny.Sequence.FromElements(_355_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _357_argIdents); } - r = (_335_funcExpr).Apply(_338_rArgs); - RAST._IExpr _out267; - DCOMP._IOwnership _out268; - (this).FromOwned(r, expectedOwnership, out _out267, out _out268); - r = _out267; - resultingOwnership = _out268; + r = (_350_funcExpr).Apply(_353_rArgs); + RAST._IExpr _out279; + DCOMP._IOwnership _out280; + (this).FromOwned(r, expectedOwnership, out _out279, out _out280); + r = _out279; + resultingOwnership = _out280; return ; } goto after_match0; @@ -6795,31 +7228,73 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_TypeTest) { - DAST._IExpression _343_on = _source0.dtor_on; - Dafny.ISequence> _344_dType = _source0.dtor_dType; - Dafny.ISequence _345_variant = _source0.dtor_variant; + DAST._IExpression _358_on = _source0.dtor_on; + Dafny.ISequence> _359_dType = _source0.dtor_dType; + Dafny.ISequence _360_variant = _source0.dtor_variant; { - RAST._IExpr _346_exprGen; - DCOMP._IOwnership _347___v217; - Dafny.ISet> _348_recIdents; - RAST._IExpr _out269; - DCOMP._IOwnership _out270; - Dafny.ISet> _out271; - (this).GenExpr(_343_on, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out269, out _out270, out _out271); - _346_exprGen = _out269; - _347___v217 = _out270; - _348_recIdents = _out271; - RAST._IType _349_dTypePath; - RAST._IType _out272; - _out272 = DCOMP.COMP.GenPath(_344_dType); - _349_dTypePath = _out272; - r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_346_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply(Dafny.Sequence.FromElements()), RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(((_349_dTypePath).MSel(DCOMP.__default.escapeName(_345_variant)))._ToString(DCOMP.__default.IND), Dafny.Sequence.UnicodeFromString("{ .. }"))))); - RAST._IExpr _out273; - DCOMP._IOwnership _out274; - (this).FromOwned(r, expectedOwnership, out _out273, out _out274); - r = _out273; - resultingOwnership = _out274; - readIdents = _348_recIdents; + RAST._IExpr _361_exprGen; + DCOMP._IOwnership _362___v225; + Dafny.ISet> _363_recIdents; + RAST._IExpr _out281; + DCOMP._IOwnership _out282; + Dafny.ISet> _out283; + (this).GenExpr(_358_on, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out281, out _out282, out _out283); + _361_exprGen = _out281; + _362___v225 = _out282; + _363_recIdents = _out283; + RAST._IType _364_dTypePath; + RAST._IType _out284; + _out284 = DCOMP.COMP.GenPathType(Dafny.Sequence>.Concat(_359_dType, Dafny.Sequence>.FromElements(_360_variant))); + _364_dTypePath = _out284; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_361_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply(Dafny.Sequence.FromElements()), RAST.Expr.create_RawExpr(Dafny.Sequence.Concat((_364_dTypePath)._ToString(DCOMP.__default.IND), Dafny.Sequence.UnicodeFromString("{ .. }"))))); + RAST._IExpr _out285; + DCOMP._IOwnership _out286; + (this).FromOwned(r, expectedOwnership, out _out285, out _out286); + r = _out285; + resultingOwnership = _out286; + readIdents = _363_recIdents; + return ; + } + goto after_match0; + } + } + { + if (_source0.is_Is) { + DAST._IExpression _365_expr = _source0.dtor_expr; + DAST._IType _366_fromType = _source0.dtor_fromType; + DAST._IType _367_toType = _source0.dtor_toType; + { + RAST._IExpr _368_expr; + DCOMP._IOwnership _369_recOwned; + Dafny.ISet> _370_recIdents; + RAST._IExpr _out287; + DCOMP._IOwnership _out288; + Dafny.ISet> _out289; + (this).GenExpr(_365_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out287, out _out288, out _out289); + _368_expr = _out287; + _369_recOwned = _out288; + _370_recIdents = _out289; + RAST._IType _371_fromType; + RAST._IType _out290; + _out290 = (this).GenType(_366_fromType, DCOMP.GenTypeContext.@default()); + _371_fromType = _out290; + RAST._IType _372_toType; + RAST._IType _out291; + _out291 = (this).GenType(_367_toType, DCOMP.GenTypeContext.@default()); + _372_toType = _out291; + if (((_371_fromType).IsObjectOrPointer()) && ((_372_toType).IsObjectOrPointer())) { + r = (((_368_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_372_toType).ObjectOrPointerUnderlying()))).Apply(Dafny.Sequence.FromElements()); + } else { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object or Ptr")); + r = RAST.Expr.create_RawExpr((this.error).dtor_value); + readIdents = Dafny.Set>.FromElements(); + } + RAST._IExpr _out292; + DCOMP._IOwnership _out293; + (this).FromOwnership(r, _369_recOwned, expectedOwnership, out _out292, out _out293); + r = _out292; + resultingOwnership = _out293; + readIdents = _370_recIdents; return ; } goto after_match0; @@ -6829,11 +7304,11 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv if (_source0.is_BoolBoundedPool) { { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("[false, true]")); - RAST._IExpr _out275; - DCOMP._IOwnership _out276; - (this).FromOwned(r, expectedOwnership, out _out275, out _out276); - r = _out275; - resultingOwnership = _out276; + RAST._IExpr _out294; + DCOMP._IOwnership _out295; + (this).FromOwned(r, expectedOwnership, out _out294, out _out295); + r = _out294; + resultingOwnership = _out295; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6842,25 +7317,25 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_SetBoundedPool) { - DAST._IExpression _350_of = _source0.dtor_of; + DAST._IExpression _373_of = _source0.dtor_of; { - RAST._IExpr _351_exprGen; - DCOMP._IOwnership _352___v218; - Dafny.ISet> _353_recIdents; - RAST._IExpr _out277; - DCOMP._IOwnership _out278; - Dafny.ISet> _out279; - (this).GenExpr(_350_of, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out277, out _out278, out _out279); - _351_exprGen = _out277; - _352___v218 = _out278; - _353_recIdents = _out279; - r = ((_351_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply(Dafny.Sequence.FromElements()); - RAST._IExpr _out280; - DCOMP._IOwnership _out281; - (this).FromOwned(r, expectedOwnership, out _out280, out _out281); - r = _out280; - resultingOwnership = _out281; - readIdents = _353_recIdents; + RAST._IExpr _374_exprGen; + DCOMP._IOwnership _375___v226; + Dafny.ISet> _376_recIdents; + RAST._IExpr _out296; + DCOMP._IOwnership _out297; + Dafny.ISet> _out298; + (this).GenExpr(_373_of, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out296, out _out297, out _out298); + _374_exprGen = _out296; + _375___v226 = _out297; + _376_recIdents = _out298; + r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out299; + DCOMP._IOwnership _out300; + (this).FromOwned(r, expectedOwnership, out _out299, out _out300); + r = _out299; + resultingOwnership = _out300; + readIdents = _376_recIdents; return ; } goto after_match0; @@ -6868,29 +7343,29 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_SeqBoundedPool) { - DAST._IExpression _354_of = _source0.dtor_of; - bool _355_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _377_of = _source0.dtor_of; + bool _378_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _356_exprGen; - DCOMP._IOwnership _357___v219; - Dafny.ISet> _358_recIdents; - RAST._IExpr _out282; - DCOMP._IOwnership _out283; - Dafny.ISet> _out284; - (this).GenExpr(_354_of, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out282, out _out283, out _out284); - _356_exprGen = _out282; - _357___v219 = _out283; - _358_recIdents = _out284; - r = ((_356_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply(Dafny.Sequence.FromElements()); - if (!(_355_includeDuplicates)) { - r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).MSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); + RAST._IExpr _379_exprGen; + DCOMP._IOwnership _380___v227; + Dafny.ISet> _381_recIdents; + RAST._IExpr _out301; + DCOMP._IOwnership _out302; + Dafny.ISet> _out303; + (this).GenExpr(_377_of, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out301, out _out302, out _out303); + _379_exprGen = _out301; + _380___v227 = _out302; + _381_recIdents = _out303; + r = ((_379_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply(Dafny.Sequence.FromElements()); + if (!(_378_includeDuplicates)) { + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).MSel(Dafny.Sequence.UnicodeFromString("unique"))).AsExpr()).Apply1(r); } - RAST._IExpr _out285; - DCOMP._IOwnership _out286; - (this).FromOwned(r, expectedOwnership, out _out285, out _out286); - r = _out285; - resultingOwnership = _out286; - readIdents = _358_recIdents; + RAST._IExpr _out304; + DCOMP._IOwnership _out305; + (this).FromOwned(r, expectedOwnership, out _out304, out _out305); + r = _out304; + resultingOwnership = _out305; + readIdents = _381_recIdents; return ; } goto after_match0; @@ -6898,66 +7373,74 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_MapBoundedPool) { - DAST._IExpression _359_of = _source0.dtor_of; + DAST._IExpression _382_of = _source0.dtor_of; { - RAST._IExpr _360_exprGen; - DCOMP._IOwnership _361___v220; - Dafny.ISet> _362_recIdents; - RAST._IExpr _out287; - DCOMP._IOwnership _out288; - Dafny.ISet> _out289; - (this).GenExpr(_359_of, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out287, out _out288, out _out289); - _360_exprGen = _out287; - _361___v220 = _out288; - _362_recIdents = _out289; - r = ((((_360_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply(Dafny.Sequence.FromElements())).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply(Dafny.Sequence.FromElements()); - readIdents = _362_recIdents; - RAST._IExpr _out290; - DCOMP._IOwnership _out291; - (this).FromOwned(r, expectedOwnership, out _out290, out _out291); - r = _out290; - resultingOwnership = _out291; + RAST._IExpr _383_exprGen; + DCOMP._IOwnership _384___v228; + Dafny.ISet> _385_recIdents; + RAST._IExpr _out306; + DCOMP._IOwnership _out307; + Dafny.ISet> _out308; + (this).GenExpr(_382_of, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out306, out _out307, out _out308); + _383_exprGen = _out306; + _384___v228 = _out307; + _385_recIdents = _out308; + r = ((((_383_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply(Dafny.Sequence.FromElements())).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply(Dafny.Sequence.FromElements()); + readIdents = _385_recIdents; + RAST._IExpr _out309; + DCOMP._IOwnership _out310; + (this).FromOwned(r, expectedOwnership, out _out309, out _out310); + r = _out309; + resultingOwnership = _out310; } goto after_match0; } } { if (_source0.is_IntRange) { - DAST._IExpression _363_lo = _source0.dtor_lo; - DAST._IExpression _364_hi = _source0.dtor_hi; - bool _365_up = _source0.dtor_up; + DAST._IType _386_typ = _source0.dtor_elemType; + DAST._IExpression _387_lo = _source0.dtor_lo; + DAST._IExpression _388_hi = _source0.dtor_hi; + bool _389_up = _source0.dtor_up; { - RAST._IExpr _366_lo; - DCOMP._IOwnership _367___v221; - Dafny.ISet> _368_recIdentsLo; - RAST._IExpr _out292; - DCOMP._IOwnership _out293; - Dafny.ISet> _out294; - (this).GenExpr(_363_lo, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out292, out _out293, out _out294); - _366_lo = _out292; - _367___v221 = _out293; - _368_recIdentsLo = _out294; - RAST._IExpr _369_hi; - DCOMP._IOwnership _370___v222; - Dafny.ISet> _371_recIdentsHi; - RAST._IExpr _out295; - DCOMP._IOwnership _out296; - Dafny.ISet> _out297; - (this).GenExpr(_364_hi, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out295, out _out296, out _out297); - _369_hi = _out295; - _370___v222 = _out296; - _371_recIdentsHi = _out297; - if (_365_up) { - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).Apply(Dafny.Sequence.FromElements(_366_lo, _369_hi)); + RAST._IExpr _390_lo; + DCOMP._IOwnership _391___v229; + Dafny.ISet> _392_recIdentsLo; + RAST._IExpr _out311; + DCOMP._IOwnership _out312; + Dafny.ISet> _out313; + (this).GenExpr(_387_lo, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out311, out _out312, out _out313); + _390_lo = _out311; + _391___v229 = _out312; + _392_recIdentsLo = _out313; + RAST._IExpr _393_hi; + DCOMP._IOwnership _394___v230; + Dafny.ISet> _395_recIdentsHi; + RAST._IExpr _out314; + DCOMP._IOwnership _out315; + Dafny.ISet> _out316; + (this).GenExpr(_388_hi, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out314, out _out315, out _out316); + _393_hi = _out314; + _394___v230 = _out315; + _395_recIdentsHi = _out316; + if (_389_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_390_lo, _393_hi)); } else { - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).Apply(Dafny.Sequence.FromElements(_369_hi, _366_lo)); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_393_hi, _390_lo)); + } + if (!((_386_typ).is_Primitive)) { + RAST._IType _396_tpe; + RAST._IType _out317; + _out317 = (this).GenType(_386_typ, DCOMP.GenTypeContext.@default()); + _396_tpe = _out317; + 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(_396_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); } - RAST._IExpr _out298; - DCOMP._IOwnership _out299; - (this).FromOwned(r, expectedOwnership, out _out298, out _out299); - r = _out298; - resultingOwnership = _out299; - readIdents = Dafny.Set>.Union(_368_recIdentsLo, _371_recIdentsHi); + RAST._IExpr _out318; + DCOMP._IOwnership _out319; + (this).FromOwned(r, expectedOwnership, out _out318, out _out319); + r = _out318; + resultingOwnership = _out319; + readIdents = Dafny.Set>.Union(_392_recIdentsLo, _395_recIdentsHi); return ; } goto after_match0; @@ -6965,30 +7448,30 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _372_start = _source0.dtor_start; - bool _373_up = _source0.dtor_up; + DAST._IExpression _397_start = _source0.dtor_start; + bool _398_up = _source0.dtor_up; { - RAST._IExpr _374_start; - DCOMP._IOwnership _375___v223; - Dafny.ISet> _376_recIdentStart; - RAST._IExpr _out300; - DCOMP._IOwnership _out301; - Dafny.ISet> _out302; - (this).GenExpr(_372_start, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out300, out _out301, out _out302); - _374_start = _out300; - _375___v223 = _out301; - _376_recIdentStart = _out302; - if (_373_up) { - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).Apply1(_374_start); + RAST._IExpr _399_start; + DCOMP._IOwnership _400___v231; + Dafny.ISet> _401_recIdentStart; + RAST._IExpr _out320; + DCOMP._IOwnership _out321; + Dafny.ISet> _out322; + (this).GenExpr(_397_start, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out320, out _out321, out _out322); + _399_start = _out320; + _400___v231 = _out321; + _401_recIdentStart = _out322; + if (_398_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_399_start); } else { - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).Apply1(_374_start); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_399_start); } - RAST._IExpr _out303; - DCOMP._IOwnership _out304; - (this).FromOwned(r, expectedOwnership, out _out303, out _out304); - r = _out303; - resultingOwnership = _out304; - readIdents = _376_recIdentStart; + RAST._IExpr _out323; + DCOMP._IOwnership _out324; + (this).FromOwned(r, expectedOwnership, out _out323, out _out324); + r = _out323; + resultingOwnership = _out324; + readIdents = _401_recIdentStart; return ; } goto after_match0; @@ -6996,23 +7479,23 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_MapBuilder) { - DAST._IType _377_keyType = _source0.dtor_keyType; - DAST._IType _378_valueType = _source0.dtor_valueType; + DAST._IType _402_keyType = _source0.dtor_keyType; + DAST._IType _403_valueType = _source0.dtor_valueType; { - RAST._IType _379_kType; - RAST._IType _out305; - _out305 = (this).GenType(_377_keyType, DCOMP.GenTypeContext.@default()); - _379_kType = _out305; - RAST._IType _380_vType; - RAST._IType _out306; - _out306 = (this).GenType(_378_valueType, DCOMP.GenTypeContext.@default()); - _380_vType = _out306; - r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).ApplyType(Dafny.Sequence.FromElements(_379_kType, _380_vType))).MSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements()); - RAST._IExpr _out307; - DCOMP._IOwnership _out308; - (this).FromOwned(r, expectedOwnership, out _out307, out _out308); - r = _out307; - resultingOwnership = _out308; + RAST._IType _404_kType; + RAST._IType _out325; + _out325 = (this).GenType(_402_keyType, DCOMP.GenTypeContext.@default()); + _404_kType = _out325; + RAST._IType _405_vType; + RAST._IType _out326; + _out326 = (this).GenType(_403_valueType, DCOMP.GenTypeContext.@default()); + _405_vType = _out326; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_404_kType, _405_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out327; + DCOMP._IOwnership _out328; + (this).FromOwned(r, expectedOwnership, out _out327, out _out328); + r = _out327; + resultingOwnership = _out328; readIdents = Dafny.Set>.FromElements(); return ; } @@ -7021,116 +7504,148 @@ public void GenExpr(DAST._IExpression e, DCOMP._ISelfInfo selfIdent, DCOMP._IEnv } { if (_source0.is_SetBuilder) { - DAST._IType _381_elemType = _source0.dtor_elemType; + DAST._IType _406_elemType = _source0.dtor_elemType; { - RAST._IType _382_eType; - RAST._IType _out309; - _out309 = (this).GenType(_381_elemType, DCOMP.GenTypeContext.@default()); - _382_eType = _out309; + RAST._IType _407_eType; + RAST._IType _out329; + _out329 = (this).GenType(_406_elemType, DCOMP.GenTypeContext.@default()); + _407_eType = _out329; readIdents = Dafny.Set>.FromElements(); - r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).ApplyType(Dafny.Sequence.FromElements(_382_eType))).MSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements()); - RAST._IExpr _out310; - DCOMP._IOwnership _out311; - (this).FromOwned(r, expectedOwnership, out _out310, out _out311); - r = _out310; - resultingOwnership = _out311; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_407_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out330; + DCOMP._IOwnership _out331; + (this).FromOwned(r, expectedOwnership, out _out330, out _out331); + r = _out330; + resultingOwnership = _out331; return ; } goto after_match0; } } { - DAST._IType _383_elemType = _source0.dtor_elemType; - DAST._IExpression _384_collection = _source0.dtor_collection; - bool _385_is__forall = _source0.dtor_is__forall; - DAST._IExpression _386_lambda = _source0.dtor_lambda; + DAST._IType _408_elemType = _source0.dtor_elemType; + DAST._IExpression _409_collection = _source0.dtor_collection; + bool _410_is__forall = _source0.dtor_is__forall; + DAST._IExpression _411_lambda = _source0.dtor_lambda; { - RAST._IType _387_tpe; - RAST._IType _out312; - _out312 = (this).GenType(_383_elemType, DCOMP.GenTypeContext.@default()); - _387_tpe = _out312; - RAST._IExpr _388_collectionGen; - DCOMP._IOwnership _389___v224; - Dafny.ISet> _390_recIdents; - RAST._IExpr _out313; - DCOMP._IOwnership _out314; - Dafny.ISet> _out315; - (this).GenExpr(_384_collection, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out313, out _out314, out _out315); - _388_collectionGen = _out313; - _389___v224 = _out314; - _390_recIdents = _out315; - Dafny.ISequence _391_extraAttributes; - _391_extraAttributes = Dafny.Sequence.FromElements(); - if ((((_384_collection).is_IntRange) || ((_384_collection).is_UnboundedIntRange)) || ((_384_collection).is_SeqBoundedPool)) { - _391_extraAttributes = Dafny.Sequence.FromElements(DCOMP.__default.AttributeOwned); - } - if ((_386_lambda).is_Lambda) { - Dafny.ISequence _392_formals; - _392_formals = (_386_lambda).dtor_params; - Dafny.ISequence _393_newFormals; - _393_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi12 = new BigInteger((_392_formals).Count); - for (BigInteger _394_i = BigInteger.Zero; _394_i < _hi12; _394_i++) { - var _pat_let_tv0 = _391_extraAttributes; - var _pat_let_tv1 = _392_formals; - _393_newFormals = Dafny.Sequence.Concat(_393_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_392_formals).Select(_394_i), _pat_let34_0 => Dafny.Helpers.Let(_pat_let34_0, _395_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_394_i)).dtor_attributes), _pat_let35_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let35_0, _396_dt__update_hattributes_h0 => DAST.Formal.create((_395_dt__update__tmp_h0).dtor_name, (_395_dt__update__tmp_h0).dtor_typ, _396_dt__update_hattributes_h0))))))); + RAST._IType _412_tpe; + RAST._IType _out332; + _out332 = (this).GenType(_408_elemType, DCOMP.GenTypeContext.@default()); + _412_tpe = _out332; + RAST._IExpr _413_collectionGen; + DCOMP._IOwnership _414___v232; + Dafny.ISet> _415_recIdents; + RAST._IExpr _out333; + DCOMP._IOwnership _out334; + Dafny.ISet> _out335; + (this).GenExpr(_409_collection, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out333, out _out334, out _out335); + _413_collectionGen = _out333; + _414___v232 = _out334; + _415_recIdents = _out335; + Dafny.ISequence _416_extraAttributes; + _416_extraAttributes = Dafny.Sequence.FromElements(); + if ((((_409_collection).is_IntRange) || ((_409_collection).is_UnboundedIntRange)) || ((_409_collection).is_SeqBoundedPool)) { + _416_extraAttributes = Dafny.Sequence.FromElements(DCOMP.__default.AttributeOwned); + } + if ((_411_lambda).is_Lambda) { + Dafny.ISequence _417_formals; + _417_formals = (_411_lambda).dtor_params; + Dafny.ISequence _418_newFormals; + _418_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi14 = new BigInteger((_417_formals).Count); + for (BigInteger _419_i = BigInteger.Zero; _419_i < _hi14; _419_i++) { + var _pat_let_tv0 = _416_extraAttributes; + var _pat_let_tv1 = _417_formals; + _418_newFormals = Dafny.Sequence.Concat(_418_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_417_formals).Select(_419_i), _pat_let23_0 => Dafny.Helpers.Let(_pat_let23_0, _420_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_419_i)).dtor_attributes), _pat_let24_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let24_0, _421_dt__update_hattributes_h0 => DAST.Formal.create((_420_dt__update__tmp_h0).dtor_name, (_420_dt__update__tmp_h0).dtor_typ, _421_dt__update_hattributes_h0))))))); } - DAST._IExpression _397_newLambda; - DAST._IExpression _398_dt__update__tmp_h1 = _386_lambda; - Dafny.ISequence _399_dt__update_hparams_h0 = _393_newFormals; - _397_newLambda = DAST.Expression.create_Lambda(_399_dt__update_hparams_h0, (_398_dt__update__tmp_h1).dtor_retType, (_398_dt__update__tmp_h1).dtor_body); - RAST._IExpr _400_lambdaGen; - DCOMP._IOwnership _401___v225; - Dafny.ISet> _402_recLambdaIdents; - RAST._IExpr _out316; - DCOMP._IOwnership _out317; - Dafny.ISet> _out318; - (this).GenExpr(_397_newLambda, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out316, out _out317, out _out318); - _400_lambdaGen = _out316; - _401___v225 = _out317; - _402_recLambdaIdents = _out318; - Dafny.ISequence _403_fn; - if (_385_is__forall) { - _403_fn = Dafny.Sequence.UnicodeFromString("all"); + DAST._IExpression _422_newLambda; + DAST._IExpression _423_dt__update__tmp_h1 = _411_lambda; + Dafny.ISequence _424_dt__update_hparams_h0 = _418_newFormals; + _422_newLambda = DAST.Expression.create_Lambda(_424_dt__update_hparams_h0, (_423_dt__update__tmp_h1).dtor_retType, (_423_dt__update__tmp_h1).dtor_body); + RAST._IExpr _425_lambdaGen; + DCOMP._IOwnership _426___v233; + Dafny.ISet> _427_recLambdaIdents; + RAST._IExpr _out336; + DCOMP._IOwnership _out337; + Dafny.ISet> _out338; + (this).GenExpr(_422_newLambda, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out336, out _out337, out _out338); + _425_lambdaGen = _out336; + _426___v233 = _out337; + _427_recLambdaIdents = _out338; + Dafny.ISequence _428_fn; + if (_410_is__forall) { + _428_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _403_fn = Dafny.Sequence.UnicodeFromString("any"); + _428_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_388_collectionGen).Sel(_403_fn)).Apply1(((_400_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply(Dafny.Sequence.FromElements())); - readIdents = Dafny.Set>.Union(_390_recIdents, _402_recLambdaIdents); + r = ((_413_collectionGen).Sel(_428_fn)).Apply1(((_425_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply(Dafny.Sequence.FromElements())); + readIdents = Dafny.Set>.Union(_415_recIdents, _427_recLambdaIdents); } else { (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda")); r = RAST.Expr.create_RawExpr((this.error).dtor_value); readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out319; - DCOMP._IOwnership _out320; - (this).FromOwned(r, expectedOwnership, out _out319, out _out320); - r = _out319; - resultingOwnership = _out320; + RAST._IExpr _out339; + DCOMP._IOwnership _out340; + (this).FromOwned(r, expectedOwnership, out _out339, out _out340); + r = _out339; + resultingOwnership = _out340; } } after_match0: ; } - public Dafny.ISequence Compile(Dafny.ISequence p) + public Dafny.ISequence Compile(Dafny.ISequence p, Dafny.ISequence> externalFiles) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.UnicodeFromString("#![allow(warnings, unconditional_panic)]\n"); s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("#![allow(nonstandard_style)]\n")); - BigInteger _0_i; - _0_i = BigInteger.Zero; - while ((_0_i) < (new BigInteger((p).Count))) { - Dafny.ISequence _1_generated = Dafny.Sequence.Empty; - RAST._IMod _2_m; - RAST._IMod _out0; - _out0 = (this).GenModule((p).Select(_0_i), Dafny.Sequence>.FromElements()); - _2_m = _out0; - _1_generated = (_2_m)._ToString(Dafny.Sequence.UnicodeFromString("")); - if ((_0_i).Sign == 1) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("\n")); - } - s = Dafny.Sequence.Concat(s, _1_generated); - _0_i = (_0_i) + (BigInteger.One); + Dafny.ISequence _0_externUseDecls; + _0_externUseDecls = Dafny.Sequence.FromElements(); + BigInteger _hi0 = new BigInteger((externalFiles).Count); + for (BigInteger _1_i = BigInteger.Zero; _1_i < _hi0; _1_i++) { + Dafny.ISequence _2_externalFile; + _2_externalFile = (externalFiles).Select(_1_i); + Dafny.ISequence _3_externalMod; + _3_externalMod = _2_externalFile; + if (((new BigInteger((_2_externalFile).Count)) > (new BigInteger(3))) && (((_2_externalFile).Drop((new BigInteger((_2_externalFile).Count)) - (new BigInteger(3)))).Equals(Dafny.Sequence.UnicodeFromString(".rs")))) { + _3_externalMod = (_2_externalFile).Subsequence(BigInteger.Zero, (new BigInteger((_2_externalFile).Count)) - (new BigInteger(3))); + } else { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Unrecognized external file "), _2_externalFile), Dafny.Sequence.UnicodeFromString(". External file must be *.rs files"))); + } + RAST._IMod _4_externMod; + _4_externMod = RAST.Mod.create_ExternMod(_3_externalMod); + s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, (_4_externMod)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\n")); + _0_externUseDecls = Dafny.Sequence.Concat(_0_externUseDecls, Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), ((RAST.__default.crate).MSel(_3_externalMod)).MSel(Dafny.Sequence.UnicodeFromString("*")))))); + } + if (!(_0_externUseDecls).Equals(Dafny.Sequence.FromElements())) { + s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, (RAST.Mod.create_Mod(DCOMP.COMP.DAFNY__EXTERN__MODULE, _0_externUseDecls))._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\n")); + } + DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _5_allModules; + _5_allModules = DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Empty(); + BigInteger _hi1 = new BigInteger((p).Count); + for (BigInteger _6_i = BigInteger.Zero; _6_i < _hi1; _6_i++) { + DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _7_m; + DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _out0; + _out0 = (this).GenModule((p).Select(_6_i), Dafny.Sequence>.FromElements()); + _7_m = _out0; + _5_allModules = DafnyCompilerRustUtils.GatheringModule.MergeSeqMap(_5_allModules, _7_m); + } + BigInteger _hi2 = new BigInteger(((_5_allModules).dtor_keys).Count); + for (BigInteger _8_i = BigInteger.Zero; _8_i < _hi2; _8_i++) { + if (!((_5_allModules).dtor_values).Contains(((_5_allModules).dtor_keys).Select(_8_i))) { + goto continue_0; + } + RAST._IMod _9_m; + _9_m = (Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select((_5_allModules).dtor_values,((_5_allModules).dtor_keys).Select(_8_i))).ToRust(); + BigInteger _hi3 = new BigInteger((this.optimizations).Count); + for (BigInteger _10_j = BigInteger.Zero; _10_j < _hi3; _10_j++) { + _9_m = Dafny.Helpers.Id>((this.optimizations).Select(_10_j))(_9_m); + } + s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("\n")); + s = Dafny.Sequence.Concat(s, (_9_m)._ToString(Dafny.Sequence.UnicodeFromString(""))); + continue_0: ; } + after_0: ; return s; } public static Dafny.ISequence EmitCallToMain(Dafny.ISequence> fullName) @@ -7210,10 +7725,10 @@ public Dafny.ISequence array__construct { get { } } } public RAST._IExpr modify__macro { get { - return (RAST.__default.dafny__runtime).MSel(((((this).ObjectType).is_RawPointers) ? (Dafny.Sequence.UnicodeFromString("modify!")) : (Dafny.Sequence.UnicodeFromString("md!")))); + return ((RAST.__default.dafny__runtime).MSel(((((this).ObjectType).is_RawPointers) ? (Dafny.Sequence.UnicodeFromString("modify!")) : (Dafny.Sequence.UnicodeFromString("md!"))))).AsExpr(); } } public RAST._IExpr read__macro { get { - return (RAST.__default.dafny__runtime).MSel(((((this).ObjectType).is_RawPointers) ? (Dafny.Sequence.UnicodeFromString("read!")) : (Dafny.Sequence.UnicodeFromString("rd!")))); + return ((RAST.__default.dafny__runtime).MSel(((((this).ObjectType).is_RawPointers) ? (Dafny.Sequence.UnicodeFromString("read!")) : (Dafny.Sequence.UnicodeFromString("rd!"))))).AsExpr(); } } public Dafny.ISequence placebos__usize { get { if (((this).ObjectType).is_RawPointers) { @@ -7256,5 +7771,8 @@ public Dafny.ISequence downcast { get { public static Dafny.IMap> OpTable { get { return Dafny.Map>.FromElements(new Dafny.Pair>(DAST.BinOp.create_Mod(), Dafny.Sequence.UnicodeFromString("%")), new Dafny.Pair>(DAST.BinOp.create_And(), Dafny.Sequence.UnicodeFromString("&&")), new Dafny.Pair>(DAST.BinOp.create_Or(), Dafny.Sequence.UnicodeFromString("||")), new Dafny.Pair>(DAST.BinOp.create_Div(), 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("<<"))); } } + public static Dafny.ISequence DAFNY__EXTERN__MODULE { get { + return Dafny.Sequence.UnicodeFromString("_dafny_externs"); + } } } } // end of namespace DCOMP \ No newline at end of file diff --git a/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs b/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs new file mode 100644 index 00000000000..ad371150899 --- /dev/null +++ b/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs @@ -0,0 +1,328 @@ +// 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 DafnyCompilerRustUtils { + + public partial class __default { + public static _System._ITuple2>, Dafny.ISequence> DafnyNameToContainingPathAndName(Dafny.ISequence n, Dafny.ISequence> acc) + { + TAIL_CALL_START: ; + Dafny.ISequence _0_s = (n); + if ((new BigInteger((_0_s).Count)).Sign == 0) { + if ((new BigInteger((acc).Count)).Sign == 0) { + return _System.Tuple2>, Dafny.ISequence>.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("")); + } else { + return _System.Tuple2>, Dafny.ISequence>.create((acc).Subsequence(BigInteger.Zero, (new BigInteger((acc).Count)) - (BigInteger.One)), ((acc).Select((new BigInteger((acc).Count)) - (BigInteger.One)))); + } + } else if (((_0_s).Select(BigInteger.Zero)) != (new Dafny.Rune('.'))) { + if ((new BigInteger((acc).Count)).Sign == 0) { + Dafny.ISequence _in0 = (_0_s).Drop(BigInteger.One); + Dafny.ISequence> _in1 = Dafny.Sequence>.FromElements((_0_s).Subsequence(BigInteger.Zero, BigInteger.One)); + n = _in0; + acc = _in1; + goto TAIL_CALL_START; + } else { + Dafny.ISequence _in2 = (_0_s).Drop(BigInteger.One); + Dafny.ISequence> _in3 = Dafny.Sequence>.Concat((acc).Subsequence(BigInteger.Zero, (new BigInteger((acc).Count)) - (BigInteger.One)), Dafny.Sequence>.FromElements(Dafny.Sequence.Concat((((acc).Select((new BigInteger((acc).Count)) - (BigInteger.One)))), Dafny.Sequence.FromElements((_0_s).Select(BigInteger.Zero))))); + n = _in2; + acc = _in3; + goto TAIL_CALL_START; + } + } else if ((new BigInteger((acc).Count)).Sign == 0) { + Dafny.ISequence _in4 = (_0_s).Drop(BigInteger.One); + Dafny.ISequence> _in5 = Dafny.Sequence>.FromElements(); + n = _in4; + acc = _in5; + goto TAIL_CALL_START; + } else { + Dafny.ISequence _in6 = (_0_s).Drop(BigInteger.One); + Dafny.ISequence> _in7 = Dafny.Sequence>.Concat(acc, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString(""))); + n = _in6; + acc = _in7; + goto TAIL_CALL_START; + } + } + } + + public partial class ModWithBody { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.Mod.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static bool _Is(RAST._IMod __source) { + RAST._IMod _1_x = __source; + return (_1_x).is_Mod; + } + } + + public partial class ExternMod { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.Mod.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static bool _Is(RAST._IMod __source) { + RAST._IMod _2_x = __source; + return (_2_x).is_ExternMod; + } + } + + public interface _ISeqMap { + bool is_SeqMap { get; } + Dafny.ISequence dtor_keys { get; } + Dafny.IMap dtor_values { get; } + _ISeqMap<__K, __V> DowncastClone<__K, __V>(Func converter0, Func converter1); + } + public class SeqMap : _ISeqMap { + public readonly Dafny.ISequence _keys; + public readonly Dafny.IMap _values; + public SeqMap(Dafny.ISequence keys, Dafny.IMap values) { + this._keys = keys; + this._values = values; + } + public _ISeqMap<__K, __V> DowncastClone<__K, __V>(Func converter0, Func converter1) { + if (this is _ISeqMap<__K, __V> dt) { return dt; } + return new SeqMap<__K, __V>((_keys).DowncastClone<__K>(Dafny.Helpers.CastConverter), (_values).DowncastClone<__K, __V>(Dafny.Helpers.CastConverter, Dafny.Helpers.CastConverter)); + } + public override bool Equals(object other) { + var oth = other as DafnyCompilerRustUtils.SeqMap; + return oth != null && object.Equals(this._keys, oth._keys) && object.Equals(this._values, oth._values); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._keys)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._values)); + return (int) hash; + } + public override string ToString() { + string s = "DafnyCompilerRustUtils.SeqMap.SeqMap"; + s += "("; + s += Dafny.Helpers.ToString(this._keys); + s += ", "; + s += Dafny.Helpers.ToString(this._values); + s += ")"; + return s; + } + public static DafnyCompilerRustUtils._ISeqMap Default() { + return create(Dafny.Sequence.Empty, Dafny.Map.Empty); + } + public static Dafny.TypeDescriptor> _TypeDescriptor() { + return new Dafny.TypeDescriptor>(DafnyCompilerRustUtils.SeqMap.Default()); + } + public static _ISeqMap create(Dafny.ISequence keys, Dafny.IMap values) { + return new SeqMap(keys, values); + } + public static _ISeqMap create_SeqMap(Dafny.ISequence keys, Dafny.IMap values) { + return create(keys, values); + } + public bool is_SeqMap { get { return true; } } + public Dafny.ISequence dtor_keys { + get { + return this._keys; + } + } + public Dafny.IMap dtor_values { + get { + return this._values; + } + } + public static DafnyCompilerRustUtils._ISeqMap Empty() { + return DafnyCompilerRustUtils.SeqMap.create(Dafny.Sequence.FromElements(), Dafny.Map.FromElements()); + } + public static DafnyCompilerRustUtils._ISeqMap Single(K key, V @value) + { + return DafnyCompilerRustUtils.SeqMap.create(Dafny.Sequence.FromElements(key), Dafny.Map.FromElements(new Dafny.Pair(key, @value))); + } + } + + public interface _IGatheringModule { + bool is_GatheringModule { get; } + bool is_ExternMod { get; } + RAST._IMod dtor_existingMod { get; } + DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> dtor_submodules { get; } + RAST._IMod dtor_m { get; } + _IGatheringModule DowncastClone(); + DafnyCompilerRustUtils._IGatheringModule Merge(DafnyCompilerRustUtils._IGatheringModule m2); + RAST._IMod ToRust(); + } + public abstract class GatheringModule : _IGatheringModule { + public GatheringModule() { + } + private static readonly DafnyCompilerRustUtils._IGatheringModule theDefault = create_GatheringModule(RAST.Mod.Default(), DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Default()); + public static DafnyCompilerRustUtils._IGatheringModule Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DafnyCompilerRustUtils.GatheringModule.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IGatheringModule create_GatheringModule(RAST._IMod existingMod, DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> submodules) { + return new GatheringModule_GatheringModule(existingMod, submodules); + } + public static _IGatheringModule create_ExternMod(RAST._IMod m) { + return new GatheringModule_ExternMod(m); + } + public bool is_GatheringModule { get { return this is GatheringModule_GatheringModule; } } + public bool is_ExternMod { get { return this is GatheringModule_ExternMod; } } + public RAST._IMod dtor_existingMod { + get { + var d = this; + return ((GatheringModule_GatheringModule)d)._existingMod; + } + } + public DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> dtor_submodules { + get { + var d = this; + return ((GatheringModule_GatheringModule)d)._submodules; + } + } + public RAST._IMod dtor_m { + get { + var d = this; + return ((GatheringModule_ExternMod)d)._m; + } + } + public abstract _IGatheringModule DowncastClone(); + public static DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> MergeSeqMap(DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> m1, DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> m2) + { + return DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.create(Dafny.Sequence>.Concat((m1).dtor_keys, Std.Collections.Seq.__default.Filter>(Dafny.Helpers.Id, DafnyCompilerRustUtils._IGatheringModule>, Func, bool>>>((_0_m1) => ((System.Func, bool>)((_1_k) => { + return !((_0_m1).dtor_keys).Contains(_1_k); +})))(m1), (m2).dtor_keys)), Dafny.Helpers.Id, DafnyCompilerRustUtils._IGatheringModule>, DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule>, Dafny.IMap,DafnyCompilerRustUtils._IGatheringModule>>>((_2_m1, _3_m2) => ((System.Func,DafnyCompilerRustUtils._IGatheringModule>>)(() => { + var _coll0 = new System.Collections.Generic.List,DafnyCompilerRustUtils._IGatheringModule>>(); + foreach (Dafny.ISequence _compr_0 in (Dafny.Set>.Union(((_2_m1).dtor_values).Keys, ((_3_m2).dtor_values).Keys)).Elements) { + Dafny.ISequence _4_k = (Dafny.ISequence)_compr_0; + if ((Dafny.Set>.Union(((_2_m1).dtor_values).Keys, ((_3_m2).dtor_values).Keys)).Contains(_4_k)) { + _coll0.Add(new Dafny.Pair,DafnyCompilerRustUtils._IGatheringModule>(_4_k, ((((_2_m1).dtor_values).Contains(_4_k)) ? (((((_3_m2).dtor_values).Contains(_4_k)) ? ((Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select((_2_m1).dtor_values,_4_k)).Merge(Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select((_3_m2).dtor_values,_4_k))) : (Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select((_2_m1).dtor_values,_4_k)))) : (Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select((_3_m2).dtor_values,_4_k))))); + } + } + return Dafny.Map,DafnyCompilerRustUtils._IGatheringModule>.FromCollection(_coll0); +}))())(m1, m2)); + } + public static DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> MergeSeqMapAll(DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> m1, Dafny.ISequence, DafnyCompilerRustUtils._IGatheringModule>> m2s) + { + TAIL_CALL_START: ; + if ((new BigInteger((m2s).Count)).Sign == 0) { + return m1; + } else { + DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _in0 = DafnyCompilerRustUtils.GatheringModule.MergeSeqMap(m1, (m2s).Select(BigInteger.Zero)); + Dafny.ISequence, DafnyCompilerRustUtils._IGatheringModule>> _in1 = (m2s).Drop(BigInteger.One); + m1 = _in0; + m2s = _in1; + goto TAIL_CALL_START; + } + } + public DafnyCompilerRustUtils._IGatheringModule Merge(DafnyCompilerRustUtils._IGatheringModule m2) { + if (!((this).is_GatheringModule)) { + return m2; + } else if (!((m2).is_GatheringModule)) { + return this; + } else { + return DafnyCompilerRustUtils.GatheringModule.create_GatheringModule(RAST.Mod.create_Mod(((this).dtor_existingMod).dtor_name, Dafny.Sequence.Concat(((this).dtor_existingMod).dtor_body, ((m2).dtor_existingMod).dtor_body)), DafnyCompilerRustUtils.GatheringModule.MergeSeqMap((this).dtor_submodules, (m2).dtor_submodules)); + } + } + public static DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> Wrap(Dafny.ISequence> containingPath, RAST._IMod rawDecl) + { + if ((new BigInteger((containingPath).Count)).Sign == 0) { + Dafny.ISequence _0_name = (rawDecl).dtor_name; + if ((rawDecl).is_Mod) { + return DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Single(_0_name, DafnyCompilerRustUtils.GatheringModule.create_GatheringModule(rawDecl, DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Empty())); + } else { + return DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Single(_0_name, DafnyCompilerRustUtils.GatheringModule.create_ExternMod(rawDecl)); + } + } else { + Dafny.ISequence _1_enclosingModule = (containingPath).Select(BigInteger.Zero); + return DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Single(_1_enclosingModule, DafnyCompilerRustUtils.GatheringModule.create_GatheringModule(RAST.Mod.create_Mod(_1_enclosingModule, Dafny.Sequence.FromElements()), DafnyCompilerRustUtils.GatheringModule.Wrap((containingPath).Drop(BigInteger.One), rawDecl))); + } + } + public RAST._IMod ToRust() { + if ((this).is_ExternMod) { + return (this).dtor_m; + } else { + Dafny.ISequence> _0_keysWithContent = Std.Collections.Seq.__default.Filter>(((System.Func, bool>)((_1_key) => { + return (((this).dtor_submodules).dtor_values).Contains(_1_key); + })), ((this).dtor_submodules).dtor_keys); + RAST._IMod _2_dt__update__tmp_h0 = (this).dtor_existingMod; + Dafny.ISequence _3_dt__update_hbody_h0 = Dafny.Sequence.Concat(((this).dtor_existingMod).dtor_body, ((System.Func>) (() => { + BigInteger dim13 = new BigInteger((_0_keysWithContent).Count); + var arr13 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim13, "array size exceeds memory limit")]; + for (int i13 = 0; i13 < dim13; i13++) { + var _4_i = (BigInteger) i13; + arr13[(int)(_4_i)] = Dafny.Helpers.Let, RAST._IModDecl>((_0_keysWithContent).Select(_4_i), _pat_let18_0 => Dafny.Helpers.Let, RAST._IModDecl>(_pat_let18_0, _5_moduleName => Dafny.Helpers.Let((Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select(((this).dtor_submodules).dtor_values,_5_moduleName)).ToRust(), _pat_let19_0 => Dafny.Helpers.Let(_pat_let19_0, _6_submodule => RAST.ModDecl.create_ModDecl(_6_submodule))))); + } + return Dafny.Sequence.FromArray(arr13); + }))()); + return RAST.Mod.create_Mod((_2_dt__update__tmp_h0).dtor_name, _3_dt__update_hbody_h0); + } + } + } + public class GatheringModule_GatheringModule : GatheringModule { + public readonly RAST._IMod _existingMod; + public readonly DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _submodules; + public GatheringModule_GatheringModule(RAST._IMod existingMod, DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> submodules) : base() { + this._existingMod = existingMod; + this._submodules = submodules; + } + public override _IGatheringModule DowncastClone() { + if (this is _IGatheringModule dt) { return dt; } + return new GatheringModule_GatheringModule(_existingMod, _submodules); + } + public override bool Equals(object other) { + var oth = other as DafnyCompilerRustUtils.GatheringModule_GatheringModule; + return oth != null && object.Equals(this._existingMod, oth._existingMod) && object.Equals(this._submodules, oth._submodules); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._existingMod)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._submodules)); + return (int) hash; + } + public override string ToString() { + string s = "DafnyCompilerRustUtils.GatheringModule.GatheringModule"; + s += "("; + s += Dafny.Helpers.ToString(this._existingMod); + s += ", "; + s += Dafny.Helpers.ToString(this._submodules); + s += ")"; + return s; + } + } + public class GatheringModule_ExternMod : GatheringModule { + public readonly RAST._IMod _m; + public GatheringModule_ExternMod(RAST._IMod m) : base() { + this._m = m; + } + public override _IGatheringModule DowncastClone() { + if (this is _IGatheringModule dt) { return dt; } + return new GatheringModule_ExternMod(_m); + } + public override bool Equals(object other) { + var oth = other as DafnyCompilerRustUtils.GatheringModule_ExternMod; + return oth != null && object.Equals(this._m, oth._m); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._m)); + return (int) hash; + } + public override string ToString() { + string s = "DafnyCompilerRustUtils.GatheringModule.ExternMod"; + s += "("; + s += Dafny.Helpers.ToString(this._m); + s += ")"; + return s; + } + } +} // end of namespace DafnyCompilerRustUtils \ No newline at end of file diff --git a/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs b/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs new file mode 100644 index 00000000000..8948704f25e --- /dev/null +++ b/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs @@ -0,0 +1,443 @@ +// 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 FactorPathsOptimization { + + public partial class __default { + public static RAST._IMod apply(RAST._IMod mod) { + return FactorPathsOptimization.__default.applyPrefix(mod, (RAST.__default.crate).MSel((mod).dtor_name)); + } + public static RAST._IMod applyPrefix(RAST._IMod mod, RAST._IPath SelfPath) + { + if ((mod).is_ExternMod) { + return mod; + } else { + FactorPathsOptimization._IMapping _0_initialMapping = FactorPathsOptimization.Mapping.create(Dafny.Map, Dafny.ISet>.FromElements(), Dafny.Sequence>.FromElements()); + FactorPathsOptimization._IMapping _1_mappings = (mod).Fold(_0_initialMapping, Dafny.Helpers.Id>>((_2_SelfPath) => ((System.Func)((_3_current, _4_modDecl) => { + return FactorPathsOptimization.__default.GatherModMapping(_2_SelfPath, _4_modDecl, _3_current); + })))(SelfPath)); + Dafny.IMap,RAST._IPath> _5_pathsToRemove = (_1_mappings).ToFinalReplacement(); + Dafny.ISequence _6_imports = (_1_mappings).ToUseStatements(_5_pathsToRemove, SelfPath); + Dafny.ISequence _7_rewrittenDeclarations = (mod).Fold>(Dafny.Sequence.FromElements(), Dafny.Helpers.Id,RAST._IPath>, RAST._IMod, Func, RAST._IModDecl, Dafny.ISequence>>>((_8_SelfPath, _9_pathsToRemove, _10_mod) => ((System.Func, RAST._IModDecl, Dafny.ISequence>)((_11_current, _12_modDecl) => { + return Dafny.Sequence.Concat(_11_current, Dafny.Sequence.FromElements(FactorPathsOptimization.__default.ReplaceModDecl(_12_modDecl, _8_SelfPath, _9_pathsToRemove))); + })))(SelfPath, _5_pathsToRemove, mod)); + RAST._IMod _13_dt__update__tmp_h0 = mod; + Dafny.ISequence _14_dt__update_hbody_h0 = Dafny.Sequence.Concat(_6_imports, _7_rewrittenDeclarations); + return RAST.Mod.create_Mod((_13_dt__update__tmp_h0).dtor_name, _14_dt__update_hbody_h0); + } + } + public static __T UniqueElementOf<__T>(Dafny.ISet<__T> s) { + return Dafny.Helpers.Let(0, _let_dummy_9 => { + __T _0_e = default(__T); + foreach (__T _assign_such_that_0 in (s).Elements) { + _0_e = (__T)_assign_such_that_0; + if ((s).Contains(_0_e)) { + goto after__ASSIGN_SUCH_THAT_0; + } + } + throw new System.Exception("assign-such-that search produced no value (line 105)"); + after__ASSIGN_SUCH_THAT_0: ; + return _0_e; + } + ); + } + public static FactorPathsOptimization._IMapping GatherTypeParams(Dafny.ISequence typeParams, FactorPathsOptimization._IMapping current) + { + return RAST.__default.FoldLeft(((System.Func)((_0_current, _1_t) => { + return RAST.__default.FoldLeft(((System.Func)((_2_current, _3_t) => { + return FactorPathsOptimization.__default.GatherTypeMapping(_3_t, _2_current); + })), _0_current, (_1_t).dtor_constraints); + })), current, typeParams); + } + public static FactorPathsOptimization._IMapping GatherFields(RAST._IFields fields, FactorPathsOptimization._IMapping current) + { + RAST._IFields _source0 = fields; + { + if (_source0.is_NamedFields) { + Dafny.ISequence _0_sFields = _source0.dtor_fields; + return RAST.__default.FoldLeft(((System.Func)((_1_current, _2_f) => { + return FactorPathsOptimization.__default.GatherTypeMapping(((_2_f).dtor_formal).dtor_tpe, _1_current); + })), current, _0_sFields); + } + } + { + Dafny.ISequence _3_sFields = _source0.dtor_types; + return RAST.__default.FoldLeft(((System.Func)((_4_current, _5_f) => { + return FactorPathsOptimization.__default.GatherTypeMapping((_5_f).dtor_tpe, _4_current); + })), current, _3_sFields); + } + } + public static FactorPathsOptimization._IMapping GatherModMapping(RAST._IPath prefix, RAST._IModDecl modDecl, FactorPathsOptimization._IMapping current) + { + RAST._IModDecl _source0 = modDecl; + { + if (_source0.is_ModDecl) { + RAST._IMod _0_mod = _source0.dtor_mod; + return (current).Add((_0_mod).dtor_name, prefix); + } + } + { + if (_source0.is_StructDecl) { + RAST._IStruct _1_struct = _source0.dtor_struct; + return FactorPathsOptimization.__default.GatherStructMapping(_1_struct, (current).Add((_1_struct).dtor_name, prefix)); + } + } + { + if (_source0.is_TypeDecl) { + RAST._ITypeSynonym _2_tpe = _source0.dtor_tpe; + return (current).Add((_2_tpe).dtor_name, prefix); + } + } + { + if (_source0.is_ConstDecl) { + RAST._IConstant _3_c = _source0.dtor_c; + return (current).Add((_3_c).dtor_name, prefix); + } + } + { + if (_source0.is_EnumDecl) { + RAST._IEnum _4_enum = _source0.dtor_enum; + return (current).Add((_4_enum).dtor_name, prefix); + } + } + { + if (_source0.is_ImplDecl) { + RAST._IImpl _5_impl = _source0.dtor_impl; + return FactorPathsOptimization.__default.GatherImplMapping(_5_impl, current); + } + } + { + if (_source0.is_TraitDecl) { + RAST._ITrait _6_tr = _source0.dtor_tr; + return current; + } + } + { + if (_source0.is_TopFnDecl) { + RAST._ITopFnDecl _7_fn = _source0.dtor_fn; + return (current).Add(((_7_fn).dtor_fn).dtor_name, prefix); + } + } + { + RAST._IUse _8_use = _source0.dtor_use; + return current; + } + } + public static FactorPathsOptimization._IMapping GatherStructMapping(RAST._IStruct @struct, FactorPathsOptimization._IMapping current) + { + return FactorPathsOptimization.__default.GatherTypeParams((@struct).dtor_typeParams, current); + } + public static FactorPathsOptimization._IMapping GatherTypeMapping(RAST._IType tpe, FactorPathsOptimization._IMapping current) + { + return (tpe).Fold(current, ((System.Func)((_0_current, _1_t) => { + return ((System.Func)(() => { + RAST._IType _source0 = _1_t; + { + if (_source0.is_TypeFromPath) { + RAST._IPath path0 = _source0.dtor_path; + if (path0.is_PMemberSelect) { + RAST._IPath _2_base = path0.dtor_base; + Dafny.ISequence _3_name = path0.dtor_name; + return (_0_current).Add(_3_name, _2_base); + } + } + } + { + return _0_current; + } + }))(); + }))); + } + public static FactorPathsOptimization._IMapping GatherImplMapping(RAST._IImpl impl, FactorPathsOptimization._IMapping current) + { + RAST._IImpl _source0 = impl; + { + if (_source0.is_ImplFor) { + Dafny.ISequence _0_typeParams = _source0.dtor_typeParams; + RAST._IType _1_tpe = _source0.dtor_tpe; + RAST._IType _2_forType = _source0.dtor_forType; + Dafny.ISequence _3_where = _source0.dtor_where; + Dafny.ISequence _4_body = _source0.dtor_body; + FactorPathsOptimization._IMapping _5_current = FactorPathsOptimization.__default.GatherTypeParams(_0_typeParams, current); + FactorPathsOptimization._IMapping _6_current = FactorPathsOptimization.__default.GatherTypeMapping(_1_tpe, _5_current); + return FactorPathsOptimization.__default.GatherTypeMapping(_2_forType, _6_current); + } + } + { + Dafny.ISequence _7_typeParams = _source0.dtor_typeParams; + RAST._IType _8_tpe = _source0.dtor_tpe; + Dafny.ISequence _9_where = _source0.dtor_where; + Dafny.ISequence _10_body = _source0.dtor_body; + return FactorPathsOptimization.__default.GatherTypeMapping(_8_tpe, current); + } + } + public static RAST._IModDecl ReplaceModDecl(RAST._IModDecl modDecl, RAST._IPath SelfPath, Dafny.IMap,RAST._IPath> replacement) + { + RAST._IModDecl _source0 = modDecl; + { + if (_source0.is_ModDecl) { + RAST._IMod _0_mod = _source0.dtor_mod; + return RAST.ModDecl.create_ModDecl(FactorPathsOptimization.__default.applyPrefix(_0_mod, (SelfPath).MSel((_0_mod).dtor_name))); + } + } + { + if (_source0.is_StructDecl) { + RAST._IStruct _1_struct = _source0.dtor_struct; + return RAST.ModDecl.create_StructDecl(FactorPathsOptimization.__default.ReplaceStruct(_1_struct, replacement)); + } + } + { + if (_source0.is_TypeDecl) { + RAST._ITypeSynonym _2_tpe = _source0.dtor_tpe; + return modDecl; + } + } + { + if (_source0.is_ConstDecl) { + RAST._IConstant _3_c = _source0.dtor_c; + return modDecl; + } + } + { + if (_source0.is_EnumDecl) { + RAST._IEnum _4_enum = _source0.dtor_enum; + return modDecl; + } + } + { + if (_source0.is_ImplDecl) { + RAST._IImpl _5_impl = _source0.dtor_impl; + return RAST.ModDecl.create_ImplDecl(FactorPathsOptimization.__default.ReplaceImplDecl(_5_impl, replacement)); + } + } + { + if (_source0.is_TraitDecl) { + RAST._ITrait _6_tr = _source0.dtor_tr; + return modDecl; + } + } + { + if (_source0.is_TopFnDecl) { + RAST._ITopFnDecl _7_fn = _source0.dtor_fn; + return modDecl; + } + } + { + RAST._IUse _8_use = _source0.dtor_use; + return modDecl; + } + } + public static RAST._IType ReplaceType(RAST._IType t, Dafny.IMap,RAST._IPath> replacement) + { + RAST._IType _source0 = t; + { + if (_source0.is_TypeFromPath) { + RAST._IPath path0 = _source0.dtor_path; + if (path0.is_PMemberSelect) { + RAST._IPath _0_base = path0.dtor_base; + Dafny.ISequence _1_id = path0.dtor_name; + if (((replacement).Contains(_1_id)) && (object.Equals(Dafny.Map, RAST._IPath>.Select(replacement,_1_id), _0_base))) { + return RAST.Type.create_TSynonym(RAST.Type.create_TIdentifier(_1_id), t); + } else { + return t; + } + } + } + } + { + return t; + } + } + public static Dafny.ISequence ReplaceTypeParams(Dafny.ISequence typeParams, Dafny.IMap,RAST._IPath> replacement) + { + return Std.Collections.Seq.__default.Map(Dafny.Helpers.Id,RAST._IPath>, Func>>((_0_replacement) => ((System.Func)((_1_t) => { + return Dafny.Helpers.Let(_1_t, _pat_let10_0 => Dafny.Helpers.Let(_pat_let10_0, _2_dt__update__tmp_h0 => Dafny.Helpers.Let, RAST._ITypeParamDecl>(Std.Collections.Seq.__default.Map(Dafny.Helpers.Id,RAST._IPath>, Func>>((_3_replacement) => ((System.Func)((_4_constraint) => { + return FactorPathsOptimization.__default.ReplaceType(_4_constraint, _3_replacement); + })))(_0_replacement), (_1_t).dtor_constraints), _pat_let11_0 => Dafny.Helpers.Let, RAST._ITypeParamDecl>(_pat_let11_0, _5_dt__update_hconstraints_h0 => RAST.TypeParamDecl.create((_2_dt__update__tmp_h0).dtor_name, _5_dt__update_hconstraints_h0))))); + })))(replacement), typeParams); + } + public static RAST._IImpl ReplaceImplDecl(RAST._IImpl impl, Dafny.IMap,RAST._IPath> replacement) + { + RAST._IImpl _source0 = impl; + { + if (_source0.is_ImplFor) { + Dafny.ISequence _0_typeParams = _source0.dtor_typeParams; + RAST._IType _1_tpe = _source0.dtor_tpe; + RAST._IType _2_forType = _source0.dtor_forType; + Dafny.ISequence _3_where = _source0.dtor_where; + Dafny.ISequence _4_body = _source0.dtor_body; + return RAST.Impl.create_ImplFor(FactorPathsOptimization.__default.ReplaceTypeParams(_0_typeParams, replacement), (_1_tpe).Replace(Dafny.Helpers.Id,RAST._IPath>, Func>>(FactorPathsOptimization.__default.typeReplacer)(replacement)), (_2_forType).Replace(Dafny.Helpers.Id,RAST._IPath>, Func>>(FactorPathsOptimization.__default.typeReplacer)(replacement)), _3_where, _4_body); + } + } + { + Dafny.ISequence _5_typeParams = _source0.dtor_typeParams; + RAST._IType _6_tpe = _source0.dtor_tpe; + Dafny.ISequence _7_where = _source0.dtor_where; + Dafny.ISequence _8_body = _source0.dtor_body; + return RAST.Impl.create_Impl(FactorPathsOptimization.__default.ReplaceTypeParams(_5_typeParams, replacement), (_6_tpe).Replace(Dafny.Helpers.Id,RAST._IPath>, Func>>(FactorPathsOptimization.__default.typeReplacer)(replacement)), _7_where, _8_body); + } + } + public static RAST._IStruct ReplaceStruct(RAST._IStruct @struct, Dafny.IMap,RAST._IPath> replacement) + { + RAST._IStruct _source0 = @struct; + { + Dafny.ISequence> _0_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_name = _source0.dtor_name; + Dafny.ISequence _2_typeParams = _source0.dtor_typeParams; + RAST._IFields _3_fields = _source0.dtor_fields; + return RAST.Struct.create(_0_attributes, _1_name, FactorPathsOptimization.__default.ReplaceTypeParams(_2_typeParams, replacement), FactorPathsOptimization.__default.ReplaceFields(_3_fields, replacement)); + } + } + public static RAST._IFields ReplaceFields(RAST._IFields fields, Dafny.IMap,RAST._IPath> replacement) + { + RAST._IFields _source0 = fields; + { + if (_source0.is_NamedFields) { + Dafny.ISequence _0_sFields = _source0.dtor_fields; + return RAST.Fields.create_NamedFields(Std.Collections.Seq.__default.Map(Dafny.Helpers.Id,RAST._IPath>, Func>>((_1_replacement) => ((System.Func)((_2_f) => { + return Dafny.Helpers.Let(_2_f, _pat_let12_0 => Dafny.Helpers.Let(_pat_let12_0, _3_dt__update__tmp_h0 => Dafny.Helpers.Let(Dafny.Helpers.Let((_2_f).dtor_formal, _pat_let14_0 => Dafny.Helpers.Let(_pat_let14_0, _4_dt__update__tmp_h1 => Dafny.Helpers.Let(FactorPathsOptimization.__default.ReplaceType(((_2_f).dtor_formal).dtor_tpe, _1_replacement), _pat_let15_0 => Dafny.Helpers.Let(_pat_let15_0, _5_dt__update_htpe_h0 => RAST.Formal.create((_4_dt__update__tmp_h1).dtor_name, _5_dt__update_htpe_h0))))), _pat_let13_0 => Dafny.Helpers.Let(_pat_let13_0, _6_dt__update_hformal_h0 => RAST.Field.create((_3_dt__update__tmp_h0).dtor_visibility, _6_dt__update_hformal_h0))))); +})))(replacement), _0_sFields)); + } + } + { + Dafny.ISequence _7_sFields = _source0.dtor_types; + return RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(Dafny.Helpers.Id,RAST._IPath>, Func>>((_8_replacement) => ((System.Func)((_9_f) => { + return Dafny.Helpers.Let(_9_f, _pat_let16_0 => Dafny.Helpers.Let(_pat_let16_0, _10_dt__update__tmp_h2 => Dafny.Helpers.Let(FactorPathsOptimization.__default.ReplaceType((_9_f).dtor_tpe, _8_replacement), _pat_let17_0 => Dafny.Helpers.Let(_pat_let17_0, _11_dt__update_htpe_h1 => RAST.NamelessField.create((_10_dt__update__tmp_h2).dtor_visibility, _11_dt__update_htpe_h1))))); +})))(replacement), _7_sFields)); + } + } + public static Func,RAST._IPath>, Func> typeReplacer { get { + return ((System.Func,RAST._IPath>, Func>)((_0_replacement) => { + return Dafny.Helpers.Id,RAST._IPath>, Func>>((_1_replacement) => ((System.Func)((_2_t) => { + return FactorPathsOptimization.__default.ReplaceType(_2_t, _1_replacement); + })))(_0_replacement); + })); + } } + } + + public interface _IMapping { + bool is_Mapping { get; } + Dafny.IMap,Dafny.ISet> dtor_provenance { get; } + Dafny.ISequence> dtor_keys { get; } + _IMapping DowncastClone(); + FactorPathsOptimization._IMapping Add(Dafny.ISequence k, RAST._IPath path); + Dafny.IMap,RAST._IPath> ToFinalReplacement(); + Dafny.ISequence ToUseStatements(Dafny.IMap,RAST._IPath> finalReplacement, RAST._IPath SelfPath); + } + public class Mapping : _IMapping { + public readonly Dafny.IMap,Dafny.ISet> _provenance; + public readonly Dafny.ISequence> _keys; + public Mapping(Dafny.IMap,Dafny.ISet> provenance, Dafny.ISequence> keys) { + this._provenance = provenance; + this._keys = keys; + } + public _IMapping DowncastClone() { + if (this is _IMapping dt) { return dt; } + return new Mapping(_provenance, _keys); + } + public override bool Equals(object other) { + var oth = other as FactorPathsOptimization.Mapping; + return oth != null && object.Equals(this._provenance, oth._provenance) && object.Equals(this._keys, oth._keys); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._provenance)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._keys)); + return (int) hash; + } + public override string ToString() { + string s = "FactorPathsOptimization.Mapping.Mapping"; + s += "("; + s += Dafny.Helpers.ToString(this._provenance); + s += ", "; + s += Dafny.Helpers.ToString(this._keys); + s += ")"; + return s; + } + private static readonly FactorPathsOptimization._IMapping theDefault = create(Dafny.Map, Dafny.ISet>.Empty, Dafny.Sequence>.Empty); + public static FactorPathsOptimization._IMapping Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(FactorPathsOptimization.Mapping.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IMapping create(Dafny.IMap,Dafny.ISet> provenance, Dafny.ISequence> keys) { + return new Mapping(provenance, keys); + } + public static _IMapping create_Mapping(Dafny.IMap,Dafny.ISet> provenance, Dafny.ISequence> keys) { + return create(provenance, keys); + } + public bool is_Mapping { get { return true; } } + public Dafny.IMap,Dafny.ISet> dtor_provenance { + get { + return this._provenance; + } + } + public Dafny.ISequence> dtor_keys { + get { + return this._keys; + } + } + public FactorPathsOptimization._IMapping Add(Dafny.ISequence k, RAST._IPath path) + { + if (((this).dtor_provenance).Contains(k)) { + FactorPathsOptimization._IMapping _0_dt__update__tmp_h0 = this; + Dafny.IMap,Dafny.ISet> _1_dt__update_hprovenance_h0 = Dafny.Map, Dafny.ISet>.Update((this).dtor_provenance, k, Dafny.Set.Union(Dafny.Map, Dafny.ISet>.Select((this).dtor_provenance,k), Dafny.Set.FromElements(path))); + return FactorPathsOptimization.Mapping.create(_1_dt__update_hprovenance_h0, (_0_dt__update__tmp_h0).dtor_keys); + } else { + FactorPathsOptimization._IMapping _2_dt__update__tmp_h1 = this; + Dafny.ISequence> _3_dt__update_hkeys_h0 = Dafny.Sequence>.Concat((this).dtor_keys, Dafny.Sequence>.FromElements(k)); + Dafny.IMap,Dafny.ISet> _4_dt__update_hprovenance_h1 = Dafny.Map, Dafny.ISet>.Update((this).dtor_provenance, k, Dafny.Set.FromElements(path)); + return FactorPathsOptimization.Mapping.create(_4_dt__update_hprovenance_h1, _3_dt__update_hkeys_h0); + } + } + public Dafny.IMap,RAST._IPath> ToFinalReplacement() { + return ((System.Func,RAST._IPath>>)(() => { + var _coll0 = new System.Collections.Generic.List,RAST._IPath>>(); + foreach (Dafny.ISequence _compr_0 in ((this).dtor_provenance).Keys.Elements) { + Dafny.ISequence _0_identifier = (Dafny.ISequence)_compr_0; + if (((this).dtor_provenance).Contains(_0_identifier)) { + foreach (Dafny.ISet _compr_1 in Dafny.Helpers.SingleValue>(Dafny.Map, Dafny.ISet>.Select((this).dtor_provenance,_0_identifier))) { + Dafny.ISet _1_paths = (Dafny.ISet)_compr_1; + if (((_1_paths).Equals(Dafny.Map, Dafny.ISet>.Select((this).dtor_provenance,_0_identifier))) && (((new BigInteger((_1_paths).Count)) == (BigInteger.One)) || (Dafny.Helpers.Id, bool>>((_2_paths) => Dafny.Helpers.Quantifier(Dafny.Helpers.SingleValue(RAST.__default.dafny__runtime), false, (((_exists_var_0) => { + RAST._IPath _3_p = (RAST._IPath)_exists_var_0; + return ((_2_paths).Contains(_3_p)) && (object.Equals(_3_p, RAST.__default.dafny__runtime)); + }))))(_1_paths)))) { + _coll0.Add(new Dafny.Pair,RAST._IPath>(_0_identifier, (((new BigInteger((_1_paths).Count)) == (BigInteger.One)) ? (FactorPathsOptimization.__default.UniqueElementOf(_1_paths)) : (RAST.__default.dafny__runtime)))); + } + } + } + } + return Dafny.Map,RAST._IPath>.FromCollection(_coll0); + }))(); + } + public Dafny.ISequence ToUseStatements(Dafny.IMap,RAST._IPath> finalReplacement, RAST._IPath SelfPath) + { + Dafny.ISequence> _0_toUse = Std.Collections.Seq.__default.Filter>(Dafny.Helpers.Id,RAST._IPath>, RAST._IPath, Func, bool>>>((_1_finalReplacement, _2_SelfPath) => ((System.Func, bool>)((_3_key) => { + return ((_1_finalReplacement).Contains(_3_key)) && (!object.Equals(Dafny.Map, RAST._IPath>.Select(_1_finalReplacement,_3_key), _2_SelfPath)); + })))(finalReplacement, SelfPath), (this).dtor_keys); + return ((System.Func>) (() => { + BigInteger dim12 = new BigInteger((_0_toUse).Count); + var arr12 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim12, "array size exceeds memory limit")]; + for (int i12 = 0; i12 < dim12; i12++) { + var _4_i = (BigInteger) i12; + arr12[(int)(_4_i)] = RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (Dafny.Map, RAST._IPath>.Select(finalReplacement,(_0_toUse).Select(_4_i))).MSel((_0_toUse).Select(_4_i)))); + } + return Dafny.Sequence.FromArray(arr12); + }))(); + } + } +} // end of namespace FactorPathsOptimization \ No newline at end of file diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index f1dc6a1bd2f..fda5a4701fb 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -15,6 +15,21 @@ namespace RAST { public partial class __default { + public static __A FoldLeft<__A, __T>(Func<__A, __T, __A> f, __A init, Dafny.ISequence<__T> xs) + { + TAIL_CALL_START: ; + if ((new BigInteger((xs).Count)).Sign == 0) { + return init; + } else { + Func<__A, __T, __A> _in0 = f; + __A _in1 = Dafny.Helpers.Id>(f)(init, (xs).Select(BigInteger.Zero)); + Dafny.ISequence<__T> _in2 = (xs).Drop(BigInteger.One); + f = _in0; + init = _in1; + xs = _in2; + goto TAIL_CALL_START; + } + } public static Dafny.ISequence SeqToString<__T>(Dafny.ISequence<__T> s, Func<__T, Dafny.ISequence> f, Dafny.ISequence separator) { if ((new BigInteger((s).Count)).Sign == 0) { @@ -24,16 +39,19 @@ public partial class __default { } } public static RAST._IType ObjectType(RAST._IType underlying) { - return ((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Object"))).Apply(Dafny.Sequence.FromElements(underlying)); + return ((RAST.__default.ObjectPath).AsType()).Apply(Dafny.Sequence.FromElements(underlying)); + } + public static RAST._IType PtrType(RAST._IType underlying) { + return ((RAST.__default.PtrPath).AsType()).Apply(Dafny.Sequence.FromElements(underlying)); } public static RAST._IType Rc(RAST._IType underlying) { return RAST.Type.create_TypeApp(RAST.__default.RcType, Dafny.Sequence.FromElements(underlying)); } public static RAST._IType RefCell(RAST._IType underlying) { - return RAST.Type.create_TypeApp(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("cell"))).MSel(Dafny.Sequence.UnicodeFromString("RefCell")), Dafny.Sequence.FromElements(underlying)); + return RAST.Type.create_TypeApp(RAST.__default.RefcellType, Dafny.Sequence.FromElements(underlying)); } public static RAST._IType Vec(RAST._IType underlying) { - return RAST.Type.create_TypeApp(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("vec"))).MSel(Dafny.Sequence.UnicodeFromString("Vec")), Dafny.Sequence.FromElements(underlying)); + return RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("vec"))).MSel(Dafny.Sequence.UnicodeFromString("Vec"))).AsType(), Dafny.Sequence.FromElements(underlying)); } public static RAST._IExpr NewVec(Dafny.ISequence elements) { return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("vec!"))).Apply(elements); @@ -51,14 +69,14 @@ public static RAST._IType Box(RAST._IType content) { return RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Box")), Dafny.Sequence.FromElements(content)); } public static RAST._IExpr BoxNew(RAST._IExpr content) { - return ((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Box"))).MSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements(content)); + return ((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Box"))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements(content)); } public static RAST._IType SystemTupleType(Dafny.ISequence elements) { - return (((RAST.__default.super__type).MSel(Dafny.Sequence.UnicodeFromString("_System"))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Tuple"), Std.Strings.__default.OfNat(new BigInteger((elements).Count))))).Apply(elements); + return ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("_System"))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Tuple"), Std.Strings.__default.OfNat(new BigInteger((elements).Count))))).AsType()).Apply(elements); } public static RAST._IExpr SystemTuple(Dafny.ISequence elements) { Dafny.ISequence _0_size = Std.Strings.__default.OfNat(new BigInteger((elements).Count)); - return RAST.Expr.create_StructBuild((((RAST.__default.super).MSel(Dafny.Sequence.UnicodeFromString("_System"))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Tuple"), _0_size))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), _0_size)), ((System.Func>) (() => { + return RAST.Expr.create_StructBuild(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("_System"))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Tuple"), _0_size))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), _0_size))).AsExpr(), ((System.Func>) (() => { BigInteger dim10 = new BigInteger((elements).Count); var arr10 = new RAST._IAssignIdentifier[Dafny.Helpers.ToIntChecked(dim10, "array size exceeds memory limit")]; for (int i10 = 0; i10 < dim10; i10++) { @@ -69,19 +87,19 @@ public static RAST._IExpr SystemTuple(Dafny.ISequence elements) { }))()); } public static RAST._IType MaybeUninitType(RAST._IType underlying) { - return (RAST.__default.MaybeUninitPath).Apply(Dafny.Sequence.FromElements(underlying)); + return (RAST.__default.MaybeUninitPathType).Apply(Dafny.Sequence.FromElements(underlying)); } public static bool IsMaybeUninitType(RAST._IType tpe) { - return (((tpe).is_TypeApp) && (object.Equals((tpe).dtor_baseName, RAST.__default.MaybeUninitPath))) && ((new BigInteger(((tpe).dtor_arguments).Count)) == (BigInteger.One)); + return (((tpe).is_TypeApp) && (object.Equals((tpe).dtor_baseName, RAST.__default.MaybeUninitPathType))) && ((new BigInteger(((tpe).dtor_arguments).Count)) == (BigInteger.One)); } public static RAST._IType MaybeUninitTypeUnderlying(RAST._IType tpe) { return ((tpe).dtor_arguments).Select(BigInteger.Zero); } public static RAST._IExpr MaybeUninitNew(RAST._IExpr underlying) { - return ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("MaybeUninit"))).MSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements(underlying)); + return ((RAST.__default.MaybeUninitPath).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements(underlying)); } public static RAST._IType MaybePlaceboType(RAST._IType underlying) { - return ((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("MaybePlacebo"))).Apply1(underlying); + return ((RAST.__default.MaybePlaceboPath).AsType()).Apply1(underlying); } public static Dafny.ISequence AddIndent(Dafny.ISequence raw, Dafny.ISequence ind) { @@ -136,85 +154,100 @@ public static RAST._IExpr AssignMember(RAST._IExpr @on, Dafny.ISequence.create_Some(RAST.AssignLhs.create_SelectMember(@on, field)), rhs); } public static RAST._IExpr MaybePlacebo(RAST._IExpr underlying) { - return (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MaybePlacebo"))).MSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(underlying); + return ((RAST.__default.MaybePlaceboPath).FSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(underlying); } public static RAST._IExpr RcNew(RAST._IExpr underlying) { return RAST.Expr.create_Call(RAST.__default.std__rc__Rc__new, Dafny.Sequence.FromElements(underlying)); } public static RAST._IExpr IntoUsize(RAST._IExpr underlying) { - return (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyUsize"))).MSel(Dafny.Sequence.UnicodeFromString("into_usize"))).Apply1(underlying); + return (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyUsize"))).FSel(Dafny.Sequence.UnicodeFromString("into_usize"))).Apply1(underlying); } + public static RAST._IType SelfOwned { get { + return (RAST.Path.create_Self()).AsType(); + } } public static RAST._IType SelfBorrowed { get { - return RAST.Type.create_Borrowed(RAST.Type.create_SelfOwned()); + return RAST.Type.create_Borrowed(RAST.__default.SelfOwned); } } public static RAST._IType SelfBorrowedMut { get { - return RAST.Type.create_BorrowedMut(RAST.Type.create_SelfOwned()); - } } - public static RAST._IType SelfPointer { get { - return RAST.Type.create_Pointer(RAST.Type.create_SelfOwned()); + return RAST.Type.create_BorrowedMut(RAST.__default.SelfOwned); } } - public static RAST._IType SelfPointerMut { get { - return RAST.Type.create_PointerMut(RAST.Type.create_SelfOwned()); + public static RAST._IPath @global { get { + return RAST.Path.create_Global(); } } - public static RAST._IType global__type { get { - return RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("")); + public static RAST._IPath std { get { + return (RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("std")); } } - public static RAST._IType std__type { get { - return (RAST.__default.global__type).MSel(Dafny.Sequence.UnicodeFromString("std")); + public static RAST._IPath RcPath { get { + return ((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("rc"))).MSel(Dafny.Sequence.UnicodeFromString("Rc")); } } public static RAST._IType RcType { get { - return ((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("rc"))).MSel(Dafny.Sequence.UnicodeFromString("Rc")); + return (RAST.__default.RcPath).AsType(); + } } + public static RAST._IPath dafny__runtime { get { + return (RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("dafny_runtime")); } } - public static RAST._IType dafny__runtime__type { get { - return (RAST.__default.global__type).MSel(Dafny.Sequence.UnicodeFromString("dafny_runtime")); + public static RAST._IPath ObjectPath { get { + return (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object")); } } - public static RAST._IType super__type { get { - return RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("super")); + public static RAST._IExpr Object { get { + return (RAST.__default.ObjectPath).AsExpr(); } } - public static RAST._IType cell__type { get { - return (RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("cell")); + public static RAST._IPath PtrPath { get { + return (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Ptr")); } } - public static RAST._IType refcell__type { get { - return (RAST.__default.cell__type).MSel(Dafny.Sequence.UnicodeFromString("RefCell")); + public static RAST._IExpr Ptr { get { + return (RAST.__default.PtrPath).AsExpr(); + } } + public static RAST._IPath cell { get { + return (RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cell")); + } } + public static RAST._IType RefcellType { get { + return ((RAST.__default.cell).MSel(Dafny.Sequence.UnicodeFromString("RefCell"))).AsType(); } } public static RAST._IType CloneTrait { get { - return RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("Clone")); + return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(); + } } + public static RAST._IPath DefaultPath { get { + return ((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default")); } } public static RAST._IType DefaultTrait { get { - return ((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default")); + return (RAST.__default.DefaultPath).AsType(); + } } + public static RAST._IType AnyTrait { get { + return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType(); } } public static RAST._IType StaticTrait { get { return RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("'static")); } } public static RAST._IType DafnyType { get { - return (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")); + return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType"))).AsType(); } } public static RAST._IType DafnyPrint { get { - return (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint")); + return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsType(); } } public static RAST._IType DafnyTypeEq { get { - return (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyTypeEq")); + return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyTypeEq"))).AsType(); } } public static RAST._IType Eq { get { - return RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Eq")); + return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(); } } public static RAST._IType Hash { get { - return ((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash")); + return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).AsType(); } } public static RAST._IType DafnyInt { get { - return (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt")); + return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt"))).AsType(); } } - public static RAST._IExpr super { get { - return RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("super")); + public static RAST._IPath MaybeUninitPath { get { + return ((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("MaybeUninit")); } } - public static RAST._IType MaybeUninitPath { get { - return ((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("MaybeUninit")); + public static RAST._IType MaybeUninitPathType { get { + return (RAST.__default.MaybeUninitPath).AsType(); } } - public static RAST._IExpr @global { get { - return RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")); + public static RAST._IExpr MaybeUninitExpr { get { + return (RAST.__default.MaybeUninitPath).AsExpr(); } } - public static RAST._IExpr std { get { - return (RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("std")); + public static RAST._IPath MaybePlaceboPath { get { + return (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MaybePlacebo")); } } public static Dafny.ISequence IND { get { return Dafny.Sequence.UnicodeFromString(" "); @@ -222,41 +255,41 @@ public static Dafny.ISequence IND { get { public static RAST._IExpr self { get { return RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self")); } } - public static RAST._IExpr dafny__runtime { get { - return (RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("dafny_runtime")); + public static RAST._IPath crate { get { + return RAST.Path.create_Crate(); } } public static RAST._IExpr dafny__runtime__Set { get { - return (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Set")); + return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Set"))).AsExpr(); } } public static RAST._IExpr dafny__runtime__Set__from__array { get { - return (RAST.__default.dafny__runtime__Set).MSel(Dafny.Sequence.UnicodeFromString("from_array")); + return (RAST.__default.dafny__runtime__Set).FSel(Dafny.Sequence.UnicodeFromString("from_array")); } } public static RAST._IExpr dafny__runtime__Sequence { get { - return (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Sequence")); + return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Sequence"))).AsExpr(); } } public static RAST._IExpr Sequence__from__array__owned { get { - return (RAST.__default.dafny__runtime__Sequence).MSel(Dafny.Sequence.UnicodeFromString("from_array_owned")); + return (RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.UnicodeFromString("from_array_owned")); } } public static RAST._IExpr Sequence__from__array { get { - return (RAST.__default.dafny__runtime__Sequence).MSel(Dafny.Sequence.UnicodeFromString("from_array")); + return (RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.UnicodeFromString("from_array")); } } public static RAST._IExpr dafny__runtime__Multiset { get { - return (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Multiset")); + return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Multiset"))).AsExpr(); } } public static RAST._IExpr dafny__runtime__Multiset__from__array { get { - return (RAST.__default.dafny__runtime__Multiset).MSel(Dafny.Sequence.UnicodeFromString("from_array")); + return (RAST.__default.dafny__runtime__Multiset).FSel(Dafny.Sequence.UnicodeFromString("from_array")); } } - public static RAST._IExpr std__rc { get { + public static RAST._IPath std__rc { get { return (RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("rc")); } } - public static RAST._IExpr std__rc__Rc { get { + public static RAST._IPath std__rc__Rc { get { return (RAST.__default.std__rc).MSel(Dafny.Sequence.UnicodeFromString("Rc")); } } public static RAST._IExpr std__rc__Rc__new { get { - return (RAST.__default.std__rc__Rc).MSel(Dafny.Sequence.UnicodeFromString("new")); + return (RAST.__default.std__rc__Rc).FSel(Dafny.Sequence.UnicodeFromString("new")); } } public static RAST._IExpr std__Default__default { get { - return ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).MSel(Dafny.Sequence.UnicodeFromString("default"))).Apply(Dafny.Sequence.FromElements()); + return ((RAST.__default.DefaultPath).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply(Dafny.Sequence.FromElements()); } } public static BigInteger MAX__TUPLE__SIZE { get { return new BigInteger(12); @@ -269,6 +302,7 @@ public interface _IMod { Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_body { get; } _IMod DowncastClone(); + __T Fold<__T>(__T acc, Func<__T, RAST._IModDecl, __T> accBuilder); Dafny.ISequence _ToString(Dafny.ISequence ind); } public abstract class Mod : _IMod { @@ -304,6 +338,14 @@ public Dafny.ISequence dtor_body { } } public abstract _IMod DowncastClone(); + public __T Fold<__T>(__T acc, Func<__T, RAST._IModDecl, __T> accBuilder) + { + if ((this).is_ExternMod) { + return acc; + } else { + return RAST.__default.FoldLeft<__T, RAST._IModDecl>(accBuilder, acc, (this).dtor_body); + } + } public Dafny.ISequence _ToString(Dafny.ISequence ind) { RAST._IMod _source0 = this; { @@ -315,9 +357,14 @@ public Dafny.ISequence dtor_body { { Dafny.ISequence _1_name = _source0.dtor_name; Dafny.ISequence _2_body = _source0.dtor_body; - return 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("pub mod "), _1_name), Dafny.Sequence.UnicodeFromString(" {")), Dafny.Sequence.UnicodeFromString("\n")), ind), RAST.__default.IND), RAST.__default.SeqToString(_2_body, Dafny.Helpers.Id, Func>>>((_3_ind) => ((System.Func>)((_4_modDecl) => { - return (_4_modDecl)._ToString(Dafny.Sequence.Concat(_3_ind, RAST.__default.IND)); - })))(ind), Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n\n"), ind), RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), ind), Dafny.Sequence.UnicodeFromString("}")); + bool _3_startWithUse = ((new BigInteger((_2_body).Count)).Sign == 1) && (((_2_body).Select(BigInteger.Zero)).is_UseDecl); + Dafny.ISequence _4_prefixIfNotUseDecl = ((_3_startWithUse) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))); + Dafny.ISequence _5_prefixIfUseDecl = ((_3_startWithUse) ? (Dafny.Sequence.Concat(ind, RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))); + Dafny.ISequence _6_infixDecl = ((_3_startWithUse) ? (Dafny.Sequence.UnicodeFromString("\n")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n\n"), ind), RAST.__default.IND))); + Dafny.ISequence _7_initialIdent = ((_3_startWithUse) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(ind, RAST.__default.IND))); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("pub mod "), _1_name), Dafny.Sequence.UnicodeFromString(" {")), Dafny.Sequence.UnicodeFromString("\n")), _7_initialIdent), RAST.__default.SeqToString(_2_body, Dafny.Helpers.Id, Dafny.ISequence, Dafny.ISequence, Func>>>((_8_prefixIfUseDecl, _9_prefixIfNotUseDecl, _10_ind) => ((System.Func>)((_11_modDecl) => { + return Dafny.Sequence.Concat((((_11_modDecl).is_UseDecl) ? (_8_prefixIfUseDecl) : (_9_prefixIfNotUseDecl)), (_11_modDecl)._ToString(Dafny.Sequence.Concat(_10_ind, RAST.__default.IND))); + })))(_5_prefixIfUseDecl, _4_prefixIfNotUseDecl, ind), _6_infixDecl)), Dafny.Sequence.UnicodeFromString("\n")), ind), Dafny.Sequence.UnicodeFromString("}")); } } } @@ -382,7 +429,6 @@ public override string ToString() { } public interface _IModDecl { - bool is_RawDecl { get; } bool is_ModDecl { get; } bool is_StructDecl { get; } bool is_TypeDecl { get; } @@ -391,7 +437,7 @@ public interface _IModDecl { bool is_ImplDecl { get; } bool is_TraitDecl { get; } bool is_TopFnDecl { get; } - Dafny.ISequence dtor_body { get; } + bool is_UseDecl { get; } RAST._IMod dtor_mod { get; } RAST._IStruct dtor_struct { get; } RAST._ITypeSynonym dtor_tpe { get; } @@ -400,13 +446,14 @@ public interface _IModDecl { RAST._IImpl dtor_impl { get; } RAST._ITrait dtor_tr { get; } RAST._ITopFnDecl dtor_fn { get; } + RAST._IUse dtor_use { get; } _IModDecl DowncastClone(); Dafny.ISequence _ToString(Dafny.ISequence ind); } public abstract class ModDecl : _IModDecl { public ModDecl() { } - private static readonly RAST._IModDecl theDefault = create_RawDecl(Dafny.Sequence.Empty); + private static readonly RAST._IModDecl theDefault = create_ModDecl(RAST.Mod.Default()); public static RAST._IModDecl Default() { return theDefault; } @@ -414,9 +461,6 @@ public static RAST._IModDecl Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IModDecl create_RawDecl(Dafny.ISequence body) { - return new ModDecl_RawDecl(body); - } public static _IModDecl create_ModDecl(RAST._IMod mod) { return new ModDecl_ModDecl(mod); } @@ -441,7 +485,9 @@ public static _IModDecl create_TraitDecl(RAST._ITrait tr) { public static _IModDecl create_TopFnDecl(RAST._ITopFnDecl fn) { return new ModDecl_TopFnDecl(fn); } - public bool is_RawDecl { get { return this is ModDecl_RawDecl; } } + public static _IModDecl create_UseDecl(RAST._IUse use) { + return new ModDecl_UseDecl(use); + } public bool is_ModDecl { get { return this is ModDecl_ModDecl; } } public bool is_StructDecl { get { return this is ModDecl_StructDecl; } } public bool is_TypeDecl { get { return this is ModDecl_TypeDecl; } } @@ -450,12 +496,7 @@ public static _IModDecl create_TopFnDecl(RAST._ITopFnDecl fn) { public bool is_ImplDecl { get { return this is ModDecl_ImplDecl; } } public bool is_TraitDecl { get { return this is ModDecl_TraitDecl; } } public bool is_TopFnDecl { get { return this is ModDecl_TopFnDecl; } } - public Dafny.ISequence dtor_body { - get { - var d = this; - return ((ModDecl_RawDecl)d)._body; - } - } + public bool is_UseDecl { get { return this is ModDecl_UseDecl; } } public RAST._IMod dtor_mod { get { var d = this; @@ -504,6 +545,12 @@ public RAST._ITopFnDecl dtor_fn { return ((ModDecl_TopFnDecl)d)._fn; } } + public RAST._IUse dtor_use { + get { + var d = this; + return ((ModDecl_UseDecl)d)._use; + } + } public abstract _IModDecl DowncastClone(); public Dafny.ISequence _ToString(Dafny.ISequence ind) { if ((this).is_ModDecl) { @@ -523,37 +570,10 @@ public RAST._ITopFnDecl dtor_fn { } else if ((this).is_TopFnDecl) { return ((this).dtor_fn)._ToString(ind); } else { - return (this).dtor_body; + return ((this).dtor_use)._ToString(ind); } } } - public class ModDecl_RawDecl : ModDecl { - public readonly Dafny.ISequence _body; - public ModDecl_RawDecl(Dafny.ISequence body) : base() { - this._body = body; - } - public override _IModDecl DowncastClone() { - if (this is _IModDecl dt) { return dt; } - return new ModDecl_RawDecl(_body); - } - public override bool Equals(object other) { - var oth = other as RAST.ModDecl_RawDecl; - return oth != null && object.Equals(this._body, oth._body); - } - public override int GetHashCode() { - ulong hash = 5381; - hash = ((hash << 5) + hash) + 0; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); - return (int) hash; - } - public override string ToString() { - string s = "RAST.ModDecl.RawDecl"; - s += "("; - s += this._body.ToVerbatimString(true); - s += ")"; - return s; - } - } public class ModDecl_ModDecl : ModDecl { public readonly RAST._IMod _mod; public ModDecl_ModDecl(RAST._IMod mod) : base() { @@ -569,7 +589,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + 0; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._mod)); return (int) hash; } @@ -596,7 +616,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + 1; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._struct)); return (int) hash; } @@ -623,7 +643,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + 2; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._tpe)); return (int) hash; } @@ -650,7 +670,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 4; + hash = ((hash << 5) + hash) + 3; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._c)); return (int) hash; } @@ -677,7 +697,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 5; + hash = ((hash << 5) + hash) + 4; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._enum)); return (int) hash; } @@ -704,7 +724,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 6; + hash = ((hash << 5) + hash) + 5; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._impl)); return (int) hash; } @@ -731,7 +751,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 7; + hash = ((hash << 5) + hash) + 6; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._tr)); return (int) hash; } @@ -758,7 +778,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 8; + hash = ((hash << 5) + hash) + 7; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fn)); return (int) hash; } @@ -770,6 +790,101 @@ public override string ToString() { return s; } } + public class ModDecl_UseDecl : ModDecl { + public readonly RAST._IUse _use; + public ModDecl_UseDecl(RAST._IUse use) : base() { + this._use = use; + } + public override _IModDecl DowncastClone() { + if (this is _IModDecl dt) { return dt; } + return new ModDecl_UseDecl(_use); + } + public override bool Equals(object other) { + var oth = other as RAST.ModDecl_UseDecl; + return oth != null && object.Equals(this._use, oth._use); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 8; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._use)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.ModDecl.UseDecl"; + s += "("; + s += Dafny.Helpers.ToString(this._use); + s += ")"; + return s; + } + } + + public interface _IUse { + bool is_Use { get; } + RAST._IVisibility dtor_visibility { get; } + RAST._IPath dtor_path { get; } + _IUse DowncastClone(); + Dafny.ISequence _ToString(Dafny.ISequence ind); + } + public class Use : _IUse { + public readonly RAST._IVisibility _visibility; + public readonly RAST._IPath _path; + public Use(RAST._IVisibility visibility, RAST._IPath path) { + this._visibility = visibility; + this._path = path; + } + public _IUse DowncastClone() { + if (this is _IUse dt) { return dt; } + return new Use(_visibility, _path); + } + public override bool Equals(object other) { + var oth = other as RAST.Use; + return oth != null && object.Equals(this._visibility, oth._visibility) && object.Equals(this._path, oth._path); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._visibility)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._path)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.Use.Use"; + s += "("; + s += Dafny.Helpers.ToString(this._visibility); + s += ", "; + s += Dafny.Helpers.ToString(this._path); + s += ")"; + return s; + } + private static readonly RAST._IUse theDefault = create(RAST.Visibility.Default(), RAST.Path.Default()); + public static RAST._IUse Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.Use.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IUse create(RAST._IVisibility visibility, RAST._IPath path) { + return new Use(visibility, path); + } + public static _IUse create_Use(RAST._IVisibility visibility, RAST._IPath path) { + return create(visibility, path); + } + public bool is_Use { get { return true; } } + public RAST._IVisibility dtor_visibility { + get { + return this._visibility; + } + } + public RAST._IPath dtor_path { + get { + return this._path; + } + } + public Dafny.ISequence _ToString(Dafny.ISequence ind) { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(((this).dtor_visibility)._ToString(), Dafny.Sequence.UnicodeFromString("use ")), ((this).dtor_path)._ToString()), Dafny.Sequence.UnicodeFromString(";")); + } + } public interface _ITopFnDecl { bool is_TopFn { get; } @@ -1605,38 +1720,38 @@ public Dafny.ISequence dtor_variants { public interface _ITypeParamDecl { bool is_TypeParamDecl { get; } - Dafny.ISequence dtor_content { get; } + Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_constraints { get; } _ITypeParamDecl DowncastClone(); RAST._ITypeParamDecl AddConstraints(Dafny.ISequence constraints); Dafny.ISequence _ToString(Dafny.ISequence ind); } public class TypeParamDecl : _ITypeParamDecl { - public readonly Dafny.ISequence _content; + public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _constraints; - public TypeParamDecl(Dafny.ISequence content, Dafny.ISequence constraints) { - this._content = content; + public TypeParamDecl(Dafny.ISequence name, Dafny.ISequence constraints) { + this._name = name; this._constraints = constraints; } public _ITypeParamDecl DowncastClone() { if (this is _ITypeParamDecl dt) { return dt; } - return new TypeParamDecl(_content, _constraints); + return new TypeParamDecl(_name, _constraints); } public override bool Equals(object other) { var oth = other as RAST.TypeParamDecl; - return oth != null && object.Equals(this._content, oth._content) && object.Equals(this._constraints, oth._constraints); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._constraints, oth._constraints); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._content)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._constraints)); return (int) hash; } public override string ToString() { string s = "RAST.TypeParamDecl.TypeParamDecl"; s += "("; - s += this._content.ToVerbatimString(true); + s += this._name.ToVerbatimString(true); s += ", "; s += Dafny.Helpers.ToString(this._constraints); s += ")"; @@ -1650,16 +1765,16 @@ public static RAST._ITypeParamDecl Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITypeParamDecl create(Dafny.ISequence content, Dafny.ISequence constraints) { - return new TypeParamDecl(content, constraints); + public static _ITypeParamDecl create(Dafny.ISequence name, Dafny.ISequence constraints) { + return new TypeParamDecl(name, constraints); } - public static _ITypeParamDecl create_TypeParamDecl(Dafny.ISequence content, Dafny.ISequence constraints) { - return create(content, constraints); + public static _ITypeParamDecl create_TypeParamDecl(Dafny.ISequence name, Dafny.ISequence constraints) { + return create(name, constraints); } public bool is_TypeParamDecl { get { return true; } } - public Dafny.ISequence dtor_content { + public Dafny.ISequence dtor_name { get { - return this._content; + return this._name; } } public Dafny.ISequence dtor_constraints { @@ -1695,17 +1810,226 @@ public Dafny.ISequence dtor_constraints { public RAST._ITypeParamDecl AddConstraints(Dafny.ISequence constraints) { RAST._ITypeParamDecl _0_dt__update__tmp_h0 = this; Dafny.ISequence _1_dt__update_hconstraints_h0 = Dafny.Sequence.Concat((this).dtor_constraints, constraints); - return RAST.TypeParamDecl.create((_0_dt__update__tmp_h0).dtor_content, _1_dt__update_hconstraints_h0); + return RAST.TypeParamDecl.create((_0_dt__update__tmp_h0).dtor_name, _1_dt__update_hconstraints_h0); } public Dafny.ISequence _ToString(Dafny.ISequence ind) { - return Dafny.Sequence.Concat((this).dtor_content, (((new BigInteger(((this).dtor_constraints).Count)).Sign == 0) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(": "), RAST.__default.SeqToString((this).dtor_constraints, Dafny.Helpers.Id, Func>>>((_0_ind) => ((System.Func>)((_1_t) => { + return Dafny.Sequence.Concat((this).dtor_name, (((new BigInteger(((this).dtor_constraints).Count)).Sign == 0) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(": "), RAST.__default.SeqToString((this).dtor_constraints, Dafny.Helpers.Id, Func>>>((_0_ind) => ((System.Func>)((_1_t) => { return (_1_t)._ToString(Dafny.Sequence.Concat(_0_ind, RAST.__default.IND)); })))(ind), Dafny.Sequence.UnicodeFromString(" + ")))))); } } + public interface _IPath { + bool is_Global { get; } + bool is_Crate { get; } + bool is_Self { get; } + bool is_PMemberSelect { get; } + RAST._IPath dtor_base { get; } + Dafny.ISequence dtor_name { get; } + _IPath DowncastClone(); + RAST._IPath MSel(Dafny.ISequence name); + RAST._IExpr FSel(Dafny.ISequence name); + RAST._IType AsType(); + RAST._IExpr AsExpr(); + Dafny.ISequence _ToString(); + Std.Wrappers._IOption> RightMostIdentifier(); + } + public abstract class Path : _IPath { + public Path() { + } + private static readonly RAST._IPath theDefault = create_Global(); + public static RAST._IPath Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.Path.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IPath create_Global() { + return new Path_Global(); + } + public static _IPath create_Crate() { + return new Path_Crate(); + } + public static _IPath create_Self() { + return new Path_Self(); + } + public static _IPath create_PMemberSelect(RAST._IPath @base, Dafny.ISequence name) { + return new Path_PMemberSelect(@base, name); + } + public bool is_Global { get { return this is Path_Global; } } + public bool is_Crate { get { return this is Path_Crate; } } + public bool is_Self { get { return this is Path_Self; } } + public bool is_PMemberSelect { get { return this is Path_PMemberSelect; } } + public RAST._IPath dtor_base { + get { + var d = this; + return ((Path_PMemberSelect)d)._base; + } + } + public Dafny.ISequence dtor_name { + get { + var d = this; + return ((Path_PMemberSelect)d)._name; + } + } + public abstract _IPath DowncastClone(); + public RAST._IPath MSel(Dafny.ISequence name) { + return RAST.Path.create_PMemberSelect(this, name); + } + public RAST._IExpr FSel(Dafny.ISequence name) { + return ((this).AsExpr()).FSel(name); + } + public RAST._IType AsType() { + return RAST.Type.create_TypeFromPath(this); + } + public RAST._IExpr AsExpr() { + return RAST.Expr.create_ExprFromPath(this); + } + public Dafny.ISequence _ToString() { + RAST._IPath _source0 = this; + { + if (_source0.is_Global) { + return Dafny.Sequence.UnicodeFromString(""); + } + } + { + if (_source0.is_Crate) { + return Dafny.Sequence.UnicodeFromString("crate"); + } + } + { + if (_source0.is_Self) { + return Dafny.Sequence.UnicodeFromString("Self"); + } + } + { + RAST._IPath _0_base = _source0.dtor_base; + Dafny.ISequence _1_name = _source0.dtor_name; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_0_base)._ToString(), Dafny.Sequence.UnicodeFromString("::")), _1_name); + } + } + public Std.Wrappers._IOption> RightMostIdentifier() { + RAST._IPath _source0 = this; + { + if (_source0.is_Global) { + return Std.Wrappers.Option>.create_None(); + } + } + { + if (_source0.is_Crate) { + return Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("crate")); + } + } + { + if (_source0.is_Self) { + return Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("Self")); + } + } + { + RAST._IPath _0_base = _source0.dtor_base; + Dafny.ISequence _1_name = _source0.dtor_name; + return Std.Wrappers.Option>.create_Some(_1_name); + } + } + } + public class Path_Global : Path { + public Path_Global() : base() { + } + public override _IPath DowncastClone() { + if (this is _IPath dt) { return dt; } + return new Path_Global(); + } + public override bool Equals(object other) { + var oth = other as RAST.Path_Global; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + return (int) hash; + } + public override string ToString() { + string s = "RAST.Path.Global"; + return s; + } + } + public class Path_Crate : Path { + public Path_Crate() : base() { + } + public override _IPath DowncastClone() { + if (this is _IPath dt) { return dt; } + return new Path_Crate(); + } + public override bool Equals(object other) { + var oth = other as RAST.Path_Crate; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + return (int) hash; + } + public override string ToString() { + string s = "RAST.Path.Crate"; + return s; + } + } + public class Path_Self : Path { + public Path_Self() : base() { + } + public override _IPath DowncastClone() { + if (this is _IPath dt) { return dt; } + return new Path_Self(); + } + public override bool Equals(object other) { + var oth = other as RAST.Path_Self; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 2; + return (int) hash; + } + public override string ToString() { + string s = "RAST.Path.Self"; + return s; + } + } + public class Path_PMemberSelect : Path { + public readonly RAST._IPath _base; + public readonly Dafny.ISequence _name; + public Path_PMemberSelect(RAST._IPath @base, Dafny.ISequence name) : base() { + this._base = @base; + this._name = name; + } + public override _IPath DowncastClone() { + if (this is _IPath dt) { return dt; } + return new Path_PMemberSelect(_base, _name); + } + public override bool Equals(object other) { + var oth = other as RAST.Path_PMemberSelect; + return oth != null && object.Equals(this._base, oth._base) && object.Equals(this._name, oth._name); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._base)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.Path.PMemberSelect"; + s += "("; + s += Dafny.Helpers.ToString(this._base); + s += ", "; + s += this._name.ToVerbatimString(true); + s += ")"; + return s; + } + } + public interface _IType { - bool is_SelfOwned { get; } bool is_U8 { get; } bool is_U16 { get; } bool is_U32 { get; } @@ -1718,20 +2042,19 @@ public interface _IType { bool is_I128 { get; } bool is_Bool { get; } bool is_TIdentifier { get; } - bool is_TMemberSelect { get; } + bool is_TypeFromPath { get; } bool is_TypeApp { get; } bool is_Borrowed { get; } bool is_BorrowedMut { get; } - bool is_Pointer { get; } - bool is_PointerMut { get; } bool is_ImplType { get; } bool is_DynType { get; } bool is_TupleType { get; } bool is_FnType { get; } bool is_IntersectionType { get; } bool is_Array { get; } + bool is_TSynonym { get; } Dafny.ISequence dtor_name { get; } - RAST._IType dtor_base { get; } + RAST._IPath dtor_path { get; } RAST._IType dtor_baseName { get; } Dafny.ISequence dtor_arguments { get; } RAST._IType dtor_underlying { get; } @@ -1739,15 +2062,19 @@ public interface _IType { RAST._IType dtor_left { get; } RAST._IType dtor_right { get; } Std.Wrappers._IOption> dtor_size { get; } + RAST._IType dtor_display { get; } + RAST._IType dtor_base { get; } _IType DowncastClone(); - RAST._IType Replace(Dafny.IMap mapping); + 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 CanReadWithoutClone(); - bool IsSelfPointer(); bool IsRcOrBorrowedRc(); Std.Wrappers._IOption ExtractMaybePlacebo(); Std.Wrappers._IOption ExtractMaybeUninitArrayElement(); Dafny.ISequence _ToString(Dafny.ISequence ind); - RAST._IType MSel(Dafny.ISequence name); RAST._IType Apply1(RAST._IType arg); RAST._IType Apply(Dafny.ISequence args); RAST._IType ToOwned(); @@ -1770,7 +2097,7 @@ public interface _IType { public abstract class Type : _IType { public Type() { } - private static readonly RAST._IType theDefault = create_SelfOwned(); + private static readonly RAST._IType theDefault = create_U8(); public static RAST._IType Default() { return theDefault; } @@ -1778,9 +2105,6 @@ public static RAST._IType Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IType create_SelfOwned() { - return new Type_SelfOwned(); - } public static _IType create_U8() { return new Type_U8(); } @@ -1817,8 +2141,8 @@ public static _IType create_Bool() { public static _IType create_TIdentifier(Dafny.ISequence name) { return new Type_TIdentifier(name); } - public static _IType create_TMemberSelect(RAST._IType @base, Dafny.ISequence name) { - return new Type_TMemberSelect(@base, name); + public static _IType create_TypeFromPath(RAST._IPath path) { + return new Type_TypeFromPath(path); } public static _IType create_TypeApp(RAST._IType baseName, Dafny.ISequence arguments) { return new Type_TypeApp(baseName, arguments); @@ -1829,12 +2153,6 @@ public static _IType create_Borrowed(RAST._IType underlying) { public static _IType create_BorrowedMut(RAST._IType underlying) { return new Type_BorrowedMut(underlying); } - public static _IType create_Pointer(RAST._IType underlying) { - return new Type_Pointer(underlying); - } - public static _IType create_PointerMut(RAST._IType underlying) { - return new Type_PointerMut(underlying); - } public static _IType create_ImplType(RAST._IType underlying) { return new Type_ImplType(underlying); } @@ -1853,7 +2171,9 @@ public static _IType create_IntersectionType(RAST._IType left, RAST._IType right public static _IType create_Array(RAST._IType underlying, Std.Wrappers._IOption> size) { return new Type_Array(underlying, size); } - public bool is_SelfOwned { get { return this is Type_SelfOwned; } } + public static _IType create_TSynonym(RAST._IType display, RAST._IType @base) { + return new Type_TSynonym(display, @base); + } 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; } } @@ -1866,29 +2186,27 @@ public static _IType create_Array(RAST._IType underlying, Std.Wrappers._IOption< public bool is_I128 { get { return this is Type_I128; } } public bool is_Bool { get { return this is Type_Bool; } } public bool is_TIdentifier { get { return this is Type_TIdentifier; } } - public bool is_TMemberSelect { get { return this is Type_TMemberSelect; } } + public bool is_TypeFromPath { get { return this is Type_TypeFromPath; } } public bool is_TypeApp { get { return this is Type_TypeApp; } } public bool is_Borrowed { get { return this is Type_Borrowed; } } public bool is_BorrowedMut { get { return this is Type_BorrowedMut; } } - public bool is_Pointer { get { return this is Type_Pointer; } } - public bool is_PointerMut { get { return this is Type_PointerMut; } } public bool is_ImplType { get { return this is Type_ImplType; } } public bool is_DynType { get { return this is Type_DynType; } } public bool is_TupleType { get { return this is Type_TupleType; } } public bool is_FnType { get { return this is Type_FnType; } } 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 Dafny.ISequence dtor_name { get { var d = this; - if (d is Type_TIdentifier) { return ((Type_TIdentifier)d)._name; } - return ((Type_TMemberSelect)d)._name; + return ((Type_TIdentifier)d)._name; } } - public RAST._IType dtor_base { + public RAST._IPath dtor_path { get { var d = this; - return ((Type_TMemberSelect)d)._base; + return ((Type_TypeFromPath)d)._path; } } public RAST._IType dtor_baseName { @@ -1910,8 +2228,6 @@ public RAST._IType dtor_underlying { var d = this; if (d is Type_Borrowed) { return ((Type_Borrowed)d)._underlying; } if (d is Type_BorrowedMut) { return ((Type_BorrowedMut)d)._underlying; } - if (d is Type_Pointer) { return ((Type_Pointer)d)._underlying; } - if (d is Type_PointerMut) { return ((Type_PointerMut)d)._underlying; } if (d is Type_ImplType) { return ((Type_ImplType)d)._underlying; } if (d is Type_DynType) { return ((Type_DynType)d)._underlying; } return ((Type_Array)d)._underlying; @@ -1941,17 +2257,42 @@ public Std.Wrappers._IOption> dtor_size { return ((Type_Array)d)._size; } } + public RAST._IType dtor_display { + get { + var d = this; + return ((Type_TSynonym)d)._display; + } + } + public RAST._IType dtor_base { + get { + var d = this; + return ((Type_TSynonym)d)._base; + } + } public abstract _IType DowncastClone(); - public RAST._IType Replace(Dafny.IMap mapping) { - if ((mapping).Contains(this)) { - return Dafny.Map.Select(mapping,this); + public RAST._IType Expand() { + _IType _this = this; + TAIL_CALL_START: ; + if ((_this).is_TSynonym) { + RAST._IType _in0 = (_this).dtor_base; + _this = _in0; + ; + 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())); + } + public RAST._IType ReplaceMap(Dafny.IMap mapping) { + return (this).Replace(Dafny.Helpers.Id, Func>>((_0_mapping) => ((System.Func)((_1_t) => { + return (((_0_mapping).Contains(_1_t)) ? (Dafny.Map.Select(_0_mapping,_1_t)) : (_1_t)); + })))(mapping)); + } + public RAST._IType Replace(Func mapping) { + RAST._IType _0_r = ((System.Func)(() => { RAST._IType _source0 = this; - { - if (_source0.is_SelfOwned) { - return this; - } - } { bool disjunctiveMatch0 = false; if (_source0.is_U8) { @@ -1997,227 +2338,292 @@ public RAST._IType Replace(Dafny.IMap mapping) { } } { - if (_source0.is_TMemberSelect) { - RAST._IType _0_base = _source0.dtor_base; - Dafny.ISequence _1_name = _source0.dtor_name; - RAST._IType _2_dt__update__tmp_h0 = this; - RAST._IType _3_dt__update_hbase_h0 = (_0_base).Replace(mapping); - return RAST.Type.create_TMemberSelect(_3_dt__update_hbase_h0, (_2_dt__update__tmp_h0).dtor_name); + if (_source0.is_TypeFromPath) { + RAST._IPath _1_path = _source0.dtor_path; + return this; } } { if (_source0.is_TypeApp) { - RAST._IType _4_baseName = _source0.dtor_baseName; - Dafny.ISequence _5_arguments = _source0.dtor_arguments; - RAST._IType _6_dt__update__tmp_h1 = this; - Dafny.ISequence _7_dt__update_harguments_h0 = Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Dafny.ISequence, Func>>((_8_mapping, _9_arguments) => ((System.Func)((_10_t) => { - return (_10_t).Replace(_8_mapping); - })))(mapping, _5_arguments), _5_arguments); - RAST._IType _11_dt__update_hbaseName_h0 = (_4_baseName).Replace(mapping); - return RAST.Type.create_TypeApp(_11_dt__update_hbaseName_h0, _7_dt__update_harguments_h0); + RAST._IType _2_baseName = _source0.dtor_baseName; + Dafny.ISequence _3_arguments = _source0.dtor_arguments; + RAST._IType _4_dt__update__tmp_h0 = this; + Dafny.ISequence _5_dt__update_harguments_h0 = Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Dafny.ISequence, Func>>((_6_mapping, _7_arguments) => ((System.Func)((_8_t) => { + return (_8_t).Replace(_6_mapping); + })))(mapping, _3_arguments), _3_arguments); + RAST._IType _9_dt__update_hbaseName_h0 = (_2_baseName).Replace(mapping); + return RAST.Type.create_TypeApp(_9_dt__update_hbaseName_h0, _5_dt__update_harguments_h0); } } { if (_source0.is_Borrowed) { - RAST._IType _12_underlying = _source0.dtor_underlying; - RAST._IType _13_dt__update__tmp_h2 = this; - RAST._IType _14_dt__update_hunderlying_h0 = (_12_underlying).Replace(mapping); - if ((_13_dt__update__tmp_h2).is_Borrowed) { - return RAST.Type.create_Borrowed(_14_dt__update_hunderlying_h0); - } else if ((_13_dt__update__tmp_h2).is_BorrowedMut) { - return RAST.Type.create_BorrowedMut(_14_dt__update_hunderlying_h0); - } else if ((_13_dt__update__tmp_h2).is_Pointer) { - return RAST.Type.create_Pointer(_14_dt__update_hunderlying_h0); - } else if ((_13_dt__update__tmp_h2).is_PointerMut) { - return RAST.Type.create_PointerMut(_14_dt__update_hunderlying_h0); - } else if ((_13_dt__update__tmp_h2).is_ImplType) { - return RAST.Type.create_ImplType(_14_dt__update_hunderlying_h0); - } else if ((_13_dt__update__tmp_h2).is_DynType) { - return RAST.Type.create_DynType(_14_dt__update_hunderlying_h0); + RAST._IType _10_underlying = _source0.dtor_underlying; + RAST._IType _11_dt__update__tmp_h1 = this; + RAST._IType _12_dt__update_hunderlying_h0 = (_10_underlying).Replace(mapping); + if ((_11_dt__update__tmp_h1).is_Borrowed) { + return RAST.Type.create_Borrowed(_12_dt__update_hunderlying_h0); + } else if ((_11_dt__update__tmp_h1).is_BorrowedMut) { + return RAST.Type.create_BorrowedMut(_12_dt__update_hunderlying_h0); + } else if ((_11_dt__update__tmp_h1).is_ImplType) { + return RAST.Type.create_ImplType(_12_dt__update_hunderlying_h0); + } else if ((_11_dt__update__tmp_h1).is_DynType) { + return RAST.Type.create_DynType(_12_dt__update_hunderlying_h0); } else { - return RAST.Type.create_Array(_14_dt__update_hunderlying_h0, (_13_dt__update__tmp_h2).dtor_size); + return RAST.Type.create_Array(_12_dt__update_hunderlying_h0, (_11_dt__update__tmp_h1).dtor_size); } } } { if (_source0.is_BorrowedMut) { - RAST._IType _15_underlying = _source0.dtor_underlying; - RAST._IType _16_dt__update__tmp_h3 = this; - RAST._IType _17_dt__update_hunderlying_h1 = (_15_underlying).Replace(mapping); - if ((_16_dt__update__tmp_h3).is_Borrowed) { - return RAST.Type.create_Borrowed(_17_dt__update_hunderlying_h1); - } else if ((_16_dt__update__tmp_h3).is_BorrowedMut) { - return RAST.Type.create_BorrowedMut(_17_dt__update_hunderlying_h1); - } else if ((_16_dt__update__tmp_h3).is_Pointer) { - return RAST.Type.create_Pointer(_17_dt__update_hunderlying_h1); - } else if ((_16_dt__update__tmp_h3).is_PointerMut) { - return RAST.Type.create_PointerMut(_17_dt__update_hunderlying_h1); - } else if ((_16_dt__update__tmp_h3).is_ImplType) { - return RAST.Type.create_ImplType(_17_dt__update_hunderlying_h1); - } else if ((_16_dt__update__tmp_h3).is_DynType) { - return RAST.Type.create_DynType(_17_dt__update_hunderlying_h1); + RAST._IType _13_underlying = _source0.dtor_underlying; + RAST._IType _14_dt__update__tmp_h2 = this; + RAST._IType _15_dt__update_hunderlying_h1 = (_13_underlying).Replace(mapping); + if ((_14_dt__update__tmp_h2).is_Borrowed) { + return RAST.Type.create_Borrowed(_15_dt__update_hunderlying_h1); + } else if ((_14_dt__update__tmp_h2).is_BorrowedMut) { + return RAST.Type.create_BorrowedMut(_15_dt__update_hunderlying_h1); + } else if ((_14_dt__update__tmp_h2).is_ImplType) { + return RAST.Type.create_ImplType(_15_dt__update_hunderlying_h1); + } else if ((_14_dt__update__tmp_h2).is_DynType) { + return RAST.Type.create_DynType(_15_dt__update_hunderlying_h1); } else { - return RAST.Type.create_Array(_17_dt__update_hunderlying_h1, (_16_dt__update__tmp_h3).dtor_size); + return RAST.Type.create_Array(_15_dt__update_hunderlying_h1, (_14_dt__update__tmp_h2).dtor_size); } } } { - if (_source0.is_Pointer) { - RAST._IType _18_underlying = _source0.dtor_underlying; - RAST._IType _19_dt__update__tmp_h4 = this; - RAST._IType _20_dt__update_hunderlying_h2 = (_18_underlying).Replace(mapping); - if ((_19_dt__update__tmp_h4).is_Borrowed) { - return RAST.Type.create_Borrowed(_20_dt__update_hunderlying_h2); - } else if ((_19_dt__update__tmp_h4).is_BorrowedMut) { - return RAST.Type.create_BorrowedMut(_20_dt__update_hunderlying_h2); - } else if ((_19_dt__update__tmp_h4).is_Pointer) { - return RAST.Type.create_Pointer(_20_dt__update_hunderlying_h2); - } else if ((_19_dt__update__tmp_h4).is_PointerMut) { - return RAST.Type.create_PointerMut(_20_dt__update_hunderlying_h2); - } else if ((_19_dt__update__tmp_h4).is_ImplType) { - return RAST.Type.create_ImplType(_20_dt__update_hunderlying_h2); - } else if ((_19_dt__update__tmp_h4).is_DynType) { - return RAST.Type.create_DynType(_20_dt__update_hunderlying_h2); + if (_source0.is_ImplType) { + RAST._IType _16_underlying = _source0.dtor_underlying; + RAST._IType _17_dt__update__tmp_h3 = this; + RAST._IType _18_dt__update_hunderlying_h2 = (_16_underlying).Replace(mapping); + if ((_17_dt__update__tmp_h3).is_Borrowed) { + return RAST.Type.create_Borrowed(_18_dt__update_hunderlying_h2); + } else if ((_17_dt__update__tmp_h3).is_BorrowedMut) { + return RAST.Type.create_BorrowedMut(_18_dt__update_hunderlying_h2); + } else if ((_17_dt__update__tmp_h3).is_ImplType) { + return RAST.Type.create_ImplType(_18_dt__update_hunderlying_h2); + } else if ((_17_dt__update__tmp_h3).is_DynType) { + return RAST.Type.create_DynType(_18_dt__update_hunderlying_h2); } else { - return RAST.Type.create_Array(_20_dt__update_hunderlying_h2, (_19_dt__update__tmp_h4).dtor_size); + return RAST.Type.create_Array(_18_dt__update_hunderlying_h2, (_17_dt__update__tmp_h3).dtor_size); } } } { - if (_source0.is_PointerMut) { - RAST._IType _21_underlying = _source0.dtor_underlying; - RAST._IType _22_dt__update__tmp_h5 = this; - RAST._IType _23_dt__update_hunderlying_h3 = (_21_underlying).Replace(mapping); - if ((_22_dt__update__tmp_h5).is_Borrowed) { - return RAST.Type.create_Borrowed(_23_dt__update_hunderlying_h3); - } else if ((_22_dt__update__tmp_h5).is_BorrowedMut) { - return RAST.Type.create_BorrowedMut(_23_dt__update_hunderlying_h3); - } else if ((_22_dt__update__tmp_h5).is_Pointer) { - return RAST.Type.create_Pointer(_23_dt__update_hunderlying_h3); - } else if ((_22_dt__update__tmp_h5).is_PointerMut) { - return RAST.Type.create_PointerMut(_23_dt__update_hunderlying_h3); - } else if ((_22_dt__update__tmp_h5).is_ImplType) { - return RAST.Type.create_ImplType(_23_dt__update_hunderlying_h3); - } else if ((_22_dt__update__tmp_h5).is_DynType) { - return RAST.Type.create_DynType(_23_dt__update_hunderlying_h3); + if (_source0.is_DynType) { + RAST._IType _19_underlying = _source0.dtor_underlying; + RAST._IType _20_dt__update__tmp_h4 = this; + RAST._IType _21_dt__update_hunderlying_h3 = (_19_underlying).Replace(mapping); + if ((_20_dt__update__tmp_h4).is_Borrowed) { + return RAST.Type.create_Borrowed(_21_dt__update_hunderlying_h3); + } else if ((_20_dt__update__tmp_h4).is_BorrowedMut) { + return RAST.Type.create_BorrowedMut(_21_dt__update_hunderlying_h3); + } else if ((_20_dt__update__tmp_h4).is_ImplType) { + return RAST.Type.create_ImplType(_21_dt__update_hunderlying_h3); + } else if ((_20_dt__update__tmp_h4).is_DynType) { + return RAST.Type.create_DynType(_21_dt__update_hunderlying_h3); } else { - return RAST.Type.create_Array(_23_dt__update_hunderlying_h3, (_22_dt__update__tmp_h5).dtor_size); + return RAST.Type.create_Array(_21_dt__update_hunderlying_h3, (_20_dt__update__tmp_h4).dtor_size); } } } { - if (_source0.is_ImplType) { - RAST._IType _24_underlying = _source0.dtor_underlying; - RAST._IType _25_dt__update__tmp_h6 = this; - RAST._IType _26_dt__update_hunderlying_h4 = (_24_underlying).Replace(mapping); - if ((_25_dt__update__tmp_h6).is_Borrowed) { - return RAST.Type.create_Borrowed(_26_dt__update_hunderlying_h4); - } else if ((_25_dt__update__tmp_h6).is_BorrowedMut) { - return RAST.Type.create_BorrowedMut(_26_dt__update_hunderlying_h4); - } else if ((_25_dt__update__tmp_h6).is_Pointer) { - return RAST.Type.create_Pointer(_26_dt__update_hunderlying_h4); - } else if ((_25_dt__update__tmp_h6).is_PointerMut) { - return RAST.Type.create_PointerMut(_26_dt__update_hunderlying_h4); - } else if ((_25_dt__update__tmp_h6).is_ImplType) { - return RAST.Type.create_ImplType(_26_dt__update_hunderlying_h4); - } else if ((_25_dt__update__tmp_h6).is_DynType) { - return RAST.Type.create_DynType(_26_dt__update_hunderlying_h4); + if (_source0.is_TupleType) { + Dafny.ISequence _22_arguments = _source0.dtor_arguments; + RAST._IType _23_dt__update__tmp_h5 = this; + Dafny.ISequence _24_dt__update_harguments_h1 = Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Dafny.ISequence, Func>>((_25_mapping, _26_arguments) => ((System.Func)((_27_t) => { + return (_27_t).Replace(_25_mapping); + })))(mapping, _22_arguments), _22_arguments); + if ((_23_dt__update__tmp_h5).is_TypeApp) { + return RAST.Type.create_TypeApp((_23_dt__update__tmp_h5).dtor_baseName, _24_dt__update_harguments_h1); + } else if ((_23_dt__update__tmp_h5).is_TupleType) { + return RAST.Type.create_TupleType(_24_dt__update_harguments_h1); } else { - return RAST.Type.create_Array(_26_dt__update_hunderlying_h4, (_25_dt__update__tmp_h6).dtor_size); + return RAST.Type.create_FnType(_24_dt__update_harguments_h1, (_23_dt__update__tmp_h5).dtor_returnType); } } } { - if (_source0.is_DynType) { - RAST._IType _27_underlying = _source0.dtor_underlying; - RAST._IType _28_dt__update__tmp_h7 = this; - RAST._IType _29_dt__update_hunderlying_h5 = (_27_underlying).Replace(mapping); - if ((_28_dt__update__tmp_h7).is_Borrowed) { - return RAST.Type.create_Borrowed(_29_dt__update_hunderlying_h5); - } else if ((_28_dt__update__tmp_h7).is_BorrowedMut) { - return RAST.Type.create_BorrowedMut(_29_dt__update_hunderlying_h5); - } else if ((_28_dt__update__tmp_h7).is_Pointer) { - return RAST.Type.create_Pointer(_29_dt__update_hunderlying_h5); - } else if ((_28_dt__update__tmp_h7).is_PointerMut) { - return RAST.Type.create_PointerMut(_29_dt__update_hunderlying_h5); - } else if ((_28_dt__update__tmp_h7).is_ImplType) { - return RAST.Type.create_ImplType(_29_dt__update_hunderlying_h5); - } else if ((_28_dt__update__tmp_h7).is_DynType) { - return RAST.Type.create_DynType(_29_dt__update_hunderlying_h5); - } else { - return RAST.Type.create_Array(_29_dt__update_hunderlying_h5, (_28_dt__update__tmp_h7).dtor_size); - } + if (_source0.is_FnType) { + Dafny.ISequence _28_arguments = _source0.dtor_arguments; + RAST._IType _29_returnType = _source0.dtor_returnType; + RAST._IType _30_dt__update__tmp_h6 = this; + RAST._IType _31_dt__update_hreturnType_h0 = (_29_returnType).Replace(mapping); + Dafny.ISequence _32_dt__update_harguments_h2 = Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Dafny.ISequence, Func>>((_33_mapping, _34_arguments) => ((System.Func)((_35_t) => { + return (_35_t).Replace(_33_mapping); + })))(mapping, _28_arguments), _28_arguments); + return RAST.Type.create_FnType(_32_dt__update_harguments_h2, _31_dt__update_hreturnType_h0); } } { - if (_source0.is_TupleType) { - Dafny.ISequence _30_arguments = _source0.dtor_arguments; - RAST._IType _31_dt__update__tmp_h8 = this; - Dafny.ISequence _32_dt__update_harguments_h1 = Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Dafny.ISequence, Func>>((_33_mapping, _34_arguments) => ((System.Func)((_35_t) => { - return (_35_t).Replace(_33_mapping); - })))(mapping, _30_arguments), _30_arguments); - if ((_31_dt__update__tmp_h8).is_TypeApp) { - return RAST.Type.create_TypeApp((_31_dt__update__tmp_h8).dtor_baseName, _32_dt__update_harguments_h1); - } else if ((_31_dt__update__tmp_h8).is_TupleType) { - return RAST.Type.create_TupleType(_32_dt__update_harguments_h1); + if (_source0.is_IntersectionType) { + RAST._IType _36_left = _source0.dtor_left; + RAST._IType _37_right = _source0.dtor_right; + RAST._IType _38_dt__update__tmp_h7 = this; + RAST._IType _39_dt__update_hright_h0 = (_37_right).Replace(mapping); + RAST._IType _40_dt__update_hleft_h0 = (_36_left).Replace(mapping); + return RAST.Type.create_IntersectionType(_40_dt__update_hleft_h0, _39_dt__update_hright_h0); + } + } + { + if (_source0.is_Array) { + RAST._IType _41_underlying = _source0.dtor_underlying; + Std.Wrappers._IOption> _42_size = _source0.dtor_size; + RAST._IType _43_dt__update__tmp_h8 = this; + RAST._IType _44_dt__update_hunderlying_h4 = (_41_underlying).Replace(mapping); + if ((_43_dt__update__tmp_h8).is_Borrowed) { + return RAST.Type.create_Borrowed(_44_dt__update_hunderlying_h4); + } else if ((_43_dt__update__tmp_h8).is_BorrowedMut) { + return RAST.Type.create_BorrowedMut(_44_dt__update_hunderlying_h4); + } else if ((_43_dt__update__tmp_h8).is_ImplType) { + return RAST.Type.create_ImplType(_44_dt__update_hunderlying_h4); + } else if ((_43_dt__update__tmp_h8).is_DynType) { + return RAST.Type.create_DynType(_44_dt__update_hunderlying_h4); } else { - return RAST.Type.create_FnType(_32_dt__update_harguments_h1, (_31_dt__update__tmp_h8).dtor_returnType); + return RAST.Type.create_Array(_44_dt__update_hunderlying_h4, (_43_dt__update__tmp_h8).dtor_size); } } } { - if (_source0.is_FnType) { - Dafny.ISequence _36_arguments = _source0.dtor_arguments; - RAST._IType _37_returnType = _source0.dtor_returnType; - RAST._IType _38_dt__update__tmp_h9 = this; - RAST._IType _39_dt__update_hreturnType_h0 = (_37_returnType).Replace(mapping); - Dafny.ISequence _40_dt__update_harguments_h2 = Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Dafny.ISequence, Func>>((_41_mapping, _42_arguments) => ((System.Func)((_43_t) => { - return (_43_t).Replace(_41_mapping); - })))(mapping, _36_arguments), _36_arguments); - return RAST.Type.create_FnType(_40_dt__update_harguments_h2, _39_dt__update_hreturnType_h0); - } + 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); + } + }))(); + return Dafny.Helpers.Id>(mapping)(_0_r); + } + public __T Fold<__T>(__T acc, Func<__T, RAST._IType, __T> f) + { + __T _0_newAcc = Dafny.Helpers.Id>(f)(acc, this); + RAST._IType _source0 = this; + { + bool disjunctiveMatch0 = false; + if (_source0.is_U8) { + disjunctiveMatch0 = true; + } + if (_source0.is_U16) { + disjunctiveMatch0 = true; + } + if (_source0.is_U32) { + disjunctiveMatch0 = true; + } + if (_source0.is_U64) { + disjunctiveMatch0 = true; + } + if (_source0.is_U128) { + disjunctiveMatch0 = true; + } + if (_source0.is_I8) { + disjunctiveMatch0 = true; + } + if (_source0.is_I16) { + disjunctiveMatch0 = true; + } + if (_source0.is_I32) { + disjunctiveMatch0 = true; + } + if (_source0.is_I64) { + disjunctiveMatch0 = true; + } + if (_source0.is_I128) { + disjunctiveMatch0 = true; + } + if (_source0.is_Bool) { + disjunctiveMatch0 = true; + } + if (disjunctiveMatch0) { + return _0_newAcc; + } + } + { + if (_source0.is_TIdentifier) { + return _0_newAcc; + } + } + { + if (_source0.is_TypeFromPath) { + RAST._IPath _1_path = _source0.dtor_path; + return _0_newAcc; + } + } + { + if (_source0.is_TypeApp) { + RAST._IType _2_baseName = _source0.dtor_baseName; + Dafny.ISequence _3_arguments = _source0.dtor_arguments; + return Std.Collections.Seq.__default.FoldLeft<__T, RAST._IType>(Dafny.Helpers.Id, Func<__T, RAST._IType, __T>>>((_4_f) => ((System.Func<__T, RAST._IType, __T>)((_5_acc, _6_argType) => { + return (_6_argType).Fold<__T>(_5_acc, _4_f); + })))(f), (_2_baseName).Fold<__T>(_0_newAcc, f), _3_arguments); + } + } + { + if (_source0.is_Borrowed) { + RAST._IType _7_underlying = _source0.dtor_underlying; + return (_7_underlying).Fold<__T>(_0_newAcc, f); + } + } + { + if (_source0.is_BorrowedMut) { + RAST._IType _8_underlying = _source0.dtor_underlying; + return (_8_underlying).Fold<__T>(_0_newAcc, f); + } + } + { + if (_source0.is_ImplType) { + RAST._IType _9_underlying = _source0.dtor_underlying; + return (_9_underlying).Fold<__T>(_0_newAcc, f); + } + } + { + if (_source0.is_DynType) { + RAST._IType _10_underlying = _source0.dtor_underlying; + return (_10_underlying).Fold<__T>(_0_newAcc, f); + } + } + { + if (_source0.is_TupleType) { + Dafny.ISequence _11_arguments = _source0.dtor_arguments; + return Std.Collections.Seq.__default.FoldLeft<__T, RAST._IType>(Dafny.Helpers.Id, Func<__T, RAST._IType, __T>>>((_12_f) => ((System.Func<__T, RAST._IType, __T>)((_13_acc, _14_argType) => { + return (_14_argType).Fold<__T>(_13_acc, _12_f); + })))(f), _0_newAcc, _11_arguments); } - { - if (_source0.is_IntersectionType) { - RAST._IType _44_left = _source0.dtor_left; - RAST._IType _45_right = _source0.dtor_right; - RAST._IType _46_dt__update__tmp_h10 = this; - RAST._IType _47_dt__update_hright_h0 = (_45_right).Replace(mapping); - RAST._IType _48_dt__update_hleft_h0 = (_44_left).Replace(mapping); - return RAST.Type.create_IntersectionType(_48_dt__update_hleft_h0, _47_dt__update_hright_h0); - } + } + { + if (_source0.is_FnType) { + Dafny.ISequence _15_arguments = _source0.dtor_arguments; + RAST._IType _16_returnType = _source0.dtor_returnType; + return (_16_returnType).Fold<__T>(Std.Collections.Seq.__default.FoldLeft<__T, RAST._IType>(Dafny.Helpers.Id, Func<__T, RAST._IType, __T>>>((_17_f) => ((System.Func<__T, RAST._IType, __T>)((_18_acc, _19_argType) => { + return (_19_argType).Fold<__T>(_18_acc, _17_f); + })))(f), _0_newAcc, _15_arguments), f); } - { - RAST._IType _49_underlying = _source0.dtor_underlying; - Std.Wrappers._IOption> _50_size = _source0.dtor_size; - RAST._IType _51_dt__update__tmp_h11 = this; - RAST._IType _52_dt__update_hunderlying_h6 = (_49_underlying).Replace(mapping); - if ((_51_dt__update__tmp_h11).is_Borrowed) { - return RAST.Type.create_Borrowed(_52_dt__update_hunderlying_h6); - } else if ((_51_dt__update__tmp_h11).is_BorrowedMut) { - return RAST.Type.create_BorrowedMut(_52_dt__update_hunderlying_h6); - } else if ((_51_dt__update__tmp_h11).is_Pointer) { - return RAST.Type.create_Pointer(_52_dt__update_hunderlying_h6); - } else if ((_51_dt__update__tmp_h11).is_PointerMut) { - return RAST.Type.create_PointerMut(_52_dt__update_hunderlying_h6); - } else if ((_51_dt__update__tmp_h11).is_ImplType) { - return RAST.Type.create_ImplType(_52_dt__update_hunderlying_h6); - } else if ((_51_dt__update__tmp_h11).is_DynType) { - return RAST.Type.create_DynType(_52_dt__update_hunderlying_h6); - } else { - return RAST.Type.create_Array(_52_dt__update_hunderlying_h6, (_51_dt__update__tmp_h11).dtor_size); - } + } + { + if (_source0.is_IntersectionType) { + RAST._IType _20_left = _source0.dtor_left; + RAST._IType _21_right = _source0.dtor_right; + return (_21_right).Fold<__T>((_20_left).Fold<__T>(_0_newAcc, f), f); + } + } + { + if (_source0.is_Array) { + RAST._IType _22_underlying = _source0.dtor_underlying; + Std.Wrappers._IOption> _23_size = _source0.dtor_size; + return (_22_underlying).Fold<__T>(_0_newAcc, f); } } + { + RAST._IType _24_display = _source0.dtor_display; + RAST._IType _25_base = _source0.dtor_base; + return (_24_display).Fold<__T>(_0_newAcc, f); + } } 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_Bool)) || ((this).is_Pointer)) || ((this).is_PointerMut); - } - public bool IsSelfPointer() { - return (((((this).is_Borrowed) && (((this).dtor_underlying).is_PointerMut)) && ((((this).dtor_underlying).dtor_underlying).is_SelfOwned)) || (((this).is_PointerMut) && (((this).dtor_underlying).is_SelfOwned))) || (((((this).is_PointerMut) && (((this).dtor_underlying).is_TypeApp)) && ((new BigInteger((((this).dtor_underlying).dtor_arguments).Count)).Sign == 0)) && ((((this).dtor_underlying).dtor_baseName).is_SelfOwned)); + 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_Bool)) || (((this).is_TSynonym) && (((this).dtor_base).CanReadWithoutClone()))) || ((this).IsPointer()); } public bool IsRcOrBorrowedRc() { - return (((this).is_TypeApp) && (object.Equals((this).dtor_baseName, RAST.__default.RcType))) || (((this).is_Borrowed) && (((this).dtor_underlying).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())); } public Std.Wrappers._IOption ExtractMaybePlacebo() { RAST._IType _source0 = this; @@ -2225,7 +2631,7 @@ public bool IsRcOrBorrowedRc() { if (_source0.is_TypeApp) { RAST._IType _0_wrapper = _source0.dtor_baseName; Dafny.ISequence _1_arguments = _source0.dtor_arguments; - if (((object.Equals(_0_wrapper, RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("MaybePlacebo")))) || (object.Equals(_0_wrapper, (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("MaybePlacebo"))))) && ((new BigInteger((_1_arguments).Count)) == (BigInteger.One))) { + if ((object.Equals(_0_wrapper, RAST.Type.create_TypeFromPath(RAST.__default.MaybePlaceboPath))) && ((new BigInteger((_1_arguments).Count)) == (BigInteger.One))) { return Std.Wrappers.Option.create_Some((_1_arguments).Select(BigInteger.Zero)); } else { return Std.Wrappers.Option.create_None(); @@ -2264,90 +2670,72 @@ public bool IsRcOrBorrowedRc() { } } { - if (_source0.is_TMemberSelect) { - RAST._IType _1_underlying = _source0.dtor_base; - Dafny.ISequence _2_name = _source0.dtor_name; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_1_underlying)._ToString(ind), Dafny.Sequence.UnicodeFromString("::")), _2_name); + if (_source0.is_TypeFromPath) { + RAST._IPath _1_underlying = _source0.dtor_path; + return (_1_underlying)._ToString(); } } { if (_source0.is_Borrowed) { - RAST._IType _3_underlying = _source0.dtor_underlying; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&"), (_3_underlying)._ToString(ind)); + RAST._IType _2_underlying = _source0.dtor_underlying; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&"), (_2_underlying)._ToString(ind)); } } { if (_source0.is_BorrowedMut) { - RAST._IType _4_underlying = _source0.dtor_underlying; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&mut "), (_4_underlying)._ToString(ind)); - } - } - { - if (_source0.is_Pointer) { - RAST._IType _5_underlying = _source0.dtor_underlying; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("*const "), (_5_underlying)._ToString(ind)); - } - } - { - if (_source0.is_PointerMut) { - RAST._IType _6_underlying = _source0.dtor_underlying; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("*mut "), (_6_underlying)._ToString(ind)); + RAST._IType _3_underlying = _source0.dtor_underlying; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&mut "), (_3_underlying)._ToString(ind)); } } { if (_source0.is_ImplType) { - RAST._IType _7_underlying = _source0.dtor_underlying; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("impl "), (_7_underlying)._ToString(ind)); + RAST._IType _4_underlying = _source0.dtor_underlying; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("impl "), (_4_underlying)._ToString(ind)); } } { if (_source0.is_DynType) { - RAST._IType _8_underlying = _source0.dtor_underlying; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("dyn "), (_8_underlying)._ToString(ind)); + RAST._IType _5_underlying = _source0.dtor_underlying; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("dyn "), (_5_underlying)._ToString(ind)); } } { if (_source0.is_FnType) { - Dafny.ISequence _9_arguments = _source0.dtor_arguments; - RAST._IType _10_returnType = _source0.dtor_returnType; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Fn("), RAST.__default.SeqToString(_9_arguments, Dafny.Helpers.Id, Func>>>((_11_ind) => ((System.Func>)((_12_arg) => { - return (_12_arg)._ToString(Dafny.Sequence.Concat(_11_ind, RAST.__default.IND)); - })))(ind), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") -> ")), (_10_returnType)._ToString(Dafny.Sequence.Concat(ind, RAST.__default.IND))); + Dafny.ISequence _6_arguments = _source0.dtor_arguments; + RAST._IType _7_returnType = _source0.dtor_returnType; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Fn("), RAST.__default.SeqToString(_6_arguments, Dafny.Helpers.Id, Func>>>((_8_ind) => ((System.Func>)((_9_arg) => { + return (_9_arg)._ToString(Dafny.Sequence.Concat(_8_ind, RAST.__default.IND)); + })))(ind), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") -> ")), (_7_returnType)._ToString(Dafny.Sequence.Concat(ind, RAST.__default.IND))); } } { if (_source0.is_IntersectionType) { - RAST._IType _13_left = _source0.dtor_left; - RAST._IType _14_right = _source0.dtor_right; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_13_left)._ToString(ind), Dafny.Sequence.UnicodeFromString(" + ")), (_14_right)._ToString(ind)); + RAST._IType _10_left = _source0.dtor_left; + RAST._IType _11_right = _source0.dtor_right; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_10_left)._ToString(ind), Dafny.Sequence.UnicodeFromString(" + ")), (_11_right)._ToString(ind)); } } { if (_source0.is_TupleType) { - Dafny.ISequence _15_args = _source0.dtor_arguments; - if ((_15_args).Equals(Dafny.Sequence.FromElements())) { + Dafny.ISequence _12_args = _source0.dtor_arguments; + if ((_12_args).Equals(Dafny.Sequence.FromElements())) { return Dafny.Sequence.UnicodeFromString("()"); } else { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString(_15_args, Dafny.Helpers.Id, Func>>>((_16_ind) => ((System.Func>)((_17_arg) => { - return (_17_arg)._ToString(Dafny.Sequence.Concat(_16_ind, RAST.__default.IND)); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString(_12_args, Dafny.Helpers.Id, Func>>>((_13_ind) => ((System.Func>)((_14_arg) => { + return (_14_arg)._ToString(Dafny.Sequence.Concat(_13_ind, RAST.__default.IND)); })))(ind), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(")")); } } } { if (_source0.is_TypeApp) { - RAST._IType _18_base = _source0.dtor_baseName; - Dafny.ISequence _19_args = _source0.dtor_arguments; - return Dafny.Sequence.Concat((_18_base)._ToString(ind), (((_19_args).Equals(Dafny.Sequence.FromElements())) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), RAST.__default.SeqToString(_19_args, Dafny.Helpers.Id, Func>>>((_20_ind) => ((System.Func>)((_21_arg) => { - return (_21_arg)._ToString(Dafny.Sequence.Concat(_20_ind, RAST.__default.IND)); + RAST._IType _15_base = _source0.dtor_baseName; + Dafny.ISequence _16_args = _source0.dtor_arguments; + return Dafny.Sequence.Concat((_15_base)._ToString(ind), (((_16_args).Equals(Dafny.Sequence.FromElements())) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), RAST.__default.SeqToString(_16_args, Dafny.Helpers.Id, Func>>>((_17_ind) => ((System.Func>)((_18_arg) => { + return (_18_arg)._ToString(Dafny.Sequence.Concat(_17_ind, RAST.__default.IND)); })))(ind), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(">"))))); } } - { - if (_source0.is_SelfOwned) { - return Dafny.Sequence.UnicodeFromString("Self"); - } - } { if (_source0.is_U8) { return Dafny.Sequence.UnicodeFromString("u8"); @@ -2399,13 +2787,17 @@ public bool IsRcOrBorrowedRc() { } } { - RAST._IType _22_underlying = _source0.dtor_underlying; - Std.Wrappers._IOption> _23_size = _source0.dtor_size; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("["), (_22_underlying)._ToString(ind)), (((_23_size).is_Some) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("; "), (_23_size).dtor_value)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString("]")); + if (_source0.is_Array) { + RAST._IType _19_underlying = _source0.dtor_underlying; + Std.Wrappers._IOption> _20_size = _source0.dtor_size; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("["), (_19_underlying)._ToString(ind)), (((_20_size).is_Some) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("; "), (_20_size).dtor_value)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString("]")); + } + } + { + RAST._IType _21_display = _source0.dtor_display; + RAST._IType _22_base = _source0.dtor_base; + return (_21_display)._ToString(ind); } - } - public RAST._IType MSel(Dafny.ISequence name) { - return RAST.Type.create_TMemberSelect(this, name); } public RAST._IType Apply1(RAST._IType arg) { return RAST.Type.create_TypeApp(this, Dafny.Sequence.FromElements(arg)); @@ -2433,26 +2825,21 @@ public RAST._IType ToOwned() { } } public RAST._IExpr ToNullExpr() { - if ((this).IsObject()) { - return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).Apply1((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("option"))).MSel(Dafny.Sequence.UnicodeFromString("Option"))).MSel(Dafny.Sequence.UnicodeFromString("None"))); + if (((this).Expand()).IsObject()) { + return ((RAST.__default.Object).FSel(Dafny.Sequence.UnicodeFromString("null"))).Apply(Dafny.Sequence.FromElements()); } else { - RAST._IType _0_underlying = (this).dtor_underlying; - Dafny.ISequence _1_n = (((this).is_PointerMut) ? (Dafny.Sequence.UnicodeFromString("null_mut")) : (Dafny.Sequence.UnicodeFromString("null"))); - if (((_0_underlying).is_Array) && (((_0_underlying).dtor_size).is_None)) { - return ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ptr"))).MSel(_1_n)).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_Array((_0_underlying).dtor_underlying, Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("0")))))).Apply(Dafny.Sequence.FromElements()); - } else { - return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ptr"))).MSel(_1_n)).Apply(Dafny.Sequence.FromElements()); - } + return ((RAST.__default.Ptr).FSel(Dafny.Sequence.UnicodeFromString("null"))).Apply(Dafny.Sequence.FromElements()); } } public bool IsMultiArray() { - return ((this).is_TypeApp) && (Dafny.Helpers.Let((this).dtor_baseName, _pat_let5_0 => Dafny.Helpers.Let(_pat_let5_0, _0_baseName => Dafny.Helpers.Let, bool>((this).dtor_arguments, _pat_let6_0 => Dafny.Helpers.Let, bool>(_pat_let6_0, _1_args => (((((new BigInteger((_1_args).Count)) == (BigInteger.One)) && ((_0_baseName).is_TMemberSelect)) && (object.Equals((_0_baseName).dtor_base, RAST.__default.dafny__runtime__type))) && ((new BigInteger(((_0_baseName).dtor_name).Count)) >= (new BigInteger(5)))) && ((((_0_baseName).dtor_name).Subsequence(BigInteger.Zero, new BigInteger(5))).Equals(Dafny.Sequence.UnicodeFromString("Array")))))))); + RAST._IType _0_t = (this).Expand(); + return ((_0_t).is_TypeApp) && (Dafny.Helpers.Let((_0_t).dtor_baseName, _pat_let5_0 => Dafny.Helpers.Let(_pat_let5_0, _1_baseName => Dafny.Helpers.Let, bool>((_0_t).dtor_arguments, _pat_let6_0 => Dafny.Helpers.Let, bool>(_pat_let6_0, _2_args => ((((((new BigInteger((_2_args).Count)) == (BigInteger.One)) && ((_1_baseName).is_TypeFromPath)) && (((_1_baseName).dtor_path).is_PMemberSelect)) && (object.Equals(((_1_baseName).dtor_path).dtor_base, RAST.__default.dafny__runtime))) && ((new BigInteger((((_1_baseName).dtor_path).dtor_name).Count)) >= (new BigInteger(5)))) && (((((_1_baseName).dtor_path).dtor_name).Subsequence(BigInteger.Zero, new BigInteger(5))).Equals(Dafny.Sequence.UnicodeFromString("Array")))))))); } public Dafny.ISequence MultiArrayClass() { - return ((this).dtor_baseName).dtor_name; + return ((((this).Expand()).dtor_baseName).dtor_path).dtor_name; } public RAST._IType MultiArrayUnderlying() { - return ((this).dtor_arguments).Select(BigInteger.Zero); + return (((this).Expand()).dtor_arguments).Select(BigInteger.Zero); } public RAST._IType TypeAtInitialization() { if ((this).IsObjectOrPointer()) { @@ -2462,14 +2849,14 @@ public RAST._IType TypeAtInitialization() { if ((this).IsObject()) { return RAST.__default.ObjectType(_1_newUnderlying); } else { - return RAST.Type.create_PointerMut(_1_newUnderlying); + return RAST.__default.PtrType(_1_newUnderlying); } } else if ((_0_s).IsMultiArray()) { - RAST._IType _2_newUnderlying = RAST.Type.create_TypeApp((_0_s).dtor_baseName, Dafny.Sequence.FromElements(RAST.__default.MaybeUninitType(((_0_s).dtor_arguments).Select(BigInteger.Zero)))); + RAST._IType _2_newUnderlying = RAST.Type.create_TypeApp(((_0_s).Expand()).dtor_baseName, Dafny.Sequence.FromElements(RAST.__default.MaybeUninitType((((_0_s).Expand()).dtor_arguments).Select(BigInteger.Zero)))); if ((this).IsObject()) { return RAST.__default.ObjectType(_2_newUnderlying); } else { - return RAST.Type.create_PointerMut(_2_newUnderlying); + return RAST.__default.PtrType(_2_newUnderlying); } } else { return this; @@ -2479,11 +2866,11 @@ public RAST._IType TypeAtInitialization() { } } public bool IsMaybeUninit() { - return (((this).is_TypeApp) && (object.Equals((this).dtor_baseName, RAST.__default.MaybeUninitPath))) && ((new BigInteger(((this).dtor_arguments).Count)) == (BigInteger.One)); + return ((((this).is_TypeApp) && (((this).dtor_baseName).is_TypeFromPath)) && (object.Equals(((this).dtor_baseName).dtor_path, RAST.__default.MaybeUninitPath))) && ((new BigInteger(((this).dtor_arguments).Count)) == (BigInteger.One)); } public bool IsUninitArray() { if ((this).IsObjectOrPointer()) { - RAST._IType _0_s = (this).ObjectOrPointerUnderlying(); + RAST._IType _0_s = ((this).ObjectOrPointerUnderlying()).Expand(); if (((_0_s).is_Array) && (((_0_s).dtor_size).is_None)) { return ((_0_s).dtor_underlying).IsMaybeUninit(); } else if ((_0_s).IsMultiArray()) { @@ -2500,24 +2887,10 @@ public bool IsObject() { { if (_source0.is_TypeApp) { RAST._IType baseName0 = _source0.dtor_baseName; - if (baseName0.is_TMemberSelect) { - RAST._IType base0 = baseName0.dtor_base; - if (base0.is_TMemberSelect) { - RAST._IType base1 = base0.dtor_base; - if (base1.is_TIdentifier) { - Dafny.ISequence name0 = base1.dtor_name; - if (object.Equals(name0, Dafny.Sequence.UnicodeFromString(""))) { - Dafny.ISequence name1 = base0.dtor_name; - if (object.Equals(name1, Dafny.Sequence.UnicodeFromString("dafny_runtime"))) { - Dafny.ISequence name2 = baseName0.dtor_name; - if (object.Equals(name2, Dafny.Sequence.UnicodeFromString("Object"))) { - Dafny.ISequence _0_elems1 = _source0.dtor_arguments; - return (new BigInteger((_0_elems1).Count)) == (BigInteger.One); - } - } - } - } - } + if (baseName0.is_TypeFromPath) { + RAST._IPath _0_o = baseName0.dtor_path; + Dafny.ISequence _1_elems1 = _source0.dtor_arguments; + return (object.Equals(_0_o, RAST.__default.ObjectPath)) && ((new BigInteger((_1_elems1).Count)) == (BigInteger.One)); } } } @@ -2526,42 +2899,52 @@ public bool IsObject() { } } public bool IsPointer() { - return ((this).is_Pointer) || ((this).is_PointerMut); + RAST._IType _source0 = this; + { + if (_source0.is_TypeApp) { + RAST._IType baseName0 = _source0.dtor_baseName; + if (baseName0.is_TypeFromPath) { + RAST._IPath _0_o = baseName0.dtor_path; + Dafny.ISequence _1_elems1 = _source0.dtor_arguments; + return (object.Equals(_0_o, RAST.__default.PtrPath)) && ((new BigInteger((_1_elems1).Count)) == (BigInteger.One)); + } + } + } + { + return false; + } } - public bool IsObjectOrPointer() { - return ((this).IsPointer()) || ((this).IsObject()); + public bool IsObjectOrPointer() + { + bool _hresult = false; + RAST._IType _0_t; + _0_t = (this).Expand(); + _hresult = ((_0_t).IsPointer()) || ((_0_t).IsObject()); + return _hresult; + return _hresult; } public RAST._IType ObjectOrPointerUnderlying() { - if (((this).is_PointerMut) || ((this).is_Pointer)) { - return (this).dtor_underlying; - } else { - RAST._IType _source0 = this; - { - RAST._IType baseName0 = _source0.dtor_baseName; - RAST._IType base0 = baseName0.dtor_base; - RAST._IType base1 = base0.dtor_base; - Dafny.ISequence name0 = base1.dtor_name; - Dafny.ISequence name1 = base0.dtor_name; - Dafny.ISequence _0_elems1 = _source0.dtor_arguments; - return (_0_elems1).Select(BigInteger.Zero); - } + RAST._IType _source0 = (this).Expand(); + { + Dafny.ISequence _0_elems1 = _source0.dtor_arguments; + return (_0_elems1).Select(BigInteger.Zero); } } public bool IsBuiltinCollection() { - RAST._IType _source0 = this; + RAST._IType _source0 = (this).Expand(); { if (_source0.is_TypeApp) { RAST._IType baseName0 = _source0.dtor_baseName; - if (baseName0.is_TMemberSelect) { - RAST._IType base0 = baseName0.dtor_base; - if (base0.is_TMemberSelect) { - RAST._IType base1 = base0.dtor_base; - if (base1.is_TIdentifier) { - Dafny.ISequence name0 = base1.dtor_name; - if (object.Equals(name0, Dafny.Sequence.UnicodeFromString(""))) { - Dafny.ISequence name1 = base0.dtor_name; - if (object.Equals(name1, Dafny.Sequence.UnicodeFromString("dafny_runtime"))) { - Dafny.ISequence _0_tpe = baseName0.dtor_name; + if (baseName0.is_TypeFromPath) { + RAST._IPath path0 = baseName0.dtor_path; + if (path0.is_PMemberSelect) { + RAST._IPath base0 = path0.dtor_base; + if (base0.is_PMemberSelect) { + RAST._IPath base1 = base0.dtor_base; + if (base1.is_Global) { + Dafny.ISequence name0 = base0.dtor_name; + if (object.Equals(name0, Dafny.Sequence.UnicodeFromString("dafny_runtime"))) { + Dafny.ISequence _0_tpe = path0.dtor_name; Dafny.ISequence _1_elems1 = _source0.dtor_arguments; return (((((_0_tpe).Equals(Dafny.Sequence.UnicodeFromString("Set"))) || ((_0_tpe).Equals(Dafny.Sequence.UnicodeFromString("Sequence")))) || ((_0_tpe).Equals(Dafny.Sequence.UnicodeFromString("Multiset")))) && ((new BigInteger((_1_elems1).Count)) == (BigInteger.One))) || (((_0_tpe).Equals(Dafny.Sequence.UnicodeFromString("Map"))) && ((new BigInteger((_1_elems1).Count)) == (new BigInteger(2)))); } @@ -2576,14 +2959,14 @@ public bool IsBuiltinCollection() { } } public RAST._IType GetBuiltinCollectionElement() { - RAST._IType _source0 = this; + RAST._IType _source0 = (this).Expand(); { RAST._IType baseName0 = _source0.dtor_baseName; - RAST._IType base0 = baseName0.dtor_base; - RAST._IType base1 = base0.dtor_base; - Dafny.ISequence name0 = base1.dtor_name; - Dafny.ISequence name1 = base0.dtor_name; - Dafny.ISequence _0_tpe = baseName0.dtor_name; + RAST._IPath path0 = baseName0.dtor_path; + RAST._IPath base0 = path0.dtor_base; + RAST._IPath base1 = base0.dtor_base; + Dafny.ISequence name0 = base0.dtor_name; + Dafny.ISequence _0_tpe = path0.dtor_name; Dafny.ISequence _1_elems = _source0.dtor_arguments; if ((_0_tpe).Equals(Dafny.Sequence.UnicodeFromString("Map"))) { return (_1_elems).Select(BigInteger.One); @@ -2599,27 +2982,6 @@ public RAST._IType RcUnderlying() { return ((this).dtor_arguments).Select(BigInteger.Zero); } } - public class Type_SelfOwned : Type { - public Type_SelfOwned() : base() { - } - public override _IType DowncastClone() { - if (this is _IType dt) { return dt; } - return new Type_SelfOwned(); - } - public override bool Equals(object other) { - var oth = other as RAST.Type_SelfOwned; - return oth != null; - } - public override int GetHashCode() { - ulong hash = 5381; - hash = ((hash << 5) + hash) + 0; - return (int) hash; - } - public override string ToString() { - string s = "RAST.Type.SelfOwned"; - return s; - } - } public class Type_U8 : Type { public Type_U8() : base() { } @@ -2633,7 +2995,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + 0; return (int) hash; } public override string ToString() { @@ -2654,7 +3016,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + 1; return (int) hash; } public override string ToString() { @@ -2675,7 +3037,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + 2; return (int) hash; } public override string ToString() { @@ -2696,7 +3058,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 4; + hash = ((hash << 5) + hash) + 3; return (int) hash; } public override string ToString() { @@ -2717,7 +3079,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 5; + hash = ((hash << 5) + hash) + 4; return (int) hash; } public override string ToString() { @@ -2738,7 +3100,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 6; + hash = ((hash << 5) + hash) + 5; return (int) hash; } public override string ToString() { @@ -2759,7 +3121,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 7; + hash = ((hash << 5) + hash) + 6; return (int) hash; } public override string ToString() { @@ -2780,7 +3142,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 8; + hash = ((hash << 5) + hash) + 7; return (int) hash; } public override string ToString() { @@ -2801,7 +3163,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 9; + hash = ((hash << 5) + hash) + 8; return (int) hash; } public override string ToString() { @@ -2822,7 +3184,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 10; + hash = ((hash << 5) + hash) + 9; return (int) hash; } public override string ToString() { @@ -2843,7 +3205,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 11; + hash = ((hash << 5) + hash) + 10; return (int) hash; } public override string ToString() { @@ -2866,7 +3228,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 12; + hash = ((hash << 5) + hash) + 11; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); return (int) hash; } @@ -2878,34 +3240,29 @@ public override string ToString() { return s; } } - public class Type_TMemberSelect : Type { - public readonly RAST._IType _base; - public readonly Dafny.ISequence _name; - public Type_TMemberSelect(RAST._IType @base, Dafny.ISequence name) : base() { - this._base = @base; - this._name = name; + public class Type_TypeFromPath : Type { + public readonly RAST._IPath _path; + public Type_TypeFromPath(RAST._IPath path) : base() { + this._path = path; } public override _IType DowncastClone() { if (this is _IType dt) { return dt; } - return new Type_TMemberSelect(_base, _name); + return new Type_TypeFromPath(_path); } public override bool Equals(object other) { - var oth = other as RAST.Type_TMemberSelect; - return oth != null && object.Equals(this._base, oth._base) && object.Equals(this._name, oth._name); + var oth = other as RAST.Type_TypeFromPath; + return oth != null && object.Equals(this._path, oth._path); } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 13; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._base)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); + hash = ((hash << 5) + hash) + 12; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._path)); return (int) hash; } public override string ToString() { - string s = "RAST.Type.TMemberSelect"; + string s = "RAST.Type.TypeFromPath"; s += "("; - s += Dafny.Helpers.ToString(this._base); - s += ", "; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._path); s += ")"; return s; } @@ -2927,7 +3284,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 14; + hash = ((hash << 5) + hash) + 13; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._baseName)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._arguments)); return (int) hash; @@ -2957,7 +3314,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 15; + hash = ((hash << 5) + hash) + 14; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); return (int) hash; } @@ -2984,7 +3341,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 16; + hash = ((hash << 5) + hash) + 15; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); return (int) hash; } @@ -2996,60 +3353,6 @@ public override string ToString() { return s; } } - public class Type_Pointer : Type { - public readonly RAST._IType _underlying; - public Type_Pointer(RAST._IType underlying) : base() { - this._underlying = underlying; - } - public override _IType DowncastClone() { - if (this is _IType dt) { return dt; } - return new Type_Pointer(_underlying); - } - public override bool Equals(object other) { - var oth = other as RAST.Type_Pointer; - return oth != null && object.Equals(this._underlying, oth._underlying); - } - public override int GetHashCode() { - ulong hash = 5381; - hash = ((hash << 5) + hash) + 17; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); - return (int) hash; - } - public override string ToString() { - string s = "RAST.Type.Pointer"; - s += "("; - s += Dafny.Helpers.ToString(this._underlying); - s += ")"; - return s; - } - } - public class Type_PointerMut : Type { - public readonly RAST._IType _underlying; - public Type_PointerMut(RAST._IType underlying) : base() { - this._underlying = underlying; - } - public override _IType DowncastClone() { - if (this is _IType dt) { return dt; } - return new Type_PointerMut(_underlying); - } - public override bool Equals(object other) { - var oth = other as RAST.Type_PointerMut; - return oth != null && object.Equals(this._underlying, oth._underlying); - } - public override int GetHashCode() { - ulong hash = 5381; - hash = ((hash << 5) + hash) + 18; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); - return (int) hash; - } - public override string ToString() { - string s = "RAST.Type.PointerMut"; - s += "("; - s += Dafny.Helpers.ToString(this._underlying); - s += ")"; - return s; - } - } public class Type_ImplType : Type { public readonly RAST._IType _underlying; public Type_ImplType(RAST._IType underlying) : base() { @@ -3065,7 +3368,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 19; + hash = ((hash << 5) + hash) + 16; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); return (int) hash; } @@ -3092,7 +3395,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 20; + hash = ((hash << 5) + hash) + 17; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); return (int) hash; } @@ -3119,7 +3422,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 21; + hash = ((hash << 5) + hash) + 18; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._arguments)); return (int) hash; } @@ -3148,7 +3451,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 22; + hash = ((hash << 5) + hash) + 19; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._arguments)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._returnType)); return (int) hash; @@ -3180,7 +3483,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 23; + hash = ((hash << 5) + hash) + 20; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._left)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._right)); return (int) hash; @@ -3212,7 +3515,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 24; + hash = ((hash << 5) + hash) + 21; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._size)); return (int) hash; @@ -3227,6 +3530,38 @@ public override string ToString() { return s; } } + public class Type_TSynonym : Type { + public readonly RAST._IType _display; + public readonly RAST._IType _base; + public Type_TSynonym(RAST._IType display, RAST._IType @base) : base() { + this._display = display; + this._base = @base; + } + public override _IType DowncastClone() { + if (this is _IType dt) { return dt; } + return new Type_TSynonym(_display, _base); + } + public override bool Equals(object other) { + var oth = other as RAST.Type_TSynonym; + return oth != null && object.Equals(this._display, oth._display) && object.Equals(this._base, oth._base); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 22; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._display)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._base)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.Type.TSynonym"; + s += "("; + s += Dafny.Helpers.ToString(this._display); + s += ", "; + s += Dafny.Helpers.ToString(this._base); + s += ")"; + return s; + } + } public interface _ITrait { bool is_Trait { get; } @@ -3794,7 +4129,7 @@ public RAST._IType dtor_tpe { } } public Dafny.ISequence _ToString(Dafny.ISequence ind) { - if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("self"))) && (object.Equals((this).dtor_tpe, RAST.Type.create_SelfOwned()))) { + if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("self"))) && (object.Equals((this).dtor_tpe, 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); @@ -3808,7 +4143,7 @@ public static RAST._IFormal selfBorrowed { get { return RAST.Formal.create(Dafny.Sequence.UnicodeFromString("self"), RAST.__default.SelfBorrowed); } } public static RAST._IFormal selfOwned { get { - return RAST.Formal.create(Dafny.Sequence.UnicodeFromString("self"), RAST.Type.create_SelfOwned()); + return RAST.Formal.create(Dafny.Sequence.UnicodeFromString("self"), RAST.__default.SelfOwned); } } public static RAST._IFormal selfBorrowedMut { get { return RAST.Formal.create(Dafny.Sequence.UnicodeFromString("self"), RAST.__default.SelfBorrowedMut); @@ -4605,7 +4940,8 @@ public interface _IExpr { bool is_Call { get; } bool is_Select { get; } bool is_SelectIndex { get; } - bool is_MemberSelect { get; } + bool is_ExprFromPath { get; } + bool is_FunctionSelect { get; } bool is_Lambda { get; } Dafny.ISequence dtor_content { get; } RAST._IType dtor_tpe { get; } @@ -4642,6 +4978,7 @@ public interface _IExpr { Std.Wrappers._IOption dtor_optExpr { get; } RAST._IExpr dtor_obj { get; } Dafny.ISequence dtor_typeParameters { get; } + RAST._IPath dtor_path { get; } Dafny.ISequence dtor_params { get; } Std.Wrappers._IOption dtor_retType { get; } _IExpr DowncastClone(); @@ -4656,7 +4993,7 @@ public interface _IExpr { Dafny.ISequence _ToString(Dafny.ISequence ind); RAST._IExpr Then(RAST._IExpr rhs2); RAST._IExpr Sel(Dafny.ISequence name); - RAST._IExpr MSel(Dafny.ISequence name); + RAST._IExpr FSel(Dafny.ISequence name); RAST._IExpr ApplyType(Dafny.ISequence typeParameters); RAST._IExpr ApplyType1(RAST._IType typeParameter); RAST._IExpr Apply(Dafny.ISequence arguments); @@ -4757,8 +5094,11 @@ public static _IExpr create_Select(RAST._IExpr obj, Dafny.ISequence public static _IExpr create_SelectIndex(RAST._IExpr obj, RAST._IExpr range) { return new Expr_SelectIndex(obj, range); } - public static _IExpr create_MemberSelect(RAST._IExpr obj, Dafny.ISequence name) { - return new Expr_MemberSelect(obj, name); + public static _IExpr create_ExprFromPath(RAST._IPath path) { + return new Expr_ExprFromPath(path); + } + public static _IExpr create_FunctionSelect(RAST._IExpr obj, Dafny.ISequence name) { + return new Expr_FunctionSelect(obj, name); } public static _IExpr create_Lambda(Dafny.ISequence @params, Std.Wrappers._IOption retType, RAST._IExpr body) { return new Expr_Lambda(@params, retType, body); @@ -4790,7 +5130,8 @@ public static _IExpr create_Lambda(Dafny.ISequence @params, Std.W public bool is_Call { get { return this is Expr_Call; } } public bool is_Select { get { return this is Expr_Select; } } public bool is_SelectIndex { get { return this is Expr_SelectIndex; } } - public bool is_MemberSelect { get { return this is Expr_MemberSelect; } } + public bool is_ExprFromPath { get { return this is Expr_ExprFromPath; } } + public bool is_FunctionSelect { get { return this is Expr_FunctionSelect; } } public bool is_Lambda { get { return this is Expr_Lambda; } } public Dafny.ISequence dtor_content { get { @@ -4812,7 +5153,7 @@ public Dafny.ISequence dtor_name { if (d is Expr_DeclareVar) { return ((Expr_DeclareVar)d)._name; } if (d is Expr_For) { return ((Expr_For)d)._name; } if (d is Expr_Select) { return ((Expr_Select)d)._name; } - return ((Expr_MemberSelect)d)._name; + return ((Expr_FunctionSelect)d)._name; } } public RAST._IExpr dtor_matchee { @@ -5013,7 +5354,7 @@ public RAST._IExpr dtor_obj { if (d is Expr_Call) { return ((Expr_Call)d)._obj; } if (d is Expr_Select) { return ((Expr_Select)d)._obj; } if (d is Expr_SelectIndex) { return ((Expr_SelectIndex)d)._obj; } - return ((Expr_MemberSelect)d)._obj; + return ((Expr_FunctionSelect)d)._obj; } } public Dafny.ISequence dtor_typeParameters { @@ -5022,6 +5363,12 @@ public Dafny.ISequence dtor_typeParameters { return ((Expr_CallType)d)._typeParameters; } } + public RAST._IPath dtor_path { + get { + var d = this; + return ((Expr_ExprFromPath)d)._path; + } + } public Dafny.ISequence dtor_params { get { var d = this; @@ -5107,59 +5454,65 @@ public RAST._IExpr Optimize() { { if (_source0.is_Call) { RAST._IExpr obj0 = _source0.dtor_obj; - if (obj0.is_MemberSelect) { - RAST._IExpr _7_r = obj0.dtor_obj; - Dafny.ISequence name0 = obj0.dtor_name; - if (object.Equals(name0, Dafny.Sequence.UnicodeFromString("truncate!"))) { - Dafny.ISequence _8_args = _source0.dtor_arguments; - if (((!object.Equals(_7_r, RAST.__default.dafny__runtime)) && (!object.Equals(_7_r, RAST.__default.@global))) || ((new BigInteger((_8_args).Count)) != (new BigInteger(2)))) { - return this; - } else { - RAST._IExpr _9_expr = (_8_args).Select(BigInteger.Zero); - RAST._IExpr _10_tpeExpr = (_8_args).Select(BigInteger.One); - if (!((_10_tpeExpr).is_ExprFromType)) { + if (obj0.is_ExprFromPath) { + RAST._IPath path0 = obj0.dtor_path; + if (path0.is_PMemberSelect) { + RAST._IPath _7_r = path0.dtor_base; + Dafny.ISequence name0 = path0.dtor_name; + if (object.Equals(name0, Dafny.Sequence.UnicodeFromString("truncate!"))) { + Dafny.ISequence _8_args = _source0.dtor_arguments; + if (((!object.Equals(_7_r, RAST.__default.dafny__runtime)) && (!object.Equals(_7_r, RAST.__default.@global))) || ((new BigInteger((_8_args).Count)) != (new BigInteger(2)))) { return this; } else { - RAST._IType _11_tpe = (_10_tpeExpr).dtor_tpe; - if (((((((((((_11_tpe).is_U8) || ((_11_tpe).is_U16)) || ((_11_tpe).is_U32)) || ((_11_tpe).is_U64)) || ((_11_tpe).is_U128)) || ((_11_tpe).is_I8)) || ((_11_tpe).is_I16)) || ((_11_tpe).is_I32)) || ((_11_tpe).is_I64)) || ((_11_tpe).is_I128)) { - RAST._IExpr _source1 = _9_expr; - { - if (_source1.is_Call) { - RAST._IExpr obj1 = _source1.dtor_obj; - if (obj1.is_MemberSelect) { - RAST._IExpr _12_base = obj1.dtor_obj; - Dafny.ISequence name1 = obj1.dtor_name; - if (object.Equals(name1, Dafny.Sequence.UnicodeFromString("int!"))) { - Dafny.ISequence _13_args = _source1.dtor_arguments; - if (((new BigInteger((_13_args).Count)) == (BigInteger.One)) && ((object.Equals(_12_base, RAST.__default.dafny__runtime)) || (object.Equals(_12_base, RAST.__default.@global)))) { - RAST._IExpr _source2 = (_13_args).Select(BigInteger.Zero); - { - if (_source2.is_LiteralInt) { - Dafny.ISequence _14_number = _source2.dtor_value; - return RAST.Expr.create_LiteralInt(_14_number); - } - } - { - if (_source2.is_LiteralString) { - Dafny.ISequence _15_number = _source2.dtor_value; - return RAST.Expr.create_LiteralInt(_15_number); + RAST._IExpr _9_expr = (_8_args).Select(BigInteger.Zero); + RAST._IExpr _10_tpeExpr = (_8_args).Select(BigInteger.One); + if (!((_10_tpeExpr).is_ExprFromType)) { + return this; + } else { + RAST._IType _11_tpe = (_10_tpeExpr).dtor_tpe; + if (((((((((((_11_tpe).is_U8) || ((_11_tpe).is_U16)) || ((_11_tpe).is_U32)) || ((_11_tpe).is_U64)) || ((_11_tpe).is_U128)) || ((_11_tpe).is_I8)) || ((_11_tpe).is_I16)) || ((_11_tpe).is_I32)) || ((_11_tpe).is_I64)) || ((_11_tpe).is_I128)) { + RAST._IExpr _source1 = _9_expr; + { + if (_source1.is_Call) { + RAST._IExpr obj1 = _source1.dtor_obj; + if (obj1.is_ExprFromPath) { + RAST._IPath path1 = obj1.dtor_path; + if (path1.is_PMemberSelect) { + RAST._IPath _12_base = path1.dtor_base; + Dafny.ISequence name1 = path1.dtor_name; + if (object.Equals(name1, Dafny.Sequence.UnicodeFromString("int!"))) { + Dafny.ISequence _13_args = _source1.dtor_arguments; + if (((new BigInteger((_13_args).Count)) == (BigInteger.One)) && ((object.Equals(_12_base, RAST.__default.dafny__runtime)) || (object.Equals(_12_base, RAST.__default.@global)))) { + RAST._IExpr _source2 = (_13_args).Select(BigInteger.Zero); + { + if (_source2.is_LiteralInt) { + Dafny.ISequence _14_number = _source2.dtor_value; + return RAST.Expr.create_LiteralInt(_14_number); + } + } + { + if (_source2.is_LiteralString) { + Dafny.ISequence _15_number = _source2.dtor_value; + return RAST.Expr.create_LiteralInt(_15_number); + } + } + { + return this; + } + } else { + return this; } } - { - return this; - } - } else { - return this; } } } } - } - { + { + return this; + } + } else { return this; } - } else { - return this; } } } @@ -5241,7 +5594,7 @@ public RAST._IExpr Optimize() { } } public bool LeftRequiresParentheses(RAST._IExpr left) { - return ((this).printingInfo).NeedParenthesesForLeft((left).printingInfo); + return ((this).printingInfo).NeedParenthesesForLeft(((left).Optimize()).printingInfo); } public _System._ITuple2, Dafny.ISequence> LeftParentheses(RAST._IExpr left) { if ((this).LeftRequiresParentheses(left)) { @@ -5251,7 +5604,7 @@ public bool LeftRequiresParentheses(RAST._IExpr left) { } } public bool RightRequiresParentheses(RAST._IExpr right) { - return ((this).printingInfo).NeedParenthesesForRight((right).printingInfo); + return ((this).printingInfo).NeedParenthesesForRight(((right).Optimize()).printingInfo); } public _System._ITuple2, Dafny.ISequence> RightParentheses(RAST._IExpr right) { if ((this).RightRequiresParentheses(right)) { @@ -5263,11 +5616,17 @@ public bool RightRequiresParentheses(RAST._IExpr right) { public Std.Wrappers._IOption> RightMostIdentifier() { RAST._IExpr _source0 = this; { - if (_source0.is_MemberSelect) { + if (_source0.is_FunctionSelect) { Dafny.ISequence _0_id = _source0.dtor_name; return Std.Wrappers.Option>.create_Some(_0_id); } } + { + if (_source0.is_ExprFromPath) { + RAST._IPath _1_p = _source0.dtor_path; + return (_1_p).RightMostIdentifier(); + } + } { return Std.Wrappers.Option>.create_None(); } @@ -5417,7 +5776,7 @@ public bool RightRequiresParentheses(RAST._IExpr right) { Dafny.ISequence _27_op = _source0.dtor_op1; RAST._IExpr _28_underlying = _source0.dtor_underlying; DAST.Format._IUnaryOpFormat _29_format = _source0.dtor_format; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs0 = ((((this).printingInfo).NeedParenthesesFor((_28_underlying).printingInfo)) ? (_System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("("), Dafny.Sequence.UnicodeFromString(")"))) : (_System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("")))); + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs0 = ((((this).printingInfo).NeedParenthesesFor(((_28_underlying).Optimize()).printingInfo)) ? (_System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("("), Dafny.Sequence.UnicodeFromString(")"))) : (_System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("")))); Dafny.ISequence _30_leftP = _let_tmp_rhs0.dtor__0; Dafny.ISequence _31_rightP = _let_tmp_rhs0.dtor__1; Dafny.ISequence _32_leftOp = ((((_27_op).Equals(Dafny.Sequence.UnicodeFromString("&mut"))) && (!(_30_leftP).Equals(Dafny.Sequence.UnicodeFromString("(")))) ? (Dafny.Sequence.Concat(_27_op, Dafny.Sequence.UnicodeFromString(" "))) : ((((_27_op).Equals(Dafny.Sequence.UnicodeFromString("?"))) ? (Dafny.Sequence.UnicodeFromString("")) : (_27_op)))); @@ -5686,28 +6045,34 @@ public bool RightRequiresParentheses(RAST._IExpr right) { } } { - if (_source0.is_MemberSelect) { - RAST._IExpr _106_expression = _source0.dtor_obj; - Dafny.ISequence _107_name = _source0.dtor_name; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs11 = (this).LeftParentheses(_106_expression); - Dafny.ISequence _108_leftP = _let_tmp_rhs11.dtor__0; - Dafny.ISequence _109_rightP = _let_tmp_rhs11.dtor__1; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_108_leftP, (_106_expression)._ToString(ind)), _109_rightP), Dafny.Sequence.UnicodeFromString("::")), _107_name); + if (_source0.is_ExprFromPath) { + RAST._IPath _106_path = _source0.dtor_path; + return (_106_path)._ToString(); + } + } + { + if (_source0.is_FunctionSelect) { + RAST._IExpr _107_expression = _source0.dtor_obj; + Dafny.ISequence _108_name = _source0.dtor_name; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs11 = (this).LeftParentheses(_107_expression); + Dafny.ISequence _109_leftP = _let_tmp_rhs11.dtor__0; + Dafny.ISequence _110_rightP = _let_tmp_rhs11.dtor__1; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_109_leftP, (_107_expression)._ToString(ind)), _110_rightP), Dafny.Sequence.UnicodeFromString("::")), _108_name); } } { if (_source0.is_Lambda) { - Dafny.ISequence _110_params = _source0.dtor_params; - Std.Wrappers._IOption _111_retType = _source0.dtor_retType; - RAST._IExpr _112_body = _source0.dtor_body; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("move |"), RAST.__default.SeqToString(_110_params, Dafny.Helpers.Id, Func>>>((_113_ind) => ((System.Func>)((_114_arg) => { - return (_114_arg)._ToString(_113_ind); - })))(ind), Dafny.Sequence.UnicodeFromString(","))), Dafny.Sequence.UnicodeFromString("| ")), (((_111_retType).is_Some) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("-> "), ((_111_retType).dtor_value)._ToString(ind))) : (Dafny.Sequence.UnicodeFromString("")))), ((((_111_retType).is_Some) && (!((_112_body).is_Block))) ? ((RAST.Expr.create_Block(_112_body))._ToString(ind)) : ((_112_body)._ToString(ind)))); + Dafny.ISequence _111_params = _source0.dtor_params; + Std.Wrappers._IOption _112_retType = _source0.dtor_retType; + RAST._IExpr _113_body = _source0.dtor_body; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("move |"), RAST.__default.SeqToString(_111_params, Dafny.Helpers.Id, Func>>>((_114_ind) => ((System.Func>)((_115_arg) => { + return (_115_arg)._ToString(_114_ind); + })))(ind), Dafny.Sequence.UnicodeFromString(","))), Dafny.Sequence.UnicodeFromString("| ")), (((_112_retType).is_Some) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("-> "), ((_112_retType).dtor_value)._ToString(ind))) : (Dafny.Sequence.UnicodeFromString("")))), ((((_112_retType).is_Some) && (!((_113_body).is_Block))) ? ((RAST.Expr.create_Block(_113_body))._ToString(ind)) : ((_113_body)._ToString(ind)))); } } { - RAST._IExpr _115_r = _source0; - return RAST.__default.AddIndent((_115_r).dtor_content, ind); + RAST._IExpr _116_r = _source0; + return RAST.__default.AddIndent((_116_r).dtor_content, ind); } } public RAST._IExpr Then(RAST._IExpr rhs2) { @@ -5722,8 +6087,8 @@ public RAST._IExpr Then(RAST._IExpr rhs2) { public RAST._IExpr Sel(Dafny.ISequence name) { return RAST.Expr.create_Select(this, name); } - public RAST._IExpr MSel(Dafny.ISequence name) { - return RAST.Expr.create_MemberSelect(this, name); + public RAST._IExpr FSel(Dafny.ISequence name) { + return RAST.Expr.create_FunctionSelect(this, name); } public RAST._IExpr ApplyType(Dafny.ISequence typeParameters) { if ((new BigInteger((typeParameters).Count)).Sign == 0) { @@ -5742,12 +6107,12 @@ public RAST._IExpr Apply1(RAST._IExpr argument) { return RAST.Expr.create_Call(this, Dafny.Sequence.FromElements(argument)); } public bool IsLhsIdentifier() { - return ((this).is_Identifier) || (((this).is_Call) && ((((object.Equals((this).dtor_obj, (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("modify!")))) && ((new BigInteger(((this).dtor_arguments).Count)) == (BigInteger.One))) && ((((this).dtor_arguments).Select(BigInteger.Zero)).is_Identifier)) || (((object.Equals((this).dtor_obj, (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("md!")))) && ((new BigInteger(((this).dtor_arguments).Count)) == (BigInteger.One))) && (Dafny.Helpers.Let(((this).dtor_arguments).Select(BigInteger.Zero), _pat_let8_0 => Dafny.Helpers.Let(_pat_let8_0, _0_lhs => (((_0_lhs).is_Call) && (((_0_lhs).dtor_obj).is_Select)) && ((((_0_lhs).dtor_obj).dtor_obj).is_Identifier))))))); + return ((this).is_Identifier) || (((this).is_Call) && (((((((this).dtor_obj).is_ExprFromPath) && (object.Equals(((this).dtor_obj).dtor_path, (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("modify!"))))) && ((new BigInteger(((this).dtor_arguments).Count)) == (BigInteger.One))) && ((((this).dtor_arguments).Select(BigInteger.Zero)).is_Identifier)) || ((((((this).dtor_obj).is_ExprFromPath) && (object.Equals(((this).dtor_obj).dtor_path, (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("md!"))))) && ((new BigInteger(((this).dtor_arguments).Count)) == (BigInteger.One))) && (Dafny.Helpers.Let(((this).dtor_arguments).Select(BigInteger.Zero), _pat_let8_0 => Dafny.Helpers.Let(_pat_let8_0, _0_lhs => (((_0_lhs).is_Call) && (((_0_lhs).dtor_obj).is_Select)) && ((((_0_lhs).dtor_obj).dtor_obj).is_Identifier))))))); } public Dafny.ISequence LhsIdentifierName() { if ((this).is_Identifier) { return (this).dtor_name; - } else if (object.Equals((this).dtor_obj, (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("modify!")))) { + } else if ((((this).dtor_obj).is_ExprFromPath) && (object.Equals(((this).dtor_obj).dtor_path, (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("modify!"))))) { return (((this).dtor_arguments).Select(BigInteger.Zero)).dtor_name; } else { return (((((this).dtor_arguments).Select(BigInteger.Zero)).dtor_obj).dtor_obj).dtor_name; @@ -5840,9 +6205,15 @@ public RAST._IPrintingInfo printingInfo { get { } } { - if (_source0.is_MemberSelect) { - RAST._IExpr _7_underlying = _source0.dtor_obj; - Dafny.ISequence _8_name = _source0.dtor_name; + if (_source0.is_ExprFromPath) { + RAST._IPath _7_underlying = _source0.dtor_path; + return RAST.PrintingInfo.create_Precedence(new BigInteger(2)); + } + } + { + if (_source0.is_FunctionSelect) { + RAST._IExpr _8_underlying = _source0.dtor_obj; + Dafny.ISequence _9_name = _source0.dtor_name; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(2), RAST.Associativity.create_LeftToRight()); } } @@ -5858,18 +6229,18 @@ public RAST._IPrintingInfo printingInfo { get { } { if (_source0.is_TypeAscription) { - RAST._IExpr _9_left = _source0.dtor_left; - RAST._IType _10_tpe = _source0.dtor_tpe; + RAST._IExpr _10_left = _source0.dtor_left; + RAST._IType _11_tpe = _source0.dtor_tpe; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(10), RAST.Associativity.create_LeftToRight()); } } { if (_source0.is_BinaryOp) { - Dafny.ISequence _11_op2 = _source0.dtor_op2; - RAST._IExpr _12_left = _source0.dtor_left; - RAST._IExpr _13_right = _source0.dtor_right; - DAST.Format._IBinaryOpFormat _14_format = _source0.dtor_format2; - Dafny.ISequence _source2 = _11_op2; + Dafny.ISequence _12_op2 = _source0.dtor_op2; + RAST._IExpr _13_left = _source0.dtor_left; + RAST._IExpr _14_right = _source0.dtor_right; + DAST.Format._IBinaryOpFormat _15_format = _source0.dtor_format2; + Dafny.ISequence _source2 = _12_op2; { bool disjunctiveMatch1 = false; if (object.Equals(_source2, Dafny.Sequence.UnicodeFromString("*"))) { @@ -5906,7 +6277,11 @@ public RAST._IPrintingInfo printingInfo { get { disjunctiveMatch3 = true; } if (disjunctiveMatch3) { - return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()); + if ((((_12_op2).Equals(Dafny.Sequence.UnicodeFromString("<<"))) && ((_13_left).is_TypeAscription)) && (((_13_left).dtor_tpe).EndsWithNameThatCanAcceptGenerics())) { + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(9), RAST.Associativity.create_LeftToRight()); + } else { + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()); + } } } { @@ -5945,7 +6320,11 @@ public RAST._IPrintingInfo printingInfo { get { disjunctiveMatch4 = true; } if (disjunctiveMatch4) { - return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()); + if (((((_12_op2).Equals(Dafny.Sequence.UnicodeFromString("<"))) || ((_12_op2).Equals(Dafny.Sequence.UnicodeFromString("<=")))) && ((_13_left).is_TypeAscription)) && (((_13_left).dtor_tpe).EndsWithNameThatCanAcceptGenerics())) { + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(9), RAST.Associativity.create_LeftToRight()); + } else { + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()); + } } } { @@ -6006,7 +6385,11 @@ public RAST._IPrintingInfo printingInfo { get { disjunctiveMatch6 = true; } if (disjunctiveMatch6) { - return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()); + if ((((_12_op2).Equals(Dafny.Sequence.UnicodeFromString("<<="))) && ((_13_left).is_TypeAscription)) && (((_13_left).dtor_tpe).EndsWithNameThatCanAcceptGenerics())) { + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(9), RAST.Associativity.create_LeftToRight()); + } else { + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()); + } } } { @@ -6878,30 +7261,57 @@ public override string ToString() { return s; } } - public class Expr_MemberSelect : Expr { + public class Expr_ExprFromPath : Expr { + public readonly RAST._IPath _path; + public Expr_ExprFromPath(RAST._IPath path) : base() { + this._path = path; + } + public override _IExpr DowncastClone() { + if (this is _IExpr dt) { return dt; } + return new Expr_ExprFromPath(_path); + } + public override bool Equals(object other) { + var oth = other as RAST.Expr_ExprFromPath; + return oth != null && object.Equals(this._path, oth._path); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 27; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._path)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.Expr.ExprFromPath"; + s += "("; + s += Dafny.Helpers.ToString(this._path); + s += ")"; + return s; + } + } + public class Expr_FunctionSelect : Expr { public readonly RAST._IExpr _obj; public readonly Dafny.ISequence _name; - public Expr_MemberSelect(RAST._IExpr obj, Dafny.ISequence name) : base() { + public Expr_FunctionSelect(RAST._IExpr obj, Dafny.ISequence name) : base() { this._obj = obj; this._name = name; } public override _IExpr DowncastClone() { if (this is _IExpr dt) { return dt; } - return new Expr_MemberSelect(_obj, _name); + return new Expr_FunctionSelect(_obj, _name); } public override bool Equals(object other) { - var oth = other as RAST.Expr_MemberSelect; + var oth = other as RAST.Expr_FunctionSelect; return oth != null && object.Equals(this._obj, oth._obj) && object.Equals(this._name, oth._name); } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 27; + hash = ((hash << 5) + hash) + 28; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._obj)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); return (int) hash; } public override string ToString() { - string s = "RAST.Expr.MemberSelect"; + string s = "RAST.Expr.FunctionSelect"; s += "("; s += Dafny.Helpers.ToString(this._obj); s += ", "; @@ -6929,7 +7339,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 28; + hash = ((hash << 5) + hash) + 29; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._params)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._retType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); diff --git a/Source/DafnyCore/Options/CommonOptionBag.cs b/Source/DafnyCore/Options/CommonOptionBag.cs index 0c0ea425ff5..634f5a206e4 100644 --- a/Source/DafnyCore/Options/CommonOptionBag.cs +++ b/Source/DafnyCore/Options/CommonOptionBag.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.CommandLine; using System.IO; @@ -196,6 +197,13 @@ Note that quantifier variable domains (<- ) are available in both syntax IsHidden = true }; + public static readonly Option RawPointers = new("--raw-pointers", () => false, + @"(backend-specific: Rust) +false - All class instances are reference-counted or garbage collected +true - All class instances are raw pointers and need to be manually deallocated") { + IsHidden = true + }; + public static readonly Option AllowAxioms = new("--allow-axioms", () => false, "Prevents a warning from being generated for axioms, such as assume statements and functions or methods without a body, that don't have an {:axiom} attribute.") { }; @@ -564,6 +572,13 @@ void ParsePrintMode(Option option, Boogie.CommandLineParseState ps, options.ShowProofObligationExpressions = value; }); + DafnyOptions.RegisterLegacyBinding(RawPointers, (options, value) => { + if (value && options.Get(CommonOptionBag.Target) != "rs") { + Console.Error.WriteLine("Error: --raw-pointers can only be used with --target:rs or -t:rs"); + System.Environment.Exit(1); + } + }); + OptionRegistry.RegisterGlobalOption(UnicodeCharacters, OptionCompatibility.CheckOptionMatches); OptionRegistry.RegisterGlobalOption(EnforceDeterminism, OptionCompatibility.CheckOptionLocalImpliesLibrary); OptionRegistry.RegisterGlobalOption(RelaxDefiniteAssignment, OptionCompatibility.OptionLibraryImpliesLocalError); @@ -600,6 +615,7 @@ void ParsePrintMode(Option option, Boogie.CommandLineParseState ps, OptionRegistry.RegisterOption(NewTypeInferenceDebug, OptionScope.Cli); OptionRegistry.RegisterOption(UseBaseFileName, OptionScope.Cli); OptionRegistry.RegisterOption(EmitUncompilableCode, OptionScope.Cli); + OptionRegistry.RegisterOption(RawPointers, OptionScope.Cli); OptionRegistry.RegisterOption(WarnMissingConstructorParenthesis, OptionScope.Module); OptionRegistry.RegisterOption(IncludeRuntimeOption, OptionScope.Cli); OptionRegistry.RegisterOption(InternalIncludeRuntimeOptionForExecution, OptionScope.Cli); diff --git a/Source/DafnyCore/Options/DafnyCommands.cs b/Source/DafnyCore/Options/DafnyCommands.cs index 033c02f71e1..414d389f47a 100644 --- a/Source/DafnyCore/Options/DafnyCommands.cs +++ b/Source/DafnyCore/Options/DafnyCommands.cs @@ -90,6 +90,7 @@ static DafnyCommands() { Function.FunctionSyntaxOption, CommonOptionBag.QuantifierSyntax, CommonOptionBag.UnicodeCharacters, + CommonOptionBag.RawPointers, CommonOptionBag.UseBaseFileName, CommonOptionBag.EmitUncompilableCode, CommonOptionBag.GeneralTraits, diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/Makefile b/Source/DafnyRuntime/DafnyRuntimeRust/Makefile new file mode 100644 index 00000000000..27cf8fe9d6a --- /dev/null +++ b/Source/DafnyRuntime/DafnyRuntimeRust/Makefile @@ -0,0 +1,21 @@ + +# Invoking the CLI this way just to stay platform-independent +DAFNY = dotnet run --project ../../Dafny --no-build -- + +GENERATED_SYSTEM_MODULE_SOURCE=../obj/systemModulePopulator-rust/src/systemModulePopulator.rs +GENERATED_SYSTEM_MODULE_TARGET=src/system/mod.rs + +all: check-system-module test + +build-system-module: + $(DAFNY) translate rs --no-verify --use-basename-for-filename --optimize-erasable-datatype-wrapper:false --system-module:OmitAllOtherModules ../systemModulePopulator.dfy --output:../obj/systemModulePopulator + python -c "import sys; data = sys.stdin.read(); sys.stdout.write(data.replace('::dafny_runtime', 'crate'))" < $(GENERATED_SYSTEM_MODULE_SOURCE) > $(GENERATED_SYSTEM_MODULE_SOURCE).tmp && mv $(GENERATED_SYSTEM_MODULE_SOURCE).tmp $(GENERATED_SYSTEM_MODULE_SOURCE) + +check-system-module: build-system-module + diff $(GENERATED_SYSTEM_MODULE_SOURCE) $(GENERATED_SYSTEM_MODULE_TARGET) + +update-system-module: build-system-module + cp $(GENERATED_SYSTEM_MODULE_SOURCE) $(GENERATED_SYSTEM_MODULE_TARGET) + +test: + cargo test \ No newline at end of file diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index 84e06d51a37..f5ab2d2e894 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -13,6 +13,7 @@ use std::{ collections::{HashMap, HashSet}, fmt::{Debug, Display, Formatter}, hash::{Hash, Hasher}, + ptr::NonNull, mem, ops::{Add, Deref, Div, Mul, Neg, Rem, Sub}, rc::{Rc, Weak}, @@ -55,10 +56,6 @@ pub mod dafny_runtime_conversions { pub type DafnyBool = bool; pub type DafnyChar = crate::DafnyChar; pub type DafnyCharUTF16 = crate::DafnyCharUTF16; - pub type DafnyClass = *mut T; - pub type DafnyArray = *mut [T]; - pub type DafnyArray2 = *mut crate::Array2; - pub type DafnyArray3 = *mut crate::Array3; use num::BigInt; use num::ToPrimitive; @@ -68,29 +65,74 @@ pub mod dafny_runtime_conversions { use std::hash::Hash; use std::rc::Rc; - // Conversion to and from Dafny classes. All these methods take ownership of the class. - pub unsafe fn dafny_class_to_struct(ptr: DafnyClass) -> T { - *dafny_class_to_boxed_struct(ptr) - } - pub unsafe fn dafny_class_to_boxed_struct(ptr: DafnyClass) -> Box { - Box::from_raw(ptr) - } - pub fn struct_to_dafny_class(t: T) -> DafnyClass { - boxed_struct_to_dafny_class(Box::new(t)) - } - pub fn boxed_struct_to_dafny_class(t: Box) -> DafnyClass { - Box::into_raw(t) + pub mod object { + pub type DafnyClass = crate::Object; + pub type DafnyArray = crate::Object<[T]>; + pub type DafnyArray2 = crate::Object>; + pub type DafnyArray3 = crate::Object>; + // Conversion to and from Dafny reference-counted classes. All these methods take ownership of the class. + pub unsafe fn dafny_class_to_struct(ptr: DafnyClass) -> T { + let t: &T = crate::rd!(ptr); + t.clone() + } + pub unsafe fn dafny_class_to_boxed_struct(ptr: DafnyClass) -> Box { + Box::new(dafny_class_to_struct(ptr)) + } + pub unsafe fn dafny_class_to_rc_struct(ptr: DafnyClass) -> ::std::rc::Rc { + crate::rcmut::to_rc(ptr.0.unwrap()) + } + pub fn struct_to_dafny_class(t: T) -> DafnyClass { + crate::Object::new(t) + } + pub fn boxed_struct_to_dafny_class(t: Box) -> DafnyClass { + struct_to_dafny_class(*t) + } + pub unsafe fn rc_struct_to_dafny_class(t: ::std::rc::Rc) -> DafnyClass { + crate::Object::from_rc(t) + } + // Conversions to and from Dafny arrays. They all take ownership + pub unsafe fn dafny_array_to_vec(ptr: DafnyArray) -> Vec { + ptr.as_ref().to_vec() + } + pub fn vec_to_dafny_array(array: Vec) -> DafnyArray { + // SAFETY: We own the array + unsafe { + crate::Object::from_rc(::std::rc::Rc::from(array.into_boxed_slice())) + } + } + pub unsafe fn dafny_array2_to_vec(ptr: DafnyArray2) -> Vec> { + crate::rd!(ptr).to_vec() + } } - // Conversions to and from Dafny arrays. They all take ownership - pub unsafe fn dafny_array_to_vec(ptr: DafnyArray) -> Vec { - ptr.as_ref().unwrap().to_vec() - } - pub fn vec_to_dafny_array(array: Vec) -> DafnyArray { - Box::into_raw(array.into_boxed_slice()) - } - pub unsafe fn dafny_array2_to_vec(ptr: DafnyArray2) -> Vec> { - Box::from_raw(ptr).to_vec() + pub mod ptr { + pub type DafnyClass = crate::Ptr; + pub type DafnyArray = crate::Ptr<[T]>; + pub type DafnyArray2 = crate::Ptr>; + pub type DafnyArray3 = crate::Ptr>; + // Conversion to and from Dafny reference-counted classes. All these methods take ownership of the class. + pub unsafe fn dafny_class_to_struct(ptr: DafnyClass) -> T { + *dafny_class_to_boxed_struct(ptr) + } + pub unsafe fn dafny_class_to_boxed_struct(ptr: DafnyClass) -> Box { + Box::from_raw(crate::Ptr::into_raw(ptr)) + } + pub fn struct_to_dafny_class(t: T) -> DafnyClass { + boxed_struct_to_dafny_class(Box::new(t)) + } + pub fn boxed_struct_to_dafny_class(t: Box) -> DafnyClass { + crate::Ptr::from_raw_nonnull(Box::into_raw(t)) + } + // Conversions to and from Dafny arrays. They all take ownership + pub unsafe fn dafny_array_to_vec(ptr: DafnyArray) -> Vec { + ptr.as_ref().to_vec() + } + pub fn vec_to_dafny_array(array: Vec) -> DafnyArray { + crate::Ptr::from_box(array.into_boxed_slice()) + } + pub unsafe fn dafny_array2_to_vec(ptr: DafnyArray2) -> Vec> { + Box::from_raw(crate::Ptr::into_raw(ptr)).to_vec() + } } pub fn dafny_int_to_bigint(i: &DafnyInt) -> BigInt { @@ -650,24 +692,60 @@ impl Sequence where T: DafnyType, { - pub fn from_array(values: &Vec) -> Sequence { + pub fn from_array(values: Ptr<[T]>) -> Sequence { + let mut v = vec![]; + v.extend_from_slice(read!(values)); + Sequence::ArraySequence { + values: Rc::new(v), + } + } + pub fn from_array_object(values: &Object<[T]>) -> Sequence { + let mut v = vec![]; + v.extend_from_slice(rd!(values)); + Sequence::ArraySequence { + values: Rc::new(v), + } + } + pub fn from_array_slice(values: Ptr<[T]>, start: &DafnyInt, end: &DafnyInt) -> Sequence { + let mut v = vec![]; + v.extend_from_slice(&read!(values)[start.to_usize().unwrap()..end.to_usize().unwrap()]); + Sequence::ArraySequence { + values: Rc::new(v), + } + } + pub fn from_array_slice_object(values: &Object<[T]>, start: &DafnyInt, end: &DafnyInt) -> Sequence { + let mut v = vec![]; + v.extend_from_slice(&rd!(values)[start.to_usize().unwrap()..end.to_usize().unwrap()]); + Sequence::ArraySequence { + values: Rc::new(v), + } + } + pub fn from_array_take(values: Ptr<[T]>, n: &DafnyInt) -> Sequence { + let mut v = vec![]; + v.extend_from_slice(&read!(values)[..n.to_usize().unwrap()]); Sequence::ArraySequence { - values: Rc::new(values.clone()), + values: Rc::new(v), } } - pub fn from_array_slice(values: &Vec, start: &DafnyInt, end: &DafnyInt) -> Sequence { + pub fn from_array_take_object(values: &Object<[T]>, n: &DafnyInt) -> Sequence { + let mut v = vec![]; + v.extend_from_slice(&rd!(values)[..n.to_usize().unwrap()]); Sequence::ArraySequence { - values: Rc::new(values[start.to_usize().unwrap()..end.to_usize().unwrap()].to_vec()), + values: Rc::new(v), } } - pub fn from_array_take(values: &Vec, n: &DafnyInt) -> Sequence { + pub fn from_array_drop(values: Ptr<[T]>, n: &DafnyInt) -> Sequence { + let mut v = vec![]; + v.extend_from_slice(&read!(values)[n.to_usize().unwrap()..]); Sequence::ArraySequence { - values: Rc::new(values[..n.to_usize().unwrap()].to_vec()), + values: Rc::new(v), } } - pub fn from_array_drop(values: &Vec, n: &DafnyInt) -> Sequence { + pub fn from_array_drop_object(values: &Object<[T]>, n: &DafnyInt) -> Sequence { + let mut v = vec![]; + v.extend_from_slice(&rd!(values)[n.to_usize().unwrap()..]); Sequence::ArraySequence { - values: Rc::new(values[n.to_usize().unwrap()..].to_vec()), + values: Rc::new(v), } } pub fn from_array_owned(values: Vec) -> Sequence { @@ -940,12 +1018,12 @@ impl Debug for Sequence { pub struct Map where K: DafnyTypeEq, - V: DafnyTypeEq, + V: DafnyType, { data: Rc>, } -impl Default for Map { +impl Default for Map { fn default() -> Self { Map { data: Rc::new(HashMap::new()), @@ -953,13 +1031,13 @@ impl Default for Map { } } -impl NontrivialDefault for Map { +impl NontrivialDefault for Map { fn nontrivial_default() -> Self { Self::default() } } -impl Hash for Map { +impl Hash for Map { fn hash(&self, state: &mut H) { self.data.len().hash(state); // Worst performance for things that are not hashable like maps } @@ -985,7 +1063,7 @@ where impl Eq for Map {} -impl Map { +impl Map { pub fn new_empty() -> Map { Map { data: Rc::new(HashMap::new()), @@ -1095,13 +1173,6 @@ impl Map { } Set::from_hashset_owned(result) } - pub fn values(&self) -> Set { - let mut result: Vec = Vec::new(); - for (_, v) in self.data.iter() { - result.push(v.clone()); - } - Set::from_array(&result) - } pub fn update_index(&self, index: &K, value: &V) -> Self { let mut result = self.data.as_ref().clone(); @@ -1124,6 +1195,24 @@ impl Map { } } + +impl Map { + pub fn values(&self) -> Set { + let mut result: Vec = Vec::new(); + for (_, v) in self.data.iter() { + result.push(v.clone()); + } + Set::from_array(&result) + } + pub fn items(&self) -> Set<(K, V)> { + let mut result: Vec<(K, V)> = Vec::new(); + for (k, v) in self.data.iter() { + result.push((k.clone(), v.clone())); + } + Set::from_array(&result) + } +} + impl Map { pub fn as_dafny_multiset(&self) -> Multiset { Multiset::from_hashmap(&self.data) @@ -1141,7 +1230,7 @@ where impl MapBuilder where K: DafnyTypeEq, - V: DafnyTypeEq, + V: DafnyType, { pub fn new() -> MapBuilder { MapBuilder { @@ -1160,7 +1249,7 @@ where impl DafnyPrint for Map where K: DafnyTypeEq, - V: DafnyTypeEq, + V: DafnyType, { fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { f.write_str("map[")?; @@ -1197,6 +1286,15 @@ pub struct Set { data: Rc>, } +// Since there is no canonical way to iterate over a set to compute the hash. +impl ::std::hash::Hash for Set { + fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { + self.cardinality_usize().hash(_state) + } +} + +impl Eq for Set {} + impl Default for Set where T: DafnyTypeEq, @@ -1724,12 +1822,6 @@ impl Hash for Multiset { } } -pub fn is_instance_of, U: 'static>(theobject: *const C) -> bool { - read!(Upcast::::upcast(read!(theobject))) - .downcast_ref::() - .is_some() -} - pub fn dafny_rational_to_int(r: &BigRational) -> BigInt { euclidian_division(r.numer().clone(), r.denom().clone()) } @@ -2515,8 +2607,8 @@ macro_rules! ARRAY_METHODS { pub fn placebos_usize( $length0: usize, $($length: usize),+ - ) -> *mut $ArrayType<$crate::MaybeUninit> { - Box::into_raw(Self::placebos_box_usize( + ) -> Ptr<$ArrayType<$crate::MaybeUninit>> { + Ptr::from_box(Self::placebos_box_usize( $length0, $($length),+ )) @@ -2527,18 +2619,16 @@ macro_rules! ARRAY_METHODS { $($length: usize),+ ) -> $crate::Object<$ArrayType<$crate::MaybeUninit>> { // SAFETY: We know the object is owned and never referred to by anything else - unsafe { - $crate::Object::from_rc(Rc::new($ArrayType { - $($length: $length),+, - data: INIT_ARRAY_DATA!($ArrayType, $length0, $($length),+), - })) - } + $crate::Object::new($ArrayType { + $($length: $length),+, + data: INIT_ARRAY_DATA!($ArrayType, $length0, $($length),+), + }) } pub fn placebos( $length0: &$crate::DafnyInt, $($length: &$crate::DafnyInt),+ - ) -> *mut $ArrayType<$crate::MaybeUninit> { + ) -> Ptr<$ArrayType<$crate::MaybeUninit>> { Self::placebos_usize( $length0.as_usize(), $($length.as_usize()),+ @@ -2546,7 +2636,7 @@ macro_rules! ARRAY_METHODS { } // Once all the elements have been initialized, transform the signature of the pointer - pub fn construct(p: *mut $ArrayType<$crate::MaybeUninit>) -> *mut $ArrayType { + pub fn construct(p: Ptr<$ArrayType<$crate::MaybeUninit>>) -> Ptr<$ArrayType> { unsafe { std::mem::transmute(p) } } // Once all the elements have been initialized, transform the signature of the pointer @@ -2847,18 +2937,20 @@ pub mod array { use num::ToPrimitive; use std::mem::MaybeUninit; use std::{boxed::Box, rc::Rc, vec::Vec}; + use super::Ptr; + #[inline] - pub fn from_native(v: Box<[T]>) -> *mut [T] { - Box::into_raw(v) + pub fn from_native(v: Box<[T]>) -> Ptr<[T]> { + Ptr::from_box(v) } #[inline] - pub fn from_vec(v: Vec) -> *mut [T] { + pub fn from_vec(v: Vec) -> Ptr<[T]> { from_native(v.into_boxed_slice()) } - pub fn to_vec(v: *mut [T]) -> Vec { - unsafe { Box::from_raw(v) }.into_vec() + pub fn to_vec(v: Ptr<[T]>) -> Vec { + unsafe { Box::<[T]>::from_raw(v.into_raw()) }.into_vec() } - pub fn initialize_usize(n: usize, initializer: Rc T>) -> *mut [T] { + pub fn initialize_usize(n: usize, initializer: Rc T>) -> Ptr<[T]> { let mut v = Vec::with_capacity(n); for i in 0..n { v.push(initializer(i)); @@ -2866,17 +2958,17 @@ pub mod array { from_vec(v) } - pub fn placebos(n: &DafnyInt) -> *mut [MaybeUninit] { + pub fn placebos(n: &DafnyInt) -> Ptr<[MaybeUninit]> { placebos_usize(n.as_usize()) } - pub fn placebos_usize(n: usize) -> *mut [MaybeUninit] { - Box::into_raw(placebos_box_usize(n)) + pub fn placebos_usize(n: usize) -> Ptr<[MaybeUninit]> { + Ptr::from_box(placebos_box_usize(n)) } pub fn placebos_usize_object(n: usize) -> super::Object<[MaybeUninit]> { super::rcmut::array_object_from_box(placebos_box_usize(n)) } // Once all the elements have been initialized, transform the signature of the pointer - pub fn construct(p: *mut [MaybeUninit]) -> *mut [T] { + pub fn construct(p: Ptr<[MaybeUninit]>) -> Ptr<[T]> { unsafe { std::mem::transmute(p) } } pub fn construct_object(p: super::Object<[MaybeUninit]>) -> super::Object<[T]> { @@ -2894,8 +2986,8 @@ pub mod array { .collect() } - pub fn initialize(n: &DafnyInt, initializer: Rc T>) -> *mut [T] { - Box::into_raw(initialize_box(n, initializer)) + pub fn initialize(n: &DafnyInt, initializer: Rc T>) -> Ptr<[T]> { + super::Ptr::from_box(initialize_box(n, initializer)) } pub fn initialize_box(n: &DafnyInt, initializer: Rc T>) -> Box<[T]> { @@ -2913,30 +3005,30 @@ pub mod array { } #[inline] - pub fn length_usize(this: *mut [T]) -> usize { + pub fn length_usize(this: Ptr<[T]>) -> usize { // safety: Dafny won't call this function unless it can guarantee the array is still allocated super::read!(this).len() } #[inline] - pub fn length(this: *mut [T]) -> DafnyInt { + pub fn length(this: Ptr<[T]>) -> DafnyInt { int!(length_usize(this)) } #[inline] - pub fn get_usize(this: *mut [T], i: usize) -> T { + pub fn get_usize(this: Ptr<[T]>, i: usize) -> T { // safety: Dafny won't call this function unless it can guarantee the array is still allocated - (unsafe { &*this } as &[T])[i].clone() + this.as_ref()[i].clone() } #[inline] - pub fn get(this: *mut [T], i: &DafnyInt) -> T { + pub fn get(this: Ptr<[T]>, i: &DafnyInt) -> T { get_usize(this, i.to_usize().unwrap()) } #[inline] - pub fn update_usize(this: *mut [T], i: usize, val: T) { + pub fn update_usize(this: Ptr<[T]>, i: usize, val: T) { // safety: Dafny won't call this function unless it can guarantee the array is still allocated - (unsafe { &mut *this } as &mut [T])[i] = val; + crate::modify!(this)[i] = val; } #[inline] - pub fn update(this: *mut [T], i: &DafnyInt, val: T) { + pub fn update(this: Ptr<[T]>, i: &DafnyInt, val: T) { update_usize(this, i.to_usize().unwrap(), val); } } @@ -2944,35 +3036,21 @@ pub mod array { /////////////////// // Class helpers // /////////////////// -pub fn allocate() -> *mut T { - let mut this: Box> = Box::new(MaybeUninit::uninit()); - let this_ptr = this.as_mut() as *mut MaybeUninit as *mut T; - Box::into_raw(this); // Make sure this is not dropped - this_ptr +pub fn allocate() -> Ptr { + let this_ptr = Box::into_raw(Box::new(MaybeUninit::uninit())) as *mut MaybeUninit as *mut T; + Ptr::from_raw_nonnull(this_ptr) } // Generic function to safely deallocate a raw pointer #[inline] -pub fn deallocate(pointer: *const T) { - // safety: Dafny won't call this function unless it can guarantee the array is still allocated +pub fn deallocate(pointer: Ptr) { + // safety: Dafny won't call this function unless it can guarantee the object is still allocated unsafe { // Takes ownership of the reference, // so that it's deallocated at the end of the method - let _ = Box::from_raw(pointer as *mut T); - } -} - -impl DafnyPrint for *mut T { - fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { - write!(f, "object") + let _ = Box::from_raw(pointer.into_raw()); } } -impl NontrivialDefault for *mut T { - fn nontrivial_default() -> Self { - // Create a null pointer - ::std::ptr::null() as *const T as *mut T - } -} pub struct ExactPool { current: T, yielded: bool, @@ -3000,16 +3078,6 @@ pub fn exact_range(value: T) -> ExactPool { // Any Dafny trait must require classes extending it to have a method "as_any_mut" // that can convert the reference from that trait to a reference of Any -// cast is meant to be used on references only, to downcast a trait reference to a class reference -#[macro_export] -macro_rules! cast { - ($raw:expr, $id:ty) => { - $crate::modify!(Upcast::::upcast($crate::modify!($raw))) - .downcast_mut::<$id>() - .unwrap() as *mut $id - }; -} - // 'is' is meant to be used on references only, to check if a trait reference is a class reference #[macro_export] macro_rules! is { @@ -3034,15 +3102,15 @@ macro_rules! is_object { #[macro_export] macro_rules! cast_any { ($raw:expr) => { - $crate::Upcast::::upcast($crate::read!($raw)) + $crate::Upcast::::upcast($crate::modify!($raw)) }; } // cast_any_object is meant to be used on references only, to convert any references (classes or traits)* // to an Any reference trait #[macro_export] macro_rules! cast_any_object { - ($raw:expr) => { - $crate::UpcastObject::::upcast($crate::rd!($raw)) + ($obj:expr) => { + $crate::UpcastObject::::upcast($crate::md!($obj)) }; } @@ -3054,7 +3122,7 @@ macro_rules! cast_any_object { #[macro_export] macro_rules! update_field_nodrop { ($ptr:expr, $field:ident, $value:expr) => { - $crate::update_nodrop!((*$ptr).$field, $value) + $crate::update_nodrop!($crate::modify!($ptr).$field, $value) }; } @@ -3073,11 +3141,9 @@ macro_rules! update_nodrop { #[macro_export] macro_rules! modify { ($ptr:expr) => { - // safety: Dafny will only obtain a mutable borrowed address of a pointer if it can ensure the object - // is still allocated { #[allow(unused_unsafe)] - let tmp = unsafe { &mut *$ptr }; + let tmp = unsafe {&mut *(::std::cell::UnsafeCell::raw_get($ptr.0.unwrap_unchecked().as_ptr()))}; tmp } } @@ -3087,11 +3153,9 @@ macro_rules! modify { #[macro_export] macro_rules! read { ($ptr:expr) => { - // safety: Dafny will only obtain a borrowed address of a pointer if it can ensure the object - // is still allocated { #[allow(unused_unsafe)] - let tmp = unsafe { &*$ptr }; + let tmp = unsafe {&*(::std::cell::UnsafeCell::raw_get($ptr.0.unwrap_unchecked().as_ptr()))}; tmp } } @@ -3102,6 +3166,7 @@ macro_rules! read { macro_rules! update_field_uninit { ($t:expr, $field:ident, $field_assigned:expr, $value:expr) => {{ let computed_value = $value; + #[allow(unused_assignments)] if $field_assigned { $crate::modify!($t).$field = computed_value; } else { @@ -3123,6 +3188,160 @@ macro_rules! update_field_if_uninit { }}; } +///////////////// +// Raw pointers (require wrapping because of equality) +///////////////// + +// This Ptr has the same run-time space as *mut +pub struct Ptr(pub Option>>); + +impl Ptr { + pub fn null() -> Self { + Ptr(None) + } + pub fn is_null(&self) -> bool { + self.0.is_none() + } + #[inline] + pub fn from_raw_nonnull(t: *mut T) -> Ptr { + unsafe { Ptr(Some(::std::mem::transmute::, NonNull>>(NonNull::new_unchecked(t)))) } + } + pub fn from_box(t: Box) -> Ptr { + Self::from_raw_nonnull(Box::into_raw(t)) + } + pub fn into_raw(self) -> *mut T { + if self.is_null() { + panic!("Cannot turn a null pointer into a raw pointer"); + } + let nonnull = unsafe { self.0.unwrap_unchecked() }; + unsafe { ::std::mem::transmute::<_, *mut T>(nonnull.as_ptr()) } + } +} + +impl > Ptr { + pub fn is_instance_of(self) -> bool { + if self.is_null() { + false + } else { + read!(Upcast::::upcast(modify!(self))) + .downcast_ref::() + .is_some() + } + } +} + +impl NontrivialDefault for Ptr { + fn nontrivial_default() -> Self { + // Create a null pointer + Self::null() + } +} + +impl Ptr { + pub fn new(val: T) -> Ptr { + Self::from_box(Box::new(val)) + } +} + + +impl Eq for Ptr {} + +impl Clone for Ptr { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for Ptr { } + +impl Default for Ptr { + fn default() -> Self { + Ptr::null() + } +} + +impl Debug for Ptr { + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { + self.fmt_print(f, false) + } +} +impl DafnyPrint for Ptr { + fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { + write!(f, "") + } +} + + +impl PartialEq> for Ptr { + fn eq(&self, other: &Ptr) -> bool { + if !self.is_null() { + if !other.is_null() { + // To compare addresses, we need to ensure we only compare thin pointers + // https://users.rust-lang.org/t/comparing-addresses-between-fat-and-thin-pointers/89008 + ::std::ptr::eq( + self.clone().into_raw() as *const (), + other.clone().into_raw() as *const ()) + } else { + false + } + } else if !other.is_null() { + false + } else { + true + } + } +} + +impl std::hash::Hash for Ptr { + fn hash(&self, state: &mut H) { + if !self.is_null() { + (read!(self.clone()) as *const T as *const ()).hash(state); + } else { + 0.hash(state); + } + } +} + +impl AsMut for Ptr { + fn as_mut(&mut self) -> &mut T { + modify!(self.clone()) + } +} +impl AsRef for Ptr { + fn as_ref(&self) -> &T { + read!(self.clone()) + } +} + +impl Ptr { + // Never use on local values, only on &self types previously called on Ptr types. + pub fn from_ref(r: &T) -> Ptr { + Ptr(unsafe {::std::mem::transmute::<_, Option>>>(r as *const T)}) + } +} +// cast is meant to be used on references only, to downcast a trait reference to a class reference +#[macro_export] +macro_rules! cast { + ($raw:expr, $id:ty) => { + { + #[allow(unused_unsafe)] + let tmp = + unsafe { + let expr = $raw; + let res: $crate::Ptr<$id> = + if expr.is_null() { + $crate::Ptr::null() + } else { + $crate::Ptr::from_raw_nonnull(expr.into_raw() as *mut $id) + }; + res + }; + tmp + } + }; + +} + ///////////////// // Reference-counted classes mode ///////////////// @@ -3130,9 +3349,28 @@ macro_rules! update_field_if_uninit { pub struct Object(pub Option>); impl Object { - unsafe fn from_rc(rc: Rc) -> Object { + pub unsafe fn from_rc(rc: Rc) -> Object { Object(Some(rcmut::from_rc(rc))) } + pub fn null() -> Object { + Object(None) + } + pub fn is_null(&self) -> bool { + self.0.is_none() + } +} +impl > Object { + pub fn is_instance_of(self) -> bool { + // safety: Dafny won't call this function unless it can guarantee the object is still allocated + rd!(UpcastObject::::upcast(md!(self))) + .downcast_ref::() + .is_some() + } +} +impl Object { + pub fn new(val: T) -> Object { + Object(Some(rcmut::new(val))) + } } impl Eq for Object {} @@ -3201,10 +3439,10 @@ impl AsRef for Object { impl Object { - pub fn from_ref(r: &T) -> Object { - let pt = r as *const T; + pub fn from_ref(r: &mut T) -> Object { + let pt = r as *mut T as *mut UnsafeCell; unsafe { ::std::rc::Rc::increment_strong_count(pt) } - let rebuilt = unsafe { Rc::from_raw(pt as *const UnsafeCell) }; + let rebuilt = unsafe { Rc::from_raw(pt) }; Object(Some(rebuilt)) } } @@ -3236,11 +3474,6 @@ pub fn allocate_object_track(allocation_tracker: &mut AllocationTrac res } -pub fn is_instance_of_object, U: 'static>(theobject: Object) -> bool { - // safety: Dafny won't call this function unless it can guarantee the object is still allocated - rd!(UpcastObject::::upcast(rd!(theobject))).downcast_ref::().is_some() -} - // Equivalent of update_field_nodrop but for rcmut #[macro_export] macro_rules! update_field_nodrop_object { @@ -3262,6 +3495,7 @@ macro_rules! update_nodrop_object { macro_rules! update_field_if_uninit_object { ($t:expr, $field:ident, $field_assigned:expr, $value:expr) => {{ let computed_value = $value; + #[allow(unused_assignments)] if !$field_assigned { $crate::update_field_nodrop_object!($t, $field, computed_value); $field_assigned = true; @@ -3274,6 +3508,7 @@ macro_rules! update_field_if_uninit_object { macro_rules! update_field_uninit_object { ($t:expr, $field:ident, $field_assigned:expr, $value:expr) => {{ let computed_value = $value; + #[allow(unused_assignments)] if $field_assigned { $crate::md!($t).$field = computed_value; } else { @@ -3501,13 +3736,13 @@ macro_rules! maybe_placebos_from { pub fn upcast_object() -> Rc) -> Object> where A : UpcastObject { - Rc::new(|x: Object| rd!(x).upcast()) + Rc::new(|mut x: Object| x.as_mut().upcast()) } -pub fn upcast() -> Rc *mut B> +pub fn upcast() -> Rc) -> Ptr> where A: Upcast { - Rc::new(|x: *mut A| read!(x).upcast()) + Rc::new(|x: Ptr| modify!(x).upcast()) } pub fn upcast_id() -> Rc A> @@ -3535,19 +3770,19 @@ pub fn fn1_coerce( // For pointers pub trait Upcast { - fn upcast(&self) -> *mut T; + fn upcast(&mut self) -> Ptr; } pub trait UpcastObject { - fn upcast(&self) -> Object; + fn upcast(&mut self) -> Object; } impl Upcast for T { - fn upcast(&self) -> *mut T { - self as *const T as *mut T + fn upcast(&mut self) -> Ptr { + Ptr::from_raw_nonnull(self as *mut T) } } impl UpcastObject for T { - fn upcast(&self) -> Object { + fn upcast(&mut self) -> Object { Object::from_ref(self) } } @@ -3562,8 +3797,8 @@ macro_rules! Extends { #[macro_export] macro_rules! UpcastFn { ($B:ty) => { - fn upcast(&self) -> *mut $B { - self as *const Self as *mut Self as *mut $B + fn upcast(&mut self) -> $crate::Ptr<$B> { + $crate::Ptr::from_raw_nonnull(self as *mut Self as *mut $B) } }; } @@ -3571,15 +3806,15 @@ macro_rules! UpcastFn { #[macro_export] macro_rules! UpcastObjectFn { ($B:ty) => { - fn upcast(&self) -> $crate::Object<$B> { - $crate::Object::from_ref($crate::read!(self as *const Self as *mut Self as *mut $B)) + fn upcast(&mut self) -> $crate::Object<$B> { + $crate::Object::from_ref(self as &mut $B) } }; } -// IT works only when there is no type parameters for $A... +// It works only when there is no type parameters for $A... #[macro_export] macro_rules! UpcastDef { ($A:ty, $B:ty) => { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs index 36df6b2d063..391263cb587 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs @@ -1,6 +1,15 @@ #![allow(warnings, unconditional_panic)] #![allow(nonstandard_style)] + pub mod _System { + pub use crate::DafnyType; + pub use ::std::fmt::Debug; + pub use crate::DafnyPrint; + pub use ::std::cmp::Eq; + pub use ::std::hash::Hash; + pub use ::std::default::Default; + pub use ::std::convert::AsRef; + pub type nat = crate::DafnyInt; #[derive(PartialEq, Clone)] @@ -8,34 +17,30 @@ pub mod _System { _T2 { _0: T0, _1: T1 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData) + } } - impl Tuple2 { + impl Tuple2 { pub fn _0(&self) -> &T0 { match self { Tuple2::_T2{_0, _1, } => _0, - Tuple2::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple2::_T2{_0, _1, } => _1, - Tuple2::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple2 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple2 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -47,12 +52,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple2::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple2 { + impl Tuple2 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>) -> ::std::rc::Rc) -> Tuple2> { ::std::rc::Rc::new(move |this: Self| -> Tuple2{ match this { @@ -62,29 +66,27 @@ pub mod _System { _1: f_1.clone()(_1) } }, - Tuple2::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple2 {} - impl ::std::hash::Hash + impl Hash for Tuple2 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple2::_T2{_0, _1, } => { - _0.hash(_state); - _1.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state) }, - Tuple2::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple2 { fn default() -> Tuple2 { Tuple2::_T2 { @@ -94,7 +96,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple2 { fn as_ref(&self) -> Self { self @@ -108,14 +110,14 @@ pub mod _System { impl Tuple0 {} - impl ::std::fmt::Debug + impl Debug for Tuple0 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple0 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -130,7 +132,7 @@ pub mod _System { impl Eq for Tuple0 {} - impl ::std::hash::Hash + impl Hash for Tuple0 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { @@ -141,14 +143,14 @@ pub mod _System { } } - impl ::std::default::Default + impl Default for Tuple0 { fn default() -> Tuple0 { Tuple0::_T0 {} } } - impl ::std::convert::AsRef + impl AsRef for &Tuple0 { fn as_ref(&self) -> Self { self @@ -159,27 +161,25 @@ pub mod _System { pub enum Tuple1 { _T1 { _0: T0 - }, - _PhantomVariant(::std::marker::PhantomData) + } } - impl Tuple1 { + impl Tuple1 { pub fn _0(&self) -> &T0 { match self { Tuple1::_T1{_0, } => _0, - Tuple1::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple1 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple1 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -189,12 +189,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple1::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple1 { + impl Tuple1 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>) -> ::std::rc::Rc) -> Tuple1> { ::std::rc::Rc::new(move |this: Self| -> Tuple1{ match this { @@ -203,28 +202,26 @@ pub mod _System { _0: f_0.clone()(_0) } }, - Tuple1::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple1 {} - impl ::std::hash::Hash + impl Hash for Tuple1 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple1::_T1{_0, } => { - _0.hash(_state) + ::std::hash::Hash::hash(_0, _state) }, - Tuple1::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple1 { fn default() -> Tuple1 { Tuple1::_T1 { @@ -233,7 +230,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple1 { fn as_ref(&self) -> Self { self @@ -246,41 +243,35 @@ pub mod _System { _0: T0, _1: T1, _2: T2 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) + } } - impl Tuple3 { + impl Tuple3 { pub fn _0(&self) -> &T0 { match self { Tuple3::_T3{_0, _1, _2, } => _0, - Tuple3::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple3::_T3{_0, _1, _2, } => _1, - Tuple3::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple3::_T3{_0, _1, _2, } => _2, - Tuple3::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple3 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple3 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -294,12 +285,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple3::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple3 { + impl Tuple3 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>) -> ::std::rc::Rc) -> Tuple3> { ::std::rc::Rc::new(move |this: Self| -> Tuple3{ match this { @@ -310,30 +300,28 @@ pub mod _System { _2: f_2.clone()(_2) } }, - Tuple3::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple3 {} - impl ::std::hash::Hash + impl Hash for Tuple3 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple3::_T3{_0, _1, _2, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state) }, - Tuple3::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple3 { fn default() -> Tuple3 { Tuple3::_T3 { @@ -344,7 +332,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple3 { fn as_ref(&self) -> Self { self @@ -358,48 +346,40 @@ pub mod _System { _1: T1, _2: T2, _3: T3 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) + } } - impl Tuple4 { + impl Tuple4 { pub fn _0(&self) -> &T0 { match self { Tuple4::_T4{_0, _1, _2, _3, } => _0, - Tuple4::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple4::_T4{_0, _1, _2, _3, } => _1, - Tuple4::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple4::_T4{_0, _1, _2, _3, } => _2, - Tuple4::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple4::_T4{_0, _1, _2, _3, } => _3, - Tuple4::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple4 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple4 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -415,12 +395,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple4::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple4 { + impl Tuple4 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>) -> ::std::rc::Rc) -> Tuple4> { ::std::rc::Rc::new(move |this: Self| -> Tuple4{ match this { @@ -432,31 +411,29 @@ pub mod _System { _3: f_3.clone()(_3) } }, - Tuple4::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple4 {} - impl ::std::hash::Hash + impl Hash for Tuple4 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple4::_T4{_0, _1, _2, _3, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state) }, - Tuple4::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple4 { fn default() -> Tuple4 { Tuple4::_T4 { @@ -468,7 +445,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple4 { fn as_ref(&self) -> Self { self @@ -483,55 +460,45 @@ pub mod _System { _2: T2, _3: T3, _4: T4 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) + } } - impl Tuple5 { + impl Tuple5 { pub fn _0(&self) -> &T0 { match self { Tuple5::_T5{_0, _1, _2, _3, _4, } => _0, - Tuple5::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple5::_T5{_0, _1, _2, _3, _4, } => _1, - Tuple5::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple5::_T5{_0, _1, _2, _3, _4, } => _2, - Tuple5::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple5::_T5{_0, _1, _2, _3, _4, } => _3, - Tuple5::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple5::_T5{_0, _1, _2, _3, _4, } => _4, - Tuple5::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple5 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple5 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -549,12 +516,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple5::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple5 { + impl Tuple5 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>) -> ::std::rc::Rc) -> Tuple5> { ::std::rc::Rc::new(move |this: Self| -> Tuple5{ match this { @@ -567,32 +533,30 @@ pub mod _System { _4: f_4.clone()(_4) } }, - Tuple5::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple5 {} - impl ::std::hash::Hash + impl Hash for Tuple5 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple5::_T5{_0, _1, _2, _3, _4, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state) }, - Tuple5::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple5 { fn default() -> Tuple5 { Tuple5::_T5 { @@ -605,7 +569,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple5 { fn as_ref(&self) -> Self { self @@ -621,62 +585,50 @@ pub mod _System { _3: T3, _4: T4, _5: T5 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) + } } - impl Tuple6 { + impl Tuple6 { pub fn _0(&self) -> &T0 { match self { Tuple6::_T6{_0, _1, _2, _3, _4, _5, } => _0, - Tuple6::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple6::_T6{_0, _1, _2, _3, _4, _5, } => _1, - Tuple6::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple6::_T6{_0, _1, _2, _3, _4, _5, } => _2, - Tuple6::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple6::_T6{_0, _1, _2, _3, _4, _5, } => _3, - Tuple6::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple6::_T6{_0, _1, _2, _3, _4, _5, } => _4, - Tuple6::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple6::_T6{_0, _1, _2, _3, _4, _5, } => _5, - Tuple6::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple6 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple6 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -696,12 +648,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple6::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple6 { + impl Tuple6 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>) -> ::std::rc::Rc) -> Tuple6> { ::std::rc::Rc::new(move |this: Self| -> Tuple6{ match this { @@ -715,33 +666,31 @@ pub mod _System { _5: f_5.clone()(_5) } }, - Tuple6::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple6 {} - impl ::std::hash::Hash + impl Hash for Tuple6 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple6::_T6{_0, _1, _2, _3, _4, _5, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state) }, - Tuple6::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple6 { fn default() -> Tuple6 { Tuple6::_T6 { @@ -755,7 +704,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple6 { fn as_ref(&self) -> Self { self @@ -772,69 +721,55 @@ pub mod _System { _4: T4, _5: T5, _6: T6 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) + } } - impl Tuple7 { + impl Tuple7 { pub fn _0(&self) -> &T0 { match self { Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, } => _0, - Tuple7::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, } => _1, - Tuple7::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, } => _2, - Tuple7::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, } => _3, - Tuple7::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, } => _4, - Tuple7::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, } => _5, - Tuple7::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, } => _6, - Tuple7::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple7 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple7 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -856,12 +791,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple7::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple7 { + impl Tuple7 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>) -> ::std::rc::Rc) -> Tuple7> { ::std::rc::Rc::new(move |this: Self| -> Tuple7{ match this { @@ -876,34 +810,32 @@ pub mod _System { _6: f_6.clone()(_6) } }, - Tuple7::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple7 {} - impl ::std::hash::Hash + impl Hash for Tuple7 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state) }, - Tuple7::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple7 { fn default() -> Tuple7 { Tuple7::_T7 { @@ -918,7 +850,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple7 { fn as_ref(&self) -> Self { self @@ -936,76 +868,60 @@ pub mod _System { _5: T5, _6: T6, _7: T7 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple8 { + } + } + + impl Tuple8 { pub fn _0(&self) -> &T0 { match self { Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, } => _0, - Tuple8::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, } => _1, - Tuple8::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, } => _2, - Tuple8::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, } => _3, - Tuple8::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, } => _4, - Tuple8::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, } => _5, - Tuple8::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, } => _6, - Tuple8::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, } => _7, - Tuple8::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple8 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple8 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -1029,12 +945,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple8::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple8 { + impl Tuple8 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>) -> ::std::rc::Rc) -> Tuple8> { ::std::rc::Rc::new(move |this: Self| -> Tuple8{ match this { @@ -1050,35 +965,33 @@ pub mod _System { _7: f_7.clone()(_7) } }, - Tuple8::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple8 {} - impl ::std::hash::Hash + impl Hash for Tuple8 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state) }, - Tuple8::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple8 { fn default() -> Tuple8 { Tuple8::_T8 { @@ -1094,7 +1007,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple8 { fn as_ref(&self) -> Self { self @@ -1113,83 +1026,65 @@ pub mod _System { _6: T6, _7: T7, _8: T8 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple9 { + } + } + + impl Tuple9 { pub fn _0(&self) -> &T0 { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => _0, - Tuple9::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => _1, - Tuple9::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => _2, - Tuple9::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => _3, - Tuple9::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => _4, - Tuple9::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => _5, - Tuple9::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => _6, - Tuple9::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => _7, - Tuple9::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => _8, - Tuple9::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple9 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple9 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -1215,12 +1110,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple9::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple9 { + impl Tuple9 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>) -> ::std::rc::Rc) -> Tuple9> { ::std::rc::Rc::new(move |this: Self| -> Tuple9{ match this { @@ -1237,36 +1131,34 @@ pub mod _System { _8: f_8.clone()(_8) } }, - Tuple9::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple9 {} - impl ::std::hash::Hash + impl Hash for Tuple9 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state) }, - Tuple9::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple9 { fn default() -> Tuple9 { Tuple9::_T9 { @@ -1283,7 +1175,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple9 { fn as_ref(&self) -> Self { self @@ -1303,90 +1195,70 @@ pub mod _System { _7: T7, _8: T8, _9: T9 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple10 { + } + } + + impl Tuple10 { pub fn _0(&self) -> &T0 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _0, - Tuple10::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _1, - Tuple10::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _2, - Tuple10::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _3, - Tuple10::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _4, - Tuple10::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _5, - Tuple10::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _6, - Tuple10::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _7, - Tuple10::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _8, - Tuple10::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => _9, - Tuple10::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple10 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple10 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -1414,12 +1286,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple10::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple10 { + impl Tuple10 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>) -> ::std::rc::Rc) -> Tuple10> { ::std::rc::Rc::new(move |this: Self| -> Tuple10{ match this { @@ -1437,37 +1308,35 @@ pub mod _System { _9: f_9.clone()(_9) } }, - Tuple10::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple10 {} - impl ::std::hash::Hash + impl Hash for Tuple10 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state) }, - Tuple10::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple10 { fn default() -> Tuple10 { Tuple10::_T10 { @@ -1485,7 +1354,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple10 { fn as_ref(&self) -> Self { self @@ -1506,97 +1375,75 @@ pub mod _System { _8: T8, _9: T9, _10: T10 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple11 { + } + } + + impl Tuple11 { pub fn _0(&self) -> &T0 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _0, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _1, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _2, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _3, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _4, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _5, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _6, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _7, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _8, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _9, - Tuple11::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => _10, - Tuple11::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple11 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple11 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -1626,12 +1473,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple11::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple11 { + impl Tuple11 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>) -> ::std::rc::Rc) -> Tuple11> { ::std::rc::Rc::new(move |this: Self| -> Tuple11{ match this { @@ -1650,38 +1496,36 @@ pub mod _System { _10: f_10.clone()(_10) } }, - Tuple11::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple11 {} - impl ::std::hash::Hash + impl Hash for Tuple11 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state) }, - Tuple11::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple11 { fn default() -> Tuple11 { Tuple11::_T11 { @@ -1700,7 +1544,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple11 { fn as_ref(&self) -> Self { self @@ -1722,104 +1566,80 @@ pub mod _System { _9: T9, _10: T10, _11: T11 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple12 { + } + } + + impl Tuple12 { pub fn _0(&self) -> &T0 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _0, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _1, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _2, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _3, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _4, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _5, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _6, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _7, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _8, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _9, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _10, - Tuple12::_PhantomVariant(..) => panic!(), } } pub fn _11(&self) -> &T11 { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => _11, - Tuple12::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple12 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple12 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -1851,12 +1671,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple12::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple12 { + impl Tuple12 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>, f_11: ::std::rc::Rc r#__T11 + 'static>) -> ::std::rc::Rc) -> Tuple12> { ::std::rc::Rc::new(move |this: Self| -> Tuple12{ match this { @@ -1876,39 +1695,37 @@ pub mod _System { _11: f_11.clone()(_11) } }, - Tuple12::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple12 {} - impl ::std::hash::Hash + impl Hash for Tuple12 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state); - _11.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state); + ::std::hash::Hash::hash(_11, _state) }, - Tuple12::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple12 { fn default() -> Tuple12 { Tuple12::_T12 { @@ -1928,7 +1745,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple12 { fn as_ref(&self) -> Self { self @@ -1951,111 +1768,85 @@ pub mod _System { _10: T10, _11: T11, _12: T12 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple13 { + } + } + + impl Tuple13 { pub fn _0(&self) -> &T0 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _0, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _1, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _2, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _3, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _4, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _5, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _6, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _7, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _8, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _9, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _10, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _11(&self) -> &T11 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _11, - Tuple13::_PhantomVariant(..) => panic!(), } } pub fn _12(&self) -> &T12 { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => _12, - Tuple13::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple13 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple13 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -2089,12 +1880,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple13::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple13 { + impl Tuple13 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>, f_11: ::std::rc::Rc r#__T11 + 'static>, f_12: ::std::rc::Rc r#__T12 + 'static>) -> ::std::rc::Rc) -> Tuple13> { ::std::rc::Rc::new(move |this: Self| -> Tuple13{ match this { @@ -2115,40 +1905,38 @@ pub mod _System { _12: f_12.clone()(_12) } }, - Tuple13::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple13 {} - impl ::std::hash::Hash + impl Hash for Tuple13 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state); - _11.hash(_state); - _12.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state); + ::std::hash::Hash::hash(_11, _state); + ::std::hash::Hash::hash(_12, _state) }, - Tuple13::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple13 { fn default() -> Tuple13 { Tuple13::_T13 { @@ -2169,7 +1957,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple13 { fn as_ref(&self) -> Self { self @@ -2193,118 +1981,90 @@ pub mod _System { _11: T11, _12: T12, _13: T13 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple14 { + } + } + + impl Tuple14 { pub fn _0(&self) -> &T0 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _0, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _1, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _2, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _3, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _4, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _5, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _6, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _7, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _8, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _9, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _10, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _11(&self) -> &T11 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _11, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _12(&self) -> &T12 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _12, - Tuple14::_PhantomVariant(..) => panic!(), } } pub fn _13(&self) -> &T13 { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => _13, - Tuple14::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple14 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple14 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -2340,12 +2100,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple14::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple14 { + impl Tuple14 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>, f_11: ::std::rc::Rc r#__T11 + 'static>, f_12: ::std::rc::Rc r#__T12 + 'static>, f_13: ::std::rc::Rc r#__T13 + 'static>) -> ::std::rc::Rc) -> Tuple14> { ::std::rc::Rc::new(move |this: Self| -> Tuple14{ match this { @@ -2367,41 +2126,39 @@ pub mod _System { _13: f_13.clone()(_13) } }, - Tuple14::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple14 {} - impl ::std::hash::Hash + impl Hash for Tuple14 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state); - _11.hash(_state); - _12.hash(_state); - _13.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state); + ::std::hash::Hash::hash(_11, _state); + ::std::hash::Hash::hash(_12, _state); + ::std::hash::Hash::hash(_13, _state) }, - Tuple14::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple14 { fn default() -> Tuple14 { Tuple14::_T14 { @@ -2423,7 +2180,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple14 { fn as_ref(&self) -> Self { self @@ -2448,125 +2205,95 @@ pub mod _System { _12: T12, _13: T13, _14: T14 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple15 { + } + } + + impl Tuple15 { pub fn _0(&self) -> &T0 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _0, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _1, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _2, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _3, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _4, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _5, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _6, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _7, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _8, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _9, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _10, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _11(&self) -> &T11 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _11, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _12(&self) -> &T12 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _12, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _13(&self) -> &T13 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _13, - Tuple15::_PhantomVariant(..) => panic!(), } } pub fn _14(&self) -> &T14 { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => _14, - Tuple15::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple15 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple15 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -2604,12 +2331,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple15::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple15 { + impl Tuple15 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>, f_11: ::std::rc::Rc r#__T11 + 'static>, f_12: ::std::rc::Rc r#__T12 + 'static>, f_13: ::std::rc::Rc r#__T13 + 'static>, f_14: ::std::rc::Rc r#__T14 + 'static>) -> ::std::rc::Rc) -> Tuple15> { ::std::rc::Rc::new(move |this: Self| -> Tuple15{ match this { @@ -2632,42 +2358,40 @@ pub mod _System { _14: f_14.clone()(_14) } }, - Tuple15::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple15 {} - impl ::std::hash::Hash + impl Hash for Tuple15 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state); - _11.hash(_state); - _12.hash(_state); - _13.hash(_state); - _14.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state); + ::std::hash::Hash::hash(_11, _state); + ::std::hash::Hash::hash(_12, _state); + ::std::hash::Hash::hash(_13, _state); + ::std::hash::Hash::hash(_14, _state) }, - Tuple15::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple15 { fn default() -> Tuple15 { Tuple15::_T15 { @@ -2690,7 +2414,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple15 { fn as_ref(&self) -> Self { self @@ -2716,132 +2440,100 @@ pub mod _System { _13: T13, _14: T14, _15: T15 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple16 { + } + } + + impl Tuple16 { pub fn _0(&self) -> &T0 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _0, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _1, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _2, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _3, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _4, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _5, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _6, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _7, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _8, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _9, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _10, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _11(&self) -> &T11 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _11, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _12(&self) -> &T12 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _12, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _13(&self) -> &T13 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _13, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _14(&self) -> &T14 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _14, - Tuple16::_PhantomVariant(..) => panic!(), } } pub fn _15(&self) -> &T15 { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => _15, - Tuple16::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple16 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple16 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -2881,12 +2573,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple16::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple16 { + impl Tuple16 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>, f_11: ::std::rc::Rc r#__T11 + 'static>, f_12: ::std::rc::Rc r#__T12 + 'static>, f_13: ::std::rc::Rc r#__T13 + 'static>, f_14: ::std::rc::Rc r#__T14 + 'static>, f_15: ::std::rc::Rc r#__T15 + 'static>) -> ::std::rc::Rc) -> Tuple16> { ::std::rc::Rc::new(move |this: Self| -> Tuple16{ match this { @@ -2910,43 +2601,41 @@ pub mod _System { _15: f_15.clone()(_15) } }, - Tuple16::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple16 {} - impl ::std::hash::Hash + impl Hash for Tuple16 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state); - _11.hash(_state); - _12.hash(_state); - _13.hash(_state); - _14.hash(_state); - _15.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state); + ::std::hash::Hash::hash(_11, _state); + ::std::hash::Hash::hash(_12, _state); + ::std::hash::Hash::hash(_13, _state); + ::std::hash::Hash::hash(_14, _state); + ::std::hash::Hash::hash(_15, _state) }, - Tuple16::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple16 { fn default() -> Tuple16 { Tuple16::_T16 { @@ -2970,7 +2659,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple16 { fn as_ref(&self) -> Self { self @@ -2997,139 +2686,105 @@ pub mod _System { _14: T14, _15: T15, _16: T16 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple17 { + } + } + + impl Tuple17 { pub fn _0(&self) -> &T0 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _0, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _1, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _2, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _3, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _4, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _5, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _6, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _7, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _8, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _9, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _10, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _11(&self) -> &T11 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _11, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _12(&self) -> &T12 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _12, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _13(&self) -> &T13 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _13, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _14(&self) -> &T14 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _14, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _15(&self) -> &T15 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _15, - Tuple17::_PhantomVariant(..) => panic!(), } } pub fn _16(&self) -> &T16 { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => _16, - Tuple17::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple17 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple17 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -3171,12 +2826,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple17::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple17 { + impl Tuple17 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>, f_11: ::std::rc::Rc r#__T11 + 'static>, f_12: ::std::rc::Rc r#__T12 + 'static>, f_13: ::std::rc::Rc r#__T13 + 'static>, f_14: ::std::rc::Rc r#__T14 + 'static>, f_15: ::std::rc::Rc r#__T15 + 'static>, f_16: ::std::rc::Rc r#__T16 + 'static>) -> ::std::rc::Rc) -> Tuple17> { ::std::rc::Rc::new(move |this: Self| -> Tuple17{ match this { @@ -3201,44 +2855,42 @@ pub mod _System { _16: f_16.clone()(_16) } }, - Tuple17::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple17 {} - impl ::std::hash::Hash + impl Hash for Tuple17 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state); - _11.hash(_state); - _12.hash(_state); - _13.hash(_state); - _14.hash(_state); - _15.hash(_state); - _16.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state); + ::std::hash::Hash::hash(_11, _state); + ::std::hash::Hash::hash(_12, _state); + ::std::hash::Hash::hash(_13, _state); + ::std::hash::Hash::hash(_14, _state); + ::std::hash::Hash::hash(_15, _state); + ::std::hash::Hash::hash(_16, _state) }, - Tuple17::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple17 { fn default() -> Tuple17 { Tuple17::_T17 { @@ -3263,7 +2915,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple17 { fn as_ref(&self) -> Self { self @@ -3291,146 +2943,110 @@ pub mod _System { _15: T15, _16: T16, _17: T17 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple18 { + } + } + + impl Tuple18 { pub fn _0(&self) -> &T0 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _0, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _1, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _2, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _3, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _4, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _5, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _6, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _7, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _8, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _9, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _10, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _11(&self) -> &T11 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _11, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _12(&self) -> &T12 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _12, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _13(&self) -> &T13 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _13, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _14(&self) -> &T14 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _14, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _15(&self) -> &T15 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _15, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _16(&self) -> &T16 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _16, - Tuple18::_PhantomVariant(..) => panic!(), } } pub fn _17(&self) -> &T17 { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => _17, - Tuple18::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple18 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple18 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -3474,12 +3090,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple18::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple18 { + impl Tuple18 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>, f_11: ::std::rc::Rc r#__T11 + 'static>, f_12: ::std::rc::Rc r#__T12 + 'static>, f_13: ::std::rc::Rc r#__T13 + 'static>, f_14: ::std::rc::Rc r#__T14 + 'static>, f_15: ::std::rc::Rc r#__T15 + 'static>, f_16: ::std::rc::Rc r#__T16 + 'static>, f_17: ::std::rc::Rc r#__T17 + 'static>) -> ::std::rc::Rc) -> Tuple18> { ::std::rc::Rc::new(move |this: Self| -> Tuple18{ match this { @@ -3505,45 +3120,43 @@ pub mod _System { _17: f_17.clone()(_17) } }, - Tuple18::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple18 {} - impl ::std::hash::Hash + impl Hash for Tuple18 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state); - _11.hash(_state); - _12.hash(_state); - _13.hash(_state); - _14.hash(_state); - _15.hash(_state); - _16.hash(_state); - _17.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state); + ::std::hash::Hash::hash(_11, _state); + ::std::hash::Hash::hash(_12, _state); + ::std::hash::Hash::hash(_13, _state); + ::std::hash::Hash::hash(_14, _state); + ::std::hash::Hash::hash(_15, _state); + ::std::hash::Hash::hash(_16, _state); + ::std::hash::Hash::hash(_17, _state) }, - Tuple18::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple18 { fn default() -> Tuple18 { Tuple18::_T18 { @@ -3569,7 +3182,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple18 { fn as_ref(&self) -> Self { self @@ -3598,153 +3211,115 @@ pub mod _System { _16: T16, _17: T17, _18: T18 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple19 { + } + } + + impl Tuple19 { pub fn _0(&self) -> &T0 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _0, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _1, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _2, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _3, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _4, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _5, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _6, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _7, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _8, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _9, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _10, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _11(&self) -> &T11 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _11, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _12(&self) -> &T12 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _12, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _13(&self) -> &T13 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _13, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _14(&self) -> &T14 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _14, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _15(&self) -> &T15 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _15, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _16(&self) -> &T16 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _16, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _17(&self) -> &T17 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _17, - Tuple19::_PhantomVariant(..) => panic!(), } } pub fn _18(&self) -> &T18 { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => _18, - Tuple19::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple19 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple19 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -3790,12 +3365,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple19::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple19 { + impl Tuple19 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>, f_11: ::std::rc::Rc r#__T11 + 'static>, f_12: ::std::rc::Rc r#__T12 + 'static>, f_13: ::std::rc::Rc r#__T13 + 'static>, f_14: ::std::rc::Rc r#__T14 + 'static>, f_15: ::std::rc::Rc r#__T15 + 'static>, f_16: ::std::rc::Rc r#__T16 + 'static>, f_17: ::std::rc::Rc r#__T17 + 'static>, f_18: ::std::rc::Rc r#__T18 + 'static>) -> ::std::rc::Rc) -> Tuple19> { ::std::rc::Rc::new(move |this: Self| -> Tuple19{ match this { @@ -3822,46 +3396,44 @@ pub mod _System { _18: f_18.clone()(_18) } }, - Tuple19::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple19 {} - impl ::std::hash::Hash + impl Hash for Tuple19 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state); - _11.hash(_state); - _12.hash(_state); - _13.hash(_state); - _14.hash(_state); - _15.hash(_state); - _16.hash(_state); - _17.hash(_state); - _18.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state); + ::std::hash::Hash::hash(_11, _state); + ::std::hash::Hash::hash(_12, _state); + ::std::hash::Hash::hash(_13, _state); + ::std::hash::Hash::hash(_14, _state); + ::std::hash::Hash::hash(_15, _state); + ::std::hash::Hash::hash(_16, _state); + ::std::hash::Hash::hash(_17, _state); + ::std::hash::Hash::hash(_18, _state) }, - Tuple19::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple19 { fn default() -> Tuple19 { Tuple19::_T19 { @@ -3888,7 +3460,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple19 { fn as_ref(&self) -> Self { self @@ -3918,160 +3490,120 @@ pub mod _System { _17: T17, _18: T18, _19: T19 - }, - _PhantomVariant(::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData, - ::std::marker::PhantomData) - } - - impl Tuple20 { + } + } + + impl Tuple20 { pub fn _0(&self) -> &T0 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _0, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _1(&self) -> &T1 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _1, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _2(&self) -> &T2 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _2, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _3(&self) -> &T3 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _3, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _4(&self) -> &T4 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _4, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _5(&self) -> &T5 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _5, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _6(&self) -> &T6 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _6, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _7(&self) -> &T7 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _7, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _8(&self) -> &T8 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _8, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _9(&self) -> &T9 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _9, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _10(&self) -> &T10 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _10, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _11(&self) -> &T11 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _11, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _12(&self) -> &T12 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _12, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _13(&self) -> &T13 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _13, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _14(&self) -> &T14 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _14, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _15(&self) -> &T15 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _15, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _16(&self) -> &T16 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _16, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _17(&self) -> &T17 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _17, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _18(&self) -> &T18 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _18, - Tuple20::_PhantomVariant(..) => panic!(), } } pub fn _19(&self) -> &T19 { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => _19, - Tuple20::_PhantomVariant(..) => panic!(), } } } - impl ::std::fmt::Debug + impl Debug for Tuple20 { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { crate::DafnyPrint::fmt_print(self, f, true) } } - impl crate::DafnyPrint + impl DafnyPrint for Tuple20 { fn fmt_print(&self, _formatter: &mut ::std::fmt::Formatter, _in_seq: bool) -> std::fmt::Result { match self { @@ -4119,12 +3651,11 @@ pub mod _System { write!(_formatter, ")")?; Ok(()) }, - Tuple20::_PhantomVariant(..) => {panic!()}, } } } - impl Tuple20 { + impl Tuple20 { pub fn coerce(f_0: ::std::rc::Rc r#__T0 + 'static>, f_1: ::std::rc::Rc r#__T1 + 'static>, f_2: ::std::rc::Rc r#__T2 + 'static>, f_3: ::std::rc::Rc r#__T3 + 'static>, f_4: ::std::rc::Rc r#__T4 + 'static>, f_5: ::std::rc::Rc r#__T5 + 'static>, f_6: ::std::rc::Rc r#__T6 + 'static>, f_7: ::std::rc::Rc r#__T7 + 'static>, f_8: ::std::rc::Rc r#__T8 + 'static>, f_9: ::std::rc::Rc r#__T9 + 'static>, f_10: ::std::rc::Rc r#__T10 + 'static>, f_11: ::std::rc::Rc r#__T11 + 'static>, f_12: ::std::rc::Rc r#__T12 + 'static>, f_13: ::std::rc::Rc r#__T13 + 'static>, f_14: ::std::rc::Rc r#__T14 + 'static>, f_15: ::std::rc::Rc r#__T15 + 'static>, f_16: ::std::rc::Rc r#__T16 + 'static>, f_17: ::std::rc::Rc r#__T17 + 'static>, f_18: ::std::rc::Rc r#__T18 + 'static>, f_19: ::std::rc::Rc r#__T19 + 'static>) -> ::std::rc::Rc) -> Tuple20> { ::std::rc::Rc::new(move |this: Self| -> Tuple20{ match this { @@ -4152,47 +3683,45 @@ pub mod _System { _19: f_19.clone()(_19) } }, - Tuple20::_PhantomVariant(..) => {panic!()}, } }) } } - impl Eq + impl Eq for Tuple20 {} - impl ::std::hash::Hash + impl Hash for Tuple20 { fn hash<_H: ::std::hash::Hasher>(&self, _state: &mut _H) { match self { Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, } => { - _0.hash(_state); - _1.hash(_state); - _2.hash(_state); - _3.hash(_state); - _4.hash(_state); - _5.hash(_state); - _6.hash(_state); - _7.hash(_state); - _8.hash(_state); - _9.hash(_state); - _10.hash(_state); - _11.hash(_state); - _12.hash(_state); - _13.hash(_state); - _14.hash(_state); - _15.hash(_state); - _16.hash(_state); - _17.hash(_state); - _18.hash(_state); - _19.hash(_state) + ::std::hash::Hash::hash(_0, _state); + ::std::hash::Hash::hash(_1, _state); + ::std::hash::Hash::hash(_2, _state); + ::std::hash::Hash::hash(_3, _state); + ::std::hash::Hash::hash(_4, _state); + ::std::hash::Hash::hash(_5, _state); + ::std::hash::Hash::hash(_6, _state); + ::std::hash::Hash::hash(_7, _state); + ::std::hash::Hash::hash(_8, _state); + ::std::hash::Hash::hash(_9, _state); + ::std::hash::Hash::hash(_10, _state); + ::std::hash::Hash::hash(_11, _state); + ::std::hash::Hash::hash(_12, _state); + ::std::hash::Hash::hash(_13, _state); + ::std::hash::Hash::hash(_14, _state); + ::std::hash::Hash::hash(_15, _state); + ::std::hash::Hash::hash(_16, _state); + ::std::hash::Hash::hash(_17, _state); + ::std::hash::Hash::hash(_18, _state); + ::std::hash::Hash::hash(_19, _state) }, - Tuple20::_PhantomVariant(..) => {panic!()}, } } } - impl ::std::default::Default + impl Default for Tuple20 { fn default() -> Tuple20 { Tuple20::_T20 { @@ -4220,7 +3749,7 @@ pub mod _System { } } - impl ::std::convert::AsRef> + impl AsRef> for &Tuple20 { fn as_ref(&self) -> Self { self diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index 6d5f9e1df9e..48dc924d582 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -182,7 +182,7 @@ mod tests { assert!(!(t != s)); let s = multiset! {55, 56, 57, 58, 59}; - let s = multiset! {55, 56, 57, 58, 58}; + let t = multiset! {55, 56, 57, 58, 58}; assert!(s != t); assert!(t != s); @@ -384,7 +384,7 @@ mod tests { struct ClassWrapper { /*var*/ t: T, /*var*/ x: crate::DafnyInt, - /*const*/ next: *mut ClassWrapper, + /*const*/ next: Ptr>, /*const*/ constant: crate::DafnyInt, } impl ClassWrapper { @@ -397,7 +397,7 @@ mod tests { } impl ClassWrapper { - fn constructor(t: T) -> *mut ClassWrapper { + fn constructor(t: T) -> Ptr> { let this = crate::allocate::>(); update_field_nodrop!(this, t, t); update_field_nodrop!(this, next, this); @@ -423,7 +423,7 @@ mod tests { #[test] #[allow(unused_unsafe)] fn test_class_wrapper() { - let c: *mut ClassWrapper = ClassWrapper::constructor(53); + let c: Ptr> = ClassWrapper::constructor(53); assert_eq!(read!(c).constant, int!(42)); assert_eq!(read!(c).t, 53); assert_eq!(read!(c).x, int!(0)); @@ -441,38 +441,6 @@ mod tests { assert_eq!(Rc::strong_count(&x_copy.data), 1); } - #[test] - #[allow(unused_unsafe)] - fn test_extern_class_wrapper_with_box() { - #[allow(unused_mut)] - let mut c = Box::new(ClassWrapper { - t: 53, - x: int!(0), - next: std::ptr::null_mut(), - constant: int!(42), - }); - assert_eq!(read!(c).constant, int!(42)); - modify!(c).increment_x(); - assert_eq!(read!(c).constant_plus_x(), int!(43)); - // Automatically dropped - } - - #[test] - #[allow(unused_unsafe)] - fn test_extern_class_wrapper_with_mutable_borrow() { - #[allow(unused_mut)] - let c: &mut ClassWrapper = &mut ClassWrapper { - t: 53, - x: int!(0), - next: std::ptr::null_mut(), - constant: int!(42), - }; - assert_eq!(read!(c).constant, int!(42)); - modify!(c).increment_x(); - assert_eq!(read!(c).constant_plus_x(), int!(43)); - // Automatically dropped - } - // Requires test1 || test2 // We will not do that as it enables the compiler to assume that t contains a valid Rc when it does not. // Prefer MaybePlacebo @@ -501,9 +469,9 @@ mod tests { } fn override_placebo(o: T, do_override: bool) { - let mut x: MaybePlacebo = MaybePlacebo::::new(); + let mut _x: MaybePlacebo = MaybePlacebo::::new(); if do_override { - x = MaybePlacebo::from(o.clone()); + _x = MaybePlacebo::from(o.clone()); } } @@ -513,8 +481,8 @@ mod tests { override_placebo::>(Rc::new(BigInt::from(1)), true); override_placebo::(int!(1), false); override_placebo::(int!(1), true); - let _x: MaybePlacebo<*mut ClassWrapper> = - MaybePlacebo::<*mut ClassWrapper>::new(); + let _x: MaybePlacebo>> = + MaybePlacebo::>>::new(); //let mut f: Rc Class> = Class> as Placebo>::new(); } @@ -531,19 +499,19 @@ mod tests { #[test] fn test_coercion_immutable() { let o = ClassWrapper::::constructor(1); - let a: *mut dyn Any = Upcast::::upcast(read!(o)); + let a: Ptr = Upcast::::upcast(modify!(o)); assert_eq!(cast!(a, ClassWrapper), o); let seq_o = seq![o]; - let seq_a = Sequence::<*mut ClassWrapper>::coerce(upcast::, dyn Any>())(seq_o); + let seq_a = Sequence::>>::coerce(upcast::, dyn Any>())(seq_o); assert_eq!(cast!(seq_a.get_usize(0), ClassWrapper), o); let set_o = set! {o}; - let set_a = Set::<*mut ClassWrapper>::coerce(upcast::, dyn Any>())(set_o); + let set_a = Set::>>::coerce(upcast::, dyn Any>())(set_o); assert_eq!(cast!(set_a.peek(), ClassWrapper), o); let multiset_o = multiset! {o, o}; - let multiset_a = Multiset::<*mut ClassWrapper>::coerce(upcast::, dyn Any>())(multiset_o); + let multiset_a = Multiset::>>::coerce(upcast::, dyn Any>())(multiset_o); assert_eq!(cast!(multiset_a.peek(), ClassWrapper), o); let map_o = map![1 => o, 2 => o]; - let map_a = Map::>::coerce(upcast::, dyn Any>())(map_o); + let map_a = Map::>>::coerce(upcast::, dyn Any>())(map_o); assert_eq!(cast!(map_a.get(&1), ClassWrapper), o); deallocate(o); } @@ -570,8 +538,8 @@ mod tests { assert_eq!(seq_i32.cardinality_usize(), 0); assert_eq!(map_i32.cardinality_usize(), 0); assert_eq!(multiset_i32.cardinality_usize(), 0); - let ptr_i32 = <*mut i32 as NontrivialDefault>::nontrivial_default(); - assert_eq!(ptr_i32, std::ptr::null_mut()); + let ptr_i32 = as NontrivialDefault>::nontrivial_default(); + assert_eq!(ptr_i32, Ptr::::null()); } #[test] @@ -782,6 +750,14 @@ mod tests { let a3: Object = cast_object!(z.clone(), NodeRcMut); assert_eq!(refcount!(x), 5); assert_eq!(rd!(a3).val, int!(42)); + + // Other way to create objects + let direct: Object = Object::::new(NodeRcMut {val: int!(1), next: Object::::null()}); + assert_eq!(rd!(direct).val, int!(1)); + let tail: Object = Object::::null(); + assert_eq!(tail, rd!(direct).next); + assert!(tail.is_null()); + assert!(!direct.is_null()); let a: Object<[i32]> = rcmut::array_object_from_rc(Rc::new([42, 43, 44])); assert_eq!(rd!(a).len(), 3); @@ -794,22 +770,22 @@ mod tests { let previous_count = refcount!(x); { - let z = Object::::from_ref(x.as_ref()); + let z = Object::::from_ref(x.as_mut()); assert_eq!(refcount!(z), previous_count + 1); assert_eq!(refcount!(x), previous_count + 1); } assert_eq!(refcount!(x), previous_count); - let mut objects: Set> = crate::set!{y.clone(), cast_any_object!(x.clone())}; + let objects: Set> = crate::set!{y.clone(), cast_any_object!(x.clone())}; assert_eq!(objects.cardinality_usize(), 1); } pub struct NodeRawMut { val: DafnyInt, - next: *mut NodeRawMut, + next: Ptr, } impl NodeRawMut { - fn _ctor(this: *mut NodeRawMut, val: DafnyInt) { + fn _ctor(this: Ptr, val: DafnyInt) { let mut val_assign = false; update_field_uninit!(this, val, val_assign, val); } @@ -822,16 +798,18 @@ mod tests { #[test] fn test_rawmut() { - let x: *mut NodeRawMut = allocate::(); + let x: Ptr = allocate::(); NodeRawMut::_ctor(x.clone(), int!(42)); assert_eq!(read!(x.clone()).val, int!(42)); modify!(x.clone()).next = x.clone(); assert_eq!(read!(read!(x.clone()).next.clone()).val, int!(42)); - modify!(read!(x.clone()).next.clone()).next = std::ptr::null_mut(); - let y: *mut dyn Any = upcast::<_, _>()(x); - let z: *mut dyn NodeRcMutTrait = upcast::<_, _>()(x); - let a2: *mut NodeRawMut = cast!(y, NodeRawMut); - let a3: *mut NodeRawMut = cast!(z, NodeRawMut); + modify!(read!(x.clone()).next.clone()).next = Ptr::null(); + let y: Ptr = upcast::<_, _>()(x); + assert!(y.is_instance_of::()); + assert!(!y.is_instance_of::()); + let z: Ptr = upcast::<_, _>()(x); + let _a2: Ptr = cast!(y, NodeRawMut); + let _a3: Ptr = cast!(z, NodeRawMut); deallocate(x); let a = array::from_native(Box::new([42, 43, 44])); @@ -857,4 +835,27 @@ mod tests { assert_eq!(DafnyUsize::into_usize(b), u); assert_eq!(DafnyUsize::into_usize(int!(b)), u); } + + // Tests that we can compose Dafny types, like a sequence of maps + fn _test(_input: Sequence>) { + } + + #[derive(Clone)] + pub struct InternalOpaqueError { + pub message: String, + } + + crate::UpcastDefObject!(InternalOpaqueError, dyn Any); + + #[test] + fn test_native_string_upcast() { + let s = InternalOpaqueError { message: "Hello, World!".to_string() }; + let o: Object = Object::new(s); + let n: Object = upcast_object::()(o); + let x = cast_object!(n, InternalOpaqueError); + let s2 = unsafe { + crate::dafny_runtime_conversions::object::dafny_class_to_struct(x) + }; + assert_eq!(s2.message, "Hello, World!"); + } } diff --git a/Source/DafnyRuntime/Makefile b/Source/DafnyRuntime/Makefile index 6d5ae6c6765..77543dbab30 100644 --- a/Source/DafnyRuntime/Makefile +++ b/Source/DafnyRuntime/Makefile @@ -5,24 +5,13 @@ DAFNY = dotnet run --project ../Dafny --no-build -- GENERATED_SYSTEM_MODULE_SOURCE=obj/systemModulePopulator.cs GENERATED_SYSTEM_MODULE_TARGET=DafnyRuntimeSystemModule.cs -GENERATED_SYSTEM_MODULE_SOURCE_RS=obj/systemModulePopulator-rust/src/systemModulePopulator.rs -GENERATED_SYSTEM_MODULE_TARGET_RS=DafnyRuntimeRust/src/system/mod.rs - all: check-system-module build-system-module: $(DAFNY) translate cs --no-verify --use-basename-for-filename --optimize-erasable-datatype-wrapper:false --system-module:OmitAllOtherModules systemModulePopulator.dfy --output:obj/systemModulePopulator -build-system-module-rs: - $(DAFNY) translate rs --no-verify --use-basename-for-filename --optimize-erasable-datatype-wrapper:false --system-module:OmitAllOtherModules systemModulePopulator.dfy --output:obj/systemModulePopulator - python -c "import sys; data = sys.stdin.read(); sys.stdout.write(data.replace('::dafny_runtime', 'crate'))" < $(GENERATED_SYSTEM_MODULE_SOURCE_RS) > $(GENERATED_SYSTEM_MODULE_SOURCE_RS).tmp && mv $(GENERATED_SYSTEM_MODULE_SOURCE_RS).tmp $(GENERATED_SYSTEM_MODULE_SOURCE_RS) - -check-system-module: build-system-module build-system-module-rs +check-system-module: build-system-module diff $(GENERATED_SYSTEM_MODULE_SOURCE) $(GENERATED_SYSTEM_MODULE_TARGET) - diff $(GENERATED_SYSTEM_MODULE_SOURCE_RS) $(GENERATED_SYSTEM_MODULE_TARGET_RS) update-system-module: build-system-module cp $(GENERATED_SYSTEM_MODULE_SOURCE) $(GENERATED_SYSTEM_MODULE_TARGET) - -update-system-module-rs: build-system-module-rs - cp $(GENERATED_SYSTEM_MODULE_SOURCE_RS) $(GENERATED_SYSTEM_MODULE_TARGET_RS) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/AsIs-Compile.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/AsIs-Compile.dfy.rs.check index 9b64d34940c..96d3f9ff702 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/AsIs-Compile.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/AsIs-Compile.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Unsupported:\ DAST_dBinOp_dPlus\ with\ not\ 2\ elements.* \ No newline at end of file +// CHECK-L: error: prefix `ClassR` is unknown \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy index 5529546afae..5f11c241c18 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy @@ -1,4 +1,4 @@ -// NONUNIFORM: Temporary development of the Rust compiler +// NONUNIFORM: Rust-specific tests // RUN: %baredafny run --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy new file mode 100644 index 00000000000..aae1bce74e3 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy @@ -0,0 +1,21 @@ +// NONUNIFORM: Can't create class instances without constructors as Rust does not support Dafny defaults since subset types are erased +// RUN: %exits-with 3 %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +class Test { + var x: T +} + +type Positive = x: int | x > 0 witness 1 + +method Main() { + var x: Test := new Test; + print x.x, "\n"; + if x.x == 0 { + assert false; + expect false; + } + x.x := 2; + expect x.x == 2; +} + diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect new file mode 100644 index 00000000000..37c2ed71ea8 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 2 verified, 0 errors +(0,-1): Error: Microsoft.Dafny.UnsupportedInvalidOperationException: Creation of object of type Test requires a constructor diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy index 4845ba95f5c..e9759a8df57 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy @@ -1,4 +1,4 @@ -// NONUNIFORM: Temporary development of the Rust compiler +// NONUNIFORM: Rust-specific tests // RUN: %baredafny run --target=rs --emit-uncompilable-code "%s" > "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy index 2a731da1728..913b7d42298 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy @@ -1,4 +1,4 @@ -// NONUNIFORM: Temporary development of the Rust compiler +// NONUNIFORM: Rust-specific tests // RUN: %baredafny run --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy index 3b672823f0b..6086f7a6b19 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy @@ -1,7 +1,8 @@ -// NONUNIFORM: Temporary development of the Rust compiler +// NONUNIFORM: Rust-specific tests // RUN: %baredafny run --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" - +// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %diff "%s.expect" "%t" class Y { var c: int @@ -30,4 +31,5 @@ method Main() { var w := z.0; var fw := FunWrap.FunWrap((z: int) => Tuple2(x, y)); var fx: FunWrap := fw; + print "Everything is ok."; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy.expect index 00a51f822da..839df7554a0 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy.expect @@ -1,2 +1,3 @@ Dafny program verifier finished with 3 verified, 0 errors +Everything is ok. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy new file mode 100644 index 00000000000..aa003792960 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy @@ -0,0 +1,6 @@ +// NONUNIFORM: Tests that references to function constants are eta-expanded with an additional call and type annotations in Rust backend +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +const f: int -> int := x => x +const g: int -> int := f diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy.expect new file mode 100644 index 00000000000..012f5b99379 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy.expect @@ -0,0 +1,2 @@ + +Dafny program verifier finished with 0 verified, 0 errors diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy new file mode 100644 index 00000000000..f964dbdb778 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy @@ -0,0 +1,38 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" +// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +method Main() { + var valuesArray := new int[8](i => i); + var values1a := valuesArray[1..]; + expect values1a == [1, 2, 3, 4, 5, 6, 7]; + var values1b := valuesArray[..7]; + expect values1b == [0, 1, 2, 3, 4, 5, 6]; + var values1c := valuesArray[..]; + expect values1c == [0, 1, 2, 3, 4, 5, 6, 7]; + var values1 := valuesArray[1..8]; + expect values1 == values1a; + var values2 := values1[1..]; + expect values2 == [2, 3, 4, 5, 6, 7]; + var values3 := values1[..5]; + expect values3 == [1, 2, 3, 4, 5]; + var values4 := values1[..]; + expect values4 == [1, 2, 3, 4, 5, 6, 7]; + var values := values1[0..6]; + expect values == [1, 2, 3, 4, 5, 6]; + var acc := 0; + for i := 0 to |values| + { + if values[i] % 3 == 0 { + acc := acc + 3; + continue; + } + if (5 <= values[i]) == true { + break; + } + acc := acc + values[i]; + } + print acc, "\n"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy.expect new file mode 100644 index 00000000000..aef9e05f0b8 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 1 verified, 0 errors +10 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy new file mode 100644 index 00000000000..a655ada01ce --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy @@ -0,0 +1,38 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +newtype Uint8 = x: int | 0 <= x < 256 + +datatype Option = Some(value: T) | None { + predicate IsFailure() { + None? + } + function PropagateFailure(): Option { + None + } + function Extract(): T + requires !IsFailure() { + value + } + method ExtractMethod() returns (r: T) + requires !IsFailure() { + return value; + } +} + +method TestCompile(input: Option) returns (output: Option) { + var middle :- input; + var middleMethod := Some(middle).ExtractMethod(); + return None; +} + +method Main() { + var x: Uint8 := 2; + // Correct rendering of expressions that can interpret the first '<' as a generic argument + var y: bv16 := (x as bv16) << 2; + expect y == 8; + expect (x as bv16) < 3; + expect (x as bv16) <= 3; + print "Everything is ok."; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy.expect new file mode 100644 index 00000000000..ce38ef0ce55 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 5 verified, 0 errors +Everything is ok. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy new file mode 100644 index 00000000000..4bde1628787 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy @@ -0,0 +1,9 @@ +// NONUNIFORM: Tests that datatype members like hash do not shadow those generated by Rust backend +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +datatype Loop = Loop(loop: Loop) | Point() { + function hash(): string { + "uh-oh!" + } +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect new file mode 100644 index 00000000000..012f5b99379 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect @@ -0,0 +1,2 @@ + +Dafny program verifier finished with 0 verified, 0 errors diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy new file mode 100644 index 00000000000..ec117b68b5c --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy @@ -0,0 +1,35 @@ +// NONUNIFORM: Tests generation of elephant assignment to shadowed variable +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +datatype Option = Some(value: string) | None() { + function IsFailure(): bool { None? } + function PropagateFailure(): Option + requires IsFailure() + { None() } + function Extract(): string + requires !IsFailure() + { value } +} + +function Foo(j: int): Option { + Some("foo") +} + +method Test1(j: int) returns (o: Option) { + var j :- Foo(j); + return Some(j); +} + +method Test2(j: int) returns (o: Option) { + var s := ""; + s :- Foo(j); + return Some(s); +} + +method Main() { + var o := Test1(0); + expect o == Some("foo"); + o := Test2(0); + expect o == Some("foo"); +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy.expect new file mode 100644 index 00000000000..ba00363fc08 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy.expect @@ -0,0 +1,2 @@ + +Dafny program verifier finished with 4 verified, 0 errors diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy new file mode 100644 index 00000000000..ebec1203fcf --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy @@ -0,0 +1,23 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %exits-with 3 %baredafny run --target=rs --input "%S/externalclasses.rs" "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +module {:extern} ExternalClassContainer { + method {:extern} Test() returns (i: int) + trait GetValueHolder { + function GetValue(): int + function GetValue2(): int + } + + class {:extern} ExternalPartialClass extends GetValueHolder { + constructor {:extern} () + function {:extern} GetValue(): int // Error + function GetValue2(): int { + 1 + } + } +} + +method Main() { + var c := new ExternalClassContainer.ExternalPartialClass(); +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy.expect new file mode 100644 index 00000000000..5a1931fc905 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 3 verified, 0 errors +(0,-1): Error: Microsoft.Dafny.UnsupportedInvalidOperationException: Error: In the class ExternalClassContainer.ExternalPartialClass, some proper methods of crate::ExternalClassContainer::GetValueHolder are marked {:extern} and some are not. For the Rust compiler, please make all methods (GetValue, GetValue2) bodiless and mark as {:extern} and implement them in a Rust file, or mark none of them as {:extern} and implement them in Dafny. Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible. diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy new file mode 100644 index 00000000000..c6d50772615 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy @@ -0,0 +1,103 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --input "%S/externalclasses.rs" "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +module {:extern "External.Class.Container"} ExternalClassContainer { + class {:extern} ExternalClass { + constructor {:extern} (i: int) + } + method {:extern} Test() returns (i: int) + trait GetValueHolder { + function GetValue(): int + } + + class {:extern} ExternalPartialClass extends GetValueHolder { + constructor {:extern} () + function {:extern} GetValue(): int + method Print() { + print GetValue(); + } + } + class {:extern} ExternalPartialClass2 extends GetValueHolder { + constructor {:extern} () + function GetValue(): int { + 2 + } + method Print() { + print GetValue(); + } + } +} + +module Dafny.FileIO { + method ReadBytesFromFile(path: string) returns (res: string) { + res := INTERNAL_ReadBytesFromFile(path); + INTERNAL_WriteBytesToFile(path, res); + } + + method {:extern "DafnyLibraries.FileIO", "INTERNAL_WriteBytesToFile"} + INTERNAL_WriteBytesToFile(path: string, content: string) + + function {:extern "DafnyLibraries.FileIO", "INTERNAL_ReadBytesFromFile"} + INTERNAL_ReadBytesFromFile(path: string): (bytes: string) +} + +module {:extern} ExternButEverythingImplemented { + function test(): int { 1 } +} + +module {:extern "ExternWithOnlyAStaticMethodUninmplemented"} ExternWithOnlyAStaticMethodUninmplemented { + method {:extern} DoThis(i: int) returns (res: int) +} + +module {:extern "ExternModuleWithOneClassToImport"} ExternModuleWithOneClassToImport { + trait {:termination false} TraitDefinedInModule { + function Get(): string + reads this + + method Put(s: string) + modifies this + ensures this.Get() == s + } + + class {:extern} NonShareableBox extends TraitDefinedInModule { + constructor {:extern} {:axiom} () + ensures this.Get() == "" + + function {:extern} Get(): string + reads this + + method {:extern} {:axiom} Put(s: string) + modifies this + ensures this.Get() == s + + function GetOpt(): (o: string) + reads this + { + if Get() == "" then "None" else "Some("+Get()+")" + } + } +} + + +method Main() { + var i := ExternalClassContainer.Test(); + expect i == 2; + var j := new ExternalClassContainer.ExternalClass(i); + var message := Dafny.FileIO.ReadBytesFromFile("hello.dfy"); + var c := new ExternalClassContainer.ExternalPartialClass(); + c.Print(); + var c2 := new ExternalClassContainer.ExternalPartialClass2(); + c2.Print(); + expect ExternButEverythingImplemented.test() == 1; + var x := ExternWithOnlyAStaticMethodUninmplemented.DoThis(1); + expect x == 2; + var n: ExternModuleWithOneClassToImport.NonShareableBox := new ExternModuleWithOneClassToImport.NonShareableBox(); + expect n as object as ExternModuleWithOneClassToImport.NonShareableBox == n; + expect n.Get() == ""; + expect n.GetOpt() == "None"; + n.Put("x"); + expect n.Get() == "x"; + expect n.GetOpt() == "Some(x)"; + print message; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect new file mode 100644 index 00000000000..86c68713487 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 7 verified, 0 errors +22Everything is ok. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs new file mode 100644 index 00000000000..5ebbf6a48b2 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs @@ -0,0 +1,107 @@ +#![allow(warnings, unconditional_panic)] +#![allow(nonstandard_style)] + +pub mod External { + pub mod Class { + pub mod Container { + use crate::*; + + pub struct ExternalClass {} + impl ExternalClass { + pub fn _allocate_object(_cmc: ::dafny_runtime::DafnyInt) -> ::dafny_runtime::Object { + // SAFETY: The Rc has not been shared before + unsafe { + ::dafny_runtime::Object::from_rc(::std::rc::Rc::new(ExternalClass {})) + } + } + } + + pub struct ExternalPartialClass {} + impl ExternalPartialClass { + pub fn _allocate_object() -> ::dafny_runtime::Object { + // SAFETY: The Rc has not been shared before + unsafe { + ::dafny_runtime::Object::from_rc(::std::rc::Rc::new(ExternalPartialClass {})) + } + } + } + + impl crate::External::Class::Container::GetValueHolder + for ExternalPartialClass { + fn GetValue(&mut self) -> dafny_runtime::DafnyInt { + ::dafny_runtime::int!(2) + } + } + + impl ::dafny_runtime::UpcastObject + for ExternalPartialClass { + ::dafny_runtime::UpcastObjectFn!(dyn crate::External::Class::Container::GetValueHolder); + } + + pub struct ExternalPartialClass2 {} + impl ExternalPartialClass2 { + pub fn _allocate_object() -> ::dafny_runtime::Object { + // SAFETY: The Rc has not been shared before + unsafe { + ::dafny_runtime::Object::from_rc(::std::rc::Rc::new(ExternalPartialClass2 {})) + } + } + } + pub struct _default {} + + impl _default { + pub fn Test() -> ::dafny_runtime::DafnyInt { + ::dafny_runtime::int!(2) + } + } + } + } +} + +pub mod ExternWithOnlyAStaticMethodUninmplemented { + pub struct _default {} + + impl _default { + pub fn DoThis(i: &::dafny_runtime::DafnyInt) -> ::dafny_runtime::DafnyInt { + i.clone() + ::dafny_runtime::int!(1) + } + } +} + +pub mod DafnyLibraries { + pub mod FileIO { + pub fn INTERNAL_ReadBytesFromFile(path: &::dafny_runtime::DafnyString) + -> ::dafny_runtime::DafnyString { + return ::dafny_runtime::string_of("Everything is ok."); + } + + pub fn INTERNAL_WriteBytesToFile(path: &::dafny_runtime::DafnyString, content: &::dafny_runtime::DafnyString) { + // Nothing to do, we mock writing to a file + } + } +} + +pub mod ExternModuleWithOneClassToImport { + pub struct NonShareableBox { + s: ::dafny_runtime::DafnyString + } + impl NonShareableBox { + pub fn _allocate_object() -> ::dafny_runtime::Object { + // SAFETY: The Rc has not been shared before + unsafe { + ::dafny_runtime::Object::from_rc(::std::rc::Rc::new(NonShareableBox { + s: ::dafny_runtime::string_of("") + })) + } + } + } + impl crate::ExternModuleWithOneClassToImport::TraitDefinedInModule + for NonShareableBox { + fn Get(&mut self) -> ::dafny_runtime::DafnyString { + self.s.clone() + } + fn Put(&mut self, c: &::dafny_runtime::DafnyString) { + self.s = c.clone(); + } + } +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy new file mode 100644 index 00000000000..48c223f62e6 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy @@ -0,0 +1,23 @@ +// RUN: %testDafnyForEachCompiler --refresh-exit-code=0 "%s" + +newtype uint8 = x: int | 0 <= x < 256 + +predicate F(f: bool -> bool) { f(false) } + +predicate p(b: bool) { !b } + +predicate Fn(f: (T, T) -> bool, a: T) { f(a, a) } + +predicate X() { F(p) } + +predicate X'() { var f := x => !x; F(f) } + +predicate F'(f: seq -> bool) { f([false]) } + +predicate p'(b: seq) { if |b| > 0 then !b[0] else false } + +predicate X''() { F'(p') } + +method Main() { + print Fn((a: uint8, b: uint8) => a == b, 2 as uint8), "\n"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect new file mode 100644 index 00000000000..27ba77ddaf6 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect @@ -0,0 +1 @@ +true diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy index c73e52965c7..6b137d39e1c 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy @@ -1,5 +1,5 @@ -// NONUNIFORM: Temporary development of the Rust compiler -// RUN: %baredafny run --target=rs --emit-uncompilable-code "%s" > "%t" +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype u8 = x: int | 0 <= x < 10 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy new file mode 100644 index 00000000000..c8fa58fd67f --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy @@ -0,0 +1,60 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --unicode-char=false "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +function Map(m: map): map { + m +} + +datatype Test_ = Test(i: int) { + ghost const Valid?: bool := 0 <= i < 4 + + predicate Char?(c: char) + requires Valid? + requires c as int < 256 + { + c < 3 as char + } +} + +datatype NeedsTypeParameter_ = NeedsTypeParameter(t: T -> bool) + +type NeedsTypeParameter = x: NeedsTypeParameter_ | true witness NeedsTypeParameter((t: T) => false) + +type Test = t: Test_ | t.Valid? witness Test(0) + +newtype UInt16 = x: int | 0 <= x < 65536 + +newtype Int16 = x: int | -32768 <= x < 32768 + +type CodeUnit = bv16 + +method CharToString(c: char, s: map) returns (r: string) { + if c in s { + return "inside:" + s[c]; + } + return "not inside"; +} + +function LastCharToNat(str: string, digits: map) : (n: nat) + requires forall c | c in str :: c in digits +{ + if str == [] then 0 + else + digits[str[|str| - 1]] +} + +method Main() { + var m := map[1 := 2]; + var s: set> := {{}}; + expect |s| == 1; + var z := (c => c as CodeUnit)('a'); + var t: Test := Test(2); + var x := CharToString('a', map['a' := "hello"]); + expect x == "inside:hello"; + var y := CharToString('z', map['a' := "hello"]); + expect y == "not inside"; + if t.Char?(2 as char) { + print "Everything is ok."; + } +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy.expect new file mode 100644 index 00000000000..e13d6aad42b --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 8 verified, 0 errors +Everything is ok. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy index aa3d2180f8f..816c9ca9f03 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy @@ -1,4 +1,4 @@ -// NONUNIFORM: Temporary development of the Rust compiler +// NONUNIFORM: Rust-specific tests // RUN: %baredafny run --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.check new file mode 100644 index 00000000000..77dcfa19320 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.check @@ -0,0 +1 @@ +// CHECK: .*pub mod B \{.* diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy new file mode 100644 index 00000000000..c8284779462 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy @@ -0,0 +1,36 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" +// Checks that, despite module B being prefixed with A, there will be a "mod B" somewhere +// and not an encoding like "mod A_B". +// This module will automatically be in mod A and referred to as "A::B" +// RUN: %OutputCheck --file-to-check "%S/nestedmodules-rust/src/nestedmodules.rs" "%S/nestedmodules.check" + +module A.B { + import opened C + method Test() { + print "A.B.Test-"; + Bar(); + } +} + +module A { + import opened B + module B.C { + method Bar() { + print "A.B.C.Bar-"; + } + } + + method Foo() { + print "A.Foo-"; + Test(); + B.C.Bar(); + } +} + +method Main() { + print "main-"; + A.Foo(); + print "end"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy.expect new file mode 100644 index 00000000000..e4a65f263e4 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 3 verified, 0 errors +main-A.Foo-A.B.Test-A.B.C.Bar-A.B.C.Bar-end \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy new file mode 100644 index 00000000000..fe08c8d50e0 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy @@ -0,0 +1,16 @@ +// NONUNIFORM: Testing explicit newtype conversion of bounded ranges in Rust backend +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +newtype uint8 = x: int | 0 <= x < 0x100 +newtype uint16 = x: int | 0 <= x < 0x10000 + +function UInt16ToSeq(x: uint16): seq { + var b0 := (x / 0x100) as uint8; + var b1 := (x % 0x100) as uint8; + [b0, b1] +} + +method Main() { + var a := set x: uint16 | 0 <= x < 0xFFFF :: UInt16ToSeq(x); +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy.expect new file mode 100644 index 00000000000..ba00363fc08 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy.expect @@ -0,0 +1,2 @@ + +Dafny program verifier finished with 4 verified, 0 errors diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy index a4605a78142..663b59551c4 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy @@ -1,4 +1,4 @@ -// NONUNIFORM: Temporary development of the Rust compiler +// NONUNIFORM: Rust-specific tests // RUN: %baredafny run --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" ghost const TWO_TO_THE_8: int := 0x100 @@ -249,7 +249,8 @@ method {:resource_limit "1e6"} Main() { expect m3.Keys == {2, 3}; expect m3.Values == {4, 6}; - print ".Keys and .Values\n"; + expect m3.Items == {(2, 4), (3, 6)}; + print ".Keys .Values .Items\n"; var st := {1}; expect 1 in st; diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy.expect index 3c24ec5673b..8923b8864bd 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy.expect @@ -5,7 +5,7 @@ Dafny program verifier finished with 21 verified, 0 errors operators(u8) operators(u16) operators(u32) operators(u64) operators(u128) operators(i8) operators(i16) operators(i32) operators(i64) operators(i128) char comparison -map contains acccess update union diff comprehension equality cardinality .Keys and .Values +map contains acccess update union diff comprehension equality cardinality .Keys .Values .Items set contains union diff comprehension equality cardinality inequality and intersection sequence prefix sequence update cardinality sequence slice multiset comparison union equality access and cardinality diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy index 8331e14b3d6..e90b5bc69af 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy @@ -5,6 +5,7 @@ datatype X = | X(fn: int, self: int, Self: int) | None(None: int) +| H(hash: int) method Main() { @@ -12,4 +13,8 @@ method Main() var self := 0; var Self := 0; expect None(3).None == 3; + var None := 0; + expect None == 0; + var hash := H(3).hash; + expect hash == 3; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.check new file mode 100644 index 00000000000..48ed719da2d --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.check @@ -0,0 +1,4 @@ +// CHECK: .*AcceptSubsetAndType\(x, y\).* +// CHECK: .*AcceptSubsetAndType2\(x, y\).* +// CHECK: .*AcceptSubsetAndType\(x, y1\).* +// CHECK: .*AcceptSubsetAndType2\(x, y1\).* diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy new file mode 100644 index 00000000000..cad15372a6b --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy @@ -0,0 +1,48 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" +// RUN: %OutputCheck --file-to-check "%S/subsetconstraints-rust/src/subsetconstraints.rs" "%S/subsetconstraints.check" + +newtype uint8 = x: int | 0 <= x < 256 + +type ValidSeqUint8 = i: seq | SubtypePredicate(i) witness [] +predicate SubtypePredicate(i: seq) { true } +type SeqUint8 = ValidSeqUint8 +type SeqSeqUInt8 = seq +type MoreThanOne = x: uint8 | x > 1 witness 2 +type DummyType = x: T | true witness * + +predicate Test(contextKeys: SeqSeqUInt8, result: SeqSeqUInt8) { + forall k <- contextKeys :: k in result +} + +method AcceptSubsetAndType(x: MoreThanOne, y: uint8) { + AcceptType(x); +} +method AcceptType(y: uint8) { +} + +method AcceptSubsetAndType2(x: DummyType, y: uint8) { + AcceptType(x); +} +class TestOwnershipConstructor { + constructor(a: SeqSeqUInt8, b: seq>, c: MoreThanOne, d: MoreThanOne) { + } +} +method Main() { + var s := [[1 as uint8]]; + var sSub: SeqSeqUInt8 := s; + expect Test(s, [[1 as uint8], [2 as uint8]]); + expect !Test([[1 as uint8], [3 as uint8]], [[1 as uint8], [2 as uint8]]); + var col := [-1, 1, 2]; + expect forall n: nat <- col :: n > 0; + var x := 2 as uint8; + var y: MoreThanOne := 2; + var y1: DummyType := y; + AcceptSubsetAndType(x, y); // Note that subset types are reversed + AcceptSubsetAndType2(x, y); // Note that subset types are reversed + AcceptSubsetAndType(x, y1); // Note that subset types are reversed + AcceptSubsetAndType2(x, y1); // Note that subset types are reversed + var z := new TestOwnershipConstructor(s, sSub, x, y); + print "Everything is ok."; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy.expect new file mode 100644 index 00000000000..753ce264737 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 6 verified, 0 errors +Everything is ok. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy index 6448866217c..952050e36b2 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy @@ -1,4 +1,4 @@ -// NONUNIFORM: Temporary development of the Rust compiler +// NONUNIFORM: Rust-specific tests // RUN: %baredafny run --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy new file mode 100644 index 00000000000..75ee7a0c39c --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy @@ -0,0 +1,15 @@ +// NONUNIFORM: Tests that type tests work in the Rust backend +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" +// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait T { } +class A extends T { constructor() {} } +class B extends T { } + +method Main() { + var v: T := new A(); + expect !(v is B), "v shouldn't be B"; + expect v is A, "v should be A"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy.expect new file mode 100644 index 00000000000..823a60a105c --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy.expect @@ -0,0 +1,2 @@ + +Dafny program verifier finished with 1 verified, 0 errors diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy new file mode 100644 index 00000000000..5be7c59ea24 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy @@ -0,0 +1,21 @@ +// NONUNIFORM: Testing robustness of Dafny/Rust backends wrt set comprehension +// RUN: %baredafny -noVerify -compileTarget:rs -compile:0 -functionSyntax:3 -spillTargetCode:3 "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +module Spoo { + + newtype uint8 = x: int | 0 <= x < 0x100 + newtype uint16 = x: int | 0 <= x < 0x10000 + function method UInt16ToSeq(x: uint16): (ret: seq) + ensures |ret| == 2 + ensures 0x100 * ret[0] as uint16 + ret[1] as uint16 == x + { + var b0 := (x / 0x100) as uint8; + var b1 := (x % 0x100) as uint8; + [b0, b1] + } + + method {:test} TestSetToOrderedSequenceManyItems() { + var a := set x:uint16 | 0 <= x < 0xFFFF :: UInt16ToSeq(x); + } +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect new file mode 100644 index 00000000000..39be9965f21 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect @@ -0,0 +1,5 @@ +Warning: this way of using the CLI is deprecated. Use 'dafny --help' to see help for the new Dafny CLI format + +Dafny program verifier did not attempt verification +Wrote textual form of target program to git-issue-5644-rust/src/git_issue_5644.rs +Additional output written to git-issue-5644-rust/src/git-issue-5644-rs.dtr diff --git a/docs/DafnyRef/integration- rust/IntegrationRust.md b/docs/DafnyRef/integration- rust/IntegrationRust.md index f86d124506d..ab78e8b09e9 100644 --- a/docs/DafnyRef/integration- rust/IntegrationRust.md +++ b/docs/DafnyRef/integration- rust/IntegrationRust.md @@ -29,7 +29,7 @@ It's worth recalling that Rust has two semantics for variables: * *Copy semantics* are the one everyone used to `C#`, `Java`, `JavaScript`, `Go` understand. At run-time, it means the actual bits of memory are copied from one location to the other. -Primitive types like `bool`, `u8`, `i8`, `u16`... but also any references `& T`, `&mut T`, `*const T` or `*mut T` have copy semantics. +Primitive types like `bool`, `u8`, `i8`, `u16`... but also any references `& T`, `&mut T`, `*const T`, `*mut T` or structs of these types have copy semantics. * *Move semantics* or *owned semantics* indicate that once a variable or a field is used without borrowing, it can no longer be used afterwards. These are the semantics that allow Rust to forget the garbage collector, by cleaning up resources Rust can statically determine they are not longer used. Move semantics are the default for any type that does not implement the `Copy` trait. @@ -41,72 +41,139 @@ Hence, whenever a variable with move semantics (borrowed or owned) is used in a For maximum flexibility, Dafny follows these rules to encode types in Rust: - Function parameters always take primitive types without borrowing them (`bool`, `u32`, etc.) -- Function parameters always borrows variables of other types (`DafnyString`, structs, etc.), because +- Function parameters always borrow variables of other types (`DafnyString`, structs, etc.), because borrowing is always cheaper than cloning for non-Copy types. Open question: There are at least two more possible alternatives - We could actually have parameters be always owned, which require `.clone()` also to be used at the call site - We could have parameter attributes like `{:rc_owned true}` so that users can choose which API to precisely give to their functions. -- Functions always return an owned type, otherwise we would need to have an automated theory about lifetimes of returned borrowed references, which Dafny does not support. Moreover, borrowing a variable makes its lifetime not `'static`, so it's not possible to use that trait. +- Functions always return an owned type, otherwise we would need to have an automated theory about lifetimes of returned borrowed references, which Dafny does not support yet. Moreover, borrowing a variable makes its lifetime not `'static`, so it's not possible to use that trait. - `& T` and `&mut T` annotations only appear at the top-level of types, never nested. -- Classes types are encoded in raw pointers, and a deallocation statement will be made available. - -|-------------------------------|-----------------------------| -| Dafny type | Rust type | -|-------------------------------|-----------------------------| -| `bool` | `bool` | -| `int` | `DafnyInt` (wrapper around `Rc`) | -| `int64` | `i64` | -| `int32` | `i32` | -| `int16` | `i16` | -| `int8` | `i8` | -| `char` | `char` OR `u16` | -| `bitvector` | appropriate `u8` ... `u128` type | -| `ORDINAL` | `DafnyInt` - TODO | -| `real` | `num::BigRational` (will move to DafnyRational) | -| | `f64` | -| `string` | `Sequence` | -| | or `Sequence` | -| datatype, codatatype `D` | `Rc` | -| | or `D` with the option `{:rust_rc false}` | -| subset type | same as base type | -| `newtype T = u: U` | `struct T(U)` | -| | or optimized to `u8`..`i128`| -| `(T1, T2...)` | `(T1, T2...)` | -| `seq` | `Sequence` (*)| -| `set`, `iset` | `Set` (*) | -| `multiset` | `MultiSet` (*) | -| `map`, `imap` | `Map` (*) | -| function (arrow) types | `Rc ...>` | - -## With the option --raw-pointers=false (default) -This version compiles classes to reference counting. -However, it requires the nightly version to compile until the following feature -is declared stable: -- [trait Unsize](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) - -To install and use the nightly, use +- Class types are encoded in reference-counted pointers by default, but there is a command-line flag `--raw-pointers` that encodes class type into an equivalent of a raw pointer. The Dafny team will have to make a deallocation statement available in the future, as it is not available yet. Please weight in on [this issue](https://github.com/dafny-lang/dafny/issues/5257) if you are interested. + +For each construct, the third column indicates if it's in the Dafny runtime, is native built-in in Rust, or is a Rust crate. +If runtime, it also indicates in parentheses what it is roughly equivalent to. `[[U]]` notation indicates the Rust equivalent of the Dafny type `U`. +The exact runtime types are subject to change, and code that is not Dafny-generated should not rely on those details. + +For guaranteed stability, code interfacting with Dafny structures should use types and conversions from `pub mod dafny_runtime_conversions`, such as `::dafny_runtime::dafny_runtime_conversions::DafnySequence` and `::dafny_runtime::dafny_runtime_conversions::vec_to_dafny_sequence(array: &Vec, elem_converter: fn(&X) -> T) -> DafnySequence` for example. + +| Dafny type | Rust type | Defined in | +|-------------------------------|-----------------------------|------------------| +| `bool` | `bool` | Native | +| `int` | `DafnyInt` | Runtime (`Rc`) | +| `int64` | `i64` | Native | +| `int32` | `i32` | Native | +| `int16` | `i16` | Native | +| `int8` | `i8` | Native | +| `char` | `DafnyChar` | Runtime (`char`) | +| `char` (`--unicode-chars=false`)| `DafnyCharUTF16` | Runtime (`u16`) | +| `bv8` ... `bv128` | `u8` ... `u128` | Native | +| `type T = u: U | ` | `[[U]]` | Native | +| `newtype T = u: U | range` | `struct T([[U]])` | Native | +| `newtype T = u: int | `| `u8` ... `i128` | Native | +| `ORDINAL` | N/A | TODO | +| `real` | Partially supported | TODO | +| `seq` | `Sequence<[[T]]> `| Runtime | +| `set`, `iset` | `Set<[[T]]>` | Runtime | +| `multiset` | `Multiset<[[T]]>` | Runtime | +| `map`, `imap` | `Map<[[T]]>` | Runtime | +| `string` | `DafnyString` | Runtime (`Sequence`) | +| `string` (`--unicode-chars=false`)| `DafnyStringUTF16` | Runtime (`Sequence`) | +| (co)datatype `D` | `std::rc::Rc` | Native wrapped struct | +| (co)datatype `D` with attribute `{:rust_rc false}` | `D` | Native struct | +| `(T1, T2...)` (Up to size 12)| `(T1, T2...)` | Native | +| `(T1, T2..., TN)` (13<=N<=20) | `_System.TupleN` | Runtime because Rust limitations | +| `A -> B` | `Rc [[B]]>`| Native (note: arguments always borrowed) | + +## Encoding of classes and arrays (default) +By default, Dafny uses reference counting to compile class and array references. + +| Dafny type | Rust type | Defined in | +|-------------------------------|-------------------------|------------------| +| `C`, `C?` (for class, iterator C) | `Object` | Runtime (`Option>>`) | +| (trait) `T` | (trait) `Object` | Runtime (`Option>>`) | +| `array` | `Object<[T]>` | Runtime (`Option>>`) | +| `array2` | `Object>` | Runtime (`struct array2 {length0: usize, length1: usize, data: Box<[Box<[T]>]>}`) | +| `array3` ... `array16` | `Object>` ... `Object>` | Runtime (`struct arrayN {length0: usize, ... lengthN-1: usize, data: Box<[...Box<[T]>...]>}`) | +| `c.x` if `c: C` | `rd!(c).x` | Runtime | +| `c.x := 2` if `c: C` | `md!(c).x = 2` | Runtime | +| `a[0]` if `a: array` | `rd!(a)[0]` | Runtime | +| `a[1] := 2` if `a: array` | `md!(a)[1] = 2` | Runtime | + + +## Encoding of classes and arrays with the option --raw-pointers +The option `--raw-pointers` ensures that classes only have 8 bytes pointers, +and array only have 8 bytes pointers + information about the length, +and point to raw memory. Therefore, pointers have copy semantics and +no call to any clone method needs to be made. +However, since pointer comparison in Rust normally compares vtables, +which is brittle, Dafny use its own pointer types which are wrappers: +```rs +pub struct Ptr(pub Option>>); ``` -rustup default nightly-x86_64-pc-windows-gnu + +| Dafny type | Rust type | Defined in | +|-------------------------------|-------------------------|------------------| +| `C`, `C?` (for class, iterator C) | `Ptr` | Runtime (`Option>>`) | +| (trait) `T` | (trait) `Ptr` | Runtime (`Option>>`) | +| `array` | `Ptr<[T]>` | Runtime (`Option>>`) | +| `array2` | `Ptr>` | Runtime (`struct array2 {length0: usize, length1: usize, data: Box<[Box<[T]>]>}`) | +| `array3` ... `array16` | `Ptr>` ... `Ptr>` | Runtime (`struct arrayN {length0: usize, ... lengthN-1: usize, data: Box<[...Box<[T]>...]>}`) | +| `c.x` if `c: C` | `read!(c).x` | Runtime | +| `c.x := 2` if `c: C` | `modify!(c).x = 2` | Runtime | +| `a[0]` if `a: array` | `read!(a)[0]` | Runtime | +| `a[1] := 2` if `a: array` | `modify!(a)[1] = 2` | Runtime | + +# Externs + +You can provide additional `*.rs` files to `dafny translate`, `dafny build` and even `dafny run` (via the `--input` option) + +The best way to see what you have to implement as an extern Rust file is to compile your code with extern attributes and adding an external Rust file. For extra methods or static methods, you would then define an additional implementation in the extern Rust file. For other class or struct types, you just need to define them without any `mod` wrapper, or using the module structure as defined in the `{:extern}` attribute. + +When using simple 1-argument externs, the compilation follows Dafny conventions: static methods are static instance methods of a `pub struct _default {}` which is defined in the module itself, or must be defined externally if all static methods are labelled as externs. +When using 2-argument extern methods or functions, the compilation follows Rust convention: The first argument is a path of Rust module names separated by `::` (or `.` for cross-compilation with e.g. the Java compiler). The second argument is the name of a static `pub fn` of that module. + +Let's assume you provide an additional input file `external.rs` with the following content: +``` +pub mod rust { + pub mod module { + fn outsideMethod() + } +} +pub mod Test { + pub struct _default {} + impl _default { + pub fn extern_y() { + } + } +} ``` -(to go back to the stable version, use `rustup default stable-x86_64-pc-windows-gnu`) - -|-------------------------------|-----------------------------| -| Dafny type | Rust type | -|-------------------------------|-----------------------------| -| `C`, `C?` (for class, iterator C) | `object` | -| (trait) `T` | (trait) `object` | -| `array` | `object<[T]>` | -| `array2` | `object>` | - -## With the option --raw-pointers=true -https://doc.rust-lang.org/book/appendix-07-nightly-rust.html -|-------------------------------|-----------------------------| -| Dafny type | Rust type | -|-------------------------------|-----------------------------| -| `C`, `C?` (for class, iterator C) | `*mut C` | -| (trait) `T` | (trait) `*mut dyn T` | -| `array` | `*mut [T]` | -| `array2` | `*mut array2` | - -(*) Defined in the Dafny runtime +Assuming that your Dafny program looks like: +``` + +module Test { + method {:extern "rust.module", "externalMethod"} outsideMethod() + method {:extern "extern_y"} dafny_y(); +} +method Main() { + Test.outsideMethod(); + Test.dafny_y(); +} +``` + +As of today, Dafny will generate the following for you (internal names not guaranteed): + +``` +pub mod external; // from the additional external.rs input file + +pub mod _dafny_externs { // from the additional external.rs input file + import opened external::*; +} +pub mod Test { + pub use super::_dafny_externs::Test::*; // Imports the _default +} +fn main() { + crate::rust::module::externalMethod(); + super::Test::_default::extern_y(); +} +```