diff --git a/Makefile b/Makefile index 632864291..d6d9295fa 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ default: exe all: exe refman exe: - (cd ${DIR} ; dotnet build Source/Dafny.sln ) ## includes parser + (cd "${DIR}" ; dotnet build Source/Dafny.sln ) ## includes parser format-dfy: (cd "${DIR}"/Source/DafnyCore ; ../../Binaries/Dafny.exe format .) @@ -14,7 +14,7 @@ dfy-to-cs: (cd "${DIR}"/Source/DafnyCore ; bash DafnyGeneratedFromDafny.sh) dfy-to-cs-exe: dfy-to-cs - (cd ${DIR} ; dotnet build Source/Dafny.sln ) + (cd "${DIR}" ; dotnet build Source/Dafny.sln ) dfy-to-cs-noverify: (cd "${DIR}"/Source/DafnyCore ; bash DafnyGeneratedFromDafny.sh --no-verify) @@ -24,74 +24,74 @@ dfy-to-cs-noverify-exe: dfy-to-cs-noverify exe boogie: ${DIR}/boogie/Binaries/Boogie.exe tests: - (cd ${DIR}; dotnet test Source/IntegrationTests) + (cd "${DIR}"; dotnet test Source/IntegrationTests) tests-verbose: - (cd ${DIR}; dotnet test --logger "console;verbosity=normal" Source/IntegrationTests ) + (cd "${DIR}"; dotnet test --logger "console;verbosity=normal" Source/IntegrationTests ) ${DIR}/boogie/Binaries/Boogie.exe: - (cd ${DIR}/boogie ; dotnet build -c Release Source/Boogie.sln ) + (cd "${DIR}"/boogie ; dotnet build -c Release Source/Boogie.sln ) refman: exe - make -C ${DIR}/docs/DafnyRef + make -C "${DIR}"/docs/DafnyRef refman-release: exe - make -C ${DIR}/docs/DafnyRef release + make -C "${DIR}"/docs/DafnyRef release z3-mac: - mkdir -p ${DIR}/Binaries/z3/bin + mkdir -p "${DIR}"/Binaries/z3/bin wget https://github.com/dafny-lang/solver-builds/releases/download/snapshot-2023-08-02/z3-4.12.1-x64-macos-11-bin.zip unzip z3-4.12.1-x64-macos-11-bin.zip rm z3-4.12.1-x64-macos-11-bin.zip wget https://github.com/dafny-lang/solver-builds/releases/download/snapshot-2023-08-02/z3-4.8.5-x64-macos-11-bin.zip unzip z3-4.8.5-x64-macos-11-bin.zip rm z3-4.8.5-x64-macos-11-bin.zip - mv z3-* ${DIR}/Binaries/z3/bin/ - chmod +x ${DIR}/Binaries/z3/bin/z3-* + mv z3-* "${DIR}"/Binaries/z3/bin/ + chmod +x "${DIR}"/Binaries/z3/bin/z3-* z3-mac-arm: - mkdir -p ${DIR}/Binaries/z3/bin + mkdir -p "${DIR}"/Binaries/z3/bin wget https://github.com/dafny-lang/solver-builds/releases/download/snapshot-2023-08-02/z3-4.12.1-arm64-macos-11-bin.zip unzip z3-4.12.1-arm64-macos-11-bin.zip rm z3-4.12.1-arm64-macos-11-bin.zip wget https://github.com/dafny-lang/solver-builds/releases/download/snapshot-2023-08-02/z3-4.8.5-x64-macos-11-bin.zip unzip z3-4.8.5-x64-macos-11-bin.zip rm z3-4.8.5-x64-macos-11-bin.zip - mv z3-* ${DIR}/Binaries/z3/bin/ - chmod +x ${DIR}/Binaries/z3/bin/z3-* + mv z3-* "${DIR}"/Binaries/z3/bin/ + chmod +x "${DIR}"/Binaries/z3/bin/z3-* z3-ubuntu: - mkdir -p ${DIR}/Binaries/z3/bin + mkdir -p "${DIR}"/Binaries/z3/bin wget https://github.com/dafny-lang/solver-builds/releases/download/snapshot-2023-08-02/z3-4.12.1-x64-ubuntu-20.04-bin.zip unzip z3-4.12.1-x64-ubuntu-20.04-bin.zip rm z3-4.12.1-x64-ubuntu-20.04-bin.zip wget https://github.com/dafny-lang/solver-builds/releases/download/snapshot-2023-08-02/z3-4.8.5-x64-ubuntu-20.04-bin.zip unzip z3-4.8.5-x64-ubuntu-20.04-bin.zip rm z3-4.8.5-x64-ubuntu-20.04-bin.zip - mv z3-* ${DIR}/Binaries/z3/bin/ - chmod +x ${DIR}/Binaries/z3/bin/z3-* + mv z3-* "${DIR}"/Binaries/z3/bin/ + chmod +x "${DIR}"/Binaries/z3/bin/z3-* format: dotnet format whitespace Source/Dafny.sln --exclude Source/DafnyCore/Scanner.cs --exclude Source/DafnyCore/Parser.cs --exclude boogie --exclude Source/DafnyCore/GeneratedFromDafny/* --exclude Source/DafnyCore.Test/GeneratedFromDafny/* --exclude Source/DafnyRuntime/DafnyRuntimeSystemModule.cs clean: - (cd ${DIR}; cd Source; rm -rf Dafny/bin Dafny/obj DafnyDriver/bin DafnyDriver/obj DafnyRuntime/obj DafnyRuntime/bin DafnyServer/bin DafnyServer/obj DafnyPipeline/obj DafnyPipeline/bin DafnyCore/obj DafnyCore/bin) - (cd ${DIR} ; dotnet build Source/Dafny.sln -v:q --nologo -target:clean ) - make -C ${DIR}/Source/DafnyCore -f Makefile clean - (cd ${DIR}/Source/Dafny && rm -rf Scanner.cs Parser.cs obj ) - (cd ${DIR}/Source/DafnyRuntime/DafnyRuntimeJava; ./gradlew clean) - make -C ${DIR}/docs/DafnyRef clean - (cd ${DIR}; cd Source; rm -rf Dafny/bin Dafny/obj DafnyDriver/bin DafnyDriver/obj DafnyRuntime/obj DafnyRuntime/bin DafnyServer/bin DafnyServer/obj DafnyPipeline/obj DafnyPipeline/bin DafnyCore/obj DafnyCore/bin) + (cd "${DIR}"; cd Source; rm -rf Dafny/bin Dafny/obj DafnyDriver/bin DafnyDriver/obj DafnyRuntime/obj DafnyRuntime/bin DafnyServer/bin DafnyServer/obj DafnyPipeline/obj DafnyPipeline/bin DafnyCore/obj DafnyCore/bin) + (cd "${DIR}" ; dotnet build Source/Dafny.sln -v:q --nologo -target:clean ) + make -C "${DIR}"/Source/DafnyCore -f Makefile clean + (cd "${DIR}"/Source/Dafny && rm -rf Scanner.cs Parser.cs obj ) + (cd "${DIR}"/Source/DafnyRuntime/DafnyRuntimeJava; ./gradlew clean) + make -C "${DIR}"/docs/DafnyRef clean + (cd "${DIR}"; cd Source; rm -rf Dafny/bin Dafny/obj DafnyDriver/bin DafnyDriver/obj DafnyRuntime/obj DafnyRuntime/bin DafnyServer/bin DafnyServer/obj DafnyPipeline/obj DafnyPipeline/bin DafnyCore/obj DafnyCore/bin) echo Source/*/bin Source/*/obj update-cs-module: - (cd ${DIR}; cd Source/DafnyRuntime; make update-system-module) + (cd "${DIR}"; cd Source/DafnyRuntime; make update-system-module) update-go-module: - (cd ${DIR}; cd Source/DafnyRuntime/DafnyRuntimeGo; make update-system-module) + (cd "${DIR}"; cd Source/DafnyRuntime/DafnyRuntimeGo; make update-system-module) update-runtime-dafny: - (cd ${DIR}; cd Source/DafnyRuntime/DafnyRuntimeDafny; make update-go) + (cd "${DIR}"; cd Source/DafnyRuntime/DafnyRuntimeDafny; make update-go) # `make pr` will bring you in a state suitable for submitting a PR # - Builds the Dafny executable diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs b/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs index 000fa0243..0354b407e 100644 --- a/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs +++ b/Source/DafnyCore.Test/GeneratedFromDafny/DafnyToRustCompilerCoverage_RASTCoverage.cs @@ -15,127 +15,129 @@ public partial class __default { 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))); + } + 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")))); + } public static void TestOptimizeToString() { - RAST._IExpr _962_x; - _962_x = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")); - RAST._IExpr _963_y; - _963_y = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), RAST.Expr.create_Call(RAST.Expr.create_Select(_962_x, Dafny.Sequence.UnicodeFromString("clone")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()), DAST.Format.UnaryOpFormat.create_NoFormat())).Optimize(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _962_x, DAST.Format.UnaryOpFormat.create_NoFormat()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), RAST.Expr.create_Call(RAST.Expr.create_Select(_962_x, Dafny.Sequence.UnicodeFromString("clone")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(_963_y)), DAST.Format.UnaryOpFormat.create_NoFormat())); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _962_x, _963_y, DAST.Format.BinaryOpFormat.create_NoFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())).Optimize(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _962_x, _963_y, DAST.Format.BinaryOpFormat.create_NoFormat()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _962_x, _963_y, DAST.Format.BinaryOpFormat.create_NoFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())).Optimize(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _962_x, _963_y, DAST.Format.BinaryOpFormat.create_NoFormat()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _962_x, _963_y, DAST.Format.BinaryOpFormat.create_ReverseFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())).Optimize(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _963_y, _962_x, DAST.Format.BinaryOpFormat.create_NoFormat()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_ConversionNum(RAST.Type.create_I128(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("DafnyInt")), Dafny.Sequence.UnicodeFromString("from")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")))))).Optimize(), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("/*optimized*/1")))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_ConversionNum(RAST.Type.create_I128(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("DafnyInt")), Dafny.Sequence.UnicodeFromString("from")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("1"), false))))).Optimize(), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("/*optimized*/1")))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize((RAST.Expr.create_ConversionNum(RAST.Type.create_I128(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("DafnyInt")), Dafny.Sequence.UnicodeFromString("from")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(_962_x)))).Optimize()); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize((RAST.Expr.create_ConversionNum(RAST.Type.create_I128(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("DafnyInt")), Dafny.Sequence.UnicodeFromString("from")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("2")))))).Optimize()); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_ConversionNum(RAST.Type.create_I128(), _962_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.Expr.create_AssignVar(Dafny.Sequence.UnicodeFromString("z"), _963_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(_963_y)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.Expr.create_AssignVar(Dafny.Sequence.UnicodeFromString("w"), _963_y), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(_962_x); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(_962_x, _962_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_Match(_962_x, Dafny.Sequence.FromElements()), _962_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_StructBuild(Dafny.Sequence.UnicodeFromString("x"), Dafny.Sequence.FromElements()), _962_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements()), _962_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _962_x, DAST.Format.UnaryOpFormat.create_NoFormat()), _962_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), _962_x, _962_x, DAST.Format.BinaryOpFormat.create_NoFormat()), _962_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_TypeAscription(_962_x, RAST.Type.create_I128()), _962_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")), _962_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("1"), true), _962_x)); - DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_ConversionNum(RAST.Type.create_I128(), _962_x), _962_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.Expr.create_AssignVar(Dafny.Sequence.UnicodeFromString("z"), _963_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(_963_y)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); - Dafny.ISequence _964_coverageExpression; - _964_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(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(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), RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("abc"), false), RAST.Expr.create_ConversionNum(RAST.Type.create_I128(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), RAST.Expr.create_ConversionNum(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("X")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))), 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.Expr.create_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(), Dafny.Sequence.FromElements()), RAST.Expr.create_Call(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), Dafny.Sequence.FromElements(RAST.Type.create_I128(), RAST.Type.create_I32()), Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")))), 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"))); - BigInteger _hi4 = new BigInteger((_964_coverageExpression).Count); - for (BigInteger _965_i = BigInteger.Zero; _965_i < _hi4; _965_i++) { - RAST._IExpr _966_c; - _966_c = (_964_coverageExpression).Select(_965_i); - RAST._IPrintingInfo _967___v0; - _967___v0 = (_966_c).printingInfo; - RAST._IExpr _968___v1; - _968___v1 = (_966_c).Optimize(); - Dafny.IMap> _969___v2; - _969___v2 = Dafny.Map>.FromElements(new Dafny.Pair>(_966_c, (_966_c)._ToString(Dafny.Sequence.UnicodeFromString("")))); - RAST._IExpr _970___v3; - _970___v3 = (RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), _966_c)).Optimize(); - RAST._IExpr _971___v4; - _971___v4 = (RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.Expr.create_AssignVar(Dafny.Sequence.UnicodeFromString("abc"), _966_c), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString(""))))).Optimize(); - RAST._IExpr _972___v5; - _972___v5 = (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _966_c, DAST.Format.UnaryOpFormat.create_NoFormat())).Optimize(); - RAST._IExpr _973___v6; - _973___v6 = (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _966_c, DAST.Format.UnaryOpFormat.create_NoFormat())).Optimize(); - RAST._IExpr _974___v7; - _974___v7 = (RAST.Expr.create_ConversionNum(RAST.Type.create_U8(), _966_c)).Optimize(); - RAST._IExpr _975___v8; - _975___v8 = (RAST.Expr.create_ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(_966_c, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()))).Optimize(); - RAST._IExpr _976___v9; - _976___v9 = (RAST.Expr.create_ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(_966_c, Dafny.Sequence.UnicodeFromString("from")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()))).Optimize(); - RAST._IExpr _977___v10; - _977___v10 = (RAST.Expr.create_ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(_966_c, Dafny.Sequence.UnicodeFromString("DafnyInt")), Dafny.Sequence.UnicodeFromString("from")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()))).Optimize(); - RAST._IExpr _978___v11; - _978___v11 = (RAST.Expr.create_ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(_966_c, Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("DafnyInt")), Dafny.Sequence.UnicodeFromString("from")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()))).Optimize(); - RAST._IExpr _979___v12; - _979___v12 = (RAST.Expr.create_ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("DafnyInt")), Dafny.Sequence.UnicodeFromString("from")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(_966_c)))).Optimize(); - Std.Wrappers._IOption> _980___v13; - _980___v13 = (_966_c).RightMostIdentifier(); + RAST._IExpr _1016_x; + _1016_x = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")); + RAST._IExpr _1017_y; + _1017_y = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), RAST.Expr.create_Call(RAST.Expr.create_Select(_1016_x, Dafny.Sequence.UnicodeFromString("clone")), Dafny.Sequence.FromElements()), DAST.Format.UnaryOpFormat.create_NoFormat())).Optimize(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _1016_x, DAST.Format.UnaryOpFormat.create_NoFormat()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), RAST.Expr.create_Call(RAST.Expr.create_Select(_1016_x, Dafny.Sequence.UnicodeFromString("clone")), Dafny.Sequence.FromElements(_1017_y)), DAST.Format.UnaryOpFormat.create_NoFormat())); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _1016_x, _1017_y, DAST.Format.BinaryOpFormat.create_NoFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())).Optimize(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _1016_x, _1017_y, DAST.Format.BinaryOpFormat.create_NoFormat()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _1016_x, _1017_y, DAST.Format.BinaryOpFormat.create_NoFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())).Optimize(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _1016_x, _1017_y, DAST.Format.BinaryOpFormat.create_NoFormat()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _1016_x, _1017_y, DAST.Format.BinaryOpFormat.create_ReverseFormat()), DAST.Format.UnaryOpFormat.create_CombineFormat())).Optimize(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1017_y, _1016_x, DAST.Format.BinaryOpFormat.create_NoFormat()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_I128(), DafnyToRustCompilerCoverage.RASTCoverage.__default.DafnyIntLiteral(Dafny.Sequence.UnicodeFromString("1")))).Optimize(), RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_I128(), _1016_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"), _1017_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(_1017_y)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("z"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("w"), _1017_y), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(_1016_x); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(_1016_x, _1016_x)); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_Match(_1016_x, Dafny.Sequence.FromElements()), _1016_x)); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_StructBuild(_1016_x, Dafny.Sequence.FromElements()), _1016_x)); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements()), _1016_x)); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _1016_x, DAST.Format.UnaryOpFormat.create_NoFormat()), _1016_x)); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), _1016_x, _1016_x, DAST.Format.BinaryOpFormat.create_NoFormat()), _1016_x)); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_TypeAscription(_1016_x, RAST.Type.create_I128()), _1016_x)); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("1")), _1016_x)); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("2"), true, false), _1016_x)); + DafnyToRustCompilerCoverage.RASTCoverage.__default.TestNoOptimize(RAST.Expr.create_StmtExpr(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("3"), false, true), _1016_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"), _1017_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(_1017_y)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("return"))))); + Dafny.ISequence _1018_coverageExpression; + _1018_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"))); + BigInteger _hi4 = new BigInteger((_1018_coverageExpression).Count); + for (BigInteger _1019_i = BigInteger.Zero; _1019_i < _hi4; _1019_i++) { + RAST._IExpr _1020_c; + _1020_c = (_1018_coverageExpression).Select(_1019_i); + RAST._IPrintingInfo _1021___v0; + _1021___v0 = (_1020_c).printingInfo; + RAST._IExpr _1022___v1; + _1022___v1 = (_1020_c).Optimize(); + Dafny.IMap> _1023___v2; + _1023___v2 = Dafny.Map>.FromElements(new Dafny.Pair>(_1020_c, (_1020_c)._ToString(Dafny.Sequence.UnicodeFromString("")))); + RAST._IExpr _1024___v3; + _1024___v3 = (RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), _1020_c)).Optimize(); + RAST._IExpr _1025___v4; + _1025___v4 = (RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("abc"), Std.Wrappers.Option.create_Some(RAST.Type.create_I128()), Std.Wrappers.Option.create_None()), RAST.Expr.create_StmtExpr(RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("abc"), _1020_c), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString(""))))).Optimize(); + RAST._IExpr _1026___v5; + _1026___v5 = (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _1020_c, DAST.Format.UnaryOpFormat.create_NoFormat())).Optimize(); + RAST._IExpr _1027___v6; + _1027___v6 = (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _1020_c, DAST.Format.UnaryOpFormat.create_NoFormat())).Optimize(); + RAST._IExpr _1028___v7; + _1028___v7 = (DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), _1020_c)).Optimize(); + RAST._IExpr _1029___v8; + _1029___v8 = (DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(_1020_c, Dafny.Sequence.FromElements()))).Optimize(); + RAST._IExpr _1030___v9; + _1030___v9 = (DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(_1020_c, Dafny.Sequence.UnicodeFromString("int!")), Dafny.Sequence.FromElements()))).Optimize(); + RAST._IExpr _1031___v10; + _1031___v10 = (DafnyToRustCompilerCoverage.RASTCoverage.__default.ConversionNum(RAST.Type.create_U8(), RAST.Expr.create_Call(RAST.Expr.create_MemberSelect(RAST.Expr.create_MemberSelect(_1020_c, Dafny.Sequence.UnicodeFromString("dafny_runtime")), Dafny.Sequence.UnicodeFromString("int!")), Dafny.Sequence.FromElements()))).Optimize(); + RAST._IExpr _1032___v11; + _1032___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(_1020_c)))).Optimize(); + Std.Wrappers._IOption> _1033___v12; + _1033___v12 = (_1020_c).RightMostIdentifier(); } } public static void TestPrintingInfo() { - RAST._IExpr _981_x; - _981_x = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")); - RAST._IExpr _982_y; - _982_y = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")); - DAST.Format._IBinaryOpFormat _983_bnf; - _983_bnf = DAST.Format.BinaryOpFormat.create_NoFormat(); + RAST._IExpr _1034_x; + _1034_x = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")); + RAST._IExpr _1035_y; + _1035_y = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")); + DAST.Format._IBinaryOpFormat _1036_bnf; + _1036_bnf = DAST.Format.BinaryOpFormat.create_NoFormat(); DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(((RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("x"))).printingInfo).is_UnknownPrecedence); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((_981_x).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((_1034_x).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("3"))).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("abc"), true)).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), _981_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_SuffixPrecedence(new BigInteger(5)))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("-"), _981_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("*"), _981_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("!"), _981_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("&"), _981_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), _981_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("!!"), _981_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_UnknownPrecedence())); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_Select(_981_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(_981_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_Call(_981_x, Dafny.Sequence.FromElements(), 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(_981_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("*"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("/"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("%"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(30), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("-"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(30), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<<"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">>"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(50), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("^"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(60), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("|"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(70), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(90), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("||"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(100), RAST.Associativity.create_LeftToRight()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(".."), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("..="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RequiresParentheses()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("-="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("*="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("/="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("%="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("|="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("^="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<<="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">>="), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("?!?"), _981_x, _982_y, _983_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(BigInteger.Zero, RAST.Associativity.create_RequiresParentheses()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("abc"), true, false)).printingInfo, RAST.PrintingInfo.create_Precedence(BigInteger.One))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), _1034_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_SuffixPrecedence(new BigInteger(5)))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("-"), _1034_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("*"), _1034_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("!"), _1034_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("&"), _1034_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_Precedence(new BigInteger(6)))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), _1034_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("!!"), _1034_x, DAST.Format.UnaryOpFormat.create_NoFormat())).printingInfo, RAST.PrintingInfo.create_UnknownPrecedence())); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_Select(_1034_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(_1034_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_Call(_1034_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(_1034_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("*"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("/"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("%"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(30), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("-"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(30), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<<"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">>"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(50), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("^"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(60), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("|"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(70), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(90), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("||"), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(100), RAST.Associativity.create_LeftToRight()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(".."), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RequiresParentheses()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("..="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RequiresParentheses()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("+="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("-="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("*="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("/="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("%="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("|="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("^="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<<="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">>="), _1034_x, _1035_y, _1036_bnf)).printingInfo, RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()))); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(object.Equals((RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("?!?"), _1034_x, _1035_y, _1036_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() @@ -154,7 +156,7 @@ public static void TestNoExtraSemicolonAfter() DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_Return(Std.Wrappers.Option.create_None())).NoExtraSemicolonAfter()); DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_Continue(Std.Wrappers.Option>.create_None())).NoExtraSemicolonAfter()); DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())).NoExtraSemicolonAfter()); - DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_AssignVar(Dafny.Sequence.UnicodeFromString("x"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")))).NoExtraSemicolonAfter()); + DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.__default.AssignVar(Dafny.Sequence.UnicodeFromString("x"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("y")))).NoExtraSemicolonAfter()); DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("x"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_None())).NoExtraSemicolonAfter()); DafnyToRustCompilerCoverage.RASTCoverage.__default.AssertCoverage(!((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x"))).NoExtraSemicolonAfter())); } diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 7d508fa10..909272026 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -15,12 +15,27 @@ module {:extern "DAST.Format"} DAST.Format | ImpliesFormat | EquivalenceFormat | ReverseFormat + + function SeqToHeight(s: seq, f: T --> nat): (r: nat) + requires forall t <- s :: f.requires(t) + ensures forall t <- s :: f(t) <= r + { + if |s| == 0 then 0 else + var i := f(s[0]); + var j := SeqToHeight(s[1..], f); + if i < j then j else i + } } module {:extern "DAST"} DAST { import opened Std.Wrappers - datatype Module = Module(name: string, isExtern: bool, body: seq) + // Prevents Dafny names to being direclty integrated into Rust without explicit conversion + // Make it a newtype once newtypes are compatible with standard library + // 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>) datatype ModuleItem = | Module(Module) @@ -44,48 +59,71 @@ module {:extern "DAST"} DAST { Primitive(Primitive) | Passthrough(string) | TypeArg(Ident) + datatype TypeArgDecl = TypeArgDecl(name: Ident, bounds: seq) + + datatype TypeArgBound = + | SupportsEquality + | SupportsDefault + datatype Primitive = Int | Real | String | Bool | Char datatype NewtypeRange = | U8 | I8 | U16 | I16 | U32 | I32 | U64 | I64 | U128 | I128 | BigInt | NoRange + datatype Attribute = Attribute(name: string, args: seq) + + datatype DatatypeType = DatatypeType(path: seq, attributes: seq) + datatype ResolvedType = - | Datatype(path: seq) - | Trait(path: seq) - | Newtype(baseType: Type, range: NewtypeRange, erase: bool) + | Datatype(datatypeType: DatatypeType) + | Trait(path: seq, attributes: seq) + | Newtype(baseType: Type, range: NewtypeRange, erase: bool, attributes: seq) - datatype Ident = Ident(id: string) + datatype Ident = Ident(id: Name) - datatype Class = Class(name: string, enclosingModule: Ident, typeParams: seq, superClasses: seq, fields: seq, body: seq) + datatype Class = Class(name: Name, enclosingModule: Ident, typeParams: seq, superClasses: seq, fields: seq, body: seq, attributes: seq) - datatype Trait = Trait(name: string, typeParams: seq, body: seq) + datatype Trait = Trait(name: Name, typeParams: seq, body: seq, attributes: seq) - datatype Datatype = Datatype(name: string, enclosingModule: Ident, typeParams: seq, ctors: seq, body: seq, isCo: bool) + datatype Datatype = Datatype(name: Name, enclosingModule: Ident, typeParams: seq, ctors: seq, body: seq, isCo: bool, attributes: seq) - datatype DatatypeCtor = DatatypeCtor(name: string, args: seq, hasAnyArgs: bool /* includes ghost */) + datatype DatatypeDtor = DatatypeDtor(formal: Formal, callName: Option) - datatype Newtype = Newtype(name: string, typeParams: seq, base: Type, range: NewtypeRange, witnessStmts: seq, witnessExpr: Option) + datatype DatatypeCtor = DatatypeCtor(name: Name, args: seq, hasAnyArgs: bool /* includes ghost */) + + datatype Newtype = Newtype(name: Name, typeParams: seq, base: Type, range: NewtypeRange, witnessStmts: seq, witnessExpr: Option, attributes: seq) datatype ClassItem = Method(Method) datatype Field = Field(formal: Formal, defaultValue: Option) - datatype Formal = Formal(name: string, typ: Type) + datatype Formal = Formal(name: Name, typ: Type, attributes: seq) + + datatype Method = Method( + isStatic: bool, + hasBody: bool, + overridingPath: Option>, + name: Name, + typeParams: seq, + params: seq, + body: seq, + outTypes: seq, + outVars: Option>) - datatype Method = Method(isStatic: bool, hasBody: bool, overridingPath: Option>, name: string, typeParams: seq, params: seq, body: seq, outTypes: seq, outVars: Option>) + datatype CallSignature = CallSignature(parameters: seq) datatype CallName = - Name(name: string) | + CallName(name: Name, onType: Option, signature: CallSignature) | MapBuilderAdd | MapBuilderBuild | SetBuilderAdd | SetBuilderBuild datatype Statement = - DeclareVar(name: string, typ: Type, maybeValue: Option) | + DeclareVar(name: Name, 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: string, boundType: Type, over: Expression, body: seq) | + Foreach(boundName: Name, boundType: Type, over: Expression, body: seq) | Call(on: Expression, callName: CallName, typeArgs: seq, args: seq, outs: Option>) | Return(expr: Expression) | EarlyReturn() | @@ -96,8 +134,8 @@ module {:extern "DAST"} DAST { Print(Expression) datatype AssignLhs = - Ident(Ident) | - Select(expr: Expression, field: string) | + Ident(ident: Ident) | + Select(expr: Expression, field: Name) | Index(expr: Expression, indices: seq) datatype CollKind = Seq | Array | Map @@ -124,12 +162,12 @@ module {:extern "DAST"} DAST { datatype Expression = Literal(Literal) | - Ident(string) | + Ident(Name) | Companion(seq) | Tuple(seq) | New(path: seq, typeArgs: seq, args: seq) | NewArray(dims: seq, typ: Type) | - DatatypeValue(path: seq, typeArgs: seq, variant: string, isCo: bool, contents: seq<(string, Expression)>) | + DatatypeValue(datatypeType: DatatypeType, typeArgs: seq, variant: Name, isCo: bool, contents: seq<(string, Expression)>) | Convert(value: Expression, from: Type, typ: Type) | SeqConstruct(length: Expression, elem: Expression) | SeqValue(elements: seq, typ: Type) | @@ -148,17 +186,17 @@ module {:extern "DAST"} DAST { ArrayLen(expr: Expression, dim: nat) | MapKeys(expr: Expression) | MapValues(expr: Expression) | - Select(expr: Expression, field: string, isConstant: bool, onDatatype: bool) | - SelectFn(expr: Expression, field: string, onDatatype: bool, isStatic: bool, arity: nat) | + Select(expr: Expression, field: Name, isConstant: bool, onDatatype: bool, fieldType: Type) | + SelectFn(expr: Expression, field: Name, onDatatype: bool, isStatic: bool, arity: nat) | Index(expr: Expression, collKind: CollKind, indices: seq) | IndexRange(expr: Expression, isArray: bool, low: Option, high: Option) | - TupleSelect(expr: Expression, index: nat) | + 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(name: Ident, typ: Type, value: Expression, iifeBody: Expression) | Apply(expr: Expression, args: seq) | - TypeTest(on: Expression, dType: seq, variant: string) | + TypeTest(on: Expression, dType: seq, variant: Name) | InitializationValue(typ: Type) | BoolBoundedPool() | SetBoundedPool(of: Expression) | @@ -167,5 +205,12 @@ module {:extern "DAST"} DAST { datatype UnaryOp = Not | BitwiseNot | Cardinality - datatype Literal = BoolLiteral(bool) | IntLiteral(string, Type) | DecLiteral(string, string, Type) | StringLiteral(string) | CharLiteral(char) | Null(Type) + datatype Literal = + | BoolLiteral(bool) + | IntLiteral(string, Type) + | DecLiteral(string, string, Type) + | StringLiteral(string, verbatim: bool) + | CharLiteral(char) + | CharLiteralUTF16(nat) + | Null(Type) } diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index 42f19c757..db9ce6f57 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Numerics; using Dafny; using DAST; using DAST.Format; @@ -7,6 +8,7 @@ using Microsoft.CodeAnalysis; using Microsoft.Dafny.Compilers; using Std.Wrappers; +using Attribute = DAST.Attribute; namespace Microsoft.Dafny.Compilers { @@ -33,26 +35,27 @@ public void AddUnsupported(string why) { interface ModuleContainer : Container { void AddModule(Module item); - public ModuleBuilder Module(string name, bool isExtern) { - return new ModuleBuilder(this, name, isExtern); + public ModuleBuilder Module(string name, Sequence attributes) { + return new ModuleBuilder(this, name, attributes); } static public Module UnsupportedToModule(string why) { - return new Module(Sequence.UnicodeFromString(why), true, - Sequence.FromArray(new ModuleItem[] { })); + return new Module(Sequence.UnicodeFromString(why), Sequence.FromElements((Attribute)Attribute.create_Attribute( + Sequence.UnicodeFromString(why), Sequence>.Empty)), + Std.Wrappers.Option>.create_None()); } } class ModuleBuilder : ClassContainer, TraitContainer, NewtypeContainer, DatatypeContainer { readonly ModuleContainer parent; readonly string name; - readonly bool isExtern; + readonly Sequence attributes; readonly List body = new(); - public ModuleBuilder(ModuleContainer parent, string name, bool isExtern) { + public ModuleBuilder(ModuleContainer parent, string name, Sequence attributes) { this.parent = parent; this.name = name; - this.isExtern = isExtern; + this.attributes = attributes; } public void AddModule(Module item) { @@ -78,9 +81,10 @@ public void AddDatatype(Datatype item) { public object Finish() { parent.AddModule((Module)Module.create( Sequence.UnicodeFromString(this.name), - this.isExtern, - Sequence.FromArray(body.ToArray()) + attributes, + Std.Wrappers.Option>.create_Some((Sequence)Sequence.FromArray(body.ToArray())) )); + return parent; } @@ -92,26 +96,30 @@ public void AddUnsupported(string why) { interface ClassContainer : Container { void AddClass(Class item); - public ClassBuilder Class(string name, string enclosingModule, List typeParams, List superClasses) { - return new ClassBuilder(this, name, enclosingModule, typeParams, superClasses); + public ClassBuilder Class(string name, string enclosingModule, List typeParams, List superClasses, ISequence<_IAttribute> attributes) { + return new ClassBuilder(this, name, enclosingModule, typeParams, superClasses, attributes); } } + + class ClassBuilder : ClassLike { readonly ClassContainer parent; readonly string name; readonly string enclosingModule; - readonly List typeParams; + readonly List typeParams; readonly List superClasses; readonly List fields = new(); readonly List body = new(); + readonly ISequence<_IAttribute> attributes; - public ClassBuilder(ClassContainer parent, string name, string enclosingModule, List typeParams, List superClasses) { + public ClassBuilder(ClassContainer parent, string name, string enclosingModule, List typeParams, List superClasses, ISequence<_IAttribute> attributes) { this.parent = parent; this.name = name; this.enclosingModule = enclosingModule; this.typeParams = typeParams; this.superClasses = superClasses; + this.attributes = attributes; } public void AddMethod(DAST.Method item) { @@ -126,10 +134,11 @@ public object Finish() { parent.AddClass((Class)Class.create( Sequence.UnicodeFromString(this.name), Sequence.UnicodeFromString(this.enclosingModule), - Sequence.FromArray(this.typeParams.ToArray()), + Sequence.FromArray(this.typeParams.ToArray()), Sequence.FromArray(this.superClasses.ToArray()), Sequence.FromArray(this.fields.ToArray()), - Sequence.FromArray(body.ToArray()) + Sequence.FromArray(body.ToArray()), + attributes )); return parent; } @@ -138,21 +147,23 @@ public object Finish() { interface TraitContainer : Container { void AddTrait(Trait item); - public TraitBuilder Trait(string name, List typeParams) { - return new TraitBuilder(this, name, typeParams); + public TraitBuilder Trait(string name, List typeParams, ISequence<_IAttribute> attributes) { + return new TraitBuilder(this, name, typeParams, attributes); } } class TraitBuilder : ClassLike { readonly TraitContainer parent; readonly string name; - readonly List typeParams; + readonly List typeParams; readonly List body = new(); + private ISequence<_IAttribute> attributes; - public TraitBuilder(TraitContainer parent, string name, List typeParams) { + public TraitBuilder(TraitContainer parent, string name, List typeParams, ISequence<_IAttribute> attributes) { this.parent = parent; this.name = name; this.typeParams = typeParams; + this.attributes = attributes; } public void AddMethod(DAST.Method item) { @@ -174,8 +185,9 @@ public void AddField(DAST.Formal item, _IOption defaultValue) public object Finish() { parent.AddTrait((Trait)Trait.create( Sequence.UnicodeFromString(this.name), - Sequence.FromArray(typeParams.ToArray()), - Sequence.FromArray(body.ToArray())) + Sequence.FromArray(typeParams.ToArray()), + Sequence.FromArray(body.ToArray()), + attributes) ); return parent; } @@ -184,23 +196,26 @@ public object Finish() { interface NewtypeContainer : Container { void AddNewtype(Newtype item); - public NewtypeBuilder Newtype(string name, List typeParams, - DAST.Type baseType, DAST.NewtypeRange newtypeRange, List witnessStmts, DAST.Expression witness) { - return new NewtypeBuilder(this, name, typeParams, newtypeRange, baseType, witnessStmts, witness); + public NewtypeBuilder Newtype(string name, List typeParams, + DAST.Type baseType, NewtypeRange newtypeRange, List witnessStmts, DAST.Expression witness, + ISequence<_IAttribute> attributes) { + return new NewtypeBuilder(this, name, typeParams, newtypeRange, baseType, witnessStmts, witness, attributes); } } class NewtypeBuilder : ClassLike { readonly NewtypeContainer parent; readonly string name; - readonly List typeParams; + readonly List typeParams; readonly DAST.Type baseType; private readonly DAST.NewtypeRange newtypeRange; readonly List witnessStmts; readonly DAST.Expression witness; + private ISequence<_IAttribute> attributes; - public NewtypeBuilder(NewtypeContainer parent, string name, List typeParams, - DAST.NewtypeRange newtypeRange, DAST.Type baseType, List statements, DAST.Expression witness) { + public NewtypeBuilder(NewtypeContainer parent, string name, List typeParams, + DAST.NewtypeRange newtypeRange, DAST.Type baseType, List statements, DAST.Expression witness, + ISequence<_IAttribute> attributes) { this.parent = parent; this.name = name; this.typeParams = typeParams; @@ -208,6 +223,7 @@ public NewtypeBuilder(NewtypeContainer parent, string name, List type this.baseType = baseType; this.witnessStmts = statements; this.witness = witness; + this.attributes = attributes; } public void AddMethod(DAST.Method item) { @@ -221,11 +237,14 @@ public void AddField(DAST.Formal item, _IOption defaultValue) public object Finish() { parent.AddNewtype((Newtype)Newtype.create( Sequence.UnicodeFromString(this.name), - Sequence.FromArray(this.typeParams.ToArray()), + Sequence.FromArray(this.typeParams.ToArray()), this.baseType, newtypeRange, Sequence.FromArray(this.witnessStmts.ToArray()), - this.witness == null ? Option.create_None() : Option.create_Some(this.witness) + this.witness == null + ? Option.create_None() + : Option.create_Some(this.witness), + attributes )); return parent; } @@ -234,8 +253,9 @@ public object Finish() { interface DatatypeContainer : Container { void AddDatatype(Datatype item); - public DatatypeBuilder Datatype(string name, string enclosingModule, List typeParams, List ctors, bool isCo) { - return new DatatypeBuilder(this, name, enclosingModule, typeParams, ctors, isCo); + public DatatypeBuilder Datatype(string name, string enclosingModule, List typeParams, + List ctors, bool isCo, ISequence<_IAttribute> attributes) { + return new DatatypeBuilder(this, name, enclosingModule, typeParams, ctors, isCo, attributes); } } @@ -243,18 +263,20 @@ class DatatypeBuilder : ClassLike { readonly DatatypeContainer parent; readonly string name; readonly string enclosingModule; - readonly List typeParams; + readonly List typeParams; readonly List ctors; readonly bool isCo; readonly List body = new(); + private ISequence<_IAttribute> attributes; - public DatatypeBuilder(DatatypeContainer parent, string name, string enclosingModule, List typeParams, List ctors, bool isCo) { + public DatatypeBuilder(DatatypeContainer parent, string name, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes) { this.parent = parent; this.name = name; this.typeParams = typeParams; this.enclosingModule = enclosingModule; this.ctors = ctors; this.isCo = isCo; + this.attributes = attributes; } public void AddMethod(DAST.Method item) { @@ -269,10 +291,10 @@ public object Finish() { parent.AddDatatype((Datatype)Datatype.create( Sequence.UnicodeFromString(this.name), Sequence.UnicodeFromString(this.enclosingModule), - Sequence.FromArray(typeParams.ToArray()), + Sequence.FromArray(typeParams.ToArray()), Sequence.FromArray(ctors.ToArray()), Sequence.FromArray(body.ToArray()), - this.isCo + this.isCo, attributes )); return parent; } @@ -287,8 +309,8 @@ public MethodBuilder Method( bool isStatic, bool hasBody, ISequence> overridingPath, string name, - List typeArgs, - List params_, + List typeArgs, + Sequence params_, List outTypes, List> outVars ) { return new MethodBuilder(this, isStatic, hasBody, overridingPath, name, typeArgs, params_, outTypes, outVars); @@ -303,8 +325,8 @@ class MethodBuilder : StatementContainer { readonly bool isStatic; readonly bool hasBody; readonly ISequence> overridingPath; - readonly List typeArgs; - readonly List params_; + readonly List typeArgs; + readonly Sequence params_; readonly List outTypes; readonly List> outVars; readonly List body = new(); @@ -314,8 +336,8 @@ public MethodBuilder( bool isStatic, bool hasBody, ISequence> overridingPath, string name, - List typeArgs, - List params_, + List typeArgs, + Sequence params_, List outTypes, List> outVars ) { this.parent = parent; @@ -352,8 +374,8 @@ public DAST.Method Build() { hasBody, overridingPath != null ? Option>>.create_Some(overridingPath) : Option>>.create_None(), Sequence.UnicodeFromString(this.name), - Sequence.FromArray(typeArgs.ToArray()), - Sequence.FromArray(params_.ToArray()), + Sequence.FromArray(typeArgs.ToArray()), + params_, Sequence.FromArray(builtStatements.ToArray()), Sequence.FromArray(outTypes.ToArray()), outVars != null ? Option>>.create_Some(Sequence>.FromArray(outVars.ToArray())) : Option>>.create_None() @@ -434,8 +456,8 @@ public TailRecursiveBuilder TailRecursive() { return ret; } - public CallStmtBuilder Call() { - var ret = new CallStmtBuilder(); + public CallStmtBuilder Call(ISequence<_IFormal> signature) { + var ret = new CallStmtBuilder(signature); AddBuildable(ret); return ret; } @@ -511,7 +533,8 @@ public void AddBuildable(BuildableExpr value) { public DAST.Statement Build() { if (this.value == null) { - return (DAST.Statement)DAST.Statement.create_DeclareVar(Sequence.UnicodeFromString(name), type, Option.create_None()); + return (DAST.Statement)DAST.Statement.create_DeclareVar( + Sequence.UnicodeFromString(name), type, Option.create_None()); } else { var builtValue = new List(); ExprContainer.RecursivelyBuild(new List { value }, builtValue); @@ -836,8 +859,11 @@ class CallStmtBuilder : ExprContainer, BuildableStatement { List typeArgs = null; readonly List args = new(); List> outs = null; + public readonly ISequence<_IFormal> Signature; - public CallStmtBuilder() { } + public CallStmtBuilder(ISequence<_IFormal> signature) { + this.Signature = signature; + } public void SetName(CallName name) { if (this.name != null) { @@ -977,6 +1003,24 @@ public void AddUnsupported(string why) { } } + class NoStatementBuffer : StatementContainer { + public void AddUnsupported(string why) { + throw new Exception(why); + } + + public void AddStatement(DAST.Statement item) { + throw new Exception("Add statements in pure expressions, in a context where statements can't be added, tried to add " + item); + } + + public void AddBuildable(BuildableStatement item) { + throw new Exception("Add buildable statements in pure expressions, in a context where statements can't be added, tried to add " + item); + } + + public List ForkList() { + throw new Exception("Fork statements in pure expressions, in a context where statements can't be added"); + } + } + class StatementBuffer : StatementContainer { readonly List statements = new(); @@ -1046,8 +1090,6 @@ public DAST.Expression Finish() { if (exprs.Count != 1) { return ExprContainer.UnsupportedToExpr("Expected exactly one expression in buffer, got " + exprs.Comma(e => e.ToString())); - throw new UnsupportedFeatureException(Token.NoToken, Feature.RunAllTests); // Warning: this is an invalid operation - //throw new InvalidOperationException("Expected exactly one expression in buffer, got " + exprs.Comma(e => e.ToString())); } else { return PopN(1)[0]; } @@ -1079,8 +1121,8 @@ BinOpBuilder BinOp(string op, Func signature) { + var ret = new CallExprBuilder(signature); AddBuildable(ret); return ret; } @@ -1139,7 +1181,7 @@ protected static void RecursivelyBuild(List body, List static DAST.Expression UnsupportedToExpr(string why) { return (DAST.Expression)DAST.Expression.create_Ident( - Sequence>.UnicodeFromString($"Unsupported: {why}") + Sequence>.UnicodeFromString($"Unsupported: {why}") ); } } @@ -1263,7 +1305,11 @@ class CallExprBuilder : ExprContainer, BuildableExpr { readonly List args = new(); List> outs = null; - public CallExprBuilder() { } + public ISequence<_IFormal> Signature { get; } + + public CallExprBuilder(ISequence<_IFormal> signature) { + Signature = signature; + } public void SetName(DAST.CallName name) { if (this.name != null) { @@ -1439,7 +1485,7 @@ public void AddBuildable(BuildableExpr item) { public DAST.Expression Build() { var builtBody = new List(); - ExprContainer.RecursivelyBuild(new List { body }, builtBody); + ExprContainer.RecursivelyBuild(new List { body ?? ExprContainer.UnsupportedToExpr("IIFEExprBuilder with empty body") }, builtBody); var builtValue = new List(); ExprContainer.RecursivelyBuild(new List { value diff --git a/Source/DafnyCore/Backends/Dafny/BuilderSyntaxTree.cs b/Source/DafnyCore/Backends/Dafny/BuilderSyntaxTree.cs index c1a14b17c..40913275d 100644 --- a/Source/DafnyCore/Backends/Dafny/BuilderSyntaxTree.cs +++ b/Source/DafnyCore/Backends/Dafny/BuilderSyntaxTree.cs @@ -28,5 +28,11 @@ public override ConcreteSyntaxTree ForkInParens() { // TODO(shadaj): perhaps should check if we are an expr container return new BuilderSyntaxTree(Builder, Compiler); } + + public override ConcreteSyntaxTree NewBlock(string header = "", string footer = "", + BlockStyle open = BlockStyle.SpaceBrace, + BlockStyle close = BlockStyle.NewlineBrace) { + return Fork(); + } } } diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 4cf135d79..0bb731ae3 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Diagnostics.Contracts; using DAST.Format; +using Microsoft.Boogie; using Std.Wrappers; namespace Microsoft.Dafny.Compilers { @@ -119,7 +120,11 @@ protected override ConcreteSyntaxTree CreateStaticMain(IClassWriter cw, string a protected override ConcreteSyntaxTree CreateModule(string moduleName, bool isDefault, ModuleDefinition externModule, string libraryName, ConcreteSyntaxTree wr) { if (currentBuilder is ModuleContainer moduleBuilder) { - currentBuilder = moduleBuilder.Module(moduleName, externModule != null); + var attributes = (Sequence)Sequence.Empty; + if (externModule != null) { + attributes = (Sequence)ParseAttributes(externModule.Attributes); + } + currentBuilder = moduleBuilder.Module(moduleName, attributes); } else { throw new InvalidOperationException(); } @@ -177,9 +182,11 @@ protected override ConcreteSyntaxTree EmitCoercionIfNecessary(Type from, Type to if (from == null || to == null || from.Equals(to, true)) { return wr; } else { - AddUnsupported($"Coercion from {from} to {to}"); - return new BuilderSyntaxTree( - new ExprBuffer(this), this); + if (wr is BuilderSyntaxTree stmt) { + return new BuilderSyntaxTree(stmt.Builder.Convert(GenType(from), GenType(to)), this); + } else { + return base.EmitCoercionIfNecessary(from, to, tok, wr); + } } } } @@ -187,32 +194,53 @@ protected override ConcreteSyntaxTree EmitCoercionIfNecessary(Type from, Type to protected override IClassWriter CreateClass(string moduleName, string name, bool isExtern, string fullPrintName, List typeParameters, TopLevelDecl cls, List superClasses, IToken tok, ConcreteSyntaxTree wr) { if (currentBuilder is ClassContainer builder) { - List typeParams = new(); + List typeParams = new(); foreach (var tp in typeParameters) { var compileName = IdProtect(tp.GetCompileName(Options)); if (!isTpSupported(tp, out var why)) { AddUnsupported(why); } + var bounds = GenTypeBounds(tp); - typeParams.Add((DAST.Type)DAST.Type.create_TypeArg(Sequence.UnicodeFromString(compileName))); + typeParams.Add((DAST.TypeArgDecl)DAST.TypeArgDecl.create_TypeArgDecl( + Sequence.UnicodeFromString(compileName), bounds)); } - return new ClassWriter(this, typeParams.Count > 0, builder.Class(name, moduleName, typeParams, superClasses.Select(t => GenType(t)).ToList())); + return new ClassWriter(this, typeParams.Count > 0, builder.Class( + name, moduleName, typeParams, superClasses.Select(t => GenType(t)).ToList(), + ParseAttributes(cls.Attributes)) + ); } else { throw new InvalidOperationException(); } } + private static ISequence<_ITypeArgBound> GenTypeBounds(TypeParameter tp) { + var characteristics = new List<_ITypeArgBound>(); + if (tp.Characteristics.AutoInit is Type.AutoInitInfo.CompilableValue) { + characteristics.Add(DAST.TypeArgBound.create_SupportsDefault()); + } + + if (tp.Characteristics.EqualitySupport is 0) { + characteristics.Add(DAST.TypeArgBound.create_SupportsEquality()); + } + + var bounds = Sequence<_ITypeArgBound>.FromArray(characteristics.ToArray()); + return bounds; + } + protected override IClassWriter CreateTrait(string name, bool isExtern, List typeParameters, TraitDecl trait, List superClasses, IToken tok, ConcreteSyntaxTree wr) { if (currentBuilder is TraitContainer builder) { - List typeParams = new(); + List typeParams = new(); foreach (var tp in trait.TypeArgs) { - typeParams.Add((DAST.Type)DAST.Type.create_TypeArg(Sequence.UnicodeFromString(IdProtect(tp.GetCompileName(Options))))); + var bounds = GenTypeBounds(tp); + + typeParams.Add((DAST.TypeArgDecl)DAST.TypeArgDecl.create_TypeArgDecl(Sequence.UnicodeFromString(IdProtect(tp.GetCompileName(Options))), bounds)); } - return new ClassWriter(this, typeParameters.Any(), builder.Trait(name, typeParams)); + return new ClassWriter(this, typeParameters.Any(), builder.Trait(name, typeParams, ParseAttributes(trait.Attributes))); } else { throw new InvalidOperationException(); } @@ -228,45 +256,49 @@ private static bool isTpSupported(TypeParameter tp, [CanBeNull] out string why) why = $"Unsupported: Type variance {tp.Variance} not supported"; return false; } - - if (tp.Characteristics.EqualitySupport != TypeParameter.EqualitySupportValue.Unspecified) { - why = $"Unsupported: Type parameter Equality support {tp.Characteristics.EqualitySupport} not supported for type parameters"; - return false; - } - why = null; return true; } protected override IClassWriter DeclareDatatype(DatatypeDecl dt, ConcreteSyntaxTree wr) { if (currentBuilder is DatatypeContainer builder) { - List typeParams = new(); + List typeParams = new(); foreach (var tp in dt.TypeArgs) { var compileName = IdProtect(tp.GetCompileName(Options)); if (!isTpSupported(tp, out var why) && !(dt is TupleTypeDecl)) { AddUnsupported(why); } + var bounds = GenTypeBounds(tp); - typeParams.Add((DAST.Type)DAST.Type.create_TypeArg(Sequence.UnicodeFromString(compileName))); + typeParams.Add((DAST.TypeArgDecl)DAST.TypeArgDecl.create_TypeArgDecl( + Sequence.UnicodeFromString(compileName), bounds)); } - List ctors = new(); - foreach (var ctor in dt.Ctors) { - List args = new(); - foreach (var arg in ctor.Formals) { - if (!arg.IsGhost) { - args.Add((DAST.Formal)DAST.Formal.create_Formal(Sequence.UnicodeFromString(arg.CompileName), GenType(arg.Type))); - } - } - ctors.Add((DAST.DatatypeCtor)DAST.DatatypeCtor.create_DatatypeCtor(Sequence.UnicodeFromString(ctor.GetCompileName(Options)), Sequence.FromArray(args.ToArray()), ctor.Formals.Count > 0)); - } + IEnumerable ctors = + from ctor in dt.Ctors + let allDtors = + from arg in ctor.Formals + where !arg.IsGhost + let formalName = Sequence.UnicodeFromString(GetDestructorFormalName(arg)) + let formalType = GenType(arg.Type) + let formalCallName = GetExtractOverrideName(arg.Attributes, arg.CompileName) + let dtorName = + Option>.create_Some((Sequence)Sequence.UnicodeFromString(formalCallName)) + let formalAttributes = ParseAttributes(arg.Attributes) + select (DAST.DatatypeDtor)DAST.DatatypeDtor.create_DatatypeDtor((DAST.Formal)DAST.Formal.create_Formal( + formalName, formalType, formalAttributes), dtorName) + let args = Sequence.FromArray(allDtors.ToArray()) + select (DAST.DatatypeCtor)DAST.DatatypeCtor.create_DatatypeCtor( + Sequence.UnicodeFromString(ctor.GetCompileName(Options)), + args, ctor.Formals.Count > 0); return new ClassWriter(this, typeParams.Count > 0, builder.Datatype( dt.GetCompileName(Options), dt.EnclosingModuleDefinition.GetCompileName(Options), typeParams, - ctors, - dt is CoDatatypeDecl + ctors.ToList(), + dt is CoDatatypeDecl, + ParseAttributes(dt.Attributes) )); } else { throw new InvalidOperationException("Cannot declare datatype outside of a module: " + currentBuilder); @@ -294,7 +326,7 @@ protected override IClassWriter DeclareNewtype(NewtypeDecl nt, ConcreteSyntaxTre return new ClassWriter(this, false, builder.Newtype( nt.GetCompileName(Options), new(), - GenType(erasedType), NativeTypeToNewtypeRange(nt.NativeType), witnessStmts, witness)); + GenType(erasedType), NativeTypeToNewtypeRange(nt.NativeType), witnessStmts, witness, ParseAttributes(nt.Attributes))); } else { throw new InvalidOperationException(); } @@ -380,18 +412,22 @@ protected override void DeclareSubsetType(SubsetTypeDecl sst, ConcreteSyntaxTree DAST.Expression baseConstraint = buf.Finish(); var baseConstraintStmts = statementBuf.PopAll(); // TODO: Integrate in AST. - List typeParams = new(); + List typeParams = new(); foreach (var tp in sst.TypeArgs) { var compileName = tp.Name; if (!isTpSupported(tp, out var why)) { AddUnsupported(why); + } - typeParams.Add((DAST.Type)DAST.Type.create_TypeArg(Sequence.UnicodeFromString(compileName))); + var bounds = GenTypeBounds(tp); + + typeParams.Add((DAST.TypeArgDecl)DAST.TypeArgDecl.create_TypeArgDecl( + Sequence.UnicodeFromString(compileName), bounds)); } builder.Newtype(sst.GetCompileName(Options), typeParams, - GenType(erasedType), (NewtypeRange)NewtypeRange.create_NoRange(), witnessStmts, witness).Finish(); + GenType(erasedType), (NewtypeRange)NewtypeRange.create_NoRange(), witnessStmts, witness, ParseAttributes(sst.Attributes)).Finish(); } else { throw new InvalidOperationException(); } @@ -403,6 +439,19 @@ protected override void GetNativeInfo(NativeType.Selection sel, out string name, needsCastAfterArithmetic = false; } + private Sequence GenFormals(List formals) { + List paramsList = new(); + foreach (var param in formals) { + if (param is not ImplicitFormal && !param.IsGhost) { + paramsList.Add((DAST.Formal)DAST.Formal.create_Formal( + Sequence.UnicodeFromString(IdProtect(param.CompileName)), GenType(param.Type), ParseAttributes(param.Attributes))); + } + } + + Sequence params_ = (Sequence)Sequence.FromArray(paramsList.ToArray()); + return params_; + } + private class ClassWriter : IClassWriter { private readonly DafnyCodeGenerator compiler; private readonly ClassLike builder; @@ -422,22 +471,18 @@ public ConcreteSyntaxTree CreateMethod(Method m, List return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); } - List astTypeArgs = new(); + List astTypeArgs = new(); foreach (var typeArg in typeArgs) { var compileName = compiler.IdProtect(typeArg.Formal.GetCompileName(compiler.Options)); if (!isTpSupported(typeArg.Formal, out var why)) { compiler.AddUnsupported(why); } + var bounds = GenTypeBounds(typeArg.Formal); - astTypeArgs.Add((DAST.Type)DAST.Type.create_TypeArg(Sequence.UnicodeFromString(compileName))); + astTypeArgs.Add((DAST.TypeArgDecl)DAST.TypeArgDecl.create_TypeArgDecl(Sequence.UnicodeFromString(compileName), bounds)); } - List params_ = new(); - foreach (var param in m.Ins) { - if (param is not ImplicitFormal && !param.IsGhost) { - params_.Add((DAST.Formal)DAST.Formal.create_Formal(Sequence.UnicodeFromString(compiler.IdProtect(param.CompileName)), compiler.GenType(param.Type))); - } - } + var params_ = compiler.GenFormals(m.Ins); List> outVars = new(); List outTypes = new(); @@ -479,22 +524,18 @@ public ConcreteSyntaxTree CreateFunction(string name, List(new StatementBuffer(), this.compiler); } - List astTypeArgs = new(); + List astTypeArgs = new(); foreach (var typeArg in typeArgs) { var compileName = compiler.IdProtect(typeArg.Formal.GetCompileName(compiler.Options)); if (!isTpSupported(typeArg.Formal, out var why)) { compiler.AddUnsupported(why); } + var bounds = GenTypeBounds(typeArg.Formal); - astTypeArgs.Add((DAST.Type)DAST.Type.create_TypeArg(Sequence.UnicodeFromString(compileName))); + astTypeArgs.Add((DAST.TypeArgDecl)DAST.TypeArgDecl.create_TypeArgDecl(Sequence.UnicodeFromString(compileName), bounds)); } - List params_ = new(); - foreach (var param in formals) { - if (!param.IsGhost) { - params_.Add((DAST.Formal)DAST.Formal.create_Formal(Sequence.UnicodeFromString(compiler.IdProtect(param.CompileName)), compiler.GenType(param.Type))); - } - } + var params_ = compiler.GenFormals(formals); var overridingTrait = member.OverriddenMember?.EnclosingClass; @@ -529,7 +570,7 @@ public ConcreteSyntaxTree CreateGetter(string name, TopLevelDecl enclosingDecl, isStatic, createBody, overridingTrait != null ? compiler.PathFromTopLevel(overridingTrait) : null, name, - new(), new(), + new(), (Sequence)Sequence.Empty, new() { compiler.GenType(resultType) }, null @@ -571,7 +612,8 @@ public void DeclareField(string name, TopLevelDecl enclosingDecl, bool isStatic, builder.AddField((DAST.Formal)DAST.Formal.create_Formal( Sequence.UnicodeFromString(name), - compiler.GenType(type) + compiler.GenType(type), + compiler.ParseAttributes(field.Attributes) ), rhsExpr); } @@ -668,19 +710,19 @@ protected override string TypeInitializationValue(Type type, ConcreteSyntaxTree bufferedInitializationValue = Option.create_None(); bufferedInitializationStmts = Option>.create_None(); } else { - if (type.AsNewtype != null && type.AsNewtype.WitnessKind == SubsetTypeDecl.WKind.Compiled) { - var buf = new ExprBuffer(null); + if (type.AsNewtype is { WitnessKind: SubsetTypeDecl.WKind.Compiled } newType) { var bufStmt = new StatementBuffer(); - EmitExpr(type.AsNewtype.Witness, false, new BuilderSyntaxTree(buf, this), - new BuilderSyntaxTree(bufStmt, this)); - bufferedInitializationValue = Option.create_Some(buf.Finish()); + bufferedInitializationValue = Option.create_Some( + DAST.Expression.create_Convert( + ConvertExpression(newType.Witness, new BuilderSyntaxTree(bufStmt, this)), + GenType(newType.BaseType), + GenType(UserDefinedType.FromTopLevelDecl(newType.Witness.tok, newType)) + )); bufferedInitializationStmts = Option>.create_Some(bufStmt.PopAll()); } else if (type.AsSubsetType != null && type.AsSubsetType.WitnessKind == SubsetTypeDecl.WKind.Compiled) { - var buf = new ExprBuffer(null); var bufStmt = new StatementBuffer(); - EmitExpr(type.AsSubsetType.Witness, false, new BuilderSyntaxTree(buf, this), - new BuilderSyntaxTree(bufStmt, this)); - bufferedInitializationValue = Option.create_Some(buf.Finish()); + bufferedInitializationValue = Option.create_Some( + ConvertExpression(type.AsSubsetType.Witness, new BuilderSyntaxTree(bufStmt, this))); bufferedInitializationStmts = Option>.create_Some(bufStmt.PopAll()); } else if (type.AsDatatype != null && type.AsDatatype.Ctors.Count == 1 && type.AsDatatype.Ctors[0].EnclosingDatatype is TupleTypeDecl tupleDecl) { var elems = new List(); @@ -752,10 +794,33 @@ protected override void EmitTypeName_Companion(Type type, ConcreteSyntaxTree wr, protected override void EmitNameAndActualTypeArgs(string protectedName, List typeArgs, IToken tok, Expression replacementReceiver, bool receiverAsArgument, ConcreteSyntaxTree wr) { + Sequence<_IFormal> receiverArgs = null; + var receiverBeforeName = replacementReceiver != null && replacementReceiver is not StaticReceiverExpr; + Option receiverType = receiverBeforeName && !receiverAsArgument + ? (Option)Option.create_Some(GenType(replacementReceiver.Type)) + : (Option)Option.create_None(); + if (receiverBeforeName) { + var name = replacementReceiver is IdentifierExpr { Var: { CompileName: var compileName } } + ? compileName + : "receiver"; + receiverArgs = (Sequence<_IFormal>)Sequence<_IFormal>.FromArray(new _IFormal[] { + DAST.Formal.create_Formal(Sequence.UnicodeFromString(name), + GenType(replacementReceiver.Type), ParseAttributes(null)) + }); + } + if (GetExprBuilder(wr, out var st) && st.Builder is CallExprBuilder callExpr) { - callExpr.SetName((DAST.CallName)DAST.CallName.create_Name(Sequence.UnicodeFromString(protectedName))); + var signature = callExpr.Signature; + if (receiverArgs != null) { + signature = Sequence<_IFormal>.FromArray(receiverArgs.Concat(signature).ToArray()); + } + callExpr.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString(protectedName), receiverType, signature)); } else if (GetExprBuilder(wr, out var st2) && st2.Builder is CallStmtBuilder callStmt) { - callStmt.SetName((DAST.CallName)DAST.CallName.create_Name(Sequence.UnicodeFromString(protectedName))); + var signature = callStmt.Signature; + if (receiverArgs != null) { + signature = Sequence<_IFormal>.FromArray(receiverArgs.Concat(signature).ToArray()); + } + callStmt.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString(protectedName), receiverType, signature)); } else { AddUnsupported("Builder issue: wr is as " + wr.GetType() + (GetExprBuilder(wr, out var st3) ? @@ -851,7 +916,8 @@ protected override void TrCallStmt(CallStmt s, string receiverReplacement, Concr if (s.Method == enclosingMethod && enclosingMethod.IsTailRecursive) { base.TrCallStmt(s, receiverReplacement, wr, wrStmts, wrStmtsAfterCall); } else { - var callBuilder = stmtContainer.Builder.Call(); + var parameters = GenFormals(s.Method.Ins); + var callBuilder = stmtContainer.Builder.Call(parameters); base.TrCallStmt(s, receiverReplacement, new BuilderSyntaxTree(callBuilder, this), wrStmts, wrStmtsAfterCall); } } else { @@ -861,7 +927,7 @@ protected override void TrCallStmt(CallStmt s, string receiverReplacement, Concr 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(); + var callBuilder = stmtContainer.Builder.Call(GenFormals(method.Ins)); base.EmitCallToInheritedMethod(method, heir, new BuilderSyntaxTree(callBuilder, this), wStmts, wStmtsAfterCall); } else { throw new InvalidOperationException("Cannot call statement in this context: " + currentBuilder); @@ -878,7 +944,7 @@ protected override void CompileFunctionCallExpr(FunctionCallExpr e, ConcreteSynt wr = EmitCoercionIfNecessary(e.Function.Original.ResultType, toType, e.tok, wr); if (wr is BuilderSyntaxTree builder) { - var callBuilder = builder.Builder.Call(); + var callBuilder = builder.Builder.Call(GenFormals(e.Function.Ins)); base.CompileFunctionCallExpr(e, new BuilderSyntaxTree(callBuilder, this), inLetExprBody, wStmts, tr, true); } else { throw new InvalidOperationException("Cannot call function in this context: " + currentBuilder); @@ -1245,20 +1311,30 @@ protected override void EmitLiteralExpr(ConcreteSyntaxTree wr, LiteralExpr e) { switch (e) { case CharLiteralExpr c: - if (UnicodeCharEnabled) { - var codePoint = Util.UnescapedCharacters(Options, (string)c.Value, false).Single(); + var codePoint = Util.UnescapedCharacters(Options, (string)c.Value, false).Single(); + if (Rune.IsRune(new BigInteger(codePoint))) { // More readable version in the generated code. baseExpr = (DAST.Expression)DAST.Expression.create_Literal(DAST.Literal.create_CharLiteral( new Rune(codePoint) )); } else { - AddUnsupported("Char literal without unicode char enabled"); - return; + baseExpr = (DAST.Expression)DAST.Expression.create_Literal(DAST.Literal.create_CharLiteralUTF16( + codePoint + )); } + break; case StringLiteralExpr str: - baseExpr = (DAST.Expression)DAST.Expression.create_Literal(DAST.Literal.create_StringLiteral( - Sequence.UnicodeFromString(str.AsStringLiteral()) - )); + if (!UnicodeCharEnabled && Util.TokensWithEscapes(str.AsStringLiteral(), false) is var tokens && tokens.Any((string token) => Util.Utf16Escape.IsMatch(token))) { + var s = Util.UnescapedCharacters(UnicodeCharEnabled, str.AsStringLiteral(), true); + var chars = tokens.Select((string singleChar) => + ConvertExpressionNoStatement(new CharLiteralExpr(Token.NoToken, singleChar) { Type = Type.Char })).ToArray(); + baseExpr = (DAST.Expression)DAST.Expression.create_SeqValue(Sequence.FromArray(chars), GenType(new CharType())); + // We need to emit a sequence of chars literal. We first + } else { + baseExpr = (DAST.Expression)DAST.Expression.create_Literal(DAST.Literal.create_StringLiteral( + Sequence.UnicodeFromString(str.AsStringLiteral()), str.IsVerbatim + )); + } break; case StaticReceiverExpr: if (e.Type.NormalizeExpandKeepConstraints() is UserDefinedType udt && udt.ResolvedClass is DatatypeDecl dt && @@ -1422,6 +1498,35 @@ private DAST.NewtypeRange NativeTypeToNewtypeRange(NativeType nativeType) { }); } + private ISequence ParseAttributes(Attributes attributes) { + var a = attributes; + var result = new List() { }; + while (a != null) { + var name = Sequence.UnicodeFromString(a.Name); + var args = new List>(); + foreach (var arg in a.Args) { + if (arg is Dafny.LiteralExpr { Value: var value }) { + var argToAdd = ""; + if (value is string s) { + argToAdd = s; + } else if (value is bool b) { + argToAdd = b ? "true" : "false"; + } else if (value is BigInteger big) { + argToAdd = big.ToString(); + } else { + argToAdd = "unknown " + value.GetType(); + } + args.Add((Sequence)Sequence.UnicodeFromString(argToAdd)); + } + } + result.Add((DAST.Attribute)DAST.Attribute.create_Attribute(name, + Sequence>.FromArray(args.ToArray()))); + a = a.Prev; + } + + return Sequence.FromArray(result.ToArray()); + } + private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List typeArgs) { var path = PathFromTopLevel(topLevel); @@ -1436,23 +1541,25 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type if (topLevel is NewtypeDecl newType) { var range = NativeTypeToNewtypeRange(newType.NativeType); resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_Newtype( - GenType(EraseNewtypeLayers(topLevel)), range, true); + GenType(EraseNewtypeLayers(topLevel)), range, true, ParseAttributes(newType.Attributes)); } else if (topLevel is TypeSynonymDecl typeSynonym) { // Also SubsetTypeDecl - resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_Newtype(GenType(EraseNewtypeLayers(topLevel)), NewtypeRange.create_NoRange(), true); + resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_Newtype( + GenType(EraseNewtypeLayers(topLevel)), NewtypeRange.create_NoRange(), true, ParseAttributes(typeSynonym.Attributes)); } else if (topLevel is TraitDecl) { AddUnsupportedFeature(Token.NoToken, Feature.Traits); resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_Newtype( DAST.Type.create_Passthrough(Sequence.UnicodeFromString("Unsupported: Traits")), - NewtypeRange.create_NoRange(), true + NewtypeRange.create_NoRange(), true, ParseAttributes(null) ); // traits need a bit more work // resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_Trait(path); } else if (topLevel is DatatypeDecl) { - resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_Datatype(path); + resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_Datatype( + (DatatypeType)DatatypeType.create_DatatypeType(path, ParseAttributes(topLevel.Attributes))); } else if (topLevel is ClassDecl) { // TODO(Mikael): have a separate type when we properly support classes - resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_Datatype(path); + resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_Datatype((DatatypeType)DatatypeType.create_DatatypeType(path, ParseAttributes(topLevel.Attributes))); } else { // SubsetTypeDecl are covered by TypeSynonymDecl throw new InvalidOperationException(topLevel.GetType().ToString()); @@ -1532,14 +1639,16 @@ protected override void EmitDatatypeValue(DatatypeValue dtv, string typeDescript int argI = 0; for (int i = 0; i < dtv.Ctor.Formals.Count; i++) { - var formal = dtv.Ctor.Formals[i]; - if (formal.IsGhost) { + var destructor = dtv.Ctor.Destructors[i]; + if (destructor.IsGhost) { continue; } var actual = contents[argI]; + var formal = dtv.Ctor.Formals[i]; + var destructorName = GetDestructorFormalName(formal); namedContents.Add(_System.Tuple2, DAST.Expression>.create( - Sequence.UnicodeFromString(formal.CompileName), + Sequence.UnicodeFromString(destructorName), actual )); @@ -1570,7 +1679,7 @@ protected override void EmitDatatypeValue(DatatypeValue dtv, string typeDescript var dtPath = PathFromTopLevel(dtv.Ctor.EnclosingDatatype); var dtTypeArgs = Sequence.FromArray(dtv.InferredTypeArgs.Select(m => GenType(m)).ToArray()); builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_DatatypeValue( - dtPath, + (DatatypeType)DatatypeType.create_DatatypeType(dtPath, ParseAttributes(dtv.Ctor.EnclosingDatatype.Attributes)), dtTypeArgs, Sequence.UnicodeFromString(dtv.Ctor.GetCompileName(Options)), dtv.Ctor.EnclosingDatatype is CoDatatypeDecl, @@ -1582,6 +1691,17 @@ protected override void EmitDatatypeValue(DatatypeValue dtv, string typeDescript } } + private static string GetDestructorFormalName(Formal formal) { + var defaultName = formal.CompileName; + object externVal = null; + bool hasExternVal = Attributes.ContainsMatchingValue(formal.Attributes, "extern", + ref externVal, new List { + Attributes.MatchingValueOption.String + }, s => throw new UnsupportedInvalidOperationException("Non-string externs for destructors")); + var destructorName = externVal as string ?? defaultName; + return destructorName; + } + protected override void GetSpecialFieldInfo(SpecialField.ID id, object idParam, Type receiverType, out string compiledName, out string preString, out string postString) { compiledName = ""; @@ -1622,20 +1742,23 @@ protected override ILvalue EmitMemberSelect(Action obj, Type if (dtor.EnclosingClass is TupleTypeDecl) { return new ExprLvalue((DAST.Expression)DAST.Expression.create_TupleSelect( objExpr, - int.Parse(dtor.CorrespondingFormals[0].NameForCompilation) + int.Parse(dtor.CorrespondingFormals[0].NameForCompilation), GenType(expectedType) ), null, this); } else { + var attributes = member.Attributes ?? + (dtor.CorrespondingFormals.Count == 1 ? dtor.CorrespondingFormals[0].Attributes : null); + var compileName = GetExtractOverrideName(attributes, member.GetCompileName(Options)); return new ExprLvalue((DAST.Expression)DAST.Expression.create_Select( objExpr, - Sequence.UnicodeFromString(member.GetCompileName(Options)), + Sequence.UnicodeFromString(compileName), member is ConstantField, - member.EnclosingClass is DatatypeDecl + member.EnclosingClass is DatatypeDecl, GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)) ), this); } - } else if (member is SpecialField arraySpecial && arraySpecial.SpecialId == SpecialField.ID.ArrayLength) { + } else if (member is SpecialField { SpecialId: SpecialField.ID.ArrayLength } arraySpecial) { obj(EmitCoercionIfNecessary( objType, objType.IsNonNullRefType || !objType.IsRefType ? null : UserDefinedType.CreateNonNullType((UserDefinedType)objType.NormalizeExpand()), @@ -1666,7 +1789,7 @@ member.EnclosingClass is DatatypeDecl objExpr, Sequence.UnicodeFromString(compiledName), member is ConstantField, - member.EnclosingClass is DatatypeDecl + member.EnclosingClass is DatatypeDecl, GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(compiledName) @@ -1697,7 +1820,7 @@ member.EnclosingClass is DatatypeDecl objExpr, Sequence.UnicodeFromString(InternalFieldPrefix + member.GetCompileName(Options)), false, - member.EnclosingClass is DatatypeDecl + member.EnclosingClass is DatatypeDecl, GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(InternalFieldPrefix + member.GetCompileName(Options)) @@ -1707,7 +1830,7 @@ member.EnclosingClass is DatatypeDecl objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), member is ConstantField, - member.EnclosingClass is DatatypeDecl + member.EnclosingClass is DatatypeDecl, GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)) @@ -1817,8 +1940,15 @@ protected bool GetExprConverter(ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts out BuilderSyntaxTree builder, out Func converter) { if (wr is BuilderSyntaxTree b) { - converter = (Expression expr) => ConvertExpression(expr, wStmts); builder = b; + if (wStmts is BuilderSyntaxTree s) { + converter = (Expression expr) => ConvertExpression(expr, s); + } else { + var statementBuf = new NoStatementBuffer(); + var sNoStmt = new BuilderSyntaxTree(statementBuf, this); + converter = (Expression expr) => ConvertExpression(expr, sNoStmt); + } + return true; } converter = null; @@ -1931,7 +2061,7 @@ protected override ConcreteSyntaxTree EmitBetaRedex(List boundVars, List (_System.Tuple2) _System.Tuple2.create( (DAST.Formal)DAST.Formal.create_Formal(Sequence.UnicodeFromString(boundVars[i]), - GenType(boundTypes[i])), convert(t))).ToList(); + GenType(boundTypes[i]), ParseAttributes(null)), convert(t))).ToList(); var retType = GenType(resultType); @@ -1958,20 +2088,27 @@ protected override void EmitDestructor(Action source, Formal if (ctor.EnclosingDatatype is TupleTypeDecl) { builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_TupleSelect( sourceAST, - int.Parse(dtor.NameForCompilation) + int.Parse(dtor.NameForCompilation), GenType(dtor.Type) )); } else { + var compileName = GetExtractOverrideName(dtor.Attributes, dtor.CompileName); builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_Select( sourceAST, - Sequence.UnicodeFromString(dtor.CompileName), + Sequence.UnicodeFromString(compileName), false, - true + true, GenType(dtor.Type) )); } } } } + private static string GetExtractOverrideName(Attributes attributes, string defaultValue) { + return ((Attributes.Find(attributes, "extern_extract") is { } extern_extract + && extern_extract.Args.Count() == 1 && extern_extract.Args[0] is LiteralExpr { Value: string overrideName } + ? overrideName : defaultValue)); + } + protected override ConcreteSyntaxTree CreateLambda(List inTypes, IToken tok, List inNames, Type resultType, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts, bool untyped = false) { if (GetExprBuilder(wr, out var builder)) { @@ -1979,7 +2116,7 @@ protected override ConcreteSyntaxTree CreateLambda(List inTypes, IToken to for (int i = 0; i < inTypes.Count; ++i) { formals.Add((DAST.Formal)DAST.Formal.create_Formal( Sequence.UnicodeFromString(inNames[i]), - GenType(inTypes[i]) + GenType(inTypes[i]), ParseAttributes(null) )); } @@ -2123,7 +2260,7 @@ protected override void EmitUnaryExpr(ResolvedUnaryOp op, Expression expr, bool } } } else { - AddUnsupported("UnaryExpr " + op + ""); + AddUnsupported("UnaryExpr " + op + " without expr container"); } } @@ -2244,6 +2381,8 @@ object C(System.Func callback Not(BinaryOp(BinOp.create_Eq(false, false), left, right))), BinaryExpr.ResolvedOpcode.SeqNeq => C((left, right) => Not(BinaryOp(BinOp.create_Eq(false, false), left, right))), + BinaryExpr.ResolvedOpcode.MapNeq => C((left, right) => + Not(BinaryOp(BinOp.create_Eq(false, false), left, right))), BinaryExpr.ResolvedOpcode.MultiSetNeq => C((left, right) => Not(BinaryOp(BinOp.create_Eq(false, false), left, right))), @@ -2529,7 +2668,7 @@ protected override void EmitMapBuilder_New(ConcreteSyntaxTree wr, MapComprehensi protected override void EmitSetBuilder_Add(CollectionType ct, string collName, Expression elmt, bool inLetExprBody, ConcreteSyntaxTree wr) { if (GetStatementBuilder(wr, out var builder)) { - var stmtBuilder = new CallStmtBuilder(); + var stmtBuilder = new CallStmtBuilder(Sequence<_IFormal>.Empty); stmtBuilder.SetName((DAST.CallName)DAST.CallName.create_SetBuilderAdd()); stmtBuilder.SetTypeArgs(new List { }); stmtBuilder.SetOuts(new List> { }); ; @@ -2549,6 +2688,12 @@ private DAST.Expression ConvertExpression(Expression term, ConcreteSyntaxTree wS return buffer0.Finish(); } + private DAST.Expression ConvertExpressionNoStatement(Expression term) { + var statementBuf = new NoStatementBuffer(); + var sNoStmt = new BuilderSyntaxTree(statementBuf, this); + return ConvertExpression(term, sNoStmt); + } + private BuilderSyntaxTree CreateExprBuilder() { var exprBuffer = new ExprBuffer(null); var exprBuilder = new BuilderSyntaxTree(exprBuffer, this); @@ -2558,7 +2703,7 @@ private BuilderSyntaxTree CreateExprBuilder() { protected override ConcreteSyntaxTree EmitMapBuilder_Add(MapType mt, IToken tok, string collName, Expression term, bool inLetExprBody, ConcreteSyntaxTree wr) { if (GetStatementBuilder(wr, out var builder)) { - var stmtBuilder = new CallStmtBuilder(); + var stmtBuilder = new CallStmtBuilder(Sequence<_IFormal>.Empty); stmtBuilder.SetName((DAST.CallName)DAST.CallName.create_MapBuilderAdd()); stmtBuilder.SetTypeArgs(new List { }); stmtBuilder.SetOuts(new List> { }); ; @@ -2634,7 +2779,7 @@ protected override Action GetSubtypeCondition(string tmpVarN protected override void GetCollectionBuilder_Build(CollectionType ct, IToken tok, string collName, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmt) { if (GetExprBuilder(wr, out var builder)) { - var callExpr = new CallExprBuilder(); + var callExpr = new CallExprBuilder(Sequence<_IFormal>.Empty); if (ct.IsMapType) { callExpr.SetName((DAST.CallName)DAST.CallName.create_MapBuilderBuild()); } else { @@ -2689,6 +2834,10 @@ protected override void EmitHaltRecoveryStmt(Statement body, string haltMessageV AddUnsupported("EmitHaltRecoveryStmt"); } + protected override ConcreteSyntaxTree GetNullClassConcreteSyntaxTree() { + return new BuilderSyntaxTree(new StatementBuffer(), this); + } + protected override void EmitNestedMatchExpr(NestedMatchExpr match, bool inLetExprBody, ConcreteSyntaxTree output, ConcreteSyntaxTree wStmts) { EmitExpr(match.Flattened, inLetExprBody, output, wStmts); diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy index 8ec52648d..9e5877cf3 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-coverage.dfy @@ -12,39 +12,33 @@ module DafnyToRustCompilerCoverage { { } + function ConversionNum(t: Type, x: Expr): Expr { + Call( + MemberSelect( + MemberSelect( + Identifier(""), + "dafny_runtime"), + "truncate!"), + [x, ExprFromType(t)]) + } + + function DafnyIntLiteral(s: string): Expr { + Call(MemberSelect(dafny_runtime, "int!"), [LiteralInt("1")]) + } + method TestOptimizeToString() { var x := Identifier("x"); var y := Identifier("y"); - AssertCoverage(UnaryOp("&", Call(Select(x, "clone"), [], []), UnaryOpFormat.NoFormat).Optimize() + AssertCoverage(UnaryOp("&", Call(Select(x, "clone"), []), UnaryOpFormat.NoFormat).Optimize() == UnaryOp("&", x, UnaryOpFormat.NoFormat)); - TestNoOptimize(UnaryOp("&", Call(Select(x, "clone"), [], [y]), UnaryOpFormat.NoFormat)); + TestNoOptimize(UnaryOp("&", Call(Select(x, "clone"), [y]), UnaryOpFormat.NoFormat)); AssertCoverage(UnaryOp("!", BinaryOp("==", x, y, BinaryOpFormat.NoFormat), CombineFormat()).Optimize() == BinaryOp("!=", x, y, BinaryOpFormat.NoFormat)); AssertCoverage(UnaryOp("!", BinaryOp("<", x, y, BinaryOpFormat.NoFormat), CombineFormat()).Optimize() == BinaryOp(">=", x, y, BinaryOpFormat.NoFormat())); AssertCoverage(UnaryOp("!", BinaryOp("<", x, y, ReverseFormat()), CombineFormat()).Optimize() == BinaryOp("<=", y, x, BinaryOpFormat.NoFormat())); - AssertCoverage( - ConversionNum( - I128, - Call(MemberSelect( - MemberSelect(MemberSelect( - Identifier(""), - "dafny_runtime"), "DafnyInt"), "from"), [], [LiteralInt("1")])).Optimize() - == LiteralInt("/*optimized*/1")); - AssertCoverage( - ConversionNum( - I128, - Call(MemberSelect( - MemberSelect(MemberSelect( - Identifier(""), "dafny_runtime"), "DafnyInt"), "from"), [], [LiteralString("1", false)])).Optimize() - == LiteralInt("/*optimized*/1")); - TestNoOptimize(ConversionNum(I128, Call(MemberSelect( - MemberSelect(MemberSelect( - Identifier(""), "dafny_runtime"), "DafnyInt"), "from"), [], [x])).Optimize()); - TestNoOptimize(ConversionNum(I128, Call(MemberSelect( - MemberSelect(MemberSelect( - Identifier(""), "dafny_runtime"), "DafnyInt"), "from"), [], [LiteralInt("1"), LiteralInt("2")])).Optimize()); + AssertCoverage(ConversionNum(I128, DafnyIntLiteral("1")).Optimize() == LiteralInt("1")); TestNoOptimize(ConversionNum(I128, x)); AssertCoverage(StmtExpr(DeclareVar(MUT, "z", Some(I128), None), StmtExpr(AssignVar("z", y), RawExpr("return"))).Optimize() == StmtExpr(DeclareVar(MUT, "z", Some(I128), Some(y)), RawExpr("return"))); @@ -53,14 +47,14 @@ module DafnyToRustCompilerCoverage { TestNoOptimize(x); TestNoOptimize(StmtExpr(x, x)); TestNoOptimize(StmtExpr(Match(x, []), x)); - TestNoOptimize(StmtExpr(StructBuild("x", []), x)); + TestNoOptimize(StmtExpr(StructBuild(x, []), x)); TestNoOptimize(StmtExpr(Tuple([]), x)); TestNoOptimize(StmtExpr(UnaryOp("&", x, UnaryOpFormat.NoFormat), x)); TestNoOptimize(StmtExpr(BinaryOp("&&", x, x, BinaryOpFormat.NoFormat), x)); TestNoOptimize(StmtExpr(TypeAscription(x, I128), x)); TestNoOptimize(StmtExpr(LiteralInt("1"), x)); - TestNoOptimize(StmtExpr(LiteralString("1", true), x)); - TestNoOptimize(StmtExpr(ConversionNum(I128, x), x)); + TestNoOptimize(StmtExpr(LiteralString("2", true, false), x)); + TestNoOptimize(StmtExpr(LiteralString("3", false, true), x)); AssertCoverage(StmtExpr(DeclareVar(MUT, "z", Some(I128), None), StmtExpr(AssignVar("z", y), RawExpr("return"))).Optimize() == StmtExpr(DeclareVar(MUT, "z", Some(I128), Some(y)), RawExpr("return"))); @@ -70,17 +64,15 @@ module DafnyToRustCompilerCoverage { Match(Identifier("x"), [MatchCase(RawPattern("abc"), Identifier("x"))]), StmtExpr(RawExpr("panic!()"), Identifier("a")), Block(RawExpr("abc")), - StructBuild("dummy", [AssignIdentifier("foo", Identifier("bar"))]), - StructBuild("dummy", [AssignIdentifier("foo", Identifier("bar")), AssignIdentifier("foo2", Identifier("bar"))]), + StructBuild(Identifier("dummy"), [AssignIdentifier("foo", Identifier("bar"))]), + StructBuild(Identifier("dummy"), [AssignIdentifier("foo", Identifier("bar")), AssignIdentifier("foo2", Identifier("bar"))]), Tuple([Identifier("x")]), UnaryOp("-", Identifier("x"), UnaryOpFormat.NoFormat), BinaryOp("+", Identifier("x"), Identifier("y"), BinaryOpFormat.NoFormat), TypeAscription(Identifier("x"), I128), LiteralInt("322"), - LiteralString("abc", true), - LiteralString("abc", false), - ConversionNum(I128, Identifier("x")), - ConversionNum(RawType("X"), Identifier("x")), + LiteralString("abc", true, false), + LiteralString("abc", false, true), DeclareVar(MUT, "abc", Some(I128), None), DeclareVar(CONST, "abc", None, Some(Identifier("x"))), AssignVar("abc", Identifier("x")), @@ -94,8 +86,9 @@ module DafnyToRustCompilerCoverage { Continue(Some("l")), Return(None), Return(Some(Identifier("x"))), - Call(Identifier("x"), [], []), - Call(Identifier("x"), [I128, I32], [Identifier("x"), Identifier("y")]), + Call(Identifier("x"), []), + Call(Identifier("x"), [Identifier("x"), Identifier("y")]), + CallType(Identifier("x"), [I128, U32]), Select(Identifier("x"), "abc"), MemberSelect(Identifier("x"), "abc") ]; @@ -109,13 +102,10 @@ module DafnyToRustCompilerCoverage { var _ := UnaryOp("&", c, UnaryOpFormat.NoFormat()).Optimize(); var _ := UnaryOp("!", c, UnaryOpFormat.NoFormat()).Optimize(); var _ := ConversionNum(U8, c).Optimize(); - var _ := ConversionNum(U8, Call(c, [], [])).Optimize(); - var _ := ConversionNum(U8, Call(MemberSelect(c, "from"), [], [])).Optimize(); - var _ := ConversionNum(U8, Call(MemberSelect(MemberSelect(c, "DafnyInt"), "from"), [], [])).Optimize(); - var _ := ConversionNum(U8, Call(MemberSelect(MemberSelect(MemberSelect(c, "dafny_runtime"), "DafnyInt"), "from"), [], [])).Optimize(); - var _ := ConversionNum(U8, Call(MemberSelect( - MemberSelect(MemberSelect( - Identifier(""), "dafny_runtime"), "DafnyInt"), "from"), [], [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(); } @@ -128,7 +118,7 @@ module DafnyToRustCompilerCoverage { AssertCoverage(RawExpr("x").printingInfo.UnknownPrecedence?); AssertCoverage(x.printingInfo == Precedence(1)); AssertCoverage(LiteralInt("3").printingInfo == Precedence(1)); - AssertCoverage(LiteralString("abc", true).printingInfo == Precedence(1)); + AssertCoverage(LiteralString("abc", true, false).printingInfo == Precedence(1)); AssertCoverage(UnaryOp("?", x, UnaryOpFormat.NoFormat).printingInfo == SuffixPrecedence(5)); AssertCoverage(UnaryOp("-", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); AssertCoverage(UnaryOp("*", x, UnaryOpFormat.NoFormat).printingInfo == Precedence(6)); @@ -138,7 +128,7 @@ module DafnyToRustCompilerCoverage { AssertCoverage(UnaryOp("!!", x, UnaryOpFormat.NoFormat).printingInfo == UnknownPrecedence()); AssertCoverage(Select(x, "name").printingInfo == PrecedenceAssociativity(2, LeftToRight)); AssertCoverage(MemberSelect(x, "name").printingInfo == PrecedenceAssociativity(2, LeftToRight)); - AssertCoverage(Call(x, [], []).printingInfo == PrecedenceAssociativity(2, LeftToRight)); + AssertCoverage(Call(x, []).printingInfo == PrecedenceAssociativity(2, LeftToRight)); AssertCoverage(TypeAscription(x, I128).printingInfo == PrecedenceAssociativity(10, LeftToRight)); AssertCoverage(BinaryOp("*", x, y, bnf).printingInfo == PrecedenceAssociativity(20, LeftToRight)); AssertCoverage(BinaryOp("/", x, y, bnf).printingInfo == PrecedenceAssociativity(20, LeftToRight)); diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index e123f42d2..22e57c671 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -11,6 +11,11 @@ module RAST import opened DAST.Format import Strings = Std.Strings + // Rust tuples support some traits like Default only till arity 12 + // Past that, we use Dafny system tuples (see https://www.reddit.com/r/rust/comments/11gvkda/why_rust_std_only_provides_trait_implementation/) + const MAX_TUPLE_SIZE := 12 + + // Default Indentation const IND := " " datatype Mod = @@ -23,13 +28,13 @@ module RAST { match this { case ExternMod(name) => - "mod " + name + ";" + "pub mod " + name + ";" case Mod(name, body) => - "mod " + name + " {" + "\n" + ind + IND + + "pub mod " + name + " {" + "\n" + ind + IND + SeqToString( body, (modDecl: ModDecl) requires modDecl < this => - modDecl.ToString(ind + IND), "\n" + ind + IND) + modDecl.ToString(ind + IND), "\n\n" + ind + IND) + "\n" + ind + "}" } } @@ -40,15 +45,6 @@ module RAST if |s| == 0 then "" else f(s[0]) + (if |s| > 1 then separator + SeqToString(s[1..], f, separator) else "") } - function SeqToHeight(s: seq, f: T --> nat): (r: nat) - requires forall t <- s :: f.requires(t) - ensures forall t <- s :: f(t) <= r - { - if |s| == 0 then 0 else - var i := f(s[0]); - var j := SeqToHeight(s[1..], f); - if i < j then j else i - } datatype ModDecl = | RawDecl(body: string) | ModDecl(mod: Mod) @@ -78,31 +74,46 @@ module RAST datatype Struct = Struct(attributes: seq, - name: string, typeParams: seq, fields: Formals) + name: string, typeParams: seq, fields: Fields) { function ToString(ind: string): string { Attribute.ToStringMultiple(attributes, ind) + "pub struct " + name + - TypeParam.ToStringMultiple(typeParams, ind) + - fields.ToString(ind + IND, fields.NamedFormals?) + - (if fields.NamelessFormals? then ";" else "") + TypeParamDecl.ToStringMultiple(typeParams, ind) + + fields.ToString(ind, fields.NamedFields?) + + (if fields.NamelessFields? then ";" else "") } } - datatype NamelessFormal = - NamelessFormal(visibility: Visibility, tpe: Type) + datatype NamelessField = + NamelessField(visibility: Visibility, tpe: Type) { function ToString(ind: string): string { - (if visibility == PUB then "pub " else "") + tpe.ToString(ind) + visibility.ToString() + tpe.ToString(ind) } } - datatype Formals = - | NamedFormals(fields: seq) - | NamelessFormals(types: seq) + datatype Field = Field(visibility: Visibility, formal: Formal) { + function ToString(ind: string): string { + visibility.ToString() + formal.ToString(ind) + } + function ToNamelessField(): NamelessField { + NamelessField(visibility, formal.tpe) + } + } + + datatype Fields = + | NamedFields(fields: seq) + | NamelessFields(types: seq) + { + function ToNamelessFields(): Fields + requires NamedFields? + { + NamelessFields(seq(|fields|, i requires 0 <= i < |fields| => fields[i].ToNamelessField())) + } function ToString(ind: string, newLine: bool): string { - if NamedFormals? then + if NamedFields? then var separator := if newLine then ",\n" + ind + IND else ", "; var (beginSpace, endSpace) := if newLine && |fields| > 0 then @@ -112,19 +123,19 @@ module RAST else ("", ""); " {" + beginSpace + - SeqToString(fields, (field: Formal) => field.ToString(ind + IND), separator) + SeqToString(fields, (field: Field) => field.ToString(ind + IND), separator) + endSpace + "}" else - assert NamelessFormals?; + assert NamelessFields?; var separator := if newLine then ",\n" + ind + IND else ", "; "("+ - SeqToString(types, (t: NamelessFormal) => t.ToString(ind + IND), separator) + SeqToString(types, (t: NamelessField) => t.ToString(ind + IND), separator) +")" } } datatype EnumCase = - | EnumCase(name: string, fields: Formals) + | EnumCase(name: string, fields: Fields) { function ToString(ind: string, newLine: bool): string { name + fields.ToString(ind, newLine) @@ -133,39 +144,39 @@ module RAST datatype Enum = Enum(attributes: seq, - name: string, typeParams: seq, + name: string, typeParams: seq, variants: seq) { function ToString(ind: string): string { Attribute.ToStringMultiple(attributes, ind) + "pub enum " + name + - TypeParam.ToStringMultiple(typeParams, ind) + TypeParamDecl.ToStringMultiple(typeParams, ind) + " {" + SeqToString( variants, (variant: EnumCase) => - "\n" + ind + IND + variant.ToString(ind + IND, false), ",") + + "\n" + ind + IND + variant.ToString(ind + IND, true), ",") + "\n" + ind + "}" } } type TypeParamConstraint = Type - datatype TypeParam = - | RawTypeParam(content: string, constraints: seq) + datatype TypeParamDecl = + | TypeParamDecl(content: string, constraints: seq) { - static function ToStringMultiple(typeParams: seq, ind: string): string { + static function ToStringMultiple(typeParams: seq, ind: string): string { if |typeParams| == 0 then "" else - "<" + SeqToString(typeParams, (t: TypeParam) => t.ToString(ind + IND), ", ") + ">" + "<" + SeqToString(typeParams, (t: TypeParamDecl) => t.ToString(ind + IND), ", ") + ">" } static function {:tailrecursion true} AddConstraintsMultiple( - typeParams: seq, constraints: seq - ): seq { + typeParams: seq, constraints: seq + ): seq { if |typeParams| == 0 then [] else [typeParams[0].AddConstraints(constraints)] + AddConstraintsMultiple(typeParams[1..], constraints) } - function AddConstraints(constraints: seq): TypeParam { + function AddConstraints(constraints: seq): TypeParamDecl { this.(constraints := this.constraints + constraints) } function ToString(ind: string): string { @@ -177,8 +188,10 @@ module RAST t.ToString(ind + IND), " + ")) } } - const Self := Borrowed(SelfOwned) - const SelfMut := BorrowedMut(SelfOwned) + const SelfBorrowed := Borrowed(SelfOwned) + + const SelfBorrowedMut := BorrowedMut(SelfOwned) + function Rc(underlying: Type): Type { TypeApp(std_type.MSel("rc").MSel("Rc"), [underlying]) } @@ -189,10 +202,10 @@ module RAST TypeApp(std_type.MSel("vec").MSel("Vec"), [underlying]) } function NewVec(elements: seq): Expr { - Call(Identifier("vec!"), [], elements) + Identifier("vec!").Apply(elements) } function Clone(underlying: Expr): Expr { - Call(Select(underlying, "clone"), [], []) + Select(underlying, "clone").Apply([]) } function Borrow(underlying: Expr): Expr { UnaryOp("&", underlying, UnaryOpFormat.NoFormat) @@ -201,18 +214,21 @@ module RAST UnaryOp("&mut", underlying, UnaryOpFormat.NoFormat) } - const CloneTrait := RawType("Clone") - const DafnyPrintTrait := RawType("::dafny_runtime::DafnyPrint") - const DefaultTrait := RawType("::std::default::Default") - const StaticTrait := RawType("'static") - function RawType(content: string): Type { TIdentifier(content) } + function Box(content: Type): Type { + TypeApp(TIdentifier("Box"), [content]) + } + function BoxNew(content: Expr): Expr { + Identifier("Box").MSel("new").Apply([content]) + } + datatype Type = | SelfOwned | U8 | U16 | U32 | U64 | U128 | I8 | I16 | I32 | I64 | I128 + | Bool | TIdentifier(name: string) | TMemberSelect(base: Type, name: string) | TypeApp(baseName: Type, arguments: seq) @@ -224,8 +240,12 @@ module RAST | FnType(arguments: seq, returnType: Type) | IntersectionType(left: Type, right: Type) { + predicate CanReadWithoutClone() { + U8? || U16? || U32? || U64? || U128? || I8? || I16? || I32? || I64? || I128? || Bool? + } function ToString(ind: string): string { match this { + case Bool() => "bool" case TIdentifier(underlying) => underlying case TMemberSelect(underlying, name) => underlying.ToString(ind) + "::" + name case Borrowed(underlying) => "&" + underlying.ToString(ind) @@ -276,19 +296,68 @@ module RAST function Apply1(arg: Type): Type { TypeApp(this, [arg]) } + + function Apply(args: seq): Type { + TypeApp(this, args) + } + + function ToOwned(): Type { + match this { + case Borrowed(x) => x + case BorrowedMut(x) => x + case x => x + } + } + } + + predicate IsImmutableConversion(fromTpe: Type, toTpe: Type) { + match (fromTpe, toTpe) { + case (TypeApp(TMemberSelect(TMemberSelect(TIdentifier(""), "dafny_runtime"), tpe1), elems1), + TypeApp(TMemberSelect(TMemberSelect(TIdentifier(""), "dafny_runtime"), tpe2), elems2)) + => + tpe1 == tpe2 && ( + tpe1 == "Set" || tpe1 == "Sequence" || tpe1 == "Multiset" || tpe1 == "Map" + ) + case _ => + false + } + } + + function SystemTupleType(elements: seq): Type { + super_type.MSel("_System").MSel("Tuple" + Strings.OfNat(|elements|)).Apply(elements) } const global_type := TIdentifier("") - const std_type := global_type.MSel("std") + 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 := global_type.MSel("dafny_runtime") + const dafny_runtime_type: Type := global_type.MSel("dafny_runtime") + const CloneTrait := RawType("Clone") + const DefaultTrait := std_type.MSel("default").MSel("Default") + 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 DafnyInt := dafny_runtime_type.MSel("DafnyInt") + + const super := Identifier("super") + + function SystemTuple(elements: seq): Expr { + var size := Strings.OfNat(|elements|); + StructBuild(super.MSel("_System").MSel("Tuple" + size).MSel("_T" + size), + seq(|elements|, i requires 0 <= i < |elements| => + AssignIdentifier("_" + Strings.OfNat(i), elements[i]) + ) + ) + } datatype Trait = - | Trait(typeParams: seq, tpe: Type, where: string, body: seq) + | Trait(typeParams: seq, tpe: Type, where: string, body: seq) { function ToString(ind: string): string { - "trait " + TypeParam.ToStringMultiple(typeParams, ind) + tpe.ToString(ind) + "pub trait " + TypeParamDecl.ToStringMultiple(typeParams, ind) + tpe.ToString(ind) + (if where != "" then "\n" + ind + IND + where else "") + " {" + SeqToString(body, (member: ImplMember) => "\n" + ind + IND + member.ToString(ind + IND), "") @@ -297,12 +366,12 @@ module RAST } datatype Impl = - | ImplFor(typeParams: seq, tpe: Type, forType: Type, where: string, body: seq) - | Impl(typeParams: seq, tpe: Type, where: string, body: seq) + | ImplFor(typeParams: seq, tpe: Type, forType: Type, where: string, body: seq) + | Impl(typeParams: seq, tpe: Type, where: string, body: seq) { function ToString(ind: string): string { - "impl " + TypeParam.ToStringMultiple(typeParams, ind) + tpe.ToString(ind) - + (if ImplFor? then " for " + forType.ToString(ind + IND) else "") + "impl" + TypeParamDecl.ToStringMultiple(typeParams, ind) + " " + tpe.ToString(ind) + + (if ImplFor? then "\n" + ind + IND + "for " + forType.ToString(ind + IND) else "") + (if where != "" then "\n" + ind + IND + where else "") + " {" + SeqToString(body, (member: ImplMember) => "\n" + ind + IND + member.ToString(ind + IND), "") @@ -314,26 +383,29 @@ module RAST | FnDecl(pub: Visibility, fun: Fn) { function ToString(ind: string): string { - if FnDecl? then - (if pub == PUB then "pub " else "") + fun.ToString(ind) + if FnDecl? then pub.ToString() + fun.ToString(ind) else assert RawImplMember?; content } } - datatype Visibility = PUB | PRIV + datatype Visibility = PUB | PRIV { + function ToString(): string { + if PUB? then "pub " else "" + } + } datatype Formal = Formal(name: string, tpe: Type) { function ToString(ind: string): string { - if name == "self" && tpe.SelfOwned? then name - else if name == "&self" && tpe == Borrowed(SelfOwned) then name - else if name == "&mut self" && tpe == Borrowed(SelfMut) then name + if name == "self" && tpe == SelfOwned then name + else if name == "self" && tpe == SelfBorrowed then "&" + name + else if name == "self" && tpe == SelfBorrowedMut then "&mut " + name else name + ": " + tpe.ToString(ind) } - static const self := Formal("&self", Self) + static const selfBorrowed := Formal("self", SelfBorrowed) static const selfOwned := Formal("self", SelfOwned) - static const selfMut := Formal("&mut self", SelfMut) + static const selfBorrowedMut := Formal("self", SelfBorrowedMut) } datatype Pattern = @@ -439,45 +511,63 @@ module RAST } } + function AssignVar(name: string, rhs: Expr): Expr { + Expr.Assign(Some(LocalVar(name)), rhs) + } + + function AssignMember(on: Expr, field: string, rhs: Expr): Expr { + Expr.Assign(Some(SelectMember(on, field)), rhs) + } + + datatype AssignLhs = + LocalVar(name: string) | + SelectMember(on: Expr, field: string) | + ExtractTuple(names: seq) | + Index(expr: Expr, indices: seq) datatype Expr = RawExpr(content: string) + | ExprFromType(tpe: Type) | Identifier(name: string) // Can be empty for global in MemberSelect | Match(matchee: Expr, cases: seq) | StmtExpr(stmt: Expr, rhs: Expr) | Block(underlying: Expr) - | StructBuild(name: string, assignments: seq) + | StructBuild(underlying: Expr, assignments: seq) | Tuple(arguments: seq) | UnaryOp(op1: string, underlying: Expr, format: Format.UnaryOpFormat) | BinaryOp(op2: string, left: Expr, right: Expr, format2: Format.BinaryOpFormat) - | TypeAscription(left: Expr, tpe: Type) + | TypeAscription(left: Expr, tpe: Type) // underlying as tpe | LiteralInt(value: string) - | LiteralString(value: string, binary: bool) - | ConversionNum(tpe: Type, underlying: Expr) - | DeclareVar(declareType: DeclareType, name: string, optType: Option, optRhs: Option) - | AssignVar(name: string, rhs: Expr) - | IfExpr(cond: Expr, thn: Expr, els: Expr) - | Loop(optCond: Option, underlying: Expr) - | For(name: string, range: Expr, body: Expr) - | Labelled(lbl: string, underlying: Expr) - | Break(optLbl: Option) - | Continue(optLbl: Option) - | Return(optExpr: Option) - | Call(obj: Expr, typeParameters: seq, arguments: seq) - | Select(obj: Expr, name: string) - | MemberSelect(obj: Expr, name: string) + | LiteralBool(bvalue: bool) + | LiteralString(value: string, binary: bool, verbatim: bool) + | DeclareVar(declareType: DeclareType, name: string, optType: Option, optRhs: Option) // let mut name: optType = optRhs; + | Assign(names: Option, rhs: Expr) // name1, name2 = rhs; + | IfExpr(cond: Expr, thn: Expr, els: Expr) // if cond { thn } else { els } + | Loop(optCond: Option, underlying: Expr) // loop { body } + | For(name: string, range: Expr, body: Expr) // for name in range { body } + | Labelled(lbl: string, underlying: Expr) // label lbl { expr } + | Break(optLbl: Option) // break lbl; + | Continue(optLbl: Option) // continue optLabel; + | Return(optExpr: Option) // return optExpr; + | CallType(obj: Expr, typeParameters: seq) // obj::<...type parameters> + | Call(obj: Expr, arguments: seq) // obj(...arguments) + | Select(obj: Expr, name: string) // obj.name + | MemberSelect(obj: Expr, name: string) // obj::name + | Lambda(params: seq, retType: Option, body: Expr) // move || -> retType { body } { predicate NoExtraSemicolonAfter() { - DeclareVar? || AssignVar? || Break? || Continue? || Return? || + DeclareVar? || Assign? || Break? || Continue? || Return? || For? || (RawExpr? && |content| > 0 && content[|content| - 1] == ';') } // Taken from https://doc.rust-lang.org/reference/expressions.html const printingInfo: PrintingInfo := match this { case RawExpr(_) => UnknownPrecedence() + case ExprFromType(_) => Precedence(1) case Identifier(_) => Precedence(1) case LiteralInt(_) => Precedence(1) - case LiteralString(_, _) => Precedence(1) + case LiteralBool(_) => Precedence(1) + case LiteralString(_, _, _) => Precedence(1) // Paths => Precedence(1) // Method call => Precedence(2) // Field expression => PrecedenceAssociativity(3, LeftToRight) @@ -490,7 +580,8 @@ module RAST } case Select(underlying, name) => PrecedenceAssociativity(2, LeftToRight) case MemberSelect(underlying, name) => PrecedenceAssociativity(2, LeftToRight) - case Call(_, _, _) => PrecedenceAssociativity(2, LeftToRight) + case CallType(_, _) => PrecedenceAssociativity(2, LeftToRight) + case Call(_, _) => PrecedenceAssociativity(2, LeftToRight) case TypeAscription(left, tpe) => PrecedenceAssociativity(10, LeftToRight) case BinaryOp(op2, left, right, format) => @@ -509,15 +600,17 @@ module RAST PrecedenceAssociativity(110, RightToLeft) case _ => PrecedenceAssociativity(0, RequiresParentheses) } + case Lambda(_, _, _) => PrecedenceAssociativity(300, LeftToRight) case _ => UnknownPrecedence() } ghost function Height(): nat { match this { case Identifier(_) => 1 + case ExprFromType(_) => 1 case LiteralInt(_) => 1 - case LiteralString(_, _) => 1 - case ConversionNum(_, underlying) => 1 + underlying.Height() + case LiteralBool(_) => 1 + case LiteralString(_, _, _) => 1 case Match(matchee, cases) => 1 + max(matchee.Height(), SeqToHeight(cases, (oneCase: MatchCase) @@ -526,19 +619,21 @@ module RAST case StmtExpr(stmt, rhs) => var default := 1 + max(stmt.Height(), rhs.Height()); match this { - case StmtExpr(DeclareVar(mod, name, Some(tpe), None), StmtExpr(AssignVar(name2, rhs), last)) => - if name == name2 then + case StmtExpr(DeclareVar(mod, name, Some(tpe), None), StmtExpr(Assign(name2, rhs), last)) => + if name2 == Some(LocalVar(name)) then 1 + default else default + case StmtExpr(IfExpr(UnaryOp("!", BinaryOp("==", a, b, f), of), RawExpr("panic!(\"Halt\");"), RawExpr("")), last) => + 1 + default case _ => default } case Block(underlying) => 1 + underlying.Height() case StructBuild(name, assignments) => - 1 + SeqToHeight(assignments, (assignment: AssignIdentifier) - requires assignment < this - => assignment.Height()) + 1 + max(name.Height(), SeqToHeight(assignments, (assignment: AssignIdentifier) + requires assignment < this + => assignment.Height())) case Tuple(arguments) => 1 + SeqToHeight(arguments, (argument: Expr) requires argument < this @@ -555,8 +650,12 @@ module RAST case Some(e) => e.Height() case None => 0 }) - case AssignVar(name, expr) => - 1 + expr.Height() + case Assign(names, expr) => + match names { + case Some(SelectMember(on, field)) => 1 + max(on.Height(), expr.Height()) + case Some(Index(arr, indices)) => 1 + max(expr.Height(), max(arr.Height(), SeqToHeight(indices, (index: Expr) requires index < this => index.Height()))) + case _ => 1 + expr.Height() + } case Loop(optCond, underlying) => 1 + if optCond.Some? then max(optCond.value.Height(), underlying.Height()) else underlying.Height() case Labelled(lbl, underlying) => @@ -567,14 +666,18 @@ module RAST 1 + max(range.Height(), body.Height()) case Return(optExpr) => if optExpr.Some? then 1 + optExpr.value.Height() else 1 - case Call(obj, tpes, args) => + case CallType(obj, tpes) => + 1 + max(obj.Height(), + SeqToHeight(tpes, (tpe: Type) requires tpe < this => 1)) + case Call(obj, args) => 1 + max(obj.Height(), - max(SeqToHeight(tpes, (tpe: Type) requires tpe < this => 1), - SeqToHeight(args, (arg: Expr) requires arg < this => arg.Height()))) + SeqToHeight(args, (arg: Expr) requires arg < this => arg.Height())) case Select(expression, name) => 1 + expression.Height() case MemberSelect(expression, name) => 1 + expression.Height() + case Lambda(params, retType, body) => + 1 + body.Height() case _ => assert RawExpr?; 1 @@ -587,10 +690,10 @@ module RAST ensures this == r || r.Height() < this.Height() { match this { - case UnaryOp("&", Call(Select(underlying, "clone"), typeArgs, args), format) => - if typeArgs == [] && args == [] then + case UnaryOp("&", Call(Select(underlying, "clone"), args), format) => + if args == [] then assert Select(underlying, "clone").Height() == 1 + underlying.Height(); - assert Call(Select(underlying, "clone"), typeArgs, args).Height() == 2 + underlying.Height(); + assert Call(Select(underlying, "clone"), args).Height() == 2 + underlying.Height(); assert UnaryOp("&", underlying, format).Height() == 1 + underlying.Height(); UnaryOp("&", underlying, format) else @@ -613,31 +716,36 @@ module RAST assert BinaryOp("<=", right, left, BinaryOpFormat.NoFormat()).Height() == BinaryOp("<", left, right, BinaryOpFormat.ReverseFormat()).Height(); BinaryOp("<=", right, left, BinaryOpFormat.NoFormat()) - - case ConversionNum(tpe, expr) => - 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( - MemberSelect(MemberSelect( - Identifier(""), "dafny_runtime"), "DafnyInt"), "from"), tpe, args) => - if |tpe| == 0 && |args| == 1 then - match args[0] { - case LiteralInt(number) => LiteralInt("/*optimized*/"+number) - case LiteralString(number, _) => LiteralInt("/*optimized*/"+number) - case _ => this - } - else this - case _ => this - } - else + case Call(MemberSelect(r, "truncate!"), args) => + if (r != dafny_runtime && r != global) || |args| != 2 then this - case StmtExpr(DeclareVar(mod, name, Some(tpe), None), StmtExpr(AssignVar(name2, rhs), last)) => - if name == name2 then + else + var expr := args[0]; + var tpeExpr := args[1]; + if !tpeExpr.ExprFromType? then this else + var tpe := tpeExpr.tpe; + if || tpe.U8? || tpe.U16? || tpe.U32? || tpe.U64? || tpe.U128? + || tpe.I8? || tpe.I16? || tpe.I32? || tpe.I64? || tpe.I128? then + match expr { + case Call( + MemberSelect(base, "int!"), args) => + if |args| == 1 && (base == dafny_runtime || base == global) then + match args[0] { + case LiteralInt(number) => LiteralInt(number) + case LiteralString(number, _, _) => LiteralInt(number) + case _ => this + } + else this + case _ => this + } + else + this + case StmtExpr(DeclareVar(mod, name, Some(tpe), None), StmtExpr(Assign(name2, rhs), last)) => + if name2 == Some(LocalVar(name)) then var rewriting := StmtExpr(DeclareVar(mod, name, Some(tpe), Some(rhs)), last); assert rewriting.Height() < this.Height() by { - assert StmtExpr(AssignVar(name2, rhs), last).Height() == - 1 + max(AssignVar(name2, rhs).Height(), last.Height()) == + assert StmtExpr(Assign(name2, rhs), last).Height() == + 1 + max(Assign(name2, rhs).Height(), last.Height()) == 1 + max(1 + rhs.Height(), last.Height()); assert this.Height() == 2 + max(1, 1 + max(1 + rhs.Height(), last.Height())); assert rewriting.Height() == 1 + max(1 + rhs.Height(), last.Height()); @@ -645,6 +753,10 @@ module RAST rewriting else this + case StmtExpr(IfExpr(UnaryOp("!", BinaryOp("==", a, b, f), of), RawExpr("panic!(\"Halt\");"), RawExpr("")), last) => + var rewriting := StmtExpr(Identifier("assert_eq!").Apply([a, b]), last); + assume {:axiom} rewriting.Height() < this.Height(); // TODO: Need to prove formally + rewriting case _ => this } } @@ -678,28 +790,37 @@ module RAST } } + static function MaxHashes(s: string, currentHashes: string, mostHashes: string): string { + if |s| == 0 then if |currentHashes| < |mostHashes| then mostHashes else currentHashes else + if s[0..1] == "#" then MaxHashes(s[1..], currentHashes + "#", mostHashes) + else MaxHashes(s[1..], "", if |currentHashes| < |mostHashes| then mostHashes else currentHashes) + } + + static function RemoveDoubleQuotes(s: string): string { + if |s| <= 1 then s else + if s[0..2] == @"""""" then @"""" + RemoveDoubleQuotes(s[2..]) else + s[0..1] + RemoveDoubleQuotes(s[1..]) + } + function ToString(ind: string): string decreases Height() { match this.Optimize() { case Identifier(name) => name + case ExprFromType(t) => t.ToString(ind) case LiteralInt(number) => number - case LiteralString(characters, binary) => - (if binary then "b" else "") + - "\"" + characters + "\"" - case ConversionNum(tpe, expr) => - if || tpe.U8? || tpe.U16? || tpe.U32? || tpe.U64? || tpe.U128? - || tpe.I8? || tpe.I16? || tpe.I32? || tpe.I64? || tpe.I128? then - "num::ToPrimitive::to_"+tpe.ToString(ind)+"(" + expr.ToString(ind) + ").unwrap()" - else - "Unsupported: Numeric conversion to " + tpe.ToString(ind) + "" + case LiteralBool(b) => if b then "true" else "false" + case LiteralString(characters, binary, verbatim) => + var hashes := if verbatim then MaxHashes(characters, "", "") + "#" else ""; + (if binary then "b" else "") + (if verbatim then "r" + hashes else "") + + "\"" + (if verbatim then RemoveDoubleQuotes(characters) else characters) + "\"" + hashes case Match(matchee, cases) => "match " + matchee.ToString(ind + IND) + " {" + SeqToString(cases, (c: MatchCase) requires c.Height() < this.Height() => - "\n" + ind + IND + c.ToString(ind + IND), ",") + + "\n" + ind + IND + c.ToString(ind + IND) + ",", "") + "\n" + ind + "}" - case StmtExpr(stmt, rhs) => // They are built like StmtExpr(StmtExpr(StmtExpr(..., 1), 2), 3...) + case StmtExpr(stmt, rhs) => // They are built like StmtExpr(1, StmtExpr(2, StmtExpr(3, ...))) if stmt.RawExpr? && stmt.content == "" then rhs.ToString(ind) else stmt.ToString(ind) + (if stmt.NoExtraSemicolonAfter() then "" else ";") + "\n" + ind + rhs.ToString(ind) @@ -707,14 +828,25 @@ module RAST "{\n" + ind + IND + underlying.ToString(ind + IND) + "\n" + ind + "}" case IfExpr(cond, thn, els) => "if " + cond.ToString(ind + IND) + " {\n" + ind + IND + thn.ToString(ind + IND) + - "\n" + ind + "} else {\n" + ind + IND + els.ToString(ind + IND) + "\n" + ind + "}" + "\n" + ind + "}" + + if els == RawExpr("") then "" else + " else {\n" + ind + IND + els.ToString(ind + IND) + "\n" + ind + "}" case StructBuild(name, assignments) => - name + " {" + - SeqToString(assignments, (assignment: AssignIdentifier) - requires assignment.Height() < this.Height() - => - "\n" + ind + IND + assignment.ToString(ind + IND), ",") + - (if |assignments| > 0 then "\n" + ind else "") + "}" + if |assignments| > 0 && assignments[0].identifier == "0" then + // Numeric + name.ToString(ind) + " (" + + SeqToString(assignments, (assignment: AssignIdentifier) + requires assignment.Height() < this.Height() + => + "\n" + ind + IND + assignment.rhs.ToString(ind + IND), ",") + + (if |assignments| > 1 then "\n" + ind else "") + ")" + else + name.ToString(ind) + " {" + + SeqToString(assignments, (assignment: AssignIdentifier) + requires assignment.Height() < this.Height() + => + "\n" + ind + IND + assignment.ToString(ind + IND), ",") + + (if |assignments| > 0 then "\n" + ind else "") + "}" case Tuple(arguments) => "(" + SeqToString(arguments, (arg: Expr) @@ -756,8 +888,21 @@ module RAST if optExpr.value.LiteralInt? then "Empty int literal" else "Another case" else " = " + optExprString else "") + ";" - case AssignVar(name, expr) => - name + " = " + expr.ToString(ind + IND) + ";" + case Assign(names, expr) => + var lhs := match names { + case Some(LocalVar(name)) => name + " = " + case Some(SelectMember(member, field)) => + var (leftP, rightP) := Select(member, field).LeftParentheses(member); + leftP + member.ToString(ind) + rightP + "." + field + " = " + case Some(ExtractTuple(names)) => "(" + SeqToString(names, (name: string) => name, ",") + ") = " + case Some(Index(e, indices)) => + var (leftP, rightP) := Call(e, indices).LeftParentheses(e); + leftP + e.ToString(ind) + rightP + "[" + SeqToString(indices, + (index: Expr) requires index.Height() < this.Height() => index.ToString(ind + IND), "][") + + "] = " + case None => "_ = " + }; + lhs + expr.ToString(ind + IND) + ";" case Labelled(name, underlying) => "'" + name + ": " + underlying.ToString(ind) case Break(optLbl) => @@ -780,7 +925,13 @@ module RAST body.ToString(ind + IND) + "\n" + ind + "}" case Return(optExpr) => "return" + (if optExpr.Some? then " " + optExpr.value.ToString(ind + IND) else "") + ";" - case Call(expr, tpes, args) => + case CallType(expr, tpes) => + var (leftP, rightP) := LeftParentheses(expr); + if tpes == [] then expr.ToString(ind) else + leftP + expr.ToString(ind) + rightP + "::<" + + SeqToString(tpes, (tpe: Type) => tpe.ToString(ind + IND), ", ") +">" + + case Call(expr, args) => var (leftP, rightP) := LeftParentheses(expr); var (leftCallP, rightCallP) := match expr.RightMostIdentifier() { case Some("seq!") | Some("map!") => @@ -790,17 +941,18 @@ module RAST case _ => ("(", ")") }; - leftP + expr.ToString(ind) + rightP + ( - if |tpes| == 0 then "" - else - "::<" + SeqToString(tpes, (tpe: Type) => tpe.ToString(ind + IND), ", ") +">" - ) + leftCallP + SeqToString(args, (arg: Expr) requires arg.Height() < this.Height() => arg.ToString(ind + IND), ", ")+ rightCallP + leftP + expr.ToString(ind) + rightP + + leftCallP + SeqToString(args, (arg: Expr) requires arg.Height() < this.Height() => arg.ToString(ind + IND), ", ")+ rightCallP case Select(expression, name) => var (leftP, rightP) := LeftParentheses(expression); leftP + expression.ToString(ind) + rightP + "." + name case MemberSelect(expression, name) => var (leftP, rightP) := LeftParentheses(expression); leftP + expression.ToString(ind) + rightP + "::" + name + case Lambda(params, retType, body) => + "move |" + SeqToString(params, (arg: Formal) => arg.ToString(ind), ",") + "| " + + (if retType.Some? then "-> " + retType.value.ToString(ind) + " " else "") + + body.ToString(ind) case r => assert r.RawExpr?; AddIndent(r.content, ind) } @@ -808,6 +960,8 @@ module RAST function Then(rhs2: Expr): Expr { if this.StmtExpr? then StmtExpr(stmt, rhs.Then(rhs2)) + else if this == RawExpr("") then + rhs2 else StmtExpr(this, rhs2) } @@ -820,16 +974,34 @@ module RAST function MSel(name: string): Expr { MemberSelect(this, name) } - - function Apply(typeParameters: seq, arguments: seq): Expr { - Call(this, typeParameters, arguments) + function ApplyType(typeParameters: seq): Expr { + CallType(this, typeParameters) + } + function ApplyType1(typeParameter: Type): Expr { + CallType(this, [typeParameter]) + } + function Apply(arguments: seq): Expr { + Call(this, arguments) } function Apply1(argument: Expr): Expr { - Call(this, [], [argument]) + Call(this, [argument]) + } + + predicate IsLhsIdentifier() { + this.Identifier? || + (this.Call? && this.obj == modify_macro && |this.arguments| == 1 && + this.arguments[0].Identifier?) + } + + function LhsIdentifierName(): string requires IsLhsIdentifier() { + if this.Identifier? then name + else this.arguments[0].name } } + const self := Identifier("self") + const global := Identifier("") const dafny_runtime := global.MSel("dafny_runtime") @@ -840,6 +1012,9 @@ module RAST 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") + function MaybePlacebo(underlying: Expr): Expr { + dafny_runtime.MSel("MaybePlacebo").MSel("from").Apply1(underlying) + } const std := global.MSel("std") @@ -849,18 +1024,22 @@ module RAST const std_rc_Rc_new := std_rc_Rc.MSel("new") + const std_Default_default := std.MSel("default").MSel("Default").MSel("default").Apply([]) + + const modify_macro := dafny_runtime.MSel("modify!") + function RcNew(underlying: Expr): Expr { - Call(std_rc_Rc_new, [], [underlying]) + Call(std_rc_Rc_new, [underlying]) } datatype Fn = - Fn(name: string, typeParams: seq, formals: seq, + Fn(name: string, typeParams: seq, formals: seq, returnType: Option, where: string, body: Option) { function ToString(ind: string): string { - "fn " + name + TypeParam.ToStringMultiple(typeParams, ind) + + "fn " + name + TypeParamDecl.ToStringMultiple(typeParams, ind) + "(" + SeqToString(formals, (formal: Formal) => formal.ToString(ind), ", ") + ")" + (match returnType case Some(t) => " -> " + t.ToString(ind) case _ => "") + (if where == "" then "" else "\n" + ind + IND + where) + @@ -885,6 +1064,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { type Type = DAST.Type type Formal = DAST.Formal + const AttributeOwned := Attribute("owned", []) + // List taken from https://doc.rust-lang.org/book/appendix-01-keywords.html const reserved_rust := { "as","async","await","break","const","continue", @@ -894,6 +1075,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { "unsafe","use","where","while","Keywords","The","abstract","become", "box","do","final","macro","override","priv","try","typeof","unsized", "virtual","yield"} + const reserved_rust_need_prefix := {"u8", "u16", "u32", "u64", "u128","i8", "i16", "i32", "i64", "i128"} predicate is_tuple_numeric(i: string) { |i| >= 2 && i[0] == '_' && @@ -905,7 +1087,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { predicate has_special(i: string) { if |i| == 0 then false else if i[0] == '.' then true - else if i[0] == '#' then true // otherwise "escapeIdent("r#") becomes "r#"" + else if i[0] == '#' then true // otherwise "escapeName("r#") becomes "r#"" else if i[0] == '_' then if 2 <= |i| then if i[1] != '_' then true @@ -957,7 +1139,11 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } predicate is_idiomatic_rust_id(i: string) { - 0 < |i| && !has_special(i) && i !in reserved_rust + 0 < |i| && !has_special(i) && i !in reserved_rust && i !in reserved_rust_need_prefix + } + + function escapeName(n: Name): string { + escapeIdent(n.dafny_name) } function escapeIdent(i: string): string { @@ -976,33 +1162,94 @@ module {:extern "DCOMP"} DafnyToRustCompiler { "r#_" + r } - datatype Ownership = OwnershipOwned | OwnershipBorrowed | OwnershipBorrowedMut | OwnershipAutoBorrowed + datatype Ownership = + | OwnershipOwned + | OwnershipOwnedBox + | OwnershipBorrowed + | OwnershipBorrowedMut + | OwnershipAutoBorrowed + // types stores the Rust type per Rust name. + // fn Test(i: T) is map["i" := R.RawType("T")] + // fn Test(i: &T) is map["i" := R.Borrowed(...)] + // fn Test(i: &mut T) is map["i" := R.BorrowedMut(...)] + + datatype Environment = Environment( + names: seq, // All variable names, after escape, in Rust + types: map + ) { + static function Empty(): Environment { + Environment([], map[]) + } + opaque predicate CanReadWithoutClone(name: string) { + name in types && types[name].CanReadWithoutClone() + } + opaque predicate HasCloneSemantics(name: string) { + !CanReadWithoutClone(name) + } + function GetType(name: string): Option { + if name in types then Some(types[name]) else None + } + predicate IsBorrowed(name: string) { + name in types && types[name].Borrowed? + } + predicate IsBorrowedMut(name: string) { + name in types && types[name].BorrowedMut? + } + function AddAssigned(name: string, tpe: R.Type): Environment + // If we know for sure the type of name extends the Copy trait + { + Environment(names + [name], types[name := tpe]) + } + function RemoveAssigned(name: string): Environment + requires name in names + { + var indexInEnv := Std.Collections.Seq.IndexOf(names, name); + Environment( + names[0..indexInEnv] + names[indexInEnv + 1..], + types - {name} + ) + } + } class COMP { - const DafnyChar := if UnicodeChars then "DafnyChar" else "DafnyCharUTF16" const UnicodeChars: bool + const DafnyChar := if UnicodeChars then "DafnyChar" else "DafnyCharUTF16" + const DafnyCharUnderlying := if UnicodeChars then R.RawType("char") else R.RawType("u16") const string_of := if UnicodeChars then "string_of" else "string_utf16_of" - constructor(UnicodeChars: bool) { - this.UnicodeChars := UnicodeChars; + var error: Option + + constructor(unicodeChars: bool) { + this.UnicodeChars := unicodeChars; + this.error := None; // If error, then the generated code contains Unsupported: .* } - method GenModule(mod: Module, containingPath: seq) returns (s: R.Mod) { - var body := GenModuleBody(mod.body, containingPath + [Ident.Ident(mod.name)]); - s := if mod.isExtern then - R.ExternMod(escapeIdent(mod.name)) - else - R.Mod(escapeIdent(mod.name), body); + method GenModule(mod: Module, containingPath: seq) returns (s: R.Mod) + decreases mod, 1 + modifies this + { + var modName := escapeName(mod.name); + if mod.body.None? { + s := 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); + } } - method GenModuleBody(body: seq, containingPath: seq) returns (s: seq) { + method GenModuleBody(ghost parent: Module, body: seq, containingPath: seq) returns (s: seq) + requires forall m: ModuleItem <- body :: m < parent + decreases parent, 0 + modifies this + { s := []; - var i := 0; - while i < |body| { + 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)]; case Class(c) => @@ -1016,104 +1263,116 @@ module {:extern "DCOMP"} DafnyToRustCompiler { generated := GenDatatype(d); } s := s + generated; - i := i + 1; } } - method GenTypeParameters(params: seq) + method GenTypeParam(tp: TypeArgDecl) returns (typeArg: Type, typeParam: R.TypeParamDecl) + { + typeArg := TypeArg(tp.name); + var genTpConstraint := if SupportsEquality in tp.bounds then + [R.DafnyTypeEq] + else + [R.DafnyType]; + if SupportsDefault in tp.bounds { + genTpConstraint := genTpConstraint + [R.std_type.MSel("default").MSel("Default")]; + } + typeParam := R.TypeParamDecl(escapeName(tp.name.id), genTpConstraint); + } + + method GenTypeParameters(params: seq) returns ( typeParamsSet: set, - typeParams: seq, - constrainedTypeParams: seq, + typeParams: seq, + constrainedTypeParams: seq, whereConstraints: string) { typeParamsSet := {}; typeParams := []; constrainedTypeParams := []; whereConstraints := ""; - var tpI := 0; - if |params| > 0 { - while tpI < |params| { + for tpI := 0 to |params| { var tp := params[tpI]; - typeParamsSet := typeParamsSet + {tp}; - var genTp := GenType(tp, false, false); - typeParams := typeParams + [R.RawTypeParam(genTp.ToString(IND), [])]; - tpI := tpI + 1; + var typeArg, typeParam := GenTypeParam(tp); + var rType := GenType(typeArg, false, false); + typeParamsSet := typeParamsSet + {typeArg}; + typeParams := typeParams + [rType]; + constrainedTypeParams := constrainedTypeParams + [typeParam]; } } - var baseConstraints := [R.CloneTrait, R.DafnyPrintTrait, R.StaticTrait]; - constrainedTypeParams := R.TypeParam.AddConstraintsMultiple( - typeParams, baseConstraints - ); } - method GenClass(c: Class, path: seq) returns (s: seq) { - var typeParamsSet, sTypeParams, sConstrainedTypeParams, whereConstraints := GenTypeParameters(c.typeParams); - var constrainedTypeParams := R.TypeParam.ToStringMultiple(sConstrainedTypeParams, R.IND + R.IND); + method GenClass(c: Class, path: seq) returns (s: seq) + modifies this + { + var typeParamsSet, rTypeParams, rTypeParamsDecls, whereConstraints := GenTypeParameters(c.typeParams); + var constrainedTypeParams := R.TypeParamDecl.ToStringMultiple(rTypeParamsDecls, R.IND + R.IND); - var fields: seq := []; + var fields: seq := []; var fieldInits: seq := []; - var fieldI := 0; - while fieldI < |c.fields| { + for fieldI := 0 to |c.fields| { var field := c.fields[fieldI]; var fieldType := GenType(field.formal.typ, false, false); - fields := fields + [R.Formal("pub " + escapeIdent(field.formal.name), R.TypeApp(R.refcell_type, [fieldType]))]; + var fieldRustName := escapeName(field.formal.name); + fields := fields + [R.Field(R.PUB, R.Formal(fieldRustName, fieldType))]; match field.defaultValue { case Some(e) => { - var eStr, _, _ := GenExpr(e, None, [], OwnershipOwned); + // TODO(mikael): Fields must be initialized before the code of the constructor if possible + var expr, _, _ := GenExpr(e, None, Environment.Empty(), OwnershipOwned); + fieldInits := fieldInits + [ R.AssignIdentifier( - escapeIdent(field.formal.name), - R.RawExpr("::std::cell::RefCell::new(" + eStr.ToString(IND) + ")"))]; + escapeName(field.formal.name), + R.RawExpr("::std::cell::RefCell::new(" + expr.ToString(IND) + ")"))]; } case None => { + // TODO(mikael) Use type descriptors for default values if generics + var default := R.std_Default_default; fieldInits := fieldInits + [ R.AssignIdentifier( - escapeIdent(field.formal.name), - R.RawExpr("::std::cell::RefCell::new(::std::default::Default::default())"))]; + fieldRustName, default)]; } } - - fieldI := fieldI + 1; } - var typeParamI := 0; - while typeParamI < |c.typeParams| { - var tpeGen := GenType(c.typeParams[typeParamI], false, false); - fields := fields + [R.Formal("_phantom_type_param_" + Strings.OfNat(typeParamI), R.TypeApp(R.std_type.MSel("marker").MSel("PhantomData"), [tpeGen]))]; + // A phantom field is necessary to avoid Rust complaining about no reference to the type parameter. + // PhantomData is zero-sized so it won't impact final performance or layout + for typeParamI := 0 to |c.typeParams| { + var typeArg, typeParam := GenTypeParam(c.typeParams[typeParamI]); + var rTypeArg := GenType(typeArg, false, false); + fields := fields + [ + R.Field(R.PRIV, + R.Formal("_phantom_type_param_" + Strings.OfNat(typeParamI), + R.TypeApp(R.std_type.MSel("marker").MSel("PhantomData"), [rTypeArg])))]; fieldInits := fieldInits + [ R.AssignIdentifier( "_phantom_type_param_" + Strings.OfNat(typeParamI), R.RawExpr("::std::marker::PhantomData"))]; - - typeParamI := typeParamI + 1; } - var struct := R.Struct([], escapeIdent(c.name), sTypeParams, R.NamedFormals(fields)); - var typeParamsAsTypes := - Std.Collections.Seq.Map((typeParam: R.TypeParam) => R.RawType(typeParam.content), sTypeParams); + var datatypeName := escapeName(c.name); + + var struct := R.Struct([], datatypeName, rTypeParamsDecls, R.NamedFields(fields)); s := [R.StructDecl(struct)]; - var implBodyRaw, traitBodies := GenClassImplBody(c.body, false, Type.Path([], [], ResolvedType.Datatype(path)), typeParamsSet); + var implBodyRaw, traitBodies := GenClassImplBody(c.body, false, Type.Path([], [], + ResolvedType.Datatype(DatatypeType(path, c.attributes))), typeParamsSet); var implBody := [R.FnDecl( R.PUB, - R.Fn( - "new", - [], [], Some(R.SelfOwned), - "", - Some(R.StructBuild( - escapeIdent(c.name), + R.Fn("new", [], [], Some(R.SelfOwned), "", + Some( + R.StructBuild( + R.Identifier(datatypeName), fieldInits )) ))] + implBodyRaw; var i := R.Impl( - sConstrainedTypeParams, - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), + rTypeParamsDecls, + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), whereConstraints, implBody ); @@ -1123,7 +1382,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { while i < |c.superClasses| { var superClass := c.superClasses[i]; match superClass { - case Path(traitPath, typeArgs, Trait(_)) => { + case Path(traitPath, typeArgs, Trait(_, _)) => { var pathStr := GenPath(traitPath); var typeArgs := GenTypeArgs(typeArgs, false, false); var body: seq := []; @@ -1134,9 +1393,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var genSelfPath := GenPath(path); var x := R.ImplDecl( R.ImplFor( - sConstrainedTypeParams, - R.TypeApp(R.TIdentifier(pathStr), typeArgs), - R.Rc(R.TypeApp(R.TIdentifier(genSelfPath), typeParamsAsTypes)), + rTypeParamsDecls, + R.TypeApp(pathStr, typeArgs), + R.Rc(R.TypeApp(genSelfPath, rTypeParams)), whereConstraints, body )); @@ -1149,48 +1408,48 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var d := R.ImplFor( - sConstrainedTypeParams, + rTypeParamsDecls, R.DefaultTrait, - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), whereConstraints, [R.FnDecl( R.PRIV, R.Fn( "default", [], [], Some(R.SelfOwned), "", - Some(R.RawExpr(escapeIdent(c.name) + "::new()"))))] + Some(R.RawExpr(datatypeName + "::new()"))))] ); var defaultImpl := [R.ImplDecl(d)]; var p := R.ImplFor( - sConstrainedTypeParams, - R.DafnyPrintTrait, - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), + rTypeParamsDecls, + R.DafnyPrint, + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), "", [R.FnDecl( R.PRIV, R.Fn( "fmt_print", [], - [R.Formal.self, R.Formal("_formatter", R.RawType("&mut ::std::fmt::Formatter")), R.Formal("_in_seq", R.RawType("bool"))], + [R.Formal.selfBorrowed, R.Formal("_formatter", R.RawType("&mut ::std::fmt::Formatter")), R.Formal("_in_seq", R.Type.Bool)], Some(R.RawType("std::fmt::Result")), "", - Some(R.RawExpr("write!(_formatter, \"" + c.enclosingModule.id + "." + c.name + "\")")) + Some(R.RawExpr("write!(_formatter, \"" + escapeName(c.enclosingModule.id) + "." + escapeName(c.name) + "\")")) ))] ); var printImpl := [R.ImplDecl(p)]; var pp := R.ImplFor( - sTypeParams, + rTypeParamsDecls, R.RawType("::std::cmp::PartialEq"), - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), "", [R.FnDecl( R.PRIV, R.Fn( "eq", [], - [R.Formal.self, R.Formal("other", R.Self)], - Some(R.RawType("bool")), + [R.Formal.selfBorrowed, R.Formal("other", R.SelfBorrowed)], + Some(R.Type.Bool), "", Some(R.RawExpr("::std::ptr::eq(self, other)")) ))] @@ -1200,35 +1459,40 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := s + defaultImpl + printImpl + ptrPartialEqImpl; } - method GenTrait(t: Trait, containingPath: seq) returns (s: string) { + method GenTrait(t: Trait, containingPath: seq) returns (s: string) + modifies this + { var typeParamsSet := {}; + var typeParamDecls := []; var typeParams := []; var tpI := 0; if |t.typeParams| > 0 { while tpI < |t.typeParams| { var tp := t.typeParams[tpI]; - typeParamsSet := typeParamsSet + {tp}; - var genTp := GenType(tp, false, false); - typeParams := typeParams + [genTp]; + var typeArg, typeParamDecl := GenTypeParam(tp); + typeParamsSet := typeParamsSet + {typeArg}; + typeParamDecls := typeParamDecls + [typeParamDecl]; + var typeParam := GenType(typeArg, false, false); + typeParams := typeParams + [typeParam]; tpI := tpI + 1; } } var fullPath := containingPath + [Ident.Ident(t.name)]; - var implBody, _ := GenClassImplBody(t.body, true, Type.Path(fullPath, [], ResolvedType.Trait(fullPath)), typeParamsSet); + var implBody, _ := GenClassImplBody(t.body, true, Type.Path(fullPath, [], ResolvedType.Trait(fullPath, t.attributes)), typeParamsSet); s := R.TraitDecl(R.Trait( - [], R.TypeApp(R.TIdentifier(escapeIdent(t.name)), typeParams), + typeParamDecls, R.TypeApp(R.TIdentifier(escapeName(t.name)), typeParams), "", implBody )).ToString(IND); } - method GenNewtype(c: Newtype) returns (s: seq) { - var typeParamsSet, sTypeParams, sConstrainedTypeParams, whereConstraints := GenTypeParameters(c.typeParams); - var typeParamsAsTypes := - Std.Collections.Seq.Map((t: R.TypeParam) => R.RawType(t.content), sTypeParams); - var constrainedTypeParams := R.TypeParam.ToStringMultiple(sConstrainedTypeParams, R.IND + R.IND); + method GenNewtype(c: Newtype) returns (s: seq) + modifies this + { + var typeParamsSet, rTypeParams, rTypeParamsDecls, whereConstraints := GenTypeParameters(c.typeParams); + var constrainedTypeParams := R.TypeParamDecl.ToStringMultiple(rTypeParamsDecls, R.IND + R.IND); var underlyingType; match NewtypeToRustType(c.base, c.range) { @@ -1237,6 +1501,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case None => underlyingType := GenType(c.base, false, false); } + var resultingType := + Path([], [], ResolvedType.Newtype(c.base, c.range, false, c.attributes)); + var datatypeName := escapeName(c.name); s := [ R.StructDecl( R.Struct( @@ -1244,21 +1511,22 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.RawAttribute("#[derive(Clone, PartialEq)]"), R.RawAttribute("#[repr(transparent)]") ], - escapeIdent(c.name), - sTypeParams, - R.NamelessFormals([R.NamelessFormal(R.PUB, underlyingType)]) + datatypeName, + rTypeParamsDecls, + R.NamelessFields([R.NamelessField(R.PUB, underlyingType)]) ))]; - var fnBody := ""; + var fnBody := R.Identifier(datatypeName); match c.witnessExpr { case Some(e) => { - // TODO(shadaj): generate statements - var eStr, _, _ := GenExpr(e, None, [], OwnershipOwned); - fnBody := fnBody + escapeIdent(c.name) + "(" + eStr.ToString(IND) + ")\n"; + var e := if c.base == resultingType then e else Convert(e, c.base, resultingType); + // TODO(Mikael): generate statements if any + var eStr, _, _ := GenExpr(e, None, Environment.Empty(), OwnershipOwned); + fnBody := fnBody.Apply1(eStr); } case None => { - fnBody := fnBody + escapeIdent(c.name) + "(::std::default::Default::default())"; + fnBody := fnBody.Apply1(R.std_Default_default); } } @@ -1268,133 +1536,152 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Fn( "default", [], [], Some(R.SelfOwned), "", - Some(R.RawExpr(fnBody)) + Some(fnBody) )); s := s + [ R.ImplDecl( R.ImplFor( - sConstrainedTypeParams, + rTypeParamsDecls, R.DefaultTrait, - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), whereConstraints, [body]))]; s := s + [ - R.ImplDecl(R.ImplFor( - sConstrainedTypeParams, - R.DafnyPrintTrait, - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), - "", - [R.FnDecl(R.PRIV, - R.Fn("fmt_print", [], - [R.Formal.self, R.Formal("_formatter", R.RawType("&mut ::std::fmt::Formatter")), R.Formal("in_seq", R.RawType("bool"))], - Some(R.RawType("::std::fmt::Result")), - "", - Some(R.RawExpr("::dafny_runtime::DafnyPrint::fmt_print(&self.0, _formatter, in_seq)")) - ))]))]; + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.DafnyPrint, + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), + "", + [R.FnDecl( + R.PRIV, + R.Fn("fmt_print", [], + [R.Formal.selfBorrowed, R.Formal("_formatter", R.RawType("&mut ::std::fmt::Formatter")), R.Formal("in_seq", R.Type.Bool)], + Some(R.RawType("::std::fmt::Result")), + "", + Some(R.RawExpr("::dafny_runtime::DafnyPrint::fmt_print(&self.0, _formatter, in_seq)")) + ))]))]; s := s + [ R.ImplDecl( R.ImplFor( - sConstrainedTypeParams, + rTypeParamsDecls, R.RawType("::std::ops::Deref"), - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), "", [R.RawImplMember("type Target = " + underlyingType.ToString(IND) + ";"), R.FnDecl( R.PRIV, R.Fn("deref", [], - [R.Formal.self], Some(R.RawType("&Self::Target")), + [R.Formal.selfBorrowed], Some(R.SelfBorrowed.MSel("Target")), "", Some(R.RawExpr("&self.0"))))]))]; } - method GenDatatype(c: Datatype) returns (s: seq) { - var typeParamsSet, sTypeParams, sConstrainedTypeParams, whereConstraints := GenTypeParameters(c.typeParams); - var typeParamsAsTypes := - Std.Collections.Seq.Map((t: R.TypeParam) => R.RawType(t.content), sTypeParams); - var constrainedTypeParams := R.TypeParam.ToStringMultiple(sConstrainedTypeParams, IND + IND); - + method GenDatatype(c: Datatype) returns (s: seq) + modifies this + { + var typeParamsSet, rTypeParams, rTypeParamsDecls, whereConstraints := GenTypeParameters(c.typeParams); + var datatypeName := escapeName(c.name); var ctors: seq := []; - var i := 0; - while i < |c.ctors| { + for i := 0 to |c.ctors| { var ctor := c.ctors[i]; - var ctorArgs: seq := []; - var j := 0; - while j < |ctor.args| { - var formal := ctor.args[j]; - var formalType := GenType(formal.typ, false, false); + var ctorArgs: seq := []; + var isNumeric := false; + for j := 0 to |ctor.args| { + var dtor := ctor.args[j]; + var formalType := GenType(dtor.formal.typ, false, false); + var formalName := escapeName(dtor.formal.name); + if j == 0 && "0" == formalName { + isNumeric := true; + } + if j != 0 && isNumeric && Strings.OfNat(j) != formalName { + error := Some("Formal extern names were supposed to be numeric but got " + formalName + " instead of " + Strings.OfNat(j)); + isNumeric := false; + } if c.isCo { ctorArgs := ctorArgs + [ - R.Formal(escapeIdent(formal.name), - R.TypeApp(R.dafny_runtime_type.MSel("LazyFieldWrapper"), [formalType]))]; + R.Field(R.PRIV, + R.Formal(formalName, + R.TypeApp(R.dafny_runtime_type.MSel("LazyFieldWrapper"), [formalType])))]; } else { ctorArgs := ctorArgs + [ - R.Formal(escapeIdent(formal.name), formalType)]; + R.Field(R.PRIV, + R.Formal(formalName, formalType))]; } - j := j + 1; } - ctors := ctors + [R.EnumCase(escapeIdent(ctor.name), R.NamedFormals(ctorArgs))]; - i := i + 1; + var namedFields := R.NamedFields(ctorArgs); + if isNumeric { + namedFields := namedFields.ToNamelessFields(); + } + ctors := ctors + [R.EnumCase(escapeName(ctor.name), namedFields)]; } var selfPath := [Ident.Ident(c.name)]; - var implBodyRaw, traitBodies := GenClassImplBody(c.body, false, Type.Path([], [], ResolvedType.Datatype(selfPath)), typeParamsSet); + var implBodyRaw, traitBodies := GenClassImplBody(c.body, false, Type.Path([], [], ResolvedType.Datatype(DatatypeType(selfPath, c.attributes))), typeParamsSet); var implBody: seq := implBodyRaw; - i := 0; var emittedFields: set := {}; - while i < |c.ctors| { + for i := 0 to |c.ctors| { // we know that across all ctors, each any fields with the same name have the same type // so we want to emit methods for each field that pull the appropriate value given // the current variant (and panic if we have a variant with no such field) var ctor := c.ctors[i]; - var j := 0; - while j < |ctor.args| { - var formal := ctor.args[j]; - if !(formal.name in emittedFields) { - emittedFields := emittedFields + {formal.name}; + for j := 0 to |ctor.args| { + var dtor := ctor.args[j]; + var callName := dtor.callName.GetOr(escapeName(dtor.formal.name)); + if !(callName in emittedFields) { + emittedFields := emittedFields + {callName}; - var formalType := GenType(formal.typ, false, false); + var formalType := GenType(dtor.formal.typ, false, false); var cases: seq := []; - var k := 0; - while k < |c.ctors| { + for k := 0 to |c.ctors| { var ctor2 := c.ctors[k]; - var pattern := escapeIdent(c.name) + "::" + escapeIdent(ctor2.name) + " { "; + var pattern := datatypeName + "::" + escapeName(ctor2.name); var rhs: string; - var l := 0; - var hasMatchingField := false; - while l < |ctor2.args| { - var formal2 := ctor2.args[l]; - if formal.name == formal2.name { - hasMatchingField := true; + var hasMatchingField := None; + var patternInner := ""; + var isNumeric := false; + for l := 0 to |ctor2.args| { + var dtor2 := ctor2.args[l]; + var patternName := escapeName(dtor2.formal.name); + if l == 0 && patternName == "0" { + isNumeric := true; + } + if isNumeric { + patternName := dtor2.callName.GetOr("v" + Strings.OfNat(l)); } - pattern := pattern + escapeIdent(formal2.name) + ", "; - l := l + 1; + if dtor.formal.name == dtor2.formal.name { + hasMatchingField := Some(patternName); + } + patternInner := patternInner + patternName + ", "; + } + if isNumeric { + pattern := pattern + "(" + patternInner + ")"; + } else { + pattern := pattern + "{" + patternInner + "}"; } - pattern := pattern + "}"; - - if hasMatchingField { + if hasMatchingField.Some? { if c.isCo { - rhs := "::std::ops::Deref::deref(&" + escapeIdent(formal.name) + ".0)"; + rhs := "::std::ops::Deref::deref(&" + hasMatchingField.value + ".0)"; } else { - rhs := escapeIdent(formal.name) + ""; + rhs := hasMatchingField.value + ""; } } else { rhs := "panic!(\"field does not exist on this variant\")"; } var ctorMatch := R.MatchCase(R.RawPattern(pattern), R.RawExpr(rhs)); cases := cases + [ctorMatch]; - k := k + 1; } if |c.typeParams| > 0 { cases := cases + [ - R.MatchCase(R.RawPattern(escapeIdent(c.name) + "::_PhantomVariant(..)"), R.RawExpr("panic!()")) + R.MatchCase(R.RawPattern(datatypeName + "::_PhantomVariant(..)"), R.RawExpr("panic!()")) ]; } var methodBody := R.Match( - R.RawExpr("self"), + R.self, cases ); @@ -1402,71 +1689,84 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.FnDecl( R.PUB, R.Fn( - escapeIdent(formal.name), - [], [R.Formal.self], Some(R.Borrowed(formalType)), + callName, + [], [R.Formal.selfBorrowed], Some(R.Borrowed(formalType)), "", Some(methodBody) ))]; } - j := j + 1; } - - i := i + 1; } if |c.typeParams| > 0 { - var typeI := 0; var types: seq := []; - while typeI < |c.typeParams| { - var genTp := GenType(c.typeParams[typeI], false, false); - types := types + [R.TypeApp(R.TIdentifier("::std::marker::PhantomData::"), [genTp])]; - typeI := typeI + 1; - } - ctors := ctors + [R.EnumCase("_PhantomVariant", - R.NamelessFormals(Std.Collections.Seq.Map( - tpe => R.NamelessFormal(R.PRIV, tpe), types)) - )]; + for typeI := 0 to |c.typeParams| { + var typeArg, rTypeParamDecl := GenTypeParam(c.typeParams[typeI]); + var rTypeArg := GenType(typeArg, false, false); + types := types + [R.TypeApp(R.std_type.MSel("marker").MSel("PhantomData"), [rTypeArg])]; + } + ctors := ctors + [ + R.EnumCase( + "_PhantomVariant", + R.NamelessFields( + Std.Collections.Seq.Map( + tpe => R.NamelessField(R.PRIV, tpe), types)) + )]; } - var enumBody := [R.EnumDecl( - R.Enum([R.RawAttribute("#[derive(PartialEq)]")], - escapeIdent(c.name), - sTypeParams, - ctors + R.Enum( + [R.RawAttribute("#[derive(PartialEq, Clone)]")], + datatypeName, + rTypeParamsDecls, + ctors )), R.ImplDecl( R.Impl( - sConstrainedTypeParams, - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), + rTypeParamsDecls, + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), whereConstraints, implBody ))]; - i := 0; var printImplBodyCases: seq := []; - while i < |c.ctors| { + for i := 0 to |c.ctors| { var ctor := c.ctors[i]; - var ctorMatch := escapeIdent(ctor.name) + " { "; + var ctorMatch := escapeName(ctor.name); - var modulePrefix := if c.enclosingModule.id == "_module" then "" else c.enclosingModule.id + "."; + var modulePrefix := if c.enclosingModule.id.dafny_name == "_module" then "" else c.enclosingModule.id.dafny_name + "."; + var ctorName := modulePrefix + c.name.dafny_name + "." + ctor.name.dafny_name; + if |ctorName| >= 13 && ctorName[0..13] == "_System.Tuple" { + ctorName := ""; + } var printRhs := - R.RawExpr("write!(_formatter, \"" + modulePrefix + c.name + "." + escapeIdent(ctor.name) + (if ctor.hasAnyArgs then "(\")?" else "\")?")); + R.RawExpr("write!(_formatter, \"" + ctorName + (if ctor.hasAnyArgs then "(\")?" else "\")?")); + + var isNumeric := false; + var ctorMatchInner := ""; + for j := 0 to |ctor.args| { + var dtor := ctor.args[j]; + var patternName := escapeName(dtor.formal.name); + if j == 0 && patternName == "0" { + isNumeric := true; + } + if isNumeric { + patternName := dtor.callName.GetOr("v" + Strings.OfNat(j)); + } - var j := 0; - while j < |ctor.args| { - var formal := ctor.args[j]; - ctorMatch := ctorMatch + escapeIdent(formal.name) + ", "; + ctorMatchInner := ctorMatchInner + patternName + ", "; if (j > 0) { printRhs := printRhs.Then(R.RawExpr("write!(_formatter, \", \")?")); } - printRhs := printRhs.Then(R.RawExpr("::dafny_runtime::DafnyPrint::fmt_print(" + escapeIdent(formal.name) + ", _formatter, false)?")); - - j := j + 1; + printRhs := printRhs.Then(R.RawExpr("::dafny_runtime::DafnyPrint::fmt_print(" + patternName + ", _formatter, false)?")); } - ctorMatch := ctorMatch + "}"; + if isNumeric { + ctorMatch := ctorMatch + "(" + ctorMatchInner + ")"; + } else { + ctorMatch := ctorMatch + "{" + ctorMatchInner + "}"; + } if (ctor.hasAnyArgs) { printRhs := printRhs.Then(R.RawExpr("write!(_formatter, \")\")?")); @@ -1475,90 +1775,132 @@ module {:extern "DCOMP"} DafnyToRustCompiler { printRhs := printRhs.Then(R.RawExpr("Ok(())")); printImplBodyCases := printImplBodyCases + [ - R.MatchCase(R.RawPattern(escapeIdent(c.name) + "::" + ctorMatch), + R.MatchCase(R.RawPattern(datatypeName + "::" + ctorMatch), R.Block(printRhs)) ]; - i := i + 1; } if |c.typeParams| > 0 { printImplBodyCases := printImplBodyCases + [ - R.MatchCase(R.RawPattern(escapeIdent(c.name) + "::_PhantomVariant(..)"), R.RawExpr("{panic!()}")) + R.MatchCase(R.RawPattern(datatypeName + "::_PhantomVariant(..)"), R.RawExpr("{panic!()}")) ]; } + var defaultConstrainedTypeParams := R.TypeParamDecl.AddConstraintsMultiple( + rTypeParamsDecls, [R.DefaultTrait] + ); var printImplBody := R.Match( - R.RawExpr("self"), + R.self, printImplBodyCases); var printImpl := [ + R.ImplDecl( + R.ImplFor(rTypeParamsDecls, + R.std_type.MSel("fmt").MSel("Debug"), + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), + "", + [ + R.FnDecl( + R.PRIV, + R.Fn( + "fmt", [], + [R.Formal.selfBorrowed, + R.Formal("f", R.BorrowedMut(R.std_type.MSel("fmt").MSel("Formatter")))], + Some(R.RawType("std::fmt::Result")), + "", + Some(R.dafny_runtime.MSel("DafnyPrint").MSel("fmt_print").Apply([ + R.self, R.Identifier("f"), R.LiteralBool(true) + ]))) + ) + ] + )), R.ImplDecl( R.ImplFor( - sConstrainedTypeParams, - R.DafnyPrintTrait, - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), + rTypeParamsDecls, + R.DafnyPrint, + R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), "", [R.FnDecl( R.PRIV, R.Fn( "fmt_print", [], - [R.Formal.self, R.Formal("_formatter", R.RawType("&mut ::std::fmt::Formatter")), R.Formal("_in_seq", R.RawType("bool"))], + [R.Formal.selfBorrowed, + R.Formal("_formatter", R.BorrowedMut(R.std_type.MSel("fmt").MSel("Formatter"))), + R.Formal("_in_seq", R.Type.Bool)], Some(R.RawType("std::fmt::Result")), "", Some(printImplBody)))] ))]; var defaultImpl := []; + var asRefImpl := []; if |c.ctors| > 0 { - i := 0; - var structName := escapeIdent(c.name) + "::" + escapeIdent(c.ctors[0].name); + var structName := R.Identifier(datatypeName).MSel(escapeName(c.ctors[0].name)); var structAssignments: seq := []; - while i < |c.ctors[0].args| { - var formal := c.ctors[0].args[i]; + for i := 0 to |c.ctors[0].args| { + var dtor := c.ctors[0].args[i]; structAssignments := structAssignments + [ - R.AssignIdentifier(escapeIdent(formal.name), R.RawExpr("::std::default::Default::default()")) + R.AssignIdentifier(escapeName(dtor.formal.name), R.RawExpr("::std::default::Default::default()")) ]; - i := i + 1; } - var defaultConstrainedTypeParams := R.TypeParam.AddConstraintsMultiple( - sTypeParams, [R.DefaultTrait] + var defaultConstrainedTypeParams := R.TypeParamDecl.AddConstraintsMultiple( + rTypeParamsDecls, [R.DefaultTrait] ); - + var fullType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); defaultImpl := [ R.ImplDecl( R.ImplFor( defaultConstrainedTypeParams, R.DefaultTrait, - R.TypeApp(R.TIdentifier(escapeIdent(c.name)), typeParamsAsTypes), + fullType, + "", + [R.FnDecl( + R.PRIV, + R.Fn( + "default", [], [], Some(fullType), + "", + Some( + R.StructBuild( + structName, + structAssignments + ))) + )] + ))]; + asRefImpl := [ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.std_type.MSel("convert").MSel("AsRef").Apply1(fullType), + R.Borrowed(fullType), "", [R.FnDecl( R.PRIV, - R.Fn("default", [], [], Some(R.SelfOwned), + R.Fn("as_ref", [], [R.Formal.selfBorrowed], Some(R.SelfOwned), "", - Some(R.StructBuild( - structName, - structAssignments - ))) + Some(R.self)) )] ))]; } - - s := enumBody + printImpl + defaultImpl; + s := enumBody + printImpl + defaultImpl + asRefImpl; } - static method GenPath(p: seq) returns (s: string) { + static method GenPath(p: seq) returns (r: R.Type) { if |p| == 0 { - // TODO(shadaj): this special casing is not great - return "Self"; + return R.SelfOwned; } else { - s := "super::"; - var i := 0; - while i < |p| { - if i > 0 { - s := s + "::"; - } - - s := s + escapeIdent(p[i].id); + // TODO: Better distinction between Dafny modules and any module + r := if p[0].id.dafny_name == "std" then R.TIdentifier("") else R.TIdentifier("super"); + for i := 0 to |p| { + r := r.MSel(escapeName(p[i].id)); + } + } + } - i := i + 1; + static method GenPathExpr(p: seq) returns (r: R.Expr) { + if |p| == 0 { + return R.self; + } else { + r := if p[0].id.dafny_name == "std" then R.Identifier("") else R.Identifier("super"); + for i := 0 to |p| { + r := r.MSel(escapeName(p[i].id)); } } } @@ -1575,21 +1917,28 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + predicate IsRcWrapped(attributes: seq) { + (Attribute("auto-nongrowing-size", []) !in attributes && + Attribute("rust_rc", ["false"]) !in attributes) || + Attribute("rust_rc", ["true"]) in attributes + } + method GenType(c: Type, inBinding: bool, inFn: bool) returns (s: R.Type) { match c { case Path(p, args, resolved) => { var t := GenPath(p); - s := R.TIdentifier(t); - var typeArgs := GenTypeArgs(args, inBinding, inFn); - s := R.TypeApp(s, typeArgs); + s := R.TypeApp(t, typeArgs); match resolved { - case Datatype(_) => { - s := R.Rc(s); + case Datatype(DatatypeType(_, attributes)) => { + // Any kind of default wrapping here if necessary + if IsRcWrapped(attributes) { + s := R.Rc(s); + } } - case Trait(_) => { - if p == [Ident.Ident("_System"), Ident.Ident("object")] { + case Trait(_, _) => { + if p == [Ident.Ident(Name("_System")), Ident.Ident(Name("object"))] { s := R.RawType("::std::rc::Rc"); } else { if inBinding { @@ -1600,7 +1949,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } } - case Newtype(t, range, erased) => { + case Newtype(t, range, erased, attributes) => { if erased { match NewtypeToRustType(t, range) { case Some(v) => @@ -1623,7 +1972,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { args := args + [generated]; i := i + 1; } - s := R.TupleType(args); + s := if |types| <= R.MAX_TUPLE_SIZE then R.TupleType(args) else R.SystemTupleType(args); } case Array(element, dims) => { var elem := GenType(element, inBinding, inFn); @@ -1661,12 +2010,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := R.TypeApp(R.dafny_runtime_type.MSel("SetBuilder"), [elemType]); } case Arrow(args, result) => { - // we cannot use impl until Rc impls Fn - // if inFn || inBinding { - // s := "::dafny_runtime::FunctionWrapper<::std::rc::Rc " + resultType + " + 'static>>"; @@ -1687,14 +2029,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // s := s + ") -> " + resultType + " + Clone + 'static>"; // } } - case TypeArg(Ident(name)) => s := R.RawType(escapeIdent(name)); + 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 Bool => s := R.RawType("bool"); + case Bool => s := R.Type.Bool; case Char => s := R.dafny_runtime_type.MSel(DafnyChar); } } @@ -1704,12 +2046,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenClassImplBody(body: seq, forTrait: bool, enclosingType: Type, enclosingTypeParams: set) returns (s: seq, traitBodies: map, seq>) + modifies this { s := []; traitBodies := map[]; - var i := 0; - while i < |body| { + for i := 0 to |body| { match body[i] { case Method(m) => { match m.overridingPath { @@ -1731,37 +2073,57 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } } - i := i + 1; } } - method GenParams(params: seq) returns (s: seq) { + // Transform DAST formals to Rust formals + method GenParams(params: seq) returns (s: seq) + ensures |s| == |params| + { s := []; - var i := 0; - while i < |params| { + for i := 0 to |params| invariant |s| == i && i <= |params| { var param := params[i]; var paramType := GenType(param.typ, false, false); - s := s + [R.Formal(escapeIdent(param.name), R.Borrowed(paramType))]; - i := i + 1; + if !paramType.CanReadWithoutClone() && AttributeOwned !in param.attributes { + paramType := R.Borrowed(paramType); + } + s := s + [R.Formal(escapeName(param.name), paramType)]; } } - method GenMethod(m: Method, forTrait: bool, enclosingType: Type, enclosingTypeParams: set) returns (s: R.ImplMember) { + method GenMethod(m: Method, forTrait: bool, enclosingType: Type, enclosingTypeParams: set) returns (s: R.ImplMember) + modifies this + { var params: seq := GenParams(m.params); var paramNames := []; - var paramI := 0; - while paramI < |m.params| { - paramNames := paramNames + [m.params[paramI].name]; - paramI := paramI + 1; + var paramTypes := map[]; + for paramI := 0 to |m.params| { + var dafny_formal := m.params[paramI]; + var formal := params[paramI]; + var name := formal.name; + paramNames := paramNames + [name]; + paramTypes := paramTypes[name := formal.tpe]; } + var fnName := escapeName(m.name); + + var selfIdentifier: Option := None; if (!m.isStatic) { + var selfId := "self"; + if fnName == "_ctor" { // Constructors take a raw pointer, which is not accepted as a self type in Rust + selfId := "this"; + } if (forTrait) { - params := [R.Formal.self] + params; + var selfFormal := R.Formal.selfBorrowedMut; + params := [selfFormal] + params; } else { var tpe := GenType(enclosingType, false, false); - params := [R.Formal("self", R.Borrowed(tpe))] + params; + if !tpe.CanReadWithoutClone() { + tpe := R.Borrowed(tpe); + } + params := [R.Formal(selfId, tpe)] + params; } + selfIdentifier := Some(selfId); } // TODO: Use mut instead of a tuple for the API of multiple output parameters @@ -1777,43 +2139,29 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var visibility := R.PUB;//if forTrait then R.PUB else R.PRIV; - var fnName := escapeIdent(m.name); var typeParamsFiltered := []; - var typeParamI := 0; - while typeParamI < |m.typeParams| { + for typeParamI := 0 to |m.typeParams| { var typeParam := m.typeParams[typeParamI]; - if !(typeParam in enclosingTypeParams) { + if !(TypeArg(typeParam.name) in enclosingTypeParams) { typeParamsFiltered := typeParamsFiltered + [typeParam]; } - - typeParamI := typeParamI + 1; } - var whereClauses := ""; - - var typeParams: seq := []; + var typeParams: seq := []; if (|typeParamsFiltered| > 0) { - whereClauses := whereClauses + " where "; - - var i := 0; - while i < |typeParamsFiltered| { - - var typeExpr := GenType(typeParamsFiltered[i], false, false); - typeParams := typeParams + [ - R.RawTypeParam(typeExpr.ToString(IND), - [R.CloneTrait, - R.DafnyPrintTrait, - R.DefaultTrait, - R.StaticTrait]) - ]; - - i := i + 1; + 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")]); + typeParams := typeParams + [rTypeParamDecl]; } } var fBody: Option; + var env: Environment; + var preBody := R.RawExpr(""); if m.hasBody { var earlyReturn: R.Expr := R.Return(None); @@ -1821,24 +2169,35 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Some(outVars) => { var tupleArgs := []; + assume {:axiom} |m.outTypes| == |outVars|; - var outI := 0; - while outI < |outVars| { - + for outI := 0 to |outVars| { var outVar := outVars[outI]; - tupleArgs := tupleArgs + [R.Identifier(escapeIdent(outVar.id))]; - - outI := outI + 1; + var outType := GenType(m.outTypes[outI], false, false); + var outName := escapeName(outVar.id); + paramNames := paramNames + [outName]; + var outMaybeType := if outType.CanReadWithoutClone() then outType else R.Borrowed(outType); + paramTypes := paramTypes[outName := outMaybeType]; + + var outVarReturn, _, _ := GenExpr(Expression.Ident(outVar.id), None, + Environment([outName], map[outName := outMaybeType]), OwnershipOwned); + tupleArgs := tupleArgs + [outVarReturn]; + } + if |tupleArgs| == 1 { + earlyReturn := R.Return(Some(tupleArgs[0])); + } else { + earlyReturn := R.Return(Some(R.Tuple(tupleArgs))); } - earlyReturn := R.Return(Some(R.Tuple(tupleArgs))); } case None => {} } + env := Environment(paramNames, paramTypes); - var body, _ := GenStmts(m.body, if m.isStatic then None else Some("self"), paramNames, true, earlyReturn); + var body, _, _ := GenStmts(m.body, selfIdentifier, env, true, earlyReturn); - fBody := Some(body); + fBody := Some(preBody.Then(body)); } else { + env := Environment(paramNames, paramTypes); fBody := None; } s := R.FnDecl( @@ -1848,156 +2207,166 @@ module {:extern "DCOMP"} DafnyToRustCompiler { typeParams, params, Some(if |retTypeArgs| == 1 then retTypeArgs[0] else R.TupleType(retTypeArgs)), - whereClauses, + "", fBody ) ); } - method GenStmts(stmts: seq, selfIdent: Option, params: seq, isLast: bool, earlyReturn: R.Expr) returns (generated: R.Expr, readIdents: set) - decreases stmts, 1 + method GenStmts(stmts: seq, selfIdent: Option, env: Environment, isLast: bool, earlyReturn: R.Expr) returns (generated: R.Expr, readIdents: set, newEnv: Environment) + decreases stmts, 1, 0 + modifies this { generated := R.RawExpr(""); var declarations := {}; readIdents := {}; var i := 0; + newEnv := env; while i < |stmts| { var stmt := stmts[i]; - var stmtExpr, recIdents := GenStmt(stmt, selfIdent, params, isLast && (i == |stmts| - 1), earlyReturn); - readIdents := readIdents + (recIdents - declarations); + var stmtExpr, recIdents, newEnv2 := GenStmt(stmt, selfIdent, newEnv, isLast && (i == |stmts| - 1), earlyReturn); + newEnv := newEnv2; match stmt { case DeclareVar(name, _, _) => { - declarations := declarations + {name}; + declarations := declarations + {escapeName(name)}; } case _ => {} } + readIdents := readIdents + (recIdents - declarations); generated := generated.Then(stmtExpr); i := i + 1; } } - method GenAssignLhs(lhs: AssignLhs, rhs: string, selfIdent: Option, params: seq) returns (generated: string, needsIIFE: bool, readIdents: set) + method GenAssignLhs(lhs: AssignLhs, rhs: R.Expr, selfIdent: Option, env: Environment) returns (generated: R.Expr, needsIIFE: bool, readIdents: set, newEnv: Environment) decreases lhs, 1 + modifies this { + newEnv := env; match lhs { case Ident(Ident(id)) => { - if id in params { - generated := "*" + escapeIdent(id); + var idRust := escapeName(id); + if env.IsBorrowed(idRust) || env.IsBorrowedMut(idRust) { + generated := R.AssignVar("*" + idRust, rhs); } else { - generated := escapeIdent(id); + generated := R.AssignVar(idRust, rhs); } - readIdents := {id}; + readIdents := {idRust}; needsIIFE := false; } case Select(on, field) => { - var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, params, OwnershipBorrowed); - generated := "*(" + onExpr.ToString(IND) + "." + escapeIdent(field) + ".borrow_mut()) = " + rhs + ";"; + var fieldName := escapeName(field); + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowedMut); + generated := R.RawExpr("*(" + onExpr.ToString(R.IND) + "." + fieldName + ".borrow_mut()) = " + rhs.ToString(R.IND) + ";"); readIdents := recIdents; needsIIFE := true; } case Index(on, indices) => { - var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, params, OwnershipBorrowed); + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); readIdents := recIdents; - generated := "{\n"; + var r := "{\n"; var i := 0; while i < |indices| { - var idx, _, recIdentsIdx := GenExpr(indices[i], selfIdent, params, OwnershipOwned); + var idx, _, recIdentsIdx := GenExpr(indices[i], selfIdent, env, OwnershipOwned); - generated := generated + "let __idx" + Strings.OfNat(i) + " = ::from(" + idx.ToString(IND) + ").unwrap();\n"; + r := r + "let __idx" + Strings.OfNat(i) + " = ::from(" + idx.ToString(IND) + ").unwrap();\n"; readIdents := readIdents + recIdentsIdx; i := i + 1; } - generated := generated + onExpr.ToString(IND) + ".borrow_mut()"; + r := r + onExpr.ToString(IND) + ".borrow_mut()"; i := 0; while i < |indices| { - generated := generated + "[__idx" + Strings.OfNat(i) + "]"; + r := r + "[__idx" + Strings.OfNat(i) + "]"; i := i + 1; } - generated := generated + " = " + rhs + ";\n}"; + generated := R.RawExpr(r + " = " + rhs.ToString(IND) + ";\n}"); needsIIFE := true; } } } - method GenStmt(stmt: Statement, selfIdent: Option, params: seq, isLast: bool, earlyReturn: R.Expr) returns (generated: R.Expr, readIdents: set) - decreases stmt, 1 + method GenStmt(stmt: Statement, selfIdent: Option, env: Environment, isLast: bool, earlyReturn: R.Expr) returns (generated: R.Expr, readIdents: set, newEnv: Environment) + decreases stmt, 1, 1 + modifies this { match stmt { case DeclareVar(name, typ, Some(expression)) => { - var typeString := GenType(typ, true, false); - var expr, _, recIdents := GenExpr(expression, selfIdent, params, OwnershipOwned); - - generated := R.DeclareVar(R.MUT, escapeIdent(name), Some(typeString), Some(expr)); + var tpe := GenType(typ, true, false); + var expr, exprOwnership, recIdents := GenExpr(expression, selfIdent, env, OwnershipOwned); readIdents := recIdents; + generated := R.DeclareVar(R.MUT, escapeName(name), Some(tpe), Some(expr)); + newEnv := env.AddAssigned(escapeName(name), tpe); } case DeclareVar(name, typ, None) => { - var typeString := GenType(typ, true, false); - generated := R.DeclareVar(R.MUT, escapeIdent(name), Some(typeString), None); - readIdents := {}; + var newStmt := DeclareVar(name, typ, Some(InitializationValue(typ))); + assume {:axiom} newStmt < stmt; + generated, readIdents, newEnv := GenStmt(newStmt, selfIdent, env, isLast, earlyReturn); } case Assign(lhs, expression) => { - var lhsGen, needsIIFE, recIdents := GenAssignLhs(lhs, "__rhs", selfIdent, params); - var exprGen, _, exprIdents := GenExpr(expression, selfIdent, params, OwnershipOwned); + var exprGen, _, exprIdents := GenExpr(expression, selfIdent, env, OwnershipOwned); + if lhs.Ident? { + var rustId := escapeName(lhs.ident.id); + var tpe := env.GetType(rustId); + } + var lhsGen, needsIIFE, recIdents, resEnv := GenAssignLhs(lhs, exprGen, selfIdent, env); + generated := lhsGen; + newEnv := resEnv; if needsIIFE { - generated := R.Block( - R.StmtExpr( - R.DeclareVar(R.CONST, "__rhs", None, Some(exprGen)), - R.RawExpr(lhsGen) - ) - ); - } else { - generated := R.AssignVar(lhsGen, exprGen); + generated := R.Block(generated); } - readIdents := recIdents + exprIdents; } - case If(cond, thn, els) => { - var cond, _, recIdents := GenExpr(cond, selfIdent, params, OwnershipOwned); + case If(cond, thnDafny, elsDafny) => { + var cond, _, recIdents := GenExpr(cond, selfIdent, env, OwnershipOwned); var condString := cond.ToString(IND); readIdents := recIdents; - var thn, thnIdents := GenStmts(thn, selfIdent, params, isLast, earlyReturn); + var thn, thnIdents, thnEnv := GenStmts(thnDafny, selfIdent, env, isLast, earlyReturn); readIdents := readIdents + thnIdents; - var els, elsIdents := GenStmts(els, selfIdent, params, isLast, earlyReturn); + var els, elsIdents, elsEnv := GenStmts(elsDafny, selfIdent, env, isLast, earlyReturn); readIdents := readIdents + elsIdents; + newEnv := env; generated := R.IfExpr(cond, thn, els); } case Labeled(lbl, body) => { - var body, bodyIdents := GenStmts(body, selfIdent, params, isLast, earlyReturn); + var body, bodyIdents, env2 := GenStmts(body, selfIdent, env, isLast, earlyReturn); readIdents := bodyIdents; generated := R.Labelled("label_" + lbl, R.Loop(None, R.StmtExpr(body, R.Break(None)))); + newEnv := env; } case While(cond, body) => { - var cond, _, recIdents := GenExpr(cond, selfIdent, params, OwnershipOwned); - + var cond, _, recIdents := GenExpr(cond, selfIdent, env, OwnershipOwned); readIdents := recIdents; - var body, bodyIdents := GenStmts(body, selfIdent, params, false, earlyReturn); - readIdents := readIdents + bodyIdents; - generated := R.Loop(Some(cond), body); + var bodyExpr, bodyIdents, bodyEnv := GenStmts(body, selfIdent, env, false, earlyReturn); + + newEnv := env; + readIdents := readIdents + bodyIdents; + generated := R.Loop(Some(cond), bodyExpr); } case Foreach(boundName, boundType, over, body) => { - var over, _, recIdents := GenExpr(over, selfIdent, params, OwnershipOwned); + var over, _, recIdents := GenExpr(over, selfIdent, env, OwnershipOwned); - var boundTypeStr := GenType(boundType, false, false); + var boundTpe := GenType(boundType, false, false); readIdents := recIdents; - var body, bodyIdents := GenStmts(body, selfIdent, params + [boundName], false, earlyReturn); - readIdents := readIdents + bodyIdents - {boundName}; - - generated := R.For(escapeIdent(boundName), over, body); + var boundRName: string := escapeName(boundName); + var bodyExpr, bodyIdents, bodyEnv := GenStmts(body, selfIdent, env.AddAssigned(boundRName, boundTpe), false, earlyReturn); + readIdents := readIdents + bodyIdents - {boundRName}; + newEnv := env; + generated := R.For(boundRName, over, bodyExpr); } case Break(toLabel) => { match toLabel { @@ -2009,111 +2378,109 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } readIdents := {}; + newEnv := env; } case TailRecursive(body) => { // clone the parameters to make them mutable generated := R.RawExpr(""); if selfIdent != None { - generated := generated.Then(R.DeclareVar(R.MUT, "_this", None, Some(R.RawExpr("self.clone()")))); - } - - var paramI := 0; - while paramI < |params| { - var param := params[paramI]; - generated := generated.Then(R.DeclareVar(R.MUT, escapeIdent(param), None, Some(R.Clone(R.Identifier(escapeIdent(param)))))); - paramI := paramI + 1; + generated := generated.Then(R.DeclareVar(R.MUT, "_this", None, Some(R.self.Sel("clone").Apply([])))); + } + newEnv := env; + for paramI := 0 to |env.names| { + var param := env.names[paramI]; + var paramInit, _, _ := GenIdent(param, selfIdent, env, OwnershipOwned); + generated := generated.Then(R.DeclareVar(R.MUT, param, None, Some(paramInit))); + if param in env.types { + // We made the input type owned by the variable. + // so we can remove borrow annotations. + var declaredType := env.types[param].ToOwned(); + newEnv := newEnv.AddAssigned(param, declaredType); + } } - - var body, bodyIdents := GenStmts(body, if selfIdent != None then Some("_this") else None, [], false, earlyReturn); + var bodyExpr, bodyIdents, bodyEnv := GenStmts(body, if selfIdent != None then Some("_this") else None, newEnv, false, earlyReturn); readIdents := bodyIdents; - generated := generated.Then(R.Labelled("TAIL_CALL_START", - R.Loop(None, body))); + generated := generated.Then( + R.Labelled("TAIL_CALL_START", + R.Loop(None, bodyExpr))); } case JumpTailCallStart() => { generated := R.Continue(Some("TAIL_CALL_START")); readIdents := {}; + newEnv := env; } case Call(on, name, typeArgs, args, maybeOutVars) => { readIdents := {}; - var typeArgString := ""; + var onExpr, _, enclosingIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + + var typeArgsR := []; if (|typeArgs| >= 1) { var typeI := 0; - var typeArgsR := []; while typeI < |typeArgs| { var tpe := GenType(typeArgs[typeI], false, false); typeArgsR := typeArgsR + [tpe]; typeI := typeI + 1; } - typeArgString := R.TypeApp(R.TIdentifier("::"), typeArgsR).ToString(IND); } - var argString := ""; - var i := 0; - while i < |args| { - if i > 0 { - argString := argString + ", "; + var argExprs := []; + for i := 0 to |args| { + var argOwnership := OwnershipBorrowed; + if name.CallName? && i < |name.signature.parameters| { + var tpe := GenType(name.signature.parameters[i].typ, false, false); + if tpe.CanReadWithoutClone() { + argOwnership := OwnershipOwned; + } } - - var argExpr, ownership, argIdents := GenExpr(args[i], selfIdent, params, OwnershipBorrowed); - var argExprString := argExpr.ToString(IND); - - argString := argString + argExprString; + var argExpr, ownership, argIdents := GenExpr(args[i], selfIdent, env, argOwnership); + argExprs := argExprs + [argExpr]; readIdents := readIdents + argIdents; - - i := i + 1; } - - var onExpr, _, enclosingIdents := GenExpr(on, selfIdent, params, OwnershipAutoBorrowed); readIdents := readIdents + enclosingIdents; - var enclosingString := onExpr.ToString(IND); + + var renderedName := match name { + case CallName(name, _, _) => escapeName(name) + case MapBuilderAdd() | SetBuilderAdd() => "add" + case MapBuilderBuild() | SetBuilderBuild() => "build" + }; match on { case Companion(_) => { - enclosingString := enclosingString + "::"; + onExpr := onExpr.MSel(renderedName); } case _ => { - enclosingString := "(" + enclosingString + ")."; + onExpr := onExpr.Sel(renderedName); } } - - var receiver := ""; - match maybeOutVars { - case Some(outVars) => { - if (|outVars| > 1) { - receiver := "("; - } - var outI := 0; - while outI < |outVars| { - if outI > 0 { - receiver := receiver + ", "; - } - - var outVar := outVars[outI]; - receiver := receiver + outVar.id; - - outI := outI + 1; - } - if (|outVars| > 1) { - receiver := receiver + ")"; - } + generated := onExpr; + if |typeArgsR| > 0 { + generated := generated.ApplyType(typeArgsR); + } + generated := generated.Apply(argExprs); + + if maybeOutVars.Some? && |maybeOutVars.value| == 1 { + var outVar := escapeName(maybeOutVars.value[0].id); + generated := R.AssignVar(outVar, generated); + } else if maybeOutVars.None? || |maybeOutVars.value| == 0 { + // Nothing to do here. + } else { // Multiple variables + var tmpVar := "_x"; + var tmpId := R.Identifier(tmpVar); + generated := R.DeclareVar(R.CONST, tmpVar, None, Some(generated)); + // 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 rhs := tmpId.Sel(Strings.OfNat(outI)); + generated := generated.Then(R.AssignVar(outVar, rhs)); } - case None => {} } - - var renderedName := match name { - case Name(name) => escapeIdent(name) - case MapBuilderAdd() | SetBuilderAdd() => "add" - case MapBuilderBuild() | SetBuilderBuild() => "build" - }; - - generated := R.RawExpr( - (if receiver != "" then (receiver + " = ") else "") + - enclosingString + renderedName + typeArgString + "(" + argString + ");"); + newEnv := env; } - case Return(expr) => { - var expr, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); + case Return(exprDafny) => { + var expr, _, recIdents := GenExpr(exprDafny, selfIdent, env, OwnershipOwned); readIdents := recIdents; if isLast { @@ -2121,26 +2488,29 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else { generated := R.Return(Some(expr)); } + newEnv := env; } case EarlyReturn() => { generated := earlyReturn; readIdents := {}; + newEnv := env; } case Halt() => { - generated := R.RawExpr("panic!(\"Halt\");"); + generated := R.Identifier("panic!").Apply1(R.LiteralString("Halt", false, false)); readIdents := {}; + newEnv := env; } case Print(e) => { - var printedExpr, recOwnership, recIdents := GenExpr(e, selfIdent, params, OwnershipBorrowed); - var printedExprString := printedExpr.ToString(IND); - generated := R.RawExpr("print!(\"{}\", ::dafny_runtime::DafnyPrintWrapper(" + printedExprString + "));"); + 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)]); readIdents := recIdents; + newEnv := env; } } } - static const OpTable: map - := + static const OpTable: map := map[ Mod() := "%", And() := "&&", @@ -2181,8 +2551,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ensures resultingOwnership != OwnershipAutoBorrowed ensures expectedOwnership != OwnershipAutoBorrowed ==> resultingOwnership == expectedOwnership + ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { - if expectedOwnership == OwnershipOwned || expectedOwnership == OwnershipAutoBorrowed { + if expectedOwnership == OwnershipOwnedBox { + out := R.BoxNew(r); + resultingOwnership := OwnershipOwnedBox; + } else if expectedOwnership == OwnershipOwned || expectedOwnership == OwnershipAutoBorrowed { out := r; resultingOwnership := OwnershipOwned; } else if expectedOwnership == OwnershipBorrowed { @@ -2200,13 +2574,23 @@ module {:extern "DCOMP"} DafnyToRustCompiler { requires ownership != OwnershipAutoBorrowed ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { + if ownership == expectedOwnership { + out := r; + resultingOwnership := expectedOwnership; + return; + } if ownership == OwnershipOwned { out, resultingOwnership := FromOwned(r, expectedOwnership); return; + } else if ownership == OwnershipOwnedBox { + out, resultingOwnership := FromOwned(R.UnaryOp("*", r, Format.UnaryOpFormat.NoFormat), expectedOwnership); } else if ownership == OwnershipBorrowed || ownership == OwnershipBorrowedMut { - if expectedOwnership == OwnershipOwned { + if expectedOwnership == OwnershipOwned{ resultingOwnership := OwnershipOwned; out := R.Clone(r); + } else if expectedOwnership == OwnershipOwnedBox { + resultingOwnership := OwnershipOwnedBox; + out := R.BoxNew(R.Clone(r)); } else if expectedOwnership == ownership || expectedOwnership == OwnershipAutoBorrowed { resultingOwnership := ownership; @@ -2234,23 +2618,18 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenExprLiteral( e: Expression, selfIdent: Option, - params: seq, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Literal? + modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 { match e { - case Literal(BoolLiteral(false)) => { - r, resultingOwnership := - FromOwned(R.RawExpr("false"), expectedOwnership); - readIdents := {}; - return; - } - case Literal(BoolLiteral(true)) => { + case Literal(BoolLiteral(b)) => { r, resultingOwnership := - FromOwned(R.RawExpr("true"), expectedOwnership); + FromOwned(R.LiteralBool(b), expectedOwnership); readIdents := {}; return; } @@ -2258,10 +2637,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { match t { case Primitive(Int) => { if |i| <= 4 { - r := R.dafny_runtime.MSel("DafnyInt").MSel("from").Apply1(R.LiteralInt(i)); + r := R.dafny_runtime.MSel("int!").Apply1(R.LiteralInt(i)); } else { - r := R.dafny_runtime.MSel("DafnyInt").MSel("from").Apply1( - R.LiteralString(i, binary := true)); + r := R.dafny_runtime.MSel("int!").Apply1( + R.LiteralString(i, binary := true, verbatim := false)); } } case o => { @@ -2288,8 +2667,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := {}; return; } - case Literal(StringLiteral(l)) => { - r := R.dafny_runtime.MSel(string_of).Apply1(R.LiteralString(l, false)); + case Literal(StringLiteral(l, verbatim)) => { + if verbatim { + error := Some("Verbatim strings prefixed by @ not supported yet."); + } + r := R.dafny_runtime.MSel(string_of).Apply1(R.LiteralString(l, binary := false, verbatim := verbatim)); + r, resultingOwnership := FromOwned(r, expectedOwnership); + readIdents := {}; + return; + } + 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, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := {}; return; @@ -2302,7 +2692,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r := R.global.MSel("std").MSel("primitive") .MSel("char").MSel("from_u32") - .Apply1(r).Sel("unwrap").Apply([], []); + .Apply1(r).Sel("unwrap").Apply([]); } r := R.dafny_runtime.MSel(DafnyChar).Apply1(r); r, resultingOwnership := FromOwned(r, expectedOwnership); @@ -2323,10 +2713,11 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenExprBinary( e: Expression, selfIdent: Option, - params: seq, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.BinOp? + modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 { @@ -2352,6 +2743,17 @@ module {:extern "DCOMP"} DafnyToRustCompiler { }; var becomesCallLeftRight := match op { case Eq(true, false) => true + case SetMerge() => true + case SetSubtraction() => true + case SetIntersection() => true + case SetDisjoint() => true + case MapMerge() => true + case MapSubtraction() => true + case MultisetMerge() => true + case MultisetSubtraction() => true + case MultisetIntersection() => true + case MultisetDisjoint() => true + case Concat() => true case _ => false }; var expectedLeftOwnership := @@ -2362,8 +2764,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if becomesLeftCallsRight || becomesCallLeftRight then OwnershipBorrowed else if becomesRightCallsLeft then OwnershipAutoBorrowed else OwnershipOwned; - var left, _, recIdentsL := GenExpr(lExpr, selfIdent, params, expectedLeftOwnership); - var right, _, recIdentsR := GenExpr(rExpr, selfIdent, params, expectedRightOwnership); + var left, _, recIdentsL := GenExpr(lExpr, selfIdent, env, expectedLeftOwnership); + var right, _, recIdentsR := GenExpr(rExpr, selfIdent, env, expectedRightOwnership); match op { case In() => { @@ -2432,19 +2834,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if (referential) { // TODO: Render using a call with two expressions if (nullable) { - r := R.Call(R.RawExpr("::dafny_runtime::nullable_referential_equality"), [], [left, right]); + r := R.RawExpr("::dafny_runtime::nullable_referential_equality").Apply([left, right]); } else { - r := R.Call(R.RawExpr("::std::rc::Rc::ptr_eq"), [], [left, right]); + r := R.RawExpr("::std::rc::Rc::ptr_eq").Apply([left, right]); } } else { r := R.BinaryOp("==", left, right, DAST.Format.BinaryOpFormat.NoFormat()); } } case EuclidianDiv() => { - r := R.Call(R.RawExpr("::dafny_runtime::euclidian_division"), [], [left, right]); + r := R.RawExpr("::dafny_runtime::euclidian_division").Apply([left, right]); } case EuclidianMod() => { - r := R.Call(R.RawExpr("::dafny_runtime::euclidian_modulo"), [], [left, right]); + r := R.RawExpr("::dafny_runtime::euclidian_modulo").Apply([left, right]); } case Passthrough(op) => { r := R.Expr.BinaryOp(op, left, right, format); @@ -2461,22 +2863,23 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenExprConvertFromNullable( e: Expression, selfIdent: Option, - params: seq, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Convert? requires e.from != e.typ requires e.from.Nullable? + modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0, 0 { var Convert(expr, fromTpe, toTpe) := e; - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, params, expectedOwnership); + var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); r := recursiveGen; if recOwned == OwnershipOwned { - r := r.Sel("as_ref").Apply([], []); + r := r.Sel("as_ref").Apply([]); } - r := r.Sel("unwrap").Apply([], []); + r := r.Sel("unwrap").Apply([]); r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); readIdents := recIdents; } @@ -2484,23 +2887,24 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenExprConvertToNullable( e: Expression, selfIdent: Option, - params: seq, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Convert? requires e.from != e.typ requires !e.from.Nullable? && e.typ.Nullable? + modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0, 0 { var Convert(expr, fromTpe, toTpe) := e; - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, params, expectedOwnership); + var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); r := recursiveGen; if recOwned == OwnershipOwned { - r := r.Sel("clone").Apply([], []); + r := r.Sel("clone").Apply([]); } - r := R.std.MSel("option").MSel("Option").MSel("Some").Apply([], [r]); + r := R.std.MSel("option").MSel("Option").MSel("Some").Apply([r]); r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); readIdents := recIdents; } @@ -2508,24 +2912,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenExprConvertToNewtype( e: Expression, selfIdent: Option, - params: seq, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Convert? requires e.from != e.typ requires !e.from.Nullable? && e.typ.Path? && e.typ.resolved.Newtype? + modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0, 0 { var Convert(expr, fromTpe, toTpe) := e; - var Path(_, _, Newtype(b, range, erase)) := toTpe; + var Path(_, _, Newtype(b, range, erase, attributes)) := toTpe; + var nativeToType := NewtypeToRustType(b, range); if fromTpe == b { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, params, expectedOwnership); + var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); + readIdents := recIdents; - var potentialRhsType := NewtypeToRustType(b, range); - match potentialRhsType { + match nativeToType { case Some(v) => - r := R.ConversionNum(v, recursiveGen); + r := R.dafny_runtime.MSel("truncate!").Apply([recursiveGen, R.ExprFromType(v)]); r, resultingOwnership := FromOwned(r, expectedOwnership); case None => if erase { @@ -2536,60 +2942,83 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); } - readIdents := recIdents; assert OwnershipGuarantee(expectedOwnership, resultingOwnership); } else { assume {:axiom} Convert(Convert(expr, fromTpe, b), b, toTpe) < e; // make termination go through - r, resultingOwnership, readIdents := GenExpr(Convert(Convert(expr, fromTpe, b), b, toTpe), selfIdent, params, expectedOwnership); + r, resultingOwnership, readIdents := GenExpr(Convert(Convert(expr, fromTpe, b), b, toTpe), selfIdent, env, expectedOwnership); assert OwnershipGuarantee(expectedOwnership, resultingOwnership); } } - method GenExprConvertFromNewtype( e: Expression, selfIdent: Option, - params: seq, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Convert? requires e.from != e.typ requires !e.from.Nullable? && (!e.typ.Path? || !e.typ.resolved.Newtype?) requires e.from.Path? && e.from.resolved.Newtype? + modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0, 0 { var Convert(expr, fromTpe, toTpe) := e; - var Path(_, _, Newtype(b, range, erase)) := fromTpe; + var Path(_, _, Newtype(b, range, erase, attributes)) := fromTpe; + var nativeFromType := NewtypeToRustType(b, range); if b == toTpe { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, params, expectedOwnership); - if erase { - r := recursiveGen; - } else { - r := recursiveGen.Sel("0"); - } - r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); readIdents := recIdents; + match nativeFromType { + case Some(v) => + var toTpeRust := GenType(toTpe, false, false); + r := R.Identifier("Into").ApplyType([toTpeRust]).MSel("into").Apply([recursiveGen]); + r, resultingOwnership := FromOwned(r, expectedOwnership); + case None => + if erase { + r := recursiveGen; + } else { + r := recursiveGen.Sel("0"); + } + r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + } } else { + if nativeFromType.Some? { + // The case where toTpe is a NewType which compiles to a native integer has already been handled. + if toTpe == Primitive(Char) { + var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); + r, resultingOwnership := FromOwnership( + R.dafny_runtime.MSel(DafnyChar).Apply1( + R.TypeAscription(recursiveGen, DafnyCharUnderlying) + ), recOwned, expectedOwnership); + readIdents := recIdents; + return; + } + } assume {:axiom} Convert(Convert(expr, fromTpe, b), b, toTpe) < e; // make termination go through - r, resultingOwnership, readIdents := GenExpr(Convert(Convert(expr, fromTpe, b), b, toTpe), selfIdent, params, expectedOwnership); + r, resultingOwnership, readIdents := GenExpr(Convert(Convert(expr, fromTpe, b), b, toTpe), selfIdent, env, expectedOwnership); } - assert OwnershipGuarantee(expectedOwnership, resultingOwnership); } method GenExprConvertNotImplemented( e: Expression, selfIdent: Option, - params: seq, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Convert? + modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0, 0 { var Convert(expr, fromTpe, toTpe) := e; - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, params, expectedOwnership); - r := R.RawExpr("(" + recursiveGen.ToString(IND) + "/* conversion not yet implemented */)"); + var fromTpeGen := GenType(fromTpe, true, false); + var toTpeGen := GenType(toTpe, true, false); + var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); + var msg := "/* Coercion from " + fromTpeGen.ToString(IND) + " to " + toTpeGen.ToString(IND) + " not yet implemented */"; + error := Some(msg); + r := R.RawExpr(recursiveGen.ToString(IND) + msg); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; } @@ -2597,75 +3026,76 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenExprConvert( e: Expression, selfIdent: Option, - params: seq, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Convert? + modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 { var Convert(expr, fromTpe, toTpe) := e; if fromTpe == toTpe { - var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, params, expectedOwnership); + var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, expectedOwnership); r := recursiveGen; r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); readIdents := recIdents; } else { match (fromTpe, toTpe) { case (Nullable(_), _) => { - r, resultingOwnership, readIdents := GenExprConvertFromNullable(e, selfIdent, params, expectedOwnership); + r, resultingOwnership, readIdents := GenExprConvertFromNullable(e, selfIdent, env, expectedOwnership); } case (_, Nullable(_)) => { - r, resultingOwnership, readIdents := GenExprConvertToNullable(e, selfIdent, params, expectedOwnership); + r, resultingOwnership, readIdents := GenExprConvertToNullable(e, selfIdent, env, expectedOwnership); } - case (_, Path(_, _, Newtype(b, range, erase))) => { - r, resultingOwnership, readIdents := GenExprConvertToNewtype(e, selfIdent, params, expectedOwnership); + case (_, Path(_, _, Newtype(b, range, erase, attributes))) => { + r, resultingOwnership, readIdents := GenExprConvertToNewtype(e, selfIdent, env, expectedOwnership); } - case (Path(_, _, Newtype(b, range, erase)), _) => { - r, resultingOwnership, readIdents := GenExprConvertFromNewtype(e, selfIdent, params, expectedOwnership); + case (Path(_, _, Newtype(b, range, erase, attributes)), _) => { + r, resultingOwnership, readIdents := GenExprConvertFromNewtype(e, selfIdent, env, expectedOwnership); } case (Primitive(Int), Primitive(Real)) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); r := R.RcNew(R.RawExpr("::dafny_runtime::BigRational::from_integer(" + recursiveGen.ToString(IND) + ")")); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; } case (Primitive(Real), Primitive(Int)) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipBorrowed); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipBorrowed); r := R.RawExpr("::dafny_runtime::dafny_rational_to_int(" + recursiveGen.ToString(IND) + ")"); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; } case (Primitive(Int), Passthrough(_)) => { var rhsType := GenType(toTpe, true, false); - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); + 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, true, false); - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); r := R.RawExpr("::dafny_runtime::DafnyInt{data: ::dafny_runtime::BigInt::from(" + recursiveGen.ToString(IND) + ")}"); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; } case (Primitive(Int), Primitive(Char)) => { var rhsType := GenType(toTpe, true, false); - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); r := R.RawExpr("char::from_u32(::from(" + recursiveGen.ToString(IND) + ").unwrap()).unwrap()"); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; } case (Primitive(Char), Primitive(Int)) => { var rhsType := GenType(fromTpe, true, false); - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); - r := R.RawExpr("::dafny_runtime::DafnyInt{data: ::BigInt::from(" + recursiveGen.ToString(IND) + " as u32)}"); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); + r := R.dafny_runtime.MSel("int!").Apply1(recursiveGen.Sel("0")); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; } case (Passthrough(_), Passthrough(_)) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); var toTpeGen := GenType(toTpe, true, false); r := R.RawExpr("((" + recursiveGen.ToString(IND) + ") as " + toTpeGen.ToString(IND) + ")"); @@ -2674,52 +3104,80 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := recIdents; } case _ => { - r, resultingOwnership, readIdents := GenExprConvertNotImplemented(e, selfIdent, params, expectedOwnership); + r, resultingOwnership, readIdents := GenExprConvertNotImplemented(e, selfIdent, env, expectedOwnership); } } } assert OwnershipGuarantee(expectedOwnership, resultingOwnership); return; } + + method GenIdent( + rName: string, + selfIdent: Option, + env: Environment, + expectedOwnership: Ownership + ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) + modifies this + ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) + { + r := R.Identifier(rName); + var tpe := env.GetType(rName); + var currentlyBorrowed := env.IsBorrowed(rName); // Otherwise names are owned + var noNeedOfClone := env.CanReadWithoutClone(rName); + if expectedOwnership == OwnershipAutoBorrowed { + resultingOwnership := OwnershipOwned; + // No need to do anything + } else if expectedOwnership == OwnershipBorrowedMut { + r := R.BorrowMut(r); // Needs to be explicit for out-parameters on methods + resultingOwnership := OwnershipBorrowedMut; + } else if expectedOwnership == OwnershipOwned { + if !noNeedOfClone { + r := R.Clone(r); // We don't transfer the ownership of an identifier + } + resultingOwnership := OwnershipOwned; + } else if expectedOwnership == OwnershipOwnedBox { + if !noNeedOfClone { + r := R.Clone(r); // We don't transfer the ownership of an identifier + } + r := R.BoxNew(r); + resultingOwnership := OwnershipOwnedBox; + } else if currentlyBorrowed { + assert expectedOwnership == OwnershipBorrowed; + resultingOwnership := OwnershipBorrowed; + } else { + // It's currently owned. If it's a pointer, we need to convert it to a borrow + r := R.Borrow(r); // Needs to be explicit for out-parameters on methods + resultingOwnership := OwnershipBorrowed; + } + readIdents := {rName}; + return; + } method GenExpr( e: Expression, selfIdent: Option, - params: seq, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) + modifies this decreases e, 1 { match e { case Literal(_) => r, resultingOwnership, readIdents := - GenExprLiteral(e, selfIdent, params, expectedOwnership); + GenExprLiteral(e, selfIdent, env, expectedOwnership); case Ident(name) => { - r := R.Identifier(escapeIdent(name)); - var currentlyBorrowed := name in params; // Otherwise names are owned // TODO(mikael) have a table to know which names are borrowed - if expectedOwnership == OwnershipAutoBorrowed { - resultingOwnership := OwnershipOwned; - // No need to do anything - } else if expectedOwnership == OwnershipBorrowedMut { - r := R.BorrowMut(r); // Needs to be explicit for out-parameters on methods - resultingOwnership := OwnershipBorrowedMut; + r, resultingOwnership, readIdents := GenIdent(escapeName(name), selfIdent, env, expectedOwnership); + } + case Companion(path) => { + r := GenPathExpr(path); + if expectedOwnership == OwnershipBorrowed { + resultingOwnership := OwnershipBorrowed; } else if expectedOwnership == OwnershipOwned { - r := R.Clone(r); // We don't transfer the ownership of an identifier resultingOwnership := OwnershipOwned; - } else if currentlyBorrowed { - assert expectedOwnership == OwnershipBorrowed; - resultingOwnership := OwnershipBorrowed; } else { - // It's currently owned. - r := R.Borrow(r); - resultingOwnership := OwnershipBorrowed; + r, resultingOwnership := FromOwned(r, expectedOwnership); } - readIdents := {name}; - return; - } - case Companion(path) => { - var p := GenPath(path); - r := R.RawExpr(p); - r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := {}; return; } @@ -2731,59 +3189,40 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case Tuple(values) => { - var s := "("; + var exprs := []; readIdents := {}; - var i := 0; - while i < |values| { - if i > 0 { - s := s + " "; - } - - var recursiveGen, _, recIdents := GenExpr(values[i], selfIdent, params, OwnershipOwned); - - s := s + recursiveGen.ToString(IND) + ","; + for i := 0 to |values| { + var recursiveGen, _, recIdents := GenExpr(values[i], selfIdent, env, OwnershipOwned); + exprs := exprs + [recursiveGen]; readIdents := readIdents + recIdents; - - i := i + 1; } - s := s + ")"; - r := R.RawExpr(s); + r := if |values| <= R.MAX_TUPLE_SIZE then R.Tuple(exprs) else R.SystemTuple(exprs); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case New(path, typeArgs, args) => { - var path := GenPath(path); - // TODO(Mikael) Use allocate(...) here. - var s := "::std::rc::Rc::new(" + path; + // args are provided if it is an extern type + r := GenPathExpr(path); if |typeArgs| > 0 { - var i := 0; var typeExprs := []; - while i < |typeArgs| { + for i := 0 to |typeArgs| { var typeExpr := GenType(typeArgs[i], false, false); typeExprs := typeExprs + [typeExpr]; - - i := i + 1; } - s := s + R.TypeApp(R.TIdentifier("::"), typeExprs).ToString(IND); + r := r.ApplyType(typeExprs); } - s := s + "::new("; - readIdents := {}; - var i := 0; - while i < |args| { - if i > 0 { - s := s + ", "; - } + r := r.MSel("new"); - var recursiveGen, _, recIdents := GenExpr(args[i], selfIdent, params, OwnershipOwned); - s := s + recursiveGen.ToString(IND); + readIdents := {}; + var arguments := []; + for i := 0 to |args| { + var recursiveGen, _, recIdents := GenExpr(args[i], selfIdent, env, OwnershipOwned); + arguments := arguments + [recursiveGen]; readIdents := readIdents + recIdents; - - i := i + 1; } - s := s + "))"; - r := R.RawExpr(s); + r := r.Apply(arguments); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } @@ -2794,7 +3233,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var s := "<" + genTyp.ToString(IND) + " as ::std::default::Default>::default()"; readIdents := {}; while i >= 0 { - var recursiveGen, _, recIdents := GenExpr(dims[i], selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(dims[i], selfIdent, env, OwnershipOwned); s := "::std::rc::Rc::new(::std::cell::RefCell::new(vec![" + s + "; ::from(" + recursiveGen.ToString(IND) + ").unwrap()]))"; readIdents := readIdents + recIdents; @@ -2806,69 +3245,58 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r, resultingOwnership := FromOwned(r, expectedOwnership); return; } - case DatatypeValue(path, typeArgs, variant, isCo, values) => { - var path := GenPath(path); - var s := "::std::rc::Rc::new(" + path + "::"; + case DatatypeValue(datatypeType, typeArgs, variant, isCo, values) => { + r := GenPathExpr(datatypeType.path); + var genTypeArgs := []; + for i := 0 to |typeArgs| { + var typeExpr := GenType(typeArgs[i], false, false); + genTypeArgs := genTypeArgs + [typeExpr]; + } if |typeArgs| > 0 { - s := s + "<"; - var i := 0; - while i < |typeArgs| { - if i > 0 { - s := s + ", "; - } - - var typeExpr := GenType(typeArgs[i], false, false); - s := s + typeExpr.ToString(IND); - - i := i + 1; - } - s := s + ">::"; + r := r.ApplyType(genTypeArgs); } - s := s + escapeIdent(variant); + r := r.MSel(escapeName(variant)); readIdents := {}; - var i := 0; - s := s + " {"; - while i < |values| { + var assignments: seq := []; + for i := 0 to |values| { var (name, value) := values[i]; - if i > 0 { - s := s + ", "; - } if isCo { - var recursiveGen, _, recIdents := GenExpr(value, selfIdent, [], OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(value, selfIdent, Environment.Empty(), OwnershipOwned); readIdents := readIdents + recIdents; var allReadCloned := ""; while recIdents != {} decreases recIdents { var next: string :| next in recIdents; - allReadCloned := allReadCloned + "let " + escapeIdent(next) + " = " + escapeIdent(next) + ".clone();\n"; + allReadCloned := allReadCloned + "let " + next + " = " + next + ".clone();\n"; recIdents := recIdents - {next}; } - s := s + escapeIdent(name) + ": ::dafny_runtime::LazyFieldWrapper(::dafny_runtime::Lazy::new(::std::boxed::Box::new({\n" + allReadCloned + "move || (" + recursiveGen.ToString(IND) + ")})))"; + var wasAssigned: string := "::dafny_runtime::LazyFieldWrapper(::dafny_runtime::Lazy::new(::std::boxed::Box::new({\n" + allReadCloned + "move || (" + recursiveGen.ToString(IND) + ")})))"; + assignments := assignments + [R.AssignIdentifier(name, R.RawExpr(wasAssigned))]; } else { - var recursiveGen, _, recIdents := GenExpr(value, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(value, selfIdent, env, OwnershipOwned); - s := s + escapeIdent(name) + ": " + "(" + recursiveGen.ToString(IND) + ")"; + assignments := assignments + [R.AssignIdentifier(name, recursiveGen)]; readIdents := readIdents + recIdents; } - i := i + 1; } - s := s + " })"; - - r := R.RawExpr(s); + r := R.StructBuild(r, assignments); + if IsRcWrapped(datatypeType.attributes) { + r := R.RcNew(r); + } r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case Convert(_, _, _) => { r, resultingOwnership, readIdents := - GenExprConvert(e, selfIdent, params, expectedOwnership); + GenExprConvert(e, selfIdent, env, expectedOwnership); } case SeqConstruct(length, expr) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); - var lengthGen, _, lengthIdents := GenExpr(length, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); + var lengthGen, _, lengthIdents := GenExpr(length, selfIdent, env, OwnershipOwned); - r := R.RawExpr("{\nlet _initializer = " + recursiveGen.ToString(IND) + ";\n::dafny_runtime::integer_range(::dafny_runtime::Zero::zero(), " + lengthGen.ToString(IND) + ").map(|i| _initializer.0(&i)).collect::<::dafny_runtime::Sequence<_>>()\n}"); + r := R.RawExpr("{\nlet _initializer = " + recursiveGen.ToString(IND) + ";\n::dafny_runtime::integer_range(::dafny_runtime::Zero::zero(), " + lengthGen.ToString(IND) + ").map(|i| _initializer(&i)).collect::<::dafny_runtime::Sequence<_>>()\n}"); readIdents := recIdents + lengthIdents; r, resultingOwnership := FromOwned(r, expectedOwnership); @@ -2882,13 +3310,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var i := 0; var args := []; while i < |exprs| { - var recursiveGen, _, recIdents := GenExpr(exprs[i], selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(exprs[i], selfIdent, env, OwnershipOwned); readIdents := readIdents + recIdents; args := args + [recursiveGen]; i := i + 1; } - r := R.dafny_runtime.MSel("seq!").Apply([], args); + r := R.dafny_runtime.MSel("seq!").Apply(args); if |args| == 0 { r := R.TypeAscription(r, R.dafny_runtime_type.MSel("Sequence").Apply1(genTpe)); @@ -2901,13 +3329,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := {}; var i := 0; while i < |exprs| { - var recursiveGen, _, recIdents := GenExpr(exprs[i], selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(exprs[i], selfIdent, env, OwnershipOwned); generatedValues := generatedValues + [recursiveGen]; readIdents := readIdents + recIdents; i := i + 1; } - r := R.dafny_runtime.MSel("set!").Apply([], generatedValues); + r := R.dafny_runtime.MSel("set!").Apply(generatedValues); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } @@ -2916,19 +3344,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := {}; var i := 0; while i < |exprs| { - var recursiveGen, _, recIdents := GenExpr(exprs[i], selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(exprs[i], selfIdent, env, OwnershipOwned); generatedValues := generatedValues + [recursiveGen]; readIdents := readIdents + recIdents; i := i + 1; } - r := R.dafny_runtime.MSel("multiset!").Apply([], generatedValues); + r := R.dafny_runtime.MSel("multiset!").Apply(generatedValues); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case ToMultiset(expr) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipAutoBorrowed); - r := recursiveGen.Sel("as_dafny_multiset").Apply([], []); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); + r := recursiveGen.Sel("as_dafny_multiset").Apply([]); readIdents := recIdents; r, resultingOwnership := FromOwned(r, expectedOwnership); return; @@ -2938,8 +3366,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := {}; var i := 0; while i < |mapElems| { - var recursiveGenKey, _, recIdentsKey := GenExpr(mapElems[i].0, selfIdent, params, OwnershipOwned); - var recursiveGenValue, _, recIdentsValue := GenExpr(mapElems[i].1, selfIdent, params, OwnershipOwned); + var recursiveGenKey, _, recIdentsKey := GenExpr(mapElems[i].0, selfIdent, env, OwnershipOwned); + var recursiveGenValue, _, recIdentsValue := GenExpr(mapElems[i].1, selfIdent, env, OwnershipOwned); generatedValues := generatedValues + [(recursiveGenKey, recursiveGenValue)]; readIdents := readIdents + recIdentsKey + recIdentsValue; @@ -2955,26 +3383,24 @@ 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!").Apply(arguments); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case SeqUpdate(expr, index, value) => { - var exprR, _, exprIdents := GenExpr(expr, selfIdent, params, OwnershipAutoBorrowed); - var indexR, indexOwnership, indexIdents := GenExpr(index, selfIdent, params, OwnershipBorrowed); - var valueR, valueOwnership, valueIdents := GenExpr(value, selfIdent, params, OwnershipBorrowed); - r := exprR.Sel("update_index").Apply([], [indexR, valueR]); + var exprR, _, exprIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); + var indexR, indexOwnership, indexIdents := GenExpr(index, selfIdent, env, OwnershipBorrowed); + var valueR, valueOwnership, valueIdents := GenExpr(value, selfIdent, env, OwnershipBorrowed); + r := exprR.Sel("update_index").Apply([indexR, valueR]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := exprIdents + indexIdents + valueIdents; return; } case MapUpdate(expr, index, value) => { - var exprR, _, exprIdents := GenExpr(expr, selfIdent, params, OwnershipAutoBorrowed); - var indexR, indexOwnership, indexIdents := GenExpr(index, selfIdent, params, OwnershipBorrowed); - var valueR, valueOwnership, valueIdents := GenExpr(value, selfIdent, params, OwnershipBorrowed); - r := exprR.Sel("update_index").Apply([], [indexR, valueR]); + var exprR, _, exprIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); + var indexR, indexOwnership, indexIdents := GenExpr(index, selfIdent, env, OwnershipBorrowed); + var valueR, valueOwnership, valueIdents := GenExpr(value, selfIdent, env, OwnershipBorrowed); + r := exprR.Sel("update_index").Apply([indexR, valueR]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := exprIdents + indexIdents + valueIdents; return; @@ -2982,10 +3408,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case This() => { match selfIdent { case Some(id) => { - r := R.RawExpr(id); + r := R.Identifier(id); if expectedOwnership == OwnershipOwned { r := R.Clone(r); resultingOwnership := OwnershipOwned; + } else if expectedOwnership == OwnershipOwnedBox { + r := R.BoxNew(R.Clone(r)); + resultingOwnership := OwnershipOwnedBox; } else if expectedOwnership == OwnershipBorrowed || expectedOwnership == OwnershipAutoBorrowed { if id != "self" { r := R.Borrow(r); @@ -3011,13 +3440,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } case Ite(cond, t, f) => { assert {:split_here} true; - var cond, _, recIdentsCond := GenExpr(cond, selfIdent, params, OwnershipOwned); + var cond, _, recIdentsCond := GenExpr(cond, selfIdent, env, OwnershipOwned); var condString := cond.ToString(IND); - var _, tHasToBeOwned, _ := GenExpr(t, selfIdent, params, expectedOwnership); // check if t has to be owned even if not requested - var fExpr, fOwned, recIdentsF := GenExpr(f, selfIdent, params, tHasToBeOwned); + var _, tHasToBeOwned, _ := GenExpr(t, selfIdent, env, expectedOwnership); // check if t has to be owned even if not requested + var fExpr, fOwned, recIdentsF := GenExpr(f, selfIdent, env, tHasToBeOwned); var fString := fExpr.ToString(IND); - var tExpr, _, recIdentsT := GenExpr(t, selfIdent, params, fOwned); // there's a chance that f forced ownership + var tExpr, _, recIdentsT := GenExpr(t, selfIdent, env, fOwned); // there's a chance that f forced ownership var tString := tExpr.ToString(IND); r := R.RawExpr("(if " + condString + " {\n" + tString + "\n} else {\n" + fString + "\n})"); @@ -3027,7 +3456,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case UnOp(Not, e, format) => { - var recursiveGen, _, recIdents := GenExpr(e, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(e, selfIdent, env, OwnershipOwned); r := R.UnaryOp("!", recursiveGen, format); r, resultingOwnership := FromOwned(r, expectedOwnership); @@ -3035,7 +3464,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case UnOp(BitwiseNot, e, format) => { - var recursiveGen, _, recIdents := GenExpr(e, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(e, selfIdent, env, OwnershipOwned); r := R.UnaryOp("~", recursiveGen, format); r, resultingOwnership := FromOwned(r, expectedOwnership); @@ -3043,18 +3472,18 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case UnOp(Cardinality, e, format) => { - var recursiveGen, recOwned, recIdents := GenExpr(e, selfIdent, params, OwnershipAutoBorrowed); + var recursiveGen, recOwned, recIdents := GenExpr(e, selfIdent, env, OwnershipAutoBorrowed); - r := recursiveGen.Sel("cardinality").Apply([], []); + r := recursiveGen.Sel("cardinality").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; } case BinOp(_, _, _, _) => r, resultingOwnership, readIdents := - GenExprBinary(e, selfIdent, params, expectedOwnership); + GenExprBinary(e, selfIdent, env, expectedOwnership); case ArrayLen(expr, dim) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); if dim == 0 { r := R.RawExpr("::dafny_runtime::BigInt::from((" + recursiveGen.ToString(IND) + ").borrow().len())"); @@ -3073,26 +3502,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case MapKeys(expr) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); readIdents := recIdents; - r := R.Call(recursiveGen.Sel("keys"), [], []); + r := recursiveGen.Sel("keys").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case MapValues(expr) => { - var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, params, OwnershipOwned); + var recursiveGen, _, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); readIdents := recIdents; - r := R.Call(recursiveGen.Sel("values"), [], []); + r := recursiveGen.Sel("values").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case SelectFn(on, field, isDatatype, isStatic, arity) => { - var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, params, OwnershipBorrowed); + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); var s: string; var onString := onExpr.ToString(IND); if isStatic { - s := onString + "::" + escapeIdent(field); + s := onString + "::" + escapeName(field); } else { s := "{\n"; s := s + "let callTarget = (" + onString + (if onOwned == OwnershipOwned then ")" else ").clone()") + ";\n"; @@ -3106,7 +3535,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { i := i + 1; } s := s + "move |" + args + "| {\n"; - s := s + "callTarget." + field + "(" + args + ")\n"; + s := s + "callTarget." + escapeName(field) + "(" + args + ")\n"; s := s + "}\n"; s := s + "}"; } @@ -3123,46 +3552,57 @@ module {:extern "DCOMP"} DafnyToRustCompiler { typeShape := typeShape + ") -> _"; - s := "::dafny_runtime::FunctionWrapper(::std::rc::Rc::new(" + s + ") as ::std::rc::Rc<" + typeShape + ">)"; + s := "::std::rc::Rc::new(" + s + ") as ::std::rc::Rc<" + typeShape + ">"; r := R.RawExpr(s); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; } - case Select(Companion(c), field, isConstant, isDatatype) => { - var onExpr, onOwned, recIdents := GenExpr(Companion(c), selfIdent, params, OwnershipBorrowed); + case Select(Companion(c), field, isConstant, isDatatype, fieldType) => { + var onExpr, onOwned, recIdents := GenExpr(Companion(c), selfIdent, env, OwnershipBorrowed); - r := R.RawExpr(onExpr.ToString(IND) + "::" + escapeIdent(field) + "()"); + r := onExpr.MSel(escapeName(field)).Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; } - case Select(on, field, isConstant, isDatatype) => { - var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, params, OwnershipBorrowed); - if isDatatype || isConstant { - r := R.Call(onExpr.Sel(escapeIdent(field)), [], []); - r, resultingOwnership := FromOwned(r, expectedOwnership); + case Select(on, field, isConstant, isDatatype, fieldType) => { + if isDatatype { + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + r := onExpr.Sel(escapeName(field)).Apply([]); + var typ := GenType(fieldType, false, false); + // All fields are returned as addresses for now until we have something more clever + r, resultingOwnership := FromOwnership(r, OwnershipBorrowed, expectedOwnership); + readIdents := recIdents; } else { - var s: string; - s := "::std::ops::Deref::deref(&((" + onExpr.ToString(IND) + ")" + "." + escapeIdent(field) + ".borrow()))"; - r, resultingOwnership := FromOwnership(R.RawExpr(s), OwnershipBorrowed, expectedOwnership); + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + r := onExpr; + r := r.Sel(escapeName(field)); + if isConstant { + r := r.Apply([]); + } else { + var s := "::std::ops::Deref::deref(&((" + onExpr.ToString(IND) + ")" + "." + escapeName(field) + ".borrow()))"; + r := R.RawExpr(s); + } + var fromOwnership := if isConstant then OwnershipOwned else OwnershipBorrowed; + r, resultingOwnership := FromOwnership(r, fromOwnership, expectedOwnership); + readIdents := recIdents; } - readIdents := recIdents; return; } case Index(on, collKind, indices) => { assert {:split_here} true; - var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, params, OwnershipAutoBorrowed); + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); readIdents := recIdents; r := onExpr; var i := 0; while i < |indices| { if collKind == CollKind.Array { - r := r.Sel("borrow").Apply([], []); + r := r.Sel("borrow").Apply([]); } - var idx, idxOwned, recIdentsIdx := GenExpr(indices[i], selfIdent, params, OwnershipBorrowed); + var idx, idxOwned, recIdentsIdx := GenExpr(indices[i], selfIdent, env, OwnershipBorrowed); r := r.Sel("get").Apply1(idx); readIdents := readIdents + recIdentsIdx; i := i + 1; @@ -3171,7 +3611,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case IndexRange(on, isArray, low, high) => { - var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, params, OwnershipAutoBorrowed); + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); readIdents := recIdents; var methodName := if low.Some? then @@ -3181,7 +3621,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var arguments := []; match low { case Some(l) => { - var lExpr, _, recIdentsL := GenExpr(l, selfIdent, params, OwnershipBorrowed); + var lExpr, _, recIdentsL := GenExpr(l, selfIdent, env, OwnershipBorrowed); arguments := arguments + [lExpr]; readIdents := readIdents + recIdentsL; } @@ -3190,7 +3630,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { match high { case Some(h) => { - var hExpr, _, recIdentsH := GenExpr(h, selfIdent, params, OwnershipBorrowed); + var hExpr, _, recIdentsH := GenExpr(h, selfIdent, env, OwnershipBorrowed); arguments := arguments + [hExpr]; readIdents := readIdents + recIdentsH; } @@ -3202,18 +3642,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if methodName != "" { methodName := "_" + methodName; } - r := R.dafny_runtime_Sequence.MSel("from_array"+methodName).Apply([], arguments); + r := R.dafny_runtime_Sequence.MSel("from_array"+methodName).Apply(arguments); } else { if methodName != "" { - r := r.Sel(methodName).Apply([], arguments); + r := r.Sel(methodName).Apply(arguments); } } r, resultingOwnership := FromOwned(r, expectedOwnership); return; } - case TupleSelect(on, idx) => { - var onExpr, onOwnership, recIdents := GenExpr(on, selfIdent, params, OwnershipAutoBorrowed); - r := onExpr.Sel(Strings.OfNat(idx)); + case TupleSelect(on, idx, fieldType) => { + var onExpr, onOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + var selName := Strings.OfNat(idx); // Rust tuples + match fieldType { + case Tuple(tps) => + if fieldType.Tuple? && |tps| > R.MAX_TUPLE_SIZE { + selName := "_" + selName; // R.SystemTuple + } + case _ => + } + r := onExpr.Sel(selName); r, resultingOwnership := FromOwnership(r, onOwnership, expectedOwnership); readIdents := recIdents; return; @@ -3221,32 +3669,34 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Call(on, name, typeArgs, args) => { readIdents := {}; + var onExpr, _, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + var typeExprs := []; if (|typeArgs| >= 1) { - var typeI := 0; - while typeI < |typeArgs| { - + for typeI := 0 to |typeArgs| { var typeExpr := GenType(typeArgs[typeI], false, false); typeExprs := typeExprs + [typeExpr]; - - typeI := typeI + 1; } } var argExprs := []; - var i := 0; - while i < |args| { - var argExpr, argOwnership, argIdents := GenExpr(args[i], selfIdent, params, OwnershipBorrowed); + for i := 0 to |args| { + var argOwnership := OwnershipBorrowed; + if name.CallName? && i < |name.signature.parameters| { + var tpe := GenType(name.signature.parameters[i].typ, false, false); + if tpe.CanReadWithoutClone() { + argOwnership := OwnershipOwned; + } + } + + var argExpr, _, argIdents := GenExpr(args[i], selfIdent, env, argOwnership); argExprs := argExprs + [argExpr]; readIdents := readIdents + argIdents; - - i := i + 1; } - var onExpr, _, recIdents := GenExpr(on, selfIdent, params, OwnershipAutoBorrowed); readIdents := readIdents + recIdents; var renderedName := match name { - case Name(ident) => escapeIdent(ident) + case CallName(ident, _, _) => escapeName(ident) case MapBuilderAdd | SetBuilderAdd => "add" case MapBuilderBuild | SetBuilderBuild => "build" }; @@ -3258,140 +3708,120 @@ module {:extern "DCOMP"} DafnyToRustCompiler { onExpr := onExpr.Sel(renderedName); } } - - r := R.Call(onExpr, typeExprs, argExprs); + r := onExpr; + if |typeExprs| > 0 { + r := r.ApplyType(typeExprs); + } + r := r.Apply(argExprs); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } - case Lambda(params, retType, body) => { + case Lambda(paramsDafny, retType, body) => { + var params := GenParams(paramsDafny); var paramNames := []; - var i := 0; - while i < |params| { - paramNames := paramNames + [params[i].name]; - i := i + 1; + var paramTypesMap := map[]; + for i := 0 to |params| { + var name := params[i].name; + paramNames := paramNames + [name]; + paramTypesMap := paramTypesMap[name := params[i].tpe]; } + var env := Environment(paramNames, paramTypesMap); - var recursiveGen, recIdents := GenStmts(body, if selfIdent != None then Some("_this") else None, paramNames, true, R.RawExpr("")); + var recursiveGen, recIdents, _ := GenStmts(body, if selfIdent != None then Some("_this") else None, env, true, R.RawExpr("")); readIdents := {}; - var allReadCloned := ""; + recIdents := recIdents - (set name <- paramNames); + var allReadCloned := R.RawExpr(""); while recIdents != {} decreases recIdents { var next: string :| next in recIdents; if selfIdent != None && next == "_this" { if selfIdent != None { - allReadCloned := allReadCloned + "let _this = self.clone();\n"; + allReadCloned := allReadCloned.Then(R.DeclareVar(R.MUT, "_this", None, Some(R.self.Sel("clone").Apply([])))); } } else if !(next in paramNames) { - allReadCloned := allReadCloned + "let " + escapeIdent(next) + " = " + escapeIdent(next) + ".clone();\n"; + allReadCloned := allReadCloned.Then( + R.DeclareVar(R.MUT, next, None, Some(R.Identifier(next).Sel("clone").Apply([]))) + ); readIdents := readIdents + {next}; } recIdents := recIdents - {next}; } - var paramsString := ""; - var paramTypes := ""; - i := 0; - while i < |params| { - if i > 0 { - paramsString := paramsString + ", "; - paramTypes := paramTypes + ", "; - } - - var typStr := GenType(params[i].typ, false, true); - - paramsString := paramsString + escapeIdent(params[i].name) + ": " + R.Borrowed(typStr).ToString(IND); - paramTypes := paramTypes + R.Borrowed(typStr).ToString(IND); - i := i + 1; - } - var retTypeGen := GenType(retType, false, true); - - r := R.RawExpr("::dafny_runtime::FunctionWrapper::<::std::rc::Rc " + retTypeGen.ToString(IND) + ">>({\n" + allReadCloned + "::std::rc::Rc::new(move |" + paramsString + "| -> " + retTypeGen.ToString(IND) + " {\n" + recursiveGen.ToString(IND) + "\n})})"); + r := R.Block( + allReadCloned.Then( + R.RcNew( + R.Lambda(params, Some(retTypeGen), R.Block(recursiveGen)) + ) + )); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case BetaRedex(values, retType, expr) => { var paramNames := []; + var paramFormals := GenParams(Std.Collections.Seq.Map( + (value: (Formal, Expression)) => value.0, values)); + var paramTypes := map[]; var paramNamesSet := {}; - var i := 0; - while i < |values| { - paramNames := paramNames + [values[i].0.name]; - paramNamesSet := paramNamesSet + {values[i].0.name}; - i := i + 1; + for i := 0 to |values| { + var name := values[i].0.name; + var rName := escapeName(name); + paramNames := paramNames + [rName]; + paramTypes := paramTypes[rName := paramFormals[i].tpe]; + paramNamesSet := paramNamesSet + {rName}; } readIdents := {}; - var s := "{\n"; + r := R.RawExpr(""); - var paramsString := ""; - i := 0; - while i < |values| { - if i > 0 { - paramsString := paramsString + ", "; - } + for i := 0 to |values| { + var typeGen := GenType(values[i].0.typ, false, true); - var typStr := GenType(values[i].0.typ, false, true); - - var valueGen, _, recIdents := GenExpr(values[i].1, selfIdent, params, OwnershipOwned); - s := s + "let " + escapeIdent(values[i].0.name) + ": " + typStr.ToString(IND) + " = "; + 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))); readIdents := readIdents + recIdents; - - s := s + valueGen.ToString(IND) + ";\n"; - i := i + 1; } - var recGen, recOwned, recIdents := GenExpr(expr, selfIdent, paramNames, expectedOwnership); - readIdents := recIdents - paramNamesSet; + var newEnv := Environment(paramNames, paramTypes); - s := s + recGen.ToString(IND) + "\n}"; - r := R.RawExpr(s); + var recGen, recOwned, recIdents := GenExpr(expr, selfIdent, newEnv, expectedOwnership); + readIdents := recIdents - paramNamesSet; + r := R.Block(r.Then(recGen)); r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); return; } case IIFE(name, tpe, value, iifeBody) => { - var valueGen, _, recIdents := GenExpr(value, selfIdent, params, OwnershipOwned); + var valueGen, _, recIdents := GenExpr(value, selfIdent, env, OwnershipOwned); readIdents := recIdents; var valueTypeGen := GenType(tpe, false, true); - var bodyGen, _, bodyIdents := GenExpr(iifeBody, selfIdent, params, OwnershipOwned); - readIdents := readIdents + (bodyIdents - {name.id}); - - r := R.RawExpr("{\nlet " + escapeIdent(name.id) + ": " + valueTypeGen.ToString(IND) + " = " + valueGen.ToString(IND) + ";\n" + bodyGen.ToString(IND) + "\n}"); + var bodyGen, _, bodyIdents := GenExpr(iifeBody, selfIdent, env, OwnershipOwned); + readIdents := readIdents + (bodyIdents - {escapeName(name.id)}); + r := R.Block( + R.DeclareVar(R.CONST, escapeName(name.id), Some(valueTypeGen), Some(valueGen)) + .Then(bodyGen)); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case Apply(func, args) => { - var funcExpr, _, recIdents := GenExpr(func, selfIdent, params, OwnershipBorrowed); + // TODO: Need the type of the input of Func to ensure we generate arguments with the right ownership + var funcExpr, _, recIdents := GenExpr(func, selfIdent, env, OwnershipBorrowed); readIdents := recIdents; - - var argString := ""; - var i := 0; - while i < |args| { - if i > 0 { - argString := argString + ", "; - } - - var argExpr, argOwned, argIdents := GenExpr(args[i], selfIdent, params, OwnershipBorrowed); - var argExprString := argExpr.ToString(IND); - if argOwned == OwnershipOwned { - argExprString := "&" + argExprString; - } - - argString := argString + argExprString; + var rArgs := []; + for i := 0 to |args| { + var argExpr, argOwned, argIdents := GenExpr(args[i], selfIdent, env, OwnershipBorrowed); + rArgs := rArgs + [argExpr]; readIdents := readIdents + argIdents; - - i := i + 1; } - - r := R.RawExpr("((" + funcExpr.ToString(IND) + ").0" + "(" + argString + "))"); + r := funcExpr.Apply(rArgs); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } case TypeTest(on, dType, variant) => { - var exprGen, _, recIdents := GenExpr(on, selfIdent, params, OwnershipBorrowed); + var exprGen, _, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); var dTypePath := GenPath(dType); - r := R.RawExpr("matches!(" + exprGen.ToString(IND) + ".as_ref(), " + dTypePath + "::" + escapeIdent(variant) + "{ .. })"); + r := R.Identifier("matches!").Apply([exprGen.Sel("as_ref").Apply([]), R.RawExpr(dTypePath.MSel(escapeName(variant)).ToString(IND) + "{ .. }")]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; @@ -3403,28 +3833,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case SetBoundedPool(of) => { - var exprGen, _, recIdents := GenExpr(of, selfIdent, params, OwnershipBorrowed); - r := R.RawExpr("(" + exprGen.ToString(IND) + ").iter()"); + var exprGen, _, recIdents := GenExpr(of, selfIdent, env, OwnershipBorrowed); + r := exprGen.Sel("iter").Apply([]).Sel("cloned").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; } case SeqBoundedPool(of, includeDuplicates) => { - var exprGen, _, recIdents := GenExpr(of, selfIdent, params, OwnershipBorrowed); - var s := "(" + exprGen.ToString(IND) + ").iter()"; + var exprGen, _, recIdents := GenExpr(of, selfIdent, env, OwnershipBorrowed); + r := exprGen.Sel("iter").Apply([]); if !includeDuplicates { - s := "::dafny_runtime::itertools::Itertools::unique(" + s + ")"; + r := R.dafny_runtime.MSel("itertools").MSel("Itertools").MSel("unique").Apply1(r); } - r := R.RawExpr(s); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; } case IntRange(lo, hi) => { - var lo, _, recIdentsLo := GenExpr(lo, selfIdent, params, OwnershipOwned); - var hi, _, recIdentsHi := GenExpr(hi, selfIdent, params, OwnershipOwned); - - r := R.RawExpr("::dafny_runtime::integer_range(" + lo.ToString(IND) + ", " + hi.ToString(IND) + ")"); + var lo, _, recIdentsLo := GenExpr(lo, selfIdent, env, OwnershipOwned); + var hi, _, recIdentsHi := GenExpr(hi, selfIdent, env, OwnershipOwned); + r := R.dafny_runtime.MSel("integer_range").Apply([lo, hi]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdentsLo + recIdentsHi; return; @@ -3432,7 +3860,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case MapBuilder(keyType, valueType) => { var kType := GenType(keyType, false, false); var vType := GenType(valueType, false, false); - r := R.RawExpr("::dafny_runtime::MapBuilder::<" + kType.ToString(IND) + ", " + vType.ToString(IND) + ">::new()"); + r := R.dafny_runtime.MSel("MapBuilder").ApplyType([kType, vType]).MSel("new").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := {}; return; @@ -3440,17 +3868,18 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case SetBuilder(elemType) => { var eType := GenType(elemType, false, false); readIdents := {}; - r := R.RawExpr("::dafny_runtime::SetBuilder::<" + eType.ToString(IND) + ">::new()"); + r := R.dafny_runtime.MSel("SetBuilder").ApplyType([eType]).MSel("new").Apply([]); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } } } - method Compile(p: seq) returns (s: string) { + method Compile(p: seq) returns (s: string) + modifies this + { s := "#![allow(warnings, unconditional_panic)]\n"; s := s + "#![allow(nonstandard_style)]\n"; - s := s + "extern crate dafny_runtime;\n"; var i := 0; while i < |p| { @@ -3467,14 +3896,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - static method EmitCallToMain(fullName: seq) returns (s: string) { + static method EmitCallToMain(fullName: seq) returns (s: string) { s := "\nfn main() {\n"; var i := 0; while i < |fullName| { if i > 0 { s := s + "::"; } - s := s + escapeIdent(fullName[i]); + s := s + escapeName(fullName[i]); i := i + 1; } s := s + "();\n}"; diff --git a/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs b/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs index ad59ebb3e..4681e9c1d 100644 --- a/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs @@ -14,15 +14,19 @@ public RustCodeGenerator(DafnyOptions options) { } public override ISequence Compile(Sequence program) { - var c = new COMP(); + var c = new DCOMP.COMP(); c.__ctor(Options.Get(CommonOptionBag.UnicodeCharacters)); - return c.Compile(program); + var s = c.Compile(program); + if (!Options.Get(CommonOptionBag.EmitUncompilableCode) && c.error.is_Some) { + throw new UnsupportedInvalidOperationException(c.error.dtor_value.ToVerbatimString(false)); + } + return s; } public override ISequence EmitCallToMain(string fullName) { var splitByDot = fullName.Split('.'); var convertedToUnicode = Sequence>.FromArray(splitByDot.Select(s => (Sequence)Sequence.UnicodeFromString(s)).ToArray()); - return COMP.EmitCallToMain(convertedToUnicode); + return DCOMP.COMP.EmitCallToMain(convertedToUnicode); } } diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 5ba50f103..7ad99fe4a 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -1648,7 +1648,7 @@ private void EmitModule(Program program, ConcreteSyntaxTree programNode, ModuleD cw.Finish(); } else { // still check that given members satisfy compilation rules - var abyss = new NullClassWriter(); + var abyss = new NullClassWriter(this); CompileClassMembers(program, defaultClassDecl, abyss); } } else if (d is ClassLikeDecl cl) { @@ -1679,7 +1679,7 @@ private void EmitModule(Program program, ConcreteSyntaxTree programNode, ModuleD cw.Finish(); } else { // still check that given members satisfy compilation rules - var abyss = new NullClassWriter(); + var abyss = new NullClassWriter(this); CompileClassMembers(program, cl, abyss); } } else if (d is ValuetypeDecl) { @@ -1717,11 +1717,16 @@ private void DetectAndMarkCapitalizationConflicts(ModuleDefinition module) { public ISet<(ModuleDefinition, string)> DeclaredDatatypes { get; } = new HashSet<(ModuleDefinition, string)>(); + protected virtual ConcreteSyntaxTree GetNullClassConcreteSyntaxTree() { + return new ConcreteSyntaxTree(); + } + protected class NullClassWriter : IClassWriter { - private readonly ConcreteSyntaxTree abyss = new ConcreteSyntaxTree(); + private readonly ConcreteSyntaxTree abyss; private readonly ConcreteSyntaxTree block; - public NullClassWriter() { + public NullClassWriter(SinglePassCodeGenerator parent) { + abyss = parent.GetNullClassConcreteSyntaxTree(); block = abyss.NewBlock(""); } @@ -2082,6 +2087,9 @@ public virtual bool NeedsCustomReceiverInDatatype(MemberDecl member) { public virtual bool NeedsCustomReceiverNotTrait(MemberDecl member) { Contract.Requires(member != null); + if (member.EnclosingClass is TraitDecl) { + return false; + } // One of the limitations in many target language encodings are restrictions to instance members. If an // instance member can't be directly expressed in the target language, we make it a static member with an // additional first argument specifying the `this`, giving it a `CustomReceiver`. @@ -4150,7 +4158,7 @@ void TrRhsArray(TypeRhs typeRhs, string nw, ConcreteSyntaxTree wr, ConcreteSynta ii++; } - } else if (DeterminesArrayTypeFromExampleElement) { + } else if (DeterminesArrayTypeFromExampleElement) { // Not the case for the Rust compiler, for example // For a 3-dimensional array allocation // m := new X[e0, e1, e2](InitFunction); // generate: diff --git a/Source/DafnyCore/ConcreteSyntax/ConcreteSyntaxTree.cs b/Source/DafnyCore/ConcreteSyntax/ConcreteSyntaxTree.cs index c103e550a..d7860896a 100644 --- a/Source/DafnyCore/ConcreteSyntax/ConcreteSyntaxTree.cs +++ b/Source/DafnyCore/ConcreteSyntax/ConcreteSyntaxTree.cs @@ -168,7 +168,7 @@ public virtual ConcreteSyntaxTree ForkInParens() { return result; } - public ConcreteSyntaxTree NewBlock(string header = "", string footer = "", + public virtual ConcreteSyntaxTree NewBlock(string header = "", string footer = "", BlockStyle open = BlockStyle.SpaceBrace, BlockStyle close = BlockStyle.NewlineBrace) { Contract.Requires(header != null); diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 9c382991c..097e828cf 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -12,50 +12,101 @@ namespace DAST { + public interface _IName { + bool is_Name { get; } + Dafny.ISequence dtor_dafny__name { get; } + } + public class Name : _IName { + public readonly Dafny.ISequence _dafny__name; + public Name(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.Name; + 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.Name.Name"; + 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 _IName create(Dafny.ISequence dafny__name) { + return new Name(dafny__name); + } + public static _IName create_Name(Dafny.ISequence dafny__name) { + return create(dafny__name); + } + public bool is_Name { 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; } - bool dtor_isExtern { get; } - Dafny.ISequence dtor_body { get; } + Dafny.ISequence dtor_attributes { get; } + Std.Wrappers._IOption> dtor_body { get; } _IModule DowncastClone(); } public class Module : _IModule { public readonly Dafny.ISequence _name; - public readonly bool _isExtern; - public readonly Dafny.ISequence _body; - public Module(Dafny.ISequence name, bool isExtern, Dafny.ISequence body) { + public readonly Dafny.ISequence _attributes; + public readonly Std.Wrappers._IOption> _body; + public Module(Dafny.ISequence name, Dafny.ISequence attributes, Std.Wrappers._IOption> body) { this._name = name; - this._isExtern = isExtern; + this._attributes = attributes; this._body = body; } public _IModule DowncastClone() { if (this is _IModule dt) { return dt; } - return new Module(_name, _isExtern, _body); + return new Module(_name, _attributes, _body); } public override bool Equals(object other) { var oth = other as DAST.Module; - return oth != null && object.Equals(this._name, oth._name) && this._isExtern == oth._isExtern && object.Equals(this._body, oth._body); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._attributes, oth._attributes) && 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._isExtern)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); return (int) hash; } public override string ToString() { string s = "DAST.Module.Module"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); s += ", "; - s += Dafny.Helpers.ToString(this._isExtern); + s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += Dafny.Helpers.ToString(this._body); s += ")"; return s; } - private static readonly DAST._IModule theDefault = create(Dafny.Sequence.Empty, false, Dafny.Sequence.Empty); + private static readonly DAST._IModule theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option>.Default()); public static DAST._IModule Default() { return theDefault; } @@ -63,11 +114,11 @@ public static DAST._IModule Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IModule create(Dafny.ISequence name, bool isExtern, Dafny.ISequence body) { - return new Module(name, isExtern, body); + public static _IModule create(Dafny.ISequence name, Dafny.ISequence attributes, Std.Wrappers._IOption> body) { + return new Module(name, attributes, body); } - public static _IModule create_Module(Dafny.ISequence name, bool isExtern, Dafny.ISequence body) { - return create(name, isExtern, body); + public static _IModule create_Module(Dafny.ISequence name, Dafny.ISequence attributes, Std.Wrappers._IOption> body) { + return create(name, attributes, body); } public bool is_Module { get { return true; } } public Dafny.ISequence dtor_name { @@ -75,12 +126,12 @@ public Dafny.ISequence dtor_name { return this._name; } } - public bool dtor_isExtern { + public Dafny.ISequence dtor_attributes { get { - return this._isExtern; + return this._attributes; } } - public Dafny.ISequence dtor_body { + public Std.Wrappers._IOption> dtor_body { get { return this._body; } @@ -898,6 +949,145 @@ public override string ToString() { } } + public interface _ITypeArgDecl { + bool is_TypeArgDecl { get; } + Dafny.ISequence dtor_name { get; } + Dafny.ISequence dtor_bounds { get; } + _ITypeArgDecl DowncastClone(); + } + public class TypeArgDecl : _ITypeArgDecl { + public readonly Dafny.ISequence _name; + public readonly Dafny.ISequence _bounds; + public TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds) { + this._name = name; + this._bounds = bounds; + } + public _ITypeArgDecl DowncastClone() { + if (this is _ITypeArgDecl dt) { return dt; } + return new TypeArgDecl(_name, _bounds); + } + public override bool Equals(object other) { + var oth = other as DAST.TypeArgDecl; + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._bounds, oth._bounds); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._bounds)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.TypeArgDecl.TypeArgDecl"; + s += "("; + s += Dafny.Helpers.ToString(this._name); + s += ", "; + s += Dafny.Helpers.ToString(this._bounds); + s += ")"; + return s; + } + private static readonly DAST._ITypeArgDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty); + public static DAST._ITypeArgDecl Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.TypeArgDecl.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _ITypeArgDecl create(Dafny.ISequence name, Dafny.ISequence bounds) { + return new TypeArgDecl(name, bounds); + } + public static _ITypeArgDecl create_TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds) { + return create(name, bounds); + } + public bool is_TypeArgDecl { get { return true; } } + public Dafny.ISequence dtor_name { + get { + return this._name; + } + } + public Dafny.ISequence dtor_bounds { + get { + return this._bounds; + } + } + } + + public interface _ITypeArgBound { + bool is_SupportsEquality { get; } + bool is_SupportsDefault { get; } + _ITypeArgBound DowncastClone(); + } + public abstract class TypeArgBound : _ITypeArgBound { + public TypeArgBound() { + } + private static readonly DAST._ITypeArgBound theDefault = create_SupportsEquality(); + public static DAST._ITypeArgBound Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.TypeArgBound.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _ITypeArgBound create_SupportsEquality() { + return new TypeArgBound_SupportsEquality(); + } + public static _ITypeArgBound create_SupportsDefault() { + return new TypeArgBound_SupportsDefault(); + } + public bool is_SupportsEquality { get { return this is TypeArgBound_SupportsEquality; } } + public bool is_SupportsDefault { get { return this is TypeArgBound_SupportsDefault; } } + public static System.Collections.Generic.IEnumerable<_ITypeArgBound> AllSingletonConstructors { + get { + yield return TypeArgBound.create_SupportsEquality(); + yield return TypeArgBound.create_SupportsDefault(); + } + } + public abstract _ITypeArgBound DowncastClone(); + } + public class TypeArgBound_SupportsEquality : TypeArgBound { + public TypeArgBound_SupportsEquality() : base() { + } + public override _ITypeArgBound DowncastClone() { + if (this is _ITypeArgBound dt) { return dt; } + return new TypeArgBound_SupportsEquality(); + } + public override bool Equals(object other) { + var oth = other as DAST.TypeArgBound_SupportsEquality; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + return (int) hash; + } + public override string ToString() { + string s = "DAST.TypeArgBound.SupportsEquality"; + return s; + } + } + public class TypeArgBound_SupportsDefault : TypeArgBound { + public TypeArgBound_SupportsDefault() : base() { + } + public override _ITypeArgBound DowncastClone() { + if (this is _ITypeArgBound dt) { return dt; } + return new TypeArgBound_SupportsDefault(); + } + public override bool Equals(object other) { + var oth = other as DAST.TypeArgBound_SupportsDefault; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + return (int) hash; + } + public override string ToString() { + string s = "DAST.TypeArgBound.SupportsDefault"; + return s; + } + } + public interface _IPrimitive { bool is_Int { get; } bool is_Real { get; } @@ -1399,11 +1589,141 @@ public override string ToString() { } } + public interface _IAttribute { + bool is_Attribute { get; } + Dafny.ISequence dtor_name { get; } + Dafny.ISequence> dtor_args { get; } + _IAttribute DowncastClone(); + } + public class Attribute : _IAttribute { + public readonly Dafny.ISequence _name; + public readonly Dafny.ISequence> _args; + public Attribute(Dafny.ISequence name, Dafny.ISequence> args) { + this._name = name; + this._args = args; + } + public _IAttribute DowncastClone() { + if (this is _IAttribute dt) { return dt; } + return new Attribute(_name, _args); + } + public override bool Equals(object other) { + var oth = other as DAST.Attribute; + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._args, oth._args); + } + 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._args)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.Attribute.Attribute"; + s += "("; + s += this._name.ToVerbatimString(true); + s += ", "; + s += Dafny.Helpers.ToString(this._args); + s += ")"; + return s; + } + private static readonly DAST._IAttribute theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty); + public static DAST._IAttribute Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.Attribute.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IAttribute create(Dafny.ISequence name, Dafny.ISequence> args) { + return new Attribute(name, args); + } + public static _IAttribute create_Attribute(Dafny.ISequence name, Dafny.ISequence> args) { + return create(name, args); + } + public bool is_Attribute { get { return true; } } + public Dafny.ISequence dtor_name { + get { + return this._name; + } + } + public Dafny.ISequence> dtor_args { + get { + return this._args; + } + } + } + + public interface _IDatatypeType { + bool is_DatatypeType { get; } + Dafny.ISequence> dtor_path { get; } + Dafny.ISequence dtor_attributes { get; } + _IDatatypeType DowncastClone(); + } + public class DatatypeType : _IDatatypeType { + public readonly Dafny.ISequence> _path; + public readonly Dafny.ISequence _attributes; + public DatatypeType(Dafny.ISequence> path, Dafny.ISequence attributes) { + this._path = path; + this._attributes = attributes; + } + public _IDatatypeType DowncastClone() { + if (this is _IDatatypeType dt) { return dt; } + return new DatatypeType(_path, _attributes); + } + public override bool Equals(object other) { + var oth = other as DAST.DatatypeType; + return oth != null && object.Equals(this._path, oth._path) && object.Equals(this._attributes, oth._attributes); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._path)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.DatatypeType.DatatypeType"; + s += "("; + s += Dafny.Helpers.ToString(this._path); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); + s += ")"; + return s; + } + private static readonly DAST._IDatatypeType theDefault = create(Dafny.Sequence>.Empty, Dafny.Sequence.Empty); + public static DAST._IDatatypeType Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.DatatypeType.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IDatatypeType create(Dafny.ISequence> path, Dafny.ISequence attributes) { + return new DatatypeType(path, attributes); + } + public static _IDatatypeType create_DatatypeType(Dafny.ISequence> path, Dafny.ISequence attributes) { + return create(path, attributes); + } + public bool is_DatatypeType { get { return true; } } + public Dafny.ISequence> dtor_path { + get { + return this._path; + } + } + public Dafny.ISequence dtor_attributes { + get { + return this._attributes; + } + } + } + public interface _IResolvedType { bool is_Datatype { get; } bool is_Trait { get; } bool is_Newtype { get; } + DAST._IDatatypeType dtor_datatypeType { get; } Dafny.ISequence> dtor_path { get; } + Dafny.ISequence dtor_attributes { get; } DAST._IType dtor_baseType { get; } DAST._INewtypeRange dtor_range { get; } bool dtor_erase { get; } @@ -1412,7 +1732,7 @@ public interface _IResolvedType { public abstract class ResolvedType : _IResolvedType { public ResolvedType() { } - private static readonly DAST._IResolvedType theDefault = create_Datatype(Dafny.Sequence>.Empty); + private static readonly DAST._IResolvedType theDefault = create_Datatype(DAST.DatatypeType.Default()); public static DAST._IResolvedType Default() { return theDefault; } @@ -1420,25 +1740,37 @@ public static DAST._IResolvedType Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IResolvedType create_Datatype(Dafny.ISequence> path) { - return new ResolvedType_Datatype(path); + public static _IResolvedType create_Datatype(DAST._IDatatypeType datatypeType) { + return new ResolvedType_Datatype(datatypeType); } - public static _IResolvedType create_Trait(Dafny.ISequence> path) { - return new ResolvedType_Trait(path); + public static _IResolvedType create_Trait(Dafny.ISequence> path, Dafny.ISequence attributes) { + return new ResolvedType_Trait(path, attributes); } - public static _IResolvedType create_Newtype(DAST._IType baseType, DAST._INewtypeRange range, bool erase) { - return new ResolvedType_Newtype(baseType, range, erase); + public static _IResolvedType create_Newtype(DAST._IType baseType, DAST._INewtypeRange range, bool erase, Dafny.ISequence attributes) { + return new ResolvedType_Newtype(baseType, range, erase, attributes); } public bool is_Datatype { get { return this is ResolvedType_Datatype; } } public bool is_Trait { get { return this is ResolvedType_Trait; } } public bool is_Newtype { get { return this is ResolvedType_Newtype; } } + public DAST._IDatatypeType dtor_datatypeType { + get { + var d = this; + return ((ResolvedType_Datatype)d)._datatypeType; + } + } public Dafny.ISequence> dtor_path { get { var d = this; - if (d is ResolvedType_Datatype) { return ((ResolvedType_Datatype)d)._path; } return ((ResolvedType_Trait)d)._path; } } + public Dafny.ISequence dtor_attributes { + get { + var d = this; + if (d is ResolvedType_Trait) { return ((ResolvedType_Trait)d)._attributes; } + return ((ResolvedType_Newtype)d)._attributes; + } + } public DAST._IType dtor_baseType { get { var d = this; @@ -1460,55 +1792,60 @@ public bool dtor_erase { public abstract _IResolvedType DowncastClone(); } public class ResolvedType_Datatype : ResolvedType { - public readonly Dafny.ISequence> _path; - public ResolvedType_Datatype(Dafny.ISequence> path) : base() { - this._path = path; + public readonly DAST._IDatatypeType _datatypeType; + public ResolvedType_Datatype(DAST._IDatatypeType datatypeType) : base() { + this._datatypeType = datatypeType; } public override _IResolvedType DowncastClone() { if (this is _IResolvedType dt) { return dt; } - return new ResolvedType_Datatype(_path); + return new ResolvedType_Datatype(_datatypeType); } public override bool Equals(object other) { var oth = other as DAST.ResolvedType_Datatype; - return oth != null && object.Equals(this._path, oth._path); + return oth != null && object.Equals(this._datatypeType, oth._datatypeType); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._path)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._datatypeType)); return (int) hash; } public override string ToString() { string s = "DAST.ResolvedType.Datatype"; s += "("; - s += Dafny.Helpers.ToString(this._path); + s += Dafny.Helpers.ToString(this._datatypeType); s += ")"; return s; } } public class ResolvedType_Trait : ResolvedType { public readonly Dafny.ISequence> _path; - public ResolvedType_Trait(Dafny.ISequence> path) : base() { + public readonly Dafny.ISequence _attributes; + public ResolvedType_Trait(Dafny.ISequence> path, Dafny.ISequence attributes) : base() { this._path = path; + this._attributes = attributes; } public override _IResolvedType DowncastClone() { if (this is _IResolvedType dt) { return dt; } - return new ResolvedType_Trait(_path); + return new ResolvedType_Trait(_path, _attributes); } public override bool Equals(object other) { var oth = other as DAST.ResolvedType_Trait; - return oth != null && object.Equals(this._path, oth._path); + return oth != null && object.Equals(this._path, oth._path) && object.Equals(this._attributes, oth._attributes); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 1; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._path)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); return (int) hash; } public override string ToString() { string s = "DAST.ResolvedType.Trait"; s += "("; s += Dafny.Helpers.ToString(this._path); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); s += ")"; return s; } @@ -1517,18 +1854,20 @@ public class ResolvedType_Newtype : ResolvedType { public readonly DAST._IType _baseType; public readonly DAST._INewtypeRange _range; public readonly bool _erase; - public ResolvedType_Newtype(DAST._IType baseType, DAST._INewtypeRange range, bool erase) : base() { + public readonly Dafny.ISequence _attributes; + public ResolvedType_Newtype(DAST._IType baseType, DAST._INewtypeRange range, bool erase, Dafny.ISequence attributes) : base() { this._baseType = baseType; this._range = range; this._erase = erase; + this._attributes = attributes; } public override _IResolvedType DowncastClone() { if (this is _IResolvedType dt) { return dt; } - return new ResolvedType_Newtype(_baseType, _range, _erase); + return new ResolvedType_Newtype(_baseType, _range, _erase, _attributes); } public override bool Equals(object other) { var oth = other as DAST.ResolvedType_Newtype; - return oth != null && object.Equals(this._baseType, oth._baseType) && object.Equals(this._range, oth._range) && this._erase == oth._erase; + return oth != null && object.Equals(this._baseType, oth._baseType) && object.Equals(this._range, oth._range) && this._erase == oth._erase && object.Equals(this._attributes, oth._attributes); } public override int GetHashCode() { ulong hash = 5381; @@ -1536,6 +1875,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._baseType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._range)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._erase)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); return (int) hash; } public override string ToString() { @@ -1546,6 +1886,8 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._range); s += ", "; s += Dafny.Helpers.ToString(this._erase); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); s += ")"; return s; } @@ -1576,7 +1918,7 @@ public override int GetHashCode() { public override string ToString() { string s = "DAST.Ident.Ident"; s += "("; - s += this._id.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._id); s += ")"; return s; } @@ -1606,34 +1948,37 @@ public interface _IClass { bool is_Class { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_enclosingModule { get; } - Dafny.ISequence dtor_typeParams { get; } + Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_superClasses { get; } Dafny.ISequence dtor_fields { get; } Dafny.ISequence dtor_body { get; } + Dafny.ISequence dtor_attributes { get; } _IClass DowncastClone(); } public class Class : _IClass { public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _enclosingModule; - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _superClasses; public readonly Dafny.ISequence _fields; public readonly Dafny.ISequence _body; - public Class(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence superClasses, Dafny.ISequence fields, Dafny.ISequence body) { + public readonly Dafny.ISequence _attributes; + public Class(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence superClasses, Dafny.ISequence fields, Dafny.ISequence body, Dafny.ISequence attributes) { this._name = name; this._enclosingModule = enclosingModule; this._typeParams = typeParams; this._superClasses = superClasses; this._fields = fields; this._body = body; + this._attributes = attributes; } public _IClass DowncastClone() { if (this is _IClass dt) { return dt; } - return new Class(_name, _enclosingModule, _typeParams, _superClasses, _fields, _body); + return new Class(_name, _enclosingModule, _typeParams, _superClasses, _fields, _body, _attributes); } public override bool Equals(object other) { var oth = other as DAST.Class; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._superClasses, oth._superClasses) && object.Equals(this._fields, oth._fields) && object.Equals(this._body, oth._body); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._superClasses, oth._superClasses) && object.Equals(this._fields, oth._fields) && object.Equals(this._body, oth._body) && object.Equals(this._attributes, oth._attributes); } public override int GetHashCode() { ulong hash = 5381; @@ -1644,12 +1989,13 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superClasses)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fields)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); return (int) hash; } public override string ToString() { string s = "DAST.Class.Class"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); s += ", "; s += Dafny.Helpers.ToString(this._enclosingModule); s += ", "; @@ -1660,10 +2006,12 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._fields); s += ", "; s += Dafny.Helpers.ToString(this._body); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); s += ")"; return s; } - private static readonly DAST._IClass theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._IClass theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._IClass Default() { return theDefault; } @@ -1671,11 +2019,11 @@ public static DAST._IClass Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IClass create(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence superClasses, Dafny.ISequence fields, Dafny.ISequence body) { - return new Class(name, enclosingModule, typeParams, superClasses, fields, body); + public static _IClass create(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence superClasses, Dafny.ISequence fields, Dafny.ISequence body, Dafny.ISequence attributes) { + return new Class(name, enclosingModule, typeParams, superClasses, fields, body, attributes); } - public static _IClass create_Class(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence superClasses, Dafny.ISequence fields, Dafny.ISequence body) { - return create(name, enclosingModule, typeParams, superClasses, fields, body); + public static _IClass create_Class(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence superClasses, Dafny.ISequence fields, Dafny.ISequence body, Dafny.ISequence attributes) { + return create(name, enclosingModule, typeParams, superClasses, fields, body, attributes); } public bool is_Class { get { return true; } } public Dafny.ISequence dtor_name { @@ -1688,7 +2036,7 @@ public Dafny.ISequence dtor_enclosingModule { return this._enclosingModule; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { return this._typeParams; } @@ -1708,31 +2056,39 @@ public Dafny.ISequence dtor_body { return this._body; } } + public Dafny.ISequence dtor_attributes { + get { + return this._attributes; + } + } } public interface _ITrait { bool is_Trait { get; } Dafny.ISequence dtor_name { get; } - Dafny.ISequence dtor_typeParams { get; } + Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_body { get; } + Dafny.ISequence dtor_attributes { get; } _ITrait DowncastClone(); } public class Trait : _ITrait { public readonly Dafny.ISequence _name; - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _body; - public Trait(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence body) { + public readonly Dafny.ISequence _attributes; + public Trait(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence body, Dafny.ISequence attributes) { this._name = name; this._typeParams = typeParams; this._body = body; + this._attributes = attributes; } public _ITrait DowncastClone() { if (this is _ITrait dt) { return dt; } - return new Trait(_name, _typeParams, _body); + return new Trait(_name, _typeParams, _body, _attributes); } public override bool Equals(object other) { var oth = other as DAST.Trait; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._body, oth._body); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._body, oth._body) && object.Equals(this._attributes, oth._attributes); } public override int GetHashCode() { ulong hash = 5381; @@ -1740,20 +2096,23 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); return (int) hash; } public override string ToString() { string s = "DAST.Trait.Trait"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); s += ", "; s += Dafny.Helpers.ToString(this._typeParams); s += ", "; s += Dafny.Helpers.ToString(this._body); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); s += ")"; return s; } - private static readonly DAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._ITrait Default() { return theDefault; } @@ -1761,11 +2120,11 @@ public static DAST._ITrait Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITrait create(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence body) { - return new Trait(name, typeParams, body); + public static _ITrait create(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence body, Dafny.ISequence attributes) { + return new Trait(name, typeParams, body, attributes); } - public static _ITrait create_Trait(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence body) { - return create(name, typeParams, body); + public static _ITrait create_Trait(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence body, Dafny.ISequence attributes) { + return create(name, typeParams, body, attributes); } public bool is_Trait { get { return true; } } public Dafny.ISequence dtor_name { @@ -1773,7 +2132,7 @@ public Dafny.ISequence dtor_name { return this._name; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { return this._typeParams; } @@ -1783,40 +2142,48 @@ public Dafny.ISequence dtor_body { return this._body; } } + public Dafny.ISequence dtor_attributes { + get { + return this._attributes; + } + } } public interface _IDatatype { bool is_Datatype { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_enclosingModule { get; } - Dafny.ISequence dtor_typeParams { get; } + Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_ctors { get; } Dafny.ISequence dtor_body { get; } bool dtor_isCo { get; } + Dafny.ISequence dtor_attributes { get; } _IDatatype DowncastClone(); } public class Datatype : _IDatatype { public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _enclosingModule; - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _ctors; public readonly Dafny.ISequence _body; public readonly bool _isCo; - public Datatype(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo) { + public readonly Dafny.ISequence _attributes; + public Datatype(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes) { this._name = name; this._enclosingModule = enclosingModule; this._typeParams = typeParams; this._ctors = ctors; this._body = body; this._isCo = isCo; + this._attributes = attributes; } public _IDatatype DowncastClone() { if (this is _IDatatype dt) { return dt; } - return new Datatype(_name, _enclosingModule, _typeParams, _ctors, _body, _isCo); + return new Datatype(_name, _enclosingModule, _typeParams, _ctors, _body, _isCo, _attributes); } public override bool Equals(object other) { var oth = other as DAST.Datatype; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._ctors, oth._ctors) && object.Equals(this._body, oth._body) && this._isCo == oth._isCo; + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._ctors, oth._ctors) && object.Equals(this._body, oth._body) && this._isCo == oth._isCo && object.Equals(this._attributes, oth._attributes); } public override int GetHashCode() { ulong hash = 5381; @@ -1827,12 +2194,13 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._ctors)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isCo)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); return (int) hash; } public override string ToString() { string s = "DAST.Datatype.Datatype"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); s += ", "; s += Dafny.Helpers.ToString(this._enclosingModule); s += ", "; @@ -1843,10 +2211,12 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._body); s += ", "; s += Dafny.Helpers.ToString(this._isCo); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); s += ")"; return s; } - private static readonly DAST._IDatatype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, false); + private static readonly DAST._IDatatype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, Dafny.Sequence.Empty); public static DAST._IDatatype Default() { return theDefault; } @@ -1854,11 +2224,11 @@ public static DAST._IDatatype Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IDatatype create(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo) { - return new Datatype(name, enclosingModule, typeParams, ctors, body, isCo); + public static _IDatatype create(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes) { + return new Datatype(name, enclosingModule, typeParams, ctors, body, isCo, attributes); } - public static _IDatatype create_Datatype(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo) { - return create(name, enclosingModule, typeParams, ctors, body, isCo); + public static _IDatatype create_Datatype(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes) { + return create(name, enclosingModule, typeParams, ctors, body, isCo, attributes); } public bool is_Datatype { get { return true; } } public Dafny.ISequence dtor_name { @@ -1871,7 +2241,7 @@ public Dafny.ISequence dtor_enclosingModule { return this._enclosingModule; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { return this._typeParams; } @@ -1891,20 +2261,89 @@ public bool dtor_isCo { return this._isCo; } } + public Dafny.ISequence dtor_attributes { + get { + return this._attributes; + } + } + } + + public interface _IDatatypeDtor { + bool is_DatatypeDtor { get; } + DAST._IFormal dtor_formal { get; } + Std.Wrappers._IOption> dtor_callName { get; } + _IDatatypeDtor DowncastClone(); + } + public class DatatypeDtor : _IDatatypeDtor { + public readonly DAST._IFormal _formal; + public readonly Std.Wrappers._IOption> _callName; + public DatatypeDtor(DAST._IFormal formal, Std.Wrappers._IOption> callName) { + this._formal = formal; + this._callName = callName; + } + public _IDatatypeDtor DowncastClone() { + if (this is _IDatatypeDtor dt) { return dt; } + return new DatatypeDtor(_formal, _callName); + } + public override bool Equals(object other) { + var oth = other as DAST.DatatypeDtor; + return oth != null && object.Equals(this._formal, oth._formal) && object.Equals(this._callName, oth._callName); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._formal)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._callName)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.DatatypeDtor.DatatypeDtor"; + s += "("; + s += Dafny.Helpers.ToString(this._formal); + s += ", "; + s += Dafny.Helpers.ToString(this._callName); + s += ")"; + return s; + } + private static readonly DAST._IDatatypeDtor theDefault = create(DAST.Formal.Default(), Std.Wrappers.Option>.Default()); + public static DAST._IDatatypeDtor Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.DatatypeDtor.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IDatatypeDtor create(DAST._IFormal formal, Std.Wrappers._IOption> callName) { + return new DatatypeDtor(formal, callName); + } + public static _IDatatypeDtor create_DatatypeDtor(DAST._IFormal formal, Std.Wrappers._IOption> callName) { + return create(formal, callName); + } + public bool is_DatatypeDtor { get { return true; } } + public DAST._IFormal dtor_formal { + get { + return this._formal; + } + } + public Std.Wrappers._IOption> dtor_callName { + get { + return this._callName; + } + } } public interface _IDatatypeCtor { bool is_DatatypeCtor { get; } Dafny.ISequence dtor_name { get; } - Dafny.ISequence dtor_args { get; } + Dafny.ISequence dtor_args { get; } bool dtor_hasAnyArgs { get; } _IDatatypeCtor DowncastClone(); } public class DatatypeCtor : _IDatatypeCtor { public readonly Dafny.ISequence _name; - public readonly Dafny.ISequence _args; + public readonly Dafny.ISequence _args; public readonly bool _hasAnyArgs; - public DatatypeCtor(Dafny.ISequence name, Dafny.ISequence args, bool hasAnyArgs) { + public DatatypeCtor(Dafny.ISequence name, Dafny.ISequence args, bool hasAnyArgs) { this._name = name; this._args = args; this._hasAnyArgs = hasAnyArgs; @@ -1928,7 +2367,7 @@ public override int GetHashCode() { public override string ToString() { string s = "DAST.DatatypeCtor.DatatypeCtor"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); s += ", "; s += Dafny.Helpers.ToString(this._args); s += ", "; @@ -1936,7 +2375,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly DAST._IDatatypeCtor theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, false); + private static readonly DAST._IDatatypeCtor theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, false); public static DAST._IDatatypeCtor Default() { return theDefault; } @@ -1944,10 +2383,10 @@ public static DAST._IDatatypeCtor Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IDatatypeCtor create(Dafny.ISequence name, Dafny.ISequence args, bool hasAnyArgs) { + public static _IDatatypeCtor create(Dafny.ISequence name, Dafny.ISequence args, bool hasAnyArgs) { return new DatatypeCtor(name, args, hasAnyArgs); } - public static _IDatatypeCtor create_DatatypeCtor(Dafny.ISequence name, Dafny.ISequence args, bool hasAnyArgs) { + public static _IDatatypeCtor create_DatatypeCtor(Dafny.ISequence name, Dafny.ISequence args, bool hasAnyArgs) { return create(name, args, hasAnyArgs); } public bool is_DatatypeCtor { get { return true; } } @@ -1956,7 +2395,7 @@ public Dafny.ISequence dtor_name { return this._name; } } - public Dafny.ISequence dtor_args { + public Dafny.ISequence dtor_args { get { return this._args; } @@ -1971,35 +2410,38 @@ public bool dtor_hasAnyArgs { public interface _INewtype { bool is_Newtype { get; } Dafny.ISequence dtor_name { get; } - Dafny.ISequence dtor_typeParams { get; } + Dafny.ISequence dtor_typeParams { get; } DAST._IType dtor_base { get; } DAST._INewtypeRange dtor_range { get; } Dafny.ISequence dtor_witnessStmts { get; } Std.Wrappers._IOption dtor_witnessExpr { get; } + Dafny.ISequence dtor_attributes { get; } _INewtype DowncastClone(); } public class Newtype : _INewtype { public readonly Dafny.ISequence _name; - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly DAST._IType _base; public readonly DAST._INewtypeRange _range; public readonly Dafny.ISequence _witnessStmts; public readonly Std.Wrappers._IOption _witnessExpr; - public Newtype(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr) { + public readonly Dafny.ISequence _attributes; + public Newtype(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes) { this._name = name; this._typeParams = typeParams; this._base = @base; this._range = range; this._witnessStmts = witnessStmts; this._witnessExpr = witnessExpr; + this._attributes = attributes; } public _INewtype DowncastClone() { if (this is _INewtype dt) { return dt; } - return new Newtype(_name, _typeParams, _base, _range, _witnessStmts, _witnessExpr); + return new Newtype(_name, _typeParams, _base, _range, _witnessStmts, _witnessExpr, _attributes); } public override bool Equals(object other) { var oth = other as DAST.Newtype; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._base, oth._base) && object.Equals(this._range, oth._range) && object.Equals(this._witnessStmts, oth._witnessStmts) && object.Equals(this._witnessExpr, oth._witnessExpr); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._base, oth._base) && object.Equals(this._range, oth._range) && object.Equals(this._witnessStmts, oth._witnessStmts) && object.Equals(this._witnessExpr, oth._witnessExpr) && object.Equals(this._attributes, oth._attributes); } public override int GetHashCode() { ulong hash = 5381; @@ -2010,12 +2452,13 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._range)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._witnessStmts)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._witnessExpr)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); return (int) hash; } public override string ToString() { string s = "DAST.Newtype.Newtype"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); s += ", "; s += Dafny.Helpers.ToString(this._typeParams); s += ", "; @@ -2026,10 +2469,12 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._witnessStmts); s += ", "; s += Dafny.Helpers.ToString(this._witnessExpr); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); s += ")"; return s; } - private static readonly DAST._INewtype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.Type.Default(), DAST.NewtypeRange.Default(), Dafny.Sequence.Empty, Std.Wrappers.Option.Default()); + private static readonly DAST._INewtype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.Type.Default(), DAST.NewtypeRange.Default(), Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Dafny.Sequence.Empty); public static DAST._INewtype Default() { return theDefault; } @@ -2037,11 +2482,11 @@ public static DAST._INewtype Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _INewtype create(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr) { - return new Newtype(name, typeParams, @base, range, witnessStmts, witnessExpr); + public static _INewtype create(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes) { + return new Newtype(name, typeParams, @base, range, witnessStmts, witnessExpr, attributes); } - public static _INewtype create_Newtype(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr) { - return create(name, typeParams, @base, range, witnessStmts, witnessExpr); + public static _INewtype create_Newtype(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes) { + return create(name, typeParams, @base, range, witnessStmts, witnessExpr, attributes); } public bool is_Newtype { get { return true; } } public Dafny.ISequence dtor_name { @@ -2049,7 +2494,7 @@ public Dafny.ISequence dtor_name { return this._name; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { return this._typeParams; } @@ -2074,6 +2519,11 @@ public Std.Wrappers._IOption dtor_witnessExpr { return this._witnessExpr; } } + public Dafny.ISequence dtor_attributes { + get { + return this._attributes; + } + } } public interface _IClassItem { @@ -2195,40 +2645,46 @@ public interface _IFormal { bool is_Formal { get; } Dafny.ISequence dtor_name { get; } DAST._IType dtor_typ { get; } + Dafny.ISequence dtor_attributes { get; } _IFormal DowncastClone(); } public class Formal : _IFormal { public readonly Dafny.ISequence _name; public readonly DAST._IType _typ; - public Formal(Dafny.ISequence name, DAST._IType typ) { + public readonly Dafny.ISequence _attributes; + public Formal(Dafny.ISequence name, DAST._IType typ, Dafny.ISequence attributes) { this._name = name; this._typ = typ; + this._attributes = attributes; } public _IFormal DowncastClone() { if (this is _IFormal dt) { return dt; } - return new Formal(_name, _typ); + return new Formal(_name, _typ, _attributes); } public override bool Equals(object other) { var oth = other as DAST.Formal; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._typ, oth._typ); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._typ, oth._typ) && object.Equals(this._attributes, oth._attributes); } 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._typ)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); return (int) hash; } public override string ToString() { string s = "DAST.Formal.Formal"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); s += ", "; s += Dafny.Helpers.ToString(this._typ); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); s += ")"; return s; } - private static readonly DAST._IFormal theDefault = create(Dafny.Sequence.Empty, DAST.Type.Default()); + private static readonly DAST._IFormal theDefault = create(Dafny.Sequence.Empty, DAST.Type.Default(), Dafny.Sequence.Empty); public static DAST._IFormal Default() { return theDefault; } @@ -2236,11 +2692,11 @@ public static DAST._IFormal Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IFormal create(Dafny.ISequence name, DAST._IType typ) { - return new Formal(name, typ); + public static _IFormal create(Dafny.ISequence name, DAST._IType typ, Dafny.ISequence attributes) { + return new Formal(name, typ, attributes); } - public static _IFormal create_Formal(Dafny.ISequence name, DAST._IType typ) { - return create(name, typ); + public static _IFormal create_Formal(Dafny.ISequence name, DAST._IType typ, Dafny.ISequence attributes) { + return create(name, typ, attributes); } public bool is_Formal { get { return true; } } public Dafny.ISequence dtor_name { @@ -2253,6 +2709,11 @@ public DAST._IType dtor_typ { return this._typ; } } + public Dafny.ISequence dtor_attributes { + get { + return this._attributes; + } + } } public interface _IMethod { @@ -2261,7 +2722,7 @@ public interface _IMethod { bool dtor_hasBody { get; } Std.Wrappers._IOption>> dtor_overridingPath { get; } Dafny.ISequence dtor_name { get; } - Dafny.ISequence dtor_typeParams { get; } + Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_params { get; } Dafny.ISequence dtor_body { get; } Dafny.ISequence dtor_outTypes { get; } @@ -2273,12 +2734,12 @@ public class Method : _IMethod { public readonly bool _hasBody; public readonly Std.Wrappers._IOption>> _overridingPath; public readonly Dafny.ISequence _name; - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _params; public readonly Dafny.ISequence _body; public readonly Dafny.ISequence _outTypes; public readonly Std.Wrappers._IOption>> _outVars; - public Method(bool isStatic, bool hasBody, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { + public Method(bool isStatic, bool hasBody, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { this._isStatic = isStatic; this._hasBody = hasBody; this._overridingPath = overridingPath; @@ -2320,7 +2781,7 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._overridingPath); s += ", "; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); s += ", "; s += Dafny.Helpers.ToString(this._typeParams); s += ", "; @@ -2334,7 +2795,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly DAST._IMethod theDefault = create(false, false, Std.Wrappers.Option>>.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option>>.Default()); + private static readonly DAST._IMethod theDefault = create(false, false, Std.Wrappers.Option>>.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option>>.Default()); public static DAST._IMethod Default() { return theDefault; } @@ -2342,10 +2803,10 @@ public static DAST._IMethod Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IMethod create(bool isStatic, bool hasBody, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { + public static _IMethod create(bool isStatic, bool hasBody, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { return new Method(isStatic, hasBody, overridingPath, name, typeParams, @params, body, outTypes, outVars); } - public static _IMethod create_Method(bool isStatic, bool hasBody, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { + public static _IMethod create_Method(bool isStatic, bool hasBody, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { return create(isStatic, hasBody, overridingPath, name, typeParams, @params, body, outTypes, outVars); } public bool is_Method { get { return true; } } @@ -2369,7 +2830,7 @@ public Dafny.ISequence dtor_name { return this._name; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { return this._typeParams; } @@ -2396,19 +2857,72 @@ public Std.Wrappers._IOption>> dtor_ } } + public interface _ICallSignature { + bool is_CallSignature { get; } + Dafny.ISequence dtor_parameters { get; } + } + public class CallSignature : _ICallSignature { + public readonly Dafny.ISequence _parameters; + public CallSignature(Dafny.ISequence parameters) { + this._parameters = parameters; + } + public static Dafny.ISequence DowncastClone(Dafny.ISequence _this) { + return _this; + } + public override bool Equals(object other) { + var oth = other as DAST.CallSignature; + return oth != null && object.Equals(this._parameters, oth._parameters); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._parameters)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.CallSignature.CallSignature"; + s += "("; + s += Dafny.Helpers.ToString(this._parameters); + 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 _ICallSignature create(Dafny.ISequence parameters) { + return new CallSignature(parameters); + } + public static _ICallSignature create_CallSignature(Dafny.ISequence parameters) { + return create(parameters); + } + public bool is_CallSignature { get { return true; } } + public Dafny.ISequence dtor_parameters { + get { + return this._parameters; + } + } + } + public interface _ICallName { - bool is_Name { get; } + bool is_CallName { get; } bool is_MapBuilderAdd { get; } bool is_MapBuilderBuild { get; } bool is_SetBuilderAdd { get; } bool is_SetBuilderBuild { get; } Dafny.ISequence dtor_name { get; } + Std.Wrappers._IOption dtor_onType { get; } + Dafny.ISequence dtor_signature { get; } _ICallName DowncastClone(); } public abstract class CallName : _ICallName { public CallName() { } - private static readonly DAST._ICallName theDefault = create_Name(Dafny.Sequence.Empty); + private static readonly DAST._ICallName theDefault = create_CallName(Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Dafny.Sequence.Empty); public static DAST._ICallName Default() { return theDefault; } @@ -2416,8 +2930,8 @@ public static DAST._ICallName Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ICallName create_Name(Dafny.ISequence name) { - return new CallName_Name(name); + public static _ICallName create_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Dafny.ISequence signature) { + return new CallName_CallName(name, onType, signature); } public static _ICallName create_MapBuilderAdd() { return new CallName_MapBuilderAdd(); @@ -2431,7 +2945,7 @@ public static _ICallName create_SetBuilderAdd() { public static _ICallName create_SetBuilderBuild() { return new CallName_SetBuilderBuild(); } - public bool is_Name { get { return this is CallName_Name; } } + public bool is_CallName { get { return this is CallName_CallName; } } public bool is_MapBuilderAdd { get { return this is CallName_MapBuilderAdd; } } public bool is_MapBuilderBuild { get { return this is CallName_MapBuilderBuild; } } public bool is_SetBuilderAdd { get { return this is CallName_SetBuilderAdd; } } @@ -2439,34 +2953,56 @@ public static _ICallName create_SetBuilderBuild() { public Dafny.ISequence dtor_name { get { var d = this; - return ((CallName_Name)d)._name; + return ((CallName_CallName)d)._name; + } + } + public Std.Wrappers._IOption dtor_onType { + get { + var d = this; + return ((CallName_CallName)d)._onType; + } + } + public Dafny.ISequence dtor_signature { + get { + var d = this; + return ((CallName_CallName)d)._signature; } } public abstract _ICallName DowncastClone(); } - public class CallName_Name : CallName { + public class CallName_CallName : CallName { public readonly Dafny.ISequence _name; - public CallName_Name(Dafny.ISequence name) : base() { + public readonly Std.Wrappers._IOption _onType; + public readonly Dafny.ISequence _signature; + public CallName_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Dafny.ISequence signature) : base() { this._name = name; + this._onType = onType; + this._signature = signature; } public override _ICallName DowncastClone() { if (this is _ICallName dt) { return dt; } - return new CallName_Name(_name); + return new CallName_CallName(_name, _onType, _signature); } public override bool Equals(object other) { - var oth = other as DAST.CallName_Name; - return oth != null && object.Equals(this._name, oth._name); + 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._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._signature)); return (int) hash; } public override string ToString() { - string s = "DAST.CallName.Name"; + string s = "DAST.CallName.CallName"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); + s += ", "; + s += Dafny.Helpers.ToString(this._onType); + s += ", "; + s += Dafny.Helpers.ToString(this._signature); s += ")"; return s; } @@ -2821,7 +3357,7 @@ public override int GetHashCode() { public override string ToString() { string s = "DAST.Statement.DeclareVar"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._name); s += ", "; s += Dafny.Helpers.ToString(this._typ); s += ", "; @@ -2994,7 +3530,7 @@ public override int GetHashCode() { public override string ToString() { string s = "DAST.Statement.Foreach"; s += "("; - s += this._boundName.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._boundName); s += ", "; s += Dafny.Helpers.ToString(this._boundType); s += ", "; @@ -3228,7 +3764,7 @@ public interface _IAssignLhs { bool is_Ident { get; } bool is_Select { get; } bool is_Index { get; } - Dafny.ISequence dtor_Ident_a0 { get; } + Dafny.ISequence dtor_ident { get; } DAST._IExpression dtor_expr { get; } Dafny.ISequence dtor_field { get; } Dafny.ISequence dtor_indices { get; } @@ -3245,8 +3781,8 @@ public static DAST._IAssignLhs Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IAssignLhs create_Ident(Dafny.ISequence _a0) { - return new AssignLhs_Ident(_a0); + public static _IAssignLhs create_Ident(Dafny.ISequence ident) { + return new AssignLhs_Ident(ident); } public static _IAssignLhs create_Select(DAST._IExpression expr, Dafny.ISequence field) { return new AssignLhs_Select(expr, field); @@ -3257,10 +3793,10 @@ public static _IAssignLhs create_Index(DAST._IExpression expr, Dafny.ISequence dtor_Ident_a0 { + public Dafny.ISequence dtor_ident { get { var d = this; - return ((AssignLhs_Ident)d)._a0; + return ((AssignLhs_Ident)d)._ident; } } public DAST._IExpression dtor_expr { @@ -3285,28 +3821,28 @@ public Dafny.ISequence dtor_indices { public abstract _IAssignLhs DowncastClone(); } public class AssignLhs_Ident : AssignLhs { - public readonly Dafny.ISequence _a0; - public AssignLhs_Ident(Dafny.ISequence _a0) : base() { - this._a0 = _a0; + public readonly Dafny.ISequence _ident; + public AssignLhs_Ident(Dafny.ISequence ident) : base() { + this._ident = ident; } public override _IAssignLhs DowncastClone() { if (this is _IAssignLhs dt) { return dt; } - return new AssignLhs_Ident(_a0); + return new AssignLhs_Ident(_ident); } public override bool Equals(object other) { var oth = other as DAST.AssignLhs_Ident; - return oth != null && object.Equals(this._a0, oth._a0); + return oth != null && object.Equals(this._ident, oth._ident); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._a0)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._ident)); return (int) hash; } public override string ToString() { string s = "DAST.AssignLhs.Ident"; s += "("; - s += Dafny.Helpers.ToString(this._a0); + s += Dafny.Helpers.ToString(this._ident); s += ")"; return s; } @@ -3338,7 +3874,7 @@ public override string ToString() { s += "("; s += Dafny.Helpers.ToString(this._expr); s += ", "; - s += this._field.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._field); s += ")"; return s; } @@ -4520,6 +5056,7 @@ public interface _IExpression { Dafny.ISequence dtor_args { get; } Dafny.ISequence dtor_dims { get; } DAST._IType dtor_typ { get; } + DAST._IDatatypeType dtor_datatypeType { get; } Dafny.ISequence dtor_variant { get; } bool dtor_isCo { get; } Dafny.ISequence<_System._ITuple2, DAST._IExpression>> dtor_contents { get; } @@ -4548,6 +5085,7 @@ public interface _IExpression { Dafny.ISequence dtor_field { get; } bool dtor_isConstant { get; } bool dtor_onDatatype { get; } + DAST._IType dtor_fieldType { get; } bool dtor_isStatic { get; } BigInteger dtor_arity { get; } DAST._ICollKind dtor_collKind { get; } @@ -4600,8 +5138,8 @@ public static _IExpression create_New(Dafny.ISequence dims, DAST._IType typ) { return new Expression_NewArray(dims, typ); } - public static _IExpression create_DatatypeValue(Dafny.ISequence> path, Dafny.ISequence typeArgs, Dafny.ISequence variant, bool isCo, Dafny.ISequence<_System._ITuple2, DAST._IExpression>> contents) { - return new Expression_DatatypeValue(path, typeArgs, variant, isCo, contents); + public static _IExpression create_DatatypeValue(DAST._IDatatypeType datatypeType, Dafny.ISequence typeArgs, Dafny.ISequence variant, bool isCo, Dafny.ISequence<_System._ITuple2, DAST._IExpression>> contents) { + return new Expression_DatatypeValue(datatypeType, typeArgs, variant, isCo, contents); } public static _IExpression create_Convert(DAST._IExpression @value, DAST._IType @from, DAST._IType typ) { return new Expression_Convert(@value, @from, typ); @@ -4657,8 +5195,8 @@ 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_Select(DAST._IExpression expr, Dafny.ISequence field, bool isConstant, bool onDatatype) { - return new Expression_Select(expr, field, isConstant, onDatatype); + 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); @@ -4669,8 +5207,8 @@ public static _IExpression create_Index(DAST._IExpression expr, DAST._ICollKind public static _IExpression create_IndexRange(DAST._IExpression expr, bool isArray, Std.Wrappers._IOption low, Std.Wrappers._IOption high) { return new Expression_IndexRange(expr, isArray, low, high); } - public static _IExpression create_TupleSelect(DAST._IExpression expr, BigInteger index) { - return new Expression_TupleSelect(expr, index); + public static _IExpression create_TupleSelect(DAST._IExpression expr, BigInteger index, DAST._IType fieldType) { + return new Expression_TupleSelect(expr, index, fieldType); } public static _IExpression create_Call(DAST._IExpression @on, DAST._ICallName callName, Dafny.ISequence typeArgs, Dafny.ISequence args) { return new Expression_Call(@on, callName, typeArgs, args); @@ -4773,8 +5311,7 @@ public Dafny.ISequence dtor_Tuple_a0 { public Dafny.ISequence> dtor_path { get { var d = this; - if (d is Expression_New) { return ((Expression_New)d)._path; } - return ((Expression_DatatypeValue)d)._path; + return ((Expression_New)d)._path; } } public Dafny.ISequence dtor_typeArgs { @@ -4809,6 +5346,12 @@ public DAST._IType dtor_typ { return ((Expression_InitializationValue)d)._typ; } } + public DAST._IDatatypeType dtor_datatypeType { + get { + var d = this; + return ((Expression_DatatypeValue)d)._datatypeType; + } + } public Dafny.ISequence dtor_variant { get { var d = this; @@ -4998,6 +5541,13 @@ public bool dtor_onDatatype { return ((Expression_SelectFn)d)._onDatatype; } } + public DAST._IType dtor_fieldType { + get { + var d = this; + if (d is Expression_Select) { return ((Expression_Select)d)._fieldType; } + return ((Expression_TupleSelect)d)._fieldType; + } + } public bool dtor_isStatic { get { var d = this; @@ -5178,7 +5728,7 @@ public override int GetHashCode() { public override string ToString() { string s = "DAST.Expression.Ident"; s += "("; - s += this._a0.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._a0); s += ")"; return s; } @@ -5307,13 +5857,13 @@ public override string ToString() { } } public class Expression_DatatypeValue : Expression { - public readonly Dafny.ISequence> _path; + public readonly DAST._IDatatypeType _datatypeType; public readonly Dafny.ISequence _typeArgs; public readonly Dafny.ISequence _variant; public readonly bool _isCo; public readonly Dafny.ISequence<_System._ITuple2, DAST._IExpression>> _contents; - public Expression_DatatypeValue(Dafny.ISequence> path, Dafny.ISequence typeArgs, Dafny.ISequence variant, bool isCo, Dafny.ISequence<_System._ITuple2, DAST._IExpression>> contents) : base() { - this._path = path; + public Expression_DatatypeValue(DAST._IDatatypeType datatypeType, Dafny.ISequence typeArgs, Dafny.ISequence variant, bool isCo, Dafny.ISequence<_System._ITuple2, DAST._IExpression>> contents) : base() { + this._datatypeType = datatypeType; this._typeArgs = typeArgs; this._variant = variant; this._isCo = isCo; @@ -5321,16 +5871,16 @@ public Expression_DatatypeValue(Dafny.ISequence> pat } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_DatatypeValue(_path, _typeArgs, _variant, _isCo, _contents); + return new Expression_DatatypeValue(_datatypeType, _typeArgs, _variant, _isCo, _contents); } public override bool Equals(object other) { var oth = other as DAST.Expression_DatatypeValue; - return oth != null && object.Equals(this._path, oth._path) && object.Equals(this._typeArgs, oth._typeArgs) && object.Equals(this._variant, oth._variant) && this._isCo == oth._isCo && object.Equals(this._contents, oth._contents); + return oth != null && object.Equals(this._datatypeType, oth._datatypeType) && object.Equals(this._typeArgs, oth._typeArgs) && object.Equals(this._variant, oth._variant) && this._isCo == oth._isCo && object.Equals(this._contents, oth._contents); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 6; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._path)); + 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)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isCo)); @@ -5340,11 +5890,11 @@ public override int GetHashCode() { public override string ToString() { string s = "DAST.Expression.DatatypeValue"; s += "("; - s += Dafny.Helpers.ToString(this._path); + s += Dafny.Helpers.ToString(this._datatypeType); s += ", "; s += Dafny.Helpers.ToString(this._typeArgs); s += ", "; - s += this._variant.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._variant); s += ", "; s += Dafny.Helpers.ToString(this._isCo); s += ", "; @@ -5923,19 +6473,21 @@ public class Expression_Select : Expression { public readonly Dafny.ISequence _field; public readonly bool _isConstant; public readonly bool _onDatatype; - public Expression_Select(DAST._IExpression expr, Dafny.ISequence field, bool isConstant, bool onDatatype) : base() { + public readonly DAST._IType _fieldType; + public Expression_Select(DAST._IExpression expr, Dafny.ISequence field, bool isConstant, bool onDatatype, DAST._IType fieldType) : base() { this._expr = expr; this._field = field; this._isConstant = isConstant; this._onDatatype = onDatatype; + this._fieldType = fieldType; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_Select(_expr, _field, _isConstant, _onDatatype); + return new Expression_Select(_expr, _field, _isConstant, _onDatatype, _fieldType); } public override bool Equals(object other) { var oth = other as DAST.Expression_Select; - return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._field, oth._field) && this._isConstant == oth._isConstant && this._onDatatype == oth._onDatatype; + return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._field, oth._field) && this._isConstant == oth._isConstant && this._onDatatype == oth._onDatatype && object.Equals(this._fieldType, oth._fieldType); } public override int GetHashCode() { ulong hash = 5381; @@ -5944,6 +6496,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._field)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isConstant)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._onDatatype)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fieldType)); return (int) hash; } public override string ToString() { @@ -5951,11 +6504,13 @@ public override string ToString() { s += "("; s += Dafny.Helpers.ToString(this._expr); s += ", "; - s += this._field.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._field); s += ", "; s += Dafny.Helpers.ToString(this._isConstant); s += ", "; s += Dafny.Helpers.ToString(this._onDatatype); + s += ", "; + s += Dafny.Helpers.ToString(this._fieldType); s += ")"; return s; } @@ -5996,7 +6551,7 @@ public override string ToString() { s += "("; s += Dafny.Helpers.ToString(this._expr); s += ", "; - s += this._field.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._field); s += ", "; s += Dafny.Helpers.ToString(this._onDatatype); s += ", "; @@ -6089,23 +6644,26 @@ public override string ToString() { public class Expression_TupleSelect : Expression { public readonly DAST._IExpression _expr; public readonly BigInteger _index; - public Expression_TupleSelect(DAST._IExpression expr, BigInteger index) : base() { + public readonly DAST._IType _fieldType; + public Expression_TupleSelect(DAST._IExpression expr, BigInteger index, DAST._IType fieldType) : base() { this._expr = expr; this._index = index; + this._fieldType = fieldType; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_TupleSelect(_expr, _index); + return new Expression_TupleSelect(_expr, _index, _fieldType); } public override bool Equals(object other) { var oth = other as DAST.Expression_TupleSelect; - return oth != null && object.Equals(this._expr, oth._expr) && this._index == oth._index; + return oth != null && object.Equals(this._expr, oth._expr) && this._index == oth._index && object.Equals(this._fieldType, oth._fieldType); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 29; 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)); return (int) hash; } public override string ToString() { @@ -6114,6 +6672,8 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._expr); s += ", "; s += Dafny.Helpers.ToString(this._index); + s += ", "; + s += Dafny.Helpers.ToString(this._fieldType); s += ")"; return s; } @@ -6340,7 +6900,7 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._dType); s += ", "; - s += this._variant.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._variant); s += ")"; return s; } @@ -6593,6 +7153,7 @@ public interface _ILiteral { bool is_DecLiteral { get; } bool is_StringLiteral { get; } bool is_CharLiteral { get; } + bool is_CharLiteralUTF16 { get; } bool is_Null { get; } bool dtor_BoolLiteral_a0 { get; } Dafny.ISequence dtor_IntLiteral_a0 { get; } @@ -6601,7 +7162,9 @@ public interface _ILiteral { Dafny.ISequence dtor_DecLiteral_a1 { get; } DAST._IType dtor_DecLiteral_a2 { get; } Dafny.ISequence dtor_StringLiteral_a0 { get; } + bool dtor_verbatim { get; } Dafny.Rune dtor_CharLiteral_a0 { get; } + BigInteger dtor_CharLiteralUTF16_a0 { get; } DAST._IType dtor_Null_a0 { get; } _ILiteral DowncastClone(); } @@ -6625,12 +7188,15 @@ public static _ILiteral create_IntLiteral(Dafny.ISequence _a0, DAST. public static _ILiteral create_DecLiteral(Dafny.ISequence _a0, Dafny.ISequence _a1, DAST._IType _a2) { return new Literal_DecLiteral(_a0, _a1, _a2); } - public static _ILiteral create_StringLiteral(Dafny.ISequence _a0) { - return new Literal_StringLiteral(_a0); + public static _ILiteral create_StringLiteral(Dafny.ISequence _a0, bool verbatim) { + return new Literal_StringLiteral(_a0, verbatim); } public static _ILiteral create_CharLiteral(Dafny.Rune _a0) { return new Literal_CharLiteral(_a0); } + public static _ILiteral create_CharLiteralUTF16(BigInteger _a0) { + return new Literal_CharLiteralUTF16(_a0); + } public static _ILiteral create_Null(DAST._IType _a0) { return new Literal_Null(_a0); } @@ -6639,6 +7205,7 @@ public static _ILiteral create_Null(DAST._IType _a0) { public bool is_DecLiteral { get { return this is Literal_DecLiteral; } } public bool is_StringLiteral { get { return this is Literal_StringLiteral; } } public bool is_CharLiteral { get { return this is Literal_CharLiteral; } } + public bool is_CharLiteralUTF16 { get { return this is Literal_CharLiteralUTF16; } } public bool is_Null { get { return this is Literal_Null; } } public bool dtor_BoolLiteral_a0 { get { @@ -6682,12 +7249,24 @@ public Dafny.ISequence dtor_StringLiteral_a0 { return ((Literal_StringLiteral)d)._a0; } } + public bool dtor_verbatim { + get { + var d = this; + return ((Literal_StringLiteral)d)._verbatim; + } + } public Dafny.Rune dtor_CharLiteral_a0 { get { var d = this; return ((Literal_CharLiteral)d)._a0; } } + public BigInteger dtor_CharLiteralUTF16_a0 { + get { + var d = this; + return ((Literal_CharLiteralUTF16)d)._a0; + } + } public DAST._IType dtor_Null_a0 { get { var d = this; @@ -6794,27 +7373,32 @@ public override string ToString() { } public class Literal_StringLiteral : Literal { public readonly Dafny.ISequence _a0; - public Literal_StringLiteral(Dafny.ISequence _a0) : base() { + public readonly bool _verbatim; + public Literal_StringLiteral(Dafny.ISequence _a0, bool verbatim) : base() { this._a0 = _a0; + this._verbatim = verbatim; } public override _ILiteral DowncastClone() { if (this is _ILiteral dt) { return dt; } - return new Literal_StringLiteral(_a0); + return new Literal_StringLiteral(_a0, _verbatim); } public override bool Equals(object other) { var oth = other as DAST.Literal_StringLiteral; - return oth != null && object.Equals(this._a0, oth._a0); + return oth != null && object.Equals(this._a0, oth._a0) && this._verbatim == oth._verbatim; } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 3; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._a0)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._verbatim)); return (int) hash; } public override string ToString() { string s = "DAST.Literal.StringLiteral"; s += "("; s += this._a0.ToVerbatimString(true); + s += ", "; + s += Dafny.Helpers.ToString(this._verbatim); s += ")"; return s; } @@ -6846,6 +7430,33 @@ public override string ToString() { return s; } } + public class Literal_CharLiteralUTF16 : Literal { + public readonly BigInteger _a0; + public Literal_CharLiteralUTF16(BigInteger _a0) : base() { + this._a0 = _a0; + } + public override _ILiteral DowncastClone() { + if (this is _ILiteral dt) { return dt; } + return new Literal_CharLiteralUTF16(_a0); + } + public override bool Equals(object other) { + var oth = other as DAST.Literal_CharLiteralUTF16; + return oth != null && this._a0 == oth._a0; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 5; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._a0)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.Literal.CharLiteralUTF16"; + s += "("; + s += Dafny.Helpers.ToString(this._a0); + s += ")"; + return s; + } + } public class Literal_Null : Literal { public readonly DAST._IType _a0; public Literal_Null(DAST._IType _a0) : base() { @@ -6861,7 +7472,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._a0)); return (int) hash; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST_Format.cs b/Source/DafnyCore/GeneratedFromDafny/DAST_Format.cs index 2a5155169..eaff31e9c 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST_Format.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST_Format.cs @@ -11,6 +11,22 @@ namespace DAST.Format { + public partial class __default { + public static BigInteger SeqToHeight<__T>(Dafny.ISequence<__T> s, Func<__T, BigInteger> f) + { + if ((new BigInteger((s).Count)).Sign == 0) { + return BigInteger.Zero; + } else { + BigInteger _763_i = Dafny.Helpers.Id>(f)((s).Select(BigInteger.Zero)); + BigInteger _764_j = DAST.Format.__default.SeqToHeight<__T>((s).Drop(BigInteger.One), f); + if ((_763_i) < (_764_j)) { + return _764_j; + } else { + return _763_i; + } + } + } + } public interface _IUnaryOpFormat { bool is_NoFormat { get; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index fdd208e48..0a8fcffa6 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -28,50 +28,50 @@ public static bool has__special(Dafny.ISequence i) { if (((i).Select(BigInteger.One)) != (new Dafny.Rune('_'))) { return true; } else { - Dafny.ISequence _in113 = (i).Drop(new BigInteger(2)); - i = _in113; + Dafny.ISequence _in121 = (i).Drop(new BigInteger(2)); + i = _in121; goto TAIL_CALL_START; } } else { return true; } } else { - Dafny.ISequence _in114 = (i).Drop(BigInteger.One); - i = _in114; + Dafny.ISequence _in122 = (i).Drop(BigInteger.One); + i = _in122; goto TAIL_CALL_START; } } public static Dafny.ISequence idiomatic__rust(Dafny.ISequence i) { - Dafny.ISequence _984___accumulator = Dafny.Sequence.FromElements(); + Dafny.ISequence _1037___accumulator = Dafny.Sequence.FromElements(); TAIL_CALL_START: ; if ((new BigInteger((i).Count)).Sign == 0) { - return Dafny.Sequence.Concat(_984___accumulator, Dafny.Sequence.UnicodeFromString("")); + return Dafny.Sequence.Concat(_1037___accumulator, Dafny.Sequence.UnicodeFromString("")); } else if (((i).Select(BigInteger.Zero)) == (new Dafny.Rune('_'))) { - _984___accumulator = Dafny.Sequence.Concat(_984___accumulator, Dafny.Sequence.UnicodeFromString("_")); - Dafny.ISequence _in115 = (i).Drop(new BigInteger(2)); - i = _in115; + _1037___accumulator = Dafny.Sequence.Concat(_1037___accumulator, Dafny.Sequence.UnicodeFromString("_")); + Dafny.ISequence _in123 = (i).Drop(new BigInteger(2)); + i = _in123; goto TAIL_CALL_START; } else { - _984___accumulator = Dafny.Sequence.Concat(_984___accumulator, Dafny.Sequence.FromElements((i).Select(BigInteger.Zero))); - Dafny.ISequence _in116 = (i).Drop(BigInteger.One); - i = _in116; + _1037___accumulator = Dafny.Sequence.Concat(_1037___accumulator, Dafny.Sequence.FromElements((i).Select(BigInteger.Zero))); + Dafny.ISequence _in124 = (i).Drop(BigInteger.One); + i = _in124; goto TAIL_CALL_START; } } public static Dafny.ISequence replaceDots(Dafny.ISequence i) { - Dafny.ISequence _985___accumulator = Dafny.Sequence.FromElements(); + Dafny.ISequence _1038___accumulator = Dafny.Sequence.FromElements(); TAIL_CALL_START: ; if ((new BigInteger((i).Count)).Sign == 0) { - return Dafny.Sequence.Concat(_985___accumulator, Dafny.Sequence.UnicodeFromString("")); + return Dafny.Sequence.Concat(_1038___accumulator, Dafny.Sequence.UnicodeFromString("")); } else if (((i).Select(BigInteger.Zero)) == (new Dafny.Rune('.'))) { - _985___accumulator = Dafny.Sequence.Concat(_985___accumulator, Dafny.Sequence.UnicodeFromString("_d")); - Dafny.ISequence _in117 = (i).Drop(BigInteger.One); - i = _in117; + _1038___accumulator = Dafny.Sequence.Concat(_1038___accumulator, Dafny.Sequence.UnicodeFromString("_d")); + Dafny.ISequence _in125 = (i).Drop(BigInteger.One); + i = _in125; goto TAIL_CALL_START; } else { - _985___accumulator = Dafny.Sequence.Concat(_985___accumulator, Dafny.Sequence.FromElements((i).Select(BigInteger.Zero))); - Dafny.ISequence _in118 = (i).Drop(BigInteger.One); - i = _in118; + _1038___accumulator = Dafny.Sequence.Concat(_1038___accumulator, Dafny.Sequence.FromElements((i).Select(BigInteger.Zero))); + Dafny.ISequence _in126 = (i).Drop(BigInteger.One); + i = _in126; goto TAIL_CALL_START; } } @@ -85,7 +85,10 @@ public static bool is__dafny__generated__id(Dafny.ISequence i) { return ((((new BigInteger((i).Count)).Sign == 1) && (((i).Select(BigInteger.Zero)) == (new Dafny.Rune('_')))) && (!(DCOMP.__default.has__special((i).Drop(BigInteger.One))))) && (!((new BigInteger((i).Count)) >= (new BigInteger(2))) || (((i).Select(BigInteger.One)) != (new Dafny.Rune('T')))); } public static bool is__idiomatic__rust__id(Dafny.ISequence i) { - return (((new BigInteger((i).Count)).Sign == 1) && (!(DCOMP.__default.has__special(i)))) && (!(DCOMP.__default.reserved__rust).Contains(i)); + return ((((new BigInteger((i).Count)).Sign == 1) && (!(DCOMP.__default.has__special(i)))) && (!(DCOMP.__default.reserved__rust).Contains(i))) && (!(DCOMP.__default.reserved__rust__need__prefix).Contains(i)); + } + public static Dafny.ISequence escapeName(Dafny.ISequence n) { + return DCOMP.__default.escapeIdent((n)); } public static Dafny.ISequence escapeIdent(Dafny.ISequence i) { if (DCOMP.__default.is__tuple__numeric(i)) { @@ -99,20 +102,27 @@ public static bool is__idiomatic__rust__id(Dafny.ISequence i) { } else if (DCOMP.__default.is__dafny__generated__id(i)) { return i; } else { - Dafny.ISequence _986_r = DCOMP.__default.replaceDots(i); - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("r#_"), _986_r); + Dafny.ISequence _1039_r = DCOMP.__default.replaceDots(i); + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("r#_"), _1039_r); } } 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("Self"), Dafny.Sequence.UnicodeFromString("self"), 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.ISequence IND { get { return RAST.__default.IND; } } + public static DAST._IAttribute AttributeOwned { get { + return DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("owned"), Dafny.Sequence>.FromElements()); + } } } public interface _IOwnership { bool is_OwnershipOwned { get; } + bool is_OwnershipOwnedBox { get; } bool is_OwnershipBorrowed { get; } bool is_OwnershipBorrowedMut { get; } bool is_OwnershipAutoBorrowed { get; } @@ -132,6 +142,9 @@ public static DCOMP._IOwnership Default() { public static _IOwnership create_OwnershipOwned() { return new Ownership_OwnershipOwned(); } + public static _IOwnership create_OwnershipOwnedBox() { + return new Ownership_OwnershipOwnedBox(); + } public static _IOwnership create_OwnershipBorrowed() { return new Ownership_OwnershipBorrowed(); } @@ -142,12 +155,14 @@ public static _IOwnership create_OwnershipAutoBorrowed() { return new Ownership_OwnershipAutoBorrowed(); } public bool is_OwnershipOwned { get { return this is Ownership_OwnershipOwned; } } + public bool is_OwnershipOwnedBox { get { return this is Ownership_OwnershipOwnedBox; } } public bool is_OwnershipBorrowed { get { return this is Ownership_OwnershipBorrowed; } } public bool is_OwnershipBorrowedMut { get { return this is Ownership_OwnershipBorrowedMut; } } public bool is_OwnershipAutoBorrowed { get { return this is Ownership_OwnershipAutoBorrowed; } } public static System.Collections.Generic.IEnumerable<_IOwnership> AllSingletonConstructors { get { yield return Ownership.create_OwnershipOwned(); + yield return Ownership.create_OwnershipOwnedBox(); yield return Ownership.create_OwnershipBorrowed(); yield return Ownership.create_OwnershipBorrowedMut(); yield return Ownership.create_OwnershipAutoBorrowed(); @@ -176,6 +191,27 @@ public override string ToString() { return s; } } + public class Ownership_OwnershipOwnedBox : Ownership { + public Ownership_OwnershipOwnedBox() : base() { + } + public override _IOwnership DowncastClone() { + if (this is _IOwnership dt) { return dt; } + return new Ownership_OwnershipOwnedBox(); + } + public override bool Equals(object other) { + var oth = other as DCOMP.Ownership_OwnershipOwnedBox; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompiler.Ownership.OwnershipOwnedBox"; + return s; + } + } public class Ownership_OwnershipBorrowed : Ownership { public Ownership_OwnershipBorrowed() : base() { } @@ -189,7 +225,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + 2; return (int) hash; } public override string ToString() { @@ -210,7 +246,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + 3; return (int) hash; } public override string ToString() { @@ -231,7 +267,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + 4; return (int) hash; } public override string ToString() { @@ -240,661 +276,867 @@ public override string ToString() { } } + public interface _IEnvironment { + bool is_Environment { get; } + Dafny.ISequence> dtor_names { get; } + Dafny.IMap,RAST._IType> dtor_types { get; } + _IEnvironment DowncastClone(); + bool CanReadWithoutClone(Dafny.ISequence name); + bool HasCloneSemantics(Dafny.ISequence name); + Std.Wrappers._IOption GetType(Dafny.ISequence name); + bool IsBorrowed(Dafny.ISequence name); + bool IsBorrowedMut(Dafny.ISequence name); + DCOMP._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IType tpe); + DCOMP._IEnvironment RemoveAssigned(Dafny.ISequence name); + } + public class Environment : _IEnvironment { + public readonly Dafny.ISequence> _names; + public readonly Dafny.IMap,RAST._IType> _types; + public Environment(Dafny.ISequence> names, Dafny.IMap,RAST._IType> types) { + this._names = names; + this._types = types; + } + public _IEnvironment DowncastClone() { + if (this is _IEnvironment dt) { return dt; } + return new Environment(_names, _types); + } + public override bool Equals(object other) { + var oth = other as DCOMP.Environment; + return oth != null && object.Equals(this._names, oth._names) && object.Equals(this._types, oth._types); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._names)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._types)); + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompiler.Environment.Environment"; + s += "("; + s += Dafny.Helpers.ToString(this._names); + s += ", "; + s += Dafny.Helpers.ToString(this._types); + s += ")"; + return s; + } + private static readonly DCOMP._IEnvironment theDefault = create(Dafny.Sequence>.Empty, Dafny.Map, RAST._IType>.Empty); + public static DCOMP._IEnvironment Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DCOMP.Environment.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IEnvironment create(Dafny.ISequence> names, Dafny.IMap,RAST._IType> types) { + return new Environment(names, types); + } + public static _IEnvironment create_Environment(Dafny.ISequence> names, Dafny.IMap,RAST._IType> types) { + return create(names, types); + } + public bool is_Environment { get { return true; } } + public Dafny.ISequence> dtor_names { + get { + return this._names; + } + } + public Dafny.IMap,RAST._IType> dtor_types { + get { + return this._types; + } + } + public static DCOMP._IEnvironment Empty() { + return DCOMP.Environment.create(Dafny.Sequence>.FromElements(), Dafny.Map, RAST._IType>.FromElements()); + } + public bool CanReadWithoutClone(Dafny.ISequence name) { + return (((this).dtor_types).Contains(name)) && ((Dafny.Map, RAST._IType>.Select((this).dtor_types,name)).CanReadWithoutClone()); + } + public bool HasCloneSemantics(Dafny.ISequence name) { + return !((this).CanReadWithoutClone(name)); + } + public Std.Wrappers._IOption GetType(Dafny.ISequence name) { + if (((this).dtor_types).Contains(name)) { + return Std.Wrappers.Option.create_Some(Dafny.Map, RAST._IType>.Select((this).dtor_types,name)); + } else { + return Std.Wrappers.Option.create_None(); + } + } + public bool IsBorrowed(Dafny.ISequence name) { + return (((this).dtor_types).Contains(name)) && ((Dafny.Map, RAST._IType>.Select((this).dtor_types,name)).is_Borrowed); + } + public bool IsBorrowedMut(Dafny.ISequence name) { + return (((this).dtor_types).Contains(name)) && ((Dafny.Map, RAST._IType>.Select((this).dtor_types,name)).is_BorrowedMut); + } + public DCOMP._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IType tpe) + { + return DCOMP.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, Dafny.Sequence>.FromElements(name)), Dafny.Map, RAST._IType>.Update((this).dtor_types, name, tpe)); + } + public DCOMP._IEnvironment RemoveAssigned(Dafny.ISequence name) { + BigInteger _1040_indexInEnv = Std.Collections.Seq.__default.IndexOf>((this).dtor_names, name); + return DCOMP.Environment.create(Dafny.Sequence>.Concat(((this).dtor_names).Subsequence(BigInteger.Zero, _1040_indexInEnv), ((this).dtor_names).Drop((_1040_indexInEnv) + (BigInteger.One))), Dafny.Map, RAST._IType>.Subtract((this).dtor_types, Dafny.Set>.FromElements(name))); + } + } + public partial class COMP { public COMP() { + this.error = Std.Wrappers.Option>.Default(); this._UnicodeChars = false; } - public void __ctor(bool UnicodeChars) + public Std.Wrappers._IOption> error {get; set;} + public void __ctor(bool unicodeChars) { - (this)._UnicodeChars = UnicodeChars; + (this)._UnicodeChars = unicodeChars; + (this).error = Std.Wrappers.Option>.create_None(); } public RAST._IMod GenModule(DAST._IModule mod, Dafny.ISequence> containingPath) { RAST._IMod s = RAST.Mod.Default(); - Dafny.ISequence _987_body; - Dafny.ISequence _out15; - _out15 = (this).GenModuleBody((mod).dtor_body, Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((mod).dtor_name))); - _987_body = _out15; - s = (((mod).dtor_isExtern) ? (RAST.Mod.create_ExternMod(DCOMP.__default.escapeIdent((mod).dtor_name))) : (RAST.Mod.create_Mod(DCOMP.__default.escapeIdent((mod).dtor_name), _987_body))); + Dafny.ISequence _1041_modName; + _1041_modName = DCOMP.__default.escapeName((mod).dtor_name); + if (((mod).dtor_body).is_None) { + s = RAST.Mod.create_ExternMod(_1041_modName); + } else { + Dafny.ISequence _1042_body; + Dafny.ISequence _out15; + _out15 = (this).GenModuleBody(((mod).dtor_body).dtor_value, Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((mod).dtor_name))); + _1042_body = _out15; + s = RAST.Mod.create_Mod(_1041_modName, _1042_body); + } return s; } public Dafny.ISequence GenModuleBody(Dafny.ISequence body, Dafny.ISequence> containingPath) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); - BigInteger _988_i; - _988_i = BigInteger.Zero; - while ((_988_i) < (new BigInteger((body).Count))) { - Dafny.ISequence _989_generated = Dafny.Sequence.Empty; - DAST._IModuleItem _source41 = (body).Select(_988_i); - bool unmatched41 = true; - if (unmatched41) { - if (_source41.is_Module) { - DAST._IModule _990_m = _source41.dtor_Module_a0; - unmatched41 = false; - RAST._IMod _991_mm; + BigInteger _hi5 = new BigInteger((body).Count); + for (BigInteger _1043_i = BigInteger.Zero; _1043_i < _hi5; _1043_i++) { + Dafny.ISequence _1044_generated = Dafny.Sequence.Empty; + DAST._IModuleItem _source44 = (body).Select(_1043_i); + bool unmatched44 = true; + if (unmatched44) { + if (_source44.is_Module) { + DAST._IModule _1045_m = _source44.dtor_Module_a0; + unmatched44 = false; + RAST._IMod _1046_mm; RAST._IMod _out16; - _out16 = (this).GenModule(_990_m, containingPath); - _991_mm = _out16; - _989_generated = Dafny.Sequence.FromElements(RAST.ModDecl.create_ModDecl(_991_mm)); + _out16 = (this).GenModule(_1045_m, containingPath); + _1046_mm = _out16; + _1044_generated = Dafny.Sequence.FromElements(RAST.ModDecl.create_ModDecl(_1046_mm)); } } - if (unmatched41) { - if (_source41.is_Class) { - DAST._IClass _992_c = _source41.dtor_Class_a0; - unmatched41 = false; + if (unmatched44) { + if (_source44.is_Class) { + DAST._IClass _1047_c = _source44.dtor_Class_a0; + unmatched44 = false; Dafny.ISequence _out17; - _out17 = (this).GenClass(_992_c, Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((_992_c).dtor_name))); - _989_generated = _out17; + _out17 = (this).GenClass(_1047_c, Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((_1047_c).dtor_name))); + _1044_generated = _out17; } } - if (unmatched41) { - if (_source41.is_Trait) { - DAST._ITrait _993_t = _source41.dtor_Trait_a0; - unmatched41 = false; - Dafny.ISequence _994_tt; + if (unmatched44) { + if (_source44.is_Trait) { + DAST._ITrait _1048_t = _source44.dtor_Trait_a0; + unmatched44 = false; + Dafny.ISequence _1049_tt; Dafny.ISequence _out18; - _out18 = (this).GenTrait(_993_t, containingPath); - _994_tt = _out18; - _989_generated = Dafny.Sequence.FromElements(RAST.ModDecl.create_RawDecl(_994_tt)); + _out18 = (this).GenTrait(_1048_t, containingPath); + _1049_tt = _out18; + _1044_generated = Dafny.Sequence.FromElements(RAST.ModDecl.create_RawDecl(_1049_tt)); } } - if (unmatched41) { - if (_source41.is_Newtype) { - DAST._INewtype _995_n = _source41.dtor_Newtype_a0; - unmatched41 = false; + if (unmatched44) { + if (_source44.is_Newtype) { + DAST._INewtype _1050_n = _source44.dtor_Newtype_a0; + unmatched44 = false; Dafny.ISequence _out19; - _out19 = (this).GenNewtype(_995_n); - _989_generated = _out19; + _out19 = (this).GenNewtype(_1050_n); + _1044_generated = _out19; } } - if (unmatched41) { - DAST._IDatatype _996_d = _source41.dtor_Datatype_a0; - unmatched41 = false; + if (unmatched44) { + DAST._IDatatype _1051_d = _source44.dtor_Datatype_a0; + unmatched44 = false; Dafny.ISequence _out20; - _out20 = (this).GenDatatype(_996_d); - _989_generated = _out20; + _out20 = (this).GenDatatype(_1051_d); + _1044_generated = _out20; } - s = Dafny.Sequence.Concat(s, _989_generated); - _988_i = (_988_i) + (BigInteger.One); + s = Dafny.Sequence.Concat(s, _1044_generated); } return s; } - public void GenTypeParameters(Dafny.ISequence @params, out Dafny.ISet typeParamsSet, out Dafny.ISequence typeParams, out Dafny.ISequence constrainedTypeParams, out Dafny.ISequence whereConstraints) + public void GenTypeParam(DAST._ITypeArgDecl tp, out DAST._IType typeArg, out RAST._ITypeParamDecl typeParam) + { + typeArg = DAST.Type.Default(); + typeParam = RAST.TypeParamDecl.Default(); + typeArg = DAST.Type.create_TypeArg((tp).dtor_name); + Dafny.ISequence _1052_genTpConstraint; + _1052_genTpConstraint = ((((tp).dtor_bounds).Contains(DAST.TypeArgBound.create_SupportsEquality())) ? (Dafny.Sequence.FromElements(RAST.__default.DafnyTypeEq)) : (Dafny.Sequence.FromElements(RAST.__default.DafnyType))); + if (((tp).dtor_bounds).Contains(DAST.TypeArgBound.create_SupportsDefault())) { + _1052_genTpConstraint = Dafny.Sequence.Concat(_1052_genTpConstraint, Dafny.Sequence.FromElements(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default")))); + } + typeParam = RAST.TypeParamDecl.create(DCOMP.__default.escapeName(((tp).dtor_name)), _1052_genTpConstraint); + } + public void GenTypeParameters(Dafny.ISequence @params, out Dafny.ISet typeParamsSet, out Dafny.ISequence typeParams, out Dafny.ISequence constrainedTypeParams, out Dafny.ISequence whereConstraints) { typeParamsSet = Dafny.Set.Empty; - typeParams = Dafny.Sequence.Empty; - constrainedTypeParams = Dafny.Sequence.Empty; + typeParams = Dafny.Sequence.Empty; + constrainedTypeParams = Dafny.Sequence.Empty; whereConstraints = Dafny.Sequence.Empty; typeParamsSet = Dafny.Set.FromElements(); - typeParams = Dafny.Sequence.FromElements(); - constrainedTypeParams = Dafny.Sequence.FromElements(); + typeParams = Dafny.Sequence.FromElements(); + constrainedTypeParams = Dafny.Sequence.FromElements(); whereConstraints = Dafny.Sequence.UnicodeFromString(""); - BigInteger _997_tpI; - _997_tpI = BigInteger.Zero; if ((new BigInteger((@params).Count)).Sign == 1) { - while ((_997_tpI) < (new BigInteger((@params).Count))) { - DAST._IType _998_tp; - _998_tp = (@params).Select(_997_tpI); - typeParamsSet = Dafny.Set.Union(typeParamsSet, Dafny.Set.FromElements(_998_tp)); - RAST._IType _999_genTp; - RAST._IType _out21; - _out21 = (this).GenType(_998_tp, false, false); - _999_genTp = _out21; - typeParams = Dafny.Sequence.Concat(typeParams, Dafny.Sequence.FromElements(RAST.TypeParam.create((_999_genTp)._ToString(DCOMP.__default.IND), Dafny.Sequence.FromElements()))); - _997_tpI = (_997_tpI) + (BigInteger.One); - } - } - Dafny.ISequence _1000_baseConstraints; - _1000_baseConstraints = Dafny.Sequence.FromElements(RAST.__default.CloneTrait, RAST.__default.DafnyPrintTrait, RAST.__default.StaticTrait); - constrainedTypeParams = RAST.TypeParam.AddConstraintsMultiple(typeParams, _1000_baseConstraints); + BigInteger _hi6 = new BigInteger((@params).Count); + for (BigInteger _1053_tpI = BigInteger.Zero; _1053_tpI < _hi6; _1053_tpI++) { + DAST._ITypeArgDecl _1054_tp; + _1054_tp = (@params).Select(_1053_tpI); + DAST._IType _1055_typeArg; + RAST._ITypeParamDecl _1056_typeParam; + DAST._IType _out21; + RAST._ITypeParamDecl _out22; + (this).GenTypeParam(_1054_tp, out _out21, out _out22); + _1055_typeArg = _out21; + _1056_typeParam = _out22; + RAST._IType _1057_rType; + RAST._IType _out23; + _out23 = (this).GenType(_1055_typeArg, false, false); + _1057_rType = _out23; + typeParamsSet = Dafny.Set.Union(typeParamsSet, Dafny.Set.FromElements(_1055_typeArg)); + typeParams = Dafny.Sequence.Concat(typeParams, Dafny.Sequence.FromElements(_1057_rType)); + constrainedTypeParams = Dafny.Sequence.Concat(constrainedTypeParams, Dafny.Sequence.FromElements(_1056_typeParam)); + } + } } public Dafny.ISequence GenClass(DAST._IClass c, Dafny.ISequence> path) { Dafny.ISequence s = Dafny.Sequence.Empty; - Dafny.ISet _1001_typeParamsSet; - Dafny.ISequence _1002_sTypeParams; - Dafny.ISequence _1003_sConstrainedTypeParams; - Dafny.ISequence _1004_whereConstraints; - Dafny.ISet _out22; - Dafny.ISequence _out23; - Dafny.ISequence _out24; - Dafny.ISequence _out25; - (this).GenTypeParameters((c).dtor_typeParams, out _out22, out _out23, out _out24, out _out25); - _1001_typeParamsSet = _out22; - _1002_sTypeParams = _out23; - _1003_sConstrainedTypeParams = _out24; - _1004_whereConstraints = _out25; - Dafny.ISequence _1005_constrainedTypeParams; - _1005_constrainedTypeParams = RAST.TypeParam.ToStringMultiple(_1003_sConstrainedTypeParams, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); - Dafny.ISequence _1006_fields; - _1006_fields = Dafny.Sequence.FromElements(); - Dafny.ISequence _1007_fieldInits; - _1007_fieldInits = Dafny.Sequence.FromElements(); - BigInteger _1008_fieldI; - _1008_fieldI = BigInteger.Zero; - while ((_1008_fieldI) < (new BigInteger(((c).dtor_fields).Count))) { - DAST._IField _1009_field; - _1009_field = ((c).dtor_fields).Select(_1008_fieldI); - RAST._IType _1010_fieldType; - RAST._IType _out26; - _out26 = (this).GenType(((_1009_field).dtor_formal).dtor_typ, false, false); - _1010_fieldType = _out26; - _1006_fields = Dafny.Sequence.Concat(_1006_fields, Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("pub "), DCOMP.__default.escapeIdent(((_1009_field).dtor_formal).dtor_name)), RAST.Type.create_TypeApp(RAST.__default.refcell__type, Dafny.Sequence.FromElements(_1010_fieldType))))); - Std.Wrappers._IOption _source42 = (_1009_field).dtor_defaultValue; - bool unmatched42 = true; - if (unmatched42) { - if (_source42.is_Some) { - DAST._IExpression _1011_e = _source42.dtor_value; - unmatched42 = false; + Dafny.ISet _1058_typeParamsSet; + Dafny.ISequence _1059_rTypeParams; + Dafny.ISequence _1060_rTypeParamsDecls; + Dafny.ISequence _1061_whereConstraints; + Dafny.ISet _out24; + Dafny.ISequence _out25; + Dafny.ISequence _out26; + Dafny.ISequence _out27; + (this).GenTypeParameters((c).dtor_typeParams, out _out24, out _out25, out _out26, out _out27); + _1058_typeParamsSet = _out24; + _1059_rTypeParams = _out25; + _1060_rTypeParamsDecls = _out26; + _1061_whereConstraints = _out27; + Dafny.ISequence _1062_constrainedTypeParams; + _1062_constrainedTypeParams = RAST.TypeParamDecl.ToStringMultiple(_1060_rTypeParamsDecls, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); + Dafny.ISequence _1063_fields; + _1063_fields = Dafny.Sequence.FromElements(); + Dafny.ISequence _1064_fieldInits; + _1064_fieldInits = Dafny.Sequence.FromElements(); + BigInteger _hi7 = new BigInteger(((c).dtor_fields).Count); + for (BigInteger _1065_fieldI = BigInteger.Zero; _1065_fieldI < _hi7; _1065_fieldI++) { + DAST._IField _1066_field; + _1066_field = ((c).dtor_fields).Select(_1065_fieldI); + RAST._IType _1067_fieldType; + RAST._IType _out28; + _out28 = (this).GenType(((_1066_field).dtor_formal).dtor_typ, false, false); + _1067_fieldType = _out28; + Dafny.ISequence _1068_fieldRustName; + _1068_fieldRustName = DCOMP.__default.escapeName(((_1066_field).dtor_formal).dtor_name); + _1063_fields = Dafny.Sequence.Concat(_1063_fields, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(_1068_fieldRustName, _1067_fieldType)))); + Std.Wrappers._IOption _source45 = (_1066_field).dtor_defaultValue; + bool unmatched45 = true; + if (unmatched45) { + if (_source45.is_Some) { + DAST._IExpression _1069_e = _source45.dtor_value; + unmatched45 = false; { - RAST._IExpr _1012_eStr; - DCOMP._IOwnership _1013___v30; - Dafny.ISet> _1014___v31; - RAST._IExpr _out27; - DCOMP._IOwnership _out28; - Dafny.ISet> _out29; - (this).GenExpr(_1011_e, Std.Wrappers.Option>.create_None(), Dafny.Sequence>.FromElements(), DCOMP.Ownership.create_OwnershipOwned(), out _out27, out _out28, out _out29); - _1012_eStr = _out27; - _1013___v30 = _out28; - _1014___v31 = _out29; - _1007_fieldInits = Dafny.Sequence.Concat(_1007_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeIdent(((_1009_field).dtor_formal).dtor_name), RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::cell::RefCell::new("), (_1012_eStr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")))))); + RAST._IExpr _1070_expr; + DCOMP._IOwnership _1071___v42; + Dafny.ISet> _1072___v43; + RAST._IExpr _out29; + DCOMP._IOwnership _out30; + Dafny.ISet> _out31; + (this).GenExpr(_1069_e, Std.Wrappers.Option>.create_None(), DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out29, out _out30, out _out31); + _1070_expr = _out29; + _1071___v42 = _out30; + _1072___v43 = _out31; + _1064_fieldInits = Dafny.Sequence.Concat(_1064_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeName(((_1066_field).dtor_formal).dtor_name), RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::cell::RefCell::new("), (_1070_expr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")))))); } } } - if (unmatched42) { - unmatched42 = false; + if (unmatched45) { + unmatched45 = false; { - _1007_fieldInits = Dafny.Sequence.Concat(_1007_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeIdent(((_1009_field).dtor_formal).dtor_name), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::cell::RefCell::new(::std::default::Default::default())"))))); - } - } - _1008_fieldI = (_1008_fieldI) + (BigInteger.One); - } - BigInteger _1015_typeParamI; - _1015_typeParamI = BigInteger.Zero; - while ((_1015_typeParamI) < (new BigInteger(((c).dtor_typeParams).Count))) { - RAST._IType _1016_tpeGen; - RAST._IType _out30; - _out30 = (this).GenType(((c).dtor_typeParams).Select(_1015_typeParamI), false, false); - _1016_tpeGen = _out30; - _1006_fields = Dafny.Sequence.Concat(_1006_fields, Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_1015_typeParamI)), RAST.Type.create_TypeApp(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData")), Dafny.Sequence.FromElements(_1016_tpeGen))))); - _1007_fieldInits = Dafny.Sequence.Concat(_1007_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_1015_typeParamI)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::marker::PhantomData"))))); - _1015_typeParamI = (_1015_typeParamI) + (BigInteger.One); - } - RAST._IStruct _1017_struct; - _1017_struct = RAST.Struct.create(Dafny.Sequence>.FromElements(), DCOMP.__default.escapeIdent((c).dtor_name), _1002_sTypeParams, RAST.Formals.create_NamedFormals(_1006_fields)); - Dafny.ISequence _1018_typeParamsAsTypes; - _1018_typeParamsAsTypes = Std.Collections.Seq.__default.Map(((System.Func)((_1019_typeParam) => { - return RAST.__default.RawType((_1019_typeParam).dtor_content); - })), _1002_sTypeParams); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_1017_struct)); - Dafny.ISequence _1020_implBodyRaw; - Dafny.IMap>,Dafny.ISequence> _1021_traitBodies; - Dafny.ISequence _out31; - Dafny.IMap>,Dafny.ISequence> _out32; - (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_Path(Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(), DAST.ResolvedType.create_Datatype(path)), _1001_typeParamsSet, out _out31, out _out32); - _1020_implBodyRaw = _out31; - _1021_traitBodies = _out32; - Dafny.ISequence _1022_implBody; - _1022_implBody = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("new"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.Type.create_SelfOwned()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(DCOMP.__default.escapeIdent((c).dtor_name), _1007_fieldInits))))), _1020_implBodyRaw); - RAST._IImpl _1023_i; - _1023_i = RAST.Impl.create_Impl(_1003_sConstrainedTypeParams, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1018_typeParamsAsTypes), _1004_whereConstraints, _1022_implBody); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_1023_i))); + RAST._IExpr _1073_default; + _1073_default = RAST.__default.std__Default__default; + _1064_fieldInits = Dafny.Sequence.Concat(_1064_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_1068_fieldRustName, _1073_default))); + } + } + } + BigInteger _hi8 = new BigInteger(((c).dtor_typeParams).Count); + for (BigInteger _1074_typeParamI = BigInteger.Zero; _1074_typeParamI < _hi8; _1074_typeParamI++) { + DAST._IType _1075_typeArg; + RAST._ITypeParamDecl _1076_typeParam; + DAST._IType _out32; + RAST._ITypeParamDecl _out33; + (this).GenTypeParam(((c).dtor_typeParams).Select(_1074_typeParamI), out _out32, out _out33); + _1075_typeArg = _out32; + _1076_typeParam = _out33; + RAST._IType _1077_rTypeArg; + RAST._IType _out34; + _out34 = (this).GenType(_1075_typeArg, false, false); + _1077_rTypeArg = _out34; + _1063_fields = Dafny.Sequence.Concat(_1063_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(_1074_typeParamI)), RAST.Type.create_TypeApp(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData")), Dafny.Sequence.FromElements(_1077_rTypeArg)))))); + _1064_fieldInits = Dafny.Sequence.Concat(_1064_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_1074_typeParamI)), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::marker::PhantomData"))))); + } + Dafny.ISequence _1078_datatypeName; + _1078_datatypeName = DCOMP.__default.escapeName((c).dtor_name); + RAST._IStruct _1079_struct; + _1079_struct = RAST.Struct.create(Dafny.Sequence>.FromElements(), _1078_datatypeName, _1060_rTypeParamsDecls, RAST.Fields.create_NamedFields(_1063_fields)); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_1079_struct)); + Dafny.ISequence _1080_implBodyRaw; + Dafny.IMap>,Dafny.ISequence> _1081_traitBodies; + Dafny.ISequence _out35; + Dafny.IMap>,Dafny.ISequence> _out36; + (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_Path(Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(), DAST.ResolvedType.create_Datatype(DAST.DatatypeType.create(path, (c).dtor_attributes))), _1058_typeParamsSet, out _out35, out _out36); + _1080_implBodyRaw = _out35; + _1081_traitBodies = _out36; + Dafny.ISequence _1082_implBody; + _1082_implBody = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("new"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.Type.create_SelfOwned()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(RAST.Expr.create_Identifier(_1078_datatypeName), _1064_fieldInits))))), _1080_implBodyRaw); + RAST._IImpl _1083_i; + _1083_i = RAST.Impl.create_Impl(_1060_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1078_datatypeName), _1059_rTypeParams), _1061_whereConstraints, _1082_implBody); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_1083_i))); if ((new BigInteger(((c).dtor_superClasses).Count)).Sign == 1) { - BigInteger _1024_i; - _1024_i = BigInteger.Zero; - while ((_1024_i) < (new BigInteger(((c).dtor_superClasses).Count))) { - DAST._IType _1025_superClass; - _1025_superClass = ((c).dtor_superClasses).Select(_1024_i); - DAST._IType _source43 = _1025_superClass; - bool unmatched43 = true; - if (unmatched43) { - if (_source43.is_Path) { - Dafny.ISequence> _1026_traitPath = _source43.dtor_Path_a0; - Dafny.ISequence _1027_typeArgs = _source43.dtor_typeArgs; - DAST._IResolvedType resolved0 = _source43.dtor_resolved; + BigInteger _1084_i; + _1084_i = BigInteger.Zero; + while ((_1084_i) < (new BigInteger(((c).dtor_superClasses).Count))) { + DAST._IType _1085_superClass; + _1085_superClass = ((c).dtor_superClasses).Select(_1084_i); + DAST._IType _source46 = _1085_superClass; + bool unmatched46 = true; + if (unmatched46) { + if (_source46.is_Path) { + Dafny.ISequence> _1086_traitPath = _source46.dtor_Path_a0; + Dafny.ISequence _1087_typeArgs = _source46.dtor_typeArgs; + DAST._IResolvedType resolved0 = _source46.dtor_resolved; if (resolved0.is_Trait) { - Dafny.ISequence> _1028___v32 = resolved0.dtor_path; - unmatched43 = false; + Dafny.ISequence> _1088___v44 = resolved0.dtor_path; + Dafny.ISequence _1089___v45 = resolved0.dtor_attributes; + unmatched46 = false; { - Dafny.ISequence _1029_pathStr; - Dafny.ISequence _out33; - _out33 = DCOMP.COMP.GenPath(_1026_traitPath); - _1029_pathStr = _out33; - Dafny.ISequence _1030_typeArgs; - Dafny.ISequence _out34; - _out34 = (this).GenTypeArgs(_1027_typeArgs, false, false); - _1030_typeArgs = _out34; - Dafny.ISequence _1031_body; - _1031_body = Dafny.Sequence.FromElements(); - if ((_1021_traitBodies).Contains(_1026_traitPath)) { - _1031_body = Dafny.Map>, Dafny.ISequence>.Select(_1021_traitBodies,_1026_traitPath); + RAST._IType _1090_pathStr; + RAST._IType _out37; + _out37 = DCOMP.COMP.GenPath(_1086_traitPath); + _1090_pathStr = _out37; + Dafny.ISequence _1091_typeArgs; + Dafny.ISequence _out38; + _out38 = (this).GenTypeArgs(_1087_typeArgs, false, false); + _1091_typeArgs = _out38; + Dafny.ISequence _1092_body; + _1092_body = Dafny.Sequence.FromElements(); + if ((_1081_traitBodies).Contains(_1086_traitPath)) { + _1092_body = Dafny.Map>, Dafny.ISequence>.Select(_1081_traitBodies,_1086_traitPath); } - Dafny.ISequence _1032_genSelfPath; - Dafny.ISequence _out35; - _out35 = DCOMP.COMP.GenPath(path); - _1032_genSelfPath = _out35; - RAST._IModDecl _1033_x; - _1033_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1003_sConstrainedTypeParams, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1029_pathStr), _1030_typeArgs), RAST.__default.Rc(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1032_genSelfPath), _1018_typeParamsAsTypes)), _1004_whereConstraints, _1031_body)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_1033_x)); + RAST._IType _1093_genSelfPath; + RAST._IType _out39; + _out39 = DCOMP.COMP.GenPath(path); + _1093_genSelfPath = _out39; + RAST._IModDecl _1094_x; + _1094_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1060_rTypeParamsDecls, RAST.Type.create_TypeApp(_1090_pathStr, _1091_typeArgs), RAST.__default.Rc(RAST.Type.create_TypeApp(_1093_genSelfPath, _1059_rTypeParams)), _1061_whereConstraints, _1092_body)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_1094_x)); } } } } - if (unmatched43) { - DAST._IType _1034___v33 = _source43; - unmatched43 = false; - } - _1024_i = (_1024_i) + (BigInteger.One); - } - } - RAST._IImpl _1035_d; - _1035_d = RAST.Impl.create_ImplFor(_1003_sConstrainedTypeParams, RAST.__default.DefaultTrait, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1018_typeParamsAsTypes), _1004_whereConstraints, 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(RAST.Type.create_SelfOwned()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(DCOMP.__default.escapeIdent((c).dtor_name), Dafny.Sequence.UnicodeFromString("::new()")))))))); - Dafny.ISequence _1036_defaultImpl; - _1036_defaultImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_1035_d)); - RAST._IImpl _1037_p; - _1037_p = RAST.Impl.create_ImplFor(_1003_sConstrainedTypeParams, RAST.__default.DafnyPrintTrait, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1018_typeParamsAsTypes), 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.self, 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.__default.RawType(Dafny.Sequence.UnicodeFromString("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.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("write!(_formatter, \""), ((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")), (c).dtor_name), Dafny.Sequence.UnicodeFromString("\")")))))))); - Dafny.ISequence _1038_printImpl; - _1038_printImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_1037_p)); - RAST._IImpl _1039_pp; - _1039_pp = RAST.Impl.create_ImplFor(_1002_sTypeParams, RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("::std::cmp::PartialEq")), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1018_typeParamsAsTypes), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.self, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.Self)), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("bool"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::ptr::eq(self, other)"))))))); - Dafny.ISequence _1040_ptrPartialEqImpl; - _1040_ptrPartialEqImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_1039_pp)); - s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, _1036_defaultImpl), _1038_printImpl), _1040_ptrPartialEqImpl); + if (unmatched46) { + DAST._IType _1095___v46 = _source46; + unmatched46 = false; + } + _1084_i = (_1084_i) + (BigInteger.One); + } + } + RAST._IImpl _1096_d; + _1096_d = RAST.Impl.create_ImplFor(_1060_rTypeParamsDecls, RAST.__default.DefaultTrait, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1078_datatypeName), _1059_rTypeParams), _1061_whereConstraints, 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(RAST.Type.create_SelfOwned()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(_1078_datatypeName, Dafny.Sequence.UnicodeFromString("::new()")))))))); + Dafny.ISequence _1097_defaultImpl; + _1097_defaultImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_1096_d)); + RAST._IImpl _1098_p; + _1098_p = RAST.Impl.create_ImplFor(_1060_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1078_datatypeName), _1059_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.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("write!(_formatter, \""), DCOMP.__default.escapeName(((c).dtor_enclosingModule))), Dafny.Sequence.UnicodeFromString(".")), DCOMP.__default.escapeName((c).dtor_name)), Dafny.Sequence.UnicodeFromString("\")")))))))); + Dafny.ISequence _1099_printImpl; + _1099_printImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_1098_p)); + RAST._IImpl _1100_pp; + _1100_pp = RAST.Impl.create_ImplFor(_1060_rTypeParamsDecls, RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("::std::cmp::PartialEq")), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1078_datatypeName), _1059_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::ptr::eq(self, other)"))))))); + Dafny.ISequence _1101_ptrPartialEqImpl; + _1101_ptrPartialEqImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_1100_pp)); + s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, _1097_defaultImpl), _1099_printImpl), _1101_ptrPartialEqImpl); return s; } public Dafny.ISequence GenTrait(DAST._ITrait t, Dafny.ISequence> containingPath) { Dafny.ISequence s = Dafny.Sequence.Empty; - Dafny.ISet _1041_typeParamsSet; - _1041_typeParamsSet = Dafny.Set.FromElements(); - Dafny.ISequence _1042_typeParams; - _1042_typeParams = Dafny.Sequence.FromElements(); - BigInteger _1043_tpI; - _1043_tpI = BigInteger.Zero; + Dafny.ISet _1102_typeParamsSet; + _1102_typeParamsSet = Dafny.Set.FromElements(); + Dafny.ISequence _1103_typeParamDecls; + _1103_typeParamDecls = Dafny.Sequence.FromElements(); + Dafny.ISequence _1104_typeParams; + _1104_typeParams = Dafny.Sequence.FromElements(); + BigInteger _1105_tpI; + _1105_tpI = BigInteger.Zero; if ((new BigInteger(((t).dtor_typeParams).Count)).Sign == 1) { - while ((_1043_tpI) < (new BigInteger(((t).dtor_typeParams).Count))) { - DAST._IType _1044_tp; - _1044_tp = ((t).dtor_typeParams).Select(_1043_tpI); - _1041_typeParamsSet = Dafny.Set.Union(_1041_typeParamsSet, Dafny.Set.FromElements(_1044_tp)); - RAST._IType _1045_genTp; - RAST._IType _out36; - _out36 = (this).GenType(_1044_tp, false, false); - _1045_genTp = _out36; - _1042_typeParams = Dafny.Sequence.Concat(_1042_typeParams, Dafny.Sequence.FromElements(_1045_genTp)); - _1043_tpI = (_1043_tpI) + (BigInteger.One); - } - } - Dafny.ISequence> _1046_fullPath; - _1046_fullPath = Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((t).dtor_name)); - Dafny.ISequence _1047_implBody; - Dafny.IMap>,Dafny.ISequence> _1048___v34; - Dafny.ISequence _out37; - Dafny.IMap>,Dafny.ISequence> _out38; - (this).GenClassImplBody((t).dtor_body, true, DAST.Type.create_Path(_1046_fullPath, Dafny.Sequence.FromElements(), DAST.ResolvedType.create_Trait(_1046_fullPath)), _1041_typeParamsSet, out _out37, out _out38); - _1047_implBody = _out37; - _1048___v34 = _out38; - s = (RAST.ModDecl.create_TraitDecl(RAST.Trait.create(Dafny.Sequence.FromElements(), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((t).dtor_name)), _1042_typeParams), Dafny.Sequence.UnicodeFromString(""), _1047_implBody)))._ToString(DCOMP.__default.IND); + while ((_1105_tpI) < (new BigInteger(((t).dtor_typeParams).Count))) { + DAST._ITypeArgDecl _1106_tp; + _1106_tp = ((t).dtor_typeParams).Select(_1105_tpI); + DAST._IType _1107_typeArg; + RAST._ITypeParamDecl _1108_typeParamDecl; + DAST._IType _out40; + RAST._ITypeParamDecl _out41; + (this).GenTypeParam(_1106_tp, out _out40, out _out41); + _1107_typeArg = _out40; + _1108_typeParamDecl = _out41; + _1102_typeParamsSet = Dafny.Set.Union(_1102_typeParamsSet, Dafny.Set.FromElements(_1107_typeArg)); + _1103_typeParamDecls = Dafny.Sequence.Concat(_1103_typeParamDecls, Dafny.Sequence.FromElements(_1108_typeParamDecl)); + RAST._IType _1109_typeParam; + RAST._IType _out42; + _out42 = (this).GenType(_1107_typeArg, false, false); + _1109_typeParam = _out42; + _1104_typeParams = Dafny.Sequence.Concat(_1104_typeParams, Dafny.Sequence.FromElements(_1109_typeParam)); + _1105_tpI = (_1105_tpI) + (BigInteger.One); + } + } + Dafny.ISequence> _1110_fullPath; + _1110_fullPath = Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((t).dtor_name)); + Dafny.ISequence _1111_implBody; + Dafny.IMap>,Dafny.ISequence> _1112___v47; + Dafny.ISequence _out43; + Dafny.IMap>,Dafny.ISequence> _out44; + (this).GenClassImplBody((t).dtor_body, true, DAST.Type.create_Path(_1110_fullPath, Dafny.Sequence.FromElements(), DAST.ResolvedType.create_Trait(_1110_fullPath, (t).dtor_attributes)), _1102_typeParamsSet, out _out43, out _out44); + _1111_implBody = _out43; + _1112___v47 = _out44; + s = (RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1103_typeParamDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeName((t).dtor_name)), _1104_typeParams), Dafny.Sequence.UnicodeFromString(""), _1111_implBody)))._ToString(DCOMP.__default.IND); return s; } public Dafny.ISequence GenNewtype(DAST._INewtype c) { Dafny.ISequence s = Dafny.Sequence.Empty; - Dafny.ISet _1049_typeParamsSet; - Dafny.ISequence _1050_sTypeParams; - Dafny.ISequence _1051_sConstrainedTypeParams; - Dafny.ISequence _1052_whereConstraints; - Dafny.ISet _out39; - Dafny.ISequence _out40; - Dafny.ISequence _out41; - Dafny.ISequence _out42; - (this).GenTypeParameters((c).dtor_typeParams, out _out39, out _out40, out _out41, out _out42); - _1049_typeParamsSet = _out39; - _1050_sTypeParams = _out40; - _1051_sConstrainedTypeParams = _out41; - _1052_whereConstraints = _out42; - Dafny.ISequence _1053_typeParamsAsTypes; - _1053_typeParamsAsTypes = Std.Collections.Seq.__default.Map(((System.Func)((_1054_t) => { - return RAST.__default.RawType((_1054_t).dtor_content); - })), _1050_sTypeParams); - Dafny.ISequence _1055_constrainedTypeParams; - _1055_constrainedTypeParams = RAST.TypeParam.ToStringMultiple(_1051_sConstrainedTypeParams, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); - RAST._IType _1056_underlyingType = RAST.Type.Default(); - Std.Wrappers._IOption _source44 = DCOMP.COMP.NewtypeToRustType((c).dtor_base, (c).dtor_range); - bool unmatched44 = true; - if (unmatched44) { - if (_source44.is_Some) { - RAST._IType _1057_v = _source44.dtor_value; - unmatched44 = false; - _1056_underlyingType = _1057_v; - } - } - if (unmatched44) { - unmatched44 = false; - RAST._IType _out43; - _out43 = (this).GenType((c).dtor_base, false, false); - _1056_underlyingType = _out43; - } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq)]"), Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), DCOMP.__default.escapeIdent((c).dtor_name), _1050_sTypeParams, RAST.Formals.create_NamelessFormals(Dafny.Sequence.FromElements(RAST.NamelessFormal.create(RAST.Visibility.create_PUB(), _1056_underlyingType)))))); - Dafny.ISequence _1058_fnBody; - _1058_fnBody = Dafny.Sequence.UnicodeFromString(""); - Std.Wrappers._IOption _source45 = (c).dtor_witnessExpr; - bool unmatched45 = true; - if (unmatched45) { - if (_source45.is_Some) { - DAST._IExpression _1059_e = _source45.dtor_value; - unmatched45 = false; + Dafny.ISet _1113_typeParamsSet; + Dafny.ISequence _1114_rTypeParams; + Dafny.ISequence _1115_rTypeParamsDecls; + Dafny.ISequence _1116_whereConstraints; + Dafny.ISet _out45; + Dafny.ISequence _out46; + Dafny.ISequence _out47; + Dafny.ISequence _out48; + (this).GenTypeParameters((c).dtor_typeParams, out _out45, out _out46, out _out47, out _out48); + _1113_typeParamsSet = _out45; + _1114_rTypeParams = _out46; + _1115_rTypeParamsDecls = _out47; + _1116_whereConstraints = _out48; + Dafny.ISequence _1117_constrainedTypeParams; + _1117_constrainedTypeParams = RAST.TypeParamDecl.ToStringMultiple(_1115_rTypeParamsDecls, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); + RAST._IType _1118_underlyingType = RAST.Type.Default(); + Std.Wrappers._IOption _source47 = DCOMP.COMP.NewtypeToRustType((c).dtor_base, (c).dtor_range); + bool unmatched47 = true; + if (unmatched47) { + if (_source47.is_Some) { + RAST._IType _1119_v = _source47.dtor_value; + unmatched47 = false; + _1118_underlyingType = _1119_v; + } + } + if (unmatched47) { + unmatched47 = false; + RAST._IType _out49; + _out49 = (this).GenType((c).dtor_base, false, false); + _1118_underlyingType = _out49; + } + DAST._IType _1120_resultingType; + _1120_resultingType = DAST.Type.create_Path(Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(), DAST.ResolvedType.create_Newtype((c).dtor_base, (c).dtor_range, false, (c).dtor_attributes)); + Dafny.ISequence _1121_datatypeName; + _1121_datatypeName = DCOMP.__default.escapeName((c).dtor_name); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq)]"), Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), _1121_datatypeName, _1115_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _1118_underlyingType)))))); + RAST._IExpr _1122_fnBody; + _1122_fnBody = RAST.Expr.create_Identifier(_1121_datatypeName); + Std.Wrappers._IOption _source48 = (c).dtor_witnessExpr; + bool unmatched48 = true; + if (unmatched48) { + if (_source48.is_Some) { + DAST._IExpression _1123_e = _source48.dtor_value; + unmatched48 = false; { - RAST._IExpr _1060_eStr; - DCOMP._IOwnership _1061___v35; - Dafny.ISet> _1062___v36; - RAST._IExpr _out44; - DCOMP._IOwnership _out45; - Dafny.ISet> _out46; - (this).GenExpr(_1059_e, Std.Wrappers.Option>.create_None(), Dafny.Sequence>.FromElements(), DCOMP.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); - _1060_eStr = _out44; - _1061___v35 = _out45; - _1062___v36 = _out46; - _1058_fnBody = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1058_fnBody, DCOMP.__default.escapeIdent((c).dtor_name)), Dafny.Sequence.UnicodeFromString("(")), (_1060_eStr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")\n")); - } - } - } - if (unmatched45) { - unmatched45 = false; + DAST._IExpression _1124_e; + _1124_e = ((object.Equals((c).dtor_base, _1120_resultingType)) ? (_1123_e) : (DAST.Expression.create_Convert(_1123_e, (c).dtor_base, _1120_resultingType))); + RAST._IExpr _1125_eStr; + DCOMP._IOwnership _1126___v48; + Dafny.ISet> _1127___v49; + RAST._IExpr _out50; + DCOMP._IOwnership _out51; + Dafny.ISet> _out52; + (this).GenExpr(_1124_e, Std.Wrappers.Option>.create_None(), DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); + _1125_eStr = _out50; + _1126___v48 = _out51; + _1127___v49 = _out52; + _1122_fnBody = (_1122_fnBody).Apply1(_1125_eStr); + } + } + } + if (unmatched48) { + unmatched48 = false; { - _1058_fnBody = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1058_fnBody, DCOMP.__default.escapeIdent((c).dtor_name)), Dafny.Sequence.UnicodeFromString("(::std::default::Default::default())")); + _1122_fnBody = (_1122_fnBody).Apply1(RAST.__default.std__Default__default); } } - RAST._IImplMember _1063_body; - _1063_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(RAST.Expr.create_RawExpr(_1058_fnBody)))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1051_sConstrainedTypeParams, RAST.__default.DefaultTrait, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1053_typeParamsAsTypes), _1052_whereConstraints, Dafny.Sequence.FromElements(_1063_body))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1051_sConstrainedTypeParams, RAST.__default.DafnyPrintTrait, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1053_typeParamsAsTypes), 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.self, 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.__default.RawType(Dafny.Sequence.UnicodeFromString("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(_1051_sConstrainedTypeParams, RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("::std::ops::Deref")), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1053_typeParamsAsTypes), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_RawImplMember(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("type Target = "), (_1056_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.self), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("&Self::Target"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("&self.0")))))))))); + RAST._IImplMember _1128_body; + _1128_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(_1122_fnBody))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1115_rTypeParamsDecls, RAST.__default.DefaultTrait, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1121_datatypeName), _1114_rTypeParams), _1116_whereConstraints, Dafny.Sequence.FromElements(_1128_body))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1115_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1121_datatypeName), _1114_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(_1115_rTypeParamsDecls, RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("::std::ops::Deref")), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1121_datatypeName), _1114_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_RawImplMember(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("type Target = "), (_1118_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")))))))))); return s; } public Dafny.ISequence GenDatatype(DAST._IDatatype c) { Dafny.ISequence s = Dafny.Sequence.Empty; - Dafny.ISet _1064_typeParamsSet; - Dafny.ISequence _1065_sTypeParams; - Dafny.ISequence _1066_sConstrainedTypeParams; - Dafny.ISequence _1067_whereConstraints; - Dafny.ISet _out47; - Dafny.ISequence _out48; - Dafny.ISequence _out49; - Dafny.ISequence _out50; - (this).GenTypeParameters((c).dtor_typeParams, out _out47, out _out48, out _out49, out _out50); - _1064_typeParamsSet = _out47; - _1065_sTypeParams = _out48; - _1066_sConstrainedTypeParams = _out49; - _1067_whereConstraints = _out50; - Dafny.ISequence _1068_typeParamsAsTypes; - _1068_typeParamsAsTypes = Std.Collections.Seq.__default.Map(((System.Func)((_1069_t) => { - return RAST.__default.RawType((_1069_t).dtor_content); - })), _1065_sTypeParams); - Dafny.ISequence _1070_constrainedTypeParams; - _1070_constrainedTypeParams = RAST.TypeParam.ToStringMultiple(_1066_sConstrainedTypeParams, Dafny.Sequence.Concat(DCOMP.__default.IND, DCOMP.__default.IND)); - Dafny.ISequence _1071_ctors; - _1071_ctors = Dafny.Sequence.FromElements(); - BigInteger _1072_i; - _1072_i = BigInteger.Zero; - while ((_1072_i) < (new BigInteger(((c).dtor_ctors).Count))) { - DAST._IDatatypeCtor _1073_ctor; - _1073_ctor = ((c).dtor_ctors).Select(_1072_i); - Dafny.ISequence _1074_ctorArgs; - _1074_ctorArgs = Dafny.Sequence.FromElements(); - BigInteger _1075_j; - _1075_j = BigInteger.Zero; - while ((_1075_j) < (new BigInteger(((_1073_ctor).dtor_args).Count))) { - DAST._IFormal _1076_formal; - _1076_formal = ((_1073_ctor).dtor_args).Select(_1075_j); - RAST._IType _1077_formalType; - RAST._IType _out51; - _out51 = (this).GenType((_1076_formal).dtor_typ, false, false); - _1077_formalType = _out51; + Dafny.ISet _1129_typeParamsSet; + Dafny.ISequence _1130_rTypeParams; + Dafny.ISequence _1131_rTypeParamsDecls; + Dafny.ISequence _1132_whereConstraints; + Dafny.ISet _out53; + Dafny.ISequence _out54; + Dafny.ISequence _out55; + Dafny.ISequence _out56; + (this).GenTypeParameters((c).dtor_typeParams, out _out53, out _out54, out _out55, out _out56); + _1129_typeParamsSet = _out53; + _1130_rTypeParams = _out54; + _1131_rTypeParamsDecls = _out55; + _1132_whereConstraints = _out56; + Dafny.ISequence _1133_datatypeName; + _1133_datatypeName = DCOMP.__default.escapeName((c).dtor_name); + Dafny.ISequence _1134_ctors; + _1134_ctors = Dafny.Sequence.FromElements(); + BigInteger _hi9 = new BigInteger(((c).dtor_ctors).Count); + for (BigInteger _1135_i = BigInteger.Zero; _1135_i < _hi9; _1135_i++) { + DAST._IDatatypeCtor _1136_ctor; + _1136_ctor = ((c).dtor_ctors).Select(_1135_i); + Dafny.ISequence _1137_ctorArgs; + _1137_ctorArgs = Dafny.Sequence.FromElements(); + bool _1138_isNumeric; + _1138_isNumeric = false; + BigInteger _hi10 = new BigInteger(((_1136_ctor).dtor_args).Count); + for (BigInteger _1139_j = BigInteger.Zero; _1139_j < _hi10; _1139_j++) { + DAST._IDatatypeDtor _1140_dtor; + _1140_dtor = ((_1136_ctor).dtor_args).Select(_1139_j); + RAST._IType _1141_formalType; + RAST._IType _out57; + _out57 = (this).GenType(((_1140_dtor).dtor_formal).dtor_typ, false, false); + _1141_formalType = _out57; + Dafny.ISequence _1142_formalName; + _1142_formalName = DCOMP.__default.escapeName(((_1140_dtor).dtor_formal).dtor_name); + if (((_1139_j).Sign == 0) && ((Dafny.Sequence.UnicodeFromString("0")).Equals(_1142_formalName))) { + _1138_isNumeric = true; + } + if ((((_1139_j).Sign != 0) && (_1138_isNumeric)) && (!(Std.Strings.__default.OfNat(_1139_j)).Equals(_1142_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 "), _1142_formalName), Dafny.Sequence.UnicodeFromString(" instead of ")), Std.Strings.__default.OfNat(_1139_j))); + _1138_isNumeric = false; + } if ((c).dtor_isCo) { - _1074_ctorArgs = Dafny.Sequence.Concat(_1074_ctorArgs, Dafny.Sequence.FromElements(RAST.Formal.create(DCOMP.__default.escapeIdent((_1076_formal).dtor_name), RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("LazyFieldWrapper")), Dafny.Sequence.FromElements(_1077_formalType))))); + _1137_ctorArgs = Dafny.Sequence.Concat(_1137_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_1142_formalName, RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("LazyFieldWrapper")), Dafny.Sequence.FromElements(_1141_formalType)))))); } else { - _1074_ctorArgs = Dafny.Sequence.Concat(_1074_ctorArgs, Dafny.Sequence.FromElements(RAST.Formal.create(DCOMP.__default.escapeIdent((_1076_formal).dtor_name), _1077_formalType))); - } - _1075_j = (_1075_j) + (BigInteger.One); - } - _1071_ctors = Dafny.Sequence.Concat(_1071_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(DCOMP.__default.escapeIdent((_1073_ctor).dtor_name), RAST.Formals.create_NamedFormals(_1074_ctorArgs)))); - _1072_i = (_1072_i) + (BigInteger.One); - } - Dafny.ISequence> _1078_selfPath; - _1078_selfPath = Dafny.Sequence>.FromElements((c).dtor_name); - Dafny.ISequence _1079_implBodyRaw; - Dafny.IMap>,Dafny.ISequence> _1080_traitBodies; - Dafny.ISequence _out52; - Dafny.IMap>,Dafny.ISequence> _out53; - (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_Path(Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(), DAST.ResolvedType.create_Datatype(_1078_selfPath)), _1064_typeParamsSet, out _out52, out _out53); - _1079_implBodyRaw = _out52; - _1080_traitBodies = _out53; - Dafny.ISequence _1081_implBody; - _1081_implBody = _1079_implBodyRaw; - _1072_i = BigInteger.Zero; - Dafny.ISet> _1082_emittedFields; - _1082_emittedFields = Dafny.Set>.FromElements(); - while ((_1072_i) < (new BigInteger(((c).dtor_ctors).Count))) { - DAST._IDatatypeCtor _1083_ctor; - _1083_ctor = ((c).dtor_ctors).Select(_1072_i); - BigInteger _1084_j; - _1084_j = BigInteger.Zero; - while ((_1084_j) < (new BigInteger(((_1083_ctor).dtor_args).Count))) { - DAST._IFormal _1085_formal; - _1085_formal = ((_1083_ctor).dtor_args).Select(_1084_j); - if (!((_1082_emittedFields).Contains((_1085_formal).dtor_name))) { - _1082_emittedFields = Dafny.Set>.Union(_1082_emittedFields, Dafny.Set>.FromElements((_1085_formal).dtor_name)); - RAST._IType _1086_formalType; - RAST._IType _out54; - _out54 = (this).GenType((_1085_formal).dtor_typ, false, false); - _1086_formalType = _out54; - Dafny.ISequence _1087_cases; - _1087_cases = Dafny.Sequence.FromElements(); - BigInteger _1088_k; - _1088_k = BigInteger.Zero; - while ((_1088_k) < (new BigInteger(((c).dtor_ctors).Count))) { - DAST._IDatatypeCtor _1089_ctor2; - _1089_ctor2 = ((c).dtor_ctors).Select(_1088_k); - Dafny.ISequence _1090_pattern; - _1090_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(DCOMP.__default.escapeIdent((c).dtor_name), Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeIdent((_1089_ctor2).dtor_name)), Dafny.Sequence.UnicodeFromString(" { ")); - Dafny.ISequence _1091_rhs = Dafny.Sequence.Empty; - BigInteger _1092_l; - _1092_l = BigInteger.Zero; - bool _1093_hasMatchingField; - _1093_hasMatchingField = false; - while ((_1092_l) < (new BigInteger(((_1089_ctor2).dtor_args).Count))) { - DAST._IFormal _1094_formal2; - _1094_formal2 = ((_1089_ctor2).dtor_args).Select(_1092_l); - if (((_1085_formal).dtor_name).Equals((_1094_formal2).dtor_name)) { - _1093_hasMatchingField = true; + _1137_ctorArgs = Dafny.Sequence.Concat(_1137_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_1142_formalName, _1141_formalType)))); + } + } + RAST._IFields _1143_namedFields; + _1143_namedFields = RAST.Fields.create_NamedFields(_1137_ctorArgs); + if (_1138_isNumeric) { + _1143_namedFields = (_1143_namedFields).ToNamelessFields(); + } + _1134_ctors = Dafny.Sequence.Concat(_1134_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(DCOMP.__default.escapeName((_1136_ctor).dtor_name), _1143_namedFields))); + } + Dafny.ISequence> _1144_selfPath; + _1144_selfPath = Dafny.Sequence>.FromElements((c).dtor_name); + Dafny.ISequence _1145_implBodyRaw; + Dafny.IMap>,Dafny.ISequence> _1146_traitBodies; + Dafny.ISequence _out58; + Dafny.IMap>,Dafny.ISequence> _out59; + (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_Path(Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(), DAST.ResolvedType.create_Datatype(DAST.DatatypeType.create(_1144_selfPath, (c).dtor_attributes))), _1129_typeParamsSet, out _out58, out _out59); + _1145_implBodyRaw = _out58; + _1146_traitBodies = _out59; + Dafny.ISequence _1147_implBody; + _1147_implBody = _1145_implBodyRaw; + Dafny.ISet> _1148_emittedFields; + _1148_emittedFields = Dafny.Set>.FromElements(); + BigInteger _hi11 = new BigInteger(((c).dtor_ctors).Count); + for (BigInteger _1149_i = BigInteger.Zero; _1149_i < _hi11; _1149_i++) { + DAST._IDatatypeCtor _1150_ctor; + _1150_ctor = ((c).dtor_ctors).Select(_1149_i); + BigInteger _hi12 = new BigInteger(((_1150_ctor).dtor_args).Count); + for (BigInteger _1151_j = BigInteger.Zero; _1151_j < _hi12; _1151_j++) { + DAST._IDatatypeDtor _1152_dtor; + _1152_dtor = ((_1150_ctor).dtor_args).Select(_1151_j); + Dafny.ISequence _1153_callName; + _1153_callName = Std.Wrappers.Option>.GetOr((_1152_dtor).dtor_callName, DCOMP.__default.escapeName(((_1152_dtor).dtor_formal).dtor_name)); + if (!((_1148_emittedFields).Contains(_1153_callName))) { + _1148_emittedFields = Dafny.Set>.Union(_1148_emittedFields, Dafny.Set>.FromElements(_1153_callName)); + RAST._IType _1154_formalType; + RAST._IType _out60; + _out60 = (this).GenType(((_1152_dtor).dtor_formal).dtor_typ, false, false); + _1154_formalType = _out60; + Dafny.ISequence _1155_cases; + _1155_cases = Dafny.Sequence.FromElements(); + BigInteger _hi13 = new BigInteger(((c).dtor_ctors).Count); + for (BigInteger _1156_k = BigInteger.Zero; _1156_k < _hi13; _1156_k++) { + DAST._IDatatypeCtor _1157_ctor2; + _1157_ctor2 = ((c).dtor_ctors).Select(_1156_k); + Dafny.ISequence _1158_pattern; + _1158_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1133_datatypeName, Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeName((_1157_ctor2).dtor_name)); + Dafny.ISequence _1159_rhs = Dafny.Sequence.Empty; + Std.Wrappers._IOption> _1160_hasMatchingField; + _1160_hasMatchingField = Std.Wrappers.Option>.create_None(); + Dafny.ISequence _1161_patternInner; + _1161_patternInner = Dafny.Sequence.UnicodeFromString(""); + bool _1162_isNumeric; + _1162_isNumeric = false; + BigInteger _hi14 = new BigInteger(((_1157_ctor2).dtor_args).Count); + for (BigInteger _1163_l = BigInteger.Zero; _1163_l < _hi14; _1163_l++) { + DAST._IDatatypeDtor _1164_dtor2; + _1164_dtor2 = ((_1157_ctor2).dtor_args).Select(_1163_l); + Dafny.ISequence _1165_patternName; + _1165_patternName = DCOMP.__default.escapeName(((_1164_dtor2).dtor_formal).dtor_name); + if (((_1163_l).Sign == 0) && ((_1165_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _1162_isNumeric = true; + } + if (_1162_isNumeric) { + _1165_patternName = Std.Wrappers.Option>.GetOr((_1164_dtor2).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_1163_l))); } - _1090_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1090_pattern, DCOMP.__default.escapeIdent((_1094_formal2).dtor_name)), Dafny.Sequence.UnicodeFromString(", ")); - _1092_l = (_1092_l) + (BigInteger.One); + if (object.Equals(((_1152_dtor).dtor_formal).dtor_name, ((_1164_dtor2).dtor_formal).dtor_name)) { + _1160_hasMatchingField = Std.Wrappers.Option>.create_Some(_1165_patternName); + } + _1161_patternInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1161_patternInner, _1165_patternName), Dafny.Sequence.UnicodeFromString(", ")); + } + if (_1162_isNumeric) { + _1158_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1158_pattern, Dafny.Sequence.UnicodeFromString("(")), _1161_patternInner), Dafny.Sequence.UnicodeFromString(")")); + } else { + _1158_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1158_pattern, Dafny.Sequence.UnicodeFromString("{")), _1161_patternInner), Dafny.Sequence.UnicodeFromString("}")); } - _1090_pattern = Dafny.Sequence.Concat(_1090_pattern, Dafny.Sequence.UnicodeFromString("}")); - if (_1093_hasMatchingField) { + if ((_1160_hasMatchingField).is_Some) { if ((c).dtor_isCo) { - _1091_rhs = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Deref::deref(&"), DCOMP.__default.escapeIdent((_1085_formal).dtor_name)), Dafny.Sequence.UnicodeFromString(".0)")); + _1159_rhs = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Deref::deref(&"), (_1160_hasMatchingField).dtor_value), Dafny.Sequence.UnicodeFromString(".0)")); } else { - _1091_rhs = Dafny.Sequence.Concat(DCOMP.__default.escapeIdent((_1085_formal).dtor_name), Dafny.Sequence.UnicodeFromString("")); + _1159_rhs = Dafny.Sequence.Concat((_1160_hasMatchingField).dtor_value, Dafny.Sequence.UnicodeFromString("")); } } else { - _1091_rhs = Dafny.Sequence.UnicodeFromString("panic!(\"field does not exist on this variant\")"); + _1159_rhs = Dafny.Sequence.UnicodeFromString("panic!(\"field does not exist on this variant\")"); } - RAST._IMatchCase _1095_ctorMatch; - _1095_ctorMatch = RAST.MatchCase.create(_1090_pattern, RAST.Expr.create_RawExpr(_1091_rhs)); - _1087_cases = Dafny.Sequence.Concat(_1087_cases, Dafny.Sequence.FromElements(_1095_ctorMatch)); - _1088_k = (_1088_k) + (BigInteger.One); + RAST._IMatchCase _1166_ctorMatch; + _1166_ctorMatch = RAST.MatchCase.create(_1158_pattern, RAST.Expr.create_RawExpr(_1159_rhs)); + _1155_cases = Dafny.Sequence.Concat(_1155_cases, Dafny.Sequence.FromElements(_1166_ctorMatch)); } if ((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) { - _1087_cases = Dafny.Sequence.Concat(_1087_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(DCOMP.__default.escapeIdent((c).dtor_name), Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("panic!()"))))); + _1155_cases = Dafny.Sequence.Concat(_1155_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_1133_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("panic!()"))))); } - RAST._IExpr _1096_methodBody; - _1096_methodBody = RAST.Expr.create_Match(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("self")), _1087_cases); - _1081_implBody = Dafny.Sequence.Concat(_1081_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(DCOMP.__default.escapeIdent((_1085_formal).dtor_name), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.self), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_1086_formalType)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_1096_methodBody))))); + RAST._IExpr _1167_methodBody; + _1167_methodBody = RAST.Expr.create_Match(RAST.__default.self, _1155_cases); + _1147_implBody = Dafny.Sequence.Concat(_1147_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(_1153_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_1154_formalType)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_1167_methodBody))))); } - _1084_j = (_1084_j) + (BigInteger.One); } - _1072_i = (_1072_i) + (BigInteger.One); } if ((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) { - BigInteger _1097_typeI; - _1097_typeI = BigInteger.Zero; - Dafny.ISequence _1098_types; - _1098_types = Dafny.Sequence.FromElements(); - while ((_1097_typeI) < (new BigInteger(((c).dtor_typeParams).Count))) { - RAST._IType _1099_genTp; - RAST._IType _out55; - _out55 = (this).GenType(((c).dtor_typeParams).Select(_1097_typeI), false, false); - _1099_genTp = _out55; - _1098_types = Dafny.Sequence.Concat(_1098_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("::std::marker::PhantomData::")), Dafny.Sequence.FromElements(_1099_genTp)))); - _1097_typeI = (_1097_typeI) + (BigInteger.One); - } - _1071_ctors = Dafny.Sequence.Concat(_1071_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Formals.create_NamelessFormals(Std.Collections.Seq.__default.Map(((System.Func)((_1100_tpe) => { - return RAST.NamelessFormal.create(RAST.Visibility.create_PRIV(), _1100_tpe); -})), _1098_types))))); - } - Dafny.ISequence _1101_enumBody; - _1101_enumBody = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq)]")), DCOMP.__default.escapeIdent((c).dtor_name), _1065_sTypeParams, _1071_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_1066_sConstrainedTypeParams, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1068_typeParamsAsTypes), _1067_whereConstraints, _1081_implBody))); - _1072_i = BigInteger.Zero; - Dafny.ISequence _1102_printImplBodyCases; - _1102_printImplBodyCases = Dafny.Sequence.FromElements(); - while ((_1072_i) < (new BigInteger(((c).dtor_ctors).Count))) { - DAST._IDatatypeCtor _1103_ctor; - _1103_ctor = ((c).dtor_ctors).Select(_1072_i); - Dafny.ISequence _1104_ctorMatch; - _1104_ctorMatch = Dafny.Sequence.Concat(DCOMP.__default.escapeIdent((_1103_ctor).dtor_name), Dafny.Sequence.UnicodeFromString(" { ")); - Dafny.ISequence _1105_modulePrefix; - _1105_modulePrefix = (((((c).dtor_enclosingModule)).Equals(Dafny.Sequence.UnicodeFromString("_module"))) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(((c).dtor_enclosingModule), Dafny.Sequence.UnicodeFromString(".")))); - RAST._IExpr _1106_printRhs; - _1106_printRhs = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("write!(_formatter, \""), _1105_modulePrefix), (c).dtor_name), Dafny.Sequence.UnicodeFromString(".")), DCOMP.__default.escapeIdent((_1103_ctor).dtor_name)), (((_1103_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(\")?")) : (Dafny.Sequence.UnicodeFromString("\")?"))))); - BigInteger _1107_j; - _1107_j = BigInteger.Zero; - while ((_1107_j) < (new BigInteger(((_1103_ctor).dtor_args).Count))) { - DAST._IFormal _1108_formal; - _1108_formal = ((_1103_ctor).dtor_args).Select(_1107_j); - _1104_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1104_ctorMatch, DCOMP.__default.escapeIdent((_1108_formal).dtor_name)), Dafny.Sequence.UnicodeFromString(", ")); - if ((_1107_j).Sign == 1) { - _1106_printRhs = (_1106_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("write!(_formatter, \", \")?"))); - } - _1106_printRhs = (_1106_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyPrint::fmt_print("), DCOMP.__default.escapeIdent((_1108_formal).dtor_name)), Dafny.Sequence.UnicodeFromString(", _formatter, false)?")))); - _1107_j = (_1107_j) + (BigInteger.One); - } - _1104_ctorMatch = Dafny.Sequence.Concat(_1104_ctorMatch, Dafny.Sequence.UnicodeFromString("}")); - if ((_1103_ctor).dtor_hasAnyArgs) { - _1106_printRhs = (_1106_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("write!(_formatter, \")\")?"))); - } - _1106_printRhs = (_1106_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("Ok(())"))); - _1102_printImplBodyCases = Dafny.Sequence.Concat(_1102_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(DCOMP.__default.escapeIdent((c).dtor_name), Dafny.Sequence.UnicodeFromString("::")), _1104_ctorMatch), RAST.Expr.create_Block(_1106_printRhs)))); - _1072_i = (_1072_i) + (BigInteger.One); + Dafny.ISequence _1168_types; + _1168_types = Dafny.Sequence.FromElements(); + BigInteger _hi15 = new BigInteger(((c).dtor_typeParams).Count); + for (BigInteger _1169_typeI = BigInteger.Zero; _1169_typeI < _hi15; _1169_typeI++) { + DAST._IType _1170_typeArg; + RAST._ITypeParamDecl _1171_rTypeParamDecl; + DAST._IType _out61; + RAST._ITypeParamDecl _out62; + (this).GenTypeParam(((c).dtor_typeParams).Select(_1169_typeI), out _out61, out _out62); + _1170_typeArg = _out61; + _1171_rTypeParamDecl = _out62; + RAST._IType _1172_rTypeArg; + RAST._IType _out63; + _out63 = (this).GenType(_1170_typeArg, false, false); + _1172_rTypeArg = _out63; + _1168_types = Dafny.Sequence.Concat(_1168_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(_1172_rTypeArg)))); + } + _1134_ctors = Dafny.Sequence.Concat(_1134_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_1173_tpe) => { + return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _1173_tpe); +})), _1168_types))))); + } + Dafny.ISequence _1174_enumBody; + _1174_enumBody = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]")), _1133_datatypeName, _1131_rTypeParamsDecls, _1134_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_1131_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1133_datatypeName), _1130_rTypeParams), _1132_whereConstraints, _1147_implBody))); + Dafny.ISequence _1175_printImplBodyCases; + _1175_printImplBodyCases = Dafny.Sequence.FromElements(); + BigInteger _hi16 = new BigInteger(((c).dtor_ctors).Count); + for (BigInteger _1176_i = BigInteger.Zero; _1176_i < _hi16; _1176_i++) { + DAST._IDatatypeCtor _1177_ctor; + _1177_ctor = ((c).dtor_ctors).Select(_1176_i); + Dafny.ISequence _1178_ctorMatch; + _1178_ctorMatch = DCOMP.__default.escapeName((_1177_ctor).dtor_name); + Dafny.ISequence _1179_modulePrefix; + _1179_modulePrefix = ((((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")))); + Dafny.ISequence _1180_ctorName; + _1180_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1179_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_1177_ctor).dtor_name)); + if (((new BigInteger((_1180_ctorName).Count)) >= (new BigInteger(13))) && (((_1180_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _1180_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _1181_printRhs; + _1181_printRhs = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("write!(_formatter, \""), _1180_ctorName), (((_1177_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(\")?")) : (Dafny.Sequence.UnicodeFromString("\")?"))))); + bool _1182_isNumeric; + _1182_isNumeric = false; + Dafny.ISequence _1183_ctorMatchInner; + _1183_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi17 = new BigInteger(((_1177_ctor).dtor_args).Count); + for (BigInteger _1184_j = BigInteger.Zero; _1184_j < _hi17; _1184_j++) { + DAST._IDatatypeDtor _1185_dtor; + _1185_dtor = ((_1177_ctor).dtor_args).Select(_1184_j); + Dafny.ISequence _1186_patternName; + _1186_patternName = DCOMP.__default.escapeName(((_1185_dtor).dtor_formal).dtor_name); + if (((_1184_j).Sign == 0) && ((_1186_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _1182_isNumeric = true; + } + if (_1182_isNumeric) { + _1186_patternName = Std.Wrappers.Option>.GetOr((_1185_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_1184_j))); + } + _1183_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1183_ctorMatchInner, _1186_patternName), Dafny.Sequence.UnicodeFromString(", ")); + if ((_1184_j).Sign == 1) { + _1181_printRhs = (_1181_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("write!(_formatter, \", \")?"))); + } + _1181_printRhs = (_1181_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyPrint::fmt_print("), _1186_patternName), Dafny.Sequence.UnicodeFromString(", _formatter, false)?")))); + } + if (_1182_isNumeric) { + _1178_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1178_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _1183_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + } else { + _1178_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1178_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _1183_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + } + if ((_1177_ctor).dtor_hasAnyArgs) { + _1181_printRhs = (_1181_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("write!(_formatter, \")\")?"))); + } + _1181_printRhs = (_1181_printRhs).Then(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("Ok(())"))); + _1175_printImplBodyCases = Dafny.Sequence.Concat(_1175_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1133_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _1178_ctorMatch), RAST.Expr.create_Block(_1181_printRhs)))); } if ((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) { - _1102_printImplBodyCases = Dafny.Sequence.Concat(_1102_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(DCOMP.__default.escapeIdent((c).dtor_name), Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("{panic!()}"))))); - } - RAST._IExpr _1109_printImplBody; - _1109_printImplBody = RAST.Expr.create_Match(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("self")), _1102_printImplBodyCases); - Dafny.ISequence _1110_printImpl; - _1110_printImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1066_sConstrainedTypeParams, RAST.__default.DafnyPrintTrait, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1068_typeParamsAsTypes), 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.self, 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.__default.RawType(Dafny.Sequence.UnicodeFromString("bool")))), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_1109_printImplBody))))))); - Dafny.ISequence _1111_defaultImpl; - _1111_defaultImpl = Dafny.Sequence.FromElements(); + _1175_printImplBodyCases = Dafny.Sequence.Concat(_1175_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_1133_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("{panic!()}"))))); + } + Dafny.ISequence _1187_defaultConstrainedTypeParams; + _1187_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_1131_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IExpr _1188_printImplBody; + _1188_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _1175_printImplBodyCases); + Dafny.ISequence _1189_printImpl; + _1189_printImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1131_rTypeParamsDecls, ((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Debug")), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1133_datatypeName), _1130_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(_1131_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1133_datatypeName), _1130_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(_1188_printImplBody))))))); + Dafny.ISequence _1190_defaultImpl; + _1190_defaultImpl = Dafny.Sequence.FromElements(); + Dafny.ISequence _1191_asRefImpl; + _1191_asRefImpl = Dafny.Sequence.FromElements(); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - _1072_i = BigInteger.Zero; - Dafny.ISequence _1112_structName; - _1112_structName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(DCOMP.__default.escapeIdent((c).dtor_name), Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeIdent((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _1113_structAssignments; - _1113_structAssignments = Dafny.Sequence.FromElements(); - while ((_1072_i) < (new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count))) { - DAST._IFormal _1114_formal; - _1114_formal = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_1072_i); - _1113_structAssignments = Dafny.Sequence.Concat(_1113_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeIdent((_1114_formal).dtor_name), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::default::Default::default()"))))); - _1072_i = (_1072_i) + (BigInteger.One); - } - Dafny.ISequence _1115_defaultConstrainedTypeParams; - _1115_defaultConstrainedTypeParams = RAST.TypeParam.AddConstraintsMultiple(_1065_sTypeParams, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - _1111_defaultImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1115_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(DCOMP.__default.escapeIdent((c).dtor_name)), _1068_typeParamsAsTypes), 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(RAST.Type.create_SelfOwned()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_1112_structName, _1113_structAssignments)))))))); - } - s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1101_enumBody, _1110_printImpl), _1111_defaultImpl); + RAST._IExpr _1192_structName; + _1192_structName = (RAST.Expr.create_Identifier(_1133_datatypeName)).MSel(DCOMP.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _1193_structAssignments; + _1193_structAssignments = Dafny.Sequence.FromElements(); + BigInteger _hi18 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); + for (BigInteger _1194_i = BigInteger.Zero; _1194_i < _hi18; _1194_i++) { + DAST._IDatatypeDtor _1195_dtor; + _1195_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_1194_i); + _1193_structAssignments = Dafny.Sequence.Concat(_1193_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(DCOMP.__default.escapeName(((_1195_dtor).dtor_formal).dtor_name), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::default::Default::default()"))))); + } + Dafny.ISequence _1196_defaultConstrainedTypeParams; + _1196_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_1131_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IType _1197_fullType; + _1197_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_1133_datatypeName), _1130_rTypeParams); + _1190_defaultImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1196_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _1197_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(_1197_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_1192_structName, _1193_structAssignments)))))))); + _1191_asRefImpl = Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1131_rTypeParamsDecls, (((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).Apply1(_1197_fullType), RAST.Type.create_Borrowed(_1197_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(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1174_enumBody, _1189_printImpl), _1190_defaultImpl), _1191_asRefImpl); return s; } - public static Dafny.ISequence GenPath(Dafny.ISequence> p) + public static RAST._IType GenPath(Dafny.ISequence> p) { - Dafny.ISequence s = Dafny.Sequence.Empty; + RAST._IType r = RAST.Type.Default(); if ((new BigInteger((p).Count)).Sign == 0) { - s = Dafny.Sequence.UnicodeFromString("Self"); - return s; + r = RAST.Type.create_SelfOwned(); + return r; } else { - s = Dafny.Sequence.UnicodeFromString("super::"); - BigInteger _1116_i; - _1116_i = BigInteger.Zero; - while ((_1116_i) < (new BigInteger((p).Count))) { - if ((_1116_i).Sign == 1) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("::")); - } - s = Dafny.Sequence.Concat(s, DCOMP.__default.escapeIdent(((p).Select(_1116_i)))); - _1116_i = (_1116_i) + (BigInteger.One); + r = ((((((p).Select(BigInteger.Zero)))).Equals(Dafny.Sequence.UnicodeFromString("std"))) ? (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString(""))) : (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("super")))); + BigInteger _hi19 = new BigInteger((p).Count); + for (BigInteger _1198_i = BigInteger.Zero; _1198_i < _hi19; _1198_i++) { + r = (r).MSel(DCOMP.__default.escapeName(((p).Select(_1198_i)))); } } - return s; + return r; + } + public static RAST._IExpr GenPathExpr(Dafny.ISequence> p) + { + RAST._IExpr r = RAST.Expr.Default(); + if ((new BigInteger((p).Count)).Sign == 0) { + r = RAST.__default.self; + return r; + } else { + r = ((((((p).Select(BigInteger.Zero)))).Equals(Dafny.Sequence.UnicodeFromString("std"))) ? (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString(""))) : (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("super")))); + BigInteger _hi20 = new BigInteger((p).Count); + for (BigInteger _1199_i = BigInteger.Zero; _1199_i < _hi20; _1199_i++) { + r = (r).MSel(DCOMP.__default.escapeName(((p).Select(_1199_i)))); + } + } + return r; } public Dafny.ISequence GenTypeArgs(Dafny.ISequence args, bool inBinding, bool inFn) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); if ((new BigInteger((args).Count)).Sign == 1) { - BigInteger _1117_i; - _1117_i = BigInteger.Zero; - while ((_1117_i) < (new BigInteger((args).Count))) { - RAST._IType _1118_genTp; - RAST._IType _out56; - _out56 = (this).GenType((args).Select(_1117_i), inBinding, inFn); - _1118_genTp = _out56; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_1118_genTp)); - _1117_i = (_1117_i) + (BigInteger.One); + BigInteger _1200_i; + _1200_i = BigInteger.Zero; + while ((_1200_i) < (new BigInteger((args).Count))) { + RAST._IType _1201_genTp; + RAST._IType _out64; + _out64 = (this).GenType((args).Select(_1200_i), inBinding, inFn); + _1201_genTp = _out64; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_1201_genTp)); + _1200_i = (_1200_i) + (BigInteger.One); } } return s; } + public bool IsRcWrapped(Dafny.ISequence attributes) { + return ((!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("auto-nongrowing-size"), Dafny.Sequence>.FromElements()))) && (!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("false")))))) || ((attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("true"))))); + } public RAST._IType GenType(DAST._IType c, bool inBinding, bool inFn) { RAST._IType s = RAST.Type.Default(); - DAST._IType _source46 = c; - bool unmatched46 = true; - if (unmatched46) { - if (_source46.is_Path) { - Dafny.ISequence> _1119_p = _source46.dtor_Path_a0; - Dafny.ISequence _1120_args = _source46.dtor_typeArgs; - DAST._IResolvedType _1121_resolved = _source46.dtor_resolved; - unmatched46 = false; + DAST._IType _source49 = c; + bool unmatched49 = true; + if (unmatched49) { + if (_source49.is_Path) { + Dafny.ISequence> _1202_p = _source49.dtor_Path_a0; + Dafny.ISequence _1203_args = _source49.dtor_typeArgs; + DAST._IResolvedType _1204_resolved = _source49.dtor_resolved; + unmatched49 = false; { - Dafny.ISequence _1122_t; - Dafny.ISequence _out57; - _out57 = DCOMP.COMP.GenPath(_1119_p); - _1122_t = _out57; - s = RAST.Type.create_TIdentifier(_1122_t); - Dafny.ISequence _1123_typeArgs; - Dafny.ISequence _out58; - _out58 = (this).GenTypeArgs(_1120_args, inBinding, inFn); - _1123_typeArgs = _out58; - s = RAST.Type.create_TypeApp(s, _1123_typeArgs); - DAST._IResolvedType _source47 = _1121_resolved; - bool unmatched47 = true; - if (unmatched47) { - if (_source47.is_Datatype) { - Dafny.ISequence> _1124___v37 = _source47.dtor_path; - unmatched47 = false; + RAST._IType _1205_t; + RAST._IType _out65; + _out65 = DCOMP.COMP.GenPath(_1202_p); + _1205_t = _out65; + Dafny.ISequence _1206_typeArgs; + Dafny.ISequence _out66; + _out66 = (this).GenTypeArgs(_1203_args, inBinding, inFn); + _1206_typeArgs = _out66; + s = RAST.Type.create_TypeApp(_1205_t, _1206_typeArgs); + DAST._IResolvedType _source50 = _1204_resolved; + bool unmatched50 = true; + if (unmatched50) { + if (_source50.is_Datatype) { + DAST._IDatatypeType datatypeType0 = _source50.dtor_datatypeType; + Dafny.ISequence> _1207___v50 = datatypeType0.dtor_path; + Dafny.ISequence _1208_attributes = datatypeType0.dtor_attributes; + unmatched50 = false; { - s = RAST.__default.Rc(s); + if ((this).IsRcWrapped(_1208_attributes)) { + s = RAST.__default.Rc(s); + } } } } - if (unmatched47) { - if (_source47.is_Trait) { - Dafny.ISequence> _1125___v38 = _source47.dtor_path; - unmatched47 = false; + if (unmatched50) { + if (_source50.is_Trait) { + Dafny.ISequence> _1209___v51 = _source50.dtor_path; + Dafny.ISequence _1210___v52 = _source50.dtor_attributes; + unmatched50 = false; { - if ((_1119_p).Equals(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("_System"), Dafny.Sequence.UnicodeFromString("object")))) { + if ((_1202_p).Equals(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("_System"), Dafny.Sequence.UnicodeFromString("object")))) { s = RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("::std::rc::Rc")); } else { if (inBinding) { @@ -906,24 +1148,25 @@ public RAST._IType GenType(DAST._IType c, bool inBinding, bool inFn) } } } - if (unmatched47) { - DAST._IType _1126_t = _source47.dtor_baseType; - DAST._INewtypeRange _1127_range = _source47.dtor_range; - bool _1128_erased = _source47.dtor_erase; - unmatched47 = false; + if (unmatched50) { + DAST._IType _1211_t = _source50.dtor_baseType; + DAST._INewtypeRange _1212_range = _source50.dtor_range; + bool _1213_erased = _source50.dtor_erase; + Dafny.ISequence _1214_attributes = _source50.dtor_attributes; + unmatched50 = false; { - if (_1128_erased) { - Std.Wrappers._IOption _source48 = DCOMP.COMP.NewtypeToRustType(_1126_t, _1127_range); - bool unmatched48 = true; - if (unmatched48) { - if (_source48.is_Some) { - RAST._IType _1129_v = _source48.dtor_value; - unmatched48 = false; - s = _1129_v; + if (_1213_erased) { + Std.Wrappers._IOption _source51 = DCOMP.COMP.NewtypeToRustType(_1211_t, _1212_range); + bool unmatched51 = true; + if (unmatched51) { + if (_source51.is_Some) { + RAST._IType _1215_v = _source51.dtor_value; + unmatched51 = false; + s = _1215_v; } } - if (unmatched48) { - unmatched48 = false; + if (unmatched51) { + unmatched51 = false; } } } @@ -931,224 +1174,224 @@ public RAST._IType GenType(DAST._IType c, bool inBinding, bool inFn) } } } - if (unmatched46) { - if (_source46.is_Nullable) { - DAST._IType _1130_inner = _source46.dtor_Nullable_a0; - unmatched46 = false; + if (unmatched49) { + if (_source49.is_Nullable) { + DAST._IType _1216_inner = _source49.dtor_Nullable_a0; + unmatched49 = false; { - RAST._IType _1131_innerExpr; - RAST._IType _out59; - _out59 = (this).GenType(_1130_inner, inBinding, inFn); - _1131_innerExpr = _out59; - s = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("::std::option::Option")), Dafny.Sequence.FromElements(_1131_innerExpr)); + RAST._IType _1217_innerExpr; + RAST._IType _out67; + _out67 = (this).GenType(_1216_inner, inBinding, inFn); + _1217_innerExpr = _out67; + s = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("::std::option::Option")), Dafny.Sequence.FromElements(_1217_innerExpr)); } } } - if (unmatched46) { - if (_source46.is_Tuple) { - Dafny.ISequence _1132_types = _source46.dtor_Tuple_a0; - unmatched46 = false; + if (unmatched49) { + if (_source49.is_Tuple) { + Dafny.ISequence _1218_types = _source49.dtor_Tuple_a0; + unmatched49 = false; { - Dafny.ISequence _1133_args; - _1133_args = Dafny.Sequence.FromElements(); - BigInteger _1134_i; - _1134_i = BigInteger.Zero; - while ((_1134_i) < (new BigInteger((_1132_types).Count))) { - RAST._IType _1135_generated; - RAST._IType _out60; - _out60 = (this).GenType((_1132_types).Select(_1134_i), inBinding, inFn); - _1135_generated = _out60; - _1133_args = Dafny.Sequence.Concat(_1133_args, Dafny.Sequence.FromElements(_1135_generated)); - _1134_i = (_1134_i) + (BigInteger.One); + Dafny.ISequence _1219_args; + _1219_args = Dafny.Sequence.FromElements(); + BigInteger _1220_i; + _1220_i = BigInteger.Zero; + while ((_1220_i) < (new BigInteger((_1218_types).Count))) { + RAST._IType _1221_generated; + RAST._IType _out68; + _out68 = (this).GenType((_1218_types).Select(_1220_i), inBinding, inFn); + _1221_generated = _out68; + _1219_args = Dafny.Sequence.Concat(_1219_args, Dafny.Sequence.FromElements(_1221_generated)); + _1220_i = (_1220_i) + (BigInteger.One); } - s = RAST.Type.create_TupleType(_1133_args); + s = (((new BigInteger((_1218_types).Count)) <= (RAST.__default.MAX__TUPLE__SIZE)) ? (RAST.Type.create_TupleType(_1219_args)) : (RAST.__default.SystemTupleType(_1219_args))); } } } - if (unmatched46) { - if (_source46.is_Array) { - DAST._IType _1136_element = _source46.dtor_element; - BigInteger _1137_dims = _source46.dtor_dims; - unmatched46 = false; + if (unmatched49) { + if (_source49.is_Array) { + DAST._IType _1222_element = _source49.dtor_element; + BigInteger _1223_dims = _source49.dtor_dims; + unmatched49 = false; { - RAST._IType _1138_elem; - RAST._IType _out61; - _out61 = (this).GenType(_1136_element, inBinding, inFn); - _1138_elem = _out61; - s = _1138_elem; - BigInteger _1139_i; - _1139_i = BigInteger.Zero; - while ((_1139_i) < (_1137_dims)) { + RAST._IType _1224_elem; + RAST._IType _out69; + _out69 = (this).GenType(_1222_element, inBinding, inFn); + _1224_elem = _out69; + s = _1224_elem; + BigInteger _1225_i; + _1225_i = BigInteger.Zero; + while ((_1225_i) < (_1223_dims)) { s = RAST.__default.Rc(RAST.__default.RefCell(RAST.__default.Vec(s))); - _1139_i = (_1139_i) + (BigInteger.One); + _1225_i = (_1225_i) + (BigInteger.One); } } } } - if (unmatched46) { - if (_source46.is_Seq) { - DAST._IType _1140_element = _source46.dtor_element; - unmatched46 = false; + if (unmatched49) { + if (_source49.is_Seq) { + DAST._IType _1226_element = _source49.dtor_element; + unmatched49 = false; { - RAST._IType _1141_elem; - RAST._IType _out62; - _out62 = (this).GenType(_1140_element, inBinding, inFn); - _1141_elem = _out62; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Sequence")), Dafny.Sequence.FromElements(_1141_elem)); + RAST._IType _1227_elem; + RAST._IType _out70; + _out70 = (this).GenType(_1226_element, inBinding, inFn); + _1227_elem = _out70; + s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Sequence")), Dafny.Sequence.FromElements(_1227_elem)); } } } - if (unmatched46) { - if (_source46.is_Set) { - DAST._IType _1142_element = _source46.dtor_element; - unmatched46 = false; + if (unmatched49) { + if (_source49.is_Set) { + DAST._IType _1228_element = _source49.dtor_element; + unmatched49 = false; { - RAST._IType _1143_elem; - RAST._IType _out63; - _out63 = (this).GenType(_1142_element, inBinding, inFn); - _1143_elem = _out63; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Set")), Dafny.Sequence.FromElements(_1143_elem)); + RAST._IType _1229_elem; + RAST._IType _out71; + _out71 = (this).GenType(_1228_element, inBinding, inFn); + _1229_elem = _out71; + s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Set")), Dafny.Sequence.FromElements(_1229_elem)); } } } - if (unmatched46) { - if (_source46.is_Multiset) { - DAST._IType _1144_element = _source46.dtor_element; - unmatched46 = false; + if (unmatched49) { + if (_source49.is_Multiset) { + DAST._IType _1230_element = _source49.dtor_element; + unmatched49 = false; { - RAST._IType _1145_elem; - RAST._IType _out64; - _out64 = (this).GenType(_1144_element, inBinding, inFn); - _1145_elem = _out64; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Multiset")), Dafny.Sequence.FromElements(_1145_elem)); + RAST._IType _1231_elem; + RAST._IType _out72; + _out72 = (this).GenType(_1230_element, inBinding, inFn); + _1231_elem = _out72; + s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Multiset")), Dafny.Sequence.FromElements(_1231_elem)); } } } - if (unmatched46) { - if (_source46.is_Map) { - DAST._IType _1146_key = _source46.dtor_key; - DAST._IType _1147_value = _source46.dtor_value; - unmatched46 = false; + if (unmatched49) { + if (_source49.is_Map) { + DAST._IType _1232_key = _source49.dtor_key; + DAST._IType _1233_value = _source49.dtor_value; + unmatched49 = false; { - RAST._IType _1148_keyType; - RAST._IType _out65; - _out65 = (this).GenType(_1146_key, inBinding, inFn); - _1148_keyType = _out65; - RAST._IType _1149_valueType; - RAST._IType _out66; - _out66 = (this).GenType(_1147_value, inBinding, inFn); - _1149_valueType = _out66; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Map")), Dafny.Sequence.FromElements(_1148_keyType, _1149_valueType)); - } - } - } - if (unmatched46) { - if (_source46.is_MapBuilder) { - DAST._IType _1150_key = _source46.dtor_key; - DAST._IType _1151_value = _source46.dtor_value; - unmatched46 = false; + RAST._IType _1234_keyType; + RAST._IType _out73; + _out73 = (this).GenType(_1232_key, inBinding, inFn); + _1234_keyType = _out73; + RAST._IType _1235_valueType; + RAST._IType _out74; + _out74 = (this).GenType(_1233_value, inBinding, inFn); + _1235_valueType = _out74; + s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Map")), Dafny.Sequence.FromElements(_1234_keyType, _1235_valueType)); + } + } + } + if (unmatched49) { + if (_source49.is_MapBuilder) { + DAST._IType _1236_key = _source49.dtor_key; + DAST._IType _1237_value = _source49.dtor_value; + unmatched49 = false; { - RAST._IType _1152_keyType; - RAST._IType _out67; - _out67 = (this).GenType(_1150_key, inBinding, inFn); - _1152_keyType = _out67; - RAST._IType _1153_valueType; - RAST._IType _out68; - _out68 = (this).GenType(_1151_value, inBinding, inFn); - _1153_valueType = _out68; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder")), Dafny.Sequence.FromElements(_1152_keyType, _1153_valueType)); - } - } - } - if (unmatched46) { - if (_source46.is_SetBuilder) { - DAST._IType _1154_elem = _source46.dtor_element; - unmatched46 = false; + RAST._IType _1238_keyType; + RAST._IType _out75; + _out75 = (this).GenType(_1236_key, inBinding, inFn); + _1238_keyType = _out75; + RAST._IType _1239_valueType; + RAST._IType _out76; + _out76 = (this).GenType(_1237_value, inBinding, inFn); + _1239_valueType = _out76; + s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder")), Dafny.Sequence.FromElements(_1238_keyType, _1239_valueType)); + } + } + } + if (unmatched49) { + if (_source49.is_SetBuilder) { + DAST._IType _1240_elem = _source49.dtor_element; + unmatched49 = false; { - RAST._IType _1155_elemType; - RAST._IType _out69; - _out69 = (this).GenType(_1154_elem, inBinding, inFn); - _1155_elemType = _out69; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder")), Dafny.Sequence.FromElements(_1155_elemType)); + RAST._IType _1241_elemType; + RAST._IType _out77; + _out77 = (this).GenType(_1240_elem, inBinding, inFn); + _1241_elemType = _out77; + s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder")), Dafny.Sequence.FromElements(_1241_elemType)); } } } - if (unmatched46) { - if (_source46.is_Arrow) { - Dafny.ISequence _1156_args = _source46.dtor_args; - DAST._IType _1157_result = _source46.dtor_result; - unmatched46 = false; + if (unmatched49) { + if (_source49.is_Arrow) { + Dafny.ISequence _1242_args = _source49.dtor_args; + DAST._IType _1243_result = _source49.dtor_result; + unmatched49 = false; { - Dafny.ISequence _1158_argTypes; - _1158_argTypes = Dafny.Sequence.FromElements(); - BigInteger _1159_i; - _1159_i = BigInteger.Zero; - while ((_1159_i) < (new BigInteger((_1156_args).Count))) { - RAST._IType _1160_generated; - RAST._IType _out70; - _out70 = (this).GenType((_1156_args).Select(_1159_i), inBinding, true); - _1160_generated = _out70; - _1158_argTypes = Dafny.Sequence.Concat(_1158_argTypes, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(_1160_generated))); - _1159_i = (_1159_i) + (BigInteger.One); + Dafny.ISequence _1244_argTypes; + _1244_argTypes = Dafny.Sequence.FromElements(); + BigInteger _1245_i; + _1245_i = BigInteger.Zero; + while ((_1245_i) < (new BigInteger((_1242_args).Count))) { + RAST._IType _1246_generated; + RAST._IType _out78; + _out78 = (this).GenType((_1242_args).Select(_1245_i), inBinding, true); + _1246_generated = _out78; + _1244_argTypes = Dafny.Sequence.Concat(_1244_argTypes, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(_1246_generated))); + _1245_i = (_1245_i) + (BigInteger.One); } - RAST._IType _1161_resultType; - RAST._IType _out71; - _out71 = (this).GenType(_1157_result, inBinding, (inFn) || (inBinding)); - _1161_resultType = _out71; - s = RAST.Type.create_TypeApp((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("FunctionWrapper")), Dafny.Sequence.FromElements(RAST.Type.create_FnType(_1158_argTypes, RAST.Type.create_IntersectionType(_1161_resultType, RAST.__default.StaticTrait)))); + RAST._IType _1247_resultType; + RAST._IType _out79; + _out79 = (this).GenType(_1243_result, inBinding, (inFn) || (inBinding)); + _1247_resultType = _out79; + s = RAST.__default.Rc(RAST.Type.create_DynType(RAST.Type.create_FnType(_1244_argTypes, _1247_resultType))); } } } - if (unmatched46) { - if (_source46.is_TypeArg) { - Dafny.ISequence _h100 = _source46.dtor_TypeArg_a0; - Dafny.ISequence _1162_name = _h100; - unmatched46 = false; - s = RAST.__default.RawType(DCOMP.__default.escapeIdent(_1162_name)); + if (unmatched49) { + if (_source49.is_TypeArg) { + Dafny.ISequence _h100 = _source49.dtor_TypeArg_a0; + Dafny.ISequence _1248_name = _h100; + unmatched49 = false; + s = RAST.Type.create_TIdentifier(DCOMP.__default.escapeName(_1248_name)); } } - if (unmatched46) { - if (_source46.is_Primitive) { - DAST._IPrimitive _1163_p = _source46.dtor_Primitive_a0; - unmatched46 = false; + if (unmatched49) { + if (_source49.is_Primitive) { + DAST._IPrimitive _1249_p = _source49.dtor_Primitive_a0; + unmatched49 = false; { - DAST._IPrimitive _source49 = _1163_p; - bool unmatched49 = true; - if (unmatched49) { - if (_source49.is_Int) { - unmatched49 = false; + DAST._IPrimitive _source52 = _1249_p; + bool unmatched52 = true; + if (unmatched52) { + if (_source52.is_Int) { + unmatched52 = false; s = (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt")); } } - if (unmatched49) { - if (_source49.is_Real) { - unmatched49 = false; + if (unmatched52) { + if (_source52.is_Real) { + unmatched52 = false; s = (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("BigRational")); } } - if (unmatched49) { - if (_source49.is_String) { - unmatched49 = false; + if (unmatched52) { + if (_source52.is_String) { + unmatched52 = false; 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))); } } - if (unmatched49) { - if (_source49.is_Bool) { - unmatched49 = false; - s = RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("bool")); + if (unmatched52) { + if (_source52.is_Bool) { + unmatched52 = false; + s = RAST.Type.create_Bool(); } } - if (unmatched49) { - unmatched49 = false; + if (unmatched52) { + unmatched52 = false; s = (RAST.__default.dafny__runtime__type).MSel((this).DafnyChar); } } } } - if (unmatched46) { - Dafny.ISequence _1164_v = _source46.dtor_Passthrough_a0; - unmatched46 = false; - s = RAST.__default.RawType(_1164_v); + if (unmatched49) { + Dafny.ISequence _1250_v = _source49.dtor_Passthrough_a0; + unmatched49 = false; + s = RAST.__default.RawType(_1250_v); } return s; } @@ -1158,877 +1401,989 @@ public void GenClassImplBody(Dafny.ISequence body, bool forTrait, traitBodies = Dafny.Map>, Dafny.ISequence>.Empty; s = Dafny.Sequence.FromElements(); traitBodies = Dafny.Map>, Dafny.ISequence>.FromElements(); - BigInteger _1165_i; - _1165_i = BigInteger.Zero; - while ((_1165_i) < (new BigInteger((body).Count))) { - DAST._IMethod _source50 = (body).Select(_1165_i); - bool unmatched50 = true; - if (unmatched50) { - DAST._IMethod _1166_m = _source50; - unmatched50 = false; + BigInteger _hi21 = new BigInteger((body).Count); + for (BigInteger _1251_i = BigInteger.Zero; _1251_i < _hi21; _1251_i++) { + DAST._IMethod _source53 = (body).Select(_1251_i); + bool unmatched53 = true; + if (unmatched53) { + DAST._IMethod _1252_m = _source53; + unmatched53 = false; { - Std.Wrappers._IOption>> _source51 = (_1166_m).dtor_overridingPath; - bool unmatched51 = true; - if (unmatched51) { - if (_source51.is_Some) { - Dafny.ISequence> _1167_p = _source51.dtor_value; - unmatched51 = false; + Std.Wrappers._IOption>> _source54 = (_1252_m).dtor_overridingPath; + bool unmatched54 = true; + if (unmatched54) { + if (_source54.is_Some) { + Dafny.ISequence> _1253_p = _source54.dtor_value; + unmatched54 = false; { - Dafny.ISequence _1168_existing; - _1168_existing = Dafny.Sequence.FromElements(); - if ((traitBodies).Contains(_1167_p)) { - _1168_existing = Dafny.Map>, Dafny.ISequence>.Select(traitBodies,_1167_p); + Dafny.ISequence _1254_existing; + _1254_existing = Dafny.Sequence.FromElements(); + if ((traitBodies).Contains(_1253_p)) { + _1254_existing = Dafny.Map>, Dafny.ISequence>.Select(traitBodies,_1253_p); } - RAST._IImplMember _1169_genMethod; - RAST._IImplMember _out72; - _out72 = (this).GenMethod(_1166_m, true, enclosingType, enclosingTypeParams); - _1169_genMethod = _out72; - _1168_existing = Dafny.Sequence.Concat(_1168_existing, Dafny.Sequence.FromElements(_1169_genMethod)); - traitBodies = Dafny.Map>, Dafny.ISequence>.Merge(traitBodies, Dafny.Map>, Dafny.ISequence>.FromElements(new Dafny.Pair>, Dafny.ISequence>(_1167_p, _1168_existing))); + RAST._IImplMember _1255_genMethod; + RAST._IImplMember _out80; + _out80 = (this).GenMethod(_1252_m, true, enclosingType, enclosingTypeParams); + _1255_genMethod = _out80; + _1254_existing = Dafny.Sequence.Concat(_1254_existing, Dafny.Sequence.FromElements(_1255_genMethod)); + traitBodies = Dafny.Map>, Dafny.ISequence>.Merge(traitBodies, Dafny.Map>, Dafny.ISequence>.FromElements(new Dafny.Pair>, Dafny.ISequence>(_1253_p, _1254_existing))); } } } - if (unmatched51) { - unmatched51 = false; + if (unmatched54) { + unmatched54 = false; { - RAST._IImplMember _1170_generated; - RAST._IImplMember _out73; - _out73 = (this).GenMethod(_1166_m, forTrait, enclosingType, enclosingTypeParams); - _1170_generated = _out73; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_1170_generated)); + RAST._IImplMember _1256_generated; + RAST._IImplMember _out81; + _out81 = (this).GenMethod(_1252_m, forTrait, enclosingType, enclosingTypeParams); + _1256_generated = _out81; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_1256_generated)); } } } } - _1165_i = (_1165_i) + (BigInteger.One); } } public Dafny.ISequence GenParams(Dafny.ISequence @params) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); - BigInteger _1171_i; - _1171_i = BigInteger.Zero; - while ((_1171_i) < (new BigInteger((@params).Count))) { - DAST._IFormal _1172_param; - _1172_param = (@params).Select(_1171_i); - RAST._IType _1173_paramType; - RAST._IType _out74; - _out74 = (this).GenType((_1172_param).dtor_typ, false, false); - _1173_paramType = _out74; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.Formal.create(DCOMP.__default.escapeIdent((_1172_param).dtor_name), RAST.Type.create_Borrowed(_1173_paramType)))); - _1171_i = (_1171_i) + (BigInteger.One); + BigInteger _hi22 = new BigInteger((@params).Count); + for (BigInteger _1257_i = BigInteger.Zero; _1257_i < _hi22; _1257_i++) { + DAST._IFormal _1258_param; + _1258_param = (@params).Select(_1257_i); + RAST._IType _1259_paramType; + RAST._IType _out82; + _out82 = (this).GenType((_1258_param).dtor_typ, false, false); + _1259_paramType = _out82; + if ((!((_1259_paramType).CanReadWithoutClone())) && (!((_1258_param).dtor_attributes).Contains(DCOMP.__default.AttributeOwned))) { + _1259_paramType = RAST.Type.create_Borrowed(_1259_paramType); + } + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.Formal.create(DCOMP.__default.escapeName((_1258_param).dtor_name), _1259_paramType))); } return s; } public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType enclosingType, Dafny.ISet enclosingTypeParams) { RAST._IImplMember s = RAST.ImplMember.Default(); - Dafny.ISequence _1174_params; - Dafny.ISequence _out75; - _out75 = (this).GenParams((m).dtor_params); - _1174_params = _out75; - Dafny.ISequence> _1175_paramNames; - _1175_paramNames = Dafny.Sequence>.FromElements(); - BigInteger _1176_paramI; - _1176_paramI = BigInteger.Zero; - while ((_1176_paramI) < (new BigInteger(((m).dtor_params).Count))) { - _1175_paramNames = Dafny.Sequence>.Concat(_1175_paramNames, Dafny.Sequence>.FromElements((((m).dtor_params).Select(_1176_paramI)).dtor_name)); - _1176_paramI = (_1176_paramI) + (BigInteger.One); - } + Dafny.ISequence _1260_params; + Dafny.ISequence _out83; + _out83 = (this).GenParams((m).dtor_params); + _1260_params = _out83; + Dafny.ISequence> _1261_paramNames; + _1261_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _1262_paramTypes; + _1262_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi23 = new BigInteger(((m).dtor_params).Count); + for (BigInteger _1263_paramI = BigInteger.Zero; _1263_paramI < _hi23; _1263_paramI++) { + DAST._IFormal _1264_dafny__formal; + _1264_dafny__formal = ((m).dtor_params).Select(_1263_paramI); + RAST._IFormal _1265_formal; + _1265_formal = (_1260_params).Select(_1263_paramI); + Dafny.ISequence _1266_name; + _1266_name = (_1265_formal).dtor_name; + _1261_paramNames = Dafny.Sequence>.Concat(_1261_paramNames, Dafny.Sequence>.FromElements(_1266_name)); + _1262_paramTypes = Dafny.Map, RAST._IType>.Update(_1262_paramTypes, _1266_name, (_1265_formal).dtor_tpe); + } + Dafny.ISequence _1267_fnName; + _1267_fnName = DCOMP.__default.escapeName((m).dtor_name); + Std.Wrappers._IOption> _1268_selfIdentifier; + _1268_selfIdentifier = Std.Wrappers.Option>.create_None(); if (!((m).dtor_isStatic)) { + Dafny.ISequence _1269_selfId; + _1269_selfId = Dafny.Sequence.UnicodeFromString("self"); + if ((_1267_fnName).Equals(Dafny.Sequence.UnicodeFromString("_ctor"))) { + _1269_selfId = Dafny.Sequence.UnicodeFromString("this"); + } if (forTrait) { - _1174_params = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.Formal.self), _1174_params); + RAST._IFormal _1270_selfFormal; + _1270_selfFormal = RAST.Formal.selfBorrowedMut; + _1260_params = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_1270_selfFormal), _1260_params); } else { - RAST._IType _1177_tpe; - RAST._IType _out76; - _out76 = (this).GenType(enclosingType, false, false); - _1177_tpe = _out76; - _1174_params = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("self"), RAST.Type.create_Borrowed(_1177_tpe))), _1174_params); - } - } - Dafny.ISequence _1178_retTypeArgs; - _1178_retTypeArgs = Dafny.Sequence.FromElements(); - BigInteger _1179_typeI; - _1179_typeI = BigInteger.Zero; - while ((_1179_typeI) < (new BigInteger(((m).dtor_outTypes).Count))) { - RAST._IType _1180_typeExpr; - RAST._IType _out77; - _out77 = (this).GenType(((m).dtor_outTypes).Select(_1179_typeI), false, false); - _1180_typeExpr = _out77; - _1178_retTypeArgs = Dafny.Sequence.Concat(_1178_retTypeArgs, Dafny.Sequence.FromElements(_1180_typeExpr)); - _1179_typeI = (_1179_typeI) + (BigInteger.One); - } - RAST._IVisibility _1181_visibility; - _1181_visibility = RAST.Visibility.create_PUB(); - Dafny.ISequence _1182_fnName; - _1182_fnName = DCOMP.__default.escapeIdent((m).dtor_name); - Dafny.ISequence _1183_typeParamsFiltered; - _1183_typeParamsFiltered = Dafny.Sequence.FromElements(); - BigInteger _1184_typeParamI; - _1184_typeParamI = BigInteger.Zero; - while ((_1184_typeParamI) < (new BigInteger(((m).dtor_typeParams).Count))) { - DAST._IType _1185_typeParam; - _1185_typeParam = ((m).dtor_typeParams).Select(_1184_typeParamI); - if (!((enclosingTypeParams).Contains(_1185_typeParam))) { - _1183_typeParamsFiltered = Dafny.Sequence.Concat(_1183_typeParamsFiltered, Dafny.Sequence.FromElements(_1185_typeParam)); - } - _1184_typeParamI = (_1184_typeParamI) + (BigInteger.One); - } - Dafny.ISequence _1186_whereClauses; - _1186_whereClauses = Dafny.Sequence.UnicodeFromString(""); - Dafny.ISequence _1187_typeParams; - _1187_typeParams = Dafny.Sequence.FromElements(); - if ((new BigInteger((_1183_typeParamsFiltered).Count)).Sign == 1) { - _1186_whereClauses = Dafny.Sequence.Concat(_1186_whereClauses, Dafny.Sequence.UnicodeFromString(" where ")); - BigInteger _1188_i; - _1188_i = BigInteger.Zero; - while ((_1188_i) < (new BigInteger((_1183_typeParamsFiltered).Count))) { - RAST._IType _1189_typeExpr; - RAST._IType _out78; - _out78 = (this).GenType((_1183_typeParamsFiltered).Select(_1188_i), false, false); - _1189_typeExpr = _out78; - _1187_typeParams = Dafny.Sequence.Concat(_1187_typeParams, Dafny.Sequence.FromElements(RAST.TypeParam.create((_1189_typeExpr)._ToString(DCOMP.__default.IND), Dafny.Sequence.FromElements(RAST.__default.CloneTrait, RAST.__default.DafnyPrintTrait, RAST.__default.DefaultTrait, RAST.__default.StaticTrait)))); - _1188_i = (_1188_i) + (BigInteger.One); - } - } - Std.Wrappers._IOption _1190_fBody = Std.Wrappers.Option.Default(); + RAST._IType _1271_tpe; + RAST._IType _out84; + _out84 = (this).GenType(enclosingType, false, false); + _1271_tpe = _out84; + if (!((_1271_tpe).CanReadWithoutClone())) { + _1271_tpe = RAST.Type.create_Borrowed(_1271_tpe); + } + _1260_params = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.Formal.create(_1269_selfId, _1271_tpe)), _1260_params); + } + _1268_selfIdentifier = Std.Wrappers.Option>.create_Some(_1269_selfId); + } + Dafny.ISequence _1272_retTypeArgs; + _1272_retTypeArgs = Dafny.Sequence.FromElements(); + BigInteger _1273_typeI; + _1273_typeI = BigInteger.Zero; + while ((_1273_typeI) < (new BigInteger(((m).dtor_outTypes).Count))) { + RAST._IType _1274_typeExpr; + RAST._IType _out85; + _out85 = (this).GenType(((m).dtor_outTypes).Select(_1273_typeI), false, false); + _1274_typeExpr = _out85; + _1272_retTypeArgs = Dafny.Sequence.Concat(_1272_retTypeArgs, Dafny.Sequence.FromElements(_1274_typeExpr)); + _1273_typeI = (_1273_typeI) + (BigInteger.One); + } + RAST._IVisibility _1275_visibility; + _1275_visibility = RAST.Visibility.create_PUB(); + Dafny.ISequence _1276_typeParamsFiltered; + _1276_typeParamsFiltered = Dafny.Sequence.FromElements(); + BigInteger _hi24 = new BigInteger(((m).dtor_typeParams).Count); + for (BigInteger _1277_typeParamI = BigInteger.Zero; _1277_typeParamI < _hi24; _1277_typeParamI++) { + DAST._ITypeArgDecl _1278_typeParam; + _1278_typeParam = ((m).dtor_typeParams).Select(_1277_typeParamI); + if (!((enclosingTypeParams).Contains(DAST.Type.create_TypeArg((_1278_typeParam).dtor_name)))) { + _1276_typeParamsFiltered = Dafny.Sequence.Concat(_1276_typeParamsFiltered, Dafny.Sequence.FromElements(_1278_typeParam)); + } + } + Dafny.ISequence _1279_typeParams; + _1279_typeParams = Dafny.Sequence.FromElements(); + if ((new BigInteger((_1276_typeParamsFiltered).Count)).Sign == 1) { + BigInteger _hi25 = new BigInteger((_1276_typeParamsFiltered).Count); + for (BigInteger _1280_i = BigInteger.Zero; _1280_i < _hi25; _1280_i++) { + DAST._IType _1281_typeArg; + RAST._ITypeParamDecl _1282_rTypeParamDecl; + DAST._IType _out86; + RAST._ITypeParamDecl _out87; + (this).GenTypeParam((_1276_typeParamsFiltered).Select(_1280_i), out _out86, out _out87); + _1281_typeArg = _out86; + _1282_rTypeParamDecl = _out87; + var _pat_let_tv101 = _1282_rTypeParamDecl; + _1282_rTypeParamDecl = Dafny.Helpers.Let(_1282_rTypeParamDecl, _pat_let6_0 => Dafny.Helpers.Let(_pat_let6_0, _1283_dt__update__tmp_h0 => Dafny.Helpers.Let, RAST._ITypeParamDecl>(Dafny.Sequence.Concat((_pat_let_tv101).dtor_constraints, Dafny.Sequence.FromElements(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default")))), _pat_let7_0 => Dafny.Helpers.Let, RAST._ITypeParamDecl>(_pat_let7_0, _1284_dt__update_hconstraints_h0 => RAST.TypeParamDecl.create((_1283_dt__update__tmp_h0).dtor_content, _1284_dt__update_hconstraints_h0))))); + _1279_typeParams = Dafny.Sequence.Concat(_1279_typeParams, Dafny.Sequence.FromElements(_1282_rTypeParamDecl)); + } + } + Std.Wrappers._IOption _1285_fBody = Std.Wrappers.Option.Default(); + DCOMP._IEnvironment _1286_env = DCOMP.Environment.Default(); + RAST._IExpr _1287_preBody; + _1287_preBody = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); if ((m).dtor_hasBody) { - RAST._IExpr _1191_earlyReturn; - _1191_earlyReturn = RAST.Expr.create_Return(Std.Wrappers.Option.create_None()); - Std.Wrappers._IOption>> _source52 = (m).dtor_outVars; - bool unmatched52 = true; - if (unmatched52) { - if (_source52.is_Some) { - Dafny.ISequence> _1192_outVars = _source52.dtor_value; - unmatched52 = false; + RAST._IExpr _1288_earlyReturn; + _1288_earlyReturn = RAST.Expr.create_Return(Std.Wrappers.Option.create_None()); + Std.Wrappers._IOption>> _source55 = (m).dtor_outVars; + bool unmatched55 = true; + if (unmatched55) { + if (_source55.is_Some) { + Dafny.ISequence> _1289_outVars = _source55.dtor_value; + unmatched55 = false; { - Dafny.ISequence _1193_tupleArgs; - _1193_tupleArgs = Dafny.Sequence.FromElements(); - BigInteger _1194_outI; - _1194_outI = BigInteger.Zero; - while ((_1194_outI) < (new BigInteger((_1192_outVars).Count))) { - Dafny.ISequence _1195_outVar; - _1195_outVar = (_1192_outVars).Select(_1194_outI); - _1193_tupleArgs = Dafny.Sequence.Concat(_1193_tupleArgs, Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(DCOMP.__default.escapeIdent((_1195_outVar))))); - _1194_outI = (_1194_outI) + (BigInteger.One); + Dafny.ISequence _1290_tupleArgs; + _1290_tupleArgs = Dafny.Sequence.FromElements(); + BigInteger _hi26 = new BigInteger((_1289_outVars).Count); + for (BigInteger _1291_outI = BigInteger.Zero; _1291_outI < _hi26; _1291_outI++) { + Dafny.ISequence _1292_outVar; + _1292_outVar = (_1289_outVars).Select(_1291_outI); + RAST._IType _1293_outType; + RAST._IType _out88; + _out88 = (this).GenType(((m).dtor_outTypes).Select(_1291_outI), false, false); + _1293_outType = _out88; + Dafny.ISequence _1294_outName; + _1294_outName = DCOMP.__default.escapeName((_1292_outVar)); + _1261_paramNames = Dafny.Sequence>.Concat(_1261_paramNames, Dafny.Sequence>.FromElements(_1294_outName)); + RAST._IType _1295_outMaybeType; + _1295_outMaybeType = (((_1293_outType).CanReadWithoutClone()) ? (_1293_outType) : (RAST.Type.create_Borrowed(_1293_outType))); + _1262_paramTypes = Dafny.Map, RAST._IType>.Update(_1262_paramTypes, _1294_outName, _1295_outMaybeType); + RAST._IExpr _1296_outVarReturn; + DCOMP._IOwnership _1297___v53; + Dafny.ISet> _1298___v54; + RAST._IExpr _out89; + DCOMP._IOwnership _out90; + Dafny.ISet> _out91; + (this).GenExpr(DAST.Expression.create_Ident((_1292_outVar)), Std.Wrappers.Option>.create_None(), DCOMP.Environment.create(Dafny.Sequence>.FromElements(_1294_outName), Dafny.Map, RAST._IType>.FromElements(new Dafny.Pair, RAST._IType>(_1294_outName, _1295_outMaybeType))), DCOMP.Ownership.create_OwnershipOwned(), out _out89, out _out90, out _out91); + _1296_outVarReturn = _out89; + _1297___v53 = _out90; + _1298___v54 = _out91; + _1290_tupleArgs = Dafny.Sequence.Concat(_1290_tupleArgs, Dafny.Sequence.FromElements(_1296_outVarReturn)); + } + if ((new BigInteger((_1290_tupleArgs).Count)) == (BigInteger.One)) { + _1288_earlyReturn = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_1290_tupleArgs).Select(BigInteger.Zero))); + } else { + _1288_earlyReturn = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_1290_tupleArgs))); } - _1191_earlyReturn = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_1193_tupleArgs))); } } } - if (unmatched52) { - unmatched52 = false; + if (unmatched55) { + unmatched55 = false; } - RAST._IExpr _1196_body; - Dafny.ISet> _1197___v39; - RAST._IExpr _out79; - Dafny.ISet> _out80; - (this).GenStmts((m).dtor_body, (((m).dtor_isStatic) ? (Std.Wrappers.Option>.create_None()) : (Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("self")))), _1175_paramNames, true, _1191_earlyReturn, out _out79, out _out80); - _1196_body = _out79; - _1197___v39 = _out80; - _1190_fBody = Std.Wrappers.Option.create_Some(_1196_body); + _1286_env = DCOMP.Environment.create(_1261_paramNames, _1262_paramTypes); + RAST._IExpr _1299_body; + Dafny.ISet> _1300___v55; + DCOMP._IEnvironment _1301___v56; + RAST._IExpr _out92; + Dafny.ISet> _out93; + DCOMP._IEnvironment _out94; + (this).GenStmts((m).dtor_body, _1268_selfIdentifier, _1286_env, true, _1288_earlyReturn, out _out92, out _out93, out _out94); + _1299_body = _out92; + _1300___v55 = _out93; + _1301___v56 = _out94; + _1285_fBody = Std.Wrappers.Option.create_Some((_1287_preBody).Then(_1299_body)); } else { - _1190_fBody = Std.Wrappers.Option.create_None(); + _1286_env = DCOMP.Environment.create(_1261_paramNames, _1262_paramTypes); + _1285_fBody = Std.Wrappers.Option.create_None(); } - s = RAST.ImplMember.create_FnDecl(_1181_visibility, RAST.Fn.create(_1182_fnName, _1187_typeParams, _1174_params, Std.Wrappers.Option.create_Some((((new BigInteger((_1178_retTypeArgs).Count)) == (BigInteger.One)) ? ((_1178_retTypeArgs).Select(BigInteger.Zero)) : (RAST.Type.create_TupleType(_1178_retTypeArgs)))), _1186_whereClauses, _1190_fBody)); + s = RAST.ImplMember.create_FnDecl(_1275_visibility, RAST.Fn.create(_1267_fnName, _1279_typeParams, _1260_params, Std.Wrappers.Option.create_Some((((new BigInteger((_1272_retTypeArgs).Count)) == (BigInteger.One)) ? ((_1272_retTypeArgs).Select(BigInteger.Zero)) : (RAST.Type.create_TupleType(_1272_retTypeArgs)))), Dafny.Sequence.UnicodeFromString(""), _1285_fBody)); return s; } - public void GenStmts(Dafny.ISequence stmts, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, bool isLast, RAST._IExpr earlyReturn, out RAST._IExpr generated, out Dafny.ISet> readIdents) + public void GenStmts(Dafny.ISequence stmts, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, bool isLast, RAST._IExpr earlyReturn, out RAST._IExpr generated, out Dafny.ISet> readIdents, out DCOMP._IEnvironment newEnv) { generated = RAST.Expr.Default(); readIdents = Dafny.Set>.Empty; + newEnv = DCOMP.Environment.Default(); generated = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); - Dafny.ISet> _1198_declarations; - _1198_declarations = Dafny.Set>.FromElements(); + Dafny.ISet> _1302_declarations; + _1302_declarations = Dafny.Set>.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _1199_i; - _1199_i = BigInteger.Zero; - while ((_1199_i) < (new BigInteger((stmts).Count))) { - DAST._IStatement _1200_stmt; - _1200_stmt = (stmts).Select(_1199_i); - RAST._IExpr _1201_stmtExpr; - Dafny.ISet> _1202_recIdents; - RAST._IExpr _out81; - Dafny.ISet> _out82; - (this).GenStmt(_1200_stmt, selfIdent, @params, (isLast) && ((_1199_i) == ((new BigInteger((stmts).Count)) - (BigInteger.One))), earlyReturn, out _out81, out _out82); - _1201_stmtExpr = _out81; - _1202_recIdents = _out82; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_1202_recIdents, _1198_declarations)); - DAST._IStatement _source53 = _1200_stmt; - bool unmatched53 = true; - if (unmatched53) { - if (_source53.is_DeclareVar) { - Dafny.ISequence _1203_name = _source53.dtor_name; - DAST._IType _1204___v40 = _source53.dtor_typ; - Std.Wrappers._IOption _1205___v41 = _source53.dtor_maybeValue; - unmatched53 = false; + BigInteger _1303_i; + _1303_i = BigInteger.Zero; + newEnv = env; + while ((_1303_i) < (new BigInteger((stmts).Count))) { + DAST._IStatement _1304_stmt; + _1304_stmt = (stmts).Select(_1303_i); + RAST._IExpr _1305_stmtExpr; + Dafny.ISet> _1306_recIdents; + DCOMP._IEnvironment _1307_newEnv2; + RAST._IExpr _out95; + Dafny.ISet> _out96; + DCOMP._IEnvironment _out97; + (this).GenStmt(_1304_stmt, selfIdent, newEnv, (isLast) && ((_1303_i) == ((new BigInteger((stmts).Count)) - (BigInteger.One))), earlyReturn, out _out95, out _out96, out _out97); + _1305_stmtExpr = _out95; + _1306_recIdents = _out96; + _1307_newEnv2 = _out97; + newEnv = _1307_newEnv2; + DAST._IStatement _source56 = _1304_stmt; + bool unmatched56 = true; + if (unmatched56) { + if (_source56.is_DeclareVar) { + Dafny.ISequence _1308_name = _source56.dtor_name; + DAST._IType _1309___v57 = _source56.dtor_typ; + Std.Wrappers._IOption _1310___v58 = _source56.dtor_maybeValue; + unmatched56 = false; { - _1198_declarations = Dafny.Set>.Union(_1198_declarations, Dafny.Set>.FromElements(_1203_name)); + _1302_declarations = Dafny.Set>.Union(_1302_declarations, Dafny.Set>.FromElements(DCOMP.__default.escapeName(_1308_name))); } } } - if (unmatched53) { - DAST._IStatement _1206___v42 = _source53; - unmatched53 = false; + if (unmatched56) { + DAST._IStatement _1311___v59 = _source56; + unmatched56 = false; } - generated = (generated).Then(_1201_stmtExpr); - _1199_i = (_1199_i) + (BigInteger.One); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_1306_recIdents, _1302_declarations)); + generated = (generated).Then(_1305_stmtExpr); + _1303_i = (_1303_i) + (BigInteger.One); } } - public void GenAssignLhs(DAST._IAssignLhs lhs, Dafny.ISequence rhs, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, out Dafny.ISequence generated, out bool needsIIFE, out Dafny.ISet> readIdents) + public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, out RAST._IExpr generated, out bool needsIIFE, out Dafny.ISet> readIdents, out DCOMP._IEnvironment newEnv) { - generated = Dafny.Sequence.Empty; + generated = RAST.Expr.Default(); needsIIFE = false; readIdents = Dafny.Set>.Empty; - DAST._IAssignLhs _source54 = lhs; - bool unmatched54 = true; - if (unmatched54) { - if (_source54.is_Ident) { - Dafny.ISequence _h130 = _source54.dtor_Ident_a0; - Dafny.ISequence _1207_id = _h130; - unmatched54 = false; + newEnv = DCOMP.Environment.Default(); + newEnv = env; + DAST._IAssignLhs _source57 = lhs; + bool unmatched57 = true; + if (unmatched57) { + if (_source57.is_Ident) { + Dafny.ISequence ident0 = _source57.dtor_ident; + Dafny.ISequence _1312_id = ident0; + unmatched57 = false; { - if ((@params).Contains(_1207_id)) { - generated = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("*"), DCOMP.__default.escapeIdent(_1207_id)); + Dafny.ISequence _1313_idRust; + _1313_idRust = DCOMP.__default.escapeName(_1312_id); + if (((env).IsBorrowed(_1313_idRust)) || ((env).IsBorrowedMut(_1313_idRust))) { + generated = RAST.__default.AssignVar(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("*"), _1313_idRust), rhs); } else { - generated = DCOMP.__default.escapeIdent(_1207_id); + generated = RAST.__default.AssignVar(_1313_idRust, rhs); } - readIdents = Dafny.Set>.FromElements(_1207_id); + readIdents = Dafny.Set>.FromElements(_1313_idRust); needsIIFE = false; } } } - if (unmatched54) { - if (_source54.is_Select) { - DAST._IExpression _1208_on = _source54.dtor_expr; - Dafny.ISequence _1209_field = _source54.dtor_field; - unmatched54 = false; + if (unmatched57) { + if (_source57.is_Select) { + DAST._IExpression _1314_on = _source57.dtor_expr; + Dafny.ISequence _1315_field = _source57.dtor_field; + unmatched57 = false; { - RAST._IExpr _1210_onExpr; - DCOMP._IOwnership _1211_onOwned; - Dafny.ISet> _1212_recIdents; - RAST._IExpr _out83; - DCOMP._IOwnership _out84; - Dafny.ISet> _out85; - (this).GenExpr(_1208_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out83, out _out84, out _out85); - _1210_onExpr = _out83; - _1211_onOwned = _out84; - _1212_recIdents = _out85; - generated = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("*("), (_1210_onExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(".")), DCOMP.__default.escapeIdent(_1209_field)), Dafny.Sequence.UnicodeFromString(".borrow_mut()) = ")), rhs), Dafny.Sequence.UnicodeFromString(";")); - readIdents = _1212_recIdents; + Dafny.ISequence _1316_fieldName; + _1316_fieldName = DCOMP.__default.escapeName(_1315_field); + RAST._IExpr _1317_onExpr; + DCOMP._IOwnership _1318_onOwned; + Dafny.ISet> _1319_recIdents; + RAST._IExpr _out98; + DCOMP._IOwnership _out99; + Dafny.ISet> _out100; + (this).GenExpr(_1314_on, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowedMut(), out _out98, out _out99, out _out100); + _1317_onExpr = _out98; + _1318_onOwned = _out99; + _1319_recIdents = _out100; + generated = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("*("), (_1317_onExpr)._ToString(RAST.__default.IND)), Dafny.Sequence.UnicodeFromString(".")), _1316_fieldName), Dafny.Sequence.UnicodeFromString(".borrow_mut()) = ")), (rhs)._ToString(RAST.__default.IND)), Dafny.Sequence.UnicodeFromString(";"))); + readIdents = _1319_recIdents; needsIIFE = true; } } } - if (unmatched54) { - DAST._IExpression _1213_on = _source54.dtor_expr; - Dafny.ISequence _1214_indices = _source54.dtor_indices; - unmatched54 = false; + if (unmatched57) { + DAST._IExpression _1320_on = _source57.dtor_expr; + Dafny.ISequence _1321_indices = _source57.dtor_indices; + unmatched57 = false; { - RAST._IExpr _1215_onExpr; - DCOMP._IOwnership _1216_onOwned; - Dafny.ISet> _1217_recIdents; - RAST._IExpr _out86; - DCOMP._IOwnership _out87; - Dafny.ISet> _out88; - (this).GenExpr(_1213_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out86, out _out87, out _out88); - _1215_onExpr = _out86; - _1216_onOwned = _out87; - _1217_recIdents = _out88; - readIdents = _1217_recIdents; - generated = Dafny.Sequence.UnicodeFromString("{\n"); - BigInteger _1218_i; - _1218_i = BigInteger.Zero; - while ((_1218_i) < (new BigInteger((_1214_indices).Count))) { - RAST._IExpr _1219_idx; - DCOMP._IOwnership _1220___v43; - Dafny.ISet> _1221_recIdentsIdx; - RAST._IExpr _out89; - DCOMP._IOwnership _out90; - Dafny.ISet> _out91; - (this).GenExpr((_1214_indices).Select(_1218_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out89, out _out90, out _out91); - _1219_idx = _out89; - _1220___v43 = _out90; - _1221_recIdentsIdx = _out91; - generated = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(generated, Dafny.Sequence.UnicodeFromString("let __idx")), Std.Strings.__default.OfNat(_1218_i)), Dafny.Sequence.UnicodeFromString(" = ::from(")), (_1219_idx)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap();\n")); - readIdents = Dafny.Set>.Union(readIdents, _1221_recIdentsIdx); - _1218_i = (_1218_i) + (BigInteger.One); - } - generated = Dafny.Sequence.Concat(Dafny.Sequence.Concat(generated, (_1215_onExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(".borrow_mut()")); - _1218_i = BigInteger.Zero; - while ((_1218_i) < (new BigInteger((_1214_indices).Count))) { - generated = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(generated, Dafny.Sequence.UnicodeFromString("[__idx")), Std.Strings.__default.OfNat(_1218_i)), Dafny.Sequence.UnicodeFromString("]")); - _1218_i = (_1218_i) + (BigInteger.One); - } - generated = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(generated, Dafny.Sequence.UnicodeFromString(" = ")), rhs), Dafny.Sequence.UnicodeFromString(";\n}")); + RAST._IExpr _1322_onExpr; + DCOMP._IOwnership _1323_onOwned; + Dafny.ISet> _1324_recIdents; + RAST._IExpr _out101; + DCOMP._IOwnership _out102; + Dafny.ISet> _out103; + (this).GenExpr(_1320_on, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out101, out _out102, out _out103); + _1322_onExpr = _out101; + _1323_onOwned = _out102; + _1324_recIdents = _out103; + readIdents = _1324_recIdents; + Dafny.ISequence _1325_r; + _1325_r = Dafny.Sequence.UnicodeFromString("{\n"); + BigInteger _1326_i; + _1326_i = BigInteger.Zero; + while ((_1326_i) < (new BigInteger((_1321_indices).Count))) { + RAST._IExpr _1327_idx; + DCOMP._IOwnership _1328___v60; + Dafny.ISet> _1329_recIdentsIdx; + RAST._IExpr _out104; + DCOMP._IOwnership _out105; + Dafny.ISet> _out106; + (this).GenExpr((_1321_indices).Select(_1326_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out104, out _out105, out _out106); + _1327_idx = _out104; + _1328___v60 = _out105; + _1329_recIdentsIdx = _out106; + _1325_r = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1325_r, Dafny.Sequence.UnicodeFromString("let __idx")), Std.Strings.__default.OfNat(_1326_i)), Dafny.Sequence.UnicodeFromString(" = ::from(")), (_1327_idx)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap();\n")); + readIdents = Dafny.Set>.Union(readIdents, _1329_recIdentsIdx); + _1326_i = (_1326_i) + (BigInteger.One); + } + _1325_r = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1325_r, (_1322_onExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(".borrow_mut()")); + _1326_i = BigInteger.Zero; + while ((_1326_i) < (new BigInteger((_1321_indices).Count))) { + _1325_r = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1325_r, Dafny.Sequence.UnicodeFromString("[__idx")), Std.Strings.__default.OfNat(_1326_i)), Dafny.Sequence.UnicodeFromString("]")); + _1326_i = (_1326_i) + (BigInteger.One); + } + generated = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1325_r, Dafny.Sequence.UnicodeFromString(" = ")), (rhs)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(";\n}"))); needsIIFE = true; } } } - public void GenStmt(DAST._IStatement stmt, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, bool isLast, RAST._IExpr earlyReturn, out RAST._IExpr generated, out Dafny.ISet> readIdents) + public void GenStmt(DAST._IStatement stmt, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, bool isLast, RAST._IExpr earlyReturn, out RAST._IExpr generated, out Dafny.ISet> readIdents, out DCOMP._IEnvironment newEnv) { generated = RAST.Expr.Default(); readIdents = Dafny.Set>.Empty; - DAST._IStatement _source55 = stmt; - bool unmatched55 = true; - if (unmatched55) { - if (_source55.is_DeclareVar) { - Dafny.ISequence _1222_name = _source55.dtor_name; - DAST._IType _1223_typ = _source55.dtor_typ; - Std.Wrappers._IOption maybeValue0 = _source55.dtor_maybeValue; + newEnv = DCOMP.Environment.Default(); + DAST._IStatement _source58 = stmt; + bool unmatched58 = true; + if (unmatched58) { + if (_source58.is_DeclareVar) { + Dafny.ISequence _1330_name = _source58.dtor_name; + DAST._IType _1331_typ = _source58.dtor_typ; + Std.Wrappers._IOption maybeValue0 = _source58.dtor_maybeValue; if (maybeValue0.is_Some) { - DAST._IExpression _1224_expression = maybeValue0.dtor_value; - unmatched55 = false; + DAST._IExpression _1332_expression = maybeValue0.dtor_value; + unmatched58 = false; { - RAST._IType _1225_typeString; - RAST._IType _out92; - _out92 = (this).GenType(_1223_typ, true, false); - _1225_typeString = _out92; - RAST._IExpr _1226_expr; - DCOMP._IOwnership _1227___v44; - Dafny.ISet> _1228_recIdents; - RAST._IExpr _out93; - DCOMP._IOwnership _out94; - Dafny.ISet> _out95; - (this).GenExpr(_1224_expression, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); - _1226_expr = _out93; - _1227___v44 = _out94; - _1228_recIdents = _out95; - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), DCOMP.__default.escapeIdent(_1222_name), Std.Wrappers.Option.create_Some(_1225_typeString), Std.Wrappers.Option.create_Some(_1226_expr)); - readIdents = _1228_recIdents; + RAST._IType _1333_tpe; + RAST._IType _out107; + _out107 = (this).GenType(_1331_typ, true, false); + _1333_tpe = _out107; + RAST._IExpr _1334_expr; + DCOMP._IOwnership _1335_exprOwnership; + Dafny.ISet> _1336_recIdents; + RAST._IExpr _out108; + DCOMP._IOwnership _out109; + Dafny.ISet> _out110; + (this).GenExpr(_1332_expression, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out108, out _out109, out _out110); + _1334_expr = _out108; + _1335_exprOwnership = _out109; + _1336_recIdents = _out110; + readIdents = _1336_recIdents; + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), DCOMP.__default.escapeName(_1330_name), Std.Wrappers.Option.create_Some(_1333_tpe), Std.Wrappers.Option.create_Some(_1334_expr)); + newEnv = (env).AddAssigned(DCOMP.__default.escapeName(_1330_name), _1333_tpe); } } } } - if (unmatched55) { - if (_source55.is_DeclareVar) { - Dafny.ISequence _1229_name = _source55.dtor_name; - DAST._IType _1230_typ = _source55.dtor_typ; - Std.Wrappers._IOption maybeValue1 = _source55.dtor_maybeValue; + if (unmatched58) { + if (_source58.is_DeclareVar) { + Dafny.ISequence _1337_name = _source58.dtor_name; + DAST._IType _1338_typ = _source58.dtor_typ; + Std.Wrappers._IOption maybeValue1 = _source58.dtor_maybeValue; if (maybeValue1.is_None) { - unmatched55 = false; + unmatched58 = false; { - RAST._IType _1231_typeString; - RAST._IType _out96; - _out96 = (this).GenType(_1230_typ, true, false); - _1231_typeString = _out96; - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), DCOMP.__default.escapeIdent(_1229_name), Std.Wrappers.Option.create_Some(_1231_typeString), Std.Wrappers.Option.create_None()); - readIdents = Dafny.Set>.FromElements(); + DAST._IStatement _1339_newStmt; + _1339_newStmt = DAST.Statement.create_DeclareVar(_1337_name, _1338_typ, Std.Wrappers.Option.create_Some(DAST.Expression.create_InitializationValue(_1338_typ))); + RAST._IExpr _out111; + Dafny.ISet> _out112; + DCOMP._IEnvironment _out113; + (this).GenStmt(_1339_newStmt, selfIdent, env, isLast, earlyReturn, out _out111, out _out112, out _out113); + generated = _out111; + readIdents = _out112; + newEnv = _out113; } } } } - if (unmatched55) { - if (_source55.is_Assign) { - DAST._IAssignLhs _1232_lhs = _source55.dtor_lhs; - DAST._IExpression _1233_expression = _source55.dtor_value; - unmatched55 = false; + if (unmatched58) { + if (_source58.is_Assign) { + DAST._IAssignLhs _1340_lhs = _source58.dtor_lhs; + DAST._IExpression _1341_expression = _source58.dtor_value; + unmatched58 = false; { - Dafny.ISequence _1234_lhsGen; - bool _1235_needsIIFE; - Dafny.ISet> _1236_recIdents; - Dafny.ISequence _out97; - bool _out98; - Dafny.ISet> _out99; - (this).GenAssignLhs(_1232_lhs, Dafny.Sequence.UnicodeFromString("__rhs"), selfIdent, @params, out _out97, out _out98, out _out99); - _1234_lhsGen = _out97; - _1235_needsIIFE = _out98; - _1236_recIdents = _out99; - RAST._IExpr _1237_exprGen; - DCOMP._IOwnership _1238___v45; - Dafny.ISet> _1239_exprIdents; - RAST._IExpr _out100; - DCOMP._IOwnership _out101; - Dafny.ISet> _out102; - (this).GenExpr(_1233_expression, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out100, out _out101, out _out102); - _1237_exprGen = _out100; - _1238___v45 = _out101; - _1239_exprIdents = _out102; - if (_1235_needsIIFE) { - generated = RAST.Expr.create_Block(RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("__rhs"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_1237_exprGen)), RAST.Expr.create_RawExpr(_1234_lhsGen))); - } else { - generated = RAST.Expr.create_AssignVar(_1234_lhsGen, _1237_exprGen); + RAST._IExpr _1342_exprGen; + DCOMP._IOwnership _1343___v61; + Dafny.ISet> _1344_exprIdents; + RAST._IExpr _out114; + DCOMP._IOwnership _out115; + Dafny.ISet> _out116; + (this).GenExpr(_1341_expression, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out114, out _out115, out _out116); + _1342_exprGen = _out114; + _1343___v61 = _out115; + _1344_exprIdents = _out116; + if ((_1340_lhs).is_Ident) { + Dafny.ISequence _1345_rustId; + _1345_rustId = DCOMP.__default.escapeName(((_1340_lhs).dtor_ident)); + Std.Wrappers._IOption _1346_tpe; + _1346_tpe = (env).GetType(_1345_rustId); + } + RAST._IExpr _1347_lhsGen; + bool _1348_needsIIFE; + Dafny.ISet> _1349_recIdents; + DCOMP._IEnvironment _1350_resEnv; + RAST._IExpr _out117; + bool _out118; + Dafny.ISet> _out119; + DCOMP._IEnvironment _out120; + (this).GenAssignLhs(_1340_lhs, _1342_exprGen, selfIdent, env, out _out117, out _out118, out _out119, out _out120); + _1347_lhsGen = _out117; + _1348_needsIIFE = _out118; + _1349_recIdents = _out119; + _1350_resEnv = _out120; + generated = _1347_lhsGen; + newEnv = _1350_resEnv; + if (_1348_needsIIFE) { + generated = RAST.Expr.create_Block(generated); } - readIdents = Dafny.Set>.Union(_1236_recIdents, _1239_exprIdents); + readIdents = Dafny.Set>.Union(_1349_recIdents, _1344_exprIdents); } } } - if (unmatched55) { - if (_source55.is_If) { - DAST._IExpression _1240_cond = _source55.dtor_cond; - Dafny.ISequence _1241_thn = _source55.dtor_thn; - Dafny.ISequence _1242_els = _source55.dtor_els; - unmatched55 = false; + if (unmatched58) { + if (_source58.is_If) { + DAST._IExpression _1351_cond = _source58.dtor_cond; + Dafny.ISequence _1352_thnDafny = _source58.dtor_thn; + Dafny.ISequence _1353_elsDafny = _source58.dtor_els; + unmatched58 = false; { - RAST._IExpr _1243_cond; - DCOMP._IOwnership _1244___v46; - Dafny.ISet> _1245_recIdents; - RAST._IExpr _out103; - DCOMP._IOwnership _out104; - Dafny.ISet> _out105; - (this).GenExpr(_1240_cond, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out103, out _out104, out _out105); - _1243_cond = _out103; - _1244___v46 = _out104; - _1245_recIdents = _out105; - Dafny.ISequence _1246_condString; - _1246_condString = (_1243_cond)._ToString(DCOMP.__default.IND); - readIdents = _1245_recIdents; - RAST._IExpr _1247_thn; - Dafny.ISet> _1248_thnIdents; - RAST._IExpr _out106; - Dafny.ISet> _out107; - (this).GenStmts(_1241_thn, selfIdent, @params, isLast, earlyReturn, out _out106, out _out107); - _1247_thn = _out106; - _1248_thnIdents = _out107; - readIdents = Dafny.Set>.Union(readIdents, _1248_thnIdents); - RAST._IExpr _1249_els; - Dafny.ISet> _1250_elsIdents; - RAST._IExpr _out108; - Dafny.ISet> _out109; - (this).GenStmts(_1242_els, selfIdent, @params, isLast, earlyReturn, out _out108, out _out109); - _1249_els = _out108; - _1250_elsIdents = _out109; - readIdents = Dafny.Set>.Union(readIdents, _1250_elsIdents); - generated = RAST.Expr.create_IfExpr(_1243_cond, _1247_thn, _1249_els); - } - } - } - if (unmatched55) { - if (_source55.is_Labeled) { - Dafny.ISequence _1251_lbl = _source55.dtor_lbl; - Dafny.ISequence _1252_body = _source55.dtor_body; - unmatched55 = false; + RAST._IExpr _1354_cond; + DCOMP._IOwnership _1355___v62; + Dafny.ISet> _1356_recIdents; + RAST._IExpr _out121; + DCOMP._IOwnership _out122; + Dafny.ISet> _out123; + (this).GenExpr(_1351_cond, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out121, out _out122, out _out123); + _1354_cond = _out121; + _1355___v62 = _out122; + _1356_recIdents = _out123; + Dafny.ISequence _1357_condString; + _1357_condString = (_1354_cond)._ToString(DCOMP.__default.IND); + readIdents = _1356_recIdents; + RAST._IExpr _1358_thn; + Dafny.ISet> _1359_thnIdents; + DCOMP._IEnvironment _1360_thnEnv; + RAST._IExpr _out124; + Dafny.ISet> _out125; + DCOMP._IEnvironment _out126; + (this).GenStmts(_1352_thnDafny, selfIdent, env, isLast, earlyReturn, out _out124, out _out125, out _out126); + _1358_thn = _out124; + _1359_thnIdents = _out125; + _1360_thnEnv = _out126; + readIdents = Dafny.Set>.Union(readIdents, _1359_thnIdents); + RAST._IExpr _1361_els; + Dafny.ISet> _1362_elsIdents; + DCOMP._IEnvironment _1363_elsEnv; + RAST._IExpr _out127; + Dafny.ISet> _out128; + DCOMP._IEnvironment _out129; + (this).GenStmts(_1353_elsDafny, selfIdent, env, isLast, earlyReturn, out _out127, out _out128, out _out129); + _1361_els = _out127; + _1362_elsIdents = _out128; + _1363_elsEnv = _out129; + readIdents = Dafny.Set>.Union(readIdents, _1362_elsIdents); + newEnv = env; + generated = RAST.Expr.create_IfExpr(_1354_cond, _1358_thn, _1361_els); + } + } + } + if (unmatched58) { + if (_source58.is_Labeled) { + Dafny.ISequence _1364_lbl = _source58.dtor_lbl; + Dafny.ISequence _1365_body = _source58.dtor_body; + unmatched58 = false; { - RAST._IExpr _1253_body; - Dafny.ISet> _1254_bodyIdents; - RAST._IExpr _out110; - Dafny.ISet> _out111; - (this).GenStmts(_1252_body, selfIdent, @params, isLast, earlyReturn, out _out110, out _out111); - _1253_body = _out110; - _1254_bodyIdents = _out111; - readIdents = _1254_bodyIdents; - generated = RAST.Expr.create_Labelled(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _1251_lbl), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), RAST.Expr.create_StmtExpr(_1253_body, RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())))); - } - } - } - if (unmatched55) { - if (_source55.is_While) { - DAST._IExpression _1255_cond = _source55.dtor_cond; - Dafny.ISequence _1256_body = _source55.dtor_body; - unmatched55 = false; + RAST._IExpr _1366_body; + Dafny.ISet> _1367_bodyIdents; + DCOMP._IEnvironment _1368_env2; + RAST._IExpr _out130; + Dafny.ISet> _out131; + DCOMP._IEnvironment _out132; + (this).GenStmts(_1365_body, selfIdent, env, isLast, earlyReturn, out _out130, out _out131, out _out132); + _1366_body = _out130; + _1367_bodyIdents = _out131; + _1368_env2 = _out132; + readIdents = _1367_bodyIdents; + generated = RAST.Expr.create_Labelled(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _1364_lbl), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), RAST.Expr.create_StmtExpr(_1366_body, RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())))); + newEnv = env; + } + } + } + if (unmatched58) { + if (_source58.is_While) { + DAST._IExpression _1369_cond = _source58.dtor_cond; + Dafny.ISequence _1370_body = _source58.dtor_body; + unmatched58 = false; { - RAST._IExpr _1257_cond; - DCOMP._IOwnership _1258___v47; - Dafny.ISet> _1259_recIdents; - RAST._IExpr _out112; - DCOMP._IOwnership _out113; - Dafny.ISet> _out114; - (this).GenExpr(_1255_cond, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out112, out _out113, out _out114); - _1257_cond = _out112; - _1258___v47 = _out113; - _1259_recIdents = _out114; - readIdents = _1259_recIdents; - RAST._IExpr _1260_body; - Dafny.ISet> _1261_bodyIdents; - RAST._IExpr _out115; - Dafny.ISet> _out116; - (this).GenStmts(_1256_body, selfIdent, @params, false, earlyReturn, out _out115, out _out116); - _1260_body = _out115; - _1261_bodyIdents = _out116; - readIdents = Dafny.Set>.Union(readIdents, _1261_bodyIdents); - generated = RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(_1257_cond), _1260_body); - } - } - } - if (unmatched55) { - if (_source55.is_Foreach) { - Dafny.ISequence _1262_boundName = _source55.dtor_boundName; - DAST._IType _1263_boundType = _source55.dtor_boundType; - DAST._IExpression _1264_over = _source55.dtor_over; - Dafny.ISequence _1265_body = _source55.dtor_body; - unmatched55 = false; + RAST._IExpr _1371_cond; + DCOMP._IOwnership _1372___v63; + Dafny.ISet> _1373_recIdents; + RAST._IExpr _out133; + DCOMP._IOwnership _out134; + Dafny.ISet> _out135; + (this).GenExpr(_1369_cond, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out133, out _out134, out _out135); + _1371_cond = _out133; + _1372___v63 = _out134; + _1373_recIdents = _out135; + readIdents = _1373_recIdents; + RAST._IExpr _1374_bodyExpr; + Dafny.ISet> _1375_bodyIdents; + DCOMP._IEnvironment _1376_bodyEnv; + RAST._IExpr _out136; + Dafny.ISet> _out137; + DCOMP._IEnvironment _out138; + (this).GenStmts(_1370_body, selfIdent, env, false, earlyReturn, out _out136, out _out137, out _out138); + _1374_bodyExpr = _out136; + _1375_bodyIdents = _out137; + _1376_bodyEnv = _out138; + newEnv = env; + readIdents = Dafny.Set>.Union(readIdents, _1375_bodyIdents); + generated = RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(_1371_cond), _1374_bodyExpr); + } + } + } + if (unmatched58) { + if (_source58.is_Foreach) { + Dafny.ISequence _1377_boundName = _source58.dtor_boundName; + DAST._IType _1378_boundType = _source58.dtor_boundType; + DAST._IExpression _1379_over = _source58.dtor_over; + Dafny.ISequence _1380_body = _source58.dtor_body; + unmatched58 = false; { - RAST._IExpr _1266_over; - DCOMP._IOwnership _1267___v48; - Dafny.ISet> _1268_recIdents; - RAST._IExpr _out117; - DCOMP._IOwnership _out118; - Dafny.ISet> _out119; - (this).GenExpr(_1264_over, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out117, out _out118, out _out119); - _1266_over = _out117; - _1267___v48 = _out118; - _1268_recIdents = _out119; - RAST._IType _1269_boundTypeStr; - RAST._IType _out120; - _out120 = (this).GenType(_1263_boundType, false, false); - _1269_boundTypeStr = _out120; - readIdents = _1268_recIdents; - RAST._IExpr _1270_body; - Dafny.ISet> _1271_bodyIdents; - RAST._IExpr _out121; - Dafny.ISet> _out122; - (this).GenStmts(_1265_body, selfIdent, Dafny.Sequence>.Concat(@params, Dafny.Sequence>.FromElements(_1262_boundName)), false, earlyReturn, out _out121, out _out122); - _1270_body = _out121; - _1271_bodyIdents = _out122; - readIdents = Dafny.Set>.Difference(Dafny.Set>.Union(readIdents, _1271_bodyIdents), Dafny.Set>.FromElements(_1262_boundName)); - generated = RAST.Expr.create_For(DCOMP.__default.escapeIdent(_1262_boundName), _1266_over, _1270_body); - } - } - } - if (unmatched55) { - if (_source55.is_Break) { - Std.Wrappers._IOption> _1272_toLabel = _source55.dtor_toLabel; - unmatched55 = false; + RAST._IExpr _1381_over; + DCOMP._IOwnership _1382___v64; + Dafny.ISet> _1383_recIdents; + RAST._IExpr _out139; + DCOMP._IOwnership _out140; + Dafny.ISet> _out141; + (this).GenExpr(_1379_over, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out139, out _out140, out _out141); + _1381_over = _out139; + _1382___v64 = _out140; + _1383_recIdents = _out141; + RAST._IType _1384_boundTpe; + RAST._IType _out142; + _out142 = (this).GenType(_1378_boundType, false, false); + _1384_boundTpe = _out142; + readIdents = _1383_recIdents; + Dafny.ISequence _1385_boundRName; + _1385_boundRName = DCOMP.__default.escapeName(_1377_boundName); + RAST._IExpr _1386_bodyExpr; + Dafny.ISet> _1387_bodyIdents; + DCOMP._IEnvironment _1388_bodyEnv; + RAST._IExpr _out143; + Dafny.ISet> _out144; + DCOMP._IEnvironment _out145; + (this).GenStmts(_1380_body, selfIdent, (env).AddAssigned(_1385_boundRName, _1384_boundTpe), false, earlyReturn, out _out143, out _out144, out _out145); + _1386_bodyExpr = _out143; + _1387_bodyIdents = _out144; + _1388_bodyEnv = _out145; + readIdents = Dafny.Set>.Difference(Dafny.Set>.Union(readIdents, _1387_bodyIdents), Dafny.Set>.FromElements(_1385_boundRName)); + newEnv = env; + generated = RAST.Expr.create_For(_1385_boundRName, _1381_over, _1386_bodyExpr); + } + } + } + if (unmatched58) { + if (_source58.is_Break) { + Std.Wrappers._IOption> _1389_toLabel = _source58.dtor_toLabel; + unmatched58 = false; { - Std.Wrappers._IOption> _source56 = _1272_toLabel; - bool unmatched56 = true; - if (unmatched56) { - if (_source56.is_Some) { - Dafny.ISequence _1273_lbl = _source56.dtor_value; - unmatched56 = false; + Std.Wrappers._IOption> _source59 = _1389_toLabel; + bool unmatched59 = true; + if (unmatched59) { + if (_source59.is_Some) { + Dafny.ISequence _1390_lbl = _source59.dtor_value; + unmatched59 = false; { - generated = RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _1273_lbl))); + generated = RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _1390_lbl))); } } } - if (unmatched56) { - unmatched56 = false; + if (unmatched59) { + unmatched59 = false; { generated = RAST.Expr.create_Break(Std.Wrappers.Option>.create_None()); } } readIdents = Dafny.Set>.FromElements(); + newEnv = env; } } } - if (unmatched55) { - if (_source55.is_TailRecursive) { - Dafny.ISequence _1274_body = _source55.dtor_body; - unmatched55 = false; + if (unmatched58) { + if (_source58.is_TailRecursive) { + Dafny.ISequence _1391_body = _source58.dtor_body; + unmatched58 = false; { generated = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); if (!object.Equals(selfIdent, Std.Wrappers.Option>.create_None())) { - 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(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("self.clone()"))))); + 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(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply(Dafny.Sequence.FromElements())))); } - BigInteger _1275_paramI; - _1275_paramI = BigInteger.Zero; - while ((_1275_paramI) < (new BigInteger((@params).Count))) { - Dafny.ISequence _1276_param; - _1276_param = (@params).Select(_1275_paramI); - generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), DCOMP.__default.escapeIdent(_1276_param), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.__default.Clone(RAST.Expr.create_Identifier(DCOMP.__default.escapeIdent(_1276_param)))))); - _1275_paramI = (_1275_paramI) + (BigInteger.One); + newEnv = env; + BigInteger _hi27 = new BigInteger(((env).dtor_names).Count); + for (BigInteger _1392_paramI = BigInteger.Zero; _1392_paramI < _hi27; _1392_paramI++) { + Dafny.ISequence _1393_param; + _1393_param = ((env).dtor_names).Select(_1392_paramI); + RAST._IExpr _1394_paramInit; + DCOMP._IOwnership _1395___v65; + Dafny.ISet> _1396___v66; + RAST._IExpr _out146; + DCOMP._IOwnership _out147; + Dafny.ISet> _out148; + (this).GenIdent(_1393_param, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out146, out _out147, out _out148); + _1394_paramInit = _out146; + _1395___v65 = _out147; + _1396___v66 = _out148; + generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _1393_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_1394_paramInit))); + if (((env).dtor_types).Contains(_1393_param)) { + RAST._IType _1397_declaredType; + _1397_declaredType = (Dafny.Map, RAST._IType>.Select((env).dtor_types,_1393_param)).ToOwned(); + newEnv = (newEnv).AddAssigned(_1393_param, _1397_declaredType); + } } - RAST._IExpr _1277_body; - Dafny.ISet> _1278_bodyIdents; - RAST._IExpr _out123; - Dafny.ISet> _out124; - (this).GenStmts(_1274_body, ((!object.Equals(selfIdent, Std.Wrappers.Option>.create_None())) ? (Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("_this"))) : (Std.Wrappers.Option>.create_None())), Dafny.Sequence>.FromElements(), false, earlyReturn, out _out123, out _out124); - _1277_body = _out123; - _1278_bodyIdents = _out124; - readIdents = _1278_bodyIdents; - generated = (generated).Then(RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), _1277_body))); - } - } - } - if (unmatched55) { - if (_source55.is_JumpTailCallStart) { - unmatched55 = false; + RAST._IExpr _1398_bodyExpr; + Dafny.ISet> _1399_bodyIdents; + DCOMP._IEnvironment _1400_bodyEnv; + RAST._IExpr _out149; + Dafny.ISet> _out150; + DCOMP._IEnvironment _out151; + (this).GenStmts(_1391_body, ((!object.Equals(selfIdent, Std.Wrappers.Option>.create_None())) ? (Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("_this"))) : (Std.Wrappers.Option>.create_None())), newEnv, false, earlyReturn, out _out149, out _out150, out _out151); + _1398_bodyExpr = _out149; + _1399_bodyIdents = _out150; + _1400_bodyEnv = _out151; + readIdents = _1399_bodyIdents; + generated = (generated).Then(RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), _1398_bodyExpr))); + } + } + } + if (unmatched58) { + if (_source58.is_JumpTailCallStart) { + unmatched58 = false; { generated = RAST.Expr.create_Continue(Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"))); readIdents = Dafny.Set>.FromElements(); + newEnv = env; } } } - if (unmatched55) { - if (_source55.is_Call) { - DAST._IExpression _1279_on = _source55.dtor_on; - DAST._ICallName _1280_name = _source55.dtor_callName; - Dafny.ISequence _1281_typeArgs = _source55.dtor_typeArgs; - Dafny.ISequence _1282_args = _source55.dtor_args; - Std.Wrappers._IOption>> _1283_maybeOutVars = _source55.dtor_outs; - unmatched55 = false; + if (unmatched58) { + if (_source58.is_Call) { + DAST._IExpression _1401_on = _source58.dtor_on; + DAST._ICallName _1402_name = _source58.dtor_callName; + Dafny.ISequence _1403_typeArgs = _source58.dtor_typeArgs; + Dafny.ISequence _1404_args = _source58.dtor_args; + Std.Wrappers._IOption>> _1405_maybeOutVars = _source58.dtor_outs; + unmatched58 = false; { readIdents = Dafny.Set>.FromElements(); - Dafny.ISequence _1284_typeArgString; - _1284_typeArgString = Dafny.Sequence.UnicodeFromString(""); - if ((new BigInteger((_1281_typeArgs).Count)) >= (BigInteger.One)) { - BigInteger _1285_typeI; - _1285_typeI = BigInteger.Zero; - Dafny.ISequence _1286_typeArgsR; - _1286_typeArgsR = Dafny.Sequence.FromElements(); - while ((_1285_typeI) < (new BigInteger((_1281_typeArgs).Count))) { - RAST._IType _1287_tpe; - RAST._IType _out125; - _out125 = (this).GenType((_1281_typeArgs).Select(_1285_typeI), false, false); - _1287_tpe = _out125; - _1286_typeArgsR = Dafny.Sequence.Concat(_1286_typeArgsR, Dafny.Sequence.FromElements(_1287_tpe)); - _1285_typeI = (_1285_typeI) + (BigInteger.One); - } - _1284_typeArgString = (RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("::")), _1286_typeArgsR))._ToString(DCOMP.__default.IND); - } - Dafny.ISequence _1288_argString; - _1288_argString = Dafny.Sequence.UnicodeFromString(""); - BigInteger _1289_i; - _1289_i = BigInteger.Zero; - while ((_1289_i) < (new BigInteger((_1282_args).Count))) { - if ((_1289_i).Sign == 1) { - _1288_argString = Dafny.Sequence.Concat(_1288_argString, Dafny.Sequence.UnicodeFromString(", ")); - } - RAST._IExpr _1290_argExpr; - DCOMP._IOwnership _1291_ownership; - Dafny.ISet> _1292_argIdents; - RAST._IExpr _out126; - DCOMP._IOwnership _out127; - Dafny.ISet> _out128; - (this).GenExpr((_1282_args).Select(_1289_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out126, out _out127, out _out128); - _1290_argExpr = _out126; - _1291_ownership = _out127; - _1292_argIdents = _out128; - Dafny.ISequence _1293_argExprString; - _1293_argExprString = (_1290_argExpr)._ToString(DCOMP.__default.IND); - _1288_argString = Dafny.Sequence.Concat(_1288_argString, _1293_argExprString); - readIdents = Dafny.Set>.Union(readIdents, _1292_argIdents); - _1289_i = (_1289_i) + (BigInteger.One); - } - RAST._IExpr _1294_onExpr; - DCOMP._IOwnership _1295___v49; - Dafny.ISet> _1296_enclosingIdents; - RAST._IExpr _out129; - DCOMP._IOwnership _out130; - Dafny.ISet> _out131; - (this).GenExpr(_1279_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out129, out _out130, out _out131); - _1294_onExpr = _out129; - _1295___v49 = _out130; - _1296_enclosingIdents = _out131; - readIdents = Dafny.Set>.Union(readIdents, _1296_enclosingIdents); - Dafny.ISequence _1297_enclosingString; - _1297_enclosingString = (_1294_onExpr)._ToString(DCOMP.__default.IND); - DAST._IExpression _source57 = _1279_on; - bool unmatched57 = true; - if (unmatched57) { - if (_source57.is_Companion) { - Dafny.ISequence> _1298___v50 = _source57.dtor_Companion_a0; - unmatched57 = false; - { - _1297_enclosingString = Dafny.Sequence.Concat(_1297_enclosingString, Dafny.Sequence.UnicodeFromString("::")); - } - } - } - if (unmatched57) { - DAST._IExpression _1299___v51 = _source57; - unmatched57 = false; - { - _1297_enclosingString = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _1297_enclosingString), Dafny.Sequence.UnicodeFromString(").")); + RAST._IExpr _1406_onExpr; + DCOMP._IOwnership _1407___v67; + Dafny.ISet> _1408_enclosingIdents; + RAST._IExpr _out152; + DCOMP._IOwnership _out153; + Dafny.ISet> _out154; + (this).GenExpr(_1401_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out152, out _out153, out _out154); + _1406_onExpr = _out152; + _1407___v67 = _out153; + _1408_enclosingIdents = _out154; + Dafny.ISequence _1409_typeArgsR; + _1409_typeArgsR = Dafny.Sequence.FromElements(); + if ((new BigInteger((_1403_typeArgs).Count)) >= (BigInteger.One)) { + BigInteger _1410_typeI; + _1410_typeI = BigInteger.Zero; + while ((_1410_typeI) < (new BigInteger((_1403_typeArgs).Count))) { + RAST._IType _1411_tpe; + RAST._IType _out155; + _out155 = (this).GenType((_1403_typeArgs).Select(_1410_typeI), false, false); + _1411_tpe = _out155; + _1409_typeArgsR = Dafny.Sequence.Concat(_1409_typeArgsR, Dafny.Sequence.FromElements(_1411_tpe)); + _1410_typeI = (_1410_typeI) + (BigInteger.One); } } - Dafny.ISequence _1300_receiver; - _1300_receiver = Dafny.Sequence.UnicodeFromString(""); - Std.Wrappers._IOption>> _source58 = _1283_maybeOutVars; - bool unmatched58 = true; - if (unmatched58) { - if (_source58.is_Some) { - Dafny.ISequence> _1301_outVars = _source58.dtor_value; - unmatched58 = false; - { - if ((new BigInteger((_1301_outVars).Count)) > (BigInteger.One)) { - _1300_receiver = Dafny.Sequence.UnicodeFromString("("); - } - BigInteger _1302_outI; - _1302_outI = BigInteger.Zero; - while ((_1302_outI) < (new BigInteger((_1301_outVars).Count))) { - if ((_1302_outI).Sign == 1) { - _1300_receiver = Dafny.Sequence.Concat(_1300_receiver, Dafny.Sequence.UnicodeFromString(", ")); - } - Dafny.ISequence _1303_outVar; - _1303_outVar = (_1301_outVars).Select(_1302_outI); - _1300_receiver = Dafny.Sequence.Concat(_1300_receiver, (_1303_outVar)); - _1302_outI = (_1302_outI) + (BigInteger.One); - } - if ((new BigInteger((_1301_outVars).Count)) > (BigInteger.One)) { - _1300_receiver = Dafny.Sequence.Concat(_1300_receiver, Dafny.Sequence.UnicodeFromString(")")); - } + Dafny.ISequence _1412_argExprs; + _1412_argExprs = Dafny.Sequence.FromElements(); + BigInteger _hi28 = new BigInteger((_1404_args).Count); + for (BigInteger _1413_i = BigInteger.Zero; _1413_i < _hi28; _1413_i++) { + DCOMP._IOwnership _1414_argOwnership; + _1414_argOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); + if (((_1402_name).is_CallName) && ((_1413_i) < (new BigInteger((((_1402_name).dtor_signature)).Count)))) { + RAST._IType _1415_tpe; + RAST._IType _out156; + _out156 = (this).GenType(((((_1402_name).dtor_signature)).Select(_1413_i)).dtor_typ, false, false); + _1415_tpe = _out156; + if ((_1415_tpe).CanReadWithoutClone()) { + _1414_argOwnership = DCOMP.Ownership.create_OwnershipOwned(); } } + RAST._IExpr _1416_argExpr; + DCOMP._IOwnership _1417_ownership; + Dafny.ISet> _1418_argIdents; + RAST._IExpr _out157; + DCOMP._IOwnership _out158; + Dafny.ISet> _out159; + (this).GenExpr((_1404_args).Select(_1413_i), selfIdent, env, _1414_argOwnership, out _out157, out _out158, out _out159); + _1416_argExpr = _out157; + _1417_ownership = _out158; + _1418_argIdents = _out159; + _1412_argExprs = Dafny.Sequence.Concat(_1412_argExprs, Dafny.Sequence.FromElements(_1416_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _1418_argIdents); } - if (unmatched58) { - unmatched58 = false; - } - Dafny.ISequence _1304_renderedName; - _1304_renderedName = ((System.Func>)(() => { - DAST._ICallName _source59 = _1280_name; - bool unmatched59 = true; - if (unmatched59) { - if (_source59.is_Name) { - Dafny.ISequence _1305_name = _source59.dtor_name; - unmatched59 = false; - return DCOMP.__default.escapeIdent(_1305_name); + readIdents = Dafny.Set>.Union(readIdents, _1408_enclosingIdents); + Dafny.ISequence _1419_renderedName; + _1419_renderedName = ((System.Func>)(() => { + DAST._ICallName _source60 = _1402_name; + bool unmatched60 = true; + if (unmatched60) { + if (_source60.is_CallName) { + Dafny.ISequence _1420_name = _source60.dtor_name; + Std.Wrappers._IOption _1421___v68 = _source60.dtor_onType; + Dafny.ISequence _1422___v69 = _source60.dtor_signature; + unmatched60 = false; + return DCOMP.__default.escapeName(_1420_name); } } - if (unmatched59) { + if (unmatched60) { bool disjunctiveMatch9 = false; - if (_source59.is_MapBuilderAdd) { + if (_source60.is_MapBuilderAdd) { disjunctiveMatch9 = true; } - if (_source59.is_SetBuilderAdd) { + if (_source60.is_SetBuilderAdd) { disjunctiveMatch9 = true; } if (disjunctiveMatch9) { - unmatched59 = false; + unmatched60 = false; return Dafny.Sequence.UnicodeFromString("add"); } } - if (unmatched59) { + if (unmatched60) { bool disjunctiveMatch10 = false; disjunctiveMatch10 = true; disjunctiveMatch10 = true; if (disjunctiveMatch10) { - unmatched59 = false; + unmatched60 = false; return Dafny.Sequence.UnicodeFromString("build"); } } throw new System.Exception("unexpected control point"); }))(); - generated = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(((!(_1300_receiver).Equals(Dafny.Sequence.UnicodeFromString(""))) ? (Dafny.Sequence.Concat(_1300_receiver, Dafny.Sequence.UnicodeFromString(" = "))) : (Dafny.Sequence.UnicodeFromString(""))), _1297_enclosingString), _1304_renderedName), _1284_typeArgString), Dafny.Sequence.UnicodeFromString("(")), _1288_argString), Dafny.Sequence.UnicodeFromString(");"))); + DAST._IExpression _source61 = _1401_on; + bool unmatched61 = true; + if (unmatched61) { + if (_source61.is_Companion) { + Dafny.ISequence> _1423___v70 = _source61.dtor_Companion_a0; + unmatched61 = false; + { + _1406_onExpr = (_1406_onExpr).MSel(_1419_renderedName); + } + } + } + if (unmatched61) { + DAST._IExpression _1424___v71 = _source61; + unmatched61 = false; + { + _1406_onExpr = (_1406_onExpr).Sel(_1419_renderedName); + } + } + generated = _1406_onExpr; + if ((new BigInteger((_1409_typeArgsR).Count)).Sign == 1) { + generated = (generated).ApplyType(_1409_typeArgsR); + } + generated = (generated).Apply(_1412_argExprs); + if (((_1405_maybeOutVars).is_Some) && ((new BigInteger(((_1405_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { + Dafny.ISequence _1425_outVar; + _1425_outVar = DCOMP.__default.escapeName((((_1405_maybeOutVars).dtor_value).Select(BigInteger.Zero))); + generated = RAST.__default.AssignVar(_1425_outVar, generated); + } else if (((_1405_maybeOutVars).is_None) || ((new BigInteger(((_1405_maybeOutVars).dtor_value).Count)).Sign == 0)) { + } else { + Dafny.ISequence _1426_tmpVar; + _1426_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); + RAST._IExpr _1427_tmpId; + _1427_tmpId = RAST.Expr.create_Identifier(_1426_tmpVar); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _1426_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); + Dafny.ISequence> _1428_outVars; + _1428_outVars = (_1405_maybeOutVars).dtor_value; + BigInteger _hi29 = new BigInteger((_1428_outVars).Count); + for (BigInteger _1429_outI = BigInteger.Zero; _1429_outI < _hi29; _1429_outI++) { + Dafny.ISequence _1430_outVar; + _1430_outVar = DCOMP.__default.escapeName(((_1428_outVars).Select(_1429_outI))); + RAST._IExpr _1431_rhs; + _1431_rhs = (_1427_tmpId).Sel(Std.Strings.__default.OfNat(_1429_outI)); + generated = (generated).Then(RAST.__default.AssignVar(_1430_outVar, _1431_rhs)); + } + } + newEnv = env; } } } - if (unmatched55) { - if (_source55.is_Return) { - DAST._IExpression _1306_expr = _source55.dtor_expr; - unmatched55 = false; + if (unmatched58) { + if (_source58.is_Return) { + DAST._IExpression _1432_exprDafny = _source58.dtor_expr; + unmatched58 = false; { - RAST._IExpr _1307_expr; - DCOMP._IOwnership _1308___v52; - Dafny.ISet> _1309_recIdents; - RAST._IExpr _out132; - DCOMP._IOwnership _out133; - Dafny.ISet> _out134; - (this).GenExpr(_1306_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); - _1307_expr = _out132; - _1308___v52 = _out133; - _1309_recIdents = _out134; - readIdents = _1309_recIdents; + RAST._IExpr _1433_expr; + DCOMP._IOwnership _1434___v72; + Dafny.ISet> _1435_recIdents; + RAST._IExpr _out160; + DCOMP._IOwnership _out161; + Dafny.ISet> _out162; + (this).GenExpr(_1432_exprDafny, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out160, out _out161, out _out162); + _1433_expr = _out160; + _1434___v72 = _out161; + _1435_recIdents = _out162; + readIdents = _1435_recIdents; if (isLast) { - generated = _1307_expr; + generated = _1433_expr; } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_1307_expr)); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_1433_expr)); } + newEnv = env; } } } - if (unmatched55) { - if (_source55.is_EarlyReturn) { - unmatched55 = false; + if (unmatched58) { + if (_source58.is_EarlyReturn) { + unmatched58 = false; { generated = earlyReturn; readIdents = Dafny.Set>.FromElements(); + newEnv = env; } } } - if (unmatched55) { - if (_source55.is_Halt) { - unmatched55 = false; + if (unmatched58) { + if (_source58.is_Halt) { + unmatched58 = false; { - generated = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("panic!(\"Halt\");")); + generated = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply1(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("Halt"), false, false)); readIdents = Dafny.Set>.FromElements(); + newEnv = env; } } } - if (unmatched55) { - DAST._IExpression _1310_e = _source55.dtor_Print_a0; - unmatched55 = false; + if (unmatched58) { + DAST._IExpression _1436_e = _source58.dtor_Print_a0; + unmatched58 = false; { - RAST._IExpr _1311_printedExpr; - DCOMP._IOwnership _1312_recOwnership; - Dafny.ISet> _1313_recIdents; - RAST._IExpr _out135; - DCOMP._IOwnership _out136; - Dafny.ISet> _out137; - (this).GenExpr(_1310_e, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out135, out _out136, out _out137); - _1311_printedExpr = _out135; - _1312_recOwnership = _out136; - _1313_recIdents = _out137; - Dafny.ISequence _1314_printedExprString; - _1314_printedExprString = (_1311_printedExpr)._ToString(DCOMP.__default.IND); - generated = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("print!(\"{}\", ::dafny_runtime::DafnyPrintWrapper("), _1314_printedExprString), Dafny.Sequence.UnicodeFromString("));"))); - readIdents = _1313_recIdents; + RAST._IExpr _1437_printedExpr; + DCOMP._IOwnership _1438_recOwnership; + Dafny.ISet> _1439_recIdents; + RAST._IExpr _out163; + DCOMP._IOwnership _out164; + Dafny.ISet> _out165; + (this).GenExpr(_1436_e, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out163, out _out164, out _out165); + _1437_printedExpr = _out163; + _1438_recOwnership = _out164; + _1439_recIdents = _out165; + 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(_1437_printedExpr))); + readIdents = _1439_recIdents; + newEnv = env; } } } public static Std.Wrappers._IOption NewtypeToRustType(DAST._IType @base, DAST._INewtypeRange range) { - DAST._INewtypeRange _source60 = range; - bool unmatched60 = true; - if (unmatched60) { - if (_source60.is_NoRange) { - unmatched60 = false; + DAST._INewtypeRange _source62 = range; + bool unmatched62 = true; + if (unmatched62) { + if (_source62.is_NoRange) { + unmatched62 = false; return Std.Wrappers.Option.create_None(); } } - if (unmatched60) { - if (_source60.is_U8) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_U8) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_U8()); } } - if (unmatched60) { - if (_source60.is_U16) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_U16) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_U16()); } } - if (unmatched60) { - if (_source60.is_U32) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_U32) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_U32()); } } - if (unmatched60) { - if (_source60.is_U64) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_U64) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_U64()); } } - if (unmatched60) { - if (_source60.is_U128) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_U128) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_U128()); } } - if (unmatched60) { - if (_source60.is_I8) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_I8) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_I8()); } } - if (unmatched60) { - if (_source60.is_I16) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_I16) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_I16()); } } - if (unmatched60) { - if (_source60.is_I32) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_I32) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_I32()); } } - if (unmatched60) { - if (_source60.is_I64) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_I64) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_I64()); } } - if (unmatched60) { - if (_source60.is_I128) { - unmatched60 = false; + if (unmatched62) { + if (_source62.is_I128) { + unmatched62 = false; return Std.Wrappers.Option.create_Some(RAST.Type.create_I128()); } } - if (unmatched60) { - DAST._INewtypeRange _1315___v53 = _source60; - unmatched60 = false; + if (unmatched62) { + DAST._INewtypeRange _1440___v73 = _source62; + unmatched62 = false; return Std.Wrappers.Option.create_None(); } throw new System.Exception("unexpected control point"); @@ -2037,7 +2392,10 @@ public static void FromOwned(RAST._IExpr r, DCOMP._IOwnership expectedOwnership, { @out = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); - if ((object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwned())) || (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipAutoBorrowed()))) { + if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwnedBox())) { + @out = RAST.__default.BoxNew(r); + resultingOwnership = DCOMP.Ownership.create_OwnershipOwnedBox(); + } else if ((object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwned())) || (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipAutoBorrowed()))) { @out = r; resultingOwnership = DCOMP.Ownership.create_OwnershipOwned(); } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipBorrowed())) { @@ -2052,17 +2410,31 @@ public static void FromOwnership(RAST._IExpr r, DCOMP._IOwnership ownership, DCO { @out = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); + if (object.Equals(ownership, expectedOwnership)) { + @out = r; + resultingOwnership = expectedOwnership; + return ; + } if (object.Equals(ownership, DCOMP.Ownership.create_OwnershipOwned())) { - RAST._IExpr _out138; - DCOMP._IOwnership _out139; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out138, out _out139); - @out = _out138; - resultingOwnership = _out139; + RAST._IExpr _out166; + DCOMP._IOwnership _out167; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out166, out _out167); + @out = _out166; + resultingOwnership = _out167; return ; + } else if (object.Equals(ownership, DCOMP.Ownership.create_OwnershipOwnedBox())) { + RAST._IExpr _out168; + DCOMP._IOwnership _out169; + DCOMP.COMP.FromOwned(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("*"), r, DAST.Format.UnaryOpFormat.create_NoFormat()), expectedOwnership, out _out168, out _out169); + @out = _out168; + resultingOwnership = _out169; } else if ((object.Equals(ownership, DCOMP.Ownership.create_OwnershipBorrowed())) || (object.Equals(ownership, DCOMP.Ownership.create_OwnershipBorrowedMut()))) { if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwned())) { resultingOwnership = DCOMP.Ownership.create_OwnershipOwned(); @out = RAST.__default.Clone(r); + } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwnedBox())) { + resultingOwnership = DCOMP.Ownership.create_OwnershipOwnedBox(); + @out = RAST.__default.BoxNew(RAST.__default.Clone(r)); } else if ((object.Equals(expectedOwnership, ownership)) || (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipAutoBorrowed()))) { resultingOwnership = ownership; @out = r; @@ -2080,1832 +2452,1970 @@ public static bool OwnershipGuarantee(DCOMP._IOwnership expectedOwnership, DCOMP { return (!(!object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipAutoBorrowed())) || (object.Equals(resultingOwnership, expectedOwnership))) && (!object.Equals(resultingOwnership, DCOMP.Ownership.create_OwnershipAutoBorrowed())); } - public void GenExprLiteral(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenExprLiteral(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); readIdents = Dafny.Set>.Empty; - DAST._IExpression _source61 = e; - bool unmatched61 = true; - if (unmatched61) { - if (_source61.is_Literal) { - DAST._ILiteral _h150 = _source61.dtor_Literal_a0; - if (_h150.is_BoolLiteral) { - bool _h200 = _h150.dtor_BoolLiteral_a0; - if ((_h200) == (false)) { - unmatched61 = false; - { - RAST._IExpr _out140; - DCOMP._IOwnership _out141; - DCOMP.COMP.FromOwned(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("false")), expectedOwnership, out _out140, out _out141); - r = _out140; - resultingOwnership = _out141; - readIdents = Dafny.Set>.FromElements(); - return ; - } - } - } - } - } - if (unmatched61) { - if (_source61.is_Literal) { - DAST._ILiteral _h151 = _source61.dtor_Literal_a0; - if (_h151.is_BoolLiteral) { - bool _h201 = _h151.dtor_BoolLiteral_a0; - if ((_h201) == (true)) { - unmatched61 = false; - { - RAST._IExpr _out142; - DCOMP._IOwnership _out143; - DCOMP.COMP.FromOwned(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("true")), expectedOwnership, out _out142, out _out143); - r = _out142; - resultingOwnership = _out143; - readIdents = Dafny.Set>.FromElements(); - return ; - } + DAST._IExpression _source63 = e; + bool unmatched63 = true; + if (unmatched63) { + if (_source63.is_Literal) { + DAST._ILiteral _h140 = _source63.dtor_Literal_a0; + if (_h140.is_BoolLiteral) { + bool _1441_b = _h140.dtor_BoolLiteral_a0; + unmatched63 = false; + { + RAST._IExpr _out170; + DCOMP._IOwnership _out171; + DCOMP.COMP.FromOwned(RAST.Expr.create_LiteralBool(_1441_b), expectedOwnership, out _out170, out _out171); + r = _out170; + resultingOwnership = _out171; + readIdents = Dafny.Set>.FromElements(); + return ; } } } } - if (unmatched61) { - if (_source61.is_Literal) { - DAST._ILiteral _h152 = _source61.dtor_Literal_a0; - if (_h152.is_IntLiteral) { - Dafny.ISequence _1316_i = _h152.dtor_IntLiteral_a0; - DAST._IType _1317_t = _h152.dtor_IntLiteral_a1; - unmatched61 = false; + if (unmatched63) { + if (_source63.is_Literal) { + DAST._ILiteral _h141 = _source63.dtor_Literal_a0; + if (_h141.is_IntLiteral) { + Dafny.ISequence _1442_i = _h141.dtor_IntLiteral_a0; + DAST._IType _1443_t = _h141.dtor_IntLiteral_a1; + unmatched63 = false; { - DAST._IType _source62 = _1317_t; - bool unmatched62 = true; - if (unmatched62) { - if (_source62.is_Primitive) { - DAST._IPrimitive _h80 = _source62.dtor_Primitive_a0; + DAST._IType _source64 = _1443_t; + bool unmatched64 = true; + if (unmatched64) { + if (_source64.is_Primitive) { + DAST._IPrimitive _h80 = _source64.dtor_Primitive_a0; if (_h80.is_Int) { - unmatched62 = false; + unmatched64 = false; { - if ((new BigInteger((_1316_i).Count)) <= (new BigInteger(4))) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt"))).MSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(RAST.Expr.create_LiteralInt(_1316_i)); + if ((new BigInteger((_1442_i).Count)) <= (new BigInteger(4))) { + r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).Apply1(RAST.Expr.create_LiteralInt(_1442_i)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt"))).MSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(RAST.Expr.create_LiteralString(_1316_i, true)); + r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).Apply1(RAST.Expr.create_LiteralString(_1442_i, true, false)); } } } } } - if (unmatched62) { - DAST._IType _1318_o = _source62; - unmatched62 = false; + if (unmatched64) { + DAST._IType _1444_o = _source64; + unmatched64 = false; { - RAST._IType _1319_genType; - RAST._IType _out144; - _out144 = (this).GenType(_1318_o, false, false); - _1319_genType = _out144; - r = RAST.Expr.create_TypeAscription(RAST.Expr.create_RawExpr(_1316_i), _1319_genType); + RAST._IType _1445_genType; + RAST._IType _out172; + _out172 = (this).GenType(_1444_o, false, false); + _1445_genType = _out172; + r = RAST.Expr.create_TypeAscription(RAST.Expr.create_RawExpr(_1442_i), _1445_genType); } } - RAST._IExpr _out145; - DCOMP._IOwnership _out146; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out145, out _out146); - r = _out145; - resultingOwnership = _out146; + RAST._IExpr _out173; + DCOMP._IOwnership _out174; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out173, out _out174); + r = _out173; + resultingOwnership = _out174; readIdents = Dafny.Set>.FromElements(); return ; } } } } - if (unmatched61) { - if (_source61.is_Literal) { - DAST._ILiteral _h153 = _source61.dtor_Literal_a0; - if (_h153.is_DecLiteral) { - Dafny.ISequence _1320_n = _h153.dtor_DecLiteral_a0; - Dafny.ISequence _1321_d = _h153.dtor_DecLiteral_a1; - DAST._IType _1322_t = _h153.dtor_DecLiteral_a2; - unmatched61 = false; + if (unmatched63) { + if (_source63.is_Literal) { + DAST._ILiteral _h142 = _source63.dtor_Literal_a0; + if (_h142.is_DecLiteral) { + Dafny.ISequence _1446_n = _h142.dtor_DecLiteral_a0; + Dafny.ISequence _1447_d = _h142.dtor_DecLiteral_a1; + DAST._IType _1448_t = _h142.dtor_DecLiteral_a2; + unmatched63 = false; { - DAST._IType _source63 = _1322_t; - bool unmatched63 = true; - if (unmatched63) { - if (_source63.is_Primitive) { - DAST._IPrimitive _h81 = _source63.dtor_Primitive_a0; + DAST._IType _source65 = _1448_t; + bool unmatched65 = true; + if (unmatched65) { + if (_source65.is_Primitive) { + DAST._IPrimitive _h81 = _source65.dtor_Primitive_a0; if (_h81.is_Real) { - unmatched63 = false; + unmatched65 = false; { - r = RAST.__default.RcNew(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::BigRational::new(::dafny_runtime::BigInt::parse_bytes(b\""), _1320_n), Dafny.Sequence.UnicodeFromString("\", 10).unwrap(), ::dafny_runtime::BigInt::parse_bytes(b\"")), _1321_d), Dafny.Sequence.UnicodeFromString("\", 10).unwrap())")))); + r = RAST.__default.RcNew(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::BigRational::new(::dafny_runtime::BigInt::parse_bytes(b\""), _1446_n), Dafny.Sequence.UnicodeFromString("\", 10).unwrap(), ::dafny_runtime::BigInt::parse_bytes(b\"")), _1447_d), Dafny.Sequence.UnicodeFromString("\", 10).unwrap())")))); } } } } - if (unmatched63) { - DAST._IType _1323_o = _source63; - unmatched63 = false; + if (unmatched65) { + DAST._IType _1449_o = _source65; + unmatched65 = false; { - RAST._IType _1324_genType; - RAST._IType _out147; - _out147 = (this).GenType(_1323_o, false, false); - _1324_genType = _out147; - r = RAST.Expr.create_TypeAscription(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _1320_n), Dafny.Sequence.UnicodeFromString(".0 / ")), _1321_d), Dafny.Sequence.UnicodeFromString(".0")), Dafny.Sequence.UnicodeFromString(")"))), _1324_genType); + RAST._IType _1450_genType; + RAST._IType _out175; + _out175 = (this).GenType(_1449_o, false, false); + _1450_genType = _out175; + r = RAST.Expr.create_TypeAscription(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _1446_n), Dafny.Sequence.UnicodeFromString(".0 / ")), _1447_d), Dafny.Sequence.UnicodeFromString(".0")), Dafny.Sequence.UnicodeFromString(")"))), _1450_genType); } } - RAST._IExpr _out148; - DCOMP._IOwnership _out149; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out148, out _out149); - r = _out148; - resultingOwnership = _out149; + RAST._IExpr _out176; + DCOMP._IOwnership _out177; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out176, out _out177); + r = _out176; + resultingOwnership = _out177; + readIdents = Dafny.Set>.FromElements(); + return ; + } + } + } + } + if (unmatched63) { + if (_source63.is_Literal) { + DAST._ILiteral _h143 = _source63.dtor_Literal_a0; + if (_h143.is_StringLiteral) { + Dafny.ISequence _1451_l = _h143.dtor_StringLiteral_a0; + bool _1452_verbatim = _h143.dtor_verbatim; + unmatched63 = false; + { + if (_1452_verbatim) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("Verbatim strings prefixed by @ not supported yet.")); + } + r = ((RAST.__default.dafny__runtime).MSel((this).string__of)).Apply1(RAST.Expr.create_LiteralString(_1451_l, false, _1452_verbatim)); + RAST._IExpr _out178; + DCOMP._IOwnership _out179; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out178, out _out179); + r = _out178; + resultingOwnership = _out179; readIdents = Dafny.Set>.FromElements(); return ; } } } } - if (unmatched61) { - if (_source61.is_Literal) { - DAST._ILiteral _h154 = _source61.dtor_Literal_a0; - if (_h154.is_StringLiteral) { - Dafny.ISequence _1325_l = _h154.dtor_StringLiteral_a0; - unmatched61 = false; + if (unmatched63) { + if (_source63.is_Literal) { + DAST._ILiteral _h144 = _source63.dtor_Literal_a0; + if (_h144.is_CharLiteralUTF16) { + BigInteger _1453_c = _h144.dtor_CharLiteralUTF16_a0; + unmatched63 = false; { - r = ((RAST.__default.dafny__runtime).MSel((this).string__of)).Apply1(RAST.Expr.create_LiteralString(_1325_l, false)); - RAST._IExpr _out150; - DCOMP._IOwnership _out151; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out150, out _out151); - r = _out150; - resultingOwnership = _out151; + r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(_1453_c)); + r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); + r = ((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).Apply1(r); + RAST._IExpr _out180; + DCOMP._IOwnership _out181; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out180, out _out181); + r = _out180; + resultingOwnership = _out181; readIdents = Dafny.Set>.FromElements(); return ; } } } } - if (unmatched61) { - if (_source61.is_Literal) { - DAST._ILiteral _h155 = _source61.dtor_Literal_a0; - if (_h155.is_CharLiteral) { - Dafny.Rune _1326_c = _h155.dtor_CharLiteral_a0; - unmatched61 = false; + if (unmatched63) { + if (_source63.is_Literal) { + DAST._ILiteral _h145 = _source63.dtor_Literal_a0; + if (_h145.is_CharLiteral) { + Dafny.Rune _1454_c = _h145.dtor_CharLiteral_a0; + unmatched63 = false; { - r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(new BigInteger((_1326_c).Value))); + r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(new BigInteger((_1454_c).Value))); 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(), Dafny.Sequence.FromElements()); + 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.dafny__runtime).MSel((this).DafnyChar)).Apply1(r); - RAST._IExpr _out152; - DCOMP._IOwnership _out153; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out152, out _out153); - r = _out152; - resultingOwnership = _out153; + RAST._IExpr _out182; + DCOMP._IOwnership _out183; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out182, out _out183); + r = _out182; + resultingOwnership = _out183; readIdents = Dafny.Set>.FromElements(); return ; } } } } - if (unmatched61) { - DAST._ILiteral _h156 = _source61.dtor_Literal_a0; - DAST._IType _1327_tpe = _h156.dtor_Null_a0; - unmatched61 = false; + if (unmatched63) { + DAST._ILiteral _h146 = _source63.dtor_Literal_a0; + DAST._IType _1455_tpe = _h146.dtor_Null_a0; + unmatched63 = false; { - RAST._IType _1328_tpeGen; - RAST._IType _out154; - _out154 = (this).GenType(_1327_tpe, false, false); - _1328_tpeGen = _out154; - r = RAST.Expr.create_TypeAscription(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("None")), _1328_tpeGen); - RAST._IExpr _out155; - DCOMP._IOwnership _out156; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out155, out _out156); - r = _out155; - resultingOwnership = _out156; + RAST._IType _1456_tpeGen; + RAST._IType _out184; + _out184 = (this).GenType(_1455_tpe, false, false); + _1456_tpeGen = _out184; + r = RAST.Expr.create_TypeAscription(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("None")), _1456_tpeGen); + RAST._IExpr _out185; + DCOMP._IOwnership _out186; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out185, out _out186); + r = _out185; + resultingOwnership = _out186; readIdents = Dafny.Set>.FromElements(); return ; } } } - public void GenExprBinary(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenExprBinary(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs49 = e; - DAST._IBinOp _1329_op = _let_tmp_rhs49.dtor_op; - DAST._IExpression _1330_lExpr = _let_tmp_rhs49.dtor_left; - DAST._IExpression _1331_rExpr = _let_tmp_rhs49.dtor_right; - DAST.Format._IBinaryOpFormat _1332_format = _let_tmp_rhs49.dtor_format2; - bool _1333_becomesLeftCallsRight; - _1333_becomesLeftCallsRight = ((System.Func)(() => { - DAST._IBinOp _source64 = _1329_op; - bool unmatched64 = true; - if (unmatched64) { + DAST._IExpression _let_tmp_rhs52 = e; + DAST._IBinOp _1457_op = _let_tmp_rhs52.dtor_op; + DAST._IExpression _1458_lExpr = _let_tmp_rhs52.dtor_left; + DAST._IExpression _1459_rExpr = _let_tmp_rhs52.dtor_right; + DAST.Format._IBinaryOpFormat _1460_format = _let_tmp_rhs52.dtor_format2; + bool _1461_becomesLeftCallsRight; + _1461_becomesLeftCallsRight = ((System.Func)(() => { + DAST._IBinOp _source66 = _1457_op; + bool unmatched66 = true; + if (unmatched66) { bool disjunctiveMatch11 = false; - if (_source64.is_SetMerge) { + if (_source66.is_SetMerge) { disjunctiveMatch11 = true; } - if (_source64.is_SetSubtraction) { + if (_source66.is_SetSubtraction) { disjunctiveMatch11 = true; } - if (_source64.is_SetIntersection) { + if (_source66.is_SetIntersection) { disjunctiveMatch11 = true; } - if (_source64.is_SetDisjoint) { + if (_source66.is_SetDisjoint) { disjunctiveMatch11 = true; } - if (_source64.is_MapMerge) { + if (_source66.is_MapMerge) { disjunctiveMatch11 = true; } - if (_source64.is_MapSubtraction) { + if (_source66.is_MapSubtraction) { disjunctiveMatch11 = true; } - if (_source64.is_MultisetMerge) { + if (_source66.is_MultisetMerge) { disjunctiveMatch11 = true; } - if (_source64.is_MultisetSubtraction) { + if (_source66.is_MultisetSubtraction) { disjunctiveMatch11 = true; } - if (_source64.is_MultisetIntersection) { + if (_source66.is_MultisetIntersection) { disjunctiveMatch11 = true; } - if (_source64.is_MultisetDisjoint) { + if (_source66.is_MultisetDisjoint) { disjunctiveMatch11 = true; } - if (_source64.is_Concat) { + if (_source66.is_Concat) { disjunctiveMatch11 = true; } if (disjunctiveMatch11) { - unmatched64 = false; + unmatched66 = false; return true; } } - if (unmatched64) { - DAST._IBinOp _1334___v54 = _source64; - unmatched64 = false; + if (unmatched66) { + DAST._IBinOp _1462___v74 = _source66; + unmatched66 = false; return false; } throw new System.Exception("unexpected control point"); }))(); - bool _1335_becomesRightCallsLeft; - _1335_becomesRightCallsLeft = ((System.Func)(() => { - DAST._IBinOp _source65 = _1329_op; - bool unmatched65 = true; - if (unmatched65) { - if (_source65.is_In) { - unmatched65 = false; + bool _1463_becomesRightCallsLeft; + _1463_becomesRightCallsLeft = ((System.Func)(() => { + DAST._IBinOp _source67 = _1457_op; + bool unmatched67 = true; + if (unmatched67) { + if (_source67.is_In) { + unmatched67 = false; return true; } } - if (unmatched65) { - DAST._IBinOp _1336___v55 = _source65; - unmatched65 = false; + if (unmatched67) { + DAST._IBinOp _1464___v75 = _source67; + unmatched67 = false; return false; } throw new System.Exception("unexpected control point"); }))(); - bool _1337_becomesCallLeftRight; - _1337_becomesCallLeftRight = ((System.Func)(() => { - DAST._IBinOp _source66 = _1329_op; - bool unmatched66 = true; - if (unmatched66) { - if (_source66.is_Eq) { - bool referential0 = _source66.dtor_referential; + bool _1465_becomesCallLeftRight; + _1465_becomesCallLeftRight = ((System.Func)(() => { + DAST._IBinOp _source68 = _1457_op; + bool unmatched68 = true; + if (unmatched68) { + if (_source68.is_Eq) { + bool referential0 = _source68.dtor_referential; if ((referential0) == (true)) { - bool nullable0 = _source66.dtor_nullable; + bool nullable0 = _source68.dtor_nullable; if ((nullable0) == (false)) { - unmatched66 = false; + unmatched68 = false; return true; } } } } - if (unmatched66) { - DAST._IBinOp _1338___v56 = _source66; - unmatched66 = false; - return false; + if (unmatched68) { + if (_source68.is_SetMerge) { + unmatched68 = false; + return true; + } } - throw new System.Exception("unexpected control point"); - }))(); - DCOMP._IOwnership _1339_expectedLeftOwnership; - _1339_expectedLeftOwnership = ((_1333_becomesLeftCallsRight) ? (DCOMP.Ownership.create_OwnershipAutoBorrowed()) : ((((_1335_becomesRightCallsLeft) || (_1337_becomesCallLeftRight)) ? (DCOMP.Ownership.create_OwnershipBorrowed()) : (DCOMP.Ownership.create_OwnershipOwned())))); - DCOMP._IOwnership _1340_expectedRightOwnership; - _1340_expectedRightOwnership = (((_1333_becomesLeftCallsRight) || (_1337_becomesCallLeftRight)) ? (DCOMP.Ownership.create_OwnershipBorrowed()) : (((_1335_becomesRightCallsLeft) ? (DCOMP.Ownership.create_OwnershipAutoBorrowed()) : (DCOMP.Ownership.create_OwnershipOwned())))); - RAST._IExpr _1341_left; - DCOMP._IOwnership _1342___v57; - Dafny.ISet> _1343_recIdentsL; - RAST._IExpr _out157; - DCOMP._IOwnership _out158; - Dafny.ISet> _out159; - (this).GenExpr(_1330_lExpr, selfIdent, @params, _1339_expectedLeftOwnership, out _out157, out _out158, out _out159); - _1341_left = _out157; - _1342___v57 = _out158; - _1343_recIdentsL = _out159; - RAST._IExpr _1344_right; - DCOMP._IOwnership _1345___v58; - Dafny.ISet> _1346_recIdentsR; - RAST._IExpr _out160; - DCOMP._IOwnership _out161; - Dafny.ISet> _out162; - (this).GenExpr(_1331_rExpr, selfIdent, @params, _1340_expectedRightOwnership, out _out160, out _out161, out _out162); - _1344_right = _out160; - _1345___v58 = _out161; - _1346_recIdentsR = _out162; - DAST._IBinOp _source67 = _1329_op; - bool unmatched67 = true; - if (unmatched67) { - if (_source67.is_In) { - unmatched67 = false; - { - r = ((_1344_right).Sel(Dafny.Sequence.UnicodeFromString("contains"))).Apply1(_1341_left); + if (unmatched68) { + if (_source68.is_SetSubtraction) { + unmatched68 = false; + return true; } } - } - if (unmatched67) { - if (_source67.is_SeqProperPrefix) { - unmatched67 = false; - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _1341_left, _1344_right, _1332_format); + if (unmatched68) { + if (_source68.is_SetIntersection) { + unmatched68 = false; + return true; + } } - } - if (unmatched67) { - if (_source67.is_SeqPrefix) { - unmatched67 = false; - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1341_left, _1344_right, _1332_format); + if (unmatched68) { + if (_source68.is_SetDisjoint) { + unmatched68 = false; + return true; + } } - } - if (unmatched67) { - if (_source67.is_SetMerge) { - unmatched67 = false; - { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_1344_right); + if (unmatched68) { + if (_source68.is_MapMerge) { + unmatched68 = false; + return true; } } - } - if (unmatched67) { - if (_source67.is_SetSubtraction) { - unmatched67 = false; - { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_1344_right); + if (unmatched68) { + if (_source68.is_MapSubtraction) { + unmatched68 = false; + return true; } } - } - if (unmatched67) { - if (_source67.is_SetIntersection) { - unmatched67 = false; - { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("intersect"))).Apply1(_1344_right); + if (unmatched68) { + if (_source68.is_MultisetMerge) { + unmatched68 = false; + return true; } } - } - if (unmatched67) { - if (_source67.is_Subset) { - unmatched67 = false; - { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1341_left, _1344_right, _1332_format); + if (unmatched68) { + if (_source68.is_MultisetSubtraction) { + unmatched68 = false; + return true; } } - } - if (unmatched67) { - if (_source67.is_ProperSubset) { - unmatched67 = false; + if (unmatched68) { + if (_source68.is_MultisetIntersection) { + unmatched68 = false; + return true; + } + } + if (unmatched68) { + if (_source68.is_MultisetDisjoint) { + unmatched68 = false; + return true; + } + } + if (unmatched68) { + if (_source68.is_Concat) { + unmatched68 = false; + return true; + } + } + if (unmatched68) { + DAST._IBinOp _1466___v76 = _source68; + unmatched68 = false; + return false; + } + throw new System.Exception("unexpected control point"); + }))(); + DCOMP._IOwnership _1467_expectedLeftOwnership; + _1467_expectedLeftOwnership = ((_1461_becomesLeftCallsRight) ? (DCOMP.Ownership.create_OwnershipAutoBorrowed()) : ((((_1463_becomesRightCallsLeft) || (_1465_becomesCallLeftRight)) ? (DCOMP.Ownership.create_OwnershipBorrowed()) : (DCOMP.Ownership.create_OwnershipOwned())))); + DCOMP._IOwnership _1468_expectedRightOwnership; + _1468_expectedRightOwnership = (((_1461_becomesLeftCallsRight) || (_1465_becomesCallLeftRight)) ? (DCOMP.Ownership.create_OwnershipBorrowed()) : (((_1463_becomesRightCallsLeft) ? (DCOMP.Ownership.create_OwnershipAutoBorrowed()) : (DCOMP.Ownership.create_OwnershipOwned())))); + RAST._IExpr _1469_left; + DCOMP._IOwnership _1470___v77; + Dafny.ISet> _1471_recIdentsL; + RAST._IExpr _out187; + DCOMP._IOwnership _out188; + Dafny.ISet> _out189; + (this).GenExpr(_1458_lExpr, selfIdent, env, _1467_expectedLeftOwnership, out _out187, out _out188, out _out189); + _1469_left = _out187; + _1470___v77 = _out188; + _1471_recIdentsL = _out189; + RAST._IExpr _1472_right; + DCOMP._IOwnership _1473___v78; + Dafny.ISet> _1474_recIdentsR; + RAST._IExpr _out190; + DCOMP._IOwnership _out191; + Dafny.ISet> _out192; + (this).GenExpr(_1459_rExpr, selfIdent, env, _1468_expectedRightOwnership, out _out190, out _out191, out _out192); + _1472_right = _out190; + _1473___v78 = _out191; + _1474_recIdentsR = _out192; + DAST._IBinOp _source69 = _1457_op; + bool unmatched69 = true; + if (unmatched69) { + if (_source69.is_In) { + unmatched69 = false; { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _1341_left, _1344_right, _1332_format); + r = ((_1472_right).Sel(Dafny.Sequence.UnicodeFromString("contains"))).Apply1(_1469_left); } } } - if (unmatched67) { - if (_source67.is_SetDisjoint) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_SeqProperPrefix) { + unmatched69 = false; + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _1469_left, _1472_right, _1460_format); + } + } + if (unmatched69) { + if (_source69.is_SeqPrefix) { + unmatched69 = false; + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1469_left, _1472_right, _1460_format); + } + } + if (unmatched69) { + if (_source69.is_SetMerge) { + unmatched69 = false; { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("disjoint"))).Apply1(_1344_right); + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_1472_right); } } } - if (unmatched67) { - if (_source67.is_MapMerge) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_SetSubtraction) { + unmatched69 = false; { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_1344_right); + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_1472_right); } } } - if (unmatched67) { - if (_source67.is_MapSubtraction) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_SetIntersection) { + unmatched69 = false; { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_1344_right); + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("intersect"))).Apply1(_1472_right); } } } - if (unmatched67) { - if (_source67.is_MultisetMerge) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_Subset) { + unmatched69 = false; { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_1344_right); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1469_left, _1472_right, _1460_format); } } } - if (unmatched67) { - if (_source67.is_MultisetSubtraction) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_ProperSubset) { + unmatched69 = false; { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_1344_right); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _1469_left, _1472_right, _1460_format); } } } - if (unmatched67) { - if (_source67.is_MultisetIntersection) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_SetDisjoint) { + unmatched69 = false; { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("intersect"))).Apply1(_1344_right); + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("disjoint"))).Apply1(_1472_right); } } } - if (unmatched67) { - if (_source67.is_Submultiset) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_MapMerge) { + unmatched69 = false; { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1341_left, _1344_right, _1332_format); + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_1472_right); } } } - if (unmatched67) { - if (_source67.is_ProperSubmultiset) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_MapSubtraction) { + unmatched69 = false; { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _1341_left, _1344_right, _1332_format); + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_1472_right); } } } - if (unmatched67) { - if (_source67.is_MultisetDisjoint) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_MultisetMerge) { + unmatched69 = false; { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("disjoint"))).Apply1(_1344_right); + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("merge"))).Apply1(_1472_right); } } } - if (unmatched67) { - if (_source67.is_Concat) { - unmatched67 = false; + if (unmatched69) { + if (_source69.is_MultisetSubtraction) { + unmatched69 = false; + { + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("subtract"))).Apply1(_1472_right); + } + } + } + if (unmatched69) { + if (_source69.is_MultisetIntersection) { + unmatched69 = false; + { + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("intersect"))).Apply1(_1472_right); + } + } + } + if (unmatched69) { + if (_source69.is_Submultiset) { + unmatched69 = false; { - r = ((_1341_left).Sel(Dafny.Sequence.UnicodeFromString("concat"))).Apply1(_1344_right); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _1469_left, _1472_right, _1460_format); } } } - if (unmatched67) { - DAST._IBinOp _1347___v59 = _source67; - unmatched67 = false; + if (unmatched69) { + if (_source69.is_ProperSubmultiset) { + unmatched69 = false; + { + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<"), _1469_left, _1472_right, _1460_format); + } + } + } + if (unmatched69) { + if (_source69.is_MultisetDisjoint) { + unmatched69 = false; + { + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("disjoint"))).Apply1(_1472_right); + } + } + } + if (unmatched69) { + if (_source69.is_Concat) { + unmatched69 = false; + { + r = ((_1469_left).Sel(Dafny.Sequence.UnicodeFromString("concat"))).Apply1(_1472_right); + } + } + } + if (unmatched69) { + DAST._IBinOp _1475___v79 = _source69; + unmatched69 = false; { - if ((DCOMP.COMP.OpTable).Contains(_1329_op)) { - r = RAST.Expr.create_BinaryOp(Dafny.Map>.Select(DCOMP.COMP.OpTable,_1329_op), _1341_left, _1344_right, _1332_format); + if ((DCOMP.COMP.OpTable).Contains(_1457_op)) { + r = RAST.Expr.create_BinaryOp(Dafny.Map>.Select(DCOMP.COMP.OpTable,_1457_op), _1469_left, _1472_right, _1460_format); } else { - DAST._IBinOp _source68 = _1329_op; - bool unmatched68 = true; - if (unmatched68) { - if (_source68.is_Eq) { - bool _1348_referential = _source68.dtor_referential; - bool _1349_nullable = _source68.dtor_nullable; - unmatched68 = false; + DAST._IBinOp _source70 = _1457_op; + bool unmatched70 = true; + if (unmatched70) { + if (_source70.is_Eq) { + bool _1476_referential = _source70.dtor_referential; + bool _1477_nullable = _source70.dtor_nullable; + unmatched70 = false; { - if (_1348_referential) { - if (_1349_nullable) { - r = RAST.Expr.create_Call(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::dafny_runtime::nullable_referential_equality")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(_1341_left, _1344_right)); + if (_1476_referential) { + if (_1477_nullable) { + r = (RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::dafny_runtime::nullable_referential_equality"))).Apply(Dafny.Sequence.FromElements(_1469_left, _1472_right)); } else { - r = RAST.Expr.create_Call(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::rc::Rc::ptr_eq")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(_1341_left, _1344_right)); + r = (RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::std::rc::Rc::ptr_eq"))).Apply(Dafny.Sequence.FromElements(_1469_left, _1472_right)); } } else { - r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _1341_left, _1344_right, DAST.Format.BinaryOpFormat.create_NoFormat()); + r = RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), _1469_left, _1472_right, DAST.Format.BinaryOpFormat.create_NoFormat()); } } } } - if (unmatched68) { - if (_source68.is_EuclidianDiv) { - unmatched68 = false; + if (unmatched70) { + if (_source70.is_EuclidianDiv) { + unmatched70 = false; { - r = RAST.Expr.create_Call(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::dafny_runtime::euclidian_division")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(_1341_left, _1344_right)); + r = (RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::dafny_runtime::euclidian_division"))).Apply(Dafny.Sequence.FromElements(_1469_left, _1472_right)); } } } - if (unmatched68) { - if (_source68.is_EuclidianMod) { - unmatched68 = false; + if (unmatched70) { + if (_source70.is_EuclidianMod) { + unmatched70 = false; { - r = RAST.Expr.create_Call(RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::dafny_runtime::euclidian_modulo")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(_1341_left, _1344_right)); + r = (RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::dafny_runtime::euclidian_modulo"))).Apply(Dafny.Sequence.FromElements(_1469_left, _1472_right)); } } } - if (unmatched68) { - Dafny.ISequence _1350_op = _source68.dtor_Passthrough_a0; - unmatched68 = false; + if (unmatched70) { + Dafny.ISequence _1478_op = _source70.dtor_Passthrough_a0; + unmatched70 = false; { - r = RAST.Expr.create_BinaryOp(_1350_op, _1341_left, _1344_right, _1332_format); + r = RAST.Expr.create_BinaryOp(_1478_op, _1469_left, _1472_right, _1460_format); } } } } } - RAST._IExpr _out163; - DCOMP._IOwnership _out164; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out163, out _out164); - r = _out163; - resultingOwnership = _out164; - readIdents = Dafny.Set>.Union(_1343_recIdentsL, _1346_recIdentsR); + RAST._IExpr _out193; + DCOMP._IOwnership _out194; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out193, out _out194); + r = _out193; + resultingOwnership = _out194; + readIdents = Dafny.Set>.Union(_1471_recIdentsL, _1474_recIdentsR); return ; } - public void GenExprConvertFromNullable(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenExprConvertFromNullable(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs50 = e; - DAST._IExpression _1351_expr = _let_tmp_rhs50.dtor_value; - DAST._IType _1352_fromTpe = _let_tmp_rhs50.dtor_from; - DAST._IType _1353_toTpe = _let_tmp_rhs50.dtor_typ; - RAST._IExpr _1354_recursiveGen; - DCOMP._IOwnership _1355_recOwned; - Dafny.ISet> _1356_recIdents; - RAST._IExpr _out165; - DCOMP._IOwnership _out166; - Dafny.ISet> _out167; - (this).GenExpr(_1351_expr, selfIdent, @params, expectedOwnership, out _out165, out _out166, out _out167); - _1354_recursiveGen = _out165; - _1355_recOwned = _out166; - _1356_recIdents = _out167; - r = _1354_recursiveGen; - if (object.Equals(_1355_recOwned, DCOMP.Ownership.create_OwnershipOwned())) { - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply(Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); - } - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply(Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); - RAST._IExpr _out168; - DCOMP._IOwnership _out169; - DCOMP.COMP.FromOwnership(r, _1355_recOwned, expectedOwnership, out _out168, out _out169); - r = _out168; - resultingOwnership = _out169; - readIdents = _1356_recIdents; + DAST._IExpression _let_tmp_rhs53 = e; + DAST._IExpression _1479_expr = _let_tmp_rhs53.dtor_value; + DAST._IType _1480_fromTpe = _let_tmp_rhs53.dtor_from; + DAST._IType _1481_toTpe = _let_tmp_rhs53.dtor_typ; + RAST._IExpr _1482_recursiveGen; + DCOMP._IOwnership _1483_recOwned; + Dafny.ISet> _1484_recIdents; + RAST._IExpr _out195; + DCOMP._IOwnership _out196; + Dafny.ISet> _out197; + (this).GenExpr(_1479_expr, selfIdent, env, expectedOwnership, out _out195, out _out196, out _out197); + _1482_recursiveGen = _out195; + _1483_recOwned = _out196; + _1484_recIdents = _out197; + r = _1482_recursiveGen; + if (object.Equals(_1483_recOwned, DCOMP.Ownership.create_OwnershipOwned())) { + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply(Dafny.Sequence.FromElements()); + } + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out198; + DCOMP._IOwnership _out199; + DCOMP.COMP.FromOwnership(r, _1483_recOwned, expectedOwnership, out _out198, out _out199); + r = _out198; + resultingOwnership = _out199; + readIdents = _1484_recIdents; } - public void GenExprConvertToNullable(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenExprConvertToNullable(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs51 = e; - DAST._IExpression _1357_expr = _let_tmp_rhs51.dtor_value; - DAST._IType _1358_fromTpe = _let_tmp_rhs51.dtor_from; - DAST._IType _1359_toTpe = _let_tmp_rhs51.dtor_typ; - RAST._IExpr _1360_recursiveGen; - DCOMP._IOwnership _1361_recOwned; - Dafny.ISet> _1362_recIdents; - RAST._IExpr _out170; - DCOMP._IOwnership _out171; - Dafny.ISet> _out172; - (this).GenExpr(_1357_expr, selfIdent, @params, expectedOwnership, out _out170, out _out171, out _out172); - _1360_recursiveGen = _out170; - _1361_recOwned = _out171; - _1362_recIdents = _out172; - r = _1360_recursiveGen; - if (object.Equals(_1361_recOwned, DCOMP.Ownership.create_OwnershipOwned())) { - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply(Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); - } - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("option"))).MSel(Dafny.Sequence.UnicodeFromString("Option"))).MSel(Dafny.Sequence.UnicodeFromString("Some"))).Apply(Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(r)); - RAST._IExpr _out173; - DCOMP._IOwnership _out174; - DCOMP.COMP.FromOwnership(r, _1361_recOwned, expectedOwnership, out _out173, out _out174); - r = _out173; - resultingOwnership = _out174; - readIdents = _1362_recIdents; + DAST._IExpression _let_tmp_rhs54 = e; + DAST._IExpression _1485_expr = _let_tmp_rhs54.dtor_value; + DAST._IType _1486_fromTpe = _let_tmp_rhs54.dtor_from; + DAST._IType _1487_toTpe = _let_tmp_rhs54.dtor_typ; + RAST._IExpr _1488_recursiveGen; + DCOMP._IOwnership _1489_recOwned; + Dafny.ISet> _1490_recIdents; + RAST._IExpr _out200; + DCOMP._IOwnership _out201; + Dafny.ISet> _out202; + (this).GenExpr(_1485_expr, selfIdent, env, expectedOwnership, out _out200, out _out201, out _out202); + _1488_recursiveGen = _out200; + _1489_recOwned = _out201; + _1490_recIdents = _out202; + r = _1488_recursiveGen; + if (object.Equals(_1489_recOwned, DCOMP.Ownership.create_OwnershipOwned())) { + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply(Dafny.Sequence.FromElements()); + } + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("option"))).MSel(Dafny.Sequence.UnicodeFromString("Option"))).MSel(Dafny.Sequence.UnicodeFromString("Some"))).Apply(Dafny.Sequence.FromElements(r)); + RAST._IExpr _out203; + DCOMP._IOwnership _out204; + DCOMP.COMP.FromOwnership(r, _1489_recOwned, expectedOwnership, out _out203, out _out204); + r = _out203; + resultingOwnership = _out204; + readIdents = _1490_recIdents; } - public void GenExprConvertToNewtype(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenExprConvertToNewtype(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs52 = e; - DAST._IExpression _1363_expr = _let_tmp_rhs52.dtor_value; - DAST._IType _1364_fromTpe = _let_tmp_rhs52.dtor_from; - DAST._IType _1365_toTpe = _let_tmp_rhs52.dtor_typ; - DAST._IType _let_tmp_rhs53 = _1365_toTpe; - Dafny.ISequence> _1366___v60 = _let_tmp_rhs53.dtor_Path_a0; - Dafny.ISequence _1367___v61 = _let_tmp_rhs53.dtor_typeArgs; - DAST._IResolvedType _let_tmp_rhs54 = _let_tmp_rhs53.dtor_resolved; - DAST._IType _1368_b = _let_tmp_rhs54.dtor_baseType; - DAST._INewtypeRange _1369_range = _let_tmp_rhs54.dtor_range; - bool _1370_erase = _let_tmp_rhs54.dtor_erase; - if (object.Equals(_1364_fromTpe, _1368_b)) { - RAST._IExpr _1371_recursiveGen; - DCOMP._IOwnership _1372_recOwned; - Dafny.ISet> _1373_recIdents; - RAST._IExpr _out175; - DCOMP._IOwnership _out176; - Dafny.ISet> _out177; - (this).GenExpr(_1363_expr, selfIdent, @params, expectedOwnership, out _out175, out _out176, out _out177); - _1371_recursiveGen = _out175; - _1372_recOwned = _out176; - _1373_recIdents = _out177; - Std.Wrappers._IOption _1374_potentialRhsType; - _1374_potentialRhsType = DCOMP.COMP.NewtypeToRustType(_1368_b, _1369_range); - Std.Wrappers._IOption _source69 = _1374_potentialRhsType; - bool unmatched69 = true; - if (unmatched69) { - if (_source69.is_Some) { - RAST._IType _1375_v = _source69.dtor_value; - unmatched69 = false; - r = RAST.Expr.create_ConversionNum(_1375_v, _1371_recursiveGen); - RAST._IExpr _out178; - DCOMP._IOwnership _out179; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out178, out _out179); - r = _out178; - resultingOwnership = _out179; - } - } - if (unmatched69) { - unmatched69 = false; - if (_1370_erase) { - r = _1371_recursiveGen; + DAST._IExpression _let_tmp_rhs55 = e; + DAST._IExpression _1491_expr = _let_tmp_rhs55.dtor_value; + DAST._IType _1492_fromTpe = _let_tmp_rhs55.dtor_from; + DAST._IType _1493_toTpe = _let_tmp_rhs55.dtor_typ; + DAST._IType _let_tmp_rhs56 = _1493_toTpe; + Dafny.ISequence> _1494___v80 = _let_tmp_rhs56.dtor_Path_a0; + Dafny.ISequence _1495___v81 = _let_tmp_rhs56.dtor_typeArgs; + DAST._IResolvedType _let_tmp_rhs57 = _let_tmp_rhs56.dtor_resolved; + DAST._IType _1496_b = _let_tmp_rhs57.dtor_baseType; + DAST._INewtypeRange _1497_range = _let_tmp_rhs57.dtor_range; + bool _1498_erase = _let_tmp_rhs57.dtor_erase; + Dafny.ISequence _1499_attributes = _let_tmp_rhs57.dtor_attributes; + Std.Wrappers._IOption _1500_nativeToType; + _1500_nativeToType = DCOMP.COMP.NewtypeToRustType(_1496_b, _1497_range); + if (object.Equals(_1492_fromTpe, _1496_b)) { + RAST._IExpr _1501_recursiveGen; + DCOMP._IOwnership _1502_recOwned; + Dafny.ISet> _1503_recIdents; + RAST._IExpr _out205; + DCOMP._IOwnership _out206; + Dafny.ISet> _out207; + (this).GenExpr(_1491_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out205, out _out206, out _out207); + _1501_recursiveGen = _out205; + _1502_recOwned = _out206; + _1503_recIdents = _out207; + readIdents = _1503_recIdents; + Std.Wrappers._IOption _source71 = _1500_nativeToType; + bool unmatched71 = true; + if (unmatched71) { + if (_source71.is_Some) { + RAST._IType _1504_v = _source71.dtor_value; + unmatched71 = false; + r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("truncate!"))).Apply(Dafny.Sequence.FromElements(_1501_recursiveGen, RAST.Expr.create_ExprFromType(_1504_v))); + RAST._IExpr _out208; + DCOMP._IOwnership _out209; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out208, out _out209); + r = _out208; + resultingOwnership = _out209; + } + } + if (unmatched71) { + unmatched71 = false; + if (_1498_erase) { + r = _1501_recursiveGen; } else { - RAST._IType _1376_rhsType; - RAST._IType _out180; - _out180 = (this).GenType(_1365_toTpe, true, false); - _1376_rhsType = _out180; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_1376_rhsType)._ToString(DCOMP.__default.IND), Dafny.Sequence.UnicodeFromString("(")), (_1371_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); - } - RAST._IExpr _out181; - DCOMP._IOwnership _out182; - DCOMP.COMP.FromOwnership(r, _1372_recOwned, expectedOwnership, out _out181, out _out182); - r = _out181; - resultingOwnership = _out182; - } - readIdents = _1373_recIdents; + RAST._IType _1505_rhsType; + RAST._IType _out210; + _out210 = (this).GenType(_1493_toTpe, true, false); + _1505_rhsType = _out210; + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_1505_rhsType)._ToString(DCOMP.__default.IND), Dafny.Sequence.UnicodeFromString("(")), (_1501_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); + } + RAST._IExpr _out211; + DCOMP._IOwnership _out212; + DCOMP.COMP.FromOwnership(r, _1502_recOwned, expectedOwnership, out _out211, out _out212); + r = _out211; + resultingOwnership = _out212; + } } else { - RAST._IExpr _out183; - DCOMP._IOwnership _out184; - Dafny.ISet> _out185; - (this).GenExpr(DAST.Expression.create_Convert(DAST.Expression.create_Convert(_1363_expr, _1364_fromTpe, _1368_b), _1368_b, _1365_toTpe), selfIdent, @params, expectedOwnership, out _out183, out _out184, out _out185); - r = _out183; - resultingOwnership = _out184; - readIdents = _out185; + RAST._IExpr _out213; + DCOMP._IOwnership _out214; + Dafny.ISet> _out215; + (this).GenExpr(DAST.Expression.create_Convert(DAST.Expression.create_Convert(_1491_expr, _1492_fromTpe, _1496_b), _1496_b, _1493_toTpe), selfIdent, env, expectedOwnership, out _out213, out _out214, out _out215); + r = _out213; + resultingOwnership = _out214; + readIdents = _out215; } } - public void GenExprConvertFromNewtype(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenExprConvertFromNewtype(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs55 = e; - DAST._IExpression _1377_expr = _let_tmp_rhs55.dtor_value; - DAST._IType _1378_fromTpe = _let_tmp_rhs55.dtor_from; - DAST._IType _1379_toTpe = _let_tmp_rhs55.dtor_typ; - DAST._IType _let_tmp_rhs56 = _1378_fromTpe; - Dafny.ISequence> _1380___v62 = _let_tmp_rhs56.dtor_Path_a0; - Dafny.ISequence _1381___v63 = _let_tmp_rhs56.dtor_typeArgs; - DAST._IResolvedType _let_tmp_rhs57 = _let_tmp_rhs56.dtor_resolved; - DAST._IType _1382_b = _let_tmp_rhs57.dtor_baseType; - DAST._INewtypeRange _1383_range = _let_tmp_rhs57.dtor_range; - bool _1384_erase = _let_tmp_rhs57.dtor_erase; - if (object.Equals(_1382_b, _1379_toTpe)) { - RAST._IExpr _1385_recursiveGen; - DCOMP._IOwnership _1386_recOwned; - Dafny.ISet> _1387_recIdents; - RAST._IExpr _out186; - DCOMP._IOwnership _out187; - Dafny.ISet> _out188; - (this).GenExpr(_1377_expr, selfIdent, @params, expectedOwnership, out _out186, out _out187, out _out188); - _1385_recursiveGen = _out186; - _1386_recOwned = _out187; - _1387_recIdents = _out188; - if (_1384_erase) { - r = _1385_recursiveGen; - } else { - r = (_1385_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("0")); - } - RAST._IExpr _out189; - DCOMP._IOwnership _out190; - DCOMP.COMP.FromOwnership(r, _1386_recOwned, expectedOwnership, out _out189, out _out190); - r = _out189; - resultingOwnership = _out190; - readIdents = _1387_recIdents; + DAST._IExpression _let_tmp_rhs58 = e; + DAST._IExpression _1506_expr = _let_tmp_rhs58.dtor_value; + DAST._IType _1507_fromTpe = _let_tmp_rhs58.dtor_from; + DAST._IType _1508_toTpe = _let_tmp_rhs58.dtor_typ; + DAST._IType _let_tmp_rhs59 = _1507_fromTpe; + Dafny.ISequence> _1509___v82 = _let_tmp_rhs59.dtor_Path_a0; + Dafny.ISequence _1510___v83 = _let_tmp_rhs59.dtor_typeArgs; + DAST._IResolvedType _let_tmp_rhs60 = _let_tmp_rhs59.dtor_resolved; + DAST._IType _1511_b = _let_tmp_rhs60.dtor_baseType; + DAST._INewtypeRange _1512_range = _let_tmp_rhs60.dtor_range; + bool _1513_erase = _let_tmp_rhs60.dtor_erase; + Dafny.ISequence _1514_attributes = _let_tmp_rhs60.dtor_attributes; + Std.Wrappers._IOption _1515_nativeFromType; + _1515_nativeFromType = DCOMP.COMP.NewtypeToRustType(_1511_b, _1512_range); + if (object.Equals(_1511_b, _1508_toTpe)) { + RAST._IExpr _1516_recursiveGen; + DCOMP._IOwnership _1517_recOwned; + Dafny.ISet> _1518_recIdents; + RAST._IExpr _out216; + DCOMP._IOwnership _out217; + Dafny.ISet> _out218; + (this).GenExpr(_1506_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out216, out _out217, out _out218); + _1516_recursiveGen = _out216; + _1517_recOwned = _out217; + _1518_recIdents = _out218; + readIdents = _1518_recIdents; + Std.Wrappers._IOption _source72 = _1515_nativeFromType; + bool unmatched72 = true; + if (unmatched72) { + if (_source72.is_Some) { + RAST._IType _1519_v = _source72.dtor_value; + unmatched72 = false; + RAST._IType _1520_toTpeRust; + RAST._IType _out219; + _out219 = (this).GenType(_1508_toTpe, false, false); + _1520_toTpeRust = _out219; + r = (((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Into"))).ApplyType(Dafny.Sequence.FromElements(_1520_toTpeRust))).MSel(Dafny.Sequence.UnicodeFromString("into"))).Apply(Dafny.Sequence.FromElements(_1516_recursiveGen)); + RAST._IExpr _out220; + DCOMP._IOwnership _out221; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out220, out _out221); + r = _out220; + resultingOwnership = _out221; + } + } + if (unmatched72) { + unmatched72 = false; + if (_1513_erase) { + r = _1516_recursiveGen; + } else { + r = (_1516_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("0")); + } + RAST._IExpr _out222; + DCOMP._IOwnership _out223; + DCOMP.COMP.FromOwnership(r, _1517_recOwned, expectedOwnership, out _out222, out _out223); + r = _out222; + resultingOwnership = _out223; + } } else { - RAST._IExpr _out191; - DCOMP._IOwnership _out192; - Dafny.ISet> _out193; - (this).GenExpr(DAST.Expression.create_Convert(DAST.Expression.create_Convert(_1377_expr, _1378_fromTpe, _1382_b), _1382_b, _1379_toTpe), selfIdent, @params, expectedOwnership, out _out191, out _out192, out _out193); - r = _out191; - resultingOwnership = _out192; - readIdents = _out193; + if ((_1515_nativeFromType).is_Some) { + if (object.Equals(_1508_toTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { + RAST._IExpr _1521_recursiveGen; + DCOMP._IOwnership _1522_recOwned; + Dafny.ISet> _1523_recIdents; + RAST._IExpr _out224; + DCOMP._IOwnership _out225; + Dafny.ISet> _out226; + (this).GenExpr(_1506_expr, selfIdent, env, expectedOwnership, out _out224, out _out225, out _out226); + _1521_recursiveGen = _out224; + _1522_recOwned = _out225; + _1523_recIdents = _out226; + RAST._IExpr _out227; + DCOMP._IOwnership _out228; + DCOMP.COMP.FromOwnership(((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).Apply1(RAST.Expr.create_TypeAscription(_1521_recursiveGen, (this).DafnyCharUnderlying)), _1522_recOwned, expectedOwnership, out _out227, out _out228); + r = _out227; + resultingOwnership = _out228; + readIdents = _1523_recIdents; + return ; + } + } + RAST._IExpr _out229; + DCOMP._IOwnership _out230; + Dafny.ISet> _out231; + (this).GenExpr(DAST.Expression.create_Convert(DAST.Expression.create_Convert(_1506_expr, _1507_fromTpe, _1511_b), _1511_b, _1508_toTpe), selfIdent, env, expectedOwnership, out _out229, out _out230, out _out231); + r = _out229; + resultingOwnership = _out230; + readIdents = _out231; } } - public void GenExprConvertNotImplemented(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenExprConvertNotImplemented(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs58 = e; - DAST._IExpression _1388_expr = _let_tmp_rhs58.dtor_value; - DAST._IType _1389_fromTpe = _let_tmp_rhs58.dtor_from; - DAST._IType _1390_toTpe = _let_tmp_rhs58.dtor_typ; - RAST._IExpr _1391_recursiveGen; - DCOMP._IOwnership _1392_recOwned; - Dafny.ISet> _1393_recIdents; - RAST._IExpr _out194; - DCOMP._IOwnership _out195; - Dafny.ISet> _out196; - (this).GenExpr(_1388_expr, selfIdent, @params, expectedOwnership, out _out194, out _out195, out _out196); - _1391_recursiveGen = _out194; - _1392_recOwned = _out195; - _1393_recIdents = _out196; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), (_1391_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString("/* conversion not yet implemented */)"))); - RAST._IExpr _out197; - DCOMP._IOwnership _out198; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out197, out _out198); - r = _out197; - resultingOwnership = _out198; - readIdents = _1393_recIdents; + DAST._IExpression _let_tmp_rhs61 = e; + DAST._IExpression _1524_expr = _let_tmp_rhs61.dtor_value; + DAST._IType _1525_fromTpe = _let_tmp_rhs61.dtor_from; + DAST._IType _1526_toTpe = _let_tmp_rhs61.dtor_typ; + RAST._IType _1527_fromTpeGen; + RAST._IType _out232; + _out232 = (this).GenType(_1525_fromTpe, true, false); + _1527_fromTpeGen = _out232; + RAST._IType _1528_toTpeGen; + RAST._IType _out233; + _out233 = (this).GenType(_1526_toTpe, true, false); + _1528_toTpeGen = _out233; + RAST._IExpr _1529_recursiveGen; + DCOMP._IOwnership _1530_recOwned; + Dafny.ISet> _1531_recIdents; + RAST._IExpr _out234; + DCOMP._IOwnership _out235; + Dafny.ISet> _out236; + (this).GenExpr(_1524_expr, selfIdent, env, expectedOwnership, out _out234, out _out235, out _out236); + _1529_recursiveGen = _out234; + _1530_recOwned = _out235; + _1531_recIdents = _out236; + Dafny.ISequence _1532_msg; + _1532_msg = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("/* Coercion from "), (_1527_fromTpeGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_1528_toTpeGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented */")); + (this).error = Std.Wrappers.Option>.create_Some(_1532_msg); + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat((_1529_recursiveGen)._ToString(DCOMP.__default.IND), _1532_msg)); + RAST._IExpr _out237; + DCOMP._IOwnership _out238; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out237, out _out238); + r = _out237; + resultingOwnership = _out238; + readIdents = _1531_recIdents; } - public void GenExprConvert(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenExprConvert(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); readIdents = Dafny.Set>.Empty; - DAST._IExpression _let_tmp_rhs59 = e; - DAST._IExpression _1394_expr = _let_tmp_rhs59.dtor_value; - DAST._IType _1395_fromTpe = _let_tmp_rhs59.dtor_from; - DAST._IType _1396_toTpe = _let_tmp_rhs59.dtor_typ; - if (object.Equals(_1395_fromTpe, _1396_toTpe)) { - RAST._IExpr _1397_recursiveGen; - DCOMP._IOwnership _1398_recOwned; - Dafny.ISet> _1399_recIdents; - RAST._IExpr _out199; - DCOMP._IOwnership _out200; - Dafny.ISet> _out201; - (this).GenExpr(_1394_expr, selfIdent, @params, expectedOwnership, out _out199, out _out200, out _out201); - _1397_recursiveGen = _out199; - _1398_recOwned = _out200; - _1399_recIdents = _out201; - r = _1397_recursiveGen; - RAST._IExpr _out202; - DCOMP._IOwnership _out203; - DCOMP.COMP.FromOwnership(r, _1398_recOwned, expectedOwnership, out _out202, out _out203); - r = _out202; - resultingOwnership = _out203; - readIdents = _1399_recIdents; + DAST._IExpression _let_tmp_rhs62 = e; + DAST._IExpression _1533_expr = _let_tmp_rhs62.dtor_value; + DAST._IType _1534_fromTpe = _let_tmp_rhs62.dtor_from; + DAST._IType _1535_toTpe = _let_tmp_rhs62.dtor_typ; + if (object.Equals(_1534_fromTpe, _1535_toTpe)) { + RAST._IExpr _1536_recursiveGen; + DCOMP._IOwnership _1537_recOwned; + Dafny.ISet> _1538_recIdents; + RAST._IExpr _out239; + DCOMP._IOwnership _out240; + Dafny.ISet> _out241; + (this).GenExpr(_1533_expr, selfIdent, env, expectedOwnership, out _out239, out _out240, out _out241); + _1536_recursiveGen = _out239; + _1537_recOwned = _out240; + _1538_recIdents = _out241; + r = _1536_recursiveGen; + RAST._IExpr _out242; + DCOMP._IOwnership _out243; + DCOMP.COMP.FromOwnership(r, _1537_recOwned, expectedOwnership, out _out242, out _out243); + r = _out242; + resultingOwnership = _out243; + readIdents = _1538_recIdents; } else { - _System._ITuple2 _source70 = _System.Tuple2.create(_1395_fromTpe, _1396_toTpe); - bool unmatched70 = true; - if (unmatched70) { - DAST._IType _00 = _source70.dtor__0; - if (_00.is_Nullable) { - DAST._IType _1400___v64 = _00.dtor_Nullable_a0; - DAST._IType _1401___v65 = _source70.dtor__1; - unmatched70 = false; + _System._ITuple2 _source73 = _System.Tuple2.create(_1534_fromTpe, _1535_toTpe); + bool unmatched73 = true; + if (unmatched73) { + DAST._IType _01 = _source73.dtor__0; + if (_01.is_Nullable) { + DAST._IType _1539___v84 = _01.dtor_Nullable_a0; + DAST._IType _1540___v85 = _source73.dtor__1; + unmatched73 = false; { - RAST._IExpr _out204; - DCOMP._IOwnership _out205; - Dafny.ISet> _out206; - (this).GenExprConvertFromNullable(e, selfIdent, @params, expectedOwnership, out _out204, out _out205, out _out206); - r = _out204; - resultingOwnership = _out205; - readIdents = _out206; + RAST._IExpr _out244; + DCOMP._IOwnership _out245; + Dafny.ISet> _out246; + (this).GenExprConvertFromNullable(e, selfIdent, env, expectedOwnership, out _out244, out _out245, out _out246); + r = _out244; + resultingOwnership = _out245; + readIdents = _out246; } } } - if (unmatched70) { - DAST._IType _1402___v66 = _source70.dtor__0; - DAST._IType _10 = _source70.dtor__1; - if (_10.is_Nullable) { - DAST._IType _1403___v67 = _10.dtor_Nullable_a0; - unmatched70 = false; + if (unmatched73) { + DAST._IType _1541___v86 = _source73.dtor__0; + DAST._IType _11 = _source73.dtor__1; + if (_11.is_Nullable) { + DAST._IType _1542___v87 = _11.dtor_Nullable_a0; + unmatched73 = false; { - RAST._IExpr _out207; - DCOMP._IOwnership _out208; - Dafny.ISet> _out209; - (this).GenExprConvertToNullable(e, selfIdent, @params, expectedOwnership, out _out207, out _out208, out _out209); - r = _out207; - resultingOwnership = _out208; - readIdents = _out209; + RAST._IExpr _out247; + DCOMP._IOwnership _out248; + Dafny.ISet> _out249; + (this).GenExprConvertToNullable(e, selfIdent, env, expectedOwnership, out _out247, out _out248, out _out249); + r = _out247; + resultingOwnership = _out248; + readIdents = _out249; } } } - if (unmatched70) { - DAST._IType _1404___v68 = _source70.dtor__0; - DAST._IType _11 = _source70.dtor__1; - if (_11.is_Path) { - Dafny.ISequence> _1405___v69 = _11.dtor_Path_a0; - Dafny.ISequence _1406___v70 = _11.dtor_typeArgs; - DAST._IResolvedType resolved1 = _11.dtor_resolved; + if (unmatched73) { + DAST._IType _1543___v88 = _source73.dtor__0; + DAST._IType _12 = _source73.dtor__1; + if (_12.is_Path) { + Dafny.ISequence> _1544___v89 = _12.dtor_Path_a0; + Dafny.ISequence _1545___v90 = _12.dtor_typeArgs; + DAST._IResolvedType resolved1 = _12.dtor_resolved; if (resolved1.is_Newtype) { - DAST._IType _1407_b = resolved1.dtor_baseType; - DAST._INewtypeRange _1408_range = resolved1.dtor_range; - bool _1409_erase = resolved1.dtor_erase; - unmatched70 = false; + DAST._IType _1546_b = resolved1.dtor_baseType; + DAST._INewtypeRange _1547_range = resolved1.dtor_range; + bool _1548_erase = resolved1.dtor_erase; + Dafny.ISequence _1549_attributes = resolved1.dtor_attributes; + unmatched73 = false; { - RAST._IExpr _out210; - DCOMP._IOwnership _out211; - Dafny.ISet> _out212; - (this).GenExprConvertToNewtype(e, selfIdent, @params, expectedOwnership, out _out210, out _out211, out _out212); - r = _out210; - resultingOwnership = _out211; - readIdents = _out212; + RAST._IExpr _out250; + DCOMP._IOwnership _out251; + Dafny.ISet> _out252; + (this).GenExprConvertToNewtype(e, selfIdent, env, expectedOwnership, out _out250, out _out251, out _out252); + r = _out250; + resultingOwnership = _out251; + readIdents = _out252; } } } } - if (unmatched70) { - DAST._IType _01 = _source70.dtor__0; - if (_01.is_Path) { - Dafny.ISequence> _1410___v71 = _01.dtor_Path_a0; - Dafny.ISequence _1411___v72 = _01.dtor_typeArgs; - DAST._IResolvedType resolved2 = _01.dtor_resolved; + if (unmatched73) { + DAST._IType _02 = _source73.dtor__0; + if (_02.is_Path) { + Dafny.ISequence> _1550___v91 = _02.dtor_Path_a0; + Dafny.ISequence _1551___v92 = _02.dtor_typeArgs; + DAST._IResolvedType resolved2 = _02.dtor_resolved; if (resolved2.is_Newtype) { - DAST._IType _1412_b = resolved2.dtor_baseType; - DAST._INewtypeRange _1413_range = resolved2.dtor_range; - bool _1414_erase = resolved2.dtor_erase; - DAST._IType _1415___v73 = _source70.dtor__1; - unmatched70 = false; + DAST._IType _1552_b = resolved2.dtor_baseType; + DAST._INewtypeRange _1553_range = resolved2.dtor_range; + bool _1554_erase = resolved2.dtor_erase; + Dafny.ISequence _1555_attributes = resolved2.dtor_attributes; + DAST._IType _1556___v93 = _source73.dtor__1; + unmatched73 = false; { - RAST._IExpr _out213; - DCOMP._IOwnership _out214; - Dafny.ISet> _out215; - (this).GenExprConvertFromNewtype(e, selfIdent, @params, expectedOwnership, out _out213, out _out214, out _out215); - r = _out213; - resultingOwnership = _out214; - readIdents = _out215; + RAST._IExpr _out253; + DCOMP._IOwnership _out254; + Dafny.ISet> _out255; + (this).GenExprConvertFromNewtype(e, selfIdent, env, expectedOwnership, out _out253, out _out254, out _out255); + r = _out253; + resultingOwnership = _out254; + readIdents = _out255; } } } } - if (unmatched70) { - DAST._IType _02 = _source70.dtor__0; - if (_02.is_Primitive) { - DAST._IPrimitive _h82 = _02.dtor_Primitive_a0; + if (unmatched73) { + DAST._IType _03 = _source73.dtor__0; + if (_03.is_Primitive) { + DAST._IPrimitive _h82 = _03.dtor_Primitive_a0; if (_h82.is_Int) { - DAST._IType _12 = _source70.dtor__1; - if (_12.is_Primitive) { - DAST._IPrimitive _h83 = _12.dtor_Primitive_a0; + DAST._IType _13 = _source73.dtor__1; + if (_13.is_Primitive) { + DAST._IPrimitive _h83 = _13.dtor_Primitive_a0; if (_h83.is_Real) { - unmatched70 = false; + unmatched73 = false; { - RAST._IExpr _1416_recursiveGen; - DCOMP._IOwnership _1417___v74; - Dafny.ISet> _1418_recIdents; - RAST._IExpr _out216; - DCOMP._IOwnership _out217; - Dafny.ISet> _out218; - (this).GenExpr(_1394_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out216, out _out217, out _out218); - _1416_recursiveGen = _out216; - _1417___v74 = _out217; - _1418_recIdents = _out218; - r = RAST.__default.RcNew(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::BigRational::from_integer("), (_1416_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")))); - RAST._IExpr _out219; - DCOMP._IOwnership _out220; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out219, out _out220); - r = _out219; - resultingOwnership = _out220; - readIdents = _1418_recIdents; + RAST._IExpr _1557_recursiveGen; + DCOMP._IOwnership _1558___v94; + Dafny.ISet> _1559_recIdents; + RAST._IExpr _out256; + DCOMP._IOwnership _out257; + Dafny.ISet> _out258; + (this).GenExpr(_1533_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out256, out _out257, out _out258); + _1557_recursiveGen = _out256; + _1558___v94 = _out257; + _1559_recIdents = _out258; + r = RAST.__default.RcNew(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::BigRational::from_integer("), (_1557_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")))); + RAST._IExpr _out259; + DCOMP._IOwnership _out260; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out259, out _out260); + r = _out259; + resultingOwnership = _out260; + readIdents = _1559_recIdents; } } } } } } - if (unmatched70) { - DAST._IType _03 = _source70.dtor__0; - if (_03.is_Primitive) { - DAST._IPrimitive _h84 = _03.dtor_Primitive_a0; + if (unmatched73) { + DAST._IType _04 = _source73.dtor__0; + if (_04.is_Primitive) { + DAST._IPrimitive _h84 = _04.dtor_Primitive_a0; if (_h84.is_Real) { - DAST._IType _13 = _source70.dtor__1; - if (_13.is_Primitive) { - DAST._IPrimitive _h85 = _13.dtor_Primitive_a0; + DAST._IType _14 = _source73.dtor__1; + if (_14.is_Primitive) { + DAST._IPrimitive _h85 = _14.dtor_Primitive_a0; if (_h85.is_Int) { - unmatched70 = false; + unmatched73 = false; { - RAST._IExpr _1419_recursiveGen; - DCOMP._IOwnership _1420___v75; - Dafny.ISet> _1421_recIdents; - RAST._IExpr _out221; - DCOMP._IOwnership _out222; - Dafny.ISet> _out223; - (this).GenExpr(_1394_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out221, out _out222, out _out223); - _1419_recursiveGen = _out221; - _1420___v75 = _out222; - _1421_recIdents = _out223; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::dafny_rational_to_int("), (_1419_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); - RAST._IExpr _out224; - DCOMP._IOwnership _out225; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out224, out _out225); - r = _out224; - resultingOwnership = _out225; - readIdents = _1421_recIdents; + RAST._IExpr _1560_recursiveGen; + DCOMP._IOwnership _1561___v95; + Dafny.ISet> _1562_recIdents; + RAST._IExpr _out261; + DCOMP._IOwnership _out262; + Dafny.ISet> _out263; + (this).GenExpr(_1533_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out261, out _out262, out _out263); + _1560_recursiveGen = _out261; + _1561___v95 = _out262; + _1562_recIdents = _out263; + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::dafny_rational_to_int("), (_1560_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); + RAST._IExpr _out264; + DCOMP._IOwnership _out265; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out264, out _out265); + r = _out264; + resultingOwnership = _out265; + readIdents = _1562_recIdents; } } } } } } - if (unmatched70) { - DAST._IType _04 = _source70.dtor__0; - if (_04.is_Primitive) { - DAST._IPrimitive _h86 = _04.dtor_Primitive_a0; + if (unmatched73) { + DAST._IType _05 = _source73.dtor__0; + if (_05.is_Primitive) { + DAST._IPrimitive _h86 = _05.dtor_Primitive_a0; if (_h86.is_Int) { - DAST._IType _14 = _source70.dtor__1; - if (_14.is_Passthrough) { - Dafny.ISequence _1422___v76 = _14.dtor_Passthrough_a0; - unmatched70 = false; + DAST._IType _15 = _source73.dtor__1; + if (_15.is_Passthrough) { + Dafny.ISequence _1563___v96 = _15.dtor_Passthrough_a0; + unmatched73 = false; { - RAST._IType _1423_rhsType; - RAST._IType _out226; - _out226 = (this).GenType(_1396_toTpe, true, false); - _1423_rhsType = _out226; - RAST._IExpr _1424_recursiveGen; - DCOMP._IOwnership _1425___v77; - Dafny.ISet> _1426_recIdents; - RAST._IExpr _out227; - DCOMP._IOwnership _out228; - Dafny.ISet> _out229; - (this).GenExpr(_1394_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out227, out _out228, out _out229); - _1424_recursiveGen = _out227; - _1425___v77 = _out228; - _1426_recIdents = _out229; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), (_1423_rhsType)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as ::dafny_runtime::NumCast>::from(")), (_1424_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap()"))); - RAST._IExpr _out230; - DCOMP._IOwnership _out231; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out230, out _out231); - r = _out230; - resultingOwnership = _out231; - readIdents = _1426_recIdents; + RAST._IType _1564_rhsType; + RAST._IType _out266; + _out266 = (this).GenType(_1535_toTpe, true, false); + _1564_rhsType = _out266; + RAST._IExpr _1565_recursiveGen; + DCOMP._IOwnership _1566___v97; + Dafny.ISet> _1567_recIdents; + RAST._IExpr _out267; + DCOMP._IOwnership _out268; + Dafny.ISet> _out269; + (this).GenExpr(_1533_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out267, out _out268, out _out269); + _1565_recursiveGen = _out267; + _1566___v97 = _out268; + _1567_recIdents = _out269; + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), (_1564_rhsType)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as ::dafny_runtime::NumCast>::from(")), (_1565_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap()"))); + RAST._IExpr _out270; + DCOMP._IOwnership _out271; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out270, out _out271); + r = _out270; + resultingOwnership = _out271; + readIdents = _1567_recIdents; } } } } } - if (unmatched70) { - DAST._IType _05 = _source70.dtor__0; - if (_05.is_Passthrough) { - Dafny.ISequence _1427___v78 = _05.dtor_Passthrough_a0; - DAST._IType _15 = _source70.dtor__1; - if (_15.is_Primitive) { - DAST._IPrimitive _h87 = _15.dtor_Primitive_a0; + if (unmatched73) { + DAST._IType _06 = _source73.dtor__0; + if (_06.is_Passthrough) { + Dafny.ISequence _1568___v98 = _06.dtor_Passthrough_a0; + DAST._IType _16 = _source73.dtor__1; + if (_16.is_Primitive) { + DAST._IPrimitive _h87 = _16.dtor_Primitive_a0; if (_h87.is_Int) { - unmatched70 = false; + unmatched73 = false; { - RAST._IType _1428_rhsType; - RAST._IType _out232; - _out232 = (this).GenType(_1395_fromTpe, true, false); - _1428_rhsType = _out232; - RAST._IExpr _1429_recursiveGen; - DCOMP._IOwnership _1430___v79; - Dafny.ISet> _1431_recIdents; - RAST._IExpr _out233; - DCOMP._IOwnership _out234; - Dafny.ISet> _out235; - (this).GenExpr(_1394_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out233, out _out234, out _out235); - _1429_recursiveGen = _out233; - _1430___v79 = _out234; - _1431_recIdents = _out235; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyInt{data: ::dafny_runtime::BigInt::from("), (_1429_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")}"))); - RAST._IExpr _out236; - DCOMP._IOwnership _out237; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out236, out _out237); - r = _out236; - resultingOwnership = _out237; - readIdents = _1431_recIdents; + RAST._IType _1569_rhsType; + RAST._IType _out272; + _out272 = (this).GenType(_1534_fromTpe, true, false); + _1569_rhsType = _out272; + RAST._IExpr _1570_recursiveGen; + DCOMP._IOwnership _1571___v99; + Dafny.ISet> _1572_recIdents; + RAST._IExpr _out273; + DCOMP._IOwnership _out274; + Dafny.ISet> _out275; + (this).GenExpr(_1533_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out273, out _out274, out _out275); + _1570_recursiveGen = _out273; + _1571___v99 = _out274; + _1572_recIdents = _out275; + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyInt{data: ::dafny_runtime::BigInt::from("), (_1570_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")}"))); + RAST._IExpr _out276; + DCOMP._IOwnership _out277; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out276, out _out277); + r = _out276; + resultingOwnership = _out277; + readIdents = _1572_recIdents; } } } } } - if (unmatched70) { - DAST._IType _06 = _source70.dtor__0; - if (_06.is_Primitive) { - DAST._IPrimitive _h88 = _06.dtor_Primitive_a0; + if (unmatched73) { + DAST._IType _07 = _source73.dtor__0; + if (_07.is_Primitive) { + DAST._IPrimitive _h88 = _07.dtor_Primitive_a0; if (_h88.is_Int) { - DAST._IType _16 = _source70.dtor__1; - if (_16.is_Primitive) { - DAST._IPrimitive _h89 = _16.dtor_Primitive_a0; + DAST._IType _17 = _source73.dtor__1; + if (_17.is_Primitive) { + DAST._IPrimitive _h89 = _17.dtor_Primitive_a0; if (_h89.is_Char) { - unmatched70 = false; + unmatched73 = false; { - RAST._IType _1432_rhsType; - RAST._IType _out238; - _out238 = (this).GenType(_1396_toTpe, true, false); - _1432_rhsType = _out238; - RAST._IExpr _1433_recursiveGen; - DCOMP._IOwnership _1434___v80; - Dafny.ISet> _1435_recIdents; - RAST._IExpr _out239; - DCOMP._IOwnership _out240; - Dafny.ISet> _out241; - (this).GenExpr(_1394_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out239, out _out240, out _out241); - _1433_recursiveGen = _out239; - _1434___v80 = _out240; - _1435_recIdents = _out241; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("char::from_u32(::from("), (_1433_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap()).unwrap()"))); - RAST._IExpr _out242; - DCOMP._IOwnership _out243; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out242, out _out243); - r = _out242; - resultingOwnership = _out243; - readIdents = _1435_recIdents; + RAST._IType _1573_rhsType; + RAST._IType _out278; + _out278 = (this).GenType(_1535_toTpe, true, false); + _1573_rhsType = _out278; + RAST._IExpr _1574_recursiveGen; + DCOMP._IOwnership _1575___v100; + Dafny.ISet> _1576_recIdents; + RAST._IExpr _out279; + DCOMP._IOwnership _out280; + Dafny.ISet> _out281; + (this).GenExpr(_1533_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out279, out _out280, out _out281); + _1574_recursiveGen = _out279; + _1575___v100 = _out280; + _1576_recIdents = _out281; + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("char::from_u32(::from("), (_1574_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap()).unwrap()"))); + RAST._IExpr _out282; + DCOMP._IOwnership _out283; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out282, out _out283); + r = _out282; + resultingOwnership = _out283; + readIdents = _1576_recIdents; } } } } } } - if (unmatched70) { - DAST._IType _07 = _source70.dtor__0; - if (_07.is_Primitive) { - DAST._IPrimitive _h810 = _07.dtor_Primitive_a0; + if (unmatched73) { + DAST._IType _08 = _source73.dtor__0; + if (_08.is_Primitive) { + DAST._IPrimitive _h810 = _08.dtor_Primitive_a0; if (_h810.is_Char) { - DAST._IType _17 = _source70.dtor__1; - if (_17.is_Primitive) { - DAST._IPrimitive _h811 = _17.dtor_Primitive_a0; + DAST._IType _18 = _source73.dtor__1; + if (_18.is_Primitive) { + DAST._IPrimitive _h811 = _18.dtor_Primitive_a0; if (_h811.is_Int) { - unmatched70 = false; + unmatched73 = false; { - RAST._IType _1436_rhsType; - RAST._IType _out244; - _out244 = (this).GenType(_1395_fromTpe, true, false); - _1436_rhsType = _out244; - RAST._IExpr _1437_recursiveGen; - DCOMP._IOwnership _1438___v81; - Dafny.ISet> _1439_recIdents; - RAST._IExpr _out245; - DCOMP._IOwnership _out246; - Dafny.ISet> _out247; - (this).GenExpr(_1394_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out245, out _out246, out _out247); - _1437_recursiveGen = _out245; - _1438___v81 = _out246; - _1439_recIdents = _out247; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyInt{data: ::BigInt::from("), (_1437_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as u32)}"))); - RAST._IExpr _out248; - DCOMP._IOwnership _out249; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out248, out _out249); - r = _out248; - resultingOwnership = _out249; - readIdents = _1439_recIdents; + RAST._IType _1577_rhsType; + RAST._IType _out284; + _out284 = (this).GenType(_1534_fromTpe, true, false); + _1577_rhsType = _out284; + RAST._IExpr _1578_recursiveGen; + DCOMP._IOwnership _1579___v101; + Dafny.ISet> _1580_recIdents; + RAST._IExpr _out285; + DCOMP._IOwnership _out286; + Dafny.ISet> _out287; + (this).GenExpr(_1533_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out285, out _out286, out _out287); + _1578_recursiveGen = _out285; + _1579___v101 = _out286; + _1580_recIdents = _out287; + r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).Apply1((_1578_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("0"))); + RAST._IExpr _out288; + DCOMP._IOwnership _out289; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out288, out _out289); + r = _out288; + resultingOwnership = _out289; + readIdents = _1580_recIdents; } } } } } } - if (unmatched70) { - DAST._IType _08 = _source70.dtor__0; - if (_08.is_Passthrough) { - Dafny.ISequence _1440___v82 = _08.dtor_Passthrough_a0; - DAST._IType _18 = _source70.dtor__1; - if (_18.is_Passthrough) { - Dafny.ISequence _1441___v83 = _18.dtor_Passthrough_a0; - unmatched70 = false; + if (unmatched73) { + DAST._IType _09 = _source73.dtor__0; + if (_09.is_Passthrough) { + Dafny.ISequence _1581___v102 = _09.dtor_Passthrough_a0; + DAST._IType _19 = _source73.dtor__1; + if (_19.is_Passthrough) { + Dafny.ISequence _1582___v103 = _19.dtor_Passthrough_a0; + unmatched73 = false; { - RAST._IExpr _1442_recursiveGen; - DCOMP._IOwnership _1443___v84; - Dafny.ISet> _1444_recIdents; - RAST._IExpr _out250; - DCOMP._IOwnership _out251; - Dafny.ISet> _out252; - (this).GenExpr(_1394_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out250, out _out251, out _out252); - _1442_recursiveGen = _out250; - _1443___v84 = _out251; - _1444_recIdents = _out252; - RAST._IType _1445_toTpeGen; - RAST._IType _out253; - _out253 = (this).GenType(_1396_toTpe, true, false); - _1445_toTpeGen = _out253; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("(("), (_1442_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(") as ")), (_1445_toTpeGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); - RAST._IExpr _out254; - DCOMP._IOwnership _out255; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out254, out _out255); - r = _out254; - resultingOwnership = _out255; - readIdents = _1444_recIdents; + RAST._IExpr _1583_recursiveGen; + DCOMP._IOwnership _1584___v104; + Dafny.ISet> _1585_recIdents; + RAST._IExpr _out290; + DCOMP._IOwnership _out291; + Dafny.ISet> _out292; + (this).GenExpr(_1533_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out290, out _out291, out _out292); + _1583_recursiveGen = _out290; + _1584___v104 = _out291; + _1585_recIdents = _out292; + RAST._IType _1586_toTpeGen; + RAST._IType _out293; + _out293 = (this).GenType(_1535_toTpe, true, false); + _1586_toTpeGen = _out293; + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("(("), (_1583_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(") as ")), (_1586_toTpeGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); + RAST._IExpr _out294; + DCOMP._IOwnership _out295; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out294, out _out295); + r = _out294; + resultingOwnership = _out295; + readIdents = _1585_recIdents; } } } } - if (unmatched70) { - _System._ITuple2 _1446___v85 = _source70; - unmatched70 = false; + if (unmatched73) { + _System._ITuple2 _1587___v105 = _source73; + unmatched73 = false; { - RAST._IExpr _out256; - DCOMP._IOwnership _out257; - Dafny.ISet> _out258; - (this).GenExprConvertNotImplemented(e, selfIdent, @params, expectedOwnership, out _out256, out _out257, out _out258); - r = _out256; - resultingOwnership = _out257; - readIdents = _out258; + RAST._IExpr _out296; + DCOMP._IOwnership _out297; + Dafny.ISet> _out298; + (this).GenExprConvertNotImplemented(e, selfIdent, env, expectedOwnership, out _out296, out _out297, out _out298); + r = _out296; + resultingOwnership = _out297; + readIdents = _out298; } } } return ; } - public void GenExpr(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, Dafny.ISequence> @params, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + public void GenIdent(Dafny.ISequence rName, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); resultingOwnership = DCOMP.Ownership.Default(); readIdents = Dafny.Set>.Empty; - DAST._IExpression _source71 = e; - bool unmatched71 = true; - if (unmatched71) { - if (_source71.is_Literal) { - DAST._ILiteral _1447___v86 = _source71.dtor_Literal_a0; - unmatched71 = false; - RAST._IExpr _out259; - DCOMP._IOwnership _out260; - Dafny.ISet> _out261; - (this).GenExprLiteral(e, selfIdent, @params, expectedOwnership, out _out259, out _out260, out _out261); - r = _out259; - resultingOwnership = _out260; - readIdents = _out261; - } - } - if (unmatched71) { - if (_source71.is_Ident) { - Dafny.ISequence _1448_name = _source71.dtor_Ident_a0; - unmatched71 = false; + r = RAST.Expr.create_Identifier(rName); + Std.Wrappers._IOption _1588_tpe; + _1588_tpe = (env).GetType(rName); + bool _1589_currentlyBorrowed; + _1589_currentlyBorrowed = (env).IsBorrowed(rName); + bool _1590_noNeedOfClone; + _1590_noNeedOfClone = (env).CanReadWithoutClone(rName); + if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipAutoBorrowed())) { + resultingOwnership = DCOMP.Ownership.create_OwnershipOwned(); + } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipBorrowedMut())) { + r = RAST.__default.BorrowMut(r); + resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowedMut(); + } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwned())) { + if (!(_1590_noNeedOfClone)) { + r = RAST.__default.Clone(r); + } + resultingOwnership = DCOMP.Ownership.create_OwnershipOwned(); + } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwnedBox())) { + if (!(_1590_noNeedOfClone)) { + r = RAST.__default.Clone(r); + } + r = RAST.__default.BoxNew(r); + resultingOwnership = DCOMP.Ownership.create_OwnershipOwnedBox(); + } else if (_1589_currentlyBorrowed) { + resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); + } else { + r = RAST.__default.Borrow(r); + resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); + } + readIdents = Dafny.Set>.FromElements(rName); + return ; + } + public void GenExpr(DAST._IExpression e, Std.Wrappers._IOption> selfIdent, DCOMP._IEnvironment env, DCOMP._IOwnership expectedOwnership, out RAST._IExpr r, out DCOMP._IOwnership resultingOwnership, out Dafny.ISet> readIdents) + { + r = RAST.Expr.Default(); + resultingOwnership = DCOMP.Ownership.Default(); + readIdents = Dafny.Set>.Empty; + DAST._IExpression _source74 = e; + bool unmatched74 = true; + if (unmatched74) { + if (_source74.is_Literal) { + DAST._ILiteral _1591___v106 = _source74.dtor_Literal_a0; + unmatched74 = false; + RAST._IExpr _out299; + DCOMP._IOwnership _out300; + Dafny.ISet> _out301; + (this).GenExprLiteral(e, selfIdent, env, expectedOwnership, out _out299, out _out300, out _out301); + r = _out299; + resultingOwnership = _out300; + readIdents = _out301; + } + } + if (unmatched74) { + if (_source74.is_Ident) { + Dafny.ISequence _1592_name = _source74.dtor_Ident_a0; + unmatched74 = false; { - r = RAST.Expr.create_Identifier(DCOMP.__default.escapeIdent(_1448_name)); - bool _1449_currentlyBorrowed; - _1449_currentlyBorrowed = (@params).Contains(_1448_name); - if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipAutoBorrowed())) { - resultingOwnership = DCOMP.Ownership.create_OwnershipOwned(); - } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipBorrowedMut())) { - r = RAST.__default.BorrowMut(r); - resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowedMut(); - } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwned())) { - r = RAST.__default.Clone(r); - resultingOwnership = DCOMP.Ownership.create_OwnershipOwned(); - } else if (_1449_currentlyBorrowed) { - resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); - } else { - r = RAST.__default.Borrow(r); - resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); - } - readIdents = Dafny.Set>.FromElements(_1448_name); - return ; + RAST._IExpr _out302; + DCOMP._IOwnership _out303; + Dafny.ISet> _out304; + (this).GenIdent(DCOMP.__default.escapeName(_1592_name), selfIdent, env, expectedOwnership, out _out302, out _out303, out _out304); + r = _out302; + resultingOwnership = _out303; + readIdents = _out304; } } } - if (unmatched71) { - if (_source71.is_Companion) { - Dafny.ISequence> _1450_path = _source71.dtor_Companion_a0; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_Companion) { + Dafny.ISequence> _1593_path = _source74.dtor_Companion_a0; + unmatched74 = false; { - Dafny.ISequence _1451_p; - Dafny.ISequence _out262; - _out262 = DCOMP.COMP.GenPath(_1450_path); - _1451_p = _out262; - r = RAST.Expr.create_RawExpr(_1451_p); - RAST._IExpr _out263; - DCOMP._IOwnership _out264; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out263, out _out264); - r = _out263; - resultingOwnership = _out264; + RAST._IExpr _out305; + _out305 = DCOMP.COMP.GenPathExpr(_1593_path); + r = _out305; + 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 _out306; + DCOMP._IOwnership _out307; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out306, out _out307); + r = _out306; + resultingOwnership = _out307; + } readIdents = Dafny.Set>.FromElements(); return ; } } } - if (unmatched71) { - if (_source71.is_InitializationValue) { - DAST._IType _1452_typ = _source71.dtor_typ; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_InitializationValue) { + DAST._IType _1594_typ = _source74.dtor_typ; + unmatched74 = false; { - RAST._IType _1453_typExpr; - RAST._IType _out265; - _out265 = (this).GenType(_1452_typ, false, false); - _1453_typExpr = _out265; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), (_1453_typExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as std::default::Default>::default()"))); - RAST._IExpr _out266; - DCOMP._IOwnership _out267; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out266, out _out267); - r = _out266; - resultingOwnership = _out267; + RAST._IType _1595_typExpr; + RAST._IType _out308; + _out308 = (this).GenType(_1594_typ, false, false); + _1595_typExpr = _out308; + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), (_1595_typExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as std::default::Default>::default()"))); + RAST._IExpr _out309; + DCOMP._IOwnership _out310; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out309, out _out310); + r = _out309; + resultingOwnership = _out310; readIdents = Dafny.Set>.FromElements(); return ; } } } - if (unmatched71) { - if (_source71.is_Tuple) { - Dafny.ISequence _1454_values = _source71.dtor_Tuple_a0; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_Tuple) { + Dafny.ISequence _1596_values = _source74.dtor_Tuple_a0; + unmatched74 = false; { - Dafny.ISequence _1455_s; - _1455_s = Dafny.Sequence.UnicodeFromString("("); + Dafny.ISequence _1597_exprs; + _1597_exprs = Dafny.Sequence.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _1456_i; - _1456_i = BigInteger.Zero; - while ((_1456_i) < (new BigInteger((_1454_values).Count))) { - if ((_1456_i).Sign == 1) { - _1455_s = Dafny.Sequence.Concat(_1455_s, Dafny.Sequence.UnicodeFromString(" ")); - } - RAST._IExpr _1457_recursiveGen; - DCOMP._IOwnership _1458___v87; - Dafny.ISet> _1459_recIdents; - RAST._IExpr _out268; - DCOMP._IOwnership _out269; - Dafny.ISet> _out270; - (this).GenExpr((_1454_values).Select(_1456_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out268, out _out269, out _out270); - _1457_recursiveGen = _out268; - _1458___v87 = _out269; - _1459_recIdents = _out270; - _1455_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1455_s, (_1457_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(",")); - readIdents = Dafny.Set>.Union(readIdents, _1459_recIdents); - _1456_i = (_1456_i) + (BigInteger.One); + BigInteger _hi30 = new BigInteger((_1596_values).Count); + for (BigInteger _1598_i = BigInteger.Zero; _1598_i < _hi30; _1598_i++) { + RAST._IExpr _1599_recursiveGen; + DCOMP._IOwnership _1600___v107; + Dafny.ISet> _1601_recIdents; + RAST._IExpr _out311; + DCOMP._IOwnership _out312; + Dafny.ISet> _out313; + (this).GenExpr((_1596_values).Select(_1598_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out311, out _out312, out _out313); + _1599_recursiveGen = _out311; + _1600___v107 = _out312; + _1601_recIdents = _out313; + _1597_exprs = Dafny.Sequence.Concat(_1597_exprs, Dafny.Sequence.FromElements(_1599_recursiveGen)); + readIdents = Dafny.Set>.Union(readIdents, _1601_recIdents); } - _1455_s = Dafny.Sequence.Concat(_1455_s, Dafny.Sequence.UnicodeFromString(")")); - r = RAST.Expr.create_RawExpr(_1455_s); - RAST._IExpr _out271; - DCOMP._IOwnership _out272; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out271, out _out272); - r = _out271; - resultingOwnership = _out272; + r = (((new BigInteger((_1596_values).Count)) <= (RAST.__default.MAX__TUPLE__SIZE)) ? (RAST.Expr.create_Tuple(_1597_exprs)) : (RAST.__default.SystemTuple(_1597_exprs))); + RAST._IExpr _out314; + DCOMP._IOwnership _out315; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out314, out _out315); + r = _out314; + resultingOwnership = _out315; return ; } } } - if (unmatched71) { - if (_source71.is_New) { - Dafny.ISequence> _1460_path = _source71.dtor_path; - Dafny.ISequence _1461_typeArgs = _source71.dtor_typeArgs; - Dafny.ISequence _1462_args = _source71.dtor_args; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_New) { + Dafny.ISequence> _1602_path = _source74.dtor_path; + Dafny.ISequence _1603_typeArgs = _source74.dtor_typeArgs; + Dafny.ISequence _1604_args = _source74.dtor_args; + unmatched74 = false; { - Dafny.ISequence _1463_path; - Dafny.ISequence _out273; - _out273 = DCOMP.COMP.GenPath(_1460_path); - _1463_path = _out273; - Dafny.ISequence _1464_s; - _1464_s = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::rc::Rc::new("), _1463_path); - if ((new BigInteger((_1461_typeArgs).Count)).Sign == 1) { - BigInteger _1465_i; - _1465_i = BigInteger.Zero; - Dafny.ISequence _1466_typeExprs; - _1466_typeExprs = Dafny.Sequence.FromElements(); - while ((_1465_i) < (new BigInteger((_1461_typeArgs).Count))) { - RAST._IType _1467_typeExpr; - RAST._IType _out274; - _out274 = (this).GenType((_1461_typeArgs).Select(_1465_i), false, false); - _1467_typeExpr = _out274; - _1466_typeExprs = Dafny.Sequence.Concat(_1466_typeExprs, Dafny.Sequence.FromElements(_1467_typeExpr)); - _1465_i = (_1465_i) + (BigInteger.One); + RAST._IExpr _out316; + _out316 = DCOMP.COMP.GenPathExpr(_1602_path); + r = _out316; + if ((new BigInteger((_1603_typeArgs).Count)).Sign == 1) { + Dafny.ISequence _1605_typeExprs; + _1605_typeExprs = Dafny.Sequence.FromElements(); + BigInteger _hi31 = new BigInteger((_1603_typeArgs).Count); + for (BigInteger _1606_i = BigInteger.Zero; _1606_i < _hi31; _1606_i++) { + RAST._IType _1607_typeExpr; + RAST._IType _out317; + _out317 = (this).GenType((_1603_typeArgs).Select(_1606_i), false, false); + _1607_typeExpr = _out317; + _1605_typeExprs = Dafny.Sequence.Concat(_1605_typeExprs, Dafny.Sequence.FromElements(_1607_typeExpr)); } - _1464_s = Dafny.Sequence.Concat(_1464_s, (RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("::")), _1466_typeExprs))._ToString(DCOMP.__default.IND)); + r = (r).ApplyType(_1605_typeExprs); } - _1464_s = Dafny.Sequence.Concat(_1464_s, Dafny.Sequence.UnicodeFromString("::new(")); + r = (r).MSel(Dafny.Sequence.UnicodeFromString("new")); readIdents = Dafny.Set>.FromElements(); - BigInteger _1468_i; - _1468_i = BigInteger.Zero; - while ((_1468_i) < (new BigInteger((_1462_args).Count))) { - if ((_1468_i).Sign == 1) { - _1464_s = Dafny.Sequence.Concat(_1464_s, Dafny.Sequence.UnicodeFromString(", ")); - } - RAST._IExpr _1469_recursiveGen; - DCOMP._IOwnership _1470___v88; - Dafny.ISet> _1471_recIdents; - RAST._IExpr _out275; - DCOMP._IOwnership _out276; - Dafny.ISet> _out277; - (this).GenExpr((_1462_args).Select(_1468_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out275, out _out276, out _out277); - _1469_recursiveGen = _out275; - _1470___v88 = _out276; - _1471_recIdents = _out277; - _1464_s = Dafny.Sequence.Concat(_1464_s, (_1469_recursiveGen)._ToString(DCOMP.__default.IND)); - readIdents = Dafny.Set>.Union(readIdents, _1471_recIdents); - _1468_i = (_1468_i) + (BigInteger.One); + Dafny.ISequence _1608_arguments; + _1608_arguments = Dafny.Sequence.FromElements(); + BigInteger _hi32 = new BigInteger((_1604_args).Count); + for (BigInteger _1609_i = BigInteger.Zero; _1609_i < _hi32; _1609_i++) { + RAST._IExpr _1610_recursiveGen; + DCOMP._IOwnership _1611___v108; + Dafny.ISet> _1612_recIdents; + RAST._IExpr _out318; + DCOMP._IOwnership _out319; + Dafny.ISet> _out320; + (this).GenExpr((_1604_args).Select(_1609_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out318, out _out319, out _out320); + _1610_recursiveGen = _out318; + _1611___v108 = _out319; + _1612_recIdents = _out320; + _1608_arguments = Dafny.Sequence.Concat(_1608_arguments, Dafny.Sequence.FromElements(_1610_recursiveGen)); + readIdents = Dafny.Set>.Union(readIdents, _1612_recIdents); } - _1464_s = Dafny.Sequence.Concat(_1464_s, Dafny.Sequence.UnicodeFromString("))")); - r = RAST.Expr.create_RawExpr(_1464_s); - RAST._IExpr _out278; - DCOMP._IOwnership _out279; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out278, out _out279); - r = _out278; - resultingOwnership = _out279; + r = (r).Apply(_1608_arguments); + RAST._IExpr _out321; + DCOMP._IOwnership _out322; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out321, out _out322); + r = _out321; + resultingOwnership = _out322; return ; } } } - if (unmatched71) { - if (_source71.is_NewArray) { - Dafny.ISequence _1472_dims = _source71.dtor_dims; - DAST._IType _1473_typ = _source71.dtor_typ; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_NewArray) { + Dafny.ISequence _1613_dims = _source74.dtor_dims; + DAST._IType _1614_typ = _source74.dtor_typ; + unmatched74 = false; { - BigInteger _1474_i; - _1474_i = (new BigInteger((_1472_dims).Count)) - (BigInteger.One); - RAST._IType _1475_genTyp; - RAST._IType _out280; - _out280 = (this).GenType(_1473_typ, false, false); - _1475_genTyp = _out280; - Dafny.ISequence _1476_s; - _1476_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), (_1475_genTyp)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as ::std::default::Default>::default()")); + BigInteger _1615_i; + _1615_i = (new BigInteger((_1613_dims).Count)) - (BigInteger.One); + RAST._IType _1616_genTyp; + RAST._IType _out323; + _out323 = (this).GenType(_1614_typ, false, false); + _1616_genTyp = _out323; + Dafny.ISequence _1617_s; + _1617_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), (_1616_genTyp)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" as ::std::default::Default>::default()")); readIdents = Dafny.Set>.FromElements(); - while ((_1474_i).Sign != -1) { - RAST._IExpr _1477_recursiveGen; - DCOMP._IOwnership _1478___v89; - Dafny.ISet> _1479_recIdents; - RAST._IExpr _out281; - DCOMP._IOwnership _out282; - Dafny.ISet> _out283; - (this).GenExpr((_1472_dims).Select(_1474_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out281, out _out282, out _out283); - _1477_recursiveGen = _out281; - _1478___v89 = _out282; - _1479_recIdents = _out283; - _1476_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::rc::Rc::new(::std::cell::RefCell::new(vec!["), _1476_s), Dafny.Sequence.UnicodeFromString("; ::from(")), (_1477_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap()]))")); - readIdents = Dafny.Set>.Union(readIdents, _1479_recIdents); - _1474_i = (_1474_i) - (BigInteger.One); + while ((_1615_i).Sign != -1) { + RAST._IExpr _1618_recursiveGen; + DCOMP._IOwnership _1619___v109; + Dafny.ISet> _1620_recIdents; + RAST._IExpr _out324; + DCOMP._IOwnership _out325; + Dafny.ISet> _out326; + (this).GenExpr((_1613_dims).Select(_1615_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out324, out _out325, out _out326); + _1618_recursiveGen = _out324; + _1619___v109 = _out325; + _1620_recIdents = _out326; + _1617_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::rc::Rc::new(::std::cell::RefCell::new(vec!["), _1617_s), Dafny.Sequence.UnicodeFromString("; ::from(")), (_1618_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").unwrap()]))")); + readIdents = Dafny.Set>.Union(readIdents, _1620_recIdents); + _1615_i = (_1615_i) - (BigInteger.One); } - r = RAST.Expr.create_RawExpr(_1476_s); - RAST._IExpr _out284; - DCOMP._IOwnership _out285; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out284, out _out285); - r = _out284; - resultingOwnership = _out285; + r = RAST.Expr.create_RawExpr(_1617_s); + RAST._IExpr _out327; + DCOMP._IOwnership _out328; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out327, out _out328); + r = _out327; + resultingOwnership = _out328; return ; } } } - if (unmatched71) { - if (_source71.is_DatatypeValue) { - Dafny.ISequence> _1480_path = _source71.dtor_path; - Dafny.ISequence _1481_typeArgs = _source71.dtor_typeArgs; - Dafny.ISequence _1482_variant = _source71.dtor_variant; - bool _1483_isCo = _source71.dtor_isCo; - Dafny.ISequence<_System._ITuple2, DAST._IExpression>> _1484_values = _source71.dtor_contents; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_DatatypeValue) { + DAST._IDatatypeType _1621_datatypeType = _source74.dtor_datatypeType; + Dafny.ISequence _1622_typeArgs = _source74.dtor_typeArgs; + Dafny.ISequence _1623_variant = _source74.dtor_variant; + bool _1624_isCo = _source74.dtor_isCo; + Dafny.ISequence<_System._ITuple2, DAST._IExpression>> _1625_values = _source74.dtor_contents; + unmatched74 = false; { - Dafny.ISequence _1485_path; - Dafny.ISequence _out286; - _out286 = DCOMP.COMP.GenPath(_1480_path); - _1485_path = _out286; - Dafny.ISequence _1486_s; - _1486_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::rc::Rc::new("), _1485_path), Dafny.Sequence.UnicodeFromString("::")); - if ((new BigInteger((_1481_typeArgs).Count)).Sign == 1) { - _1486_s = Dafny.Sequence.Concat(_1486_s, Dafny.Sequence.UnicodeFromString("<")); - BigInteger _1487_i; - _1487_i = BigInteger.Zero; - while ((_1487_i) < (new BigInteger((_1481_typeArgs).Count))) { - if ((_1487_i).Sign == 1) { - _1486_s = Dafny.Sequence.Concat(_1486_s, Dafny.Sequence.UnicodeFromString(", ")); - } - RAST._IType _1488_typeExpr; - RAST._IType _out287; - _out287 = (this).GenType((_1481_typeArgs).Select(_1487_i), false, false); - _1488_typeExpr = _out287; - _1486_s = Dafny.Sequence.Concat(_1486_s, (_1488_typeExpr)._ToString(DCOMP.__default.IND)); - _1487_i = (_1487_i) + (BigInteger.One); - } - _1486_s = Dafny.Sequence.Concat(_1486_s, Dafny.Sequence.UnicodeFromString(">::")); + RAST._IExpr _out329; + _out329 = DCOMP.COMP.GenPathExpr((_1621_datatypeType).dtor_path); + r = _out329; + Dafny.ISequence _1626_genTypeArgs; + _1626_genTypeArgs = Dafny.Sequence.FromElements(); + BigInteger _hi33 = new BigInteger((_1622_typeArgs).Count); + for (BigInteger _1627_i = BigInteger.Zero; _1627_i < _hi33; _1627_i++) { + RAST._IType _1628_typeExpr; + RAST._IType _out330; + _out330 = (this).GenType((_1622_typeArgs).Select(_1627_i), false, false); + _1628_typeExpr = _out330; + _1626_genTypeArgs = Dafny.Sequence.Concat(_1626_genTypeArgs, Dafny.Sequence.FromElements(_1628_typeExpr)); + } + if ((new BigInteger((_1622_typeArgs).Count)).Sign == 1) { + r = (r).ApplyType(_1626_genTypeArgs); } - _1486_s = Dafny.Sequence.Concat(_1486_s, DCOMP.__default.escapeIdent(_1482_variant)); + r = (r).MSel(DCOMP.__default.escapeName(_1623_variant)); readIdents = Dafny.Set>.FromElements(); - BigInteger _1489_i; - _1489_i = BigInteger.Zero; - _1486_s = Dafny.Sequence.Concat(_1486_s, Dafny.Sequence.UnicodeFromString(" {")); - while ((_1489_i) < (new BigInteger((_1484_values).Count))) { - _System._ITuple2, DAST._IExpression> _let_tmp_rhs60 = (_1484_values).Select(_1489_i); - Dafny.ISequence _1490_name = _let_tmp_rhs60.dtor__0; - DAST._IExpression _1491_value = _let_tmp_rhs60.dtor__1; - if ((_1489_i).Sign == 1) { - _1486_s = Dafny.Sequence.Concat(_1486_s, Dafny.Sequence.UnicodeFromString(", ")); - } - if (_1483_isCo) { - RAST._IExpr _1492_recursiveGen; - DCOMP._IOwnership _1493___v90; - Dafny.ISet> _1494_recIdents; - RAST._IExpr _out288; - DCOMP._IOwnership _out289; - Dafny.ISet> _out290; - (this).GenExpr(_1491_value, selfIdent, Dafny.Sequence>.FromElements(), DCOMP.Ownership.create_OwnershipOwned(), out _out288, out _out289, out _out290); - _1492_recursiveGen = _out288; - _1493___v90 = _out289; - _1494_recIdents = _out290; - readIdents = Dafny.Set>.Union(readIdents, _1494_recIdents); - Dafny.ISequence _1495_allReadCloned; - _1495_allReadCloned = Dafny.Sequence.UnicodeFromString(""); - while (!(_1494_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _1496_next; - foreach (Dafny.ISequence _assign_such_that_2 in (_1494_recIdents).Elements) { - _1496_next = (Dafny.ISequence)_assign_such_that_2; - if ((_1494_recIdents).Contains(_1496_next)) { + Dafny.ISequence _1629_assignments; + _1629_assignments = Dafny.Sequence.FromElements(); + BigInteger _hi34 = new BigInteger((_1625_values).Count); + for (BigInteger _1630_i = BigInteger.Zero; _1630_i < _hi34; _1630_i++) { + _System._ITuple2, DAST._IExpression> _let_tmp_rhs63 = (_1625_values).Select(_1630_i); + Dafny.ISequence _1631_name = _let_tmp_rhs63.dtor__0; + DAST._IExpression _1632_value = _let_tmp_rhs63.dtor__1; + if (_1624_isCo) { + RAST._IExpr _1633_recursiveGen; + DCOMP._IOwnership _1634___v110; + Dafny.ISet> _1635_recIdents; + RAST._IExpr _out331; + DCOMP._IOwnership _out332; + Dafny.ISet> _out333; + (this).GenExpr(_1632_value, selfIdent, DCOMP.Environment.Empty(), DCOMP.Ownership.create_OwnershipOwned(), out _out331, out _out332, out _out333); + _1633_recursiveGen = _out331; + _1634___v110 = _out332; + _1635_recIdents = _out333; + readIdents = Dafny.Set>.Union(readIdents, _1635_recIdents); + Dafny.ISequence _1636_allReadCloned; + _1636_allReadCloned = Dafny.Sequence.UnicodeFromString(""); + while (!(_1635_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _1637_next; + foreach (Dafny.ISequence _assign_such_that_2 in (_1635_recIdents).Elements) { + _1637_next = (Dafny.ISequence)_assign_such_that_2; + if ((_1635_recIdents).Contains(_1637_next)) { goto after__ASSIGN_SUCH_THAT_2; } } - throw new System.Exception("assign-such-that search produced no value (line 2844)"); + throw new System.Exception("assign-such-that search produced no value (line 3271)"); after__ASSIGN_SUCH_THAT_2: ; - _1495_allReadCloned = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1495_allReadCloned, Dafny.Sequence.UnicodeFromString("let ")), DCOMP.__default.escapeIdent(_1496_next)), Dafny.Sequence.UnicodeFromString(" = ")), DCOMP.__default.escapeIdent(_1496_next)), Dafny.Sequence.UnicodeFromString(".clone();\n")); - _1494_recIdents = Dafny.Set>.Difference(_1494_recIdents, Dafny.Set>.FromElements(_1496_next)); + _1636_allReadCloned = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1636_allReadCloned, Dafny.Sequence.UnicodeFromString("let ")), _1637_next), Dafny.Sequence.UnicodeFromString(" = ")), _1637_next), Dafny.Sequence.UnicodeFromString(".clone();\n")); + _1635_recIdents = Dafny.Set>.Difference(_1635_recIdents, Dafny.Set>.FromElements(_1637_next)); } - _1486_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1486_s, DCOMP.__default.escapeIdent(_1490_name)), Dafny.Sequence.UnicodeFromString(": ::dafny_runtime::LazyFieldWrapper(::dafny_runtime::Lazy::new(::std::boxed::Box::new({\n")), _1495_allReadCloned), Dafny.Sequence.UnicodeFromString("move || (")), (_1492_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")})))")); + Dafny.ISequence _1638_wasAssigned; + _1638_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"), _1636_allReadCloned), Dafny.Sequence.UnicodeFromString("move || (")), (_1633_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")})))")); + _1629_assignments = Dafny.Sequence.Concat(_1629_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_1631_name, RAST.Expr.create_RawExpr(_1638_wasAssigned)))); } else { - RAST._IExpr _1497_recursiveGen; - DCOMP._IOwnership _1498___v91; - Dafny.ISet> _1499_recIdents; - RAST._IExpr _out291; - DCOMP._IOwnership _out292; - Dafny.ISet> _out293; - (this).GenExpr(_1491_value, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out291, out _out292, out _out293); - _1497_recursiveGen = _out291; - _1498___v91 = _out292; - _1499_recIdents = _out293; - _1486_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1486_s, DCOMP.__default.escapeIdent(_1490_name)), Dafny.Sequence.UnicodeFromString(": ")), Dafny.Sequence.UnicodeFromString("(")), (_1497_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")); - readIdents = Dafny.Set>.Union(readIdents, _1499_recIdents); + RAST._IExpr _1639_recursiveGen; + DCOMP._IOwnership _1640___v111; + Dafny.ISet> _1641_recIdents; + RAST._IExpr _out334; + DCOMP._IOwnership _out335; + Dafny.ISet> _out336; + (this).GenExpr(_1632_value, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); + _1639_recursiveGen = _out334; + _1640___v111 = _out335; + _1641_recIdents = _out336; + _1629_assignments = Dafny.Sequence.Concat(_1629_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_1631_name, _1639_recursiveGen))); + readIdents = Dafny.Set>.Union(readIdents, _1641_recIdents); } - _1489_i = (_1489_i) + (BigInteger.One); } - _1486_s = Dafny.Sequence.Concat(_1486_s, Dafny.Sequence.UnicodeFromString(" })")); - r = RAST.Expr.create_RawExpr(_1486_s); - RAST._IExpr _out294; - DCOMP._IOwnership _out295; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out294, out _out295); - r = _out294; - resultingOwnership = _out295; + r = RAST.Expr.create_StructBuild(r, _1629_assignments); + if ((this).IsRcWrapped((_1621_datatypeType).dtor_attributes)) { + r = RAST.__default.RcNew(r); + } + RAST._IExpr _out337; + DCOMP._IOwnership _out338; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out337, out _out338); + r = _out337; + resultingOwnership = _out338; return ; } } } - if (unmatched71) { - if (_source71.is_Convert) { - DAST._IExpression _1500___v92 = _source71.dtor_value; - DAST._IType _1501___v93 = _source71.dtor_from; - DAST._IType _1502___v94 = _source71.dtor_typ; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_Convert) { + DAST._IExpression _1642___v112 = _source74.dtor_value; + DAST._IType _1643___v113 = _source74.dtor_from; + DAST._IType _1644___v114 = _source74.dtor_typ; + unmatched74 = false; { - RAST._IExpr _out296; - DCOMP._IOwnership _out297; - Dafny.ISet> _out298; - (this).GenExprConvert(e, selfIdent, @params, expectedOwnership, out _out296, out _out297, out _out298); - r = _out296; - resultingOwnership = _out297; - readIdents = _out298; + RAST._IExpr _out339; + DCOMP._IOwnership _out340; + Dafny.ISet> _out341; + (this).GenExprConvert(e, selfIdent, env, expectedOwnership, out _out339, out _out340, out _out341); + r = _out339; + resultingOwnership = _out340; + readIdents = _out341; } } } - if (unmatched71) { - if (_source71.is_SeqConstruct) { - DAST._IExpression _1503_length = _source71.dtor_length; - DAST._IExpression _1504_expr = _source71.dtor_elem; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_SeqConstruct) { + DAST._IExpression _1645_length = _source74.dtor_length; + DAST._IExpression _1646_expr = _source74.dtor_elem; + unmatched74 = false; { - RAST._IExpr _1505_recursiveGen; - DCOMP._IOwnership _1506___v95; - Dafny.ISet> _1507_recIdents; - RAST._IExpr _out299; - DCOMP._IOwnership _out300; - Dafny.ISet> _out301; - (this).GenExpr(_1504_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out299, out _out300, out _out301); - _1505_recursiveGen = _out299; - _1506___v95 = _out300; - _1507_recIdents = _out301; - RAST._IExpr _1508_lengthGen; - DCOMP._IOwnership _1509___v96; - Dafny.ISet> _1510_lengthIdents; - RAST._IExpr _out302; - DCOMP._IOwnership _out303; - Dafny.ISet> _out304; - (this).GenExpr(_1503_length, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out302, out _out303, out _out304); - _1508_lengthGen = _out302; - _1509___v96 = _out303; - _1510_lengthIdents = _out304; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("{\nlet _initializer = "), (_1505_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(";\n::dafny_runtime::integer_range(::dafny_runtime::Zero::zero(), ")), (_1508_lengthGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").map(|i| _initializer.0(&i)).collect::<::dafny_runtime::Sequence<_>>()\n}"))); - readIdents = Dafny.Set>.Union(_1507_recIdents, _1510_lengthIdents); - RAST._IExpr _out305; - DCOMP._IOwnership _out306; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out305, out _out306); - r = _out305; - resultingOwnership = _out306; + RAST._IExpr _1647_recursiveGen; + DCOMP._IOwnership _1648___v115; + Dafny.ISet> _1649_recIdents; + RAST._IExpr _out342; + DCOMP._IOwnership _out343; + Dafny.ISet> _out344; + (this).GenExpr(_1646_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out342, out _out343, out _out344); + _1647_recursiveGen = _out342; + _1648___v115 = _out343; + _1649_recIdents = _out344; + RAST._IExpr _1650_lengthGen; + DCOMP._IOwnership _1651___v116; + Dafny.ISet> _1652_lengthIdents; + RAST._IExpr _out345; + DCOMP._IOwnership _out346; + Dafny.ISet> _out347; + (this).GenExpr(_1645_length, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out345, out _out346, out _out347); + _1650_lengthGen = _out345; + _1651___v116 = _out346; + _1652_lengthIdents = _out347; + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("{\nlet _initializer = "), (_1647_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(";\n::dafny_runtime::integer_range(::dafny_runtime::Zero::zero(), ")), (_1650_lengthGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").map(|i| _initializer(&i)).collect::<::dafny_runtime::Sequence<_>>()\n}"))); + readIdents = Dafny.Set>.Union(_1649_recIdents, _1652_lengthIdents); + RAST._IExpr _out348; + DCOMP._IOwnership _out349; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out348, out _out349); + r = _out348; + resultingOwnership = _out349; return ; } } } - if (unmatched71) { - if (_source71.is_SeqValue) { - Dafny.ISequence _1511_exprs = _source71.dtor_elements; - DAST._IType _1512_typ = _source71.dtor_typ; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_SeqValue) { + Dafny.ISequence _1653_exprs = _source74.dtor_elements; + DAST._IType _1654_typ = _source74.dtor_typ; + unmatched74 = false; { readIdents = Dafny.Set>.FromElements(); - RAST._IType _1513_genTpe; - RAST._IType _out307; - _out307 = (this).GenType(_1512_typ, false, false); - _1513_genTpe = _out307; - BigInteger _1514_i; - _1514_i = BigInteger.Zero; - Dafny.ISequence _1515_args; - _1515_args = Dafny.Sequence.FromElements(); - while ((_1514_i) < (new BigInteger((_1511_exprs).Count))) { - RAST._IExpr _1516_recursiveGen; - DCOMP._IOwnership _1517___v97; - Dafny.ISet> _1518_recIdents; - RAST._IExpr _out308; - DCOMP._IOwnership _out309; - Dafny.ISet> _out310; - (this).GenExpr((_1511_exprs).Select(_1514_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out308, out _out309, out _out310); - _1516_recursiveGen = _out308; - _1517___v97 = _out309; - _1518_recIdents = _out310; - readIdents = Dafny.Set>.Union(readIdents, _1518_recIdents); - _1515_args = Dafny.Sequence.Concat(_1515_args, Dafny.Sequence.FromElements(_1516_recursiveGen)); - _1514_i = (_1514_i) + (BigInteger.One); + RAST._IType _1655_genTpe; + RAST._IType _out350; + _out350 = (this).GenType(_1654_typ, false, false); + _1655_genTpe = _out350; + BigInteger _1656_i; + _1656_i = BigInteger.Zero; + Dafny.ISequence _1657_args; + _1657_args = Dafny.Sequence.FromElements(); + while ((_1656_i) < (new BigInteger((_1653_exprs).Count))) { + RAST._IExpr _1658_recursiveGen; + DCOMP._IOwnership _1659___v117; + Dafny.ISet> _1660_recIdents; + RAST._IExpr _out351; + DCOMP._IOwnership _out352; + Dafny.ISet> _out353; + (this).GenExpr((_1653_exprs).Select(_1656_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out351, out _out352, out _out353); + _1658_recursiveGen = _out351; + _1659___v117 = _out352; + _1660_recIdents = _out353; + readIdents = Dafny.Set>.Union(readIdents, _1660_recIdents); + _1657_args = Dafny.Sequence.Concat(_1657_args, Dafny.Sequence.FromElements(_1658_recursiveGen)); + _1656_i = (_1656_i) + (BigInteger.One); } - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).Apply(Dafny.Sequence.FromElements(), _1515_args); - if ((new BigInteger((_1515_args).Count)).Sign == 0) { - r = RAST.Expr.create_TypeAscription(r, ((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Sequence"))).Apply1(_1513_genTpe)); + r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).Apply(_1657_args); + if ((new BigInteger((_1657_args).Count)).Sign == 0) { + r = RAST.Expr.create_TypeAscription(r, ((RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("Sequence"))).Apply1(_1655_genTpe)); } - RAST._IExpr _out311; - DCOMP._IOwnership _out312; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out311, out _out312); - r = _out311; - resultingOwnership = _out312; + RAST._IExpr _out354; + DCOMP._IOwnership _out355; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out354, out _out355); + r = _out354; + resultingOwnership = _out355; return ; } } } - if (unmatched71) { - if (_source71.is_SetValue) { - Dafny.ISequence _1519_exprs = _source71.dtor_elements; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_SetValue) { + Dafny.ISequence _1661_exprs = _source74.dtor_elements; + unmatched74 = false; { - Dafny.ISequence _1520_generatedValues; - _1520_generatedValues = Dafny.Sequence.FromElements(); + Dafny.ISequence _1662_generatedValues; + _1662_generatedValues = Dafny.Sequence.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _1521_i; - _1521_i = BigInteger.Zero; - while ((_1521_i) < (new BigInteger((_1519_exprs).Count))) { - RAST._IExpr _1522_recursiveGen; - DCOMP._IOwnership _1523___v98; - Dafny.ISet> _1524_recIdents; - RAST._IExpr _out313; - DCOMP._IOwnership _out314; - Dafny.ISet> _out315; - (this).GenExpr((_1519_exprs).Select(_1521_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out313, out _out314, out _out315); - _1522_recursiveGen = _out313; - _1523___v98 = _out314; - _1524_recIdents = _out315; - _1520_generatedValues = Dafny.Sequence.Concat(_1520_generatedValues, Dafny.Sequence.FromElements(_1522_recursiveGen)); - readIdents = Dafny.Set>.Union(readIdents, _1524_recIdents); - _1521_i = (_1521_i) + (BigInteger.One); + BigInteger _1663_i; + _1663_i = BigInteger.Zero; + while ((_1663_i) < (new BigInteger((_1661_exprs).Count))) { + RAST._IExpr _1664_recursiveGen; + DCOMP._IOwnership _1665___v118; + Dafny.ISet> _1666_recIdents; + RAST._IExpr _out356; + DCOMP._IOwnership _out357; + Dafny.ISet> _out358; + (this).GenExpr((_1661_exprs).Select(_1663_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out356, out _out357, out _out358); + _1664_recursiveGen = _out356; + _1665___v118 = _out357; + _1666_recIdents = _out358; + _1662_generatedValues = Dafny.Sequence.Concat(_1662_generatedValues, Dafny.Sequence.FromElements(_1664_recursiveGen)); + readIdents = Dafny.Set>.Union(readIdents, _1666_recIdents); + _1663_i = (_1663_i) + (BigInteger.One); } - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("set!"))).Apply(Dafny.Sequence.FromElements(), _1520_generatedValues); - RAST._IExpr _out316; - DCOMP._IOwnership _out317; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out316, out _out317); - r = _out316; - resultingOwnership = _out317; + r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("set!"))).Apply(_1662_generatedValues); + RAST._IExpr _out359; + DCOMP._IOwnership _out360; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out359, out _out360); + r = _out359; + resultingOwnership = _out360; return ; } } } - if (unmatched71) { - if (_source71.is_MultisetValue) { - Dafny.ISequence _1525_exprs = _source71.dtor_elements; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_MultisetValue) { + Dafny.ISequence _1667_exprs = _source74.dtor_elements; + unmatched74 = false; { - Dafny.ISequence _1526_generatedValues; - _1526_generatedValues = Dafny.Sequence.FromElements(); + Dafny.ISequence _1668_generatedValues; + _1668_generatedValues = Dafny.Sequence.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _1527_i; - _1527_i = BigInteger.Zero; - while ((_1527_i) < (new BigInteger((_1525_exprs).Count))) { - RAST._IExpr _1528_recursiveGen; - DCOMP._IOwnership _1529___v99; - Dafny.ISet> _1530_recIdents; - RAST._IExpr _out318; - DCOMP._IOwnership _out319; - Dafny.ISet> _out320; - (this).GenExpr((_1525_exprs).Select(_1527_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out318, out _out319, out _out320); - _1528_recursiveGen = _out318; - _1529___v99 = _out319; - _1530_recIdents = _out320; - _1526_generatedValues = Dafny.Sequence.Concat(_1526_generatedValues, Dafny.Sequence.FromElements(_1528_recursiveGen)); - readIdents = Dafny.Set>.Union(readIdents, _1530_recIdents); - _1527_i = (_1527_i) + (BigInteger.One); + BigInteger _1669_i; + _1669_i = BigInteger.Zero; + while ((_1669_i) < (new BigInteger((_1667_exprs).Count))) { + RAST._IExpr _1670_recursiveGen; + DCOMP._IOwnership _1671___v119; + Dafny.ISet> _1672_recIdents; + RAST._IExpr _out361; + DCOMP._IOwnership _out362; + Dafny.ISet> _out363; + (this).GenExpr((_1667_exprs).Select(_1669_i), selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out361, out _out362, out _out363); + _1670_recursiveGen = _out361; + _1671___v119 = _out362; + _1672_recIdents = _out363; + _1668_generatedValues = Dafny.Sequence.Concat(_1668_generatedValues, Dafny.Sequence.FromElements(_1670_recursiveGen)); + readIdents = Dafny.Set>.Union(readIdents, _1672_recIdents); + _1669_i = (_1669_i) + (BigInteger.One); } - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("multiset!"))).Apply(Dafny.Sequence.FromElements(), _1526_generatedValues); - RAST._IExpr _out321; - DCOMP._IOwnership _out322; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out321, out _out322); - r = _out321; - resultingOwnership = _out322; + r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("multiset!"))).Apply(_1668_generatedValues); + RAST._IExpr _out364; + DCOMP._IOwnership _out365; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out364, out _out365); + r = _out364; + resultingOwnership = _out365; return ; } } } - if (unmatched71) { - if (_source71.is_ToMultiset) { - DAST._IExpression _1531_expr = _source71.dtor_ToMultiset_a0; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_ToMultiset) { + DAST._IExpression _1673_expr = _source74.dtor_ToMultiset_a0; + unmatched74 = false; { - RAST._IExpr _1532_recursiveGen; - DCOMP._IOwnership _1533___v100; - Dafny.ISet> _1534_recIdents; - RAST._IExpr _out323; - DCOMP._IOwnership _out324; - Dafny.ISet> _out325; - (this).GenExpr(_1531_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out323, out _out324, out _out325); - _1532_recursiveGen = _out323; - _1533___v100 = _out324; - _1534_recIdents = _out325; - r = ((_1532_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply(Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); - readIdents = _1534_recIdents; - RAST._IExpr _out326; - DCOMP._IOwnership _out327; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out326, out _out327); - r = _out326; - resultingOwnership = _out327; + RAST._IExpr _1674_recursiveGen; + DCOMP._IOwnership _1675___v120; + Dafny.ISet> _1676_recIdents; + RAST._IExpr _out366; + DCOMP._IOwnership _out367; + Dafny.ISet> _out368; + (this).GenExpr(_1673_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out366, out _out367, out _out368); + _1674_recursiveGen = _out366; + _1675___v120 = _out367; + _1676_recIdents = _out368; + r = ((_1674_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply(Dafny.Sequence.FromElements()); + readIdents = _1676_recIdents; + RAST._IExpr _out369; + DCOMP._IOwnership _out370; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out369, out _out370); + r = _out369; + resultingOwnership = _out370; return ; } } } - if (unmatched71) { - if (_source71.is_MapValue) { - Dafny.ISequence<_System._ITuple2> _1535_mapElems = _source71.dtor_mapElems; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_MapValue) { + Dafny.ISequence<_System._ITuple2> _1677_mapElems = _source74.dtor_mapElems; + unmatched74 = false; { - Dafny.ISequence<_System._ITuple2> _1536_generatedValues; - _1536_generatedValues = Dafny.Sequence<_System._ITuple2>.FromElements(); + Dafny.ISequence<_System._ITuple2> _1678_generatedValues; + _1678_generatedValues = Dafny.Sequence<_System._ITuple2>.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _1537_i; - _1537_i = BigInteger.Zero; - while ((_1537_i) < (new BigInteger((_1535_mapElems).Count))) { - RAST._IExpr _1538_recursiveGenKey; - DCOMP._IOwnership _1539___v101; - Dafny.ISet> _1540_recIdentsKey; - RAST._IExpr _out328; - DCOMP._IOwnership _out329; - Dafny.ISet> _out330; - (this).GenExpr(((_1535_mapElems).Select(_1537_i)).dtor__0, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); - _1538_recursiveGenKey = _out328; - _1539___v101 = _out329; - _1540_recIdentsKey = _out330; - RAST._IExpr _1541_recursiveGenValue; - DCOMP._IOwnership _1542___v102; - Dafny.ISet> _1543_recIdentsValue; - RAST._IExpr _out331; - DCOMP._IOwnership _out332; - Dafny.ISet> _out333; - (this).GenExpr(((_1535_mapElems).Select(_1537_i)).dtor__1, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out331, out _out332, out _out333); - _1541_recursiveGenValue = _out331; - _1542___v102 = _out332; - _1543_recIdentsValue = _out333; - _1536_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_1536_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_1538_recursiveGenKey, _1541_recursiveGenValue))); - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _1540_recIdentsKey), _1543_recIdentsValue); - _1537_i = (_1537_i) + (BigInteger.One); + BigInteger _1679_i; + _1679_i = BigInteger.Zero; + while ((_1679_i) < (new BigInteger((_1677_mapElems).Count))) { + RAST._IExpr _1680_recursiveGenKey; + DCOMP._IOwnership _1681___v121; + Dafny.ISet> _1682_recIdentsKey; + RAST._IExpr _out371; + DCOMP._IOwnership _out372; + Dafny.ISet> _out373; + (this).GenExpr(((_1677_mapElems).Select(_1679_i)).dtor__0, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out371, out _out372, out _out373); + _1680_recursiveGenKey = _out371; + _1681___v121 = _out372; + _1682_recIdentsKey = _out373; + RAST._IExpr _1683_recursiveGenValue; + DCOMP._IOwnership _1684___v122; + Dafny.ISet> _1685_recIdentsValue; + RAST._IExpr _out374; + DCOMP._IOwnership _out375; + Dafny.ISet> _out376; + (this).GenExpr(((_1677_mapElems).Select(_1679_i)).dtor__1, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out374, out _out375, out _out376); + _1683_recursiveGenValue = _out374; + _1684___v122 = _out375; + _1685_recIdentsValue = _out376; + _1678_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_1678_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_1680_recursiveGenKey, _1683_recursiveGenValue))); + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _1682_recIdentsKey), _1685_recIdentsValue); + _1679_i = (_1679_i) + (BigInteger.One); } - _1537_i = BigInteger.Zero; - Dafny.ISequence _1544_arguments; - _1544_arguments = Dafny.Sequence.FromElements(); - while ((_1537_i) < (new BigInteger((_1536_generatedValues).Count))) { - RAST._IExpr _1545_genKey; - _1545_genKey = ((_1536_generatedValues).Select(_1537_i)).dtor__0; - RAST._IExpr _1546_genValue; - _1546_genValue = ((_1536_generatedValues).Select(_1537_i)).dtor__1; - _1544_arguments = Dafny.Sequence.Concat(_1544_arguments, Dafny.Sequence.FromElements(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=>"), _1545_genKey, _1546_genValue, DAST.Format.BinaryOpFormat.create_NoFormat()))); - _1537_i = (_1537_i) + (BigInteger.One); + _1679_i = BigInteger.Zero; + Dafny.ISequence _1686_arguments; + _1686_arguments = Dafny.Sequence.FromElements(); + while ((_1679_i) < (new BigInteger((_1678_generatedValues).Count))) { + RAST._IExpr _1687_genKey; + _1687_genKey = ((_1678_generatedValues).Select(_1679_i)).dtor__0; + RAST._IExpr _1688_genValue; + _1688_genValue = ((_1678_generatedValues).Select(_1679_i)).dtor__1; + _1686_arguments = Dafny.Sequence.Concat(_1686_arguments, Dafny.Sequence.FromElements(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=>"), _1687_genKey, _1688_genValue, DAST.Format.BinaryOpFormat.create_NoFormat()))); + _1679_i = (_1679_i) + (BigInteger.One); } - r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("map!"))).Apply(Dafny.Sequence.FromElements(), _1544_arguments); - RAST._IExpr _out334; - DCOMP._IOwnership _out335; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out334, out _out335); - r = _out334; - resultingOwnership = _out335; + r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("map!"))).Apply(_1686_arguments); + RAST._IExpr _out377; + DCOMP._IOwnership _out378; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out377, out _out378); + r = _out377; + resultingOwnership = _out378; return ; } } } - if (unmatched71) { - if (_source71.is_SeqUpdate) { - DAST._IExpression _1547_expr = _source71.dtor_expr; - DAST._IExpression _1548_index = _source71.dtor_indexExpr; - DAST._IExpression _1549_value = _source71.dtor_value; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_SeqUpdate) { + DAST._IExpression _1689_expr = _source74.dtor_expr; + DAST._IExpression _1690_index = _source74.dtor_indexExpr; + DAST._IExpression _1691_value = _source74.dtor_value; + unmatched74 = false; { - RAST._IExpr _1550_exprR; - DCOMP._IOwnership _1551___v103; - Dafny.ISet> _1552_exprIdents; - RAST._IExpr _out336; - DCOMP._IOwnership _out337; - Dafny.ISet> _out338; - (this).GenExpr(_1547_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out336, out _out337, out _out338); - _1550_exprR = _out336; - _1551___v103 = _out337; - _1552_exprIdents = _out338; - RAST._IExpr _1553_indexR; - DCOMP._IOwnership _1554_indexOwnership; - Dafny.ISet> _1555_indexIdents; - RAST._IExpr _out339; - DCOMP._IOwnership _out340; - Dafny.ISet> _out341; - (this).GenExpr(_1548_index, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out339, out _out340, out _out341); - _1553_indexR = _out339; - _1554_indexOwnership = _out340; - _1555_indexIdents = _out341; - RAST._IExpr _1556_valueR; - DCOMP._IOwnership _1557_valueOwnership; - Dafny.ISet> _1558_valueIdents; - RAST._IExpr _out342; - DCOMP._IOwnership _out343; - Dafny.ISet> _out344; - (this).GenExpr(_1549_value, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out342, out _out343, out _out344); - _1556_valueR = _out342; - _1557_valueOwnership = _out343; - _1558_valueIdents = _out344; - r = ((_1550_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(_1553_indexR, _1556_valueR)); - RAST._IExpr _out345; - DCOMP._IOwnership _out346; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out345, out _out346); - r = _out345; - resultingOwnership = _out346; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_1552_exprIdents, _1555_indexIdents), _1558_valueIdents); + RAST._IExpr _1692_exprR; + DCOMP._IOwnership _1693___v123; + Dafny.ISet> _1694_exprIdents; + RAST._IExpr _out379; + DCOMP._IOwnership _out380; + Dafny.ISet> _out381; + (this).GenExpr(_1689_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out379, out _out380, out _out381); + _1692_exprR = _out379; + _1693___v123 = _out380; + _1694_exprIdents = _out381; + RAST._IExpr _1695_indexR; + DCOMP._IOwnership _1696_indexOwnership; + Dafny.ISet> _1697_indexIdents; + RAST._IExpr _out382; + DCOMP._IOwnership _out383; + Dafny.ISet> _out384; + (this).GenExpr(_1690_index, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out382, out _out383, out _out384); + _1695_indexR = _out382; + _1696_indexOwnership = _out383; + _1697_indexIdents = _out384; + RAST._IExpr _1698_valueR; + DCOMP._IOwnership _1699_valueOwnership; + Dafny.ISet> _1700_valueIdents; + RAST._IExpr _out385; + DCOMP._IOwnership _out386; + Dafny.ISet> _out387; + (this).GenExpr(_1691_value, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out385, out _out386, out _out387); + _1698_valueR = _out385; + _1699_valueOwnership = _out386; + _1700_valueIdents = _out387; + r = ((_1692_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_1695_indexR, _1698_valueR)); + RAST._IExpr _out388; + DCOMP._IOwnership _out389; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out388, out _out389); + r = _out388; + resultingOwnership = _out389; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_1694_exprIdents, _1697_indexIdents), _1700_valueIdents); return ; } } } - if (unmatched71) { - if (_source71.is_MapUpdate) { - DAST._IExpression _1559_expr = _source71.dtor_expr; - DAST._IExpression _1560_index = _source71.dtor_indexExpr; - DAST._IExpression _1561_value = _source71.dtor_value; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_MapUpdate) { + DAST._IExpression _1701_expr = _source74.dtor_expr; + DAST._IExpression _1702_index = _source74.dtor_indexExpr; + DAST._IExpression _1703_value = _source74.dtor_value; + unmatched74 = false; { - RAST._IExpr _1562_exprR; - DCOMP._IOwnership _1563___v104; - Dafny.ISet> _1564_exprIdents; - RAST._IExpr _out347; - DCOMP._IOwnership _out348; - Dafny.ISet> _out349; - (this).GenExpr(_1559_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out347, out _out348, out _out349); - _1562_exprR = _out347; - _1563___v104 = _out348; - _1564_exprIdents = _out349; - RAST._IExpr _1565_indexR; - DCOMP._IOwnership _1566_indexOwnership; - Dafny.ISet> _1567_indexIdents; - RAST._IExpr _out350; - DCOMP._IOwnership _out351; - Dafny.ISet> _out352; - (this).GenExpr(_1560_index, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out350, out _out351, out _out352); - _1565_indexR = _out350; - _1566_indexOwnership = _out351; - _1567_indexIdents = _out352; - RAST._IExpr _1568_valueR; - DCOMP._IOwnership _1569_valueOwnership; - Dafny.ISet> _1570_valueIdents; - RAST._IExpr _out353; - DCOMP._IOwnership _out354; - Dafny.ISet> _out355; - (this).GenExpr(_1561_value, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out353, out _out354, out _out355); - _1568_valueR = _out353; - _1569_valueOwnership = _out354; - _1570_valueIdents = _out355; - r = ((_1562_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(_1565_indexR, _1568_valueR)); - RAST._IExpr _out356; - DCOMP._IOwnership _out357; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out356, out _out357); - r = _out356; - resultingOwnership = _out357; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_1564_exprIdents, _1567_indexIdents), _1570_valueIdents); + RAST._IExpr _1704_exprR; + DCOMP._IOwnership _1705___v124; + Dafny.ISet> _1706_exprIdents; + RAST._IExpr _out390; + DCOMP._IOwnership _out391; + Dafny.ISet> _out392; + (this).GenExpr(_1701_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out390, out _out391, out _out392); + _1704_exprR = _out390; + _1705___v124 = _out391; + _1706_exprIdents = _out392; + RAST._IExpr _1707_indexR; + DCOMP._IOwnership _1708_indexOwnership; + Dafny.ISet> _1709_indexIdents; + RAST._IExpr _out393; + DCOMP._IOwnership _out394; + Dafny.ISet> _out395; + (this).GenExpr(_1702_index, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out393, out _out394, out _out395); + _1707_indexR = _out393; + _1708_indexOwnership = _out394; + _1709_indexIdents = _out395; + RAST._IExpr _1710_valueR; + DCOMP._IOwnership _1711_valueOwnership; + Dafny.ISet> _1712_valueIdents; + RAST._IExpr _out396; + DCOMP._IOwnership _out397; + Dafny.ISet> _out398; + (this).GenExpr(_1703_value, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out396, out _out397, out _out398); + _1710_valueR = _out396; + _1711_valueOwnership = _out397; + _1712_valueIdents = _out398; + r = ((_1704_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_1707_indexR, _1710_valueR)); + RAST._IExpr _out399; + DCOMP._IOwnership _out400; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out399, out _out400); + r = _out399; + resultingOwnership = _out400; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_1706_exprIdents, _1709_indexIdents), _1712_valueIdents); return ; } } } - if (unmatched71) { - if (_source71.is_This) { - unmatched71 = false; + if (unmatched74) { + if (_source74.is_This) { + unmatched74 = false; { - Std.Wrappers._IOption> _source72 = selfIdent; - bool unmatched72 = true; - if (unmatched72) { - if (_source72.is_Some) { - Dafny.ISequence _1571_id = _source72.dtor_value; - unmatched72 = false; + Std.Wrappers._IOption> _source75 = selfIdent; + bool unmatched75 = true; + if (unmatched75) { + if (_source75.is_Some) { + Dafny.ISequence _1713_id = _source75.dtor_value; + unmatched75 = false; { - r = RAST.Expr.create_RawExpr(_1571_id); + r = RAST.Expr.create_Identifier(_1713_id); if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwned())) { r = RAST.__default.Clone(r); resultingOwnership = DCOMP.Ownership.create_OwnershipOwned(); + } else if (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipOwnedBox())) { + r = RAST.__default.BoxNew(RAST.__default.Clone(r)); + resultingOwnership = DCOMP.Ownership.create_OwnershipOwnedBox(); } else if ((object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipBorrowed())) || (object.Equals(expectedOwnership, DCOMP.Ownership.create_OwnershipAutoBorrowed()))) { - if (!(_1571_id).Equals(Dafny.Sequence.UnicodeFromString("self"))) { + if (!(_1713_id).Equals(Dafny.Sequence.UnicodeFromString("self"))) { r = RAST.__default.Borrow(r); } resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); } else { - if (!(_1571_id).Equals(Dafny.Sequence.UnicodeFromString("self"))) { + if (!(_1713_id).Equals(Dafny.Sequence.UnicodeFromString("self"))) { r = RAST.__default.BorrowMut(r); } resultingOwnership = DCOMP.Ownership.create_OwnershipBorrowedMut(); } - readIdents = Dafny.Set>.FromElements(_1571_id); + readIdents = Dafny.Set>.FromElements(_1713_id); } } } - if (unmatched72) { - unmatched72 = false; + if (unmatched75) { + unmatched75 = false; { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("panic!(\"this outside of a method\")")); - RAST._IExpr _out358; - DCOMP._IOwnership _out359; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out358, out _out359); - r = _out358; - resultingOwnership = _out359; + RAST._IExpr _out401; + DCOMP._IOwnership _out402; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out401, out _out402); + r = _out401; + resultingOwnership = _out402; readIdents = Dafny.Set>.FromElements(); } } @@ -3913,1115 +4423,1168 @@ public void GenExpr(DAST._IExpression e, Std.Wrappers._IOption> _1577_recIdentsCond; - RAST._IExpr _out360; - DCOMP._IOwnership _out361; - Dafny.ISet> _out362; - (this).GenExpr(_1572_cond, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out360, out _out361, out _out362); - _1575_cond = _out360; - _1576___v105 = _out361; - _1577_recIdentsCond = _out362; - Dafny.ISequence _1578_condString; - _1578_condString = (_1575_cond)._ToString(DCOMP.__default.IND); - RAST._IExpr _1579___v106; - DCOMP._IOwnership _1580_tHasToBeOwned; - Dafny.ISet> _1581___v107; - RAST._IExpr _out363; - DCOMP._IOwnership _out364; - Dafny.ISet> _out365; - (this).GenExpr(_1573_t, selfIdent, @params, expectedOwnership, out _out363, out _out364, out _out365); - _1579___v106 = _out363; - _1580_tHasToBeOwned = _out364; - _1581___v107 = _out365; - RAST._IExpr _1582_fExpr; - DCOMP._IOwnership _1583_fOwned; - Dafny.ISet> _1584_recIdentsF; - RAST._IExpr _out366; - DCOMP._IOwnership _out367; - Dafny.ISet> _out368; - (this).GenExpr(_1574_f, selfIdent, @params, _1580_tHasToBeOwned, out _out366, out _out367, out _out368); - _1582_fExpr = _out366; - _1583_fOwned = _out367; - _1584_recIdentsF = _out368; - Dafny.ISequence _1585_fString; - _1585_fString = (_1582_fExpr)._ToString(DCOMP.__default.IND); - RAST._IExpr _1586_tExpr; - DCOMP._IOwnership _1587___v108; - Dafny.ISet> _1588_recIdentsT; - RAST._IExpr _out369; - DCOMP._IOwnership _out370; - Dafny.ISet> _out371; - (this).GenExpr(_1573_t, selfIdent, @params, _1583_fOwned, out _out369, out _out370, out _out371); - _1586_tExpr = _out369; - _1587___v108 = _out370; - _1588_recIdentsT = _out371; - Dafny.ISequence _1589_tString; - _1589_tString = (_1586_tExpr)._ToString(DCOMP.__default.IND); - 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.UnicodeFromString("(if "), _1578_condString), Dafny.Sequence.UnicodeFromString(" {\n")), _1589_tString), Dafny.Sequence.UnicodeFromString("\n} else {\n")), _1585_fString), Dafny.Sequence.UnicodeFromString("\n})"))); - RAST._IExpr _out372; - DCOMP._IOwnership _out373; - DCOMP.COMP.FromOwnership(r, _1583_fOwned, expectedOwnership, out _out372, out _out373); - r = _out372; - resultingOwnership = _out373; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_1577_recIdentsCond, _1588_recIdentsT), _1584_recIdentsF); + RAST._IExpr _1717_cond; + DCOMP._IOwnership _1718___v125; + Dafny.ISet> _1719_recIdentsCond; + RAST._IExpr _out403; + DCOMP._IOwnership _out404; + Dafny.ISet> _out405; + (this).GenExpr(_1714_cond, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out403, out _out404, out _out405); + _1717_cond = _out403; + _1718___v125 = _out404; + _1719_recIdentsCond = _out405; + Dafny.ISequence _1720_condString; + _1720_condString = (_1717_cond)._ToString(DCOMP.__default.IND); + RAST._IExpr _1721___v126; + DCOMP._IOwnership _1722_tHasToBeOwned; + Dafny.ISet> _1723___v127; + RAST._IExpr _out406; + DCOMP._IOwnership _out407; + Dafny.ISet> _out408; + (this).GenExpr(_1715_t, selfIdent, env, expectedOwnership, out _out406, out _out407, out _out408); + _1721___v126 = _out406; + _1722_tHasToBeOwned = _out407; + _1723___v127 = _out408; + RAST._IExpr _1724_fExpr; + DCOMP._IOwnership _1725_fOwned; + Dafny.ISet> _1726_recIdentsF; + RAST._IExpr _out409; + DCOMP._IOwnership _out410; + Dafny.ISet> _out411; + (this).GenExpr(_1716_f, selfIdent, env, _1722_tHasToBeOwned, out _out409, out _out410, out _out411); + _1724_fExpr = _out409; + _1725_fOwned = _out410; + _1726_recIdentsF = _out411; + Dafny.ISequence _1727_fString; + _1727_fString = (_1724_fExpr)._ToString(DCOMP.__default.IND); + RAST._IExpr _1728_tExpr; + DCOMP._IOwnership _1729___v128; + Dafny.ISet> _1730_recIdentsT; + RAST._IExpr _out412; + DCOMP._IOwnership _out413; + Dafny.ISet> _out414; + (this).GenExpr(_1715_t, selfIdent, env, _1725_fOwned, out _out412, out _out413, out _out414); + _1728_tExpr = _out412; + _1729___v128 = _out413; + _1730_recIdentsT = _out414; + Dafny.ISequence _1731_tString; + _1731_tString = (_1728_tExpr)._ToString(DCOMP.__default.IND); + 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.UnicodeFromString("(if "), _1720_condString), Dafny.Sequence.UnicodeFromString(" {\n")), _1731_tString), Dafny.Sequence.UnicodeFromString("\n} else {\n")), _1727_fString), Dafny.Sequence.UnicodeFromString("\n})"))); + RAST._IExpr _out415; + DCOMP._IOwnership _out416; + DCOMP.COMP.FromOwnership(r, _1725_fOwned, expectedOwnership, out _out415, out _out416); + r = _out415; + resultingOwnership = _out416; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_1719_recIdentsCond, _1730_recIdentsT), _1726_recIdentsF); return ; } } } - if (unmatched71) { - if (_source71.is_UnOp) { - DAST._IUnaryOp unOp0 = _source71.dtor_unOp; + if (unmatched74) { + if (_source74.is_UnOp) { + DAST._IUnaryOp unOp0 = _source74.dtor_unOp; if (unOp0.is_Not) { - DAST._IExpression _1590_e = _source71.dtor_expr; - DAST.Format._IUnaryOpFormat _1591_format = _source71.dtor_format1; - unmatched71 = false; + DAST._IExpression _1732_e = _source74.dtor_expr; + DAST.Format._IUnaryOpFormat _1733_format = _source74.dtor_format1; + unmatched74 = false; { - RAST._IExpr _1592_recursiveGen; - DCOMP._IOwnership _1593___v109; - Dafny.ISet> _1594_recIdents; - RAST._IExpr _out374; - DCOMP._IOwnership _out375; - Dafny.ISet> _out376; - (this).GenExpr(_1590_e, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out374, out _out375, out _out376); - _1592_recursiveGen = _out374; - _1593___v109 = _out375; - _1594_recIdents = _out376; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _1592_recursiveGen, _1591_format); - RAST._IExpr _out377; - DCOMP._IOwnership _out378; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out377, out _out378); - r = _out377; - resultingOwnership = _out378; - readIdents = _1594_recIdents; + RAST._IExpr _1734_recursiveGen; + DCOMP._IOwnership _1735___v129; + Dafny.ISet> _1736_recIdents; + RAST._IExpr _out417; + DCOMP._IOwnership _out418; + Dafny.ISet> _out419; + (this).GenExpr(_1732_e, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out417, out _out418, out _out419); + _1734_recursiveGen = _out417; + _1735___v129 = _out418; + _1736_recIdents = _out419; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _1734_recursiveGen, _1733_format); + RAST._IExpr _out420; + DCOMP._IOwnership _out421; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out420, out _out421); + r = _out420; + resultingOwnership = _out421; + readIdents = _1736_recIdents; return ; } } } } - if (unmatched71) { - if (_source71.is_UnOp) { - DAST._IUnaryOp unOp1 = _source71.dtor_unOp; + if (unmatched74) { + if (_source74.is_UnOp) { + DAST._IUnaryOp unOp1 = _source74.dtor_unOp; if (unOp1.is_BitwiseNot) { - DAST._IExpression _1595_e = _source71.dtor_expr; - DAST.Format._IUnaryOpFormat _1596_format = _source71.dtor_format1; - unmatched71 = false; + DAST._IExpression _1737_e = _source74.dtor_expr; + DAST.Format._IUnaryOpFormat _1738_format = _source74.dtor_format1; + unmatched74 = false; { - RAST._IExpr _1597_recursiveGen; - DCOMP._IOwnership _1598___v110; - Dafny.ISet> _1599_recIdents; - RAST._IExpr _out379; - DCOMP._IOwnership _out380; - Dafny.ISet> _out381; - (this).GenExpr(_1595_e, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out379, out _out380, out _out381); - _1597_recursiveGen = _out379; - _1598___v110 = _out380; - _1599_recIdents = _out381; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("~"), _1597_recursiveGen, _1596_format); - RAST._IExpr _out382; - DCOMP._IOwnership _out383; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out382, out _out383); - r = _out382; - resultingOwnership = _out383; - readIdents = _1599_recIdents; + RAST._IExpr _1739_recursiveGen; + DCOMP._IOwnership _1740___v130; + Dafny.ISet> _1741_recIdents; + RAST._IExpr _out422; + DCOMP._IOwnership _out423; + Dafny.ISet> _out424; + (this).GenExpr(_1737_e, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out422, out _out423, out _out424); + _1739_recursiveGen = _out422; + _1740___v130 = _out423; + _1741_recIdents = _out424; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("~"), _1739_recursiveGen, _1738_format); + RAST._IExpr _out425; + DCOMP._IOwnership _out426; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out425, out _out426); + r = _out425; + resultingOwnership = _out426; + readIdents = _1741_recIdents; return ; } } } } - if (unmatched71) { - if (_source71.is_UnOp) { - DAST._IUnaryOp unOp2 = _source71.dtor_unOp; + if (unmatched74) { + if (_source74.is_UnOp) { + DAST._IUnaryOp unOp2 = _source74.dtor_unOp; if (unOp2.is_Cardinality) { - DAST._IExpression _1600_e = _source71.dtor_expr; - DAST.Format._IUnaryOpFormat _1601_format = _source71.dtor_format1; - unmatched71 = false; + DAST._IExpression _1742_e = _source74.dtor_expr; + DAST.Format._IUnaryOpFormat _1743_format = _source74.dtor_format1; + unmatched74 = false; { - RAST._IExpr _1602_recursiveGen; - DCOMP._IOwnership _1603_recOwned; - Dafny.ISet> _1604_recIdents; - RAST._IExpr _out384; - DCOMP._IOwnership _out385; - Dafny.ISet> _out386; - (this).GenExpr(_1600_e, selfIdent, @params, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out384, out _out385, out _out386); - _1602_recursiveGen = _out384; - _1603_recOwned = _out385; - _1604_recIdents = _out386; - r = ((_1602_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply(Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); - RAST._IExpr _out387; - DCOMP._IOwnership _out388; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out387, out _out388); - r = _out387; - resultingOwnership = _out388; - readIdents = _1604_recIdents; + RAST._IExpr _1744_recursiveGen; + DCOMP._IOwnership _1745_recOwned; + Dafny.ISet> _1746_recIdents; + RAST._IExpr _out427; + DCOMP._IOwnership _out428; + Dafny.ISet> _out429; + (this).GenExpr(_1742_e, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out427, out _out428, out _out429); + _1744_recursiveGen = _out427; + _1745_recOwned = _out428; + _1746_recIdents = _out429; + r = ((_1744_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out430; + DCOMP._IOwnership _out431; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out430, out _out431); + r = _out430; + resultingOwnership = _out431; + readIdents = _1746_recIdents; return ; } } } } - if (unmatched71) { - if (_source71.is_BinOp) { - DAST._IBinOp _1605___v111 = _source71.dtor_op; - DAST._IExpression _1606___v112 = _source71.dtor_left; - DAST._IExpression _1607___v113 = _source71.dtor_right; - DAST.Format._IBinaryOpFormat _1608___v114 = _source71.dtor_format2; - unmatched71 = false; - RAST._IExpr _out389; - DCOMP._IOwnership _out390; - Dafny.ISet> _out391; - (this).GenExprBinary(e, selfIdent, @params, expectedOwnership, out _out389, out _out390, out _out391); - r = _out389; - resultingOwnership = _out390; - readIdents = _out391; - } - } - if (unmatched71) { - if (_source71.is_ArrayLen) { - DAST._IExpression _1609_expr = _source71.dtor_expr; - BigInteger _1610_dim = _source71.dtor_dim; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_BinOp) { + DAST._IBinOp _1747___v131 = _source74.dtor_op; + DAST._IExpression _1748___v132 = _source74.dtor_left; + DAST._IExpression _1749___v133 = _source74.dtor_right; + DAST.Format._IBinaryOpFormat _1750___v134 = _source74.dtor_format2; + unmatched74 = false; + RAST._IExpr _out432; + DCOMP._IOwnership _out433; + Dafny.ISet> _out434; + (this).GenExprBinary(e, selfIdent, env, expectedOwnership, out _out432, out _out433, out _out434); + r = _out432; + resultingOwnership = _out433; + readIdents = _out434; + } + } + if (unmatched74) { + if (_source74.is_ArrayLen) { + DAST._IExpression _1751_expr = _source74.dtor_expr; + BigInteger _1752_dim = _source74.dtor_dim; + unmatched74 = false; { - RAST._IExpr _1611_recursiveGen; - DCOMP._IOwnership _1612___v115; - Dafny.ISet> _1613_recIdents; - RAST._IExpr _out392; - DCOMP._IOwnership _out393; - Dafny.ISet> _out394; - (this).GenExpr(_1609_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out392, out _out393, out _out394); - _1611_recursiveGen = _out392; - _1612___v115 = _out393; - _1613_recIdents = _out394; - if ((_1610_dim).Sign == 0) { - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::BigInt::from(("), (_1611_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").borrow().len())"))); + RAST._IExpr _1753_recursiveGen; + DCOMP._IOwnership _1754___v135; + Dafny.ISet> _1755_recIdents; + RAST._IExpr _out435; + DCOMP._IOwnership _out436; + Dafny.ISet> _out437; + (this).GenExpr(_1751_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out435, out _out436, out _out437); + _1753_recursiveGen = _out435; + _1754___v135 = _out436; + _1755_recIdents = _out437; + if ((_1752_dim).Sign == 0) { + r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::BigInt::from(("), (_1753_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").borrow().len())"))); } else { - Dafny.ISequence _1614_s; - _1614_s = (RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::dafny_runtime::BigInt::from(m.borrow().len())")))._ToString(DCOMP.__default.IND); - BigInteger _1615_i; - _1615_i = BigInteger.One; - while ((_1615_i) < (_1610_dim)) { - _1614_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("m.borrow().get(0).map(|m| "), _1614_s), Dafny.Sequence.UnicodeFromString(").unwrap_or(::dafny_runtime::BigInt::from(0))")); - _1615_i = (_1615_i) + (BigInteger.One); + Dafny.ISequence _1756_s; + _1756_s = (RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("::dafny_runtime::BigInt::from(m.borrow().len())")))._ToString(DCOMP.__default.IND); + BigInteger _1757_i; + _1757_i = BigInteger.One; + while ((_1757_i) < (_1752_dim)) { + _1756_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("m.borrow().get(0).map(|m| "), _1756_s), Dafny.Sequence.UnicodeFromString(").unwrap_or(::dafny_runtime::BigInt::from(0))")); + _1757_i = (_1757_i) + (BigInteger.One); } - r = RAST.__default.RcNew(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), (_1611_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")), Dafny.Sequence.UnicodeFromString(".borrow().get(0).map(|m| ")), _1614_s), Dafny.Sequence.UnicodeFromString(").unwrap_or(::dafny_runtime::BigInt::from(0))")))); + r = RAST.__default.RcNew(RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), (_1753_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")), Dafny.Sequence.UnicodeFromString(".borrow().get(0).map(|m| ")), _1756_s), Dafny.Sequence.UnicodeFromString(").unwrap_or(::dafny_runtime::BigInt::from(0))")))); } - RAST._IExpr _out395; - DCOMP._IOwnership _out396; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out395, out _out396); - r = _out395; - resultingOwnership = _out396; - readIdents = _1613_recIdents; + RAST._IExpr _out438; + DCOMP._IOwnership _out439; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out438, out _out439); + r = _out438; + resultingOwnership = _out439; + readIdents = _1755_recIdents; return ; } } } - if (unmatched71) { - if (_source71.is_MapKeys) { - DAST._IExpression _1616_expr = _source71.dtor_expr; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_MapKeys) { + DAST._IExpression _1758_expr = _source74.dtor_expr; + unmatched74 = false; { - RAST._IExpr _1617_recursiveGen; - DCOMP._IOwnership _1618___v116; - Dafny.ISet> _1619_recIdents; - RAST._IExpr _out397; - DCOMP._IOwnership _out398; - Dafny.ISet> _out399; - (this).GenExpr(_1616_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out397, out _out398, out _out399); - _1617_recursiveGen = _out397; - _1618___v116 = _out398; - _1619_recIdents = _out399; - readIdents = _1619_recIdents; - r = RAST.Expr.create_Call((_1617_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); - RAST._IExpr _out400; - DCOMP._IOwnership _out401; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out400, out _out401); - r = _out400; - resultingOwnership = _out401; + RAST._IExpr _1759_recursiveGen; + DCOMP._IOwnership _1760___v136; + Dafny.ISet> _1761_recIdents; + RAST._IExpr _out440; + DCOMP._IOwnership _out441; + Dafny.ISet> _out442; + (this).GenExpr(_1758_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out440, out _out441, out _out442); + _1759_recursiveGen = _out440; + _1760___v136 = _out441; + _1761_recIdents = _out442; + readIdents = _1761_recIdents; + r = ((_1759_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out443; + DCOMP._IOwnership _out444; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out443, out _out444); + r = _out443; + resultingOwnership = _out444; return ; } } } - if (unmatched71) { - if (_source71.is_MapValues) { - DAST._IExpression _1620_expr = _source71.dtor_expr; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_MapValues) { + DAST._IExpression _1762_expr = _source74.dtor_expr; + unmatched74 = false; { - RAST._IExpr _1621_recursiveGen; - DCOMP._IOwnership _1622___v117; - Dafny.ISet> _1623_recIdents; - RAST._IExpr _out402; - DCOMP._IOwnership _out403; - Dafny.ISet> _out404; - (this).GenExpr(_1620_expr, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out402, out _out403, out _out404); - _1621_recursiveGen = _out402; - _1622___v117 = _out403; - _1623_recIdents = _out404; - readIdents = _1623_recIdents; - r = RAST.Expr.create_Call((_1621_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); - RAST._IExpr _out405; - DCOMP._IOwnership _out406; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out405, out _out406); - r = _out405; - resultingOwnership = _out406; + RAST._IExpr _1763_recursiveGen; + DCOMP._IOwnership _1764___v137; + Dafny.ISet> _1765_recIdents; + RAST._IExpr _out445; + DCOMP._IOwnership _out446; + Dafny.ISet> _out447; + (this).GenExpr(_1762_expr, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out445, out _out446, out _out447); + _1763_recursiveGen = _out445; + _1764___v137 = _out446; + _1765_recIdents = _out447; + readIdents = _1765_recIdents; + r = ((_1763_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out448; + DCOMP._IOwnership _out449; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out448, out _out449); + r = _out448; + resultingOwnership = _out449; return ; } } } - if (unmatched71) { - if (_source71.is_SelectFn) { - DAST._IExpression _1624_on = _source71.dtor_expr; - Dafny.ISequence _1625_field = _source71.dtor_field; - bool _1626_isDatatype = _source71.dtor_onDatatype; - bool _1627_isStatic = _source71.dtor_isStatic; - BigInteger _1628_arity = _source71.dtor_arity; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_SelectFn) { + DAST._IExpression _1766_on = _source74.dtor_expr; + Dafny.ISequence _1767_field = _source74.dtor_field; + bool _1768_isDatatype = _source74.dtor_onDatatype; + bool _1769_isStatic = _source74.dtor_isStatic; + BigInteger _1770_arity = _source74.dtor_arity; + unmatched74 = false; { - RAST._IExpr _1629_onExpr; - DCOMP._IOwnership _1630_onOwned; - Dafny.ISet> _1631_recIdents; - RAST._IExpr _out407; - DCOMP._IOwnership _out408; - Dafny.ISet> _out409; - (this).GenExpr(_1624_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out407, out _out408, out _out409); - _1629_onExpr = _out407; - _1630_onOwned = _out408; - _1631_recIdents = _out409; - Dafny.ISequence _1632_s = Dafny.Sequence.Empty; - Dafny.ISequence _1633_onString; - _1633_onString = (_1629_onExpr)._ToString(DCOMP.__default.IND); - if (_1627_isStatic) { - _1632_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1633_onString, Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeIdent(_1625_field)); + RAST._IExpr _1771_onExpr; + DCOMP._IOwnership _1772_onOwned; + Dafny.ISet> _1773_recIdents; + RAST._IExpr _out450; + DCOMP._IOwnership _out451; + Dafny.ISet> _out452; + (this).GenExpr(_1766_on, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out450, out _out451, out _out452); + _1771_onExpr = _out450; + _1772_onOwned = _out451; + _1773_recIdents = _out452; + Dafny.ISequence _1774_s = Dafny.Sequence.Empty; + Dafny.ISequence _1775_onString; + _1775_onString = (_1771_onExpr)._ToString(DCOMP.__default.IND); + if (_1769_isStatic) { + _1774_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1775_onString, Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeName(_1767_field)); } else { - _1632_s = Dafny.Sequence.UnicodeFromString("{\n"); - _1632_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1632_s, Dafny.Sequence.UnicodeFromString("let callTarget = (")), _1633_onString), ((object.Equals(_1630_onOwned, DCOMP.Ownership.create_OwnershipOwned())) ? (Dafny.Sequence.UnicodeFromString(")")) : (Dafny.Sequence.UnicodeFromString(").clone()")))), Dafny.Sequence.UnicodeFromString(";\n")); - Dafny.ISequence _1634_args; - _1634_args = Dafny.Sequence.UnicodeFromString(""); - BigInteger _1635_i; - _1635_i = BigInteger.Zero; - while ((_1635_i) < (_1628_arity)) { - if ((_1635_i).Sign == 1) { - _1634_args = Dafny.Sequence.Concat(_1634_args, Dafny.Sequence.UnicodeFromString(", ")); + _1774_s = Dafny.Sequence.UnicodeFromString("{\n"); + _1774_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1774_s, Dafny.Sequence.UnicodeFromString("let callTarget = (")), _1775_onString), ((object.Equals(_1772_onOwned, DCOMP.Ownership.create_OwnershipOwned())) ? (Dafny.Sequence.UnicodeFromString(")")) : (Dafny.Sequence.UnicodeFromString(").clone()")))), Dafny.Sequence.UnicodeFromString(";\n")); + Dafny.ISequence _1776_args; + _1776_args = Dafny.Sequence.UnicodeFromString(""); + BigInteger _1777_i; + _1777_i = BigInteger.Zero; + while ((_1777_i) < (_1770_arity)) { + if ((_1777_i).Sign == 1) { + _1776_args = Dafny.Sequence.Concat(_1776_args, Dafny.Sequence.UnicodeFromString(", ")); } - _1634_args = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1634_args, Dafny.Sequence.UnicodeFromString("arg")), Std.Strings.__default.OfNat(_1635_i)); - _1635_i = (_1635_i) + (BigInteger.One); + _1776_args = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1776_args, Dafny.Sequence.UnicodeFromString("arg")), Std.Strings.__default.OfNat(_1777_i)); + _1777_i = (_1777_i) + (BigInteger.One); } - _1632_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1632_s, Dafny.Sequence.UnicodeFromString("move |")), _1634_args), Dafny.Sequence.UnicodeFromString("| {\n")); - _1632_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1632_s, Dafny.Sequence.UnicodeFromString("callTarget.")), _1625_field), Dafny.Sequence.UnicodeFromString("(")), _1634_args), Dafny.Sequence.UnicodeFromString(")\n")); - _1632_s = Dafny.Sequence.Concat(_1632_s, Dafny.Sequence.UnicodeFromString("}\n")); - _1632_s = Dafny.Sequence.Concat(_1632_s, Dafny.Sequence.UnicodeFromString("}")); + _1774_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1774_s, Dafny.Sequence.UnicodeFromString("move |")), _1776_args), Dafny.Sequence.UnicodeFromString("| {\n")); + _1774_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1774_s, Dafny.Sequence.UnicodeFromString("callTarget.")), DCOMP.__default.escapeName(_1767_field)), Dafny.Sequence.UnicodeFromString("(")), _1776_args), Dafny.Sequence.UnicodeFromString(")\n")); + _1774_s = Dafny.Sequence.Concat(_1774_s, Dafny.Sequence.UnicodeFromString("}\n")); + _1774_s = Dafny.Sequence.Concat(_1774_s, Dafny.Sequence.UnicodeFromString("}")); } - Dafny.ISequence _1636_typeShape; - _1636_typeShape = Dafny.Sequence.UnicodeFromString("dyn ::std::ops::Fn("); - BigInteger _1637_i; - _1637_i = BigInteger.Zero; - while ((_1637_i) < (_1628_arity)) { - if ((_1637_i).Sign == 1) { - _1636_typeShape = Dafny.Sequence.Concat(_1636_typeShape, Dafny.Sequence.UnicodeFromString(", ")); + Dafny.ISequence _1778_typeShape; + _1778_typeShape = Dafny.Sequence.UnicodeFromString("dyn ::std::ops::Fn("); + BigInteger _1779_i; + _1779_i = BigInteger.Zero; + while ((_1779_i) < (_1770_arity)) { + if ((_1779_i).Sign == 1) { + _1778_typeShape = Dafny.Sequence.Concat(_1778_typeShape, Dafny.Sequence.UnicodeFromString(", ")); } - _1636_typeShape = Dafny.Sequence.Concat(_1636_typeShape, Dafny.Sequence.UnicodeFromString("&_")); - _1637_i = (_1637_i) + (BigInteger.One); + _1778_typeShape = Dafny.Sequence.Concat(_1778_typeShape, Dafny.Sequence.UnicodeFromString("&_")); + _1779_i = (_1779_i) + (BigInteger.One); } - _1636_typeShape = Dafny.Sequence.Concat(_1636_typeShape, Dafny.Sequence.UnicodeFromString(") -> _")); - _1632_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::FunctionWrapper(::std::rc::Rc::new("), _1632_s), Dafny.Sequence.UnicodeFromString(") as ::std::rc::Rc<")), _1636_typeShape), Dafny.Sequence.UnicodeFromString(">)")); - r = RAST.Expr.create_RawExpr(_1632_s); - RAST._IExpr _out410; - DCOMP._IOwnership _out411; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out410, out _out411); - r = _out410; - resultingOwnership = _out411; - readIdents = _1631_recIdents; + _1778_typeShape = Dafny.Sequence.Concat(_1778_typeShape, Dafny.Sequence.UnicodeFromString(") -> _")); + _1774_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::rc::Rc::new("), _1774_s), Dafny.Sequence.UnicodeFromString(") as ::std::rc::Rc<")), _1778_typeShape), Dafny.Sequence.UnicodeFromString(">")); + r = RAST.Expr.create_RawExpr(_1774_s); + RAST._IExpr _out453; + DCOMP._IOwnership _out454; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out453, out _out454); + r = _out453; + resultingOwnership = _out454; + readIdents = _1773_recIdents; return ; } } } - if (unmatched71) { - if (_source71.is_Select) { - DAST._IExpression expr0 = _source71.dtor_expr; + if (unmatched74) { + if (_source74.is_Select) { + DAST._IExpression expr0 = _source74.dtor_expr; if (expr0.is_Companion) { - Dafny.ISequence> _1638_c = expr0.dtor_Companion_a0; - Dafny.ISequence _1639_field = _source71.dtor_field; - bool _1640_isConstant = _source71.dtor_isConstant; - bool _1641_isDatatype = _source71.dtor_onDatatype; - unmatched71 = false; + Dafny.ISequence> _1780_c = expr0.dtor_Companion_a0; + Dafny.ISequence _1781_field = _source74.dtor_field; + bool _1782_isConstant = _source74.dtor_isConstant; + bool _1783_isDatatype = _source74.dtor_onDatatype; + DAST._IType _1784_fieldType = _source74.dtor_fieldType; + unmatched74 = false; { - RAST._IExpr _1642_onExpr; - DCOMP._IOwnership _1643_onOwned; - Dafny.ISet> _1644_recIdents; - RAST._IExpr _out412; - DCOMP._IOwnership _out413; - Dafny.ISet> _out414; - (this).GenExpr(DAST.Expression.create_Companion(_1638_c), selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out412, out _out413, out _out414); - _1642_onExpr = _out412; - _1643_onOwned = _out413; - _1644_recIdents = _out414; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_1642_onExpr)._ToString(DCOMP.__default.IND), Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeIdent(_1639_field)), Dafny.Sequence.UnicodeFromString("()"))); - RAST._IExpr _out415; - DCOMP._IOwnership _out416; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out415, out _out416); - r = _out415; - resultingOwnership = _out416; - readIdents = _1644_recIdents; + RAST._IExpr _1785_onExpr; + DCOMP._IOwnership _1786_onOwned; + Dafny.ISet> _1787_recIdents; + RAST._IExpr _out455; + DCOMP._IOwnership _out456; + Dafny.ISet> _out457; + (this).GenExpr(DAST.Expression.create_Companion(_1780_c), selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out455, out _out456, out _out457); + _1785_onExpr = _out455; + _1786_onOwned = _out456; + _1787_recIdents = _out457; + r = ((_1785_onExpr).MSel(DCOMP.__default.escapeName(_1781_field))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out458; + DCOMP._IOwnership _out459; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out458, out _out459); + r = _out458; + resultingOwnership = _out459; + readIdents = _1787_recIdents; return ; } } } } - if (unmatched71) { - if (_source71.is_Select) { - DAST._IExpression _1645_on = _source71.dtor_expr; - Dafny.ISequence _1646_field = _source71.dtor_field; - bool _1647_isConstant = _source71.dtor_isConstant; - bool _1648_isDatatype = _source71.dtor_onDatatype; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_Select) { + DAST._IExpression _1788_on = _source74.dtor_expr; + Dafny.ISequence _1789_field = _source74.dtor_field; + bool _1790_isConstant = _source74.dtor_isConstant; + bool _1791_isDatatype = _source74.dtor_onDatatype; + DAST._IType _1792_fieldType = _source74.dtor_fieldType; + unmatched74 = false; { - RAST._IExpr _1649_onExpr; - DCOMP._IOwnership _1650_onOwned; - Dafny.ISet> _1651_recIdents; - RAST._IExpr _out417; - DCOMP._IOwnership _out418; - Dafny.ISet> _out419; - (this).GenExpr(_1645_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out417, out _out418, out _out419); - _1649_onExpr = _out417; - _1650_onOwned = _out418; - _1651_recIdents = _out419; - if ((_1648_isDatatype) || (_1647_isConstant)) { - r = RAST.Expr.create_Call((_1649_onExpr).Sel(DCOMP.__default.escapeIdent(_1646_field)), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); - RAST._IExpr _out420; - DCOMP._IOwnership _out421; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out420, out _out421); - r = _out420; - resultingOwnership = _out421; + if (_1791_isDatatype) { + RAST._IExpr _1793_onExpr; + DCOMP._IOwnership _1794_onOwned; + Dafny.ISet> _1795_recIdents; + RAST._IExpr _out460; + DCOMP._IOwnership _out461; + Dafny.ISet> _out462; + (this).GenExpr(_1788_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out460, out _out461, out _out462); + _1793_onExpr = _out460; + _1794_onOwned = _out461; + _1795_recIdents = _out462; + r = ((_1793_onExpr).Sel(DCOMP.__default.escapeName(_1789_field))).Apply(Dafny.Sequence.FromElements()); + RAST._IType _1796_typ; + RAST._IType _out463; + _out463 = (this).GenType(_1792_fieldType, false, false); + _1796_typ = _out463; + RAST._IExpr _out464; + DCOMP._IOwnership _out465; + DCOMP.COMP.FromOwnership(r, DCOMP.Ownership.create_OwnershipBorrowed(), expectedOwnership, out _out464, out _out465); + r = _out464; + resultingOwnership = _out465; + readIdents = _1795_recIdents; } else { - Dafny.ISequence _1652_s = Dafny.Sequence.Empty; - _1652_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Deref::deref(&(("), (_1649_onExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")), Dafny.Sequence.UnicodeFromString(".")), DCOMP.__default.escapeIdent(_1646_field)), Dafny.Sequence.UnicodeFromString(".borrow()))")); - RAST._IExpr _out422; - DCOMP._IOwnership _out423; - DCOMP.COMP.FromOwnership(RAST.Expr.create_RawExpr(_1652_s), DCOMP.Ownership.create_OwnershipBorrowed(), expectedOwnership, out _out422, out _out423); - r = _out422; - resultingOwnership = _out423; + RAST._IExpr _1797_onExpr; + DCOMP._IOwnership _1798_onOwned; + Dafny.ISet> _1799_recIdents; + RAST._IExpr _out466; + DCOMP._IOwnership _out467; + Dafny.ISet> _out468; + (this).GenExpr(_1788_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out466, out _out467, out _out468); + _1797_onExpr = _out466; + _1798_onOwned = _out467; + _1799_recIdents = _out468; + r = _1797_onExpr; + r = (r).Sel(DCOMP.__default.escapeName(_1789_field)); + if (_1790_isConstant) { + r = (r).Apply(Dafny.Sequence.FromElements()); + } else { + Dafny.ISequence _1800_s; + _1800_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Deref::deref(&(("), (_1797_onExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")")), Dafny.Sequence.UnicodeFromString(".")), DCOMP.__default.escapeName(_1789_field)), Dafny.Sequence.UnicodeFromString(".borrow()))")); + r = RAST.Expr.create_RawExpr(_1800_s); + } + DCOMP._IOwnership _1801_fromOwnership; + _1801_fromOwnership = ((_1790_isConstant) ? (DCOMP.Ownership.create_OwnershipOwned()) : (DCOMP.Ownership.create_OwnershipBorrowed())); + RAST._IExpr _out469; + DCOMP._IOwnership _out470; + DCOMP.COMP.FromOwnership(r, _1801_fromOwnership, expectedOwnership, out _out469, out _out470); + r = _out469; + resultingOwnership = _out470; + readIdents = _1799_recIdents; } - readIdents = _1651_recIdents; return ; } } } - if (unmatched71) { - if (_source71.is_Index) { - DAST._IExpression _1653_on = _source71.dtor_expr; - DAST._ICollKind _1654_collKind = _source71.dtor_collKind; - Dafny.ISequence _1655_indices = _source71.dtor_indices; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_Index) { + DAST._IExpression _1802_on = _source74.dtor_expr; + DAST._ICollKind _1803_collKind = _source74.dtor_collKind; + Dafny.ISequence _1804_indices = _source74.dtor_indices; + unmatched74 = false; { - RAST._IExpr _1656_onExpr; - DCOMP._IOwnership _1657_onOwned; - Dafny.ISet> _1658_recIdents; - RAST._IExpr _out424; - DCOMP._IOwnership _out425; - Dafny.ISet> _out426; - (this).GenExpr(_1653_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out424, out _out425, out _out426); - _1656_onExpr = _out424; - _1657_onOwned = _out425; - _1658_recIdents = _out426; - readIdents = _1658_recIdents; - r = _1656_onExpr; - BigInteger _1659_i; - _1659_i = BigInteger.Zero; - while ((_1659_i) < (new BigInteger((_1655_indices).Count))) { - if (object.Equals(_1654_collKind, DAST.CollKind.create_Array())) { - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("borrow"))).Apply(Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); + RAST._IExpr _1805_onExpr; + DCOMP._IOwnership _1806_onOwned; + Dafny.ISet> _1807_recIdents; + RAST._IExpr _out471; + DCOMP._IOwnership _out472; + Dafny.ISet> _out473; + (this).GenExpr(_1802_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out471, out _out472, out _out473); + _1805_onExpr = _out471; + _1806_onOwned = _out472; + _1807_recIdents = _out473; + readIdents = _1807_recIdents; + r = _1805_onExpr; + BigInteger _1808_i; + _1808_i = BigInteger.Zero; + while ((_1808_i) < (new BigInteger((_1804_indices).Count))) { + if (object.Equals(_1803_collKind, DAST.CollKind.create_Array())) { + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("borrow"))).Apply(Dafny.Sequence.FromElements()); } - RAST._IExpr _1660_idx; - DCOMP._IOwnership _1661_idxOwned; - Dafny.ISet> _1662_recIdentsIdx; - RAST._IExpr _out427; - DCOMP._IOwnership _out428; - Dafny.ISet> _out429; - (this).GenExpr((_1655_indices).Select(_1659_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out427, out _out428, out _out429); - _1660_idx = _out427; - _1661_idxOwned = _out428; - _1662_recIdentsIdx = _out429; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_1660_idx); - readIdents = Dafny.Set>.Union(readIdents, _1662_recIdentsIdx); - _1659_i = (_1659_i) + (BigInteger.One); + RAST._IExpr _1809_idx; + DCOMP._IOwnership _1810_idxOwned; + Dafny.ISet> _1811_recIdentsIdx; + RAST._IExpr _out474; + DCOMP._IOwnership _out475; + Dafny.ISet> _out476; + (this).GenExpr((_1804_indices).Select(_1808_i), selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out474, out _out475, out _out476); + _1809_idx = _out474; + _1810_idxOwned = _out475; + _1811_recIdentsIdx = _out476; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_1809_idx); + readIdents = Dafny.Set>.Union(readIdents, _1811_recIdentsIdx); + _1808_i = (_1808_i) + (BigInteger.One); } - RAST._IExpr _out430; - DCOMP._IOwnership _out431; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out430, out _out431); - r = _out430; - resultingOwnership = _out431; + RAST._IExpr _out477; + DCOMP._IOwnership _out478; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out477, out _out478); + r = _out477; + resultingOwnership = _out478; return ; } } } - if (unmatched71) { - if (_source71.is_IndexRange) { - DAST._IExpression _1663_on = _source71.dtor_expr; - bool _1664_isArray = _source71.dtor_isArray; - Std.Wrappers._IOption _1665_low = _source71.dtor_low; - Std.Wrappers._IOption _1666_high = _source71.dtor_high; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_IndexRange) { + DAST._IExpression _1812_on = _source74.dtor_expr; + bool _1813_isArray = _source74.dtor_isArray; + Std.Wrappers._IOption _1814_low = _source74.dtor_low; + Std.Wrappers._IOption _1815_high = _source74.dtor_high; + unmatched74 = false; { - RAST._IExpr _1667_onExpr; - DCOMP._IOwnership _1668_onOwned; - Dafny.ISet> _1669_recIdents; - RAST._IExpr _out432; - DCOMP._IOwnership _out433; - Dafny.ISet> _out434; - (this).GenExpr(_1663_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out432, out _out433, out _out434); - _1667_onExpr = _out432; - _1668_onOwned = _out433; - _1669_recIdents = _out434; - readIdents = _1669_recIdents; - Dafny.ISequence _1670_methodName; - _1670_methodName = (((_1665_low).is_Some) ? ((((_1666_high).is_Some) ? (Dafny.Sequence.UnicodeFromString("slice")) : (Dafny.Sequence.UnicodeFromString("drop")))) : ((((_1666_high).is_Some) ? (Dafny.Sequence.UnicodeFromString("take")) : (Dafny.Sequence.UnicodeFromString(""))))); - Dafny.ISequence _1671_arguments; - _1671_arguments = Dafny.Sequence.FromElements(); - Std.Wrappers._IOption _source73 = _1665_low; - bool unmatched73 = true; - if (unmatched73) { - if (_source73.is_Some) { - DAST._IExpression _1672_l = _source73.dtor_value; - unmatched73 = false; + RAST._IExpr _1816_onExpr; + DCOMP._IOwnership _1817_onOwned; + Dafny.ISet> _1818_recIdents; + RAST._IExpr _out479; + DCOMP._IOwnership _out480; + Dafny.ISet> _out481; + (this).GenExpr(_1812_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out479, out _out480, out _out481); + _1816_onExpr = _out479; + _1817_onOwned = _out480; + _1818_recIdents = _out481; + readIdents = _1818_recIdents; + Dafny.ISequence _1819_methodName; + _1819_methodName = (((_1814_low).is_Some) ? ((((_1815_high).is_Some) ? (Dafny.Sequence.UnicodeFromString("slice")) : (Dafny.Sequence.UnicodeFromString("drop")))) : ((((_1815_high).is_Some) ? (Dafny.Sequence.UnicodeFromString("take")) : (Dafny.Sequence.UnicodeFromString(""))))); + Dafny.ISequence _1820_arguments; + _1820_arguments = Dafny.Sequence.FromElements(); + Std.Wrappers._IOption _source76 = _1814_low; + bool unmatched76 = true; + if (unmatched76) { + if (_source76.is_Some) { + DAST._IExpression _1821_l = _source76.dtor_value; + unmatched76 = false; { - RAST._IExpr _1673_lExpr; - DCOMP._IOwnership _1674___v118; - Dafny.ISet> _1675_recIdentsL; - RAST._IExpr _out435; - DCOMP._IOwnership _out436; - Dafny.ISet> _out437; - (this).GenExpr(_1672_l, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out435, out _out436, out _out437); - _1673_lExpr = _out435; - _1674___v118 = _out436; - _1675_recIdentsL = _out437; - _1671_arguments = Dafny.Sequence.Concat(_1671_arguments, Dafny.Sequence.FromElements(_1673_lExpr)); - readIdents = Dafny.Set>.Union(readIdents, _1675_recIdentsL); + RAST._IExpr _1822_lExpr; + DCOMP._IOwnership _1823___v138; + Dafny.ISet> _1824_recIdentsL; + RAST._IExpr _out482; + DCOMP._IOwnership _out483; + Dafny.ISet> _out484; + (this).GenExpr(_1821_l, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out482, out _out483, out _out484); + _1822_lExpr = _out482; + _1823___v138 = _out483; + _1824_recIdentsL = _out484; + _1820_arguments = Dafny.Sequence.Concat(_1820_arguments, Dafny.Sequence.FromElements(_1822_lExpr)); + readIdents = Dafny.Set>.Union(readIdents, _1824_recIdentsL); } } } - if (unmatched73) { - unmatched73 = false; + if (unmatched76) { + unmatched76 = false; } - Std.Wrappers._IOption _source74 = _1666_high; - bool unmatched74 = true; - if (unmatched74) { - if (_source74.is_Some) { - DAST._IExpression _1676_h = _source74.dtor_value; - unmatched74 = false; + Std.Wrappers._IOption _source77 = _1815_high; + bool unmatched77 = true; + if (unmatched77) { + if (_source77.is_Some) { + DAST._IExpression _1825_h = _source77.dtor_value; + unmatched77 = false; { - RAST._IExpr _1677_hExpr; - DCOMP._IOwnership _1678___v119; - Dafny.ISet> _1679_recIdentsH; - RAST._IExpr _out438; - DCOMP._IOwnership _out439; - Dafny.ISet> _out440; - (this).GenExpr(_1676_h, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out438, out _out439, out _out440); - _1677_hExpr = _out438; - _1678___v119 = _out439; - _1679_recIdentsH = _out440; - _1671_arguments = Dafny.Sequence.Concat(_1671_arguments, Dafny.Sequence.FromElements(_1677_hExpr)); - readIdents = Dafny.Set>.Union(readIdents, _1679_recIdentsH); + RAST._IExpr _1826_hExpr; + DCOMP._IOwnership _1827___v139; + Dafny.ISet> _1828_recIdentsH; + RAST._IExpr _out485; + DCOMP._IOwnership _out486; + Dafny.ISet> _out487; + (this).GenExpr(_1825_h, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out485, out _out486, out _out487); + _1826_hExpr = _out485; + _1827___v139 = _out486; + _1828_recIdentsH = _out487; + _1820_arguments = Dafny.Sequence.Concat(_1820_arguments, Dafny.Sequence.FromElements(_1826_hExpr)); + readIdents = Dafny.Set>.Union(readIdents, _1828_recIdentsH); } } } - if (unmatched74) { - unmatched74 = false; + if (unmatched77) { + unmatched77 = false; } - r = _1667_onExpr; - if (_1664_isArray) { - if (!(_1670_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - _1670_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _1670_methodName); + r = _1816_onExpr; + if (_1813_isArray) { + if (!(_1819_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + _1819_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _1819_methodName); } - r = ((RAST.__default.dafny__runtime__Sequence).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _1670_methodName))).Apply(Dafny.Sequence.FromElements(), _1671_arguments); + r = ((RAST.__default.dafny__runtime__Sequence).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _1819_methodName))).Apply(_1820_arguments); } else { - if (!(_1670_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - r = ((r).Sel(_1670_methodName)).Apply(Dafny.Sequence.FromElements(), _1671_arguments); + if (!(_1819_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + r = ((r).Sel(_1819_methodName)).Apply(_1820_arguments); } } - RAST._IExpr _out441; - DCOMP._IOwnership _out442; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out441, out _out442); - r = _out441; - resultingOwnership = _out442; + RAST._IExpr _out488; + DCOMP._IOwnership _out489; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out488, out _out489); + r = _out488; + resultingOwnership = _out489; return ; } } } - if (unmatched71) { - if (_source71.is_TupleSelect) { - DAST._IExpression _1680_on = _source71.dtor_expr; - BigInteger _1681_idx = _source71.dtor_index; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_TupleSelect) { + DAST._IExpression _1829_on = _source74.dtor_expr; + BigInteger _1830_idx = _source74.dtor_index; + DAST._IType _1831_fieldType = _source74.dtor_fieldType; + unmatched74 = false; { - RAST._IExpr _1682_onExpr; - DCOMP._IOwnership _1683_onOwnership; - Dafny.ISet> _1684_recIdents; - RAST._IExpr _out443; - DCOMP._IOwnership _out444; - Dafny.ISet> _out445; - (this).GenExpr(_1680_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out443, out _out444, out _out445); - _1682_onExpr = _out443; - _1683_onOwnership = _out444; - _1684_recIdents = _out445; - r = (_1682_onExpr).Sel(Std.Strings.__default.OfNat(_1681_idx)); - RAST._IExpr _out446; - DCOMP._IOwnership _out447; - DCOMP.COMP.FromOwnership(r, _1683_onOwnership, expectedOwnership, out _out446, out _out447); - r = _out446; - resultingOwnership = _out447; - readIdents = _1684_recIdents; + RAST._IExpr _1832_onExpr; + DCOMP._IOwnership _1833_onOwnership; + Dafny.ISet> _1834_recIdents; + RAST._IExpr _out490; + DCOMP._IOwnership _out491; + Dafny.ISet> _out492; + (this).GenExpr(_1829_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out490, out _out491, out _out492); + _1832_onExpr = _out490; + _1833_onOwnership = _out491; + _1834_recIdents = _out492; + Dafny.ISequence _1835_selName; + _1835_selName = Std.Strings.__default.OfNat(_1830_idx); + DAST._IType _source78 = _1831_fieldType; + bool unmatched78 = true; + if (unmatched78) { + if (_source78.is_Tuple) { + Dafny.ISequence _1836_tps = _source78.dtor_Tuple_a0; + unmatched78 = false; + if (((_1831_fieldType).is_Tuple) && ((new BigInteger((_1836_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { + _1835_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _1835_selName); + } + } + } + if (unmatched78) { + DAST._IType _1837___v140 = _source78; + unmatched78 = false; + } + r = (_1832_onExpr).Sel(_1835_selName); + RAST._IExpr _out493; + DCOMP._IOwnership _out494; + DCOMP.COMP.FromOwnership(r, _1833_onOwnership, expectedOwnership, out _out493, out _out494); + r = _out493; + resultingOwnership = _out494; + readIdents = _1834_recIdents; return ; } } } - if (unmatched71) { - if (_source71.is_Call) { - DAST._IExpression _1685_on = _source71.dtor_on; - DAST._ICallName _1686_name = _source71.dtor_callName; - Dafny.ISequence _1687_typeArgs = _source71.dtor_typeArgs; - Dafny.ISequence _1688_args = _source71.dtor_args; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_Call) { + DAST._IExpression _1838_on = _source74.dtor_on; + DAST._ICallName _1839_name = _source74.dtor_callName; + Dafny.ISequence _1840_typeArgs = _source74.dtor_typeArgs; + Dafny.ISequence _1841_args = _source74.dtor_args; + unmatched74 = false; { readIdents = Dafny.Set>.FromElements(); - Dafny.ISequence _1689_typeExprs; - _1689_typeExprs = Dafny.Sequence.FromElements(); - if ((new BigInteger((_1687_typeArgs).Count)) >= (BigInteger.One)) { - BigInteger _1690_typeI; - _1690_typeI = BigInteger.Zero; - while ((_1690_typeI) < (new BigInteger((_1687_typeArgs).Count))) { - RAST._IType _1691_typeExpr; - RAST._IType _out448; - _out448 = (this).GenType((_1687_typeArgs).Select(_1690_typeI), false, false); - _1691_typeExpr = _out448; - _1689_typeExprs = Dafny.Sequence.Concat(_1689_typeExprs, Dafny.Sequence.FromElements(_1691_typeExpr)); - _1690_typeI = (_1690_typeI) + (BigInteger.One); + RAST._IExpr _1842_onExpr; + DCOMP._IOwnership _1843___v141; + Dafny.ISet> _1844_recIdents; + RAST._IExpr _out495; + DCOMP._IOwnership _out496; + Dafny.ISet> _out497; + (this).GenExpr(_1838_on, selfIdent, env, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out495, out _out496, out _out497); + _1842_onExpr = _out495; + _1843___v141 = _out496; + _1844_recIdents = _out497; + Dafny.ISequence _1845_typeExprs; + _1845_typeExprs = Dafny.Sequence.FromElements(); + if ((new BigInteger((_1840_typeArgs).Count)) >= (BigInteger.One)) { + BigInteger _hi35 = new BigInteger((_1840_typeArgs).Count); + for (BigInteger _1846_typeI = BigInteger.Zero; _1846_typeI < _hi35; _1846_typeI++) { + RAST._IType _1847_typeExpr; + RAST._IType _out498; + _out498 = (this).GenType((_1840_typeArgs).Select(_1846_typeI), false, false); + _1847_typeExpr = _out498; + _1845_typeExprs = Dafny.Sequence.Concat(_1845_typeExprs, Dafny.Sequence.FromElements(_1847_typeExpr)); } } - Dafny.ISequence _1692_argExprs; - _1692_argExprs = Dafny.Sequence.FromElements(); - BigInteger _1693_i; - _1693_i = BigInteger.Zero; - while ((_1693_i) < (new BigInteger((_1688_args).Count))) { - RAST._IExpr _1694_argExpr; - DCOMP._IOwnership _1695_argOwnership; - Dafny.ISet> _1696_argIdents; - RAST._IExpr _out449; - DCOMP._IOwnership _out450; - Dafny.ISet> _out451; - (this).GenExpr((_1688_args).Select(_1693_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out449, out _out450, out _out451); - _1694_argExpr = _out449; - _1695_argOwnership = _out450; - _1696_argIdents = _out451; - _1692_argExprs = Dafny.Sequence.Concat(_1692_argExprs, Dafny.Sequence.FromElements(_1694_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _1696_argIdents); - _1693_i = (_1693_i) + (BigInteger.One); + Dafny.ISequence _1848_argExprs; + _1848_argExprs = Dafny.Sequence.FromElements(); + BigInteger _hi36 = new BigInteger((_1841_args).Count); + for (BigInteger _1849_i = BigInteger.Zero; _1849_i < _hi36; _1849_i++) { + DCOMP._IOwnership _1850_argOwnership; + _1850_argOwnership = DCOMP.Ownership.create_OwnershipBorrowed(); + if (((_1839_name).is_CallName) && ((_1849_i) < (new BigInteger((((_1839_name).dtor_signature)).Count)))) { + RAST._IType _1851_tpe; + RAST._IType _out499; + _out499 = (this).GenType(((((_1839_name).dtor_signature)).Select(_1849_i)).dtor_typ, false, false); + _1851_tpe = _out499; + if ((_1851_tpe).CanReadWithoutClone()) { + _1850_argOwnership = DCOMP.Ownership.create_OwnershipOwned(); + } + } + RAST._IExpr _1852_argExpr; + DCOMP._IOwnership _1853___v142; + Dafny.ISet> _1854_argIdents; + RAST._IExpr _out500; + DCOMP._IOwnership _out501; + Dafny.ISet> _out502; + (this).GenExpr((_1841_args).Select(_1849_i), selfIdent, env, _1850_argOwnership, out _out500, out _out501, out _out502); + _1852_argExpr = _out500; + _1853___v142 = _out501; + _1854_argIdents = _out502; + _1848_argExprs = Dafny.Sequence.Concat(_1848_argExprs, Dafny.Sequence.FromElements(_1852_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _1854_argIdents); } - RAST._IExpr _1697_onExpr; - DCOMP._IOwnership _1698___v120; - Dafny.ISet> _1699_recIdents; - RAST._IExpr _out452; - DCOMP._IOwnership _out453; - Dafny.ISet> _out454; - (this).GenExpr(_1685_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipAutoBorrowed(), out _out452, out _out453, out _out454); - _1697_onExpr = _out452; - _1698___v120 = _out453; - _1699_recIdents = _out454; - readIdents = Dafny.Set>.Union(readIdents, _1699_recIdents); - Dafny.ISequence _1700_renderedName; - _1700_renderedName = ((System.Func>)(() => { - DAST._ICallName _source75 = _1686_name; - bool unmatched75 = true; - if (unmatched75) { - if (_source75.is_Name) { - Dafny.ISequence _1701_ident = _source75.dtor_name; - unmatched75 = false; - return DCOMP.__default.escapeIdent(_1701_ident); + readIdents = Dafny.Set>.Union(readIdents, _1844_recIdents); + Dafny.ISequence _1855_renderedName; + _1855_renderedName = ((System.Func>)(() => { + DAST._ICallName _source79 = _1839_name; + bool unmatched79 = true; + if (unmatched79) { + if (_source79.is_CallName) { + Dafny.ISequence _1856_ident = _source79.dtor_name; + Std.Wrappers._IOption _1857___v143 = _source79.dtor_onType; + Dafny.ISequence _1858___v144 = _source79.dtor_signature; + unmatched79 = false; + return DCOMP.__default.escapeName(_1856_ident); } } - if (unmatched75) { + if (unmatched79) { bool disjunctiveMatch12 = false; - if (_source75.is_MapBuilderAdd) { + if (_source79.is_MapBuilderAdd) { disjunctiveMatch12 = true; } - if (_source75.is_SetBuilderAdd) { + if (_source79.is_SetBuilderAdd) { disjunctiveMatch12 = true; } if (disjunctiveMatch12) { - unmatched75 = false; + unmatched79 = false; return Dafny.Sequence.UnicodeFromString("add"); } } - if (unmatched75) { + if (unmatched79) { bool disjunctiveMatch13 = false; disjunctiveMatch13 = true; disjunctiveMatch13 = true; if (disjunctiveMatch13) { - unmatched75 = false; + unmatched79 = false; return Dafny.Sequence.UnicodeFromString("build"); } } throw new System.Exception("unexpected control point"); }))(); - DAST._IExpression _source76 = _1685_on; - bool unmatched76 = true; - if (unmatched76) { - if (_source76.is_Companion) { - Dafny.ISequence> _1702___v121 = _source76.dtor_Companion_a0; - unmatched76 = false; + DAST._IExpression _source80 = _1838_on; + bool unmatched80 = true; + if (unmatched80) { + if (_source80.is_Companion) { + Dafny.ISequence> _1859___v145 = _source80.dtor_Companion_a0; + unmatched80 = false; { - _1697_onExpr = (_1697_onExpr).MSel(_1700_renderedName); + _1842_onExpr = (_1842_onExpr).MSel(_1855_renderedName); } } } - if (unmatched76) { - DAST._IExpression _1703___v122 = _source76; - unmatched76 = false; + if (unmatched80) { + DAST._IExpression _1860___v146 = _source80; + unmatched80 = false; { - _1697_onExpr = (_1697_onExpr).Sel(_1700_renderedName); + _1842_onExpr = (_1842_onExpr).Sel(_1855_renderedName); } } - r = RAST.Expr.create_Call(_1697_onExpr, _1689_typeExprs, _1692_argExprs); - RAST._IExpr _out455; - DCOMP._IOwnership _out456; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out455, out _out456); - r = _out455; - resultingOwnership = _out456; + r = _1842_onExpr; + if ((new BigInteger((_1845_typeExprs).Count)).Sign == 1) { + r = (r).ApplyType(_1845_typeExprs); + } + r = (r).Apply(_1848_argExprs); + RAST._IExpr _out503; + DCOMP._IOwnership _out504; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out503, out _out504); + r = _out503; + resultingOwnership = _out504; return ; } } } - if (unmatched71) { - if (_source71.is_Lambda) { - Dafny.ISequence _1704_params = _source71.dtor_params; - DAST._IType _1705_retType = _source71.dtor_retType; - Dafny.ISequence _1706_body = _source71.dtor_body; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_Lambda) { + Dafny.ISequence _1861_paramsDafny = _source74.dtor_params; + DAST._IType _1862_retType = _source74.dtor_retType; + Dafny.ISequence _1863_body = _source74.dtor_body; + unmatched74 = false; { - Dafny.ISequence> _1707_paramNames; - _1707_paramNames = Dafny.Sequence>.FromElements(); - BigInteger _1708_i; - _1708_i = BigInteger.Zero; - while ((_1708_i) < (new BigInteger((_1704_params).Count))) { - _1707_paramNames = Dafny.Sequence>.Concat(_1707_paramNames, Dafny.Sequence>.FromElements(((_1704_params).Select(_1708_i)).dtor_name)); - _1708_i = (_1708_i) + (BigInteger.One); + Dafny.ISequence _1864_params; + Dafny.ISequence _out505; + _out505 = (this).GenParams(_1861_paramsDafny); + _1864_params = _out505; + Dafny.ISequence> _1865_paramNames; + _1865_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _1866_paramTypesMap; + _1866_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi37 = new BigInteger((_1864_params).Count); + for (BigInteger _1867_i = BigInteger.Zero; _1867_i < _hi37; _1867_i++) { + Dafny.ISequence _1868_name; + _1868_name = ((_1864_params).Select(_1867_i)).dtor_name; + _1865_paramNames = Dafny.Sequence>.Concat(_1865_paramNames, Dafny.Sequence>.FromElements(_1868_name)); + _1866_paramTypesMap = Dafny.Map, RAST._IType>.Update(_1866_paramTypesMap, _1868_name, ((_1864_params).Select(_1867_i)).dtor_tpe); } - RAST._IExpr _1709_recursiveGen; - Dafny.ISet> _1710_recIdents; - RAST._IExpr _out457; - Dafny.ISet> _out458; - (this).GenStmts(_1706_body, ((!object.Equals(selfIdent, Std.Wrappers.Option>.create_None())) ? (Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("_this"))) : (Std.Wrappers.Option>.create_None())), _1707_paramNames, true, RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")), out _out457, out _out458); - _1709_recursiveGen = _out457; - _1710_recIdents = _out458; + DCOMP._IEnvironment _1869_env; + _1869_env = DCOMP.Environment.create(_1865_paramNames, _1866_paramTypesMap); + RAST._IExpr _1870_recursiveGen; + Dafny.ISet> _1871_recIdents; + DCOMP._IEnvironment _1872___v147; + RAST._IExpr _out506; + Dafny.ISet> _out507; + DCOMP._IEnvironment _out508; + (this).GenStmts(_1863_body, ((!object.Equals(selfIdent, Std.Wrappers.Option>.create_None())) ? (Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("_this"))) : (Std.Wrappers.Option>.create_None())), _1869_env, true, RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")), out _out506, out _out507, out _out508); + _1870_recursiveGen = _out506; + _1871_recIdents = _out507; + _1872___v147 = _out508; readIdents = Dafny.Set>.FromElements(); - Dafny.ISequence _1711_allReadCloned; - _1711_allReadCloned = Dafny.Sequence.UnicodeFromString(""); - while (!(_1710_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _1712_next; - foreach (Dafny.ISequence _assign_such_that_3 in (_1710_recIdents).Elements) { - _1712_next = (Dafny.ISequence)_assign_such_that_3; - if ((_1710_recIdents).Contains(_1712_next)) { + _1871_recIdents = Dafny.Set>.Difference(_1871_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_1873_paramNames) => ((System.Func>>)(() => { + var _coll6 = new System.Collections.Generic.List>(); + foreach (Dafny.ISequence _compr_6 in (_1873_paramNames).CloneAsArray()) { + Dafny.ISequence _1874_name = (Dafny.ISequence)_compr_6; + if ((_1873_paramNames).Contains(_1874_name)) { + _coll6.Add(_1874_name); + } + } + return Dafny.Set>.FromCollection(_coll6); + }))())(_1865_paramNames)); + RAST._IExpr _1875_allReadCloned; + _1875_allReadCloned = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); + while (!(_1871_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _1876_next; + foreach (Dafny.ISequence _assign_such_that_3 in (_1871_recIdents).Elements) { + _1876_next = (Dafny.ISequence)_assign_such_that_3; + if ((_1871_recIdents).Contains(_1876_next)) { goto after__ASSIGN_SUCH_THAT_3; } } - throw new System.Exception("assign-such-that search produced no value (line 3278)"); + throw new System.Exception("assign-such-that search produced no value (line 3735)"); after__ASSIGN_SUCH_THAT_3: ; - if ((!object.Equals(selfIdent, Std.Wrappers.Option>.create_None())) && ((_1712_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + if ((!object.Equals(selfIdent, Std.Wrappers.Option>.create_None())) && ((_1876_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { if (!object.Equals(selfIdent, Std.Wrappers.Option>.create_None())) { - _1711_allReadCloned = Dafny.Sequence.Concat(_1711_allReadCloned, Dafny.Sequence.UnicodeFromString("let _this = self.clone();\n")); + _1875_allReadCloned = (_1875_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply(Dafny.Sequence.FromElements())))); } - } else if (!((_1707_paramNames).Contains(_1712_next))) { - _1711_allReadCloned = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1711_allReadCloned, Dafny.Sequence.UnicodeFromString("let ")), DCOMP.__default.escapeIdent(_1712_next)), Dafny.Sequence.UnicodeFromString(" = ")), DCOMP.__default.escapeIdent(_1712_next)), Dafny.Sequence.UnicodeFromString(".clone();\n")); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_1712_next)); - } - _1710_recIdents = Dafny.Set>.Difference(_1710_recIdents, Dafny.Set>.FromElements(_1712_next)); - } - Dafny.ISequence _1713_paramsString; - _1713_paramsString = Dafny.Sequence.UnicodeFromString(""); - Dafny.ISequence _1714_paramTypes; - _1714_paramTypes = Dafny.Sequence.UnicodeFromString(""); - _1708_i = BigInteger.Zero; - while ((_1708_i) < (new BigInteger((_1704_params).Count))) { - if ((_1708_i).Sign == 1) { - _1713_paramsString = Dafny.Sequence.Concat(_1713_paramsString, Dafny.Sequence.UnicodeFromString(", ")); - _1714_paramTypes = Dafny.Sequence.Concat(_1714_paramTypes, Dafny.Sequence.UnicodeFromString(", ")); + } else if (!((_1865_paramNames).Contains(_1876_next))) { + _1875_allReadCloned = (_1875_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _1876_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(_1876_next)).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply(Dafny.Sequence.FromElements())))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_1876_next)); } - RAST._IType _1715_typStr; - RAST._IType _out459; - _out459 = (this).GenType(((_1704_params).Select(_1708_i)).dtor_typ, false, true); - _1715_typStr = _out459; - _1713_paramsString = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1713_paramsString, DCOMP.__default.escapeIdent(((_1704_params).Select(_1708_i)).dtor_name)), Dafny.Sequence.UnicodeFromString(": ")), (RAST.Type.create_Borrowed(_1715_typStr))._ToString(DCOMP.__default.IND)); - _1714_paramTypes = Dafny.Sequence.Concat(_1714_paramTypes, (RAST.Type.create_Borrowed(_1715_typStr))._ToString(DCOMP.__default.IND)); - _1708_i = (_1708_i) + (BigInteger.One); + _1871_recIdents = Dafny.Set>.Difference(_1871_recIdents, Dafny.Set>.FromElements(_1876_next)); } - RAST._IType _1716_retTypeGen; - RAST._IType _out460; - _out460 = (this).GenType(_1705_retType, false, true); - _1716_retTypeGen = _out460; - 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.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::FunctionWrapper::<::std::rc::Rc.UnicodeFromString(") -> ")), (_1716_retTypeGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(">>({\n")), _1711_allReadCloned), Dafny.Sequence.UnicodeFromString("::std::rc::Rc::new(move |")), _1713_paramsString), Dafny.Sequence.UnicodeFromString("| -> ")), (_1716_retTypeGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" {\n")), (_1709_recursiveGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString("\n})})"))); - RAST._IExpr _out461; - DCOMP._IOwnership _out462; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out461, out _out462); - r = _out461; - resultingOwnership = _out462; + RAST._IType _1877_retTypeGen; + RAST._IType _out509; + _out509 = (this).GenType(_1862_retType, false, true); + _1877_retTypeGen = _out509; + r = RAST.Expr.create_Block((_1875_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_1864_params, Std.Wrappers.Option.create_Some(_1877_retTypeGen), RAST.Expr.create_Block(_1870_recursiveGen))))); + RAST._IExpr _out510; + DCOMP._IOwnership _out511; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out510, out _out511); + r = _out510; + resultingOwnership = _out511; return ; } } } - if (unmatched71) { - if (_source71.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _1717_values = _source71.dtor_values; - DAST._IType _1718_retType = _source71.dtor_retType; - DAST._IExpression _1719_expr = _source71.dtor_expr; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_BetaRedex) { + Dafny.ISequence<_System._ITuple2> _1878_values = _source74.dtor_values; + DAST._IType _1879_retType = _source74.dtor_retType; + DAST._IExpression _1880_expr = _source74.dtor_expr; + unmatched74 = false; { - Dafny.ISequence> _1720_paramNames; - _1720_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISet> _1721_paramNamesSet; - _1721_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _1722_i; - _1722_i = BigInteger.Zero; - while ((_1722_i) < (new BigInteger((_1717_values).Count))) { - _1720_paramNames = Dafny.Sequence>.Concat(_1720_paramNames, Dafny.Sequence>.FromElements((((_1717_values).Select(_1722_i)).dtor__0).dtor_name)); - _1721_paramNamesSet = Dafny.Set>.Union(_1721_paramNamesSet, Dafny.Set>.FromElements((((_1717_values).Select(_1722_i)).dtor__0).dtor_name)); - _1722_i = (_1722_i) + (BigInteger.One); + Dafny.ISequence> _1881_paramNames; + _1881_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _1882_paramFormals; + Dafny.ISequence _out512; + _out512 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_1883_value) => { + return (_1883_value).dtor__0; + })), _1878_values)); + _1882_paramFormals = _out512; + Dafny.IMap,RAST._IType> _1884_paramTypes; + _1884_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _1885_paramNamesSet; + _1885_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi38 = new BigInteger((_1878_values).Count); + for (BigInteger _1886_i = BigInteger.Zero; _1886_i < _hi38; _1886_i++) { + Dafny.ISequence _1887_name; + _1887_name = (((_1878_values).Select(_1886_i)).dtor__0).dtor_name; + Dafny.ISequence _1888_rName; + _1888_rName = DCOMP.__default.escapeName(_1887_name); + _1881_paramNames = Dafny.Sequence>.Concat(_1881_paramNames, Dafny.Sequence>.FromElements(_1888_rName)); + _1884_paramTypes = Dafny.Map, RAST._IType>.Update(_1884_paramTypes, _1888_rName, ((_1882_paramFormals).Select(_1886_i)).dtor_tpe); + _1885_paramNamesSet = Dafny.Set>.Union(_1885_paramNamesSet, Dafny.Set>.FromElements(_1888_rName)); } readIdents = Dafny.Set>.FromElements(); - Dafny.ISequence _1723_s; - _1723_s = Dafny.Sequence.UnicodeFromString("{\n"); - Dafny.ISequence _1724_paramsString; - _1724_paramsString = Dafny.Sequence.UnicodeFromString(""); - _1722_i = BigInteger.Zero; - while ((_1722_i) < (new BigInteger((_1717_values).Count))) { - if ((_1722_i).Sign == 1) { - _1724_paramsString = Dafny.Sequence.Concat(_1724_paramsString, Dafny.Sequence.UnicodeFromString(", ")); - } - RAST._IType _1725_typStr; - RAST._IType _out463; - _out463 = (this).GenType((((_1717_values).Select(_1722_i)).dtor__0).dtor_typ, false, true); - _1725_typStr = _out463; - RAST._IExpr _1726_valueGen; - DCOMP._IOwnership _1727___v123; - Dafny.ISet> _1728_recIdents; - RAST._IExpr _out464; - DCOMP._IOwnership _out465; - Dafny.ISet> _out466; - (this).GenExpr(((_1717_values).Select(_1722_i)).dtor__1, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out464, out _out465, out _out466); - _1726_valueGen = _out464; - _1727___v123 = _out465; - _1728_recIdents = _out466; - _1723_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1723_s, Dafny.Sequence.UnicodeFromString("let ")), DCOMP.__default.escapeIdent((((_1717_values).Select(_1722_i)).dtor__0).dtor_name)), Dafny.Sequence.UnicodeFromString(": ")), (_1725_typStr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" = ")); - readIdents = Dafny.Set>.Union(readIdents, _1728_recIdents); - _1723_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1723_s, (_1726_valueGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(";\n")); - _1722_i = (_1722_i) + (BigInteger.One); + r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); + BigInteger _hi39 = new BigInteger((_1878_values).Count); + for (BigInteger _1889_i = BigInteger.Zero; _1889_i < _hi39; _1889_i++) { + RAST._IType _1890_typeGen; + RAST._IType _out513; + _out513 = (this).GenType((((_1878_values).Select(_1889_i)).dtor__0).dtor_typ, false, true); + _1890_typeGen = _out513; + RAST._IExpr _1891_valueGen; + DCOMP._IOwnership _1892___v148; + Dafny.ISet> _1893_recIdents; + RAST._IExpr _out514; + DCOMP._IOwnership _out515; + Dafny.ISet> _out516; + (this).GenExpr(((_1878_values).Select(_1889_i)).dtor__1, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out514, out _out515, out _out516); + _1891_valueGen = _out514; + _1892___v148 = _out515; + _1893_recIdents = _out516; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), DCOMP.__default.escapeName((((_1878_values).Select(_1889_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_1890_typeGen), Std.Wrappers.Option.create_Some(_1891_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _1893_recIdents); } - RAST._IExpr _1729_recGen; - DCOMP._IOwnership _1730_recOwned; - Dafny.ISet> _1731_recIdents; - RAST._IExpr _out467; - DCOMP._IOwnership _out468; - Dafny.ISet> _out469; - (this).GenExpr(_1719_expr, selfIdent, _1720_paramNames, expectedOwnership, out _out467, out _out468, out _out469); - _1729_recGen = _out467; - _1730_recOwned = _out468; - _1731_recIdents = _out469; - readIdents = Dafny.Set>.Difference(_1731_recIdents, _1721_paramNamesSet); - _1723_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_1723_s, (_1729_recGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString("\n}")); - r = RAST.Expr.create_RawExpr(_1723_s); - RAST._IExpr _out470; - DCOMP._IOwnership _out471; - DCOMP.COMP.FromOwnership(r, _1730_recOwned, expectedOwnership, out _out470, out _out471); - r = _out470; - resultingOwnership = _out471; + DCOMP._IEnvironment _1894_newEnv; + _1894_newEnv = DCOMP.Environment.create(_1881_paramNames, _1884_paramTypes); + RAST._IExpr _1895_recGen; + DCOMP._IOwnership _1896_recOwned; + Dafny.ISet> _1897_recIdents; + RAST._IExpr _out517; + DCOMP._IOwnership _out518; + Dafny.ISet> _out519; + (this).GenExpr(_1880_expr, selfIdent, _1894_newEnv, expectedOwnership, out _out517, out _out518, out _out519); + _1895_recGen = _out517; + _1896_recOwned = _out518; + _1897_recIdents = _out519; + readIdents = Dafny.Set>.Difference(_1897_recIdents, _1885_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_1895_recGen)); + RAST._IExpr _out520; + DCOMP._IOwnership _out521; + DCOMP.COMP.FromOwnership(r, _1896_recOwned, expectedOwnership, out _out520, out _out521); + r = _out520; + resultingOwnership = _out521; return ; } } } - if (unmatched71) { - if (_source71.is_IIFE) { - Dafny.ISequence _1732_name = _source71.dtor_name; - DAST._IType _1733_tpe = _source71.dtor_typ; - DAST._IExpression _1734_value = _source71.dtor_value; - DAST._IExpression _1735_iifeBody = _source71.dtor_iifeBody; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_IIFE) { + Dafny.ISequence _1898_name = _source74.dtor_name; + DAST._IType _1899_tpe = _source74.dtor_typ; + DAST._IExpression _1900_value = _source74.dtor_value; + DAST._IExpression _1901_iifeBody = _source74.dtor_iifeBody; + unmatched74 = false; { - RAST._IExpr _1736_valueGen; - DCOMP._IOwnership _1737___v124; - Dafny.ISet> _1738_recIdents; - RAST._IExpr _out472; - DCOMP._IOwnership _out473; - Dafny.ISet> _out474; - (this).GenExpr(_1734_value, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out472, out _out473, out _out474); - _1736_valueGen = _out472; - _1737___v124 = _out473; - _1738_recIdents = _out474; - readIdents = _1738_recIdents; - RAST._IType _1739_valueTypeGen; - RAST._IType _out475; - _out475 = (this).GenType(_1733_tpe, false, true); - _1739_valueTypeGen = _out475; - RAST._IExpr _1740_bodyGen; - DCOMP._IOwnership _1741___v125; - Dafny.ISet> _1742_bodyIdents; - RAST._IExpr _out476; - DCOMP._IOwnership _out477; - Dafny.ISet> _out478; - (this).GenExpr(_1735_iifeBody, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out476, out _out477, out _out478); - _1740_bodyGen = _out476; - _1741___v125 = _out477; - _1742_bodyIdents = _out478; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_1742_bodyIdents, Dafny.Set>.FromElements((_1732_name)))); - 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.Concat(Dafny.Sequence.UnicodeFromString("{\nlet "), DCOMP.__default.escapeIdent((_1732_name))), Dafny.Sequence.UnicodeFromString(": ")), (_1739_valueTypeGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(" = ")), (_1736_valueGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(";\n")), (_1740_bodyGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString("\n}"))); - RAST._IExpr _out479; - DCOMP._IOwnership _out480; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out479, out _out480); - r = _out479; - resultingOwnership = _out480; + RAST._IExpr _1902_valueGen; + DCOMP._IOwnership _1903___v149; + Dafny.ISet> _1904_recIdents; + RAST._IExpr _out522; + DCOMP._IOwnership _out523; + Dafny.ISet> _out524; + (this).GenExpr(_1900_value, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out522, out _out523, out _out524); + _1902_valueGen = _out522; + _1903___v149 = _out523; + _1904_recIdents = _out524; + readIdents = _1904_recIdents; + RAST._IType _1905_valueTypeGen; + RAST._IType _out525; + _out525 = (this).GenType(_1899_tpe, false, true); + _1905_valueTypeGen = _out525; + RAST._IExpr _1906_bodyGen; + DCOMP._IOwnership _1907___v150; + Dafny.ISet> _1908_bodyIdents; + RAST._IExpr _out526; + DCOMP._IOwnership _out527; + Dafny.ISet> _out528; + (this).GenExpr(_1901_iifeBody, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out526, out _out527, out _out528); + _1906_bodyGen = _out526; + _1907___v150 = _out527; + _1908_bodyIdents = _out528; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_1908_bodyIdents, Dafny.Set>.FromElements(DCOMP.__default.escapeName((_1898_name))))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), DCOMP.__default.escapeName((_1898_name)), Std.Wrappers.Option.create_Some(_1905_valueTypeGen), Std.Wrappers.Option.create_Some(_1902_valueGen))).Then(_1906_bodyGen)); + RAST._IExpr _out529; + DCOMP._IOwnership _out530; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out529, out _out530); + r = _out529; + resultingOwnership = _out530; return ; } } } - if (unmatched71) { - if (_source71.is_Apply) { - DAST._IExpression _1743_func = _source71.dtor_expr; - Dafny.ISequence _1744_args = _source71.dtor_args; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_Apply) { + DAST._IExpression _1909_func = _source74.dtor_expr; + Dafny.ISequence _1910_args = _source74.dtor_args; + unmatched74 = false; { - RAST._IExpr _1745_funcExpr; - DCOMP._IOwnership _1746___v126; - Dafny.ISet> _1747_recIdents; - RAST._IExpr _out481; - DCOMP._IOwnership _out482; - Dafny.ISet> _out483; - (this).GenExpr(_1743_func, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out481, out _out482, out _out483); - _1745_funcExpr = _out481; - _1746___v126 = _out482; - _1747_recIdents = _out483; - readIdents = _1747_recIdents; - Dafny.ISequence _1748_argString; - _1748_argString = Dafny.Sequence.UnicodeFromString(""); - BigInteger _1749_i; - _1749_i = BigInteger.Zero; - while ((_1749_i) < (new BigInteger((_1744_args).Count))) { - if ((_1749_i).Sign == 1) { - _1748_argString = Dafny.Sequence.Concat(_1748_argString, Dafny.Sequence.UnicodeFromString(", ")); - } - RAST._IExpr _1750_argExpr; - DCOMP._IOwnership _1751_argOwned; - Dafny.ISet> _1752_argIdents; - RAST._IExpr _out484; - DCOMP._IOwnership _out485; - Dafny.ISet> _out486; - (this).GenExpr((_1744_args).Select(_1749_i), selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out484, out _out485, out _out486); - _1750_argExpr = _out484; - _1751_argOwned = _out485; - _1752_argIdents = _out486; - Dafny.ISequence _1753_argExprString; - _1753_argExprString = (_1750_argExpr)._ToString(DCOMP.__default.IND); - if (object.Equals(_1751_argOwned, DCOMP.Ownership.create_OwnershipOwned())) { - _1753_argExprString = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&"), _1753_argExprString); - } - _1748_argString = Dafny.Sequence.Concat(_1748_argString, _1753_argExprString); - readIdents = Dafny.Set>.Union(readIdents, _1752_argIdents); - _1749_i = (_1749_i) + (BigInteger.One); + RAST._IExpr _1911_funcExpr; + DCOMP._IOwnership _1912___v151; + Dafny.ISet> _1913_recIdents; + RAST._IExpr _out531; + DCOMP._IOwnership _out532; + Dafny.ISet> _out533; + (this).GenExpr(_1909_func, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out531, out _out532, out _out533); + _1911_funcExpr = _out531; + _1912___v151 = _out532; + _1913_recIdents = _out533; + readIdents = _1913_recIdents; + Dafny.ISequence _1914_rArgs; + _1914_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi40 = new BigInteger((_1910_args).Count); + for (BigInteger _1915_i = BigInteger.Zero; _1915_i < _hi40; _1915_i++) { + RAST._IExpr _1916_argExpr; + DCOMP._IOwnership _1917_argOwned; + Dafny.ISet> _1918_argIdents; + RAST._IExpr _out534; + DCOMP._IOwnership _out535; + Dafny.ISet> _out536; + (this).GenExpr((_1910_args).Select(_1915_i), selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out534, out _out535, out _out536); + _1916_argExpr = _out534; + _1917_argOwned = _out535; + _1918_argIdents = _out536; + _1914_rArgs = Dafny.Sequence.Concat(_1914_rArgs, Dafny.Sequence.FromElements(_1916_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _1918_argIdents); } - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("(("), (_1745_funcExpr)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").0")), Dafny.Sequence.UnicodeFromString("(")), _1748_argString), Dafny.Sequence.UnicodeFromString("))"))); - RAST._IExpr _out487; - DCOMP._IOwnership _out488; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out487, out _out488); - r = _out487; - resultingOwnership = _out488; + r = (_1911_funcExpr).Apply(_1914_rArgs); + RAST._IExpr _out537; + DCOMP._IOwnership _out538; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out537, out _out538); + r = _out537; + resultingOwnership = _out538; return ; } } } - if (unmatched71) { - if (_source71.is_TypeTest) { - DAST._IExpression _1754_on = _source71.dtor_on; - Dafny.ISequence> _1755_dType = _source71.dtor_dType; - Dafny.ISequence _1756_variant = _source71.dtor_variant; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_TypeTest) { + DAST._IExpression _1919_on = _source74.dtor_on; + Dafny.ISequence> _1920_dType = _source74.dtor_dType; + Dafny.ISequence _1921_variant = _source74.dtor_variant; + unmatched74 = false; { - RAST._IExpr _1757_exprGen; - DCOMP._IOwnership _1758___v127; - Dafny.ISet> _1759_recIdents; - RAST._IExpr _out489; - DCOMP._IOwnership _out490; - Dafny.ISet> _out491; - (this).GenExpr(_1754_on, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out489, out _out490, out _out491); - _1757_exprGen = _out489; - _1758___v127 = _out490; - _1759_recIdents = _out491; - Dafny.ISequence _1760_dTypePath; - Dafny.ISequence _out492; - _out492 = DCOMP.COMP.GenPath(_1755_dType); - _1760_dTypePath = _out492; - 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.UnicodeFromString("matches!("), (_1757_exprGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(".as_ref(), ")), _1760_dTypePath), Dafny.Sequence.UnicodeFromString("::")), DCOMP.__default.escapeIdent(_1756_variant)), Dafny.Sequence.UnicodeFromString("{ .. })"))); - RAST._IExpr _out493; - DCOMP._IOwnership _out494; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out493, out _out494); - r = _out493; - resultingOwnership = _out494; - readIdents = _1759_recIdents; + RAST._IExpr _1922_exprGen; + DCOMP._IOwnership _1923___v152; + Dafny.ISet> _1924_recIdents; + RAST._IExpr _out539; + DCOMP._IOwnership _out540; + Dafny.ISet> _out541; + (this).GenExpr(_1919_on, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out539, out _out540, out _out541); + _1922_exprGen = _out539; + _1923___v152 = _out540; + _1924_recIdents = _out541; + RAST._IType _1925_dTypePath; + RAST._IType _out542; + _out542 = DCOMP.COMP.GenPath(_1920_dType); + _1925_dTypePath = _out542; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_1922_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply(Dafny.Sequence.FromElements()), RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(((_1925_dTypePath).MSel(DCOMP.__default.escapeName(_1921_variant)))._ToString(DCOMP.__default.IND), Dafny.Sequence.UnicodeFromString("{ .. }"))))); + RAST._IExpr _out543; + DCOMP._IOwnership _out544; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out543, out _out544); + r = _out543; + resultingOwnership = _out544; + readIdents = _1924_recIdents; return ; } } } - if (unmatched71) { - if (_source71.is_BoolBoundedPool) { - unmatched71 = false; + if (unmatched74) { + if (_source74.is_BoolBoundedPool) { + unmatched74 = false; { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("[false, true]")); - RAST._IExpr _out495; - DCOMP._IOwnership _out496; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out495, out _out496); - r = _out495; - resultingOwnership = _out496; + RAST._IExpr _out545; + DCOMP._IOwnership _out546; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out545, out _out546); + r = _out545; + resultingOwnership = _out546; readIdents = Dafny.Set>.FromElements(); return ; } } } - if (unmatched71) { - if (_source71.is_SetBoundedPool) { - DAST._IExpression _1761_of = _source71.dtor_of; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_SetBoundedPool) { + DAST._IExpression _1926_of = _source74.dtor_of; + unmatched74 = false; { - RAST._IExpr _1762_exprGen; - DCOMP._IOwnership _1763___v128; - Dafny.ISet> _1764_recIdents; - RAST._IExpr _out497; - DCOMP._IOwnership _out498; - Dafny.ISet> _out499; - (this).GenExpr(_1761_of, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out497, out _out498, out _out499); - _1762_exprGen = _out497; - _1763___v128 = _out498; - _1764_recIdents = _out499; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), (_1762_exprGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").iter()"))); - RAST._IExpr _out500; - DCOMP._IOwnership _out501; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out500, out _out501); - r = _out500; - resultingOwnership = _out501; - readIdents = _1764_recIdents; + RAST._IExpr _1927_exprGen; + DCOMP._IOwnership _1928___v153; + Dafny.ISet> _1929_recIdents; + RAST._IExpr _out547; + DCOMP._IOwnership _out548; + Dafny.ISet> _out549; + (this).GenExpr(_1926_of, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out547, out _out548, out _out549); + _1927_exprGen = _out547; + _1928___v153 = _out548; + _1929_recIdents = _out549; + r = ((((_1927_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply(Dafny.Sequence.FromElements())).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out550; + DCOMP._IOwnership _out551; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out550, out _out551); + r = _out550; + resultingOwnership = _out551; + readIdents = _1929_recIdents; return ; } } } - if (unmatched71) { - if (_source71.is_SeqBoundedPool) { - DAST._IExpression _1765_of = _source71.dtor_of; - bool _1766_includeDuplicates = _source71.dtor_includeDuplicates; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_SeqBoundedPool) { + DAST._IExpression _1930_of = _source74.dtor_of; + bool _1931_includeDuplicates = _source74.dtor_includeDuplicates; + unmatched74 = false; { - RAST._IExpr _1767_exprGen; - DCOMP._IOwnership _1768___v129; - Dafny.ISet> _1769_recIdents; - RAST._IExpr _out502; - DCOMP._IOwnership _out503; - Dafny.ISet> _out504; - (this).GenExpr(_1765_of, selfIdent, @params, DCOMP.Ownership.create_OwnershipBorrowed(), out _out502, out _out503, out _out504); - _1767_exprGen = _out502; - _1768___v129 = _out503; - _1769_recIdents = _out504; - Dafny.ISequence _1770_s; - _1770_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), (_1767_exprGen)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(").iter()")); - if (!(_1766_includeDuplicates)) { - _1770_s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::itertools::Itertools::unique("), _1770_s), Dafny.Sequence.UnicodeFromString(")")); + RAST._IExpr _1932_exprGen; + DCOMP._IOwnership _1933___v154; + Dafny.ISet> _1934_recIdents; + RAST._IExpr _out552; + DCOMP._IOwnership _out553; + Dafny.ISet> _out554; + (this).GenExpr(_1930_of, selfIdent, env, DCOMP.Ownership.create_OwnershipBorrowed(), out _out552, out _out553, out _out554); + _1932_exprGen = _out552; + _1933___v154 = _out553; + _1934_recIdents = _out554; + r = ((_1932_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply(Dafny.Sequence.FromElements()); + if (!(_1931_includeDuplicates)) { + r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).MSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } - r = RAST.Expr.create_RawExpr(_1770_s); - RAST._IExpr _out505; - DCOMP._IOwnership _out506; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out505, out _out506); - r = _out505; - resultingOwnership = _out506; - readIdents = _1769_recIdents; + RAST._IExpr _out555; + DCOMP._IOwnership _out556; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out555, out _out556); + r = _out555; + resultingOwnership = _out556; + readIdents = _1934_recIdents; return ; } } } - if (unmatched71) { - if (_source71.is_IntRange) { - DAST._IExpression _1771_lo = _source71.dtor_lo; - DAST._IExpression _1772_hi = _source71.dtor_hi; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_IntRange) { + DAST._IExpression _1935_lo = _source74.dtor_lo; + DAST._IExpression _1936_hi = _source74.dtor_hi; + unmatched74 = false; { - RAST._IExpr _1773_lo; - DCOMP._IOwnership _1774___v130; - Dafny.ISet> _1775_recIdentsLo; - RAST._IExpr _out507; - DCOMP._IOwnership _out508; - Dafny.ISet> _out509; - (this).GenExpr(_1771_lo, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out507, out _out508, out _out509); - _1773_lo = _out507; - _1774___v130 = _out508; - _1775_recIdentsLo = _out509; - RAST._IExpr _1776_hi; - DCOMP._IOwnership _1777___v131; - Dafny.ISet> _1778_recIdentsHi; - RAST._IExpr _out510; - DCOMP._IOwnership _out511; - Dafny.ISet> _out512; - (this).GenExpr(_1772_hi, selfIdent, @params, DCOMP.Ownership.create_OwnershipOwned(), out _out510, out _out511, out _out512); - _1776_hi = _out510; - _1777___v131 = _out511; - _1778_recIdentsHi = _out512; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::integer_range("), (_1773_lo)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(", ")), (_1776_hi)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(")"))); - RAST._IExpr _out513; - DCOMP._IOwnership _out514; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out513, out _out514); - r = _out513; - resultingOwnership = _out514; - readIdents = Dafny.Set>.Union(_1775_recIdentsLo, _1778_recIdentsHi); + RAST._IExpr _1937_lo; + DCOMP._IOwnership _1938___v155; + Dafny.ISet> _1939_recIdentsLo; + RAST._IExpr _out557; + DCOMP._IOwnership _out558; + Dafny.ISet> _out559; + (this).GenExpr(_1935_lo, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out557, out _out558, out _out559); + _1937_lo = _out557; + _1938___v155 = _out558; + _1939_recIdentsLo = _out559; + RAST._IExpr _1940_hi; + DCOMP._IOwnership _1941___v156; + Dafny.ISet> _1942_recIdentsHi; + RAST._IExpr _out560; + DCOMP._IOwnership _out561; + Dafny.ISet> _out562; + (this).GenExpr(_1936_hi, selfIdent, env, DCOMP.Ownership.create_OwnershipOwned(), out _out560, out _out561, out _out562); + _1940_hi = _out560; + _1941___v156 = _out561; + _1942_recIdentsHi = _out562; + r = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).Apply(Dafny.Sequence.FromElements(_1937_lo, _1940_hi)); + RAST._IExpr _out563; + DCOMP._IOwnership _out564; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out563, out _out564); + r = _out563; + resultingOwnership = _out564; + readIdents = Dafny.Set>.Union(_1939_recIdentsLo, _1942_recIdentsHi); return ; } } } - if (unmatched71) { - if (_source71.is_MapBuilder) { - DAST._IType _1779_keyType = _source71.dtor_keyType; - DAST._IType _1780_valueType = _source71.dtor_valueType; - unmatched71 = false; + if (unmatched74) { + if (_source74.is_MapBuilder) { + DAST._IType _1943_keyType = _source74.dtor_keyType; + DAST._IType _1944_valueType = _source74.dtor_valueType; + unmatched74 = false; { - RAST._IType _1781_kType; - RAST._IType _out515; - _out515 = (this).GenType(_1779_keyType, false, false); - _1781_kType = _out515; - RAST._IType _1782_vType; - RAST._IType _out516; - _out516 = (this).GenType(_1780_valueType, false, false); - _1782_vType = _out516; - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::MapBuilder::<"), (_1781_kType)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(", ")), (_1782_vType)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(">::new()"))); - RAST._IExpr _out517; - DCOMP._IOwnership _out518; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out517, out _out518); - r = _out517; - resultingOwnership = _out518; + RAST._IType _1945_kType; + RAST._IType _out565; + _out565 = (this).GenType(_1943_keyType, false, false); + _1945_kType = _out565; + RAST._IType _1946_vType; + RAST._IType _out566; + _out566 = (this).GenType(_1944_valueType, false, false); + _1946_vType = _out566; + r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).ApplyType(Dafny.Sequence.FromElements(_1945_kType, _1946_vType))).MSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out567; + DCOMP._IOwnership _out568; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out567, out _out568); + r = _out567; + resultingOwnership = _out568; readIdents = Dafny.Set>.FromElements(); return ; } } } - if (unmatched71) { - DAST._IType _1783_elemType = _source71.dtor_elemType; - unmatched71 = false; + if (unmatched74) { + DAST._IType _1947_elemType = _source74.dtor_elemType; + unmatched74 = false; { - RAST._IType _1784_eType; - RAST._IType _out519; - _out519 = (this).GenType(_1783_elemType, false, false); - _1784_eType = _out519; + RAST._IType _1948_eType; + RAST._IType _out569; + _out569 = (this).GenType(_1947_elemType, false, false); + _1948_eType = _out569; readIdents = Dafny.Set>.FromElements(); - r = RAST.Expr.create_RawExpr(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::dafny_runtime::SetBuilder::<"), (_1784_eType)._ToString(DCOMP.__default.IND)), Dafny.Sequence.UnicodeFromString(">::new()"))); - RAST._IExpr _out520; - DCOMP._IOwnership _out521; - DCOMP.COMP.FromOwned(r, expectedOwnership, out _out520, out _out521); - r = _out520; - resultingOwnership = _out521; + r = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).ApplyType(Dafny.Sequence.FromElements(_1948_eType))).MSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements()); + RAST._IExpr _out570; + DCOMP._IOwnership _out571; + DCOMP.COMP.FromOwned(r, expectedOwnership, out _out570, out _out571); + r = _out570; + resultingOwnership = _out571; return ; } } @@ -5031,21 +5594,20 @@ public void GenExpr(DAST._IExpression e, Std.Wrappers._IOption 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")); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("extern crate dafny_runtime;\n")); - BigInteger _1785_i; - _1785_i = BigInteger.Zero; - while ((_1785_i) < (new BigInteger((p).Count))) { - Dafny.ISequence _1786_generated = Dafny.Sequence.Empty; - RAST._IMod _1787_m; - RAST._IMod _out522; - _out522 = (this).GenModule((p).Select(_1785_i), Dafny.Sequence>.FromElements()); - _1787_m = _out522; - _1786_generated = (_1787_m)._ToString(Dafny.Sequence.UnicodeFromString("")); - if ((_1785_i).Sign == 1) { + BigInteger _1949_i; + _1949_i = BigInteger.Zero; + while ((_1949_i) < (new BigInteger((p).Count))) { + Dafny.ISequence _1950_generated = Dafny.Sequence.Empty; + RAST._IMod _1951_m; + RAST._IMod _out572; + _out572 = (this).GenModule((p).Select(_1949_i), Dafny.Sequence>.FromElements()); + _1951_m = _out572; + _1950_generated = (_1951_m)._ToString(Dafny.Sequence.UnicodeFromString("")); + if ((_1949_i).Sign == 1) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("\n")); } - s = Dafny.Sequence.Concat(s, _1786_generated); - _1785_i = (_1785_i) + (BigInteger.One); + s = Dafny.Sequence.Concat(s, _1950_generated); + _1949_i = (_1949_i) + (BigInteger.One); } return s; } @@ -5053,14 +5615,14 @@ public void GenExpr(DAST._IExpression e, Std.Wrappers._IOption s = Dafny.Sequence.Empty; s = Dafny.Sequence.UnicodeFromString("\nfn main() {\n"); - BigInteger _1788_i; - _1788_i = BigInteger.Zero; - while ((_1788_i) < (new BigInteger((fullName).Count))) { - if ((_1788_i).Sign == 1) { + BigInteger _1952_i; + _1952_i = BigInteger.Zero; + while ((_1952_i) < (new BigInteger((fullName).Count))) { + if ((_1952_i).Sign == 1) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("::")); } - s = Dafny.Sequence.Concat(s, DCOMP.__default.escapeIdent((fullName).Select(_1788_i))); - _1788_i = (_1788_i) + (BigInteger.One); + s = Dafny.Sequence.Concat(s, DCOMP.__default.escapeName((fullName).Select(_1952_i))); + _1952_i = (_1952_i) + (BigInteger.One); } s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("();\n}")); return s; @@ -5076,6 +5638,13 @@ public Dafny.ISequence DafnyChar { get { return Dafny.Sequence.UnicodeFromString("DafnyCharUTF16"); } } } + public RAST._IType DafnyCharUnderlying { get { + if ((this).UnicodeChars) { + return RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("char")); + } else { + return RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("u16")); + } + } } public Dafny.ISequence string__of { get { if ((this).UnicodeChars) { return Dafny.Sequence.UnicodeFromString("string_of"); diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 81bedfa3e..c10ca2e00 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -20,20 +20,6 @@ public partial class __default { return Dafny.Sequence.Concat(Dafny.Helpers.Id>>(f)((s).Select(BigInteger.Zero)), (((new BigInteger((s).Count)) > (BigInteger.One)) ? (Dafny.Sequence.Concat(separator, RAST.__default.SeqToString<__T>((s).Drop(BigInteger.One), f, separator))) : (Dafny.Sequence.UnicodeFromString("")))); } } - public static BigInteger SeqToHeight<__T>(Dafny.ISequence<__T> s, Func<__T, BigInteger> f) - { - if ((new BigInteger((s).Count)).Sign == 0) { - return BigInteger.Zero; - } else { - BigInteger _763_i = Dafny.Helpers.Id>(f)((s).Select(BigInteger.Zero)); - BigInteger _764_j = RAST.__default.SeqToHeight<__T>((s).Drop(BigInteger.One), f); - if ((_763_i) < (_764_j)) { - return _764_j; - } else { - return _763_i; - } - } - } public static RAST._IType Rc(RAST._IType underlying) { return RAST.Type.create_TypeApp(((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("rc"))).MSel(Dafny.Sequence.UnicodeFromString("Rc")), Dafny.Sequence.FromElements(underlying)); } @@ -44,10 +30,10 @@ 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)); } public static RAST._IExpr NewVec(Dafny.ISequence elements) { - return RAST.Expr.create_Call(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("vec!")), Dafny.Sequence.FromElements(), elements); + return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("vec!"))).Apply(elements); } public static RAST._IExpr Clone(RAST._IExpr underlying) { - return RAST.Expr.create_Call(RAST.Expr.create_Select(underlying, Dafny.Sequence.UnicodeFromString("clone")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements()); + return (RAST.Expr.create_Select(underlying, Dafny.Sequence.UnicodeFromString("clone"))).Apply(Dafny.Sequence.FromElements()); } public static RAST._IExpr Borrow(RAST._IExpr underlying) { return RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), underlying, DAST.Format.UnaryOpFormat.create_NoFormat()); @@ -58,35 +44,111 @@ public static RAST._IExpr BorrowMut(RAST._IExpr underlying) { public static RAST._IType RawType(Dafny.ISequence content) { return RAST.Type.create_TIdentifier(content); } + 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)); + } + public static bool IsImmutableConversion(RAST._IType fromTpe, RAST._IType toTpe) + { + _System._ITuple2 _source25 = _System.Tuple2.create(fromTpe, toTpe); + bool unmatched25 = true; + if (unmatched25) { + RAST._IType _00 = _source25.dtor__0; + if (_00.is_TypeApp) { + RAST._IType baseName0 = _00.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 _765_tpe1 = baseName0.dtor_name; + Dafny.ISequence _766_elems1 = _00.dtor_arguments; + RAST._IType _10 = _source25.dtor__1; + if (_10.is_TypeApp) { + RAST._IType baseName1 = _10.dtor_baseName; + if (baseName1.is_TMemberSelect) { + RAST._IType base2 = baseName1.dtor_base; + if (base2.is_TMemberSelect) { + RAST._IType base3 = base2.dtor_base; + if (base3.is_TIdentifier) { + Dafny.ISequence name2 = base3.dtor_name; + if (object.Equals(name2, Dafny.Sequence.UnicodeFromString(""))) { + Dafny.ISequence name3 = base2.dtor_name; + if (object.Equals(name3, Dafny.Sequence.UnicodeFromString("dafny_runtime"))) { + Dafny.ISequence _767_tpe2 = baseName1.dtor_name; + Dafny.ISequence _768_elems2 = _10.dtor_arguments; + unmatched25 = false; + return ((_765_tpe1).Equals(_767_tpe2)) && (((((_765_tpe1).Equals(Dafny.Sequence.UnicodeFromString("Set"))) || ((_765_tpe1).Equals(Dafny.Sequence.UnicodeFromString("Sequence")))) || ((_765_tpe1).Equals(Dafny.Sequence.UnicodeFromString("Multiset")))) || ((_765_tpe1).Equals(Dafny.Sequence.UnicodeFromString("Map")))); + } + } + } + } + } + } + } + } + } + } + } + } + } + if (unmatched25) { + _System._ITuple2 _769___v0 = _source25; + unmatched25 = false; + return false; + } + throw new System.Exception("unexpected control point"); + } + 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); + } + public static RAST._IExpr SystemTuple(Dafny.ISequence elements) { + Dafny.ISequence _770_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"), _770_size))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), _770_size)), ((System.Func>) (() => { + BigInteger dim10 = new BigInteger((elements).Count); + var arr10 = new RAST._IAssignIdentifier[Dafny.Helpers.ToIntChecked(dim10, "array size exceeds memory limit")]; + for (int i10 = 0; i10 < dim10; i10++) { + var _771_i = (BigInteger) i10; + arr10[(int)(_771_i)] = RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), Std.Strings.__default.OfNat(_771_i)), (elements).Select(_771_i)); + } + return Dafny.Sequence.FromArray(arr10); +}))()); + } public static Dafny.ISequence AddIndent(Dafny.ISequence raw, Dafny.ISequence ind) { - Dafny.ISequence _765___accumulator = Dafny.Sequence.FromElements(); + Dafny.ISequence _772___accumulator = Dafny.Sequence.FromElements(); TAIL_CALL_START: ; if ((new BigInteger((raw).Count)).Sign == 0) { - return Dafny.Sequence.Concat(_765___accumulator, raw); + return Dafny.Sequence.Concat(_772___accumulator, raw); } else if ((Dafny.Sequence.UnicodeFromString("[({")).Contains((raw).Select(BigInteger.Zero))) { - _765___accumulator = Dafny.Sequence.Concat(_765___accumulator, Dafny.Sequence.FromElements((raw).Select(BigInteger.Zero))); + _772___accumulator = Dafny.Sequence.Concat(_772___accumulator, Dafny.Sequence.FromElements((raw).Select(BigInteger.Zero))); Dafny.ISequence _in103 = (raw).Drop(BigInteger.One); Dafny.ISequence _in104 = Dafny.Sequence.Concat(ind, RAST.__default.IND); raw = _in103; ind = _in104; goto TAIL_CALL_START; } else if (((Dafny.Sequence.UnicodeFromString("})]")).Contains((raw).Select(BigInteger.Zero))) && ((new BigInteger((ind).Count)) > (new BigInteger(2)))) { - _765___accumulator = Dafny.Sequence.Concat(_765___accumulator, Dafny.Sequence.FromElements((raw).Select(BigInteger.Zero))); + _772___accumulator = Dafny.Sequence.Concat(_772___accumulator, Dafny.Sequence.FromElements((raw).Select(BigInteger.Zero))); Dafny.ISequence _in105 = (raw).Drop(BigInteger.One); Dafny.ISequence _in106 = (ind).Take((new BigInteger((ind).Count)) - (new BigInteger(2))); raw = _in105; ind = _in106; goto TAIL_CALL_START; } else if (((raw).Select(BigInteger.Zero)) == (new Dafny.Rune('\n'))) { - _765___accumulator = Dafny.Sequence.Concat(_765___accumulator, Dafny.Sequence.Concat(Dafny.Sequence.FromElements((raw).Select(BigInteger.Zero)), ind)); + _772___accumulator = Dafny.Sequence.Concat(_772___accumulator, Dafny.Sequence.Concat(Dafny.Sequence.FromElements((raw).Select(BigInteger.Zero)), ind)); Dafny.ISequence _in107 = (raw).Drop(BigInteger.One); Dafny.ISequence _in108 = ind; raw = _in107; ind = _in108; goto TAIL_CALL_START; } else { - _765___accumulator = Dafny.Sequence.Concat(_765___accumulator, Dafny.Sequence.FromElements((raw).Select(BigInteger.Zero))); + _772___accumulator = Dafny.Sequence.Concat(_772___accumulator, Dafny.Sequence.FromElements((raw).Select(BigInteger.Zero))); Dafny.ISequence _in109 = (raw).Drop(BigInteger.One); Dafny.ISequence _in110 = ind; raw = _in109; @@ -102,13 +164,24 @@ public static BigInteger max(BigInteger i, BigInteger j) return i; } } + public static RAST._IExpr AssignVar(Dafny.ISequence name, RAST._IExpr rhs) + { + return RAST.Expr.create_Assign(Std.Wrappers.Option.create_Some(RAST.AssignLhs.create_LocalVar(name)), rhs); + } + public static RAST._IExpr AssignMember(RAST._IExpr @on, Dafny.ISequence field, RAST._IExpr rhs) + { + return RAST.Expr.create_Assign(Std.Wrappers.Option.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); + } public static RAST._IExpr RcNew(RAST._IExpr underlying) { - return RAST.Expr.create_Call(RAST.__default.std__rc__Rc__new, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(underlying)); + return RAST.Expr.create_Call(RAST.__default.std__rc__Rc__new, Dafny.Sequence.FromElements(underlying)); } - public static RAST._IType Self { get { + public static RAST._IType SelfBorrowed { get { return RAST.Type.create_Borrowed(RAST.Type.create_SelfOwned()); } } - public static RAST._IType SelfMut { get { + public static RAST._IType SelfBorrowedMut { get { return RAST.Type.create_BorrowedMut(RAST.Type.create_SelfOwned()); } } public static RAST._IType global__type { get { @@ -117,30 +190,51 @@ public static RAST._IType global__type { get { public static RAST._IType std__type { get { return (RAST.__default.global__type).MSel(Dafny.Sequence.UnicodeFromString("std")); } } + public static RAST._IType super__type { get { + return RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("super")); + } } + public static RAST._IType cell__type { get { + return (RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("cell")); + } } + public static RAST._IType refcell__type { get { + return (RAST.__default.cell__type).MSel(Dafny.Sequence.UnicodeFromString("RefCell")); + } } + public static RAST._IType dafny__runtime__type { get { + return (RAST.__default.global__type).MSel(Dafny.Sequence.UnicodeFromString("dafny_runtime")); + } } public static RAST._IType CloneTrait { get { return RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("Clone")); } } - public static RAST._IType DafnyPrintTrait { get { - return RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("::dafny_runtime::DafnyPrint")); - } } public static RAST._IType DefaultTrait { get { - return RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("::std::default::Default")); + return ((RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default")); } } public static RAST._IType StaticTrait { get { return RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("'static")); } } - public static RAST._IType cell__type { get { - return (RAST.__default.std__type).MSel(Dafny.Sequence.UnicodeFromString("cell")); + public static RAST._IType DafnyType { get { + return (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")); } } - public static RAST._IType refcell__type { get { - return (RAST.__default.cell__type).MSel(Dafny.Sequence.UnicodeFromString("RefCell")); + public static RAST._IType DafnyPrint { get { + return (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint")); } } - public static RAST._IType dafny__runtime__type { get { - return (RAST.__default.global__type).MSel(Dafny.Sequence.UnicodeFromString("dafny_runtime")); + public static RAST._IType DafnyTypeEq { get { + return (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyTypeEq")); + } } + public static RAST._IType Eq { get { + return RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Eq")); + } } + public static RAST._IType DafnyInt { get { + return (RAST.__default.dafny__runtime__type).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt")); + } } + public static RAST._IExpr super { get { + return RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("super")); } } public static Dafny.ISequence IND { get { return Dafny.Sequence.UnicodeFromString(" "); } } + public static RAST._IExpr self { get { + return RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self")); + } } public static RAST._IExpr @global { get { return RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("")); } } @@ -180,6 +274,15 @@ public static RAST._IExpr std__rc__Rc { get { public static RAST._IExpr std__rc__Rc__new { get { return (RAST.__default.std__rc__Rc).MSel(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()); + } } + public static RAST._IExpr modify__macro { get { + return (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("modify!")); + } } + public static BigInteger MAX__TUPLE__SIZE { get { + return new BigInteger(12); + } } } public interface _IMod { @@ -228,22 +331,22 @@ public Dafny.ISequence dtor_body { var _pat_let_tv24 = ind; var _pat_let_tv25 = ind; var _pat_let_tv26 = ind; - RAST._IMod _source25 = this; - bool unmatched25 = true; - if (unmatched25) { - if (_source25.is_ExternMod) { - Dafny.ISequence _766_name = _source25.dtor_name; - unmatched25 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("mod "), _766_name), Dafny.Sequence.UnicodeFromString(";")); + RAST._IMod _source26 = this; + bool unmatched26 = true; + if (unmatched26) { + if (_source26.is_ExternMod) { + Dafny.ISequence _773_name = _source26.dtor_name; + unmatched26 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("pub mod "), _773_name), Dafny.Sequence.UnicodeFromString(";")); } } - if (unmatched25) { - Dafny.ISequence _767_name = _source25.dtor_name; - Dafny.ISequence _768_body = _source25.dtor_body; - unmatched25 = false; - 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("mod "), _767_name), Dafny.Sequence.UnicodeFromString(" {")), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv23), RAST.__default.IND), RAST.__default.SeqToString(_768_body, Dafny.Helpers.Id, Func>>>((_769_ind) => ((System.Func>)((_770_modDecl) => { - return (_770_modDecl)._ToString(Dafny.Sequence.Concat(_769_ind, RAST.__default.IND)); - })))(_pat_let_tv24), Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv25), RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv26), Dafny.Sequence.UnicodeFromString("}")); + if (unmatched26) { + Dafny.ISequence _774_name = _source26.dtor_name; + Dafny.ISequence _775_body = _source26.dtor_body; + unmatched26 = false; + 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 "), _774_name), Dafny.Sequence.UnicodeFromString(" {")), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv23), RAST.__default.IND), RAST.__default.SeqToString(_775_body, Dafny.Helpers.Id, Func>>>((_776_ind) => ((System.Func>)((_777_modDecl) => { + return (_777_modDecl)._ToString(Dafny.Sequence.Concat(_776_ind, RAST.__default.IND)); + })))(_pat_let_tv24), Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n\n"), _pat_let_tv25), RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv26), Dafny.Sequence.UnicodeFromString("}")); } throw new System.Exception("unexpected control point"); } @@ -626,8 +729,8 @@ public Dafny.ISequence dtor_content { } public static Dafny.ISequence ToStringMultiple(Dafny.ISequence> attributes, Dafny.ISequence ind) { - return RAST.__default.SeqToString>(attributes, Dafny.Helpers.Id, Func, Dafny.ISequence>>>((_771_ind) => ((System.Func, Dafny.ISequence>)((_772_attribute) => { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_772_attribute), Dafny.Sequence.UnicodeFromString("\n")), _771_ind); + return RAST.__default.SeqToString>(attributes, Dafny.Helpers.Id, Func, Dafny.ISequence>>>((_778_ind) => ((System.Func, Dafny.ISequence>)((_779_attribute) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_779_attribute), Dafny.Sequence.UnicodeFromString("\n")), _778_ind); })))(ind), Dafny.Sequence.UnicodeFromString("")); } } @@ -636,17 +739,17 @@ public interface _IStruct { bool is_Struct { get; } Dafny.ISequence> dtor_attributes { get; } Dafny.ISequence dtor_name { get; } - Dafny.ISequence dtor_typeParams { get; } - RAST._IFormals dtor_fields { get; } + Dafny.ISequence dtor_typeParams { get; } + RAST._IFields dtor_fields { get; } _IStruct DowncastClone(); Dafny.ISequence _ToString(Dafny.ISequence ind); } public class Struct : _IStruct { public readonly Dafny.ISequence> _attributes; public readonly Dafny.ISequence _name; - public readonly Dafny.ISequence _typeParams; - public readonly RAST._IFormals _fields; - public Struct(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFormals fields) { + public readonly Dafny.ISequence _typeParams; + public readonly RAST._IFields _fields; + public Struct(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { this._attributes = attributes; this._name = name; this._typeParams = typeParams; @@ -682,7 +785,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IStruct theDefault = create(Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Formals.Default()); + private static readonly RAST._IStruct theDefault = create(Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Fields.Default()); public static RAST._IStruct Default() { return theDefault; } @@ -690,10 +793,10 @@ public static RAST._IStruct Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IStruct create(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFormals fields) { + public static _IStruct create(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { return new Struct(attributes, name, typeParams, fields); } - public static _IStruct create_Struct(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFormals fields) { + public static _IStruct create_Struct(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { return create(attributes, name, typeParams, fields); } public bool is_Struct { get { return true; } } @@ -707,41 +810,41 @@ public Dafny.ISequence dtor_name { return this._name; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { return this._typeParams; } } - public RAST._IFormals dtor_fields { + public RAST._IFields dtor_fields { get { return this._fields; } } public Dafny.ISequence _ToString(Dafny.ISequence ind) { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind), Dafny.Sequence.UnicodeFromString("pub struct ")), (this).dtor_name), RAST.TypeParam.ToStringMultiple((this).dtor_typeParams, ind)), ((this).dtor_fields)._ToString(Dafny.Sequence.Concat(ind, RAST.__default.IND), ((this).dtor_fields).is_NamedFormals)), ((((this).dtor_fields).is_NamelessFormals) ? (Dafny.Sequence.UnicodeFromString(";")) : (Dafny.Sequence.UnicodeFromString("")))); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind), Dafny.Sequence.UnicodeFromString("pub struct ")), (this).dtor_name), RAST.TypeParamDecl.ToStringMultiple((this).dtor_typeParams, ind)), ((this).dtor_fields)._ToString(ind, ((this).dtor_fields).is_NamedFields)), ((((this).dtor_fields).is_NamelessFields) ? (Dafny.Sequence.UnicodeFromString(";")) : (Dafny.Sequence.UnicodeFromString("")))); } } - public interface _INamelessFormal { - bool is_NamelessFormal { get; } + public interface _INamelessField { + bool is_NamelessField { get; } RAST._IVisibility dtor_visibility { get; } RAST._IType dtor_tpe { get; } - _INamelessFormal DowncastClone(); + _INamelessField DowncastClone(); Dafny.ISequence _ToString(Dafny.ISequence ind); } - public class NamelessFormal : _INamelessFormal { + public class NamelessField : _INamelessField { public readonly RAST._IVisibility _visibility; public readonly RAST._IType _tpe; - public NamelessFormal(RAST._IVisibility visibility, RAST._IType tpe) { + public NamelessField(RAST._IVisibility visibility, RAST._IType tpe) { this._visibility = visibility; this._tpe = tpe; } - public _INamelessFormal DowncastClone() { - if (this is _INamelessFormal dt) { return dt; } - return new NamelessFormal(_visibility, _tpe); + public _INamelessField DowncastClone() { + if (this is _INamelessField dt) { return dt; } + return new NamelessField(_visibility, _tpe); } public override bool Equals(object other) { - var oth = other as RAST.NamelessFormal; + var oth = other as RAST.NamelessField; return oth != null && object.Equals(this._visibility, oth._visibility) && object.Equals(this._tpe, oth._tpe); } public override int GetHashCode() { @@ -752,7 +855,7 @@ public override int GetHashCode() { return (int) hash; } public override string ToString() { - string s = "RAST.NamelessFormal.NamelessFormal"; + string s = "RAST.NamelessField.NamelessField"; s += "("; s += Dafny.Helpers.ToString(this._visibility); s += ", "; @@ -760,21 +863,21 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._INamelessFormal theDefault = create(RAST.Visibility.Default(), RAST.Type.Default()); - public static RAST._INamelessFormal Default() { + private static readonly RAST._INamelessField theDefault = create(RAST.Visibility.Default(), RAST.Type.Default()); + public static RAST._INamelessField Default() { return theDefault; } - private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.NamelessFormal.Default()); - public static Dafny.TypeDescriptor _TypeDescriptor() { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.NamelessField.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _INamelessFormal create(RAST._IVisibility visibility, RAST._IType tpe) { - return new NamelessFormal(visibility, tpe); + public static _INamelessField create(RAST._IVisibility visibility, RAST._IType tpe) { + return new NamelessField(visibility, tpe); } - public static _INamelessFormal create_NamelessFormal(RAST._IVisibility visibility, RAST._IType tpe) { + public static _INamelessField create_NamelessField(RAST._IVisibility visibility, RAST._IType tpe) { return create(visibility, tpe); } - public bool is_NamelessFormal { get { return true; } } + public bool is_NamelessField { get { return true; } } public RAST._IVisibility dtor_visibility { get { return this._visibility; @@ -786,79 +889,163 @@ public RAST._IType dtor_tpe { } } public Dafny.ISequence _ToString(Dafny.ISequence ind) { - return Dafny.Sequence.Concat(((object.Equals((this).dtor_visibility, RAST.Visibility.create_PUB())) ? (Dafny.Sequence.UnicodeFromString("pub ")) : (Dafny.Sequence.UnicodeFromString(""))), ((this).dtor_tpe)._ToString(ind)); + return Dafny.Sequence.Concat(((this).dtor_visibility)._ToString(), ((this).dtor_tpe)._ToString(ind)); + } + } + + public interface _IField { + bool is_Field { get; } + RAST._IVisibility dtor_visibility { get; } + RAST._IFormal dtor_formal { get; } + _IField DowncastClone(); + Dafny.ISequence _ToString(Dafny.ISequence ind); + RAST._INamelessField ToNamelessField(); + } + public class Field : _IField { + public readonly RAST._IVisibility _visibility; + public readonly RAST._IFormal _formal; + public Field(RAST._IVisibility visibility, RAST._IFormal formal) { + this._visibility = visibility; + this._formal = formal; + } + public _IField DowncastClone() { + if (this is _IField dt) { return dt; } + return new Field(_visibility, _formal); + } + public override bool Equals(object other) { + var oth = other as RAST.Field; + return oth != null && object.Equals(this._visibility, oth._visibility) && object.Equals(this._formal, oth._formal); + } + 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._formal)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.Field.Field"; + s += "("; + s += Dafny.Helpers.ToString(this._visibility); + s += ", "; + s += Dafny.Helpers.ToString(this._formal); + s += ")"; + return s; + } + private static readonly RAST._IField theDefault = create(RAST.Visibility.Default(), RAST.Formal.Default()); + public static RAST._IField Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.Field.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IField create(RAST._IVisibility visibility, RAST._IFormal formal) { + return new Field(visibility, formal); + } + public static _IField create_Field(RAST._IVisibility visibility, RAST._IFormal formal) { + return create(visibility, formal); + } + public bool is_Field { get { return true; } } + public RAST._IVisibility dtor_visibility { + get { + return this._visibility; + } + } + public RAST._IFormal dtor_formal { + get { + return this._formal; + } + } + public Dafny.ISequence _ToString(Dafny.ISequence ind) { + return Dafny.Sequence.Concat(((this).dtor_visibility)._ToString(), ((this).dtor_formal)._ToString(ind)); + } + public RAST._INamelessField ToNamelessField() { + return RAST.NamelessField.create((this).dtor_visibility, ((this).dtor_formal).dtor_tpe); } } - public interface _IFormals { - bool is_NamedFormals { get; } - bool is_NamelessFormals { get; } - Dafny.ISequence dtor_fields { get; } - Dafny.ISequence dtor_types { get; } - _IFormals DowncastClone(); + public interface _IFields { + bool is_NamedFields { get; } + bool is_NamelessFields { get; } + Dafny.ISequence dtor_fields { get; } + Dafny.ISequence dtor_types { get; } + _IFields DowncastClone(); + RAST._IFields ToNamelessFields(); Dafny.ISequence _ToString(Dafny.ISequence ind, bool newLine); } - public abstract class Formals : _IFormals { - public Formals() { + public abstract class Fields : _IFields { + public Fields() { } - private static readonly RAST._IFormals theDefault = create_NamedFormals(Dafny.Sequence.Empty); - public static RAST._IFormals Default() { + private static readonly RAST._IFields theDefault = create_NamedFields(Dafny.Sequence.Empty); + public static RAST._IFields Default() { return theDefault; } - private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.Formals.Default()); - public static Dafny.TypeDescriptor _TypeDescriptor() { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.Fields.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IFormals create_NamedFormals(Dafny.ISequence fields) { - return new Formals_NamedFormals(fields); + public static _IFields create_NamedFields(Dafny.ISequence fields) { + return new Fields_NamedFields(fields); } - public static _IFormals create_NamelessFormals(Dafny.ISequence types) { - return new Formals_NamelessFormals(types); + public static _IFields create_NamelessFields(Dafny.ISequence types) { + return new Fields_NamelessFields(types); } - public bool is_NamedFormals { get { return this is Formals_NamedFormals; } } - public bool is_NamelessFormals { get { return this is Formals_NamelessFormals; } } - public Dafny.ISequence dtor_fields { + public bool is_NamedFields { get { return this is Fields_NamedFields; } } + public bool is_NamelessFields { get { return this is Fields_NamelessFields; } } + public Dafny.ISequence dtor_fields { get { var d = this; - return ((Formals_NamedFormals)d)._fields; + return ((Fields_NamedFields)d)._fields; } } - public Dafny.ISequence dtor_types { + public Dafny.ISequence dtor_types { get { var d = this; - return ((Formals_NamelessFormals)d)._types; + return ((Fields_NamelessFields)d)._types; } } - public abstract _IFormals DowncastClone(); + public abstract _IFields DowncastClone(); + public RAST._IFields ToNamelessFields() { + return RAST.Fields.create_NamelessFields(((System.Func>) (() => { + BigInteger dim11 = new BigInteger(((this).dtor_fields).Count); + var arr11 = new RAST._INamelessField[Dafny.Helpers.ToIntChecked(dim11, "array size exceeds memory limit")]; + for (int i11 = 0; i11 < dim11; i11++) { + var _780_i = (BigInteger) i11; + arr11[(int)(_780_i)] = (((this).dtor_fields).Select(_780_i)).ToNamelessField(); + } + return Dafny.Sequence.FromArray(arr11); +}))()); + } public Dafny.ISequence _ToString(Dafny.ISequence ind, bool newLine) { - if ((this).is_NamedFormals) { - Dafny.ISequence _773_separator = ((newLine) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(",\n"), ind), RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(", "))); + if ((this).is_NamedFields) { + Dafny.ISequence _781_separator = ((newLine) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(",\n"), ind), RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(", "))); _System._ITuple2, Dafny.ISequence> _let_tmp_rhs40 = (((newLine) && ((new BigInteger(((this).dtor_fields).Count)).Sign == 1)) ? (_System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND), Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind))) : ((((new BigInteger(((this).dtor_fields).Count)).Sign == 1) ? (_System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString(" "), Dafny.Sequence.UnicodeFromString(" "))) : (_System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("")))))); - Dafny.ISequence _774_beginSpace = _let_tmp_rhs40.dtor__0; - Dafny.ISequence _775_endSpace = _let_tmp_rhs40.dtor__1; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" {"), _774_beginSpace), RAST.__default.SeqToString((this).dtor_fields, Dafny.Helpers.Id, Func>>>((_776_ind) => ((System.Func>)((_777_field) => { - return (_777_field)._ToString(Dafny.Sequence.Concat(_776_ind, RAST.__default.IND)); - })))(ind), _773_separator)), _775_endSpace), Dafny.Sequence.UnicodeFromString("}")); + Dafny.ISequence _782_beginSpace = _let_tmp_rhs40.dtor__0; + Dafny.ISequence _783_endSpace = _let_tmp_rhs40.dtor__1; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" {"), _782_beginSpace), RAST.__default.SeqToString((this).dtor_fields, Dafny.Helpers.Id, Func>>>((_784_ind) => ((System.Func>)((_785_field) => { + return (_785_field)._ToString(Dafny.Sequence.Concat(_784_ind, RAST.__default.IND)); + })))(ind), _781_separator)), _783_endSpace), Dafny.Sequence.UnicodeFromString("}")); } else { - Dafny.ISequence _778_separator = ((newLine) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(",\n"), ind), RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(", "))); - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString((this).dtor_types, Dafny.Helpers.Id, Func>>>((_779_ind) => ((System.Func>)((_780_t) => { - return (_780_t)._ToString(Dafny.Sequence.Concat(_779_ind, RAST.__default.IND)); - })))(ind), _778_separator)), Dafny.Sequence.UnicodeFromString(")")); + Dafny.ISequence _786_separator = ((newLine) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(",\n"), ind), RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(", "))); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString((this).dtor_types, Dafny.Helpers.Id, Func>>>((_787_ind) => ((System.Func>)((_788_t) => { + return (_788_t)._ToString(Dafny.Sequence.Concat(_787_ind, RAST.__default.IND)); + })))(ind), _786_separator)), Dafny.Sequence.UnicodeFromString(")")); } } } - public class Formals_NamedFormals : Formals { - public readonly Dafny.ISequence _fields; - public Formals_NamedFormals(Dafny.ISequence fields) : base() { + public class Fields_NamedFields : Fields { + public readonly Dafny.ISequence _fields; + public Fields_NamedFields(Dafny.ISequence fields) : base() { this._fields = fields; } - public override _IFormals DowncastClone() { - if (this is _IFormals dt) { return dt; } - return new Formals_NamedFormals(_fields); + public override _IFields DowncastClone() { + if (this is _IFields dt) { return dt; } + return new Fields_NamedFields(_fields); } public override bool Equals(object other) { - var oth = other as RAST.Formals_NamedFormals; + var oth = other as RAST.Fields_NamedFields; return oth != null && object.Equals(this._fields, oth._fields); } public override int GetHashCode() { @@ -868,24 +1055,24 @@ public override int GetHashCode() { return (int) hash; } public override string ToString() { - string s = "RAST.Formals.NamedFormals"; + string s = "RAST.Fields.NamedFields"; s += "("; s += Dafny.Helpers.ToString(this._fields); s += ")"; return s; } } - public class Formals_NamelessFormals : Formals { - public readonly Dafny.ISequence _types; - public Formals_NamelessFormals(Dafny.ISequence types) : base() { + public class Fields_NamelessFields : Fields { + public readonly Dafny.ISequence _types; + public Fields_NamelessFields(Dafny.ISequence types) : base() { this._types = types; } - public override _IFormals DowncastClone() { - if (this is _IFormals dt) { return dt; } - return new Formals_NamelessFormals(_types); + public override _IFields DowncastClone() { + if (this is _IFields dt) { return dt; } + return new Fields_NamelessFields(_types); } public override bool Equals(object other) { - var oth = other as RAST.Formals_NamelessFormals; + var oth = other as RAST.Fields_NamelessFields; return oth != null && object.Equals(this._types, oth._types); } public override int GetHashCode() { @@ -895,7 +1082,7 @@ public override int GetHashCode() { return (int) hash; } public override string ToString() { - string s = "RAST.Formals.NamelessFormals"; + string s = "RAST.Fields.NamelessFields"; s += "("; s += Dafny.Helpers.ToString(this._types); s += ")"; @@ -906,14 +1093,14 @@ public override string ToString() { public interface _IEnumCase { bool is_EnumCase { get; } Dafny.ISequence dtor_name { get; } - RAST._IFormals dtor_fields { get; } + RAST._IFields dtor_fields { get; } _IEnumCase DowncastClone(); Dafny.ISequence _ToString(Dafny.ISequence ind, bool newLine); } public class EnumCase : _IEnumCase { public readonly Dafny.ISequence _name; - public readonly RAST._IFormals _fields; - public EnumCase(Dafny.ISequence name, RAST._IFormals fields) { + public readonly RAST._IFields _fields; + public EnumCase(Dafny.ISequence name, RAST._IFields fields) { this._name = name; this._fields = fields; } @@ -941,7 +1128,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IEnumCase theDefault = create(Dafny.Sequence.Empty, RAST.Formals.Default()); + private static readonly RAST._IEnumCase theDefault = create(Dafny.Sequence.Empty, RAST.Fields.Default()); public static RAST._IEnumCase Default() { return theDefault; } @@ -949,10 +1136,10 @@ public static RAST._IEnumCase Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IEnumCase create(Dafny.ISequence name, RAST._IFormals fields) { + public static _IEnumCase create(Dafny.ISequence name, RAST._IFields fields) { return new EnumCase(name, fields); } - public static _IEnumCase create_EnumCase(Dafny.ISequence name, RAST._IFormals fields) { + public static _IEnumCase create_EnumCase(Dafny.ISequence name, RAST._IFields fields) { return create(name, fields); } public bool is_EnumCase { get { return true; } } @@ -961,7 +1148,7 @@ public Dafny.ISequence dtor_name { return this._name; } } - public RAST._IFormals dtor_fields { + public RAST._IFields dtor_fields { get { return this._fields; } @@ -976,7 +1163,7 @@ public interface _IEnum { bool is_Enum { get; } Dafny.ISequence> dtor_attributes { get; } Dafny.ISequence dtor_name { get; } - Dafny.ISequence dtor_typeParams { get; } + Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_variants { get; } _IEnum DowncastClone(); Dafny.ISequence _ToString(Dafny.ISequence ind); @@ -984,9 +1171,9 @@ public interface _IEnum { public class Enum : _IEnum { public readonly Dafny.ISequence> _attributes; public readonly Dafny.ISequence _name; - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _variants; - public Enum(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + public Enum(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { this._attributes = attributes; this._name = name; this._typeParams = typeParams; @@ -1022,7 +1209,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IEnum theDefault = create(Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly RAST._IEnum theDefault = create(Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._IEnum Default() { return theDefault; } @@ -1030,10 +1217,10 @@ public static RAST._IEnum Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IEnum create(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + public static _IEnum create(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { return new Enum(attributes, name, typeParams, variants); } - public static _IEnum create_Enum(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + public static _IEnum create_Enum(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { return create(attributes, name, typeParams, variants); } public bool is_Enum { get { return true; } } @@ -1047,7 +1234,7 @@ public Dafny.ISequence dtor_name { return this._name; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { return this._typeParams; } @@ -1058,33 +1245,33 @@ public Dafny.ISequence dtor_variants { } } public Dafny.ISequence _ToString(Dafny.ISequence 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(RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind), Dafny.Sequence.UnicodeFromString("pub enum ")), (this).dtor_name), RAST.TypeParam.ToStringMultiple((this).dtor_typeParams, ind)), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_variants, Dafny.Helpers.Id, Func>>>((_781_ind) => ((System.Func>)((_782_variant) => { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _781_ind), RAST.__default.IND), (_782_variant)._ToString(Dafny.Sequence.Concat(_781_ind, RAST.__default.IND), false)); + 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(RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind), Dafny.Sequence.UnicodeFromString("pub enum ")), (this).dtor_name), RAST.TypeParamDecl.ToStringMultiple((this).dtor_typeParams, ind)), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_variants, Dafny.Helpers.Id, Func>>>((_789_ind) => ((System.Func>)((_790_variant) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _789_ind), RAST.__default.IND), (_790_variant)._ToString(Dafny.Sequence.Concat(_789_ind, RAST.__default.IND), true)); })))(ind), Dafny.Sequence.UnicodeFromString(","))), Dafny.Sequence.UnicodeFromString("\n")), ind), Dafny.Sequence.UnicodeFromString("}")); } } - public interface _ITypeParam { - bool is_RawTypeParam { get; } + public interface _ITypeParamDecl { + bool is_TypeParamDecl { get; } Dafny.ISequence dtor_content { get; } Dafny.ISequence dtor_constraints { get; } - _ITypeParam DowncastClone(); - RAST._ITypeParam AddConstraints(Dafny.ISequence constraints); + _ITypeParamDecl DowncastClone(); + RAST._ITypeParamDecl AddConstraints(Dafny.ISequence constraints); Dafny.ISequence _ToString(Dafny.ISequence ind); } - public class TypeParam : _ITypeParam { + public class TypeParamDecl : _ITypeParamDecl { public readonly Dafny.ISequence _content; public readonly Dafny.ISequence _constraints; - public TypeParam(Dafny.ISequence content, Dafny.ISequence constraints) { + public TypeParamDecl(Dafny.ISequence content, Dafny.ISequence constraints) { this._content = content; this._constraints = constraints; } - public _ITypeParam DowncastClone() { - if (this is _ITypeParam dt) { return dt; } - return new TypeParam(_content, _constraints); + public _ITypeParamDecl DowncastClone() { + if (this is _ITypeParamDecl dt) { return dt; } + return new TypeParamDecl(_content, _constraints); } public override bool Equals(object other) { - var oth = other as RAST.TypeParam; + var oth = other as RAST.TypeParamDecl; return oth != null && object.Equals(this._content, oth._content) && object.Equals(this._constraints, oth._constraints); } public override int GetHashCode() { @@ -1095,7 +1282,7 @@ public override int GetHashCode() { return (int) hash; } public override string ToString() { - string s = "RAST.TypeParam.RawTypeParam"; + string s = "RAST.TypeParamDecl.TypeParamDecl"; s += "("; s += this._content.ToVerbatimString(true); s += ", "; @@ -1103,21 +1290,21 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITypeParam theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty); - public static RAST._ITypeParam Default() { + private static readonly RAST._ITypeParamDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty); + public static RAST._ITypeParamDecl Default() { return theDefault; } - private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.TypeParam.Default()); - public static Dafny.TypeDescriptor _TypeDescriptor() { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.TypeParamDecl.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITypeParam create(Dafny.ISequence content, Dafny.ISequence constraints) { - return new TypeParam(content, constraints); + public static _ITypeParamDecl create(Dafny.ISequence content, Dafny.ISequence constraints) { + return new TypeParamDecl(content, constraints); } - public static _ITypeParam create_RawTypeParam(Dafny.ISequence content, Dafny.ISequence constraints) { + public static _ITypeParamDecl create_TypeParamDecl(Dafny.ISequence content, Dafny.ISequence constraints) { return create(content, constraints); } - public bool is_RawTypeParam { get { return true; } } + public bool is_TypeParamDecl { get { return true; } } public Dafny.ISequence dtor_content { get { return this._content; @@ -1128,39 +1315,39 @@ public Dafny.ISequence dtor_constraints { return this._constraints; } } - public static Dafny.ISequence ToStringMultiple(Dafny.ISequence typeParams, Dafny.ISequence ind) + public static Dafny.ISequence ToStringMultiple(Dafny.ISequence typeParams, Dafny.ISequence ind) { if ((new BigInteger((typeParams).Count)).Sign == 0) { return Dafny.Sequence.UnicodeFromString(""); } else { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), RAST.__default.SeqToString(typeParams, Dafny.Helpers.Id, Func>>>((_783_ind) => ((System.Func>)((_784_t) => { - return (_784_t)._ToString(Dafny.Sequence.Concat(_783_ind, RAST.__default.IND)); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), RAST.__default.SeqToString(typeParams, Dafny.Helpers.Id, Func>>>((_791_ind) => ((System.Func>)((_792_t) => { + return (_792_t)._ToString(Dafny.Sequence.Concat(_791_ind, RAST.__default.IND)); })))(ind), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(">")); } } - public static Dafny.ISequence AddConstraintsMultiple(Dafny.ISequence typeParams, Dafny.ISequence constraints) + public static Dafny.ISequence AddConstraintsMultiple(Dafny.ISequence typeParams, Dafny.ISequence constraints) { - Dafny.ISequence _785___accumulator = Dafny.Sequence.FromElements(); + Dafny.ISequence _793___accumulator = Dafny.Sequence.FromElements(); TAIL_CALL_START: ; if ((new BigInteger((typeParams).Count)).Sign == 0) { - return Dafny.Sequence.Concat(_785___accumulator, Dafny.Sequence.FromElements()); + return Dafny.Sequence.Concat(_793___accumulator, Dafny.Sequence.FromElements()); } else { - _785___accumulator = Dafny.Sequence.Concat(_785___accumulator, Dafny.Sequence.FromElements(((typeParams).Select(BigInteger.Zero)).AddConstraints(constraints))); - Dafny.ISequence _in111 = (typeParams).Drop(BigInteger.One); + _793___accumulator = Dafny.Sequence.Concat(_793___accumulator, Dafny.Sequence.FromElements(((typeParams).Select(BigInteger.Zero)).AddConstraints(constraints))); + Dafny.ISequence _in111 = (typeParams).Drop(BigInteger.One); Dafny.ISequence _in112 = constraints; typeParams = _in111; constraints = _in112; goto TAIL_CALL_START; } } - public RAST._ITypeParam AddConstraints(Dafny.ISequence constraints) { - RAST._ITypeParam _786_dt__update__tmp_h0 = this; - Dafny.ISequence _787_dt__update_hconstraints_h0 = Dafny.Sequence.Concat((this).dtor_constraints, constraints); - return RAST.TypeParam.create((_786_dt__update__tmp_h0).dtor_content, _787_dt__update_hconstraints_h0); + public RAST._ITypeParamDecl AddConstraints(Dafny.ISequence constraints) { + RAST._ITypeParamDecl _794_dt__update__tmp_h0 = this; + Dafny.ISequence _795_dt__update_hconstraints_h0 = Dafny.Sequence.Concat((this).dtor_constraints, constraints); + return RAST.TypeParamDecl.create((_794_dt__update__tmp_h0).dtor_content, _795_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>>>((_788_ind) => ((System.Func>)((_789_t) => { - return (_789_t)._ToString(Dafny.Sequence.Concat(_788_ind, RAST.__default.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>>>((_796_ind) => ((System.Func>)((_797_t) => { + return (_797_t)._ToString(Dafny.Sequence.Concat(_796_ind, RAST.__default.IND)); })))(ind), Dafny.Sequence.UnicodeFromString(" + ")))))); } } @@ -1177,6 +1364,7 @@ public interface _IType { bool is_I32 { get; } bool is_I64 { get; } bool is_I128 { get; } + bool is_Bool { get; } bool is_TIdentifier { get; } bool is_TMemberSelect { get; } bool is_TypeApp { get; } @@ -1196,9 +1384,12 @@ public interface _IType { RAST._IType dtor_left { get; } RAST._IType dtor_right { get; } _IType DowncastClone(); + bool CanReadWithoutClone(); 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(); } public abstract class Type : _IType { public Type() { @@ -1244,6 +1435,9 @@ public static _IType create_I64() { public static _IType create_I128() { return new Type_I128(); } + public static _IType create_Bool() { + return new Type_Bool(); + } public static _IType create_TIdentifier(Dafny.ISequence name) { return new Type_TIdentifier(name); } @@ -1285,6 +1479,7 @@ public static _IType create_IntersectionType(RAST._IType left, RAST._IType right public bool is_I32 { get { return this is Type_I32; } } public bool is_I64 { get { return this is Type_I64; } } 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_TypeApp { get { return this is Type_TypeApp; } } @@ -1350,6 +1545,9 @@ public RAST._IType dtor_right { } } public abstract _IType DowncastClone(); + 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); + } public Dafny.ISequence _ToString(Dafny.ISequence ind) { var _pat_let_tv27 = ind; var _pat_let_tv28 = ind; @@ -1363,154 +1561,160 @@ public RAST._IType dtor_right { var _pat_let_tv36 = ind; var _pat_let_tv37 = ind; var _pat_let_tv38 = ind; - RAST._IType _source26 = this; - bool unmatched26 = true; - if (unmatched26) { - if (_source26.is_TIdentifier) { - Dafny.ISequence _790_underlying = _source26.dtor_name; - unmatched26 = false; - return _790_underlying; + RAST._IType _source27 = this; + bool unmatched27 = true; + if (unmatched27) { + if (_source27.is_Bool) { + unmatched27 = false; + return Dafny.Sequence.UnicodeFromString("bool"); } } - if (unmatched26) { - if (_source26.is_TMemberSelect) { - RAST._IType _791_underlying = _source26.dtor_base; - Dafny.ISequence _792_name = _source26.dtor_name; - unmatched26 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_791_underlying)._ToString(_pat_let_tv27), Dafny.Sequence.UnicodeFromString("::")), _792_name); + if (unmatched27) { + if (_source27.is_TIdentifier) { + Dafny.ISequence _798_underlying = _source27.dtor_name; + unmatched27 = false; + return _798_underlying; } } - if (unmatched26) { - if (_source26.is_Borrowed) { - RAST._IType _793_underlying = _source26.dtor_underlying; - unmatched26 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&"), (_793_underlying)._ToString(_pat_let_tv28)); + if (unmatched27) { + if (_source27.is_TMemberSelect) { + RAST._IType _799_underlying = _source27.dtor_base; + Dafny.ISequence _800_name = _source27.dtor_name; + unmatched27 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_799_underlying)._ToString(_pat_let_tv27), Dafny.Sequence.UnicodeFromString("::")), _800_name); } } - if (unmatched26) { - if (_source26.is_BorrowedMut) { - RAST._IType _794_underlying = _source26.dtor_underlying; - unmatched26 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&mut "), (_794_underlying)._ToString(_pat_let_tv29)); + if (unmatched27) { + if (_source27.is_Borrowed) { + RAST._IType _801_underlying = _source27.dtor_underlying; + unmatched27 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&"), (_801_underlying)._ToString(_pat_let_tv28)); } } - if (unmatched26) { - if (_source26.is_ImplType) { - RAST._IType _795_underlying = _source26.dtor_underlying; - unmatched26 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("impl "), (_795_underlying)._ToString(_pat_let_tv30)); + if (unmatched27) { + if (_source27.is_BorrowedMut) { + RAST._IType _802_underlying = _source27.dtor_underlying; + unmatched27 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&mut "), (_802_underlying)._ToString(_pat_let_tv29)); } } - if (unmatched26) { - if (_source26.is_DynType) { - RAST._IType _796_underlying = _source26.dtor_underlying; - unmatched26 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("dyn "), (_796_underlying)._ToString(_pat_let_tv31)); + if (unmatched27) { + if (_source27.is_ImplType) { + RAST._IType _803_underlying = _source27.dtor_underlying; + unmatched27 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("impl "), (_803_underlying)._ToString(_pat_let_tv30)); } } - if (unmatched26) { - if (_source26.is_FnType) { - Dafny.ISequence _797_arguments = _source26.dtor_arguments; - RAST._IType _798_returnType = _source26.dtor_returnType; - unmatched26 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Fn("), RAST.__default.SeqToString(_797_arguments, Dafny.Helpers.Id, Func>>>((_799_ind) => ((System.Func>)((_800_arg) => { - return (_800_arg)._ToString(Dafny.Sequence.Concat(_799_ind, RAST.__default.IND)); - })))(_pat_let_tv32), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") -> ")), (_798_returnType)._ToString(Dafny.Sequence.Concat(_pat_let_tv33, RAST.__default.IND))); + if (unmatched27) { + if (_source27.is_DynType) { + RAST._IType _804_underlying = _source27.dtor_underlying; + unmatched27 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("dyn "), (_804_underlying)._ToString(_pat_let_tv31)); } } - if (unmatched26) { - if (_source26.is_IntersectionType) { - RAST._IType _801_left = _source26.dtor_left; - RAST._IType _802_right = _source26.dtor_right; - unmatched26 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_801_left)._ToString(_pat_let_tv34), Dafny.Sequence.UnicodeFromString(" + ")), (_802_right)._ToString(_pat_let_tv35)); + if (unmatched27) { + if (_source27.is_FnType) { + Dafny.ISequence _805_arguments = _source27.dtor_arguments; + RAST._IType _806_returnType = _source27.dtor_returnType; + unmatched27 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::std::ops::Fn("), RAST.__default.SeqToString(_805_arguments, Dafny.Helpers.Id, Func>>>((_807_ind) => ((System.Func>)((_808_arg) => { + return (_808_arg)._ToString(Dafny.Sequence.Concat(_807_ind, RAST.__default.IND)); + })))(_pat_let_tv32), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") -> ")), (_806_returnType)._ToString(Dafny.Sequence.Concat(_pat_let_tv33, RAST.__default.IND))); } } - if (unmatched26) { - if (_source26.is_TupleType) { - Dafny.ISequence _803_args = _source26.dtor_arguments; - unmatched26 = false; - if ((_803_args).Equals(Dafny.Sequence.FromElements())) { + if (unmatched27) { + if (_source27.is_IntersectionType) { + RAST._IType _809_left = _source27.dtor_left; + RAST._IType _810_right = _source27.dtor_right; + unmatched27 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_809_left)._ToString(_pat_let_tv34), Dafny.Sequence.UnicodeFromString(" + ")), (_810_right)._ToString(_pat_let_tv35)); + } + } + if (unmatched27) { + if (_source27.is_TupleType) { + Dafny.ISequence _811_args = _source27.dtor_arguments; + unmatched27 = false; + if ((_811_args).Equals(Dafny.Sequence.FromElements())) { return Dafny.Sequence.UnicodeFromString("()"); } else { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString(_803_args, Dafny.Helpers.Id, Func>>>((_804_ind) => ((System.Func>)((_805_arg) => { - return (_805_arg)._ToString(Dafny.Sequence.Concat(_804_ind, RAST.__default.IND)); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString(_811_args, Dafny.Helpers.Id, Func>>>((_812_ind) => ((System.Func>)((_813_arg) => { + return (_813_arg)._ToString(Dafny.Sequence.Concat(_812_ind, RAST.__default.IND)); })))(_pat_let_tv36), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(")")); } } } - if (unmatched26) { - if (_source26.is_TypeApp) { - RAST._IType _806_base = _source26.dtor_baseName; - Dafny.ISequence _807_args = _source26.dtor_arguments; - unmatched26 = false; - return Dafny.Sequence.Concat((_806_base)._ToString(_pat_let_tv37), (((_807_args).Equals(Dafny.Sequence.FromElements())) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), RAST.__default.SeqToString(_807_args, Dafny.Helpers.Id, Func>>>((_808_ind) => ((System.Func>)((_809_arg) => { - return (_809_arg)._ToString(Dafny.Sequence.Concat(_808_ind, RAST.__default.IND)); + if (unmatched27) { + if (_source27.is_TypeApp) { + RAST._IType _814_base = _source27.dtor_baseName; + Dafny.ISequence _815_args = _source27.dtor_arguments; + unmatched27 = false; + return Dafny.Sequence.Concat((_814_base)._ToString(_pat_let_tv37), (((_815_args).Equals(Dafny.Sequence.FromElements())) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("<"), RAST.__default.SeqToString(_815_args, Dafny.Helpers.Id, Func>>>((_816_ind) => ((System.Func>)((_817_arg) => { + return (_817_arg)._ToString(Dafny.Sequence.Concat(_816_ind, RAST.__default.IND)); })))(_pat_let_tv38), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(">"))))); } } - if (unmatched26) { - if (_source26.is_SelfOwned) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_SelfOwned) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("Self"); } } - if (unmatched26) { - if (_source26.is_U8) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_U8) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("u8"); } } - if (unmatched26) { - if (_source26.is_U16) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_U16) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("u16"); } } - if (unmatched26) { - if (_source26.is_U32) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_U32) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("u32"); } } - if (unmatched26) { - if (_source26.is_U64) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_U64) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("u64"); } } - if (unmatched26) { - if (_source26.is_U128) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_U128) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("u128"); } } - if (unmatched26) { - if (_source26.is_I8) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_I8) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("i8"); } } - if (unmatched26) { - if (_source26.is_I16) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_I16) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("i16"); } } - if (unmatched26) { - if (_source26.is_I32) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_I32) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("i32"); } } - if (unmatched26) { - if (_source26.is_I64) { - unmatched26 = false; + if (unmatched27) { + if (_source27.is_I64) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("i64"); } } - if (unmatched26) { - unmatched26 = false; + if (unmatched27) { + unmatched27 = false; return Dafny.Sequence.UnicodeFromString("i128"); } throw new System.Exception("unexpected control point"); @@ -1521,6 +1725,33 @@ public RAST._IType MSel(Dafny.ISequence name) { public RAST._IType Apply1(RAST._IType arg) { return RAST.Type.create_TypeApp(this, Dafny.Sequence.FromElements(arg)); } + public RAST._IType Apply(Dafny.ISequence args) { + return RAST.Type.create_TypeApp(this, args); + } + public RAST._IType ToOwned() { + RAST._IType _source28 = this; + bool unmatched28 = true; + if (unmatched28) { + if (_source28.is_Borrowed) { + RAST._IType _818_x = _source28.dtor_underlying; + unmatched28 = false; + return _818_x; + } + } + if (unmatched28) { + if (_source28.is_BorrowedMut) { + RAST._IType _819_x = _source28.dtor_underlying; + unmatched28 = false; + return _819_x; + } + } + if (unmatched28) { + RAST._IType _820_x = _source28; + unmatched28 = false; + return _820_x; + } + throw new System.Exception("unexpected control point"); + } } public class Type_SelfOwned : Type { public Type_SelfOwned() : base() { @@ -1753,6 +1984,27 @@ public override string ToString() { return s; } } + public class Type_Bool : Type { + public Type_Bool() : base() { + } + public override _IType DowncastClone() { + if (this is _IType dt) { return dt; } + return new Type_Bool(); + } + public override bool Equals(object other) { + var oth = other as RAST.Type_Bool; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 11; + return (int) hash; + } + public override string ToString() { + string s = "RAST.Type.Bool"; + return s; + } + } public class Type_TIdentifier : Type { public readonly Dafny.ISequence _name; public Type_TIdentifier(Dafny.ISequence name) : base() { @@ -1768,7 +2020,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._name)); return (int) hash; } @@ -1797,7 +2049,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._base)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); return (int) hash; @@ -1829,7 +2081,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._baseName)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._arguments)); return (int) hash; @@ -1859,7 +2111,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._underlying)); return (int) hash; } @@ -1886,7 +2138,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._underlying)); return (int) hash; } @@ -1913,7 +2165,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._underlying)); return (int) hash; } @@ -1940,7 +2192,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._underlying)); return (int) hash; } @@ -1967,7 +2219,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._arguments)); return (int) hash; } @@ -1996,7 +2248,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._arguments)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._returnType)); return (int) hash; @@ -2028,7 +2280,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 20; + hash = ((hash << 5) + hash) + 21; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._left)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._right)); return (int) hash; @@ -2046,7 +2298,7 @@ public override string ToString() { public interface _ITrait { bool is_Trait { get; } - Dafny.ISequence dtor_typeParams { get; } + Dafny.ISequence dtor_typeParams { get; } RAST._IType dtor_tpe { get; } Dafny.ISequence dtor_where { get; } Dafny.ISequence dtor_body { get; } @@ -2054,11 +2306,11 @@ public interface _ITrait { Dafny.ISequence _ToString(Dafny.ISequence ind); } public class Trait : _ITrait { - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly RAST._IType _tpe; public readonly Dafny.ISequence _where; public readonly Dafny.ISequence _body; - public Trait(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) { + public Trait(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) { this._typeParams = typeParams; this._tpe = tpe; this._where = @where; @@ -2094,7 +2346,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITrait theDefault = create(Dafny.Sequence.Empty, RAST.Type.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly RAST._ITrait theDefault = create(Dafny.Sequence.Empty, RAST.Type.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._ITrait Default() { return theDefault; } @@ -2102,14 +2354,14 @@ public static RAST._ITrait Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITrait create(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) { + public static _ITrait create(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) { return new Trait(typeParams, tpe, @where, body); } - public static _ITrait create_Trait(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) { + public static _ITrait create_Trait(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) { return create(typeParams, tpe, @where, body); } public bool is_Trait { get { return true; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { return this._typeParams; } @@ -2130,8 +2382,8 @@ public Dafny.ISequence dtor_body { } } public Dafny.ISequence _ToString(Dafny.ISequence 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.UnicodeFromString("trait "), RAST.TypeParam.ToStringMultiple((this).dtor_typeParams, ind)), ((this).dtor_tpe)._ToString(ind)), ((!((this).dtor_where).Equals(Dafny.Sequence.UnicodeFromString(""))) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND), (this).dtor_where)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_body, Dafny.Helpers.Id, Func>>>((_810_ind) => ((System.Func>)((_811_member) => { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _810_ind), RAST.__default.IND), (_811_member)._ToString(Dafny.Sequence.Concat(_810_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.UnicodeFromString("pub trait "), RAST.TypeParamDecl.ToStringMultiple((this).dtor_typeParams, ind)), ((this).dtor_tpe)._ToString(ind)), ((!((this).dtor_where).Equals(Dafny.Sequence.UnicodeFromString(""))) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND), (this).dtor_where)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_body, Dafny.Helpers.Id, Func>>>((_821_ind) => ((System.Func>)((_822_member) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _821_ind), RAST.__default.IND), (_822_member)._ToString(Dafny.Sequence.Concat(_821_ind, RAST.__default.IND))); })))(ind), Dafny.Sequence.UnicodeFromString(""))), (((new BigInteger(((this).dtor_body).Count)).Sign == 0) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind)))), Dafny.Sequence.UnicodeFromString("}")); } } @@ -2139,7 +2391,7 @@ public Dafny.ISequence dtor_body { public interface _IImpl { bool is_ImplFor { get; } bool is_Impl { get; } - Dafny.ISequence dtor_typeParams { get; } + Dafny.ISequence dtor_typeParams { get; } RAST._IType dtor_tpe { get; } RAST._IType dtor_forType { get; } Dafny.ISequence dtor_where { get; } @@ -2150,7 +2402,7 @@ public interface _IImpl { public abstract class Impl : _IImpl { public Impl() { } - private static readonly RAST._IImpl theDefault = create_ImplFor(Dafny.Sequence.Empty, RAST.Type.Default(), RAST.Type.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly RAST._IImpl theDefault = create_ImplFor(Dafny.Sequence.Empty, RAST.Type.Default(), RAST.Type.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._IImpl Default() { return theDefault; } @@ -2158,15 +2410,15 @@ public static RAST._IImpl Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IImpl create_ImplFor(Dafny.ISequence typeParams, RAST._IType tpe, RAST._IType forType, Dafny.ISequence @where, Dafny.ISequence body) { + public static _IImpl create_ImplFor(Dafny.ISequence typeParams, RAST._IType tpe, RAST._IType forType, Dafny.ISequence @where, Dafny.ISequence body) { return new Impl_ImplFor(typeParams, tpe, forType, @where, body); } - public static _IImpl create_Impl(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) { + public static _IImpl create_Impl(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) { return new Impl_Impl(typeParams, tpe, @where, body); } public bool is_ImplFor { get { return this is Impl_ImplFor; } } public bool is_Impl { get { return this is Impl_Impl; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { var d = this; if (d is Impl_ImplFor) { return ((Impl_ImplFor)d)._typeParams; } @@ -2202,18 +2454,18 @@ public Dafny.ISequence dtor_body { } public abstract _IImpl DowncastClone(); public Dafny.ISequence _ToString(Dafny.ISequence 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("impl "), RAST.TypeParam.ToStringMultiple((this).dtor_typeParams, ind)), ((this).dtor_tpe)._ToString(ind)), (((this).is_ImplFor) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" for "), ((this).dtor_forType)._ToString(Dafny.Sequence.Concat(ind, RAST.__default.IND)))) : (Dafny.Sequence.UnicodeFromString("")))), ((!((this).dtor_where).Equals(Dafny.Sequence.UnicodeFromString(""))) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND), (this).dtor_where)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_body, Dafny.Helpers.Id, Func>>>((_812_ind) => ((System.Func>)((_813_member) => { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _812_ind), RAST.__default.IND), (_813_member)._ToString(Dafny.Sequence.Concat(_812_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.Concat(Dafny.Sequence.UnicodeFromString("impl"), RAST.TypeParamDecl.ToStringMultiple((this).dtor_typeParams, ind)), Dafny.Sequence.UnicodeFromString(" ")), ((this).dtor_tpe)._ToString(ind)), (((this).is_ImplFor) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND), Dafny.Sequence.UnicodeFromString("for ")), ((this).dtor_forType)._ToString(Dafny.Sequence.Concat(ind, RAST.__default.IND)))) : (Dafny.Sequence.UnicodeFromString("")))), ((!((this).dtor_where).Equals(Dafny.Sequence.UnicodeFromString(""))) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND), (this).dtor_where)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_body, Dafny.Helpers.Id, Func>>>((_823_ind) => ((System.Func>)((_824_member) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _823_ind), RAST.__default.IND), (_824_member)._ToString(Dafny.Sequence.Concat(_823_ind, RAST.__default.IND))); })))(ind), Dafny.Sequence.UnicodeFromString(""))), (((new BigInteger(((this).dtor_body).Count)).Sign == 0) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind)))), Dafny.Sequence.UnicodeFromString("}")); } } public class Impl_ImplFor : Impl { - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly RAST._IType _tpe; public readonly RAST._IType _forType; public readonly Dafny.ISequence _where; public readonly Dafny.ISequence _body; - public Impl_ImplFor(Dafny.ISequence typeParams, RAST._IType tpe, RAST._IType forType, Dafny.ISequence @where, Dafny.ISequence body) : base() { + public Impl_ImplFor(Dafny.ISequence typeParams, RAST._IType tpe, RAST._IType forType, Dafny.ISequence @where, Dafny.ISequence body) : base() { this._typeParams = typeParams; this._tpe = tpe; this._forType = forType; @@ -2255,11 +2507,11 @@ public override string ToString() { } } public class Impl_Impl : Impl { - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly RAST._IType _tpe; public readonly Dafny.ISequence _where; public readonly Dafny.ISequence _body; - public Impl_Impl(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) : base() { + public Impl_Impl(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence @where, Dafny.ISequence body) : base() { this._typeParams = typeParams; this._tpe = tpe; this._where = @where; @@ -2346,7 +2598,7 @@ public RAST._IFn dtor_fun { public abstract _IImplMember DowncastClone(); public Dafny.ISequence _ToString(Dafny.ISequence ind) { if ((this).is_FnDecl) { - return Dafny.Sequence.Concat(((object.Equals((this).dtor_pub, RAST.Visibility.create_PUB())) ? (Dafny.Sequence.UnicodeFromString("pub ")) : (Dafny.Sequence.UnicodeFromString(""))), ((this).dtor_fun)._ToString(ind)); + return Dafny.Sequence.Concat(((this).dtor_pub)._ToString(), ((this).dtor_fun)._ToString(ind)); } else { return (this).dtor_content; } @@ -2416,6 +2668,7 @@ public interface _IVisibility { bool is_PUB { get; } bool is_PRIV { get; } _IVisibility DowncastClone(); + Dafny.ISequence _ToString(); } public abstract class Visibility : _IVisibility { public Visibility() { @@ -2443,6 +2696,13 @@ public static System.Collections.Generic.IEnumerable<_IVisibility> AllSingletonC } } public abstract _IVisibility DowncastClone(); + public Dafny.ISequence _ToString() { + if ((this).is_PUB) { + return Dafny.Sequence.UnicodeFromString("pub "); + } else { + return Dafny.Sequence.UnicodeFromString(""); + } + } } public class Visibility_PUB : Visibility { public Visibility_PUB() : base() { @@ -2551,24 +2811,24 @@ public RAST._IType dtor_tpe { } } public Dafny.ISequence _ToString(Dafny.ISequence ind) { - if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("self"))) && (((this).dtor_tpe).is_SelfOwned)) { - return (this).dtor_name; - } else if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("&self"))) && (object.Equals((this).dtor_tpe, RAST.Type.create_Borrowed(RAST.Type.create_SelfOwned())))) { - return (this).dtor_name; - } else if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("&mut self"))) && (object.Equals((this).dtor_tpe, RAST.Type.create_Borrowed(RAST.__default.SelfMut)))) { + if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("self"))) && (object.Equals((this).dtor_tpe, RAST.Type.create_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); + } else if ((((this).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("self"))) && (object.Equals((this).dtor_tpe, RAST.__default.SelfBorrowedMut))) { + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("&mut "), (this).dtor_name); } else { return Dafny.Sequence.Concat(Dafny.Sequence.Concat((this).dtor_name, Dafny.Sequence.UnicodeFromString(": ")), ((this).dtor_tpe)._ToString(ind)); } } - public static RAST._IFormal self { get { - return RAST.Formal.create(Dafny.Sequence.UnicodeFromString("&self"), RAST.__default.Self); + 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()); } } - public static RAST._IFormal selfMut { get { - return RAST.Formal.create(Dafny.Sequence.UnicodeFromString("&mut self"), RAST.__default.SelfMut); + public static RAST._IFormal selfBorrowedMut { get { + return RAST.Formal.create(Dafny.Sequence.UnicodeFromString("self"), RAST.__default.SelfBorrowedMut); } } } @@ -2690,9 +2950,9 @@ public RAST._IExpr dtor_rhs { } } public Dafny.ISequence _ToString(Dafny.ISequence ind) { - Dafny.ISequence _814_newIndent = ((((this).dtor_rhs).is_Block) ? (ind) : (Dafny.Sequence.Concat(ind, RAST.__default.IND))); - Dafny.ISequence _815_rhsString = ((this).dtor_rhs)._ToString(_814_newIndent); - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.Pattern._ToString((this).dtor_pattern, ind), Dafny.Sequence.UnicodeFromString(" =>")), ((((_815_rhsString).Contains(new Dafny.Rune('\n'))) && (((_815_rhsString).Select(BigInteger.Zero)) != (new Dafny.Rune('{')))) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND), _815_rhsString)) : (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" "), _815_rhsString)))); + Dafny.ISequence _825_newIndent = ((((this).dtor_rhs).is_Block) ? (ind) : (Dafny.Sequence.Concat(ind, RAST.__default.IND))); + Dafny.ISequence _826_rhsString = ((this).dtor_rhs)._ToString(_825_newIndent); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.Pattern._ToString((this).dtor_pattern, ind), Dafny.Sequence.UnicodeFromString(" =>")), ((((_826_rhsString).Contains(new Dafny.Rune('\n'))) && (((_826_rhsString).Select(BigInteger.Zero)) != (new Dafny.Rune('{')))) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND), _826_rhsString)) : (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" "), _826_rhsString)))); } } @@ -3137,8 +3397,206 @@ public override string ToString() { } } - public interface _IExpr { + public interface _IAssignLhs { + bool is_LocalVar { get; } + bool is_SelectMember { get; } + bool is_ExtractTuple { get; } + bool is_Index { get; } + Dafny.ISequence dtor_name { get; } + RAST._IExpr dtor_on { get; } + Dafny.ISequence dtor_field { get; } + Dafny.ISequence> dtor_names { get; } + RAST._IExpr dtor_expr { get; } + Dafny.ISequence dtor_indices { get; } + _IAssignLhs DowncastClone(); + } + public abstract class AssignLhs : _IAssignLhs { + public AssignLhs() { + } + private static readonly RAST._IAssignLhs theDefault = create_LocalVar(Dafny.Sequence.Empty); + public static RAST._IAssignLhs Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.AssignLhs.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IAssignLhs create_LocalVar(Dafny.ISequence name) { + return new AssignLhs_LocalVar(name); + } + public static _IAssignLhs create_SelectMember(RAST._IExpr @on, Dafny.ISequence field) { + return new AssignLhs_SelectMember(@on, field); + } + public static _IAssignLhs create_ExtractTuple(Dafny.ISequence> names) { + return new AssignLhs_ExtractTuple(names); + } + public static _IAssignLhs create_Index(RAST._IExpr expr, Dafny.ISequence indices) { + return new AssignLhs_Index(expr, indices); + } + public bool is_LocalVar { get { return this is AssignLhs_LocalVar; } } + public bool is_SelectMember { get { return this is AssignLhs_SelectMember; } } + public bool is_ExtractTuple { get { return this is AssignLhs_ExtractTuple; } } + public bool is_Index { get { return this is AssignLhs_Index; } } + public Dafny.ISequence dtor_name { + get { + var d = this; + return ((AssignLhs_LocalVar)d)._name; + } + } + public RAST._IExpr dtor_on { + get { + var d = this; + return ((AssignLhs_SelectMember)d)._on; + } + } + public Dafny.ISequence dtor_field { + get { + var d = this; + return ((AssignLhs_SelectMember)d)._field; + } + } + public Dafny.ISequence> dtor_names { + get { + var d = this; + return ((AssignLhs_ExtractTuple)d)._names; + } + } + public RAST._IExpr dtor_expr { + get { + var d = this; + return ((AssignLhs_Index)d)._expr; + } + } + public Dafny.ISequence dtor_indices { + get { + var d = this; + return ((AssignLhs_Index)d)._indices; + } + } + public abstract _IAssignLhs DowncastClone(); + } + public class AssignLhs_LocalVar : AssignLhs { + public readonly Dafny.ISequence _name; + public AssignLhs_LocalVar(Dafny.ISequence name) : base() { + this._name = name; + } + public override _IAssignLhs DowncastClone() { + if (this is _IAssignLhs dt) { return dt; } + return new AssignLhs_LocalVar(_name); + } + public override bool Equals(object other) { + var oth = other as RAST.AssignLhs_LocalVar; + return oth != null && object.Equals(this._name, oth._name); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.AssignLhs.LocalVar"; + s += "("; + s += this._name.ToVerbatimString(true); + s += ")"; + return s; + } + } + public class AssignLhs_SelectMember : AssignLhs { + public readonly RAST._IExpr _on; + public readonly Dafny.ISequence _field; + public AssignLhs_SelectMember(RAST._IExpr @on, Dafny.ISequence field) : base() { + this._on = @on; + this._field = field; + } + public override _IAssignLhs DowncastClone() { + if (this is _IAssignLhs dt) { return dt; } + return new AssignLhs_SelectMember(_on, _field); + } + public override bool Equals(object other) { + var oth = other as RAST.AssignLhs_SelectMember; + return oth != null && object.Equals(this._on, oth._on) && object.Equals(this._field, oth._field); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._on)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._field)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.AssignLhs.SelectMember"; + s += "("; + s += Dafny.Helpers.ToString(this._on); + s += ", "; + s += this._field.ToVerbatimString(true); + s += ")"; + return s; + } + } + public class AssignLhs_ExtractTuple : AssignLhs { + public readonly Dafny.ISequence> _names; + public AssignLhs_ExtractTuple(Dafny.ISequence> names) : base() { + this._names = names; + } + public override _IAssignLhs DowncastClone() { + if (this is _IAssignLhs dt) { return dt; } + return new AssignLhs_ExtractTuple(_names); + } + public override bool Equals(object other) { + var oth = other as RAST.AssignLhs_ExtractTuple; + return oth != null && object.Equals(this._names, oth._names); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._names)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.AssignLhs.ExtractTuple"; + s += "("; + s += Dafny.Helpers.ToString(this._names); + s += ")"; + return s; + } + } + public class AssignLhs_Index : AssignLhs { + public readonly RAST._IExpr _expr; + public readonly Dafny.ISequence _indices; + public AssignLhs_Index(RAST._IExpr expr, Dafny.ISequence indices) : base() { + this._expr = expr; + this._indices = indices; + } + public override _IAssignLhs DowncastClone() { + if (this is _IAssignLhs dt) { return dt; } + return new AssignLhs_Index(_expr, _indices); + } + public override bool Equals(object other) { + var oth = other as RAST.AssignLhs_Index; + return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._indices, oth._indices); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._indices)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.AssignLhs.Index"; + s += "("; + s += Dafny.Helpers.ToString(this._expr); + s += ", "; + s += Dafny.Helpers.ToString(this._indices); + s += ")"; + return s; + } + } + + public interface _IExpr { bool is_RawExpr { get; } + bool is_ExprFromType { get; } bool is_Identifier { get; } bool is_Match { get; } bool is_StmtExpr { get; } @@ -3149,10 +3607,10 @@ public interface _IExpr { bool is_BinaryOp { get; } bool is_TypeAscription { get; } bool is_LiteralInt { get; } + bool is_LiteralBool { get; } bool is_LiteralString { get; } - bool is_ConversionNum { get; } bool is_DeclareVar { get; } - bool is_AssignVar { get; } + bool is_Assign { get; } bool is_IfExpr { get; } bool is_Loop { get; } bool is_For { get; } @@ -3160,10 +3618,13 @@ public interface _IExpr { bool is_Break { get; } bool is_Continue { get; } bool is_Return { get; } + bool is_CallType { get; } bool is_Call { get; } bool is_Select { get; } bool is_MemberSelect { get; } + bool is_Lambda { get; } Dafny.ISequence dtor_content { get; } + RAST._IType dtor_tpe { get; } Dafny.ISequence dtor_name { get; } RAST._IExpr dtor_matchee { get; } Dafny.ISequence dtor_cases { get; } @@ -3178,12 +3639,14 @@ public interface _IExpr { RAST._IExpr dtor_left { get; } RAST._IExpr dtor_right { get; } DAST.Format._IBinaryOpFormat dtor_format2 { get; } - RAST._IType dtor_tpe { get; } Dafny.ISequence dtor_value { get; } + bool dtor_bvalue { get; } bool dtor_binary { get; } + bool dtor_verbatim { get; } RAST._IDeclareType dtor_declareType { get; } Std.Wrappers._IOption dtor_optType { get; } Std.Wrappers._IOption dtor_optRhs { get; } + Std.Wrappers._IOption dtor_names { get; } RAST._IExpr dtor_cond { get; } RAST._IExpr dtor_thn { get; } RAST._IExpr dtor_els { get; } @@ -3195,6 +3658,8 @@ public interface _IExpr { Std.Wrappers._IOption dtor_optExpr { get; } RAST._IExpr dtor_obj { get; } Dafny.ISequence dtor_typeParameters { get; } + Dafny.ISequence dtor_params { get; } + Std.Wrappers._IOption dtor_retType { get; } _IExpr DowncastClone(); bool NoExtraSemicolonAfter(); RAST._IPrintingInfo printingInfo { get; } @@ -3208,8 +3673,12 @@ public interface _IExpr { RAST._IExpr Then(RAST._IExpr rhs2); RAST._IExpr Sel(Dafny.ISequence name); RAST._IExpr MSel(Dafny.ISequence name); - RAST._IExpr Apply(Dafny.ISequence typeParameters, Dafny.ISequence arguments); + RAST._IExpr ApplyType(Dafny.ISequence typeParameters); + RAST._IExpr ApplyType1(RAST._IType typeParameter); + RAST._IExpr Apply(Dafny.ISequence arguments); RAST._IExpr Apply1(RAST._IExpr argument); + bool IsLhsIdentifier(); + Dafny.ISequence LhsIdentifierName(); } public abstract class Expr : _IExpr { public Expr() { @@ -3225,6 +3694,9 @@ public static RAST._IExpr Default() { public static _IExpr create_RawExpr(Dafny.ISequence content) { return new Expr_RawExpr(content); } + public static _IExpr create_ExprFromType(RAST._IType tpe) { + return new Expr_ExprFromType(tpe); + } public static _IExpr create_Identifier(Dafny.ISequence name) { return new Expr_Identifier(name); } @@ -3237,8 +3709,8 @@ public static _IExpr create_StmtExpr(RAST._IExpr stmt, RAST._IExpr rhs) { public static _IExpr create_Block(RAST._IExpr underlying) { return new Expr_Block(underlying); } - public static _IExpr create_StructBuild(Dafny.ISequence name, Dafny.ISequence assignments) { - return new Expr_StructBuild(name, assignments); + public static _IExpr create_StructBuild(RAST._IExpr underlying, Dafny.ISequence assignments) { + return new Expr_StructBuild(underlying, assignments); } public static _IExpr create_Tuple(Dafny.ISequence arguments) { return new Expr_Tuple(arguments); @@ -3255,17 +3727,17 @@ public static _IExpr create_TypeAscription(RAST._IExpr left, RAST._IType tpe) { public static _IExpr create_LiteralInt(Dafny.ISequence @value) { return new Expr_LiteralInt(@value); } - public static _IExpr create_LiteralString(Dafny.ISequence @value, bool binary) { - return new Expr_LiteralString(@value, binary); + public static _IExpr create_LiteralBool(bool bvalue) { + return new Expr_LiteralBool(bvalue); } - public static _IExpr create_ConversionNum(RAST._IType tpe, RAST._IExpr underlying) { - return new Expr_ConversionNum(tpe, underlying); + public static _IExpr create_LiteralString(Dafny.ISequence @value, bool binary, bool verbatim) { + return new Expr_LiteralString(@value, binary, verbatim); } public static _IExpr create_DeclareVar(RAST._IDeclareType declareType, Dafny.ISequence name, Std.Wrappers._IOption optType, Std.Wrappers._IOption optRhs) { return new Expr_DeclareVar(declareType, name, optType, optRhs); } - public static _IExpr create_AssignVar(Dafny.ISequence name, RAST._IExpr rhs) { - return new Expr_AssignVar(name, rhs); + public static _IExpr create_Assign(Std.Wrappers._IOption names, RAST._IExpr rhs) { + return new Expr_Assign(names, rhs); } public static _IExpr create_IfExpr(RAST._IExpr cond, RAST._IExpr thn, RAST._IExpr els) { return new Expr_IfExpr(cond, thn, els); @@ -3288,8 +3760,11 @@ public static _IExpr create_Continue(Std.Wrappers._IOption optExpr) { return new Expr_Return(optExpr); } - public static _IExpr create_Call(RAST._IExpr obj, Dafny.ISequence typeParameters, Dafny.ISequence arguments) { - return new Expr_Call(obj, typeParameters, arguments); + public static _IExpr create_CallType(RAST._IExpr obj, Dafny.ISequence typeParameters) { + return new Expr_CallType(obj, typeParameters); + } + public static _IExpr create_Call(RAST._IExpr obj, Dafny.ISequence arguments) { + return new Expr_Call(obj, arguments); } public static _IExpr create_Select(RAST._IExpr obj, Dafny.ISequence name) { return new Expr_Select(obj, name); @@ -3297,7 +3772,11 @@ public static _IExpr create_Select(RAST._IExpr obj, Dafny.ISequence public static _IExpr create_MemberSelect(RAST._IExpr obj, Dafny.ISequence name) { return new Expr_MemberSelect(obj, name); } + public static _IExpr create_Lambda(Dafny.ISequence @params, Std.Wrappers._IOption retType, RAST._IExpr body) { + return new Expr_Lambda(@params, retType, body); + } public bool is_RawExpr { get { return this is Expr_RawExpr; } } + public bool is_ExprFromType { get { return this is Expr_ExprFromType; } } public bool is_Identifier { get { return this is Expr_Identifier; } } public bool is_Match { get { return this is Expr_Match; } } public bool is_StmtExpr { get { return this is Expr_StmtExpr; } } @@ -3308,10 +3787,10 @@ public static _IExpr create_MemberSelect(RAST._IExpr obj, Dafny.ISequence dtor_content { get { var d = this; return ((Expr_RawExpr)d)._content; } } + public RAST._IType dtor_tpe { + get { + var d = this; + if (d is Expr_ExprFromType) { return ((Expr_ExprFromType)d)._tpe; } + return ((Expr_TypeAscription)d)._tpe; + } + } public Dafny.ISequence dtor_name { get { var d = this; if (d is Expr_Identifier) { return ((Expr_Identifier)d)._name; } - if (d is Expr_StructBuild) { return ((Expr_StructBuild)d)._name; } if (d is Expr_DeclareVar) { return ((Expr_DeclareVar)d)._name; } - if (d is Expr_AssignVar) { return ((Expr_AssignVar)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; @@ -3362,15 +3848,15 @@ public RAST._IExpr dtor_rhs { get { var d = this; if (d is Expr_StmtExpr) { return ((Expr_StmtExpr)d)._rhs; } - return ((Expr_AssignVar)d)._rhs; + return ((Expr_Assign)d)._rhs; } } public RAST._IExpr dtor_underlying { get { var d = this; if (d is Expr_Block) { return ((Expr_Block)d)._underlying; } + if (d is Expr_StructBuild) { return ((Expr_StructBuild)d)._underlying; } if (d is Expr_UnaryOp) { return ((Expr_UnaryOp)d)._underlying; } - if (d is Expr_ConversionNum) { return ((Expr_ConversionNum)d)._underlying; } if (d is Expr_Loop) { return ((Expr_Loop)d)._underlying; } return ((Expr_Labelled)d)._underlying; } @@ -3425,18 +3911,17 @@ public DAST.Format._IBinaryOpFormat dtor_format2 { return ((Expr_BinaryOp)d)._format2; } } - public RAST._IType dtor_tpe { + public Dafny.ISequence dtor_value { get { var d = this; - if (d is Expr_TypeAscription) { return ((Expr_TypeAscription)d)._tpe; } - return ((Expr_ConversionNum)d)._tpe; + if (d is Expr_LiteralInt) { return ((Expr_LiteralInt)d)._value; } + return ((Expr_LiteralString)d)._value; } } - public Dafny.ISequence dtor_value { + public bool dtor_bvalue { get { var d = this; - if (d is Expr_LiteralInt) { return ((Expr_LiteralInt)d)._value; } - return ((Expr_LiteralString)d)._value; + return ((Expr_LiteralBool)d)._bvalue; } } public bool dtor_binary { @@ -3445,6 +3930,12 @@ public bool dtor_binary { return ((Expr_LiteralString)d)._binary; } } + public bool dtor_verbatim { + get { + var d = this; + return ((Expr_LiteralString)d)._verbatim; + } + } public RAST._IDeclareType dtor_declareType { get { var d = this; @@ -3463,6 +3954,12 @@ public Std.Wrappers._IOption dtor_optRhs { return ((Expr_DeclareVar)d)._optRhs; } } + public Std.Wrappers._IOption dtor_names { + get { + var d = this; + return ((Expr_Assign)d)._names; + } + } public RAST._IExpr dtor_cond { get { var d = this; @@ -3496,7 +3993,8 @@ public RAST._IExpr dtor_range { public RAST._IExpr dtor_body { get { var d = this; - return ((Expr_For)d)._body; + if (d is Expr_For) { return ((Expr_For)d)._body; } + return ((Expr_Lambda)d)._body; } } public Dafny.ISequence dtor_lbl { @@ -3521,6 +4019,7 @@ public Std.Wrappers._IOption dtor_optExpr { public RAST._IExpr dtor_obj { get { var d = this; + if (d is Expr_CallType) { return ((Expr_CallType)d)._obj; } if (d is Expr_Call) { return ((Expr_Call)d)._obj; } if (d is Expr_Select) { return ((Expr_Select)d)._obj; } return ((Expr_MemberSelect)d)._obj; @@ -3529,33 +4028,44 @@ public RAST._IExpr dtor_obj { public Dafny.ISequence dtor_typeParameters { get { var d = this; - return ((Expr_Call)d)._typeParameters; + return ((Expr_CallType)d)._typeParameters; + } + } + public Dafny.ISequence dtor_params { + get { + var d = this; + return ((Expr_Lambda)d)._params; + } + } + public Std.Wrappers._IOption dtor_retType { + get { + var d = this; + return ((Expr_Lambda)d)._retType; } } public abstract _IExpr DowncastClone(); public bool NoExtraSemicolonAfter() { - return ((((((this).is_DeclareVar) || ((this).is_AssignVar)) || ((this).is_Break)) || ((this).is_Continue)) || ((this).is_Return)) || ((((this).is_RawExpr) && ((new BigInteger(((this).dtor_content).Count)).Sign == 1)) && ((((this).dtor_content).Select((new BigInteger(((this).dtor_content).Count)) - (BigInteger.One))) == (new Dafny.Rune(';')))); + return (((((((this).is_DeclareVar) || ((this).is_Assign)) || ((this).is_Break)) || ((this).is_Continue)) || ((this).is_Return)) || ((this).is_For)) || ((((this).is_RawExpr) && ((new BigInteger(((this).dtor_content).Count)).Sign == 1)) && ((((this).dtor_content).Select((new BigInteger(((this).dtor_content).Count)) - (BigInteger.One))) == (new Dafny.Rune(';')))); } public RAST._IExpr Optimize() { - RAST._IExpr _source27 = this; - bool unmatched27 = true; - if (unmatched27) { - if (_source27.is_UnaryOp) { - Dafny.ISequence op10 = _source27.dtor_op1; + RAST._IExpr _source29 = this; + bool unmatched29 = true; + if (unmatched29) { + if (_source29.is_UnaryOp) { + Dafny.ISequence op10 = _source29.dtor_op1; if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { - RAST._IExpr underlying0 = _source27.dtor_underlying; + RAST._IExpr underlying0 = _source29.dtor_underlying; if (underlying0.is_Call) { RAST._IExpr obj0 = underlying0.dtor_obj; if (obj0.is_Select) { - RAST._IExpr _816_underlying = obj0.dtor_obj; - Dafny.ISequence name0 = obj0.dtor_name; - if (object.Equals(name0, Dafny.Sequence.UnicodeFromString("clone"))) { - Dafny.ISequence _817_typeArgs = underlying0.dtor_typeParameters; - Dafny.ISequence _818_args = underlying0.dtor_arguments; - DAST.Format._IUnaryOpFormat _819_format = _source27.dtor_format; - unmatched27 = false; - if (((_817_typeArgs).Equals(Dafny.Sequence.FromElements())) && ((_818_args).Equals(Dafny.Sequence.FromElements()))) { - return RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _816_underlying, _819_format); + RAST._IExpr _827_underlying = obj0.dtor_obj; + Dafny.ISequence name4 = obj0.dtor_name; + if (object.Equals(name4, Dafny.Sequence.UnicodeFromString("clone"))) { + Dafny.ISequence _828_args = underlying0.dtor_arguments; + DAST.Format._IUnaryOpFormat _829_format = _source29.dtor_format; + unmatched29 = false; + if ((_828_args).Equals(Dafny.Sequence.FromElements())) { + return RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&"), _827_underlying, _829_format); } else { return this; } @@ -3565,43 +4075,43 @@ public RAST._IExpr Optimize() { } } } - if (unmatched27) { - if (_source27.is_UnaryOp) { - Dafny.ISequence op11 = _source27.dtor_op1; + if (unmatched29) { + if (_source29.is_UnaryOp) { + Dafny.ISequence op11 = _source29.dtor_op1; if (object.Equals(op11, Dafny.Sequence.UnicodeFromString("!"))) { - RAST._IExpr underlying1 = _source27.dtor_underlying; + RAST._IExpr underlying1 = _source29.dtor_underlying; if (underlying1.is_BinaryOp) { Dafny.ISequence op20 = underlying1.dtor_op2; if (object.Equals(op20, Dafny.Sequence.UnicodeFromString("=="))) { - RAST._IExpr _820_left = underlying1.dtor_left; - RAST._IExpr _821_right = underlying1.dtor_right; - DAST.Format._IBinaryOpFormat _822_format = underlying1.dtor_format2; - DAST.Format._IUnaryOpFormat format0 = _source27.dtor_format; + RAST._IExpr _830_left = underlying1.dtor_left; + RAST._IExpr _831_right = underlying1.dtor_right; + DAST.Format._IBinaryOpFormat _832_format = underlying1.dtor_format2; + DAST.Format._IUnaryOpFormat format0 = _source29.dtor_format; if (format0.is_CombineFormat) { - unmatched27 = false; - return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _820_left, _821_right, DAST.Format.BinaryOpFormat.create_NoFormat()); + unmatched29 = false; + return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("!="), _830_left, _831_right, DAST.Format.BinaryOpFormat.create_NoFormat()); } } } } } } - if (unmatched27) { - if (_source27.is_UnaryOp) { - Dafny.ISequence op12 = _source27.dtor_op1; + if (unmatched29) { + if (_source29.is_UnaryOp) { + Dafny.ISequence op12 = _source29.dtor_op1; if (object.Equals(op12, Dafny.Sequence.UnicodeFromString("!"))) { - RAST._IExpr underlying2 = _source27.dtor_underlying; + RAST._IExpr underlying2 = _source29.dtor_underlying; if (underlying2.is_BinaryOp) { Dafny.ISequence op21 = underlying2.dtor_op2; if (object.Equals(op21, Dafny.Sequence.UnicodeFromString("<"))) { - RAST._IExpr _823_left = underlying2.dtor_left; - RAST._IExpr _824_right = underlying2.dtor_right; + RAST._IExpr _833_left = underlying2.dtor_left; + RAST._IExpr _834_right = underlying2.dtor_right; DAST.Format._IBinaryOpFormat format20 = underlying2.dtor_format2; if (format20.is_NoFormat) { - DAST.Format._IUnaryOpFormat format1 = _source27.dtor_format; + DAST.Format._IUnaryOpFormat format1 = _source29.dtor_format; if (format1.is_CombineFormat) { - unmatched27 = false; - return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _823_left, _824_right, DAST.Format.BinaryOpFormat.create_NoFormat()); + unmatched29 = false; + return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString(">="), _833_left, _834_right, DAST.Format.BinaryOpFormat.create_NoFormat()); } } } @@ -3609,22 +4119,22 @@ public RAST._IExpr Optimize() { } } } - if (unmatched27) { - if (_source27.is_UnaryOp) { - Dafny.ISequence op13 = _source27.dtor_op1; + if (unmatched29) { + if (_source29.is_UnaryOp) { + Dafny.ISequence op13 = _source29.dtor_op1; if (object.Equals(op13, Dafny.Sequence.UnicodeFromString("!"))) { - RAST._IExpr underlying3 = _source27.dtor_underlying; + RAST._IExpr underlying3 = _source29.dtor_underlying; if (underlying3.is_BinaryOp) { Dafny.ISequence op22 = underlying3.dtor_op2; if (object.Equals(op22, Dafny.Sequence.UnicodeFromString("<"))) { - RAST._IExpr _825_left = underlying3.dtor_left; - RAST._IExpr _826_right = underlying3.dtor_right; + RAST._IExpr _835_left = underlying3.dtor_left; + RAST._IExpr _836_right = underlying3.dtor_right; DAST.Format._IBinaryOpFormat format21 = underlying3.dtor_format2; if (format21.is_ReverseFormat) { - DAST.Format._IUnaryOpFormat format2 = _source27.dtor_format; + DAST.Format._IUnaryOpFormat format2 = _source29.dtor_format; if (format2.is_CombineFormat) { - unmatched27 = false; - return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _826_right, _825_left, DAST.Format.BinaryOpFormat.create_NoFormat()); + unmatched29 = false; + return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("<="), _836_right, _835_left, DAST.Format.BinaryOpFormat.create_NoFormat()); } } } @@ -3632,105 +4142,105 @@ public RAST._IExpr Optimize() { } } } - if (unmatched27) { - if (_source27.is_ConversionNum) { - RAST._IType _827_tpe = _source27.dtor_tpe; - RAST._IExpr _828_expr = _source27.dtor_underlying; - unmatched27 = false; - if (((((((((((_827_tpe).is_U8) || ((_827_tpe).is_U16)) || ((_827_tpe).is_U32)) || ((_827_tpe).is_U64)) || ((_827_tpe).is_U128)) || ((_827_tpe).is_I8)) || ((_827_tpe).is_I16)) || ((_827_tpe).is_I32)) || ((_827_tpe).is_I64)) || ((_827_tpe).is_I128)) { - RAST._IExpr _source28 = _828_expr; - bool unmatched28 = true; - if (unmatched28) { - if (_source28.is_Call) { - RAST._IExpr obj1 = _source28.dtor_obj; - if (obj1.is_MemberSelect) { - RAST._IExpr obj2 = obj1.dtor_obj; - if (obj2.is_MemberSelect) { - RAST._IExpr obj3 = obj2.dtor_obj; - if (obj3.is_MemberSelect) { - RAST._IExpr obj4 = obj3.dtor_obj; - if (obj4.is_Identifier) { - Dafny.ISequence name1 = obj4.dtor_name; - if (object.Equals(name1, Dafny.Sequence.UnicodeFromString(""))) { - Dafny.ISequence name2 = obj3.dtor_name; - if (object.Equals(name2, Dafny.Sequence.UnicodeFromString("dafny_runtime"))) { - Dafny.ISequence name3 = obj2.dtor_name; - if (object.Equals(name3, Dafny.Sequence.UnicodeFromString("DafnyInt"))) { - Dafny.ISequence name4 = obj1.dtor_name; - if (object.Equals(name4, Dafny.Sequence.UnicodeFromString("from"))) { - Dafny.ISequence _829_tpe = _source28.dtor_typeParameters; - Dafny.ISequence _830_args = _source28.dtor_arguments; - unmatched28 = false; - if (((new BigInteger((_829_tpe).Count)).Sign == 0) && ((new BigInteger((_830_args).Count)) == (BigInteger.One))) { - RAST._IExpr _source29 = (_830_args).Select(BigInteger.Zero); - bool unmatched29 = true; - if (unmatched29) { - if (_source29.is_LiteralInt) { - Dafny.ISequence _831_number = _source29.dtor_value; - unmatched29 = false; - return RAST.Expr.create_LiteralInt(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("/*optimized*/"), _831_number)); - } - } - if (unmatched29) { - if (_source29.is_LiteralString) { - Dafny.ISequence _832_number = _source29.dtor_value; - bool _833___v22 = _source29.dtor_binary; - unmatched29 = false; - return RAST.Expr.create_LiteralInt(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("/*optimized*/"), _832_number)); - } - } - if (unmatched29) { - RAST._IExpr _834___v23 = _source29; - unmatched29 = false; - return this; - } - throw new System.Exception("unexpected control point"); - } else { - return this; + if (unmatched29) { + if (_source29.is_Call) { + RAST._IExpr obj1 = _source29.dtor_obj; + if (obj1.is_MemberSelect) { + RAST._IExpr _837_r = obj1.dtor_obj; + Dafny.ISequence name5 = obj1.dtor_name; + if (object.Equals(name5, Dafny.Sequence.UnicodeFromString("truncate!"))) { + Dafny.ISequence _838_args = _source29.dtor_arguments; + unmatched29 = false; + if (((!object.Equals(_837_r, RAST.__default.dafny__runtime)) && (!object.Equals(_837_r, RAST.__default.@global))) || ((new BigInteger((_838_args).Count)) != (new BigInteger(2)))) { + return this; + } else { + RAST._IExpr _839_expr = (_838_args).Select(BigInteger.Zero); + RAST._IExpr _840_tpeExpr = (_838_args).Select(BigInteger.One); + if (!((_840_tpeExpr).is_ExprFromType)) { + return this; + } else { + RAST._IType _841_tpe = (_840_tpeExpr).dtor_tpe; + if (((((((((((_841_tpe).is_U8) || ((_841_tpe).is_U16)) || ((_841_tpe).is_U32)) || ((_841_tpe).is_U64)) || ((_841_tpe).is_U128)) || ((_841_tpe).is_I8)) || ((_841_tpe).is_I16)) || ((_841_tpe).is_I32)) || ((_841_tpe).is_I64)) || ((_841_tpe).is_I128)) { + RAST._IExpr _source30 = _839_expr; + bool unmatched30 = true; + if (unmatched30) { + if (_source30.is_Call) { + RAST._IExpr obj2 = _source30.dtor_obj; + if (obj2.is_MemberSelect) { + RAST._IExpr _842_base = obj2.dtor_obj; + Dafny.ISequence name6 = obj2.dtor_name; + if (object.Equals(name6, Dafny.Sequence.UnicodeFromString("int!"))) { + Dafny.ISequence _843_args = _source30.dtor_arguments; + unmatched30 = false; + if (((new BigInteger((_843_args).Count)) == (BigInteger.One)) && ((object.Equals(_842_base, RAST.__default.dafny__runtime)) || (object.Equals(_842_base, RAST.__default.@global)))) { + RAST._IExpr _source31 = (_843_args).Select(BigInteger.Zero); + bool unmatched31 = true; + if (unmatched31) { + if (_source31.is_LiteralInt) { + Dafny.ISequence _844_number = _source31.dtor_value; + unmatched31 = false; + return RAST.Expr.create_LiteralInt(_844_number); + } + } + if (unmatched31) { + if (_source31.is_LiteralString) { + Dafny.ISequence _845_number = _source31.dtor_value; + bool _846___v33 = _source31.dtor_binary; + bool _847___v34 = _source31.dtor_verbatim; + unmatched31 = false; + return RAST.Expr.create_LiteralInt(_845_number); } } + if (unmatched31) { + RAST._IExpr _848___v35 = _source31; + unmatched31 = false; + return this; + } + throw new System.Exception("unexpected control point"); + } else { + return this; } } } } } + if (unmatched30) { + RAST._IExpr _849___v36 = _source30; + unmatched30 = false; + return this; + } + throw new System.Exception("unexpected control point"); + } else { + return this; } } } } - if (unmatched28) { - RAST._IExpr _835___v24 = _source28; - unmatched28 = false; - return this; - } - throw new System.Exception("unexpected control point"); - } else { - return this; } } } - if (unmatched27) { - if (_source27.is_StmtExpr) { - RAST._IExpr stmt0 = _source27.dtor_stmt; + if (unmatched29) { + if (_source29.is_StmtExpr) { + RAST._IExpr stmt0 = _source29.dtor_stmt; if (stmt0.is_DeclareVar) { - RAST._IDeclareType _836_mod = stmt0.dtor_declareType; - Dafny.ISequence _837_name = stmt0.dtor_name; + RAST._IDeclareType _850_mod = stmt0.dtor_declareType; + Dafny.ISequence _851_name = stmt0.dtor_name; Std.Wrappers._IOption optType0 = stmt0.dtor_optType; if (optType0.is_Some) { - RAST._IType _838_tpe = optType0.dtor_value; + RAST._IType _852_tpe = optType0.dtor_value; Std.Wrappers._IOption optRhs0 = stmt0.dtor_optRhs; if (optRhs0.is_None) { - RAST._IExpr rhs0 = _source27.dtor_rhs; + RAST._IExpr rhs0 = _source29.dtor_rhs; if (rhs0.is_StmtExpr) { RAST._IExpr stmt1 = rhs0.dtor_stmt; - if (stmt1.is_AssignVar) { - Dafny.ISequence _839_name2 = stmt1.dtor_name; - RAST._IExpr _840_rhs = stmt1.dtor_rhs; - RAST._IExpr _841_last = rhs0.dtor_rhs; - unmatched27 = false; - if ((_837_name).Equals(_839_name2)) { - RAST._IExpr _842_rewriting = RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(_836_mod, _837_name, Std.Wrappers.Option.create_Some(_838_tpe), Std.Wrappers.Option.create_Some(_840_rhs)), _841_last); - return _842_rewriting; + if (stmt1.is_Assign) { + Std.Wrappers._IOption _853_name2 = stmt1.dtor_names; + RAST._IExpr _854_rhs = stmt1.dtor_rhs; + RAST._IExpr _855_last = rhs0.dtor_rhs; + unmatched29 = false; + if (object.Equals(_853_name2, Std.Wrappers.Option.create_Some(RAST.AssignLhs.create_LocalVar(_851_name)))) { + RAST._IExpr _856_rewriting = RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(_850_mod, _851_name, Std.Wrappers.Option.create_Some(_852_tpe), Std.Wrappers.Option.create_Some(_854_rhs)), _855_last); + return _856_rewriting; } else { return this; } @@ -3741,9 +4251,48 @@ public RAST._IExpr Optimize() { } } } - if (unmatched27) { - RAST._IExpr _843___v25 = _source27; - unmatched27 = false; + if (unmatched29) { + if (_source29.is_StmtExpr) { + RAST._IExpr stmt2 = _source29.dtor_stmt; + if (stmt2.is_IfExpr) { + RAST._IExpr cond0 = stmt2.dtor_cond; + if (cond0.is_UnaryOp) { + Dafny.ISequence op14 = cond0.dtor_op1; + if (object.Equals(op14, Dafny.Sequence.UnicodeFromString("!"))) { + RAST._IExpr underlying4 = cond0.dtor_underlying; + if (underlying4.is_BinaryOp) { + Dafny.ISequence op23 = underlying4.dtor_op2; + if (object.Equals(op23, Dafny.Sequence.UnicodeFromString("=="))) { + RAST._IExpr _857_a = underlying4.dtor_left; + RAST._IExpr _858_b = underlying4.dtor_right; + DAST.Format._IBinaryOpFormat _859_f = underlying4.dtor_format2; + DAST.Format._IUnaryOpFormat _860_of = cond0.dtor_format; + RAST._IExpr thn0 = stmt2.dtor_thn; + if (thn0.is_RawExpr) { + Dafny.ISequence content0 = thn0.dtor_content; + if (object.Equals(content0, Dafny.Sequence.UnicodeFromString("panic!(\"Halt\");"))) { + RAST._IExpr els0 = stmt2.dtor_els; + if (els0.is_RawExpr) { + Dafny.ISequence content1 = els0.dtor_content; + if (object.Equals(content1, Dafny.Sequence.UnicodeFromString(""))) { + RAST._IExpr _861_last = _source29.dtor_rhs; + unmatched29 = false; + RAST._IExpr _862_rewriting = RAST.Expr.create_StmtExpr((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("assert_eq!"))).Apply(Dafny.Sequence.FromElements(_857_a, _858_b)), _861_last); + return _862_rewriting; + } + } + } + } + } + } + } + } + } + } + } + if (unmatched29) { + RAST._IExpr _863___v37 = _source29; + unmatched29 = false; return this; } throw new System.Exception("unexpected control point"); @@ -3769,23 +4318,67 @@ public bool RightRequiresParentheses(RAST._IExpr right) { } } public Std.Wrappers._IOption> RightMostIdentifier() { - RAST._IExpr _source30 = this; - bool unmatched30 = true; - if (unmatched30) { - if (_source30.is_MemberSelect) { - RAST._IExpr _844___v26 = _source30.dtor_obj; - Dafny.ISequence _845_id = _source30.dtor_name; - unmatched30 = false; - return Std.Wrappers.Option>.create_Some(_845_id); + RAST._IExpr _source32 = this; + bool unmatched32 = true; + if (unmatched32) { + if (_source32.is_MemberSelect) { + RAST._IExpr _864___v38 = _source32.dtor_obj; + Dafny.ISequence _865_id = _source32.dtor_name; + unmatched32 = false; + return Std.Wrappers.Option>.create_Some(_865_id); } } - if (unmatched30) { - RAST._IExpr _846___v27 = _source30; - unmatched30 = false; + if (unmatched32) { + RAST._IExpr _866___v39 = _source32; + unmatched32 = false; return Std.Wrappers.Option>.create_None(); } throw new System.Exception("unexpected control point"); } + public static Dafny.ISequence MaxHashes(Dafny.ISequence s, Dafny.ISequence currentHashes, Dafny.ISequence mostHashes) + { + TAIL_CALL_START: ; + if ((new BigInteger((s).Count)).Sign == 0) { + if ((new BigInteger((currentHashes).Count)) < (new BigInteger((mostHashes).Count))) { + return mostHashes; + } else { + return currentHashes; + } + } else if (((s).Subsequence(BigInteger.Zero, BigInteger.One)).Equals(Dafny.Sequence.UnicodeFromString("#"))) { + Dafny.ISequence _in113 = (s).Drop(BigInteger.One); + Dafny.ISequence _in114 = Dafny.Sequence.Concat(currentHashes, Dafny.Sequence.UnicodeFromString("#")); + Dafny.ISequence _in115 = mostHashes; + s = _in113; + currentHashes = _in114; + mostHashes = _in115; + goto TAIL_CALL_START; + } else { + Dafny.ISequence _in116 = (s).Drop(BigInteger.One); + Dafny.ISequence _in117 = Dafny.Sequence.UnicodeFromString(""); + Dafny.ISequence _in118 = (((new BigInteger((currentHashes).Count)) < (new BigInteger((mostHashes).Count))) ? (mostHashes) : (currentHashes)); + s = _in116; + currentHashes = _in117; + mostHashes = _in118; + goto TAIL_CALL_START; + } + } + public static Dafny.ISequence RemoveDoubleQuotes(Dafny.ISequence s) { + Dafny.ISequence _867___accumulator = Dafny.Sequence.FromElements(); + TAIL_CALL_START: ; + if ((new BigInteger((s).Count)) <= (BigInteger.One)) { + return Dafny.Sequence.Concat(_867___accumulator, s); + } else if (((s).Subsequence(BigInteger.Zero, new BigInteger(2))).Equals(Dafny.Sequence.UnicodeFromString(@""""""))) { + _867___accumulator = Dafny.Sequence.Concat(_867___accumulator, Dafny.Sequence.UnicodeFromString(@"""")); + Dafny.ISequence _in119 = (s).Drop(new BigInteger(2)); + s = _in119; + goto TAIL_CALL_START; + } else { + _867___accumulator = Dafny.Sequence.Concat(_867___accumulator, (s).Subsequence(BigInteger.Zero, BigInteger.One)); + Dafny.ISequence _in120 = (s).Drop(BigInteger.One); + s = _in120; + goto TAIL_CALL_START; + } + } public Dafny.ISequence _ToString(Dafny.ISequence ind) { var _pat_let_tv39 = ind; var _pat_let_tv40 = ind; @@ -3835,346 +4428,458 @@ public bool RightRequiresParentheses(RAST._IExpr right) { var _pat_let_tv84 = ind; var _pat_let_tv85 = ind; var _pat_let_tv86 = ind; - RAST._IExpr _source31 = (this).Optimize(); - bool unmatched31 = true; - if (unmatched31) { - if (_source31.is_Identifier) { - Dafny.ISequence _847_name = _source31.dtor_name; - unmatched31 = false; - return _847_name; + var _pat_let_tv87 = ind; + var _pat_let_tv88 = ind; + var _pat_let_tv89 = ind; + var _pat_let_tv90 = ind; + var _pat_let_tv91 = ind; + var _pat_let_tv92 = ind; + var _pat_let_tv93 = ind; + var _pat_let_tv94 = ind; + var _pat_let_tv95 = ind; + var _pat_let_tv96 = ind; + RAST._IExpr _source33 = (this).Optimize(); + bool unmatched33 = true; + if (unmatched33) { + if (_source33.is_Identifier) { + Dafny.ISequence _868_name = _source33.dtor_name; + unmatched33 = false; + return _868_name; } } - if (unmatched31) { - if (_source31.is_LiteralInt) { - Dafny.ISequence _848_number = _source31.dtor_value; - unmatched31 = false; - return _848_number; + if (unmatched33) { + if (_source33.is_ExprFromType) { + RAST._IType _869_t = _source33.dtor_tpe; + unmatched33 = false; + return (_869_t)._ToString(_pat_let_tv39); } } - if (unmatched31) { - if (_source31.is_LiteralString) { - Dafny.ISequence _849_characters = _source31.dtor_value; - bool _850_binary = _source31.dtor_binary; - unmatched31 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(((_850_binary) ? (Dafny.Sequence.UnicodeFromString("b")) : (Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\"")), _849_characters), Dafny.Sequence.UnicodeFromString("\"")); + if (unmatched33) { + if (_source33.is_LiteralInt) { + Dafny.ISequence _870_number = _source33.dtor_value; + unmatched33 = false; + return _870_number; } } - if (unmatched31) { - if (_source31.is_ConversionNum) { - RAST._IType _851_tpe = _source31.dtor_tpe; - RAST._IExpr _852_expr = _source31.dtor_underlying; - unmatched31 = false; - if (((((((((((_851_tpe).is_U8) || ((_851_tpe).is_U16)) || ((_851_tpe).is_U32)) || ((_851_tpe).is_U64)) || ((_851_tpe).is_U128)) || ((_851_tpe).is_I8)) || ((_851_tpe).is_I16)) || ((_851_tpe).is_I32)) || ((_851_tpe).is_I64)) || ((_851_tpe).is_I128)) { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("num::ToPrimitive::to_"), (_851_tpe)._ToString(_pat_let_tv39)), Dafny.Sequence.UnicodeFromString("(")), (_852_expr)._ToString(_pat_let_tv40)), Dafny.Sequence.UnicodeFromString(").unwrap()")); + if (unmatched33) { + if (_source33.is_LiteralBool) { + bool _871_b = _source33.dtor_bvalue; + unmatched33 = false; + if (_871_b) { + return Dafny.Sequence.UnicodeFromString("true"); } else { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Unsupported: Numeric conversion to "), (_851_tpe)._ToString(_pat_let_tv41)), Dafny.Sequence.UnicodeFromString("")); + return Dafny.Sequence.UnicodeFromString("false"); } } } - if (unmatched31) { - if (_source31.is_Match) { - RAST._IExpr _853_matchee = _source31.dtor_matchee; - Dafny.ISequence _854_cases = _source31.dtor_cases; - unmatched31 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("match "), (_853_matchee)._ToString(Dafny.Sequence.Concat(_pat_let_tv42, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString(_854_cases, Dafny.Helpers.Id, Func>>>((_855_ind) => ((System.Func>)((_856_c) => { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _855_ind), RAST.__default.IND), (_856_c)._ToString(Dafny.Sequence.Concat(_855_ind, RAST.__default.IND))); - })))(_pat_let_tv43), Dafny.Sequence.UnicodeFromString(","))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv44), Dafny.Sequence.UnicodeFromString("}")); + if (unmatched33) { + if (_source33.is_LiteralString) { + Dafny.ISequence _872_characters = _source33.dtor_value; + bool _873_binary = _source33.dtor_binary; + bool _874_verbatim = _source33.dtor_verbatim; + unmatched33 = false; + Dafny.ISequence _875_hashes = ((_874_verbatim) ? (Dafny.Sequence.Concat(RAST.Expr.MaxHashes(_872_characters, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString("#"))) : (Dafny.Sequence.UnicodeFromString(""))); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(((_873_binary) ? (Dafny.Sequence.UnicodeFromString("b")) : (Dafny.Sequence.UnicodeFromString(""))), ((_874_verbatim) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("r"), _875_hashes)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString("\"")), ((_874_verbatim) ? (RAST.Expr.RemoveDoubleQuotes(_872_characters)) : (_872_characters))), Dafny.Sequence.UnicodeFromString("\"")), _875_hashes); + } + } + if (unmatched33) { + if (_source33.is_Match) { + RAST._IExpr _876_matchee = _source33.dtor_matchee; + Dafny.ISequence _877_cases = _source33.dtor_cases; + unmatched33 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("match "), (_876_matchee)._ToString(Dafny.Sequence.Concat(_pat_let_tv40, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString(_877_cases, Dafny.Helpers.Id, Func>>>((_878_ind) => ((System.Func>)((_879_c) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _878_ind), RAST.__default.IND), (_879_c)._ToString(Dafny.Sequence.Concat(_878_ind, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString(",")); + })))(_pat_let_tv41), Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv42), Dafny.Sequence.UnicodeFromString("}")); } } - if (unmatched31) { - if (_source31.is_StmtExpr) { - RAST._IExpr _857_stmt = _source31.dtor_stmt; - RAST._IExpr _858_rhs = _source31.dtor_rhs; - unmatched31 = false; - if (((_857_stmt).is_RawExpr) && (((_857_stmt).dtor_content).Equals(Dafny.Sequence.UnicodeFromString("")))) { - return (_858_rhs)._ToString(_pat_let_tv45); + if (unmatched33) { + if (_source33.is_StmtExpr) { + RAST._IExpr _880_stmt = _source33.dtor_stmt; + RAST._IExpr _881_rhs = _source33.dtor_rhs; + unmatched33 = false; + if (((_880_stmt).is_RawExpr) && (((_880_stmt).dtor_content).Equals(Dafny.Sequence.UnicodeFromString("")))) { + return (_881_rhs)._ToString(_pat_let_tv43); } else { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_857_stmt)._ToString(_pat_let_tv46), (((_857_stmt).NoExtraSemicolonAfter()) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.UnicodeFromString(";")))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv47), (_858_rhs)._ToString(_pat_let_tv48)); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_880_stmt)._ToString(_pat_let_tv44), (((_880_stmt).NoExtraSemicolonAfter()) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.UnicodeFromString(";")))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv45), (_881_rhs)._ToString(_pat_let_tv46)); } } } - if (unmatched31) { - if (_source31.is_Block) { - RAST._IExpr _859_underlying = _source31.dtor_underlying; - unmatched31 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("{\n"), _pat_let_tv49), RAST.__default.IND), (_859_underlying)._ToString(Dafny.Sequence.Concat(_pat_let_tv50, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv51), Dafny.Sequence.UnicodeFromString("}")); + if (unmatched33) { + if (_source33.is_Block) { + RAST._IExpr _882_underlying = _source33.dtor_underlying; + unmatched33 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("{\n"), _pat_let_tv47), RAST.__default.IND), (_882_underlying)._ToString(Dafny.Sequence.Concat(_pat_let_tv48, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv49), Dafny.Sequence.UnicodeFromString("}")); } } - if (unmatched31) { - if (_source31.is_IfExpr) { - RAST._IExpr _860_cond = _source31.dtor_cond; - RAST._IExpr _861_thn = _source31.dtor_thn; - RAST._IExpr _862_els = _source31.dtor_els; - unmatched31 = false; - 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.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("if "), (_860_cond)._ToString(Dafny.Sequence.Concat(_pat_let_tv52, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString(" {\n")), _pat_let_tv53), RAST.__default.IND), (_861_thn)._ToString(Dafny.Sequence.Concat(_pat_let_tv54, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv55), Dafny.Sequence.UnicodeFromString("} else {\n")), _pat_let_tv56), RAST.__default.IND), (_862_els)._ToString(Dafny.Sequence.Concat(_pat_let_tv57, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv58), Dafny.Sequence.UnicodeFromString("}")); + if (unmatched33) { + if (_source33.is_IfExpr) { + RAST._IExpr _883_cond = _source33.dtor_cond; + RAST._IExpr _884_thn = _source33.dtor_thn; + RAST._IExpr _885_els = _source33.dtor_els; + unmatched33 = false; + 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("if "), (_883_cond)._ToString(Dafny.Sequence.Concat(_pat_let_tv50, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString(" {\n")), _pat_let_tv51), RAST.__default.IND), (_884_thn)._ToString(Dafny.Sequence.Concat(_pat_let_tv52, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv53), Dafny.Sequence.UnicodeFromString("}")), ((object.Equals(_885_els, RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")))) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" else {\n"), _pat_let_tv54), RAST.__default.IND), (_885_els)._ToString(Dafny.Sequence.Concat(_pat_let_tv55, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv56), Dafny.Sequence.UnicodeFromString("}"))))); } } - if (unmatched31) { - if (_source31.is_StructBuild) { - Dafny.ISequence _863_name = _source31.dtor_name; - Dafny.ISequence _864_assignments = _source31.dtor_assignments; - unmatched31 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_863_name, Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString(_864_assignments, Dafny.Helpers.Id, Func>>>((_865_ind) => ((System.Func>)((_866_assignment) => { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _865_ind), RAST.__default.IND), (_866_assignment)._ToString(Dafny.Sequence.Concat(_865_ind, RAST.__default.IND))); - })))(_pat_let_tv59), Dafny.Sequence.UnicodeFromString(","))), (((new BigInteger((_864_assignments).Count)).Sign == 1) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv60)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString("}")); + if (unmatched33) { + if (_source33.is_StructBuild) { + RAST._IExpr _886_name = _source33.dtor_underlying; + Dafny.ISequence _887_assignments = _source33.dtor_assignments; + unmatched33 = false; + if (((new BigInteger((_887_assignments).Count)).Sign == 1) && ((((_887_assignments).Select(BigInteger.Zero)).dtor_identifier).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_886_name)._ToString(_pat_let_tv57), Dafny.Sequence.UnicodeFromString(" (")), RAST.__default.SeqToString(_887_assignments, Dafny.Helpers.Id, Func>>>((_888_ind) => ((System.Func>)((_889_assignment) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _888_ind), RAST.__default.IND), ((_889_assignment).dtor_rhs)._ToString(Dafny.Sequence.Concat(_888_ind, RAST.__default.IND))); + })))(_pat_let_tv58), Dafny.Sequence.UnicodeFromString(","))), (((new BigInteger((_887_assignments).Count)) > (BigInteger.One)) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv59)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(")")); + } else { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_886_name)._ToString(_pat_let_tv60), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString(_887_assignments, Dafny.Helpers.Id, Func>>>((_890_ind) => ((System.Func>)((_891_assignment) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _890_ind), RAST.__default.IND), (_891_assignment)._ToString(Dafny.Sequence.Concat(_890_ind, RAST.__default.IND))); + })))(_pat_let_tv61), Dafny.Sequence.UnicodeFromString(","))), (((new BigInteger((_887_assignments).Count)).Sign == 1) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv62)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString("}")); + } } } - if (unmatched31) { - if (_source31.is_Tuple) { - Dafny.ISequence _867_arguments = _source31.dtor_arguments; - unmatched31 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString(_867_arguments, Dafny.Helpers.Id, Func>>>((_868_ind) => ((System.Func>)((_869_arg) => { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _868_ind), RAST.__default.IND), (_869_arg)._ToString(Dafny.Sequence.Concat(_868_ind, RAST.__default.IND))); - })))(_pat_let_tv61), Dafny.Sequence.UnicodeFromString(","))), (((new BigInteger((_867_arguments).Count)).Sign == 1) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv62)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(")")); + if (unmatched33) { + if (_source33.is_Tuple) { + Dafny.ISequence _892_arguments = _source33.dtor_arguments; + unmatched33 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString(_892_arguments, Dafny.Helpers.Id, Func>>>((_893_ind) => ((System.Func>)((_894_arg) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _893_ind), RAST.__default.IND), (_894_arg)._ToString(Dafny.Sequence.Concat(_893_ind, RAST.__default.IND))); + })))(_pat_let_tv63), Dafny.Sequence.UnicodeFromString(","))), (((new BigInteger((_892_arguments).Count)).Sign == 1) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv64)) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(")")); } } - if (unmatched31) { - if (_source31.is_UnaryOp) { - Dafny.ISequence _870_op = _source31.dtor_op1; - RAST._IExpr _871_underlying = _source31.dtor_underlying; - DAST.Format._IUnaryOpFormat _872_format = _source31.dtor_format; - unmatched31 = false; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs41 = ((((this).printingInfo).NeedParenthesesFor((_871_underlying).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 _873_leftP = _let_tmp_rhs41.dtor__0; - Dafny.ISequence _874_rightP = _let_tmp_rhs41.dtor__1; - Dafny.ISequence _875_leftOp = ((((_870_op).Equals(Dafny.Sequence.UnicodeFromString("&mut"))) && (!(_873_leftP).Equals(Dafny.Sequence.UnicodeFromString("(")))) ? (Dafny.Sequence.Concat(_870_op, Dafny.Sequence.UnicodeFromString(" "))) : ((((_870_op).Equals(Dafny.Sequence.UnicodeFromString("?"))) ? (Dafny.Sequence.UnicodeFromString("")) : (_870_op)))); - Dafny.ISequence _876_rightOp = (((_870_op).Equals(Dafny.Sequence.UnicodeFromString("?"))) ? (_870_op) : (Dafny.Sequence.UnicodeFromString(""))); - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_875_leftOp, _873_leftP), (_871_underlying)._ToString(_pat_let_tv63)), _874_rightP), _876_rightOp); + if (unmatched33) { + if (_source33.is_UnaryOp) { + Dafny.ISequence _895_op = _source33.dtor_op1; + RAST._IExpr _896_underlying = _source33.dtor_underlying; + DAST.Format._IUnaryOpFormat _897_format = _source33.dtor_format; + unmatched33 = false; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs41 = ((((this).printingInfo).NeedParenthesesFor((_896_underlying).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 _898_leftP = _let_tmp_rhs41.dtor__0; + Dafny.ISequence _899_rightP = _let_tmp_rhs41.dtor__1; + Dafny.ISequence _900_leftOp = ((((_895_op).Equals(Dafny.Sequence.UnicodeFromString("&mut"))) && (!(_898_leftP).Equals(Dafny.Sequence.UnicodeFromString("(")))) ? (Dafny.Sequence.Concat(_895_op, Dafny.Sequence.UnicodeFromString(" "))) : ((((_895_op).Equals(Dafny.Sequence.UnicodeFromString("?"))) ? (Dafny.Sequence.UnicodeFromString("")) : (_895_op)))); + Dafny.ISequence _901_rightOp = (((_895_op).Equals(Dafny.Sequence.UnicodeFromString("?"))) ? (_895_op) : (Dafny.Sequence.UnicodeFromString(""))); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_900_leftOp, _898_leftP), (_896_underlying)._ToString(_pat_let_tv65)), _899_rightP), _901_rightOp); } } - if (unmatched31) { - if (_source31.is_TypeAscription) { - RAST._IExpr _877_left = _source31.dtor_left; - RAST._IType _878_tpe = _source31.dtor_tpe; - unmatched31 = false; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs42 = (this).LeftParentheses(_877_left); - Dafny.ISequence _879_leftLeftP = _let_tmp_rhs42.dtor__0; - Dafny.ISequence _880_leftRightP = _let_tmp_rhs42.dtor__1; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_879_leftLeftP, (_877_left)._ToString(RAST.__default.IND)), _880_leftRightP), Dafny.Sequence.UnicodeFromString(" as ")), (_878_tpe)._ToString(RAST.__default.IND)); + if (unmatched33) { + if (_source33.is_TypeAscription) { + RAST._IExpr _902_left = _source33.dtor_left; + RAST._IType _903_tpe = _source33.dtor_tpe; + unmatched33 = false; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs42 = (this).LeftParentheses(_902_left); + Dafny.ISequence _904_leftLeftP = _let_tmp_rhs42.dtor__0; + Dafny.ISequence _905_leftRightP = _let_tmp_rhs42.dtor__1; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_904_leftLeftP, (_902_left)._ToString(RAST.__default.IND)), _905_leftRightP), Dafny.Sequence.UnicodeFromString(" as ")), (_903_tpe)._ToString(RAST.__default.IND)); } } - if (unmatched31) { - if (_source31.is_BinaryOp) { - Dafny.ISequence _881_op2 = _source31.dtor_op2; - RAST._IExpr _882_left = _source31.dtor_left; - RAST._IExpr _883_right = _source31.dtor_right; - DAST.Format._IBinaryOpFormat _884_format = _source31.dtor_format2; - unmatched31 = false; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs43 = (this).LeftParentheses(_882_left); - Dafny.ISequence _885_leftLeftP = _let_tmp_rhs43.dtor__0; - Dafny.ISequence _886_leftRighP = _let_tmp_rhs43.dtor__1; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs44 = (this).RightParentheses(_883_right); - Dafny.ISequence _887_rightLeftP = _let_tmp_rhs44.dtor__0; - Dafny.ISequence _888_rightRightP = _let_tmp_rhs44.dtor__1; - Dafny.ISequence _889_opRendered = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" "), _881_op2), Dafny.Sequence.UnicodeFromString(" ")); - Dafny.ISequence _890_indLeft = (((_885_leftLeftP).Equals(Dafny.Sequence.UnicodeFromString("("))) ? (Dafny.Sequence.Concat(_pat_let_tv64, RAST.__default.IND)) : (_pat_let_tv65)); - Dafny.ISequence _891_indRight = (((_887_rightLeftP).Equals(Dafny.Sequence.UnicodeFromString("("))) ? (Dafny.Sequence.Concat(_pat_let_tv66, RAST.__default.IND)) : (_pat_let_tv67)); - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_885_leftLeftP, (_882_left)._ToString(_890_indLeft)), _886_leftRighP), _889_opRendered), _887_rightLeftP), (_883_right)._ToString(_891_indRight)), _888_rightRightP); + if (unmatched33) { + if (_source33.is_BinaryOp) { + Dafny.ISequence _906_op2 = _source33.dtor_op2; + RAST._IExpr _907_left = _source33.dtor_left; + RAST._IExpr _908_right = _source33.dtor_right; + DAST.Format._IBinaryOpFormat _909_format = _source33.dtor_format2; + unmatched33 = false; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs43 = (this).LeftParentheses(_907_left); + Dafny.ISequence _910_leftLeftP = _let_tmp_rhs43.dtor__0; + Dafny.ISequence _911_leftRighP = _let_tmp_rhs43.dtor__1; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs44 = (this).RightParentheses(_908_right); + Dafny.ISequence _912_rightLeftP = _let_tmp_rhs44.dtor__0; + Dafny.ISequence _913_rightRightP = _let_tmp_rhs44.dtor__1; + Dafny.ISequence _914_opRendered = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" "), _906_op2), Dafny.Sequence.UnicodeFromString(" ")); + Dafny.ISequence _915_indLeft = (((_910_leftLeftP).Equals(Dafny.Sequence.UnicodeFromString("("))) ? (Dafny.Sequence.Concat(_pat_let_tv66, RAST.__default.IND)) : (_pat_let_tv67)); + Dafny.ISequence _916_indRight = (((_912_rightLeftP).Equals(Dafny.Sequence.UnicodeFromString("("))) ? (Dafny.Sequence.Concat(_pat_let_tv68, RAST.__default.IND)) : (_pat_let_tv69)); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_910_leftLeftP, (_907_left)._ToString(_915_indLeft)), _911_leftRighP), _914_opRendered), _912_rightLeftP), (_908_right)._ToString(_916_indRight)), _913_rightRightP); } } - if (unmatched31) { - if (_source31.is_DeclareVar) { - RAST._IDeclareType _892_declareType = _source31.dtor_declareType; - Dafny.ISequence _893_name = _source31.dtor_name; - Std.Wrappers._IOption _894_optType = _source31.dtor_optType; - Std.Wrappers._IOption _895_optExpr = _source31.dtor_optRhs; - unmatched31 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("let "), ((object.Equals(_892_declareType, RAST.DeclareType.create_MUT())) ? (Dafny.Sequence.UnicodeFromString("mut ")) : (Dafny.Sequence.UnicodeFromString("")))), _893_name), (((_894_optType).is_Some) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(": "), ((_894_optType).dtor_value)._ToString(Dafny.Sequence.Concat(_pat_let_tv68, RAST.__default.IND)))) : (Dafny.Sequence.UnicodeFromString("")))), (((_895_optExpr).is_Some) ? (Dafny.Helpers.Let, Dafny.ISequence>(((_895_optExpr).dtor_value)._ToString(Dafny.Sequence.Concat(_pat_let_tv69, RAST.__default.IND)), _pat_let5_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let5_0, _896_optExprString => (((_896_optExprString).Equals(Dafny.Sequence.UnicodeFromString(""))) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("= /*issue with empty RHS*/"), ((((_895_optExpr).dtor_value).is_RawExpr) ? (Dafny.Sequence.UnicodeFromString("Empty Raw expr")) : (((((_895_optExpr).dtor_value).is_LiteralString) ? (Dafny.Sequence.UnicodeFromString("Empty string literal")) : (((((_895_optExpr).dtor_value).is_LiteralInt) ? (Dafny.Sequence.UnicodeFromString("Empty int literal")) : (Dafny.Sequence.UnicodeFromString("Another case"))))))))) : (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" = "), _896_optExprString)))))) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(";")); + if (unmatched33) { + if (_source33.is_DeclareVar) { + RAST._IDeclareType _917_declareType = _source33.dtor_declareType; + Dafny.ISequence _918_name = _source33.dtor_name; + Std.Wrappers._IOption _919_optType = _source33.dtor_optType; + Std.Wrappers._IOption _920_optExpr = _source33.dtor_optRhs; + unmatched33 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("let "), ((object.Equals(_917_declareType, RAST.DeclareType.create_MUT())) ? (Dafny.Sequence.UnicodeFromString("mut ")) : (Dafny.Sequence.UnicodeFromString("")))), _918_name), (((_919_optType).is_Some) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(": "), ((_919_optType).dtor_value)._ToString(Dafny.Sequence.Concat(_pat_let_tv70, RAST.__default.IND)))) : (Dafny.Sequence.UnicodeFromString("")))), (((_920_optExpr).is_Some) ? (Dafny.Helpers.Let, Dafny.ISequence>(((_920_optExpr).dtor_value)._ToString(Dafny.Sequence.Concat(_pat_let_tv71, RAST.__default.IND)), _pat_let5_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let5_0, _921_optExprString => (((_921_optExprString).Equals(Dafny.Sequence.UnicodeFromString(""))) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("= /*issue with empty RHS*/"), ((((_920_optExpr).dtor_value).is_RawExpr) ? (Dafny.Sequence.UnicodeFromString("Empty Raw expr")) : (((((_920_optExpr).dtor_value).is_LiteralString) ? (Dafny.Sequence.UnicodeFromString("Empty string literal")) : (((((_920_optExpr).dtor_value).is_LiteralInt) ? (Dafny.Sequence.UnicodeFromString("Empty int literal")) : (Dafny.Sequence.UnicodeFromString("Another case"))))))))) : (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" = "), _921_optExprString)))))) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(";")); } } - if (unmatched31) { - if (_source31.is_AssignVar) { - Dafny.ISequence _897_name = _source31.dtor_name; - RAST._IExpr _898_expr = _source31.dtor_rhs; - unmatched31 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_897_name, Dafny.Sequence.UnicodeFromString(" = ")), (_898_expr)._ToString(Dafny.Sequence.Concat(_pat_let_tv70, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString(";")); + if (unmatched33) { + if (_source33.is_Assign) { + Std.Wrappers._IOption _922_names = _source33.dtor_names; + RAST._IExpr _923_expr = _source33.dtor_rhs; + unmatched33 = false; + Dafny.ISequence _924_lhs = ((System.Func>)(() => { + Std.Wrappers._IOption _source34 = _922_names; + bool unmatched34 = true; + if (unmatched34) { + if (_source34.is_Some) { + RAST._IAssignLhs value0 = _source34.dtor_value; + if (value0.is_LocalVar) { + Dafny.ISequence _925_name = value0.dtor_name; + unmatched34 = false; + return Dafny.Sequence.Concat(_925_name, Dafny.Sequence.UnicodeFromString(" = ")); + } + } + } + if (unmatched34) { + if (_source34.is_Some) { + RAST._IAssignLhs value1 = _source34.dtor_value; + if (value1.is_SelectMember) { + RAST._IExpr _926_member = value1.dtor_on; + Dafny.ISequence _927_field = value1.dtor_field; + unmatched34 = false; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs45 = (RAST.Expr.create_Select(_926_member, _927_field)).LeftParentheses(_926_member); + Dafny.ISequence _928_leftP = _let_tmp_rhs45.dtor__0; + Dafny.ISequence _929_rightP = _let_tmp_rhs45.dtor__1; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_928_leftP, (_926_member)._ToString(_pat_let_tv72)), _929_rightP), Dafny.Sequence.UnicodeFromString(".")), _927_field), Dafny.Sequence.UnicodeFromString(" = ")); + } + } + } + if (unmatched34) { + if (_source34.is_Some) { + RAST._IAssignLhs value2 = _source34.dtor_value; + if (value2.is_ExtractTuple) { + Dafny.ISequence> _930_names = value2.dtor_names; + unmatched34 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString>(_930_names, ((System.Func, Dafny.ISequence>)((_931_name) => { + return _931_name; + })), Dafny.Sequence.UnicodeFromString(","))), Dafny.Sequence.UnicodeFromString(") = ")); + } + } + } + if (unmatched34) { + if (_source34.is_Some) { + RAST._IAssignLhs value3 = _source34.dtor_value; + if (value3.is_Index) { + RAST._IExpr _932_e = value3.dtor_expr; + Dafny.ISequence _933_indices = value3.dtor_indices; + unmatched34 = false; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs46 = (RAST.Expr.create_Call(_932_e, _933_indices)).LeftParentheses(_932_e); + Dafny.ISequence _934_leftP = _let_tmp_rhs46.dtor__0; + Dafny.ISequence _935_rightP = _let_tmp_rhs46.dtor__1; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_934_leftP, (_932_e)._ToString(_pat_let_tv73)), _935_rightP), Dafny.Sequence.UnicodeFromString("[")), RAST.__default.SeqToString(_933_indices, Dafny.Helpers.Id, Func>>>((_936_ind) => ((System.Func>)((_937_index) => { + return (_937_index)._ToString(Dafny.Sequence.Concat(_936_ind, RAST.__default.IND)); + })))(_pat_let_tv74), Dafny.Sequence.UnicodeFromString("]["))), Dafny.Sequence.UnicodeFromString("] = ")); + } + } + } + if (unmatched34) { + unmatched34 = false; + return Dafny.Sequence.UnicodeFromString("_ = "); + } + throw new System.Exception("unexpected control point"); + }))(); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(_924_lhs, (_923_expr)._ToString(Dafny.Sequence.Concat(_pat_let_tv75, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString(";")); } } - if (unmatched31) { - if (_source31.is_Labelled) { - Dafny.ISequence _899_name = _source31.dtor_lbl; - RAST._IExpr _900_underlying = _source31.dtor_underlying; - unmatched31 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("'"), _899_name), Dafny.Sequence.UnicodeFromString(": ")), (_900_underlying)._ToString(_pat_let_tv71)); + if (unmatched33) { + if (_source33.is_Labelled) { + Dafny.ISequence _938_name = _source33.dtor_lbl; + RAST._IExpr _939_underlying = _source33.dtor_underlying; + unmatched33 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("'"), _938_name), Dafny.Sequence.UnicodeFromString(": ")), (_939_underlying)._ToString(_pat_let_tv76)); } } - if (unmatched31) { - if (_source31.is_Break) { - Std.Wrappers._IOption> _901_optLbl = _source31.dtor_optLbl; - unmatched31 = false; - Std.Wrappers._IOption> _source32 = _901_optLbl; - bool unmatched32 = true; - if (unmatched32) { - if (_source32.is_Some) { - Dafny.ISequence _902_lbl = _source32.dtor_value; - unmatched32 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("break '"), _902_lbl), Dafny.Sequence.UnicodeFromString(";")); + if (unmatched33) { + if (_source33.is_Break) { + Std.Wrappers._IOption> _940_optLbl = _source33.dtor_optLbl; + unmatched33 = false; + Std.Wrappers._IOption> _source35 = _940_optLbl; + bool unmatched35 = true; + if (unmatched35) { + if (_source35.is_Some) { + Dafny.ISequence _941_lbl = _source35.dtor_value; + unmatched35 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("break '"), _941_lbl), Dafny.Sequence.UnicodeFromString(";")); } } - if (unmatched32) { - unmatched32 = false; + if (unmatched35) { + unmatched35 = false; return Dafny.Sequence.UnicodeFromString("break;"); } throw new System.Exception("unexpected control point"); } } - if (unmatched31) { - if (_source31.is_Continue) { - Std.Wrappers._IOption> _903_optLbl = _source31.dtor_optLbl; - unmatched31 = false; - Std.Wrappers._IOption> _source33 = _903_optLbl; - bool unmatched33 = true; - if (unmatched33) { - if (_source33.is_Some) { - Dafny.ISequence _904_lbl = _source33.dtor_value; - unmatched33 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("continue '"), _904_lbl), Dafny.Sequence.UnicodeFromString(";")); + if (unmatched33) { + if (_source33.is_Continue) { + Std.Wrappers._IOption> _942_optLbl = _source33.dtor_optLbl; + unmatched33 = false; + Std.Wrappers._IOption> _source36 = _942_optLbl; + bool unmatched36 = true; + if (unmatched36) { + if (_source36.is_Some) { + Dafny.ISequence _943_lbl = _source36.dtor_value; + unmatched36 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("continue '"), _943_lbl), Dafny.Sequence.UnicodeFromString(";")); } } - if (unmatched33) { - unmatched33 = false; + if (unmatched36) { + unmatched36 = false; return Dafny.Sequence.UnicodeFromString("continue;"); } throw new System.Exception("unexpected control point"); } } - if (unmatched31) { - if (_source31.is_Loop) { - Std.Wrappers._IOption _905_optCond = _source31.dtor_optCond; - RAST._IExpr _906_underlying = _source31.dtor_underlying; - unmatched31 = false; + if (unmatched33) { + if (_source33.is_Loop) { + Std.Wrappers._IOption _944_optCond = _source33.dtor_optCond; + RAST._IExpr _945_underlying = _source33.dtor_underlying; + unmatched33 = false; return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(((System.Func>)(() => { - Std.Wrappers._IOption _source34 = _905_optCond; - bool unmatched34 = true; - if (unmatched34) { - if (_source34.is_None) { - unmatched34 = false; + Std.Wrappers._IOption _source37 = _944_optCond; + bool unmatched37 = true; + if (unmatched37) { + if (_source37.is_None) { + unmatched37 = false; return Dafny.Sequence.UnicodeFromString("loop"); } } - if (unmatched34) { - RAST._IExpr _907_c = _source34.dtor_value; - unmatched34 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("while "), (_907_c)._ToString(Dafny.Sequence.Concat(_pat_let_tv72, RAST.__default.IND))); + if (unmatched37) { + RAST._IExpr _946_c = _source37.dtor_value; + unmatched37 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("while "), (_946_c)._ToString(Dafny.Sequence.Concat(_pat_let_tv77, RAST.__default.IND))); } throw new System.Exception("unexpected control point"); - }))(), Dafny.Sequence.UnicodeFromString(" {\n")), _pat_let_tv73), RAST.__default.IND), (_906_underlying)._ToString(Dafny.Sequence.Concat(_pat_let_tv74, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv75), Dafny.Sequence.UnicodeFromString("}")); + }))(), Dafny.Sequence.UnicodeFromString(" {\n")), _pat_let_tv78), RAST.__default.IND), (_945_underlying)._ToString(Dafny.Sequence.Concat(_pat_let_tv79, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv80), Dafny.Sequence.UnicodeFromString("}")); } } - if (unmatched31) { - if (_source31.is_For) { - Dafny.ISequence _908_name = _source31.dtor_name; - RAST._IExpr _909_range = _source31.dtor_range; - RAST._IExpr _910_body = _source31.dtor_body; - unmatched31 = false; - 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.Concat(Dafny.Sequence.UnicodeFromString("for "), _908_name), Dafny.Sequence.UnicodeFromString(" in ")), (_909_range)._ToString(Dafny.Sequence.Concat(_pat_let_tv76, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString(" {\n")), _pat_let_tv77), RAST.__default.IND), (_910_body)._ToString(Dafny.Sequence.Concat(_pat_let_tv78, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv79), Dafny.Sequence.UnicodeFromString("}")); + if (unmatched33) { + if (_source33.is_For) { + Dafny.ISequence _947_name = _source33.dtor_name; + RAST._IExpr _948_range = _source33.dtor_range; + RAST._IExpr _949_body = _source33.dtor_body; + unmatched33 = false; + 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.Concat(Dafny.Sequence.UnicodeFromString("for "), _947_name), Dafny.Sequence.UnicodeFromString(" in ")), (_948_range)._ToString(Dafny.Sequence.Concat(_pat_let_tv81, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString(" {\n")), _pat_let_tv82), RAST.__default.IND), (_949_body)._ToString(Dafny.Sequence.Concat(_pat_let_tv83, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv84), Dafny.Sequence.UnicodeFromString("}")); } } - if (unmatched31) { - if (_source31.is_Return) { - Std.Wrappers._IOption _911_optExpr = _source31.dtor_optExpr; - unmatched31 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("return"), (((_911_optExpr).is_Some) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" "), ((_911_optExpr).dtor_value)._ToString(Dafny.Sequence.Concat(_pat_let_tv80, RAST.__default.IND)))) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(";")); + if (unmatched33) { + if (_source33.is_Return) { + Std.Wrappers._IOption _950_optExpr = _source33.dtor_optExpr; + unmatched33 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("return"), (((_950_optExpr).is_Some) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" "), ((_950_optExpr).dtor_value)._ToString(Dafny.Sequence.Concat(_pat_let_tv85, RAST.__default.IND)))) : (Dafny.Sequence.UnicodeFromString("")))), Dafny.Sequence.UnicodeFromString(";")); } } - if (unmatched31) { - if (_source31.is_Call) { - RAST._IExpr _912_expr = _source31.dtor_obj; - Dafny.ISequence _913_tpes = _source31.dtor_typeParameters; - Dafny.ISequence _914_args = _source31.dtor_arguments; - unmatched31 = false; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs45 = (this).LeftParentheses(_912_expr); - Dafny.ISequence _915_leftP = _let_tmp_rhs45.dtor__0; - Dafny.ISequence _916_rightP = _let_tmp_rhs45.dtor__1; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs46 = ((System.Func<_System._ITuple2, Dafny.ISequence>>)(() => { - Std.Wrappers._IOption> _source35 = (_912_expr).RightMostIdentifier(); - bool unmatched35 = true; - if (unmatched35) { + if (unmatched33) { + if (_source33.is_CallType) { + RAST._IExpr _951_expr = _source33.dtor_obj; + Dafny.ISequence _952_tpes = _source33.dtor_typeParameters; + unmatched33 = false; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs47 = (this).LeftParentheses(_951_expr); + Dafny.ISequence _953_leftP = _let_tmp_rhs47.dtor__0; + Dafny.ISequence _954_rightP = _let_tmp_rhs47.dtor__1; + if ((_952_tpes).Equals(Dafny.Sequence.FromElements())) { + return (_951_expr)._ToString(_pat_let_tv86); + } else { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_953_leftP, (_951_expr)._ToString(_pat_let_tv87)), _954_rightP), Dafny.Sequence.UnicodeFromString("::<")), RAST.__default.SeqToString(_952_tpes, Dafny.Helpers.Id, Func>>>((_955_ind) => ((System.Func>)((_956_tpe) => { + return (_956_tpe)._ToString(Dafny.Sequence.Concat(_955_ind, RAST.__default.IND)); + })))(_pat_let_tv88), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(">")); + } + } + } + if (unmatched33) { + if (_source33.is_Call) { + RAST._IExpr _957_expr = _source33.dtor_obj; + Dafny.ISequence _958_args = _source33.dtor_arguments; + unmatched33 = false; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs48 = (this).LeftParentheses(_957_expr); + Dafny.ISequence _959_leftP = _let_tmp_rhs48.dtor__0; + Dafny.ISequence _960_rightP = _let_tmp_rhs48.dtor__1; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs49 = ((System.Func<_System._ITuple2, Dafny.ISequence>>)(() => { + Std.Wrappers._IOption> _source38 = (_957_expr).RightMostIdentifier(); + bool unmatched38 = true; + if (unmatched38) { bool disjunctiveMatch0 = false; - if (_source35.is_Some) { - Dafny.ISequence value0 = _source35.dtor_value; - if (object.Equals(value0, Dafny.Sequence.UnicodeFromString("seq!"))) { + if (_source38.is_Some) { + Dafny.ISequence value4 = _source38.dtor_value; + if (object.Equals(value4, Dafny.Sequence.UnicodeFromString("seq!"))) { disjunctiveMatch0 = true; } } - if (_source35.is_Some) { - Dafny.ISequence value1 = _source35.dtor_value; - if (object.Equals(value1, Dafny.Sequence.UnicodeFromString("map!"))) { + if (_source38.is_Some) { + Dafny.ISequence value5 = _source38.dtor_value; + if (object.Equals(value5, Dafny.Sequence.UnicodeFromString("map!"))) { disjunctiveMatch0 = true; } } if (disjunctiveMatch0) { - unmatched35 = false; + unmatched38 = false; return _System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("["), Dafny.Sequence.UnicodeFromString("]")); } } - if (unmatched35) { + if (unmatched38) { bool disjunctiveMatch1 = false; - if (_source35.is_Some) { - Dafny.ISequence value2 = _source35.dtor_value; - if (object.Equals(value2, Dafny.Sequence.UnicodeFromString("set!"))) { + if (_source38.is_Some) { + Dafny.ISequence value6 = _source38.dtor_value; + if (object.Equals(value6, Dafny.Sequence.UnicodeFromString("set!"))) { disjunctiveMatch1 = true; } } - if (_source35.is_Some) { - Dafny.ISequence value3 = _source35.dtor_value; - if (object.Equals(value3, Dafny.Sequence.UnicodeFromString("multiset!"))) { + if (_source38.is_Some) { + Dafny.ISequence value7 = _source38.dtor_value; + if (object.Equals(value7, Dafny.Sequence.UnicodeFromString("multiset!"))) { disjunctiveMatch1 = true; } } if (disjunctiveMatch1) { - unmatched35 = false; + unmatched38 = false; return _System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("{"), Dafny.Sequence.UnicodeFromString("}")); } } - if (unmatched35) { - Std.Wrappers._IOption> _917___v28 = _source35; - unmatched35 = false; + if (unmatched38) { + Std.Wrappers._IOption> _961___v40 = _source38; + unmatched38 = false; return _System.Tuple2, Dafny.ISequence>.create(Dafny.Sequence.UnicodeFromString("("), Dafny.Sequence.UnicodeFromString(")")); } throw new System.Exception("unexpected control point"); }))(); - Dafny.ISequence _918_leftCallP = _let_tmp_rhs46.dtor__0; - Dafny.ISequence _919_rightCallP = _let_tmp_rhs46.dtor__1; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_915_leftP, (_912_expr)._ToString(_pat_let_tv81)), _916_rightP), (((new BigInteger((_913_tpes).Count)).Sign == 0) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("::<"), RAST.__default.SeqToString(_913_tpes, Dafny.Helpers.Id, Func>>>((_920_ind) => ((System.Func>)((_921_tpe) => { - return (_921_tpe)._ToString(Dafny.Sequence.Concat(_920_ind, RAST.__default.IND)); - })))(_pat_let_tv82), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(">"))))), _918_leftCallP), RAST.__default.SeqToString(_914_args, Dafny.Helpers.Id, Func>>>((_922_ind) => ((System.Func>)((_923_arg) => { - return (_923_arg)._ToString(Dafny.Sequence.Concat(_922_ind, RAST.__default.IND)); - })))(_pat_let_tv83), Dafny.Sequence.UnicodeFromString(", "))), _919_rightCallP); + Dafny.ISequence _962_leftCallP = _let_tmp_rhs49.dtor__0; + Dafny.ISequence _963_rightCallP = _let_tmp_rhs49.dtor__1; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_959_leftP, (_957_expr)._ToString(_pat_let_tv89)), _960_rightP), _962_leftCallP), RAST.__default.SeqToString(_958_args, Dafny.Helpers.Id, Func>>>((_964_ind) => ((System.Func>)((_965_arg) => { + return (_965_arg)._ToString(Dafny.Sequence.Concat(_964_ind, RAST.__default.IND)); + })))(_pat_let_tv90), Dafny.Sequence.UnicodeFromString(", "))), _963_rightCallP); } } - if (unmatched31) { - if (_source31.is_Select) { - RAST._IExpr _924_expression = _source31.dtor_obj; - Dafny.ISequence _925_name = _source31.dtor_name; - unmatched31 = false; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs47 = (this).LeftParentheses(_924_expression); - Dafny.ISequence _926_leftP = _let_tmp_rhs47.dtor__0; - Dafny.ISequence _927_rightP = _let_tmp_rhs47.dtor__1; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_926_leftP, (_924_expression)._ToString(_pat_let_tv84)), _927_rightP), Dafny.Sequence.UnicodeFromString(".")), _925_name); + if (unmatched33) { + if (_source33.is_Select) { + RAST._IExpr _966_expression = _source33.dtor_obj; + Dafny.ISequence _967_name = _source33.dtor_name; + unmatched33 = false; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs50 = (this).LeftParentheses(_966_expression); + Dafny.ISequence _968_leftP = _let_tmp_rhs50.dtor__0; + Dafny.ISequence _969_rightP = _let_tmp_rhs50.dtor__1; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_968_leftP, (_966_expression)._ToString(_pat_let_tv91)), _969_rightP), Dafny.Sequence.UnicodeFromString(".")), _967_name); } } - if (unmatched31) { - if (_source31.is_MemberSelect) { - RAST._IExpr _928_expression = _source31.dtor_obj; - Dafny.ISequence _929_name = _source31.dtor_name; - unmatched31 = false; - _System._ITuple2, Dafny.ISequence> _let_tmp_rhs48 = (this).LeftParentheses(_928_expression); - Dafny.ISequence _930_leftP = _let_tmp_rhs48.dtor__0; - Dafny.ISequence _931_rightP = _let_tmp_rhs48.dtor__1; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_930_leftP, (_928_expression)._ToString(_pat_let_tv85)), _931_rightP), Dafny.Sequence.UnicodeFromString("::")), _929_name); + if (unmatched33) { + if (_source33.is_MemberSelect) { + RAST._IExpr _970_expression = _source33.dtor_obj; + Dafny.ISequence _971_name = _source33.dtor_name; + unmatched33 = false; + _System._ITuple2, Dafny.ISequence> _let_tmp_rhs51 = (this).LeftParentheses(_970_expression); + Dafny.ISequence _972_leftP = _let_tmp_rhs51.dtor__0; + Dafny.ISequence _973_rightP = _let_tmp_rhs51.dtor__1; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_972_leftP, (_970_expression)._ToString(_pat_let_tv92)), _973_rightP), Dafny.Sequence.UnicodeFromString("::")), _971_name); } } - if (unmatched31) { - RAST._IExpr _932_r = _source31; - unmatched31 = false; - return RAST.__default.AddIndent((_932_r).dtor_content, _pat_let_tv86); + if (unmatched33) { + if (_source33.is_Lambda) { + Dafny.ISequence _974_params = _source33.dtor_params; + Std.Wrappers._IOption _975_retType = _source33.dtor_retType; + RAST._IExpr _976_body = _source33.dtor_body; + unmatched33 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("move |"), RAST.__default.SeqToString(_974_params, Dafny.Helpers.Id, Func>>>((_977_ind) => ((System.Func>)((_978_arg) => { + return (_978_arg)._ToString(_977_ind); + })))(_pat_let_tv93), Dafny.Sequence.UnicodeFromString(","))), Dafny.Sequence.UnicodeFromString("| ")), (((_975_retType).is_Some) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("-> "), ((_975_retType).dtor_value)._ToString(_pat_let_tv94)), Dafny.Sequence.UnicodeFromString(" "))) : (Dafny.Sequence.UnicodeFromString("")))), (_976_body)._ToString(_pat_let_tv95)); + } + } + if (unmatched33) { + RAST._IExpr _979_r = _source33; + unmatched33 = false; + return RAST.__default.AddIndent((_979_r).dtor_content, _pat_let_tv96); } throw new System.Exception("unexpected control point"); } public RAST._IExpr Then(RAST._IExpr rhs2) { if ((this).is_StmtExpr) { return RAST.Expr.create_StmtExpr((this).dtor_stmt, ((this).dtor_rhs).Then(rhs2)); + } else if (object.Equals(this, RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")))) { + return rhs2; } else { return RAST.Expr.create_StmtExpr(this, rhs2); } @@ -4185,292 +4890,338 @@ public RAST._IExpr Sel(Dafny.ISequence name) { public RAST._IExpr MSel(Dafny.ISequence name) { return RAST.Expr.create_MemberSelect(this, name); } - public RAST._IExpr Apply(Dafny.ISequence typeParameters, Dafny.ISequence arguments) - { - return RAST.Expr.create_Call(this, typeParameters, arguments); + public RAST._IExpr ApplyType(Dafny.ISequence typeParameters) { + return RAST.Expr.create_CallType(this, typeParameters); + } + public RAST._IExpr ApplyType1(RAST._IType typeParameter) { + return RAST.Expr.create_CallType(this, Dafny.Sequence.FromElements(typeParameter)); + } + public RAST._IExpr Apply(Dafny.ISequence arguments) { + return RAST.Expr.create_Call(this, arguments); } public RAST._IExpr Apply1(RAST._IExpr argument) { - return RAST.Expr.create_Call(this, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(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.modify__macro))) && ((new BigInteger(((this).dtor_arguments).Count)) == (BigInteger.One))) && ((((this).dtor_arguments).Select(BigInteger.Zero)).is_Identifier)); + } + public Dafny.ISequence LhsIdentifierName() { + if ((this).is_Identifier) { + return (this).dtor_name; + } else { + return (((this).dtor_arguments).Select(BigInteger.Zero)).dtor_name; + } } public RAST._IPrintingInfo printingInfo { get { - RAST._IExpr _source36 = this; - bool unmatched36 = true; - if (unmatched36) { - if (_source36.is_RawExpr) { - Dafny.ISequence _933___v0 = _source36.dtor_content; - unmatched36 = false; + RAST._IExpr _source39 = this; + bool unmatched39 = true; + if (unmatched39) { + if (_source39.is_RawExpr) { + Dafny.ISequence _980___v1 = _source39.dtor_content; + unmatched39 = false; return RAST.PrintingInfo.create_UnknownPrecedence(); } } - if (unmatched36) { - if (_source36.is_Identifier) { - Dafny.ISequence _934___v1 = _source36.dtor_name; - unmatched36 = false; + if (unmatched39) { + if (_source39.is_ExprFromType) { + RAST._IType _981___v2 = _source39.dtor_tpe; + unmatched39 = false; return RAST.PrintingInfo.create_Precedence(BigInteger.One); } } - if (unmatched36) { - if (_source36.is_LiteralInt) { - Dafny.ISequence _935___v2 = _source36.dtor_value; - unmatched36 = false; + if (unmatched39) { + if (_source39.is_Identifier) { + Dafny.ISequence _982___v3 = _source39.dtor_name; + unmatched39 = false; return RAST.PrintingInfo.create_Precedence(BigInteger.One); } } - if (unmatched36) { - if (_source36.is_LiteralString) { - Dafny.ISequence _936___v3 = _source36.dtor_value; - bool _937___v4 = _source36.dtor_binary; - unmatched36 = false; + if (unmatched39) { + if (_source39.is_LiteralInt) { + Dafny.ISequence _983___v4 = _source39.dtor_value; + unmatched39 = false; return RAST.PrintingInfo.create_Precedence(BigInteger.One); } } - if (unmatched36) { - if (_source36.is_UnaryOp) { - Dafny.ISequence _938_op = _source36.dtor_op1; - RAST._IExpr _939_underlying = _source36.dtor_underlying; - DAST.Format._IUnaryOpFormat _940_format = _source36.dtor_format; - unmatched36 = false; - Dafny.ISequence _source37 = _938_op; - bool unmatched37 = true; - if (unmatched37) { - if (object.Equals(_source37, Dafny.Sequence.UnicodeFromString("?"))) { - unmatched37 = false; + if (unmatched39) { + if (_source39.is_LiteralBool) { + bool _984___v5 = _source39.dtor_bvalue; + unmatched39 = false; + return RAST.PrintingInfo.create_Precedence(BigInteger.One); + } + } + if (unmatched39) { + if (_source39.is_LiteralString) { + Dafny.ISequence _985___v6 = _source39.dtor_value; + bool _986___v7 = _source39.dtor_binary; + bool _987___v8 = _source39.dtor_verbatim; + unmatched39 = false; + return RAST.PrintingInfo.create_Precedence(BigInteger.One); + } + } + if (unmatched39) { + if (_source39.is_UnaryOp) { + Dafny.ISequence _988_op = _source39.dtor_op1; + RAST._IExpr _989_underlying = _source39.dtor_underlying; + DAST.Format._IUnaryOpFormat _990_format = _source39.dtor_format; + unmatched39 = false; + Dafny.ISequence _source40 = _988_op; + bool unmatched40 = true; + if (unmatched40) { + if (object.Equals(_source40, Dafny.Sequence.UnicodeFromString("?"))) { + unmatched40 = false; return RAST.PrintingInfo.create_SuffixPrecedence(new BigInteger(5)); } } - if (unmatched37) { + if (unmatched40) { bool disjunctiveMatch2 = false; - if (object.Equals(_source37, Dafny.Sequence.UnicodeFromString("-"))) { + if (object.Equals(_source40, Dafny.Sequence.UnicodeFromString("-"))) { disjunctiveMatch2 = true; } - if (object.Equals(_source37, Dafny.Sequence.UnicodeFromString("*"))) { + if (object.Equals(_source40, Dafny.Sequence.UnicodeFromString("*"))) { disjunctiveMatch2 = true; } - if (object.Equals(_source37, Dafny.Sequence.UnicodeFromString("!"))) { + if (object.Equals(_source40, Dafny.Sequence.UnicodeFromString("!"))) { disjunctiveMatch2 = true; } - if (object.Equals(_source37, Dafny.Sequence.UnicodeFromString("&"))) { + if (object.Equals(_source40, Dafny.Sequence.UnicodeFromString("&"))) { disjunctiveMatch2 = true; } - if (object.Equals(_source37, Dafny.Sequence.UnicodeFromString("&mut"))) { + if (object.Equals(_source40, Dafny.Sequence.UnicodeFromString("&mut"))) { disjunctiveMatch2 = true; } if (disjunctiveMatch2) { - unmatched37 = false; + unmatched40 = false; return RAST.PrintingInfo.create_Precedence(new BigInteger(6)); } } - if (unmatched37) { - Dafny.ISequence _941___v5 = _source37; - unmatched37 = false; + if (unmatched40) { + Dafny.ISequence _991___v9 = _source40; + unmatched40 = false; return RAST.PrintingInfo.create_UnknownPrecedence(); } throw new System.Exception("unexpected control point"); } } - if (unmatched36) { - if (_source36.is_Select) { - RAST._IExpr _942_underlying = _source36.dtor_obj; - Dafny.ISequence _943_name = _source36.dtor_name; - unmatched36 = false; + if (unmatched39) { + if (_source39.is_Select) { + RAST._IExpr _992_underlying = _source39.dtor_obj; + Dafny.ISequence _993_name = _source39.dtor_name; + unmatched39 = false; + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(2), RAST.Associativity.create_LeftToRight()); + } + } + if (unmatched39) { + if (_source39.is_MemberSelect) { + RAST._IExpr _994_underlying = _source39.dtor_obj; + Dafny.ISequence _995_name = _source39.dtor_name; + unmatched39 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(2), RAST.Associativity.create_LeftToRight()); } } - if (unmatched36) { - if (_source36.is_MemberSelect) { - RAST._IExpr _944_underlying = _source36.dtor_obj; - Dafny.ISequence _945_name = _source36.dtor_name; - unmatched36 = false; + if (unmatched39) { + if (_source39.is_CallType) { + RAST._IExpr _996___v10 = _source39.dtor_obj; + Dafny.ISequence _997___v11 = _source39.dtor_typeParameters; + unmatched39 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(2), RAST.Associativity.create_LeftToRight()); } } - if (unmatched36) { - if (_source36.is_Call) { - RAST._IExpr _946___v6 = _source36.dtor_obj; - Dafny.ISequence _947___v7 = _source36.dtor_typeParameters; - Dafny.ISequence _948___v8 = _source36.dtor_arguments; - unmatched36 = false; + if (unmatched39) { + if (_source39.is_Call) { + RAST._IExpr _998___v12 = _source39.dtor_obj; + Dafny.ISequence _999___v13 = _source39.dtor_arguments; + unmatched39 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(2), RAST.Associativity.create_LeftToRight()); } } - if (unmatched36) { - if (_source36.is_TypeAscription) { - RAST._IExpr _949_left = _source36.dtor_left; - RAST._IType _950_tpe = _source36.dtor_tpe; - unmatched36 = false; + if (unmatched39) { + if (_source39.is_TypeAscription) { + RAST._IExpr _1000_left = _source39.dtor_left; + RAST._IType _1001_tpe = _source39.dtor_tpe; + unmatched39 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(10), RAST.Associativity.create_LeftToRight()); } } - if (unmatched36) { - if (_source36.is_BinaryOp) { - Dafny.ISequence _951_op2 = _source36.dtor_op2; - RAST._IExpr _952_left = _source36.dtor_left; - RAST._IExpr _953_right = _source36.dtor_right; - DAST.Format._IBinaryOpFormat _954_format = _source36.dtor_format2; - unmatched36 = false; - Dafny.ISequence _source38 = _951_op2; - bool unmatched38 = true; - if (unmatched38) { + if (unmatched39) { + if (_source39.is_BinaryOp) { + Dafny.ISequence _1002_op2 = _source39.dtor_op2; + RAST._IExpr _1003_left = _source39.dtor_left; + RAST._IExpr _1004_right = _source39.dtor_right; + DAST.Format._IBinaryOpFormat _1005_format = _source39.dtor_format2; + unmatched39 = false; + Dafny.ISequence _source41 = _1002_op2; + bool unmatched41 = true; + if (unmatched41) { bool disjunctiveMatch3 = false; - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("*"))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("*"))) { disjunctiveMatch3 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("/"))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("/"))) { disjunctiveMatch3 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("%"))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("%"))) { disjunctiveMatch3 = true; } if (disjunctiveMatch3) { - unmatched38 = false; + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(20), RAST.Associativity.create_LeftToRight()); } } - if (unmatched38) { + if (unmatched41) { bool disjunctiveMatch4 = false; - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("+"))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("+"))) { disjunctiveMatch4 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("-"))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("-"))) { disjunctiveMatch4 = true; } if (disjunctiveMatch4) { - unmatched38 = false; + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(30), RAST.Associativity.create_LeftToRight()); } } - if (unmatched38) { + if (unmatched41) { bool disjunctiveMatch5 = false; - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("<<"))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("<<"))) { disjunctiveMatch5 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString(">>"))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString(">>"))) { disjunctiveMatch5 = true; } if (disjunctiveMatch5) { - unmatched38 = false; + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(40), RAST.Associativity.create_LeftToRight()); } } - if (unmatched38) { - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("&"))) { - unmatched38 = false; + if (unmatched41) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("&"))) { + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(50), RAST.Associativity.create_LeftToRight()); } } - if (unmatched38) { - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("^"))) { - unmatched38 = false; + if (unmatched41) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("^"))) { + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(60), RAST.Associativity.create_LeftToRight()); } } - if (unmatched38) { - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("|"))) { - unmatched38 = false; + if (unmatched41) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("|"))) { + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(70), RAST.Associativity.create_LeftToRight()); } } - if (unmatched38) { + if (unmatched41) { bool disjunctiveMatch6 = false; - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("=="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("=="))) { disjunctiveMatch6 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("!="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("!="))) { disjunctiveMatch6 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("<"))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("<"))) { disjunctiveMatch6 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString(">"))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString(">"))) { disjunctiveMatch6 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("<="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("<="))) { disjunctiveMatch6 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString(">="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString(">="))) { disjunctiveMatch6 = true; } if (disjunctiveMatch6) { - unmatched38 = false; + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(80), RAST.Associativity.create_RequiresParentheses()); } } - if (unmatched38) { - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("&&"))) { - unmatched38 = false; + if (unmatched41) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("&&"))) { + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(90), RAST.Associativity.create_LeftToRight()); } } - if (unmatched38) { - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("||"))) { - unmatched38 = false; + if (unmatched41) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("||"))) { + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(100), RAST.Associativity.create_LeftToRight()); } } - if (unmatched38) { + if (unmatched41) { bool disjunctiveMatch7 = false; - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString(".."))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString(".."))) { disjunctiveMatch7 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("..="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("..="))) { disjunctiveMatch7 = true; } if (disjunctiveMatch7) { - unmatched38 = false; + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RequiresParentheses()); } } - if (unmatched38) { + if (unmatched41) { bool disjunctiveMatch8 = false; - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("+="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("+="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("-="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("-="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("*="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("*="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("/="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("/="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("%="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("%="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("&="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("&="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("|="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("|="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("^="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("^="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString("<<="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString("<<="))) { disjunctiveMatch8 = true; } - if (object.Equals(_source38, Dafny.Sequence.UnicodeFromString(">>="))) { + if (object.Equals(_source41, Dafny.Sequence.UnicodeFromString(">>="))) { disjunctiveMatch8 = true; } if (disjunctiveMatch8) { - unmatched38 = false; + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(110), RAST.Associativity.create_RightToLeft()); } } - if (unmatched38) { - Dafny.ISequence _955___v9 = _source38; - unmatched38 = false; + if (unmatched41) { + Dafny.ISequence _1006___v14 = _source41; + unmatched41 = false; return RAST.PrintingInfo.create_PrecedenceAssociativity(BigInteger.Zero, RAST.Associativity.create_RequiresParentheses()); } throw new System.Exception("unexpected control point"); } } - if (unmatched36) { - RAST._IExpr _956___v10 = _source36; - unmatched36 = false; + if (unmatched39) { + if (_source39.is_Lambda) { + Dafny.ISequence _1007___v15 = _source39.dtor_params; + Std.Wrappers._IOption _1008___v16 = _source39.dtor_retType; + RAST._IExpr _1009___v17 = _source39.dtor_body; + unmatched39 = false; + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(300), RAST.Associativity.create_LeftToRight()); + } + } + if (unmatched39) { + RAST._IExpr _1010___v18 = _source39; + unmatched39 = false; return RAST.PrintingInfo.create_UnknownPrecedence(); } throw new System.Exception("unexpected control point"); @@ -4503,6 +5254,33 @@ public override string ToString() { return s; } } + public class Expr_ExprFromType : Expr { + public readonly RAST._IType _tpe; + public Expr_ExprFromType(RAST._IType tpe) : base() { + this._tpe = tpe; + } + public override _IExpr DowncastClone() { + if (this is _IExpr dt) { return dt; } + return new Expr_ExprFromType(_tpe); + } + public override bool Equals(object other) { + var oth = other as RAST.Expr_ExprFromType; + return oth != null && object.Equals(this._tpe, oth._tpe); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._tpe)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.Expr.ExprFromType"; + s += "("; + s += Dafny.Helpers.ToString(this._tpe); + s += ")"; + return s; + } + } public class Expr_Identifier : Expr { public readonly Dafny.ISequence _name; public Expr_Identifier(Dafny.ISequence name) : base() { @@ -4518,7 +5296,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 1; + hash = ((hash << 5) + hash) + 2; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); return (int) hash; } @@ -4547,7 +5325,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + 3; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._matchee)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._cases)); return (int) hash; @@ -4579,7 +5357,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._stmt)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._rhs)); return (int) hash; @@ -4609,7 +5387,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._underlying)); return (int) hash; } @@ -4622,31 +5400,31 @@ public override string ToString() { } } public class Expr_StructBuild : Expr { - public readonly Dafny.ISequence _name; + public readonly RAST._IExpr _underlying; public readonly Dafny.ISequence _assignments; - public Expr_StructBuild(Dafny.ISequence name, Dafny.ISequence assignments) : base() { - this._name = name; + public Expr_StructBuild(RAST._IExpr underlying, Dafny.ISequence assignments) : base() { + this._underlying = underlying; this._assignments = assignments; } public override _IExpr DowncastClone() { if (this is _IExpr dt) { return dt; } - return new Expr_StructBuild(_name, _assignments); + return new Expr_StructBuild(_underlying, _assignments); } public override bool Equals(object other) { var oth = other as RAST.Expr_StructBuild; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._assignments, oth._assignments); + return oth != null && object.Equals(this._underlying, oth._underlying) && object.Equals(this._assignments, oth._assignments); } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 5; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); + hash = ((hash << 5) + hash) + 6; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._assignments)); return (int) hash; } public override string ToString() { string s = "RAST.Expr.StructBuild"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._underlying); s += ", "; s += Dafny.Helpers.ToString(this._assignments); s += ")"; @@ -4668,7 +5446,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._arguments)); return (int) hash; } @@ -4699,7 +5477,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._op1)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._format)); @@ -4738,7 +5516,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._op2)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._left)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._right)); @@ -4776,7 +5554,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._left)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._tpe)); return (int) hash; @@ -4806,7 +5584,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._value)); return (int) hash; } @@ -4818,66 +5596,66 @@ public override string ToString() { return s; } } - public class Expr_LiteralString : Expr { - public readonly Dafny.ISequence _value; - public readonly bool _binary; - public Expr_LiteralString(Dafny.ISequence @value, bool binary) : base() { - this._value = @value; - this._binary = binary; + public class Expr_LiteralBool : Expr { + public readonly bool _bvalue; + public Expr_LiteralBool(bool bvalue) : base() { + this._bvalue = bvalue; } public override _IExpr DowncastClone() { if (this is _IExpr dt) { return dt; } - return new Expr_LiteralString(_value, _binary); + return new Expr_LiteralBool(_bvalue); } public override bool Equals(object other) { - var oth = other as RAST.Expr_LiteralString; - return oth != null && object.Equals(this._value, oth._value) && this._binary == oth._binary; + var oth = other as RAST.Expr_LiteralBool; + return oth != null && this._bvalue == oth._bvalue; } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 11; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._binary)); + hash = ((hash << 5) + hash) + 12; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._bvalue)); return (int) hash; } public override string ToString() { - string s = "RAST.Expr.LiteralString"; + string s = "RAST.Expr.LiteralBool"; s += "("; - s += this._value.ToVerbatimString(true); - s += ", "; - s += Dafny.Helpers.ToString(this._binary); + s += Dafny.Helpers.ToString(this._bvalue); s += ")"; return s; } } - public class Expr_ConversionNum : Expr { - public readonly RAST._IType _tpe; - public readonly RAST._IExpr _underlying; - public Expr_ConversionNum(RAST._IType tpe, RAST._IExpr underlying) : base() { - this._tpe = tpe; - this._underlying = underlying; + public class Expr_LiteralString : Expr { + public readonly Dafny.ISequence _value; + public readonly bool _binary; + public readonly bool _verbatim; + public Expr_LiteralString(Dafny.ISequence @value, bool binary, bool verbatim) : base() { + this._value = @value; + this._binary = binary; + this._verbatim = verbatim; } public override _IExpr DowncastClone() { if (this is _IExpr dt) { return dt; } - return new Expr_ConversionNum(_tpe, _underlying); + return new Expr_LiteralString(_value, _binary, _verbatim); } public override bool Equals(object other) { - var oth = other as RAST.Expr_ConversionNum; - return oth != null && object.Equals(this._tpe, oth._tpe) && object.Equals(this._underlying, oth._underlying); + var oth = other as RAST.Expr_LiteralString; + return oth != null && object.Equals(this._value, oth._value) && this._binary == oth._binary && this._verbatim == oth._verbatim; } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 12; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._tpe)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); + hash = ((hash << 5) + hash) + 13; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._value)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._binary)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._verbatim)); return (int) hash; } public override string ToString() { - string s = "RAST.Expr.ConversionNum"; + string s = "RAST.Expr.LiteralString"; s += "("; - s += Dafny.Helpers.ToString(this._tpe); + s += this._value.ToVerbatimString(true); s += ", "; - s += Dafny.Helpers.ToString(this._underlying); + s += Dafny.Helpers.ToString(this._binary); + s += ", "; + s += Dafny.Helpers.ToString(this._verbatim); s += ")"; return s; } @@ -4903,7 +5681,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._declareType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._optType)); @@ -4924,32 +5702,32 @@ public override string ToString() { return s; } } - public class Expr_AssignVar : Expr { - public readonly Dafny.ISequence _name; + public class Expr_Assign : Expr { + public readonly Std.Wrappers._IOption _names; public readonly RAST._IExpr _rhs; - public Expr_AssignVar(Dafny.ISequence name, RAST._IExpr rhs) : base() { - this._name = name; + public Expr_Assign(Std.Wrappers._IOption names, RAST._IExpr rhs) : base() { + this._names = names; this._rhs = rhs; } public override _IExpr DowncastClone() { if (this is _IExpr dt) { return dt; } - return new Expr_AssignVar(_name, _rhs); + return new Expr_Assign(_names, _rhs); } public override bool Equals(object other) { - var oth = other as RAST.Expr_AssignVar; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._rhs, oth._rhs); + var oth = other as RAST.Expr_Assign; + return oth != null && object.Equals(this._names, oth._names) && object.Equals(this._rhs, oth._rhs); } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 14; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); + hash = ((hash << 5) + hash) + 15; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._names)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._rhs)); return (int) hash; } public override string ToString() { - string s = "RAST.Expr.AssignVar"; + string s = "RAST.Expr.Assign"; s += "("; - s += this._name.ToVerbatimString(true); + s += Dafny.Helpers.ToString(this._names); s += ", "; s += Dafny.Helpers.ToString(this._rhs); s += ")"; @@ -4975,7 +5753,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._cond)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._thn)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._els)); @@ -5010,7 +5788,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._optCond)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); return (int) hash; @@ -5044,7 +5822,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._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._range)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); @@ -5079,7 +5857,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._lbl)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._underlying)); return (int) hash; @@ -5109,7 +5887,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._optLbl)); return (int) hash; } @@ -5136,7 +5914,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 20; + hash = ((hash << 5) + hash) + 21; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._optLbl)); return (int) hash; } @@ -5163,7 +5941,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._optExpr)); return (int) hash; } @@ -5175,28 +5953,57 @@ public override string ToString() { return s; } } - public class Expr_Call : Expr { + public class Expr_CallType : Expr { public readonly RAST._IExpr _obj; public readonly Dafny.ISequence _typeParameters; - public readonly Dafny.ISequence _arguments; - public Expr_Call(RAST._IExpr obj, Dafny.ISequence typeParameters, Dafny.ISequence arguments) : base() { + public Expr_CallType(RAST._IExpr obj, Dafny.ISequence typeParameters) : base() { this._obj = obj; this._typeParameters = typeParameters; + } + public override _IExpr DowncastClone() { + if (this is _IExpr dt) { return dt; } + return new Expr_CallType(_obj, _typeParameters); + } + public override bool Equals(object other) { + var oth = other as RAST.Expr_CallType; + return oth != null && object.Equals(this._obj, oth._obj) && object.Equals(this._typeParameters, oth._typeParameters); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 23; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._obj)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParameters)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.Expr.CallType"; + s += "("; + s += Dafny.Helpers.ToString(this._obj); + s += ", "; + s += Dafny.Helpers.ToString(this._typeParameters); + s += ")"; + return s; + } + } + public class Expr_Call : Expr { + public readonly RAST._IExpr _obj; + public readonly Dafny.ISequence _arguments; + public Expr_Call(RAST._IExpr obj, Dafny.ISequence arguments) : base() { + this._obj = obj; this._arguments = arguments; } public override _IExpr DowncastClone() { if (this is _IExpr dt) { return dt; } - return new Expr_Call(_obj, _typeParameters, _arguments); + return new Expr_Call(_obj, _arguments); } public override bool Equals(object other) { var oth = other as RAST.Expr_Call; - return oth != null && object.Equals(this._obj, oth._obj) && object.Equals(this._typeParameters, oth._typeParameters) && object.Equals(this._arguments, oth._arguments); + return oth != null && object.Equals(this._obj, oth._obj) && object.Equals(this._arguments, oth._arguments); } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 22; + hash = ((hash << 5) + hash) + 24; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._obj)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParameters)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._arguments)); return (int) hash; } @@ -5205,8 +6012,6 @@ public override string ToString() { s += "("; s += Dafny.Helpers.ToString(this._obj); s += ", "; - s += Dafny.Helpers.ToString(this._typeParameters); - s += ", "; s += Dafny.Helpers.ToString(this._arguments); s += ")"; return s; @@ -5229,7 +6034,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 23; + hash = ((hash << 5) + hash) + 25; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._obj)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); return (int) hash; @@ -5261,7 +6066,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 24; + hash = ((hash << 5) + hash) + 26; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._obj)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); return (int) hash; @@ -5276,11 +6081,48 @@ public override string ToString() { return s; } } + public class Expr_Lambda : Expr { + public readonly Dafny.ISequence _params; + public readonly Std.Wrappers._IOption _retType; + public readonly RAST._IExpr _body; + public Expr_Lambda(Dafny.ISequence @params, Std.Wrappers._IOption retType, RAST._IExpr body) : base() { + this._params = @params; + this._retType = retType; + this._body = body; + } + public override _IExpr DowncastClone() { + if (this is _IExpr dt) { return dt; } + return new Expr_Lambda(_params, _retType, _body); + } + public override bool Equals(object other) { + var oth = other as RAST.Expr_Lambda; + return oth != null && object.Equals(this._params, oth._params) && object.Equals(this._retType, oth._retType) && object.Equals(this._body, oth._body); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 27; + 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)); + return (int) hash; + } + public override string ToString() { + string s = "RAST.Expr.Lambda"; + s += "("; + s += Dafny.Helpers.ToString(this._params); + s += ", "; + s += Dafny.Helpers.ToString(this._retType); + s += ", "; + s += Dafny.Helpers.ToString(this._body); + s += ")"; + return s; + } + } public interface _IFn { bool is_Fn { get; } Dafny.ISequence dtor_name { get; } - Dafny.ISequence dtor_typeParams { get; } + Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_formals { get; } Std.Wrappers._IOption dtor_returnType { get; } Dafny.ISequence dtor_where { get; } @@ -5290,12 +6132,12 @@ public interface _IFn { } public class Fn : _IFn { public readonly Dafny.ISequence _name; - public readonly Dafny.ISequence _typeParams; + public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _formals; public readonly Std.Wrappers._IOption _returnType; public readonly Dafny.ISequence _where; public readonly Std.Wrappers._IOption _body; - public Fn(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence formals, Std.Wrappers._IOption returnType, Dafny.ISequence @where, Std.Wrappers._IOption body) { + public Fn(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence formals, Std.Wrappers._IOption returnType, Dafny.ISequence @where, Std.Wrappers._IOption body) { this._name = name; this._typeParams = typeParams; this._formals = formals; @@ -5339,7 +6181,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IFn theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Dafny.Sequence.Empty, Std.Wrappers.Option.Default()); + private static readonly RAST._IFn theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Dafny.Sequence.Empty, Std.Wrappers.Option.Default()); public static RAST._IFn Default() { return theDefault; } @@ -5347,10 +6189,10 @@ public static RAST._IFn Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IFn create(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence formals, Std.Wrappers._IOption returnType, Dafny.ISequence @where, Std.Wrappers._IOption body) { + public static _IFn create(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence formals, Std.Wrappers._IOption returnType, Dafny.ISequence @where, Std.Wrappers._IOption body) { return new Fn(name, typeParams, formals, returnType, @where, body); } - public static _IFn create_Fn(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence formals, Std.Wrappers._IOption returnType, Dafny.ISequence @where, Std.Wrappers._IOption body) { + public static _IFn create_Fn(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence formals, Std.Wrappers._IOption returnType, Dafny.ISequence @where, Std.Wrappers._IOption body) { return create(name, typeParams, formals, returnType, @where, body); } public bool is_Fn { get { return true; } } @@ -5359,7 +6201,7 @@ public Dafny.ISequence dtor_name { return this._name; } } - public Dafny.ISequence dtor_typeParams { + public Dafny.ISequence dtor_typeParams { get { return this._typeParams; } @@ -5385,41 +6227,41 @@ public Std.Wrappers._IOption dtor_body { } } public Dafny.ISequence _ToString(Dafny.ISequence ind) { - var _pat_let_tv87 = ind; - var _pat_let_tv88 = ind; - var _pat_let_tv89 = ind; - var _pat_let_tv90 = 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("fn "), (this).dtor_name), RAST.TypeParam.ToStringMultiple((this).dtor_typeParams, ind)), Dafny.Sequence.UnicodeFromString("(")), RAST.__default.SeqToString((this).dtor_formals, Dafny.Helpers.Id, Func>>>((_957_ind) => ((System.Func>)((_958_formal) => { - return (_958_formal)._ToString(_957_ind); + var _pat_let_tv97 = ind; + var _pat_let_tv98 = ind; + var _pat_let_tv99 = ind; + var _pat_let_tv100 = 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("fn "), (this).dtor_name), RAST.TypeParamDecl.ToStringMultiple((this).dtor_typeParams, ind)), Dafny.Sequence.UnicodeFromString("(")), RAST.__default.SeqToString((this).dtor_formals, Dafny.Helpers.Id, Func>>>((_1011_ind) => ((System.Func>)((_1012_formal) => { + return (_1012_formal)._ToString(_1011_ind); })))(ind), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(")")), ((System.Func>)(() => { - Std.Wrappers._IOption _source39 = (this).dtor_returnType; - bool unmatched39 = true; - if (unmatched39) { - if (_source39.is_Some) { - RAST._IType _959_t = _source39.dtor_value; - unmatched39 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" -> "), (_959_t)._ToString(_pat_let_tv87)); + Std.Wrappers._IOption _source42 = (this).dtor_returnType; + bool unmatched42 = true; + if (unmatched42) { + if (_source42.is_Some) { + RAST._IType _1013_t = _source42.dtor_value; + unmatched42 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" -> "), (_1013_t)._ToString(_pat_let_tv97)); } } - if (unmatched39) { - Std.Wrappers._IOption _960___v29 = _source39; - unmatched39 = false; + if (unmatched42) { + Std.Wrappers._IOption _1014___v41 = _source42; + unmatched42 = false; return Dafny.Sequence.UnicodeFromString(""); } throw new System.Exception("unexpected control point"); }))()), ((((this).dtor_where).Equals(Dafny.Sequence.UnicodeFromString(""))) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), ind), RAST.__default.IND), (this).dtor_where)))), ((System.Func>)(() => { - Std.Wrappers._IOption _source40 = (this).dtor_body; - bool unmatched40 = true; - if (unmatched40) { - if (_source40.is_None) { - unmatched40 = false; + Std.Wrappers._IOption _source43 = (this).dtor_body; + bool unmatched43 = true; + if (unmatched43) { + if (_source43.is_None) { + unmatched43 = false; return Dafny.Sequence.UnicodeFromString(";"); } } - if (unmatched40) { - RAST._IExpr _961_body = _source40.dtor_value; - unmatched40 = false; - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" {\n"), _pat_let_tv88), RAST.__default.IND), (_961_body)._ToString(Dafny.Sequence.Concat(_pat_let_tv89, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv90), Dafny.Sequence.UnicodeFromString("}")); + if (unmatched43) { + RAST._IExpr _1015_body = _source43.dtor_value; + unmatched43 = false; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString(" {\n"), _pat_let_tv98), RAST.__default.IND), (_1015_body)._ToString(Dafny.Sequence.Concat(_pat_let_tv99, RAST.__default.IND))), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv100), Dafny.Sequence.UnicodeFromString("}")); } throw new System.Exception("unexpected control point"); }))()); diff --git a/Source/DafnyCore/Generic/Util.cs b/Source/DafnyCore/Generic/Util.cs index 69be67819..d52650ab2 100644 --- a/Source/DafnyCore/Generic/Util.cs +++ b/Source/DafnyCore/Generic/Util.cs @@ -281,8 +281,12 @@ public static string RemoveEscaping(DafnyOptions options, string s, bool isVerba public static readonly Regex UnicodeEscape = new Regex(@"\\U\{([0-9a-fA-F_]+)\}"); private static readonly Regex NullEscape = new Regex(@"\\0"); - private static string ToUtf16Escape(char c) { - return $"\\u{(int)c:x4}"; + private static string ToUtf16Escape(char c, bool addBraces = false) { + if (addBraces) { + return $"\\u{{{(int)c:x4}}}"; + } else { + return $"\\u{(int)c:x4}"; + } } public static string ReplaceTokensWithEscapes(string s, Regex pattern, MatchEvaluator evaluator) { @@ -322,6 +326,10 @@ public static string ReplaceNullEscapesWithCharacterEscapes(string s) { return ReplaceTokensWithEscapes(s, NullEscape, match => "\\u0000"); } + public static IEnumerable UnescapedCharacters(DafnyOptions options, string p, bool isVerbatimString) { + return UnescapedCharacters(options.Get(CommonOptionBag.UnicodeCharacters), p, isVerbatimString); + } + /// /// Returns the characters of the well-parsed string p, replacing any /// escaped characters by the actual characters. @@ -330,8 +338,7 @@ public static string ReplaceNullEscapesWithCharacterEscapes(string s) { /// if --unicode-char is enabled - these are synthesized by the parser when /// reading the original UTF-8 source, but don't represent the true character values. /// - public static IEnumerable UnescapedCharacters(DafnyOptions options, string p, bool isVerbatimString) { - var unicodeChars = options.Get(CommonOptionBag.UnicodeCharacters); + public static IEnumerable UnescapedCharacters(bool unicodeChars, string p, bool isVerbatimString) { if (isVerbatimString) { foreach (var s in TokensWithEscapes(p, true)) { if (s == "\"\"") { diff --git a/Source/DafnyCore/dfyconfig.toml b/Source/DafnyCore/dfyconfig.toml index 1de176d7e..afc7fafcc 100644 --- a/Source/DafnyCore/dfyconfig.toml +++ b/Source/DafnyCore/dfyconfig.toml @@ -2,4 +2,4 @@ includes = ["Backends/**/*.dfy","AST/Formatting.dfy"] excludes = [] [options] -standard-libraries=true \ No newline at end of file +standard-libraries=true diff --git a/Source/DafnyLanguageServer/LanguageServer.cs b/Source/DafnyLanguageServer/LanguageServer.cs index 71519f67f..d80f22afa 100644 --- a/Source/DafnyLanguageServer/LanguageServer.cs +++ b/Source/DafnyLanguageServer/LanguageServer.cs @@ -90,10 +90,15 @@ private static void InitializeLogger(DafnyOptions options, IConfiguration config var logLevel = options.Get(CommonOptionBag.LogLevelOption); var logLocation = options.Get(CommonOptionBag.LogLocation) ?? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Environment.SetEnvironmentVariable("DAFNYLS_APP_DIR", logLocation); - Log.Logger = new LoggerConfiguration() + LoggerConfiguration config = new LoggerConfiguration() .ReadFrom.Configuration(configuration) - .MinimumLevel.Override("Microsoft.Dafny", logLevel) - .CreateLogger(); + .MinimumLevel.Override("Microsoft.Dafny", logLevel); + if (logLocation != null) { + var logFile = Path.Combine(logLocation, + "DafnyLanguageServerLog" + DateTime.Now.ToString().Replace("/", "_").Replace("\\", "_") + ".txt"); + config = config.WriteTo.File(logFile); + } + Log.Logger = config.CreateLogger(); } private static void LogException(Exception exception) { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/Cargo.toml b/Source/DafnyRuntime/DafnyRuntimeRust/Cargo.toml index 08fbd06ff..3ddcbab78 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/Cargo.toml +++ b/Source/DafnyRuntime/DafnyRuntimeRust/Cargo.toml @@ -8,4 +8,4 @@ once_cell = "1.18.0" paste = "1.0" num = "0.4" itertools = "0.11.0" -as-any = "0.3.1" +as-any = "0.3.1" \ No newline at end of file diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index 9b15c8e0f..9a0b03553 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -1,35 +1,45 @@ #[cfg(test)] mod tests; -use std::{any::Any, borrow::Borrow, cell::{RefCell, UnsafeCell}, cmp::Ordering, collections::{HashMap, HashSet}, fmt::{Debug, Display, Formatter}, hash::{Hash, Hasher}, ops::{Add, Deref, Div, Mul, Neg, Rem, Sub}, rc::Rc}; -use num::{bigint::ParseBigIntError, Integer, Num, One, Signed, ToPrimitive}; - +pub use mem::MaybeUninit; +use num::{bigint::ParseBigIntError, Integer, Num, One, Signed}; pub use once_cell::unsync::Lazy; +use std::{ + any::Any, + borrow::Borrow, + cell::{RefCell, UnsafeCell}, + cmp::Ordering, + collections::{HashMap, HashSet}, + fmt::{Debug, Display, Formatter}, + hash::{Hash, Hasher}, + mem, + ops::{Add, Deref, Div, Mul, Neg, Rem, Sub}, + rc::Rc, +}; +pub use itertools; pub use num::bigint::BigInt; pub use num::rational::BigRational; pub use num::FromPrimitive; pub use num::NumCast; +pub use num::ToPrimitive; pub use num::Zero; -pub use itertools; +pub use std::convert::Into; // An atomic box is just a RefCell in Rust pub type SizeT = usize; -// Dafny types must be clonable in constant time -pub trait DafnyType: Clone + DafnyPrint + Debug {} +pub trait DafnyType: Clone + DafnyPrint + 'static {} + +impl DafnyType for T where T: Clone + DafnyPrint + 'static {} pub trait DafnyTypeEq: DafnyType + Hash + Eq {} -/****************************************************************************** - * Sequences - ******************************************************************************/ +impl DafnyTypeEq for T where T: DafnyType + Hash + Eq {} -// Three elements -// ArraySequence(var isString: bool, nodeCount: SizeT, immutable_array) -// ConcatSequence(var isString: bool, nodeCount: SizeT, left: Sequence, right: Sequence) -// LazySequence(length: BigInteger, box: RefCell>>) -// We use the named version using {...}, and use snake_case format +// Dafny's type (0) compiles to NontrivialDefault to prevent subset types from being considered as Default if their witness is nonzero +pub trait NontrivialDefault { + fn nontrivial_default() -> Self; +} -// The T must be either a *const T (allocated) OR a Reference Counting (immutable) pub mod dafny_runtime_conversions { use crate::DafnyType; use crate::DafnyTypeEq; @@ -39,26 +49,58 @@ pub mod dafny_runtime_conversions { pub type DafnySet = crate::Set; pub type DafnyMultiset = crate::Multiset; 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; use std::collections::HashMap; use std::collections::HashSet; - use std::rc::Rc; 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) + } + + // 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_vec2(ptr: DafnyArray2) -> Vec> { + Box::from_raw(ptr).to_vec2() + } pub fn dafny_int_to_bigint(i: &DafnyInt) -> BigInt { i.data.as_ref().clone() } pub fn bigint_to_dafny_int(i: &BigInt) -> DafnyInt { - DafnyInt{data: Rc::new(i.clone())} + DafnyInt { + data: Rc::new(i.clone()), + } } - pub fn dafny_sequence_to_vec( - s: &DafnySequence, - elem_converter: fn(&T) -> X) -> Vec - where T: DafnyType + pub fn dafny_sequence_to_vec(s: &DafnySequence, elem_converter: fn(&T) -> X) -> Vec + where + T: DafnyType, { let mut array: Vec = Vec::with_capacity(s.cardinality_usize()); DafnySequence::::append_recursive(&mut array, s); @@ -66,9 +108,12 @@ pub mod dafny_runtime_conversions { } // Used for external conversions - pub fn vec_to_dafny_sequence(array: &Vec, elem_converter: fn(&X) -> T) - -> DafnySequence - where T: DafnyType + pub fn vec_to_dafny_sequence( + array: &Vec, + elem_converter: fn(&X) -> T, + ) -> DafnySequence + where + T: DafnyType, { let mut result: Vec = Vec::with_capacity(array.len()); for elem in array.iter() { @@ -76,20 +121,31 @@ pub mod dafny_runtime_conversions { } DafnySequence::::from_array_owned(result) } - - pub fn dafny_map_to_hashmap(m: &DafnyMap, converter_k: fn(&K)->K2, converter_v: fn(&V)->V2) -> HashMap - where - K: DafnyTypeEq, V: DafnyTypeEq, - K2: Eq + Hash, V2: Clone + + pub fn dafny_map_to_hashmap( + m: &DafnyMap, + converter_k: fn(&K) -> K2, + converter_v: fn(&V) -> V2, + ) -> HashMap + where + K: DafnyTypeEq, + V: DafnyTypeEq, + K2: Eq + Hash, + V2: Clone, { m.to_hashmap_owned(converter_k, converter_v) } - pub fn hashmap_to_dafny_map(map: &HashMap, converter_k: fn(&K2)->K, converter_v: fn(&V2)->V) - -> DafnyMap - where - K: DafnyTypeEq, V: DafnyTypeEq, - K2: Eq + Hash, V2: Clone + pub fn hashmap_to_dafny_map( + map: &HashMap, + converter_k: fn(&K2) -> K, + converter_v: fn(&V2) -> V, + ) -> DafnyMap + where + K: DafnyTypeEq, + V: DafnyTypeEq, + K2: Eq + Hash, + V2: Clone, { DafnyMap::::from_hashmap(map, converter_k, converter_v) } @@ -109,7 +165,7 @@ pub mod dafny_runtime_conversions { characters.iter().map(|v| v.0).collect::() } } - + // --unicode-chars:false pub mod unicode_chars_false { use crate::Sequence; @@ -121,18 +177,26 @@ pub mod dafny_runtime_conversions { Sequence::from_array_owned(s.encode_utf16().map(|v| crate::DafnyCharUTF16(v)).collect()) } pub fn dafny_string_to_string(s: &DafnyString) -> String { - let characters = s.to_array().as_ref().iter().map(|v| v.0).collect::>(); + let characters = s + .to_array() + .as_ref() + .iter() + .map(|v| v.0) + .collect::>(); String::from_utf16_lossy(&characters) } } - - pub fn set_to_dafny_set(set: &HashSet, converter: fn(&U) -> T) - -> DafnySet - { + + pub fn set_to_dafny_set( + set: &HashSet, + converter: fn(&U) -> T, + ) -> DafnySet { DafnySet::from_iterator(set.iter().map(converter)) } pub fn dafny_set_to_set(set: &DafnySet, converter: fn(&T) -> U) -> HashSet - where T: DafnyTypeEq, U: Clone + Eq + Hash + where + T: DafnyTypeEq, + U: Clone + Eq + Hash, { let mut result: HashSet = HashSet::new(); for s in set.data.iter() { @@ -141,8 +205,13 @@ pub mod dafny_runtime_conversions { result } - pub fn dafny_multiset_to_owned_vec(ms: &DafnyMultiset, converter: fn(&T) -> U) -> Vec - where T: DafnyTypeEq, U: Clone + Eq + pub fn dafny_multiset_to_owned_vec( + ms: &DafnyMultiset, + converter: fn(&T) -> U, + ) -> Vec + where + T: DafnyTypeEq, + U: Clone + Eq, { let mut result: Vec = Vec::new(); for s in ms.data.iter() { @@ -155,16 +224,14 @@ pub mod dafny_runtime_conversions { } pub fn vec_to_dafny_multiset(vec: &Vec, converter: fn(&U) -> T) -> DafnyMultiset - where T: DafnyTypeEq, U: Clone + Eq + Hash + where + T: DafnyTypeEq, + U: Clone + Eq + Hash, { - DafnyMultiset::from_iterator( - vec.into_iter().map(|u: &U| converter(u)) - ) + DafnyMultiset::from_iterator(vec.into_iter().map(|u: &U| converter(u))) } - } - // ************** // Dafny integers // ************** @@ -172,7 +239,82 @@ pub mod dafny_runtime_conversions { // Zero-cost abstraction over a Rc #[derive(Clone)] pub struct DafnyInt { - data: Rc + data: Rc, +} + +impl DafnyInt { + pub fn new(data: Rc) -> DafnyInt { + DafnyInt { data } + } + pub fn as_usize(&self) -> usize { + self.to_usize().unwrap() + } +} + +impl AsRef for DafnyInt { + fn as_ref(&self) -> &BigInt { + &self.data + } +} + +// truncate_u(x, u64) +// = ::to_u128(&x).unwrap() as u64; +#[macro_export] +macro_rules! truncate { + ($x:expr, $t:ty) => { + <$crate::DafnyInt as $crate::Into<$t>>::into($x) + }; +} + +impl Into for DafnyInt { + fn into(self) -> u8 { + self.data.to_u8().unwrap() + } +} +impl Into for DafnyInt { + fn into(self) -> u16 { + self.data.to_u16().unwrap() + } +} +impl Into for DafnyInt { + fn into(self) -> u32 { + self.data.to_u32().unwrap() + } +} +impl Into for DafnyInt { + fn into(self) -> u64 { + self.data.to_u64().unwrap() + } +} +impl Into for DafnyInt { + fn into(self) -> u128 { + self.data.to_u128().unwrap() + } +} +impl Into for DafnyInt { + fn into(self) -> i8 { + self.data.to_i8().unwrap() + } +} +impl Into for DafnyInt { + fn into(self) -> i16 { + self.data.to_i16().unwrap() + } +} +impl Into for DafnyInt { + fn into(self) -> i32 { + self.data.to_i32().unwrap() + } +} +impl Into for DafnyInt { + fn into(self) -> i64 { + self.data.to_i64().unwrap() + } +} +impl Into for DafnyInt { + fn into(self) -> i128 { + self.data.to_i128().unwrap() + } } impl ToPrimitive for DafnyInt { @@ -183,14 +325,26 @@ impl ToPrimitive for DafnyInt { fn to_u64(&self) -> Option { self.data.to_u64() } -} -impl DafnyType for DafnyInt {} -impl DafnyTypeEq for DafnyInt {} + // Override of functions + fn to_u128(&self) -> Option { + self.data.to_u128() + } + + fn to_i128(&self) -> Option { + self.data.to_i128() + } +} impl Default for DafnyInt { fn default() -> Self { - DafnyInt{data: Rc::new(BigInt::zero())} + DafnyInt::new(Rc::new(BigInt::zero())) + } +} + +impl NontrivialDefault for DafnyInt { + fn nontrivial_default() -> Self { + Self::default() } } @@ -212,7 +366,7 @@ impl DafnyPrint for DafnyInt { } } -impl Debug for DafnyInt { +impl ::std::fmt::Debug for DafnyInt { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.data) } @@ -222,7 +376,9 @@ impl Add for DafnyInt { type Output = DafnyInt; fn add(self, rhs: DafnyInt) -> Self::Output { - DafnyInt{data: Rc::new(self.data.as_ref() + rhs.data.as_ref())} + DafnyInt { + data: Rc::new(self.data.as_ref() + rhs.data.as_ref()), + } } } @@ -230,7 +386,9 @@ impl Mul for DafnyInt { type Output = DafnyInt; fn mul(self, rhs: DafnyInt) -> Self::Output { - DafnyInt{data: Rc::new(self.data.as_ref() * rhs.data.as_ref())} + DafnyInt { + data: Rc::new(self.data.as_ref() * rhs.data.as_ref()), + } } } @@ -238,7 +396,9 @@ impl Div for DafnyInt { type Output = DafnyInt; fn div(self, rhs: DafnyInt) -> Self::Output { - DafnyInt{data: Rc::new(self.data.as_ref() / rhs.data.as_ref())} + DafnyInt { + data: Rc::new(self.data.as_ref() / rhs.data.as_ref()), + } } } @@ -246,14 +406,18 @@ impl Sub for DafnyInt { type Output = DafnyInt; fn sub(self, rhs: DafnyInt) -> Self::Output { - DafnyInt{data: Rc::new(self.data.as_ref() - rhs.data.as_ref())} + DafnyInt { + data: Rc::new(self.data.as_ref() - rhs.data.as_ref()), + } } } impl Rem for DafnyInt { type Output = DafnyInt; fn rem(self, rhs: DafnyInt) -> Self::Output { - DafnyInt{data: Rc::new(self.data.as_ref() % rhs.data.as_ref())} + DafnyInt { + data: Rc::new(self.data.as_ref() % rhs.data.as_ref()), + } } } impl Neg for DafnyInt { @@ -261,13 +425,17 @@ impl Neg for DafnyInt { #[inline] fn neg(self) -> Self::Output { - DafnyInt{data: Rc::new(-self.data.as_ref())} + DafnyInt { + data: Rc::new(-self.data.as_ref()), + } } } impl Zero for DafnyInt { #[inline] fn zero() -> Self { - DafnyInt{data: Rc::new(BigInt::zero())} + DafnyInt { + data: Rc::new(BigInt::zero()), + } } #[inline] fn is_zero(&self) -> bool { @@ -277,7 +445,9 @@ impl Zero for DafnyInt { impl One for DafnyInt { #[inline] fn one() -> Self { - DafnyInt{data: Rc::new(BigInt::one())} + DafnyInt { + data: Rc::new(BigInt::one()), + } } } impl Num for DafnyInt { @@ -285,7 +455,9 @@ impl Num for DafnyInt { #[inline] fn from_str_radix(s: &str, radix: u32) -> Result { - Ok(DafnyInt{data: Rc::new(BigInt::from_str_radix(s, radix)?)}) + Ok(DafnyInt { + data: Rc::new(BigInt::from_str_radix(s, radix)?), + }) } } impl Ord for DafnyInt { @@ -297,17 +469,23 @@ impl Ord for DafnyInt { impl Signed for DafnyInt { #[inline] fn abs(&self) -> Self { - DafnyInt{data: Rc::new(self.data.as_ref().abs())} + DafnyInt { + data: Rc::new(self.data.as_ref().abs()), + } } #[inline] fn abs_sub(&self, other: &Self) -> Self { - DafnyInt{data: Rc::new(self.data.as_ref().abs_sub(other.data.as_ref()))} + DafnyInt { + data: Rc::new(self.data.as_ref().abs_sub(other.data.as_ref())), + } } #[inline] fn signum(&self) -> Self { - DafnyInt{data: Rc::new(self.data.as_ref().signum())} + DafnyInt { + data: Rc::new(self.data.as_ref().signum()), + } } #[inline] @@ -332,23 +510,30 @@ impl PartialOrd for DafnyInt { impl DafnyInt { #[inline] pub fn parse_bytes(number: &[u8], radix: u32) -> DafnyInt { - DafnyInt{data: ::std::rc::Rc::new(BigInt::parse_bytes(number, radix).unwrap())} + DafnyInt { + data: ::std::rc::Rc::new(BigInt::parse_bytes(number, radix).unwrap()), + } } pub fn from_usize(usize: usize) -> DafnyInt { - DafnyInt{data: Rc::new(BigInt::from(usize))} + DafnyInt { + data: Rc::new(BigInt::from(usize)), + } } pub fn from_i32(i: i32) -> DafnyInt { - DafnyInt{data: Rc::new(BigInt::from(i))} + DafnyInt { + data: Rc::new(BigInt::from(i)), + } } } -macro_rules! impl_dafnyint_from{ +macro_rules! impl_dafnyint_from { () => {}; ($type:ident) => { - impl From<$type> for DafnyInt - { + impl From<$type> for DafnyInt { fn from(n: $type) -> Self { - DafnyInt{data: Rc::new(n.into())} + DafnyInt { + data: Rc::new(n.into()), + } } } }; @@ -366,22 +551,45 @@ impl_dafnyint_from! { i64 } impl_dafnyint_from! { i128 } impl_dafnyint_from! { usize } -impl <'a> From<&'a [u8]> for DafnyInt { +impl<'a> From<&'a [u8]> for DafnyInt { fn from(number: &[u8]) -> Self { DafnyInt::parse_bytes(number, 10) } } +// Now the same but for &[u8, N] for any kind of such references +impl<'a, const N: usize> From<&'a [u8; N]> for DafnyInt { + fn from(number: &[u8; N]) -> Self { + DafnyInt::parse_bytes(number, 10) + } +} + +impl From for DafnyInt { + fn from(c: char) -> Self { + let cu32: u32 = c.into(); + int!(cu32) + } +} + +impl From for DafnyInt { + fn from(c: DafnyChar) -> Self { + int!(c.0) + } +} + +impl From for DafnyInt { + fn from(c: DafnyCharUTF16) -> Self { + int!(c.0) + } +} + // ************** // Immutable sequences // ************** -impl DafnyType for Sequence {} -impl DafnyTypeEq for Sequence {} -impl Eq for Sequence {} +impl Eq for Sequence {} -impl Add<&Sequence> for &Sequence -{ +impl Add<&Sequence> for &Sequence { type Output = Sequence; fn add(self, rhs: &Sequence) -> Self::Output { @@ -389,7 +597,7 @@ impl Add<&Sequence> for &Sequence } } -impl Hash for Sequence { +impl Hash for Sequence { fn hash(&self, state: &mut H) { self.cardinality_usize().hash(state); let array = self.to_array(); @@ -403,10 +611,11 @@ impl Hash for Sequence { // Clone can be derived automatically #[derive(Clone)] pub enum Sequence - where T: DafnyType, +where + T: DafnyType, { ArraySequence { - // Values could be a native array because we will know statically that all + // Values could be a native array because we will know statically that all // accesses are in bounds when using this data structure values: Rc>, }, @@ -414,30 +623,32 @@ pub enum Sequence left: Rc>>, right: Rc>>, length: SizeT, - boxed: Rc>>>> - } + boxed: Rc>>>>, + }, } -impl Sequence -where T: DafnyType { +impl Sequence +where + T: DafnyType, +{ pub fn from_array(values: &Vec) -> Sequence { Sequence::ArraySequence { - values: Rc::new(values.clone()) + values: Rc::new(values.clone()), } } pub fn from_array_slice(values: &Vec, start: &DafnyInt, end: &DafnyInt) -> Sequence { Sequence::ArraySequence { - values: Rc::new(values[start.to_usize().unwrap()..end.to_usize().unwrap()].to_vec()) + values: Rc::new(values[start.to_usize().unwrap()..end.to_usize().unwrap()].to_vec()), } } pub fn from_array_take(values: &Vec, n: &DafnyInt) -> Sequence { Sequence::ArraySequence { - values: Rc::new(values[..n.to_usize().unwrap()].to_vec()) + values: Rc::new(values[..n.to_usize().unwrap()].to_vec()), } } pub fn from_array_drop(values: &Vec, n: &DafnyInt) -> Sequence { Sequence::ArraySequence { - values: Rc::new(values[n.to_usize().unwrap()..].to_vec()) + values: Rc::new(values[n.to_usize().unwrap()..].to_vec()), } } pub fn from_array_owned(values: Vec) -> Sequence { @@ -457,12 +668,19 @@ where T: DafnyType { // Let's convert the if then else below to a proper match statement match self { Sequence::ArraySequence { values, .. } => - // The length of the elements - Rc::clone(values), - Sequence::ConcatSequence { length, boxed, left, right } => { - let clone_boxed = boxed.as_ref().clone(); - let clone_boxed_borrowed = clone_boxed.borrow(); - let borrowed: Option<&Rc>> = clone_boxed_borrowed.as_ref(); + // The length of the elements + { + Rc::clone(values) + } + Sequence::ConcatSequence { + length, + boxed, + left, + right, + } => { + let into_boxed = boxed.as_ref().clone(); + let into_boxed_borrowed = into_boxed.borrow(); + let borrowed: Option<&Rc>> = into_boxed_borrowed.as_ref(); if let Some(cache) = borrowed.as_ref() { return Rc::clone(cache); } @@ -474,6 +692,7 @@ where T: DafnyType { let mut cache = boxed.borrow_mut(); let mutable_left: *mut Sequence = left.get(); let mutable_right: *mut Sequence = right.get(); + // safety: Once the array is computed, left and right won't ever be read again. unsafe { *mutable_left = seq!() }; unsafe { *mutable_right = seq!() }; *cache = Some(result.clone()); @@ -485,25 +704,30 @@ where T: DafnyType { pub fn append_recursive(array: &mut Vec, this: &Sequence) { match this { Sequence::ArraySequence { values, .. } => - // The length of the elements - for value in values.iter() { - array.push(value.clone()); - }, - Sequence::ConcatSequence { boxed, left, right, .. } => - // Let's create an array of size length and fill it up recursively - { - let clone_boxed = boxed.as_ref().clone(); - let clone_boxed_borrowed = clone_boxed.borrow(); - let borrowed: Option<&Rc>> = clone_boxed_borrowed.as_ref(); + // The length of the elements + { + for value in values.iter() { + array.push(value.clone()); + } + } + Sequence::ConcatSequence { + boxed, left, right, .. + } => + // Let's create an array of size length and fill it up recursively + { + let into_boxed = boxed.as_ref().clone(); + let into_boxed_borrowed = into_boxed.borrow(); + let borrowed: Option<&Rc>> = into_boxed_borrowed.as_ref(); if let Some(values) = borrowed.as_ref() { for value in values.iter() { array.push(value.clone()); } return; } + // safety: When a concat is initialized, the left and right are well defined Sequence::::append_recursive(array, unsafe { &mut *left.get() }); Sequence::::append_recursive(array, unsafe { &mut *right.get() }); - } + } } } /// Returns the cardinality of this [`Sequence`]. @@ -511,16 +735,17 @@ where T: DafnyType { pub fn cardinality_usize(&self) -> SizeT { match self { Sequence::ArraySequence { values, .. } => - // The length of the elements - values.len(), - Sequence::ConcatSequence { length, .. } => - *length, + // The length of the elements + { + values.len() + } + Sequence::ConcatSequence { length, .. } => *length, } } pub fn cardinality(&self) -> DafnyInt { DafnyInt::from_usize(self.cardinality_usize()) } - pub fn select(&self, index: SizeT) -> T { + pub fn get_usize(&self, index: SizeT) -> T { let array = self.to_array(); array[index].clone() } @@ -540,7 +765,7 @@ where T: DafnyType { let start_index = start.data.as_ref().to_usize().unwrap(); let new_data = Sequence::from_array_owned(self.to_array()[start_index..].to_vec()); new_data - } + } pub fn update_index(&self, index: &DafnyInt, value: &T) -> Self { let mut result = self.to_array().as_ref().clone(); @@ -553,7 +778,30 @@ where T: DafnyType { } pub fn get(&self, index: &DafnyInt) -> T { - self.select(index.data.to_usize().unwrap()) + self.get_usize(index.data.to_usize().unwrap()) + } + pub fn iter(&self) -> SequenceIter { + SequenceIter { + array: self.to_array(), + index: 0, + } + } +} + +pub struct SequenceIter { + array: Rc>, + index: SizeT, +} +impl Iterator for SequenceIter { + type Item = T; + fn next(&mut self) -> Option { + if self.index < self.array.len() { + let result = self.array[self.index].clone(); + self.index += 1; + Some(result) + } else { + None + } } } @@ -562,27 +810,33 @@ impl Default for Sequence { Sequence::from_array_owned(vec![]) } } +impl NontrivialDefault for Sequence { + fn nontrivial_default() -> Self { + Self::default() + } +} -impl Sequence { +impl Sequence { pub fn as_dafny_multiset(&self) -> Multiset { Multiset::from_array(&self.to_array()) } } // Makes it possible to write iterator.collect::> and obtain a sequence -impl FromIterator for Sequence { +impl FromIterator for Sequence { fn from_iter>(iter: I) -> Self { Sequence::from_array_owned(iter.into_iter().collect()) } } -impl Sequence { +impl Sequence { pub fn contains(&self, value: &T) -> bool { self.to_array().contains(value) } } -impl PartialEq> for Sequence - where T: DafnyTypeEq +impl PartialEq> for Sequence +where + T: DafnyTypeEq, { fn eq(&self, other: &Sequence) -> bool { // Iterate through both elements and verify that they are equal @@ -592,7 +846,7 @@ impl PartialEq> for Sequence } let mut i: usize = 0; for value in values.iter() { - if value != &other.select(i) { + if value != &other.get_usize(i) { return false; } i += 1; @@ -601,24 +855,28 @@ impl PartialEq> for Sequence } } -impl PartialOrd for Sequence { +impl PartialOrd for Sequence { fn partial_cmp(&self, other: &Sequence) -> Option { // Comparison is only prefix-based match self.cardinality_usize().cmp(&other.cardinality_usize()) { Ordering::Equal => { - if self == other { Some(Ordering::Equal) } else { None } - }, + if self == other { + Some(Ordering::Equal) + } else { + None + } + } Ordering::Less => { for i in 0..self.cardinality_usize() { - if self.select(i) != other.select(i) { + if self.get_usize(i) != other.get_usize(i) { return None; } } Some(Ordering::Less) - }, + } Ordering::Greater => { for i in 0..other.cardinality_usize() { - if self.select(i) != other.select(i) { + if self.get_usize(i) != other.get_usize(i) { return None; } } @@ -628,29 +886,28 @@ impl PartialOrd for Sequence { } } -impl DafnyPrint for Sequence -{ +impl DafnyPrint for Sequence { fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { if !V::is_char() { write!(f, "[")?; } - let mut first = true; - for value in self.to_array().iter() { - if !first && !V::is_char() { - write!(f, ", ")?; - } - first = false; - value.fmt_print(f, true)?; - } - if !V::is_char() { - write!(f, "]") - } else { - write!(f, "") - } + let mut first = true; + for value in self.to_array().iter() { + if !first && !V::is_char() { + write!(f, ", ")?; + } + first = false; + value.fmt_print(f, true)?; + } + if !V::is_char() { + write!(f, "]") + } else { + write!(f, "") + } } } -impl Debug for Sequence { +impl Debug for Sequence { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { self.fmt_print(f, false) } @@ -662,20 +919,37 @@ impl Debug for Sequence { #[derive(Clone)] pub struct Map - where K: DafnyTypeEq, V: DafnyTypeEq +where + K: DafnyTypeEq, + V: DafnyTypeEq, { - data: Rc> + data: Rc>, } -impl Hash for Map -{ +impl Default for Map { + fn default() -> Self { + Map { + data: Rc::new(HashMap::new()), + } + } +} + +impl NontrivialDefault for Map { + fn nontrivial_default() -> Self { + Self::default() + } +} + +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 } } -impl PartialEq> for Map - where K: DafnyTypeEq, V: DafnyTypeEq +impl PartialEq> for Map +where + K: DafnyTypeEq, + V: DafnyTypeEq, { fn eq(&self, other: &Map) -> bool { if self.data.len() != other.data.len() { @@ -690,40 +964,40 @@ impl PartialEq> for Map } } -impl DafnyType for (K, V) {} -impl DafnyTypeEq for (K, V) {} +impl Eq for Map {} -impl DafnyType for Map {} -impl DafnyTypeEq for Map {} - -impl Eq for Map { -} - -impl Map -{ +impl Map { pub fn new_empty() -> Map { Map { - data: Rc::new(HashMap::new()) + data: Rc::new(HashMap::new()), } } pub fn from_array(values: &Vec<(K, V)>) -> Map { - Self::from_iterator(values.iter().map(|(k, v)| - (k.clone(), v.clone()))) + Self::from_iterator(values.iter().map(|(k, v)| (k.clone(), v.clone()))) } pub fn from_iterator(data: I) -> Map - where I: Iterator + where + I: Iterator, { let mut result: HashMap = HashMap::new(); for (k, v) in data { result.insert(k, v); - } - Self::from_hashmap_owned(result) + } + Self::from_hashmap_owned(result) } pub fn from_hashmap_owned(values: HashMap) -> Map { - Map { data: Rc::new(values) } + Map { + data: Rc::new(values), + } } - pub fn to_hashmap_owned(&self, converter_k: fn(&K)->K2, converter_v: fn(&V)->V2) -> HashMap - where K2: Eq + std::hash::Hash, V2: Clone + pub fn to_hashmap_owned( + &self, + converter_k: fn(&K) -> K2, + converter_v: fn(&V) -> V2, + ) -> HashMap + where + K2: Eq + std::hash::Hash, + V2: Clone, { let mut result: HashMap = HashMap::new(); for (k, v) in self.data.iter() { @@ -765,7 +1039,7 @@ impl Map } pub fn subtract(&self, keys: &Set) -> Self { if keys.cardinality_usize() == 0 { - return self.clone() + return self.clone(); } let mut result: HashMap = HashMap::new(); for (k, v) in self.data.iter() { @@ -776,18 +1050,23 @@ impl Map Self::from_hashmap_owned(result) } - pub fn from_hashmap(map: &HashMap, converter_k: fn(&K2)->K, converter_v: fn(&V2)->V) - -> Map - where - K: DafnyTypeEq, V: DafnyTypeEq, - K2: Eq + Hash, V2: Clone + pub fn from_hashmap( + map: &HashMap, + converter_k: fn(&K2) -> K, + converter_v: fn(&V2) -> V, + ) -> Map + where + K: DafnyTypeEq, + V: DafnyTypeEq, + K2: Eq + Hash, + V2: Clone, { let mut result: HashMap = HashMap::new(); for (k, v) in map.iter() { result.insert(converter_k(k), converter_v(v)); } Map { - data: Rc::new(result) + data: Rc::new(result), } } pub fn keys(&self) -> Set { @@ -816,26 +1095,38 @@ impl Map result.insert(index, value); Map::from_hashmap_owned(result) } + + pub fn iter_raw(&self) -> std::collections::hash_map::Iter<'_, K, V> { + self.data.iter() + } + + pub fn iter(&self) -> impl Iterator + '_ { + self.data.iter().map(|(k, _v)| k).cloned() + } } -impl Map { +impl Map { pub fn as_dafny_multiset(&self) -> Multiset { Multiset::from_hashmap(&self.data) } } pub struct MapBuilder - where K: Clone + Eq + std::hash::Hash, V: Clone +where + K: Clone + Eq + std::hash::Hash, + V: Clone, { - data: HashMap + data: HashMap, } -impl MapBuilder - where K: DafnyTypeEq, V: DafnyTypeEq +impl MapBuilder +where + K: DafnyTypeEq, + V: DafnyTypeEq, { pub fn new() -> MapBuilder { MapBuilder { - data: HashMap::new() + data: HashMap::new(), } } pub fn add(&mut self, key: &K, value: &V) { @@ -847,29 +1138,31 @@ impl MapBuilder } } -impl DafnyPrint for Map - where K: DafnyTypeEq, V: DafnyTypeEq +impl DafnyPrint for Map +where + K: DafnyTypeEq, + V: DafnyTypeEq, { fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { f.write_str("map[")?; - let mut first = true; - for (k, v) in self.data.iter() { - if !first { - f.write_str(", ")?; - } - first = false; - k.fmt_print(f, in_seq)?; - f.write_str(" := ")?; - v.fmt_print(f, in_seq)?; - } - f.write_str("}") - + let mut first = true; + for (k, v) in self.data.iter() { + if !first { + f.write_str(", ")?; + } + first = false; + k.fmt_print(f, in_seq)?; + f.write_str(" := ")?; + v.fmt_print(f, in_seq)?; + } + f.write_str("]") } } - -impl Debug for Map - where K: DafnyTypeEq, V: DafnyTypeEq +impl Debug for Map +where + K: DafnyTypeEq, + V: DafnyTypeEq, { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { self.fmt_print(f, false) @@ -881,13 +1174,27 @@ impl Debug for Map // ************** #[derive(Clone)] -pub struct Set +pub struct Set { + data: Rc>, +} + +impl Default for Set +where + T: DafnyTypeEq, { - data: Rc> + fn default() -> Self { + Self::new_empty() + } +} +impl NontrivialDefault for Set { + fn nontrivial_default() -> Self { + Self::default() + } } -impl PartialEq> for Set - where V: DafnyTypeEq +impl PartialEq> for Set +where + V: DafnyTypeEq, { fn eq(&self, other: &Set) -> bool { // 1. Same cardinality @@ -910,7 +1217,7 @@ impl PartialEq> for Set } } -impl PartialOrd for Set { +impl PartialOrd for Set { fn partial_cmp(&self, other: &Self) -> Option { // Partial ordering is inclusion if self.cardinality_usize() <= other.cardinality_usize() { @@ -935,7 +1242,7 @@ impl PartialOrd for Set { } } -impl Set { +impl Set { pub fn new_empty() -> Set { Self::from_hashset_owned(HashSet::new()) } @@ -943,7 +1250,8 @@ impl Set { Self::from_iterator(array.iter().map(|v| v.clone())) } pub fn from_iterator(data: I) -> Set - where I: Iterator + where + I: Iterator, { let mut set: HashSet = HashSet::new(); for value in data { @@ -956,13 +1264,9 @@ impl Set { } pub fn from_hashset_owned(hashset: HashSet) -> Set { Set { - data: Rc::new(hashset) + data: Rc::new(hashset), } } -} - -impl Set -{ pub fn cardinality_usize(&self) -> usize { self.data.len() } @@ -998,7 +1302,7 @@ impl Set } // Start with an empty vec with capacity the smallest of both sets let mut result = HashSet::new(); - + // iterate over the other, take only elements in common for value in self.data.iter() { if other.data.contains(value) { @@ -1017,7 +1321,7 @@ impl Set } // Start with a vec the size of the first one let mut result = HashSet::new(); - + // iterate over the other, take only elements not in second for value in self.data.iter() { if !other.contains(value) { @@ -1072,19 +1376,27 @@ impl Set pub fn as_dafny_multiset(&self) -> Multiset { Multiset::from_set(self) } + + pub fn iter(&self) -> std::collections::hash_set::Iter<'_, V> { + self.data.iter() + } + + pub fn peek(&self) -> V { + self.data.iter().next().unwrap().clone() + } } pub struct SetBuilder - where T: Clone + Eq + std::hash::Hash +where + T: Clone + Eq + std::hash::Hash, { - data: HashMap + data: HashMap, } -impl SetBuilder -{ +impl SetBuilder { pub fn new() -> SetBuilder { SetBuilder { - data: HashMap::new() + data: HashMap::new(), } } pub fn add(&mut self, value: &T) { @@ -1097,13 +1409,12 @@ impl SetBuilder for (k, _v) in self.data.iter() { result.push(k.clone()); } - + Set::from_array(&result) } } -impl DafnyPrint for Set -{ +impl DafnyPrint for Set { fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { f.write_str("{")?; let mut first = true; @@ -1118,8 +1429,9 @@ impl DafnyPrint for Set } } -impl Debug for Set - where V: DafnyTypeEq +impl Debug for Set +where + V: DafnyTypeEq, { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { self.fmt_print(f, false) @@ -1131,16 +1443,14 @@ impl Debug for Set // ******************* #[derive(Clone)] -pub struct Multiset -{ +pub struct Multiset { pub data: HashMap, - pub size: DafnyInt + pub size: DafnyInt, } -impl Multiset -{ +impl Multiset { pub fn new_empty() -> Multiset { - Self::from_array(&vec!()) + Self::from_array(&vec![]) } pub fn get_total(map: &HashMap) -> DafnyInt { let mut total = DafnyInt::zero(); @@ -1149,20 +1459,21 @@ impl Multiset } total } - pub fn from_hashmap_owned(map: HashMap) -> Multiset{ + pub fn from_hashmap_owned(map: HashMap) -> Multiset { Multiset { size: Self::get_total(&map), - data: map + data: map, } } - pub fn from_hashmap(map: &HashMap) -> Multiset{ + pub fn from_hashmap(map: &HashMap) -> Multiset { Self::from_hashmap_owned(map.clone()) } pub fn from_array(data: &Vec) -> Multiset { Self::from_iterator(data.iter().map(|x| x.clone())) } pub fn from_iterator(data: I) -> Multiset - where I: Iterator + where + I: Iterator, { let mut hashmap: HashMap = HashMap::new(); let mut total: DafnyInt = DafnyInt::zero(); @@ -1173,7 +1484,7 @@ impl Multiset } Multiset { data: hashmap, - size: total + size: total, } } pub fn from_set(set: &Set) -> Multiset { @@ -1212,7 +1523,7 @@ impl Multiset return self.clone(); } if self.size.is_zero() { - return other.clone() + return other.clone(); } let mut result = self.data.clone(); for (k, v) in other.data.iter() { @@ -1220,14 +1531,17 @@ impl Multiset let new_count = old_count.clone() + v.clone(); result.insert(k.clone(), new_count); } - Multiset { data: result, size: self.size.clone() + other.size.clone() } + Multiset { + data: result, + size: self.size.clone() + other.size.clone(), + } } pub fn intersect(&self, other: &Multiset) -> Multiset { if other.size.is_zero() { - return other.clone() + return other.clone(); } if self.size.is_zero() { - return self.clone() + return self.clone(); } let mut result = HashMap::::new(); let mut total = DafnyInt::zero(); @@ -1243,7 +1557,10 @@ impl Multiset total = total + resulting_count; } } - Multiset { data: result, size: total } + Multiset { + data: result, + size: total, + } } pub fn subtract(&self, other: &Multiset) -> Multiset { if other.size.is_zero() { @@ -1265,7 +1582,10 @@ impl Multiset result.insert(k.clone(), new_count); } } - Multiset { data: result, size: total } + Multiset { + data: result, + size: total, + } } pub fn disjoint(&self, other: &Multiset) -> bool { for value in other.data.keys() { @@ -1279,12 +1599,35 @@ impl Multiset pub fn as_dafny_multiset(&self) -> Multiset { self.clone() } + + pub fn peek(&self) -> V { + self.data.iter().next().unwrap().0.clone() + } + + pub fn iter_raw(&self) -> std::collections::hash_map::Iter<'_, V, DafnyInt> { + self.data.iter() + } + + pub fn iter(&self) -> impl Iterator + '_ { + self.data.iter().map(|(k, _v)| k).cloned() + } } -impl DafnyType for Multiset {} -impl DafnyTypeEq for Multiset {} +impl Default for Multiset +where + T: DafnyTypeEq, +{ + fn default() -> Self { + Self::new_empty() + } +} +impl NontrivialDefault for Multiset { + fn nontrivial_default() -> Self { + Self::default() + } +} -impl PartialOrd> for Multiset { +impl PartialOrd> for Multiset { fn partial_cmp(&self, other: &Multiset) -> Option { match self.cardinality().cmp(&other.cardinality()) { Ordering::Less => { @@ -1302,7 +1645,7 @@ impl PartialOrd> for Multiset { } } Some(Ordering::Equal) - }, + } Ordering::Greater => { for value in self.data.keys() { if !other.contains(value) || self.get(value) < other.get(value) { @@ -1315,7 +1658,7 @@ impl PartialOrd> for Multiset { } } -impl DafnyPrint for Multiset { +impl DafnyPrint for Multiset { fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { f.write_str("multiset{")?; let mut first = true; @@ -1332,16 +1675,16 @@ impl DafnyPrint for Multiset { } } - -impl Debug for Multiset - where V: DafnyTypeEq +impl Debug for Multiset +where + V: DafnyTypeEq, { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { self.fmt_print(f, false) } } -impl PartialEq> for Multiset { +impl PartialEq> for Multiset { fn eq(&self, other: &Multiset) -> bool { if self.cardinality() != other.cardinality() { return false; @@ -1355,71 +1698,32 @@ impl PartialEq> for Multiset { true } } -impl Eq for Multiset {} -impl Hash for Multiset { +impl Eq for Multiset {} +impl Hash for Multiset { fn hash(&self, state: &mut H) { self.cardinality().hash(state); } } -// Generic function to allocate and return a raw pointer immediately -#[inline] -pub fn allocate(value: Box) -> *const T { - Box::into_raw(value) -} - -// Generic function to safely deallocate a raw pointer -#[inline] -pub fn deallocate(pointer: *const T) { - 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); - } -} // Define the AsAny trait pub trait AsAny { - fn as_any(&self) -> &dyn Any; -} -pub fn is_instance_of(theobject: *const C) -> bool { - unsafe { &*theobject }.as_any().downcast_ref::().is_some() -} -pub trait DafnyUpdowncast { - fn updowncast(&self) -> U; - fn is_instance_of(&self) -> bool; + fn as_any(&self) -> &dyn Any; + fn as_any_mut(&mut self) -> &mut dyn Any; } -/*impl DafnyUpdowncast<*const U> for T -{ - fn updowncast(&self) -> *const U { - self.as_any().downcast_ref::().unwrap() - } - - fn is_instance_of(&self) -> bool { - is_instance_of::(self) - //self.as_any().downcast_ref::().is_some() - } -}*/ -impl DafnyUpdowncast<*const U> for *const T -{ - fn updowncast(&self) -> *const U { - unsafe { &**self }.as_any().downcast_ref::().unwrap() +impl AsAny for dyn Any { + fn as_any(&self) -> &dyn Any { + self } - - fn is_instance_of(&self) -> bool { - is_instance_of::(*self) - //self.as_any().downcast_ref::().is_some() + fn as_any_mut(&mut self) -> &mut dyn Any { + self } } -impl DafnyUpdowncast<*const U> for Rc -{ - fn updowncast(&self) -> *const U { - self.as_any().downcast_ref::().unwrap() - } - - fn is_instance_of(&self) -> bool { - is_instance_of::(self.as_ref()) - //self.as_any().downcast_ref::().is_some() - } +pub fn is_instance_of(theobject: *const C) -> bool { + // safety: Dafny won't call this function unless it can guarantee the object is still allocated + unsafe { &*theobject } + .as_any() + .downcast_ref::() + .is_some() } pub fn dafny_rational_to_int(r: &BigRational) -> BigInt { @@ -1428,11 +1732,9 @@ pub fn dafny_rational_to_int(r: &BigRational) -> BigInt { pub fn nullable_referential_equality(left: Option>, right: Option>) -> bool { match (left, right) { - (Some(l), Some(r)) => { - Rc::ptr_eq(&l, &r) - } + (Some(l), Some(r)) => Rc::ptr_eq(&l, &r), (None, None) => true, - _ => false + _ => false, } } @@ -1475,10 +1777,10 @@ pub struct IntegerRange + One + Ord + Clone> { current: A, } -impl + One + Ord + Clone> Iterator for IntegerRange { +impl + One + Ord + Clone> Iterator for IntegerRange { type Item = A; - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.current < self.hi { let result = self.current.clone(); self.current = self.current.clone() + One::one(); @@ -1489,54 +1791,141 @@ impl + One + Ord + Clone> Iterator for IntegerRange { } } -pub fn integer_range + One + Ord + Clone>(low: A, hi: A) -> impl Iterator { - IntegerRange { - hi, - current: low - } +pub fn integer_range + One + Ord + Clone>( + low: A, + hi: A, +) -> impl Iterator { + IntegerRange { hi, current: low } } -pub struct LazyFieldWrapper(pub Lazy A>>); +pub struct IntegerRangeDown + One + Ord + Clone> { + current: A, + low: A, +} -impl PartialEq for LazyFieldWrapper { - fn eq(&self, other: &Self) -> bool { - self.0.deref() == other.0.deref() +impl + One + Ord + Clone> Iterator for IntegerRangeDown { + type Item = A; + + fn next(&mut self) -> Option { + if self.current > self.low { + self.current = self.current.clone() - One::one(); + Some(self.current.clone()) + } else { + None + } } } -impl Default for LazyFieldWrapper { - fn default() -> Self { - Self(Lazy::new(Box::new(A::default))) - } +pub fn integer_range_down + One + Ord + Clone>( + hi: A, + low: A, +) -> impl Iterator { + IntegerRangeDown { current: hi, low } } -impl DafnyPrint for LazyFieldWrapper { - fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { - self.0.deref().fmt_print(f, in_seq) - } +// Unbounded versions + +pub struct IntegerRangeUnbounded + One + Clone> { + current: A, } +impl + One + Clone> Iterator for IntegerRangeUnbounded { + type Item = A; -pub struct FunctionWrapper(pub A); -impl DafnyPrint for FunctionWrapper { - fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { - write!(f, "") + fn next(&mut self) -> Option { + let result = self.current.clone(); + self.current = self.current.clone() + One::one(); + Some(result) } } +pub fn integer_range_unbounded + One + Clone>( + low: A, +) -> impl Iterator { + IntegerRangeUnbounded { current: low } +} -impl Clone for FunctionWrapper { +pub struct IntegerRangeDownUnbounded + One + Clone> { + current: A, +} + +impl + One + Clone> Iterator for IntegerRangeDownUnbounded { + type Item = A; + + fn next(&mut self) -> Option { + self.current = self.current.clone() - One::one(); + Some(self.current.clone()) + } +} + +pub fn integer_range_down_unbounded + One + Clone>( + hi: A, +) -> impl Iterator { + IntegerRangeDownUnbounded { current: hi } +} + +pub struct LazyFieldWrapper(pub Lazy A>>); + +impl PartialEq for LazyFieldWrapper { + fn eq(&self, other: &Self) -> bool { + self.0.deref() == other.0.deref() + } +} + +impl Default for LazyFieldWrapper { + fn default() -> Self { + Self(Lazy::new(Box::new(A::default))) + } +} + +impl DafnyPrint for LazyFieldWrapper { + fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { + self.0.deref().fmt_print(f, in_seq) + } +} + +// Convert the DafnyPrint above into a macro so that we can create it for functions of any input arity +macro_rules! dafny_print_function { + ($($n:tt)*) => { + impl DafnyPrint for Rc B> { + fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { + write!(f, "") + } + } + } +} +// Now create a loop like impl_tuple_print_loop so that we can create functions up to size 32 +macro_rules! dafny_print_function_loop { + ($first:ident $($rest:ident)*) => { + dafny_print_function_loop! { $($rest)* } + dafny_print_function! { $first $($rest)* } + }; + () => { + } +} +// Emit functions till 32 parameters +dafny_print_function_loop! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 +A17 A18 A19 A20 A21 A22 A23 A24 A25 A26 A27 A28 A29 A30 A31 A32 } + +pub struct FunctionWrapper(pub A); +impl DafnyPrint for FunctionWrapper { + fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { + write!(f, "") + } +} + +impl Clone for FunctionWrapper { fn clone(&self) -> Self { Self(self.0.clone()) } } -impl PartialEq for FunctionWrapper> { +impl PartialEq for FunctionWrapper> { fn eq(&self, other: &Self) -> bool { Rc::ptr_eq(&self.0, &other.0) } } pub struct DafnyPrintWrapper(pub T); -impl Display for DafnyPrintWrapper<&T> { +impl Display for DafnyPrintWrapper<&T> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { self.0.fmt_print(f, false) } @@ -1562,7 +1951,7 @@ pub trait DafnyPrint { } } -impl DafnyPrint for *const T { +impl DafnyPrint for *const T { fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { write!(f, "<{} object>", std::any::type_name::()) } @@ -1575,13 +1964,10 @@ macro_rules! impl_print_display { std::fmt::Display::fmt(&self, f) } } - impl DafnyType for $name {} - impl DafnyTypeEq for $name {} }; } impl_print_display! { String } -impl_print_display! { &str } impl_print_display! { bool } impl_print_display! { u8 } impl_print_display! { u16 } @@ -1619,20 +2005,16 @@ pub type DafnyStringUTF16 = Sequence; impl Default for DafnyCharUTF16 { fn default() -> Self { - Self(0) + Self('a' as u16) } } -impl DafnyType for DafnyCharUTF16 {} -impl DafnyTypeEq for DafnyCharUTF16 {} - - impl DafnyPrint for DafnyCharUTF16 { #[inline] fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { - let real_char = char::decode_utf16(vec!(self.clone()).iter().map(|v| v.0)) - .map(|r| r.map_err(|e| e.unpaired_surrogate())) - .collect::>()[0]; + let real_char = char::decode_utf16(vec![self.clone()].iter().map(|v| v.0)) + .map(|r| r.map_err(|e| e.unpaired_surrogate())) + .collect::>()[0]; let rendered_char = match real_char { Ok(c) => c, Err(e) => { @@ -1653,8 +2035,7 @@ impl DafnyPrint for DafnyCharUTF16 { } } -impl Debug for DafnyCharUTF16 -{ +impl Debug for DafnyCharUTF16 { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { self.fmt_print(f, false) } @@ -1680,9 +2061,13 @@ impl PartialOrd for DafnyCharUTF16 { #[derive(Clone)] pub struct DafnyChar(pub char); +pub type DafnyString = Sequence; -impl DafnyType for DafnyChar {} -impl DafnyTypeEq for DafnyChar {} +impl Default for DafnyChar { + fn default() -> Self { + Self('a') + } +} impl DafnyPrint for DafnyChar { #[inline] @@ -1700,8 +2085,7 @@ impl DafnyPrint for DafnyChar { } } -impl Debug for DafnyChar -{ +impl Debug for DafnyChar { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { self.fmt_print(f, false) } @@ -1725,11 +2109,11 @@ impl Hash for DafnyChar { } } -impl DafnyPrint for Option { +impl DafnyPrint for Option { fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { match self { Some(x) => x.fmt_print(f, false), - None => write!(f, "null") + None => write!(f, "null"), } } } @@ -1813,13 +2197,13 @@ impl DafnyPrint for BigRational { } } -impl DafnyPrint for Rc { +impl DafnyPrint for Rc { fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { self.as_ref().fmt_print(f, in_seq) } } -impl DafnyPrint for Vec { +impl DafnyPrint for Vec { fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { if !T::is_char() { write!(f, "[")?; @@ -1845,13 +2229,13 @@ impl DafnyPrint for Vec { } } -impl DafnyPrint for RefCell { +impl DafnyPrint for RefCell { fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { self.borrow().fmt_print(f, _in_seq) } } -impl DafnyPrint for HashSet { +impl DafnyPrint for HashSet { fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { write!(f, "{{")?; @@ -1878,8 +2262,10 @@ pub fn char_lt(left: char, right: char) -> bool { left_code < right_code } -pub fn string_of(s: &str) -> Sequence { - s.chars().map(|v| DafnyChar(v)).collect::>() +pub fn string_of(s: &str) -> DafnyString { + s.chars() + .map(|v| DafnyChar(v)) + .collect::>() } pub fn string_utf16_of(s: &str) -> DafnyStringUTF16 { @@ -1900,7 +2286,7 @@ macro_rules! impl_tuple_print { write!(f, "(")?; let mut i = 0; - + $( if (i > 0) { write!(f, ", ")?; @@ -1998,6 +2384,750 @@ macro_rules! map { macro_rules! int { ($x:expr) => { $crate::DafnyInt::from($x) + }; +} + +////////// +// Arrays +////////// + +// An 1-dimensional Dafny array is a zero-cost abstraction over a pointer on a native array +#[macro_export] +macro_rules! array { + ($($x:expr), *) => { + array::from_native(Box::new([$($x), *])) + } +} + +pub struct Array2 { + length1: usize, + data: Box<[Box<[T]>]>, +} +impl Array2 { + #[inline] + pub fn length0(&self) -> DafnyInt { + DafnyInt::from(self.length0_usize()) + } + #[inline] + pub fn length0_usize(&self) -> usize { + self.data.len() + } + #[inline] + pub fn length1(&self) -> DafnyInt { + DafnyInt::from(self.length1_usize()) + } + #[inline] + pub fn length1_usize(&self) -> usize { + self.length1 + } + + pub fn placebos_usize(length0: usize, length1: usize) -> *mut Array2> { + Box::into_raw(Box::new(Array2 { + length1: length1, + data: array::initialize_box_usize(length0, { + Rc::new(move |_| array::placebos_box_usize::(length1)) + }), + })) + } + pub fn placebos(length0: &DafnyInt, length1: &DafnyInt) -> *mut Array2> { + Self::placebos_usize(length0.as_usize(), length1.as_usize()) + } + // Once all the elements have been initialized, transform the signature of the pointer + pub fn construct(p: *mut Array2>) -> *mut Array2 { + unsafe { std::mem::transmute(p) } + } + + // Needs to test + pub fn to_vec2(self) -> Vec> { + let mut v = Vec::new(); + for i in 0..self.length0_usize() { + v.push(self.data[i].to_vec()); + } + v + } +} + +pub struct Array3 { + length1: usize, + length2: usize, + data: Box<[Box<[Box<[T]>]>]>, +} +impl Array3 { + #[inline] + pub fn length0(&self) -> DafnyInt { + DafnyInt::from(self.length0_usize()) + } + #[inline] + pub fn length0_usize(&self) -> usize { + self.data.len() + } + #[inline] + pub fn length1(&self) -> DafnyInt { + DafnyInt::from(self.length1_usize()) + } + #[inline] + pub fn length1_usize(&self) -> usize { + self.length1 + } + #[inline] + pub fn length2(&self) -> DafnyInt { + DafnyInt::from(self.length2_usize()) + } + #[inline] + pub fn length2_usize(&self) -> usize { + self.length2 + } + + pub fn placebos_usize( + length0: usize, + length1: usize, + length2: usize, + ) -> *mut Array3> { + Box::into_raw(Box::new(Array3 { + length1: length1, + length2: length2, + data: array::initialize_box_usize(length0, { + Rc::new(move |_| { + array::initialize_box_usize(length1, { + Rc::new(move |_| array::placebos_box_usize::(length2)) + }) + }) + }), + })) + } + pub fn placebos( + length0: &DafnyInt, + length1: &DafnyInt, + length2: &DafnyInt, + ) -> *mut Array3> { + Self::placebos_usize(length0.as_usize(), length1.as_usize(), length2.as_usize()) + } + // Once all the elements have been initialized, transform the signature of the pointer + pub fn construct(p: *mut Array3>) -> *mut Array3 { + unsafe { std::mem::transmute(p) } + } +} + +pub mod array { + use super::DafnyInt; + use num::ToPrimitive; + use std::mem::MaybeUninit; + use std::{boxed::Box, rc::Rc, vec::Vec}; + #[inline] + pub fn from_native(v: Box<[T]>) -> *mut [T] { + Box::into_raw(v) + } + #[inline] + pub fn from_vec(v: Vec) -> *mut [T] { + from_native(v.into_boxed_slice()) + } + pub fn to_vec(v: *mut [T]) -> Vec { + unsafe { Box::from_raw(v) }.into_vec() + } + pub fn initialize_usize(n: usize, initializer: Rc T>) -> *mut [T] { + let mut v = Vec::with_capacity(n); + for i in 0..n { + v.push(initializer(i)); + } + from_vec(v) + } + + pub fn placebos(n: &DafnyInt) -> *mut [MaybeUninit] { + placebos_usize(n.as_usize()) + } + pub fn placebos_usize(n: usize) -> *mut [MaybeUninit] { + Box::into_raw(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] { + unsafe { std::mem::transmute(p) } + } + + pub fn placebos_box(n: &DafnyInt) -> Box<[MaybeUninit]> { + placebos_box_usize(n.to_usize().unwrap()) + } + pub fn placebos_box_usize(n_usize: usize) -> Box<[MaybeUninit]> { + // This code is optimized to take a constant time. See: + // https://users.rust-lang.org/t/allocate-a-boxed-array-of-maybeuninit/110169/7 + std::iter::repeat_with(MaybeUninit::uninit) + .take(n_usize) + .collect() + } + + pub fn initialize(n: &DafnyInt, initializer: Rc T>) -> *mut [T] { + Box::into_raw(initialize_box(n, initializer)) + } + + pub fn initialize_box(n: &DafnyInt, initializer: Rc T>) -> Box<[T]> { + initialize_box_usize(n.to_usize().unwrap(), initializer) + } + pub fn initialize_box_usize( + n_usize: usize, + initializer: Rc T>, + ) -> Box<[T]> { + let mut v = Vec::with_capacity(n_usize); + for i in 0..n_usize { + v.push(initializer(&int!(i))); + } + v.into_boxed_slice() + } + + #[inline] + pub fn length_usize(this: *mut [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 { + int!(length_usize(this)) + } + #[inline] + pub fn get_usize(this: *mut [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() + } + #[inline] + pub fn get(this: *mut [T], i: &DafnyInt) -> T { + get_usize(this, i.to_usize().unwrap()) + } + #[inline] + pub fn update_usize(this: *mut [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; + } + #[inline] + pub fn update(this: *mut [T], i: &DafnyInt, val: T) { + update_usize(this, i.to_usize().unwrap(), val); + } +} + +/////////////////// +// 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 +} +// 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 + 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") + } +} + +impl NontrivialDefault for *mut T { + fn nontrivial_default() -> Self { + 0 as *mut T + } +} +pub struct ExactPool { + current: T, + yielded: bool, +} + +// Implement iterator for an exact pool, yielding +impl Iterator for ExactPool { + type Item = T; + fn next(&mut self) -> Option { + if self.yielded { + None + } else { + self.yielded = true; + Some(self.current.clone()) + } + } +} +pub fn exact_range(value: T) -> ExactPool { + ExactPool { + current: value, + yielded: false, + } +} + +// 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!($raw) + .as_any_mut() + .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 { + ($raw:expr, $id:ty) => { + $crate::modify!($raw) + .as_any_mut() + .downcast_mut::<$id>() + .is_some() + }; +} + +// cast_any 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 { + ($raw:expr) => { + $crate::modify!($raw).as_any_mut() + }; +} + +// When initializing an uninitialized field for the first time, +// we ensure we don't drop the previous content +// This is problematic if the same field is overwritten multiple times +/// In that case, prefer to use update_uninit +#[macro_export] +macro_rules! update_field_nodrop { + ($ptr:expr, $field:ident, $value:expr) => { + $crate::update_nodrop!((*$ptr).$field, $value) + }; +} + +// When initializing an uninitialized field for the first time, +// we ensure we don't drop the previous content +#[macro_export] +macro_rules! update_nodrop { + ($ptr:expr, $value:expr) => { + // safety: Dafny won't call this function unless it can guarantee the value at the address was not + // yet initialized, so that not dropping it won't create a memory leak + unsafe { ::std::ptr::addr_of_mut!($ptr).write($value) } + } +} + +// Given a class or array pointer, transforms it to a mutable reference +#[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 + (unsafe { &mut *$ptr }) + } +} + +// Given a class or array pointer, transforms it to a read-only reference +#[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 + (unsafe { &*$ptr }) + } +} + +// If the field is guaranteed to be assigned only once, update_field_nodrop is sufficient +#[macro_export] +macro_rules! update_field_uninit { + ($t:expr, $field:ident, $field_assigned:expr, $value:expr) => {{ + let computed_value = $value; + if $field_assigned { + $crate::modify!($t).$field = computed_value; + } else { + $crate::update_field_nodrop!($t, $field, computed_value); + $field_assigned = true; + } + }}; +} + +// Macro to call at the end of the first new; constructor when not every field is guaranteed to be assigned. +#[macro_export] +macro_rules! update_field_if_uninit { + ($t:expr, $field:ident, $field_assigned:expr, $value:expr) => {{ + let computed_value = $value; + if !$field_assigned { + $crate::update_field_nodrop!($t, $field, computed_value); + $field_assigned = true; + } + }}; +} + +///////////////// +// Reference-counted classes mode +///////////////// + +pub type Object = Option>; + +#[macro_export] +macro_rules! cast_object { + ($raw:expr, $id:ty) => { + unsafe { + let res: Object<$id> = + Some(Rc::from_raw( + Rc::into_raw($raw.unwrap()) as _)); + res + } + }; +} + +// Returns an object whose fields are yet initialized. Only use update_field_uninit_rcmut and update_field_if_uninit_rcmut to initialize fields. +pub fn allocate_rcmut() -> Object { + unsafe { mem::transmute(object::new::>(MaybeUninit::uninit())) } +} + +pub fn is_instance_of_rcmut(theobject: Object) -> bool { + // safety: Dafny won't call this function unless it can guarantee the object is still allocated + unsafe { + rcmut::borrow(&theobject.unwrap()).as_any().downcast_ref::().is_some() + } +} + +// Equivalent of update_field_nodrop but for rcmut +#[macro_export] +macro_rules! update_field_nodrop_rcmut { + ($ptr:expr, $field: ident, $value:expr) => { + update_nodrop_rcmut!((rcmut::borrow_mut(&mut $ptr.clone().unwrap())).$field, $value) + }; +} + +// Equivalent of update_nodrop but for rcmut +#[macro_export] +macro_rules! update_nodrop_rcmut { + ($ptr:expr, $value:expr) => { + unsafe { unsafe { ::std::ptr::addr_of_mut!($ptr).write($value) } } + }; +} + +// Equivalent of update_field_if_uninit but for rcmut +#[macro_export] +macro_rules! update_field_if_uninit_rcmut { + ($t:expr, $field:ident, $field_assigned:expr, $value:expr) => {{ + let computed_value = $value; + if !$field_assigned { + update_field_nodrop_rcmut!($t, $field, computed_value); + $field_assigned = true; + } + }}; +} + +// Equivalent of update_field_uninit but for rcmut +#[macro_export] +macro_rules! update_field_uninit_rcmut { + ($t:expr, $field:ident, $field_assigned:expr, $value:expr) => {{ + let computed_value = $value; + if $field_assigned { + $crate::md!($t).$field = computed_value; + } else { + update_field_nodrop_rcmut!($t, $field, computed_value); + $field_assigned = true; + } + }}; +} + +// Equivalent of modify but for rcmut +#[macro_export] +macro_rules! md { + ($x:expr) => { + unsafe { rcmut::borrow_mut(&mut $x.unwrap()) } + }; +} + +// Equivalent of read but for rcmut +#[macro_export] +macro_rules! rd { + ($x:expr) => { + unsafe { rcmut::borrow(& $x.unwrap()) } + }; +} + +// Count the number of references to the given object +#[macro_export] +macro_rules! refcount { + ($x:expr) => { + Rc::strong_count(unsafe { rcmut::as_rc(& $x.unwrap()) }) + }; +} + +impl UpcastTo> for Object { + fn upcast_to(&self) -> Object { + if self.is_none() { + None + } else { + Some(self.clone().unwrap() as Rc>) + } + } +} + +pub mod object { + pub fn new(val: T) -> crate::Object { + Some(crate::rcmut::new(val)) + } +} + +// Inspired from https://crates.io/crates/rcmut +pub mod rcmut { + use std::cell::UnsafeCell; + use std::mem::{self, MaybeUninit}; + use std::rc::Rc; + use std::sync::Arc; + + pub fn array_from_rc(data: Rc<[T]>) -> crate::Object<[T]> { + Some(unsafe { crate::rcmut::from_rc(data) }) + } + pub struct Array { + pub data: Box<[T]>, + } + impl Array { + pub fn new(data: Box<[T]>) -> crate::Object> { + Some(crate::rcmut::new(Array { data })) + } + + pub fn placebos_usize(length: usize) -> Option>>> { + let x = crate::array::placebos_box_usize::(length); + crate::rcmut::Array::>::new(x) + } + } + /// A reference counted smart pointer with unrestricted mutability. + pub type RcMut = Rc>; + + /// Create a new RcMut for a value. + pub fn new(val: T) -> RcMut { + Rc::new(UnsafeCell::new(val)) + } + /// Retrieve the inner Rc as a reference. + pub unsafe fn from(value: Box) -> RcMut { + mem::transmute(Rc::new(*value)) + } + + pub unsafe fn from_rc(value: Rc) -> RcMut { + mem::transmute(value) + } + + pub unsafe fn as_rc(this: &RcMut) -> &Rc { + mem::transmute(this) + } + pub unsafe fn to_rc(this: RcMut) -> Rc { + mem::transmute(this) + } + + /// Retrieve the inner Rc as a mutable reference. + pub unsafe fn as_rc_mut(this: &mut RcMut) -> &mut Rc { + mem::transmute(this) + } + + /// Get a reference to the value. + #[inline] + pub unsafe fn borrow(this: &RcMut) -> &T { + mem::transmute(this.get()) + } + + /// Get a mutable reference to the value. + #[inline] + pub unsafe fn borrow_mut(this: &mut RcMut) -> &mut T { + mem::transmute(this.get()) + } + + /// A reference counted smart pointer with unrestricted mutability. + pub struct ArcMut { + inner: Arc>, + } + + impl Clone for ArcMut { + fn clone(&self) -> ArcMut { + ArcMut { + inner: self.inner.clone(), + } + } + } + + impl ArcMut { + /// Create a new ArcMut for a value. + pub fn new(val: T) -> ArcMut { + ArcMut { + inner: Arc::new(UnsafeCell::new(val)), + } + } + } + + impl ArcMut { + /// Retrieve the inner Rc as a reference. + pub unsafe fn as_arc(&self) -> &Arc { + mem::transmute(&self.inner) + } + + /// Retrieve the inner Rc as a mutable reference. + pub unsafe fn as_arc_mut(&mut self) -> &mut Arc { + mem::transmute(&mut self.inner) + } + + /// Get a reference to the value. + pub unsafe fn borrow(&self) -> &T { + mem::transmute(self.inner.get()) + } + + /// Get a mutable reference to the value. + pub unsafe fn borrow_mut(&mut self) -> &mut T { + mem::transmute(self.inner.get()) + } + } +} + +///////////////// +// Method helpers +///////////////// + +// A MaybePlacebo is a value that is either a placebo or a real value. +// It is a wrapper around a MaybeUninit value, but knowing whether the value is a placebo or not. +// That way, when it is dropped, the underlying value is only dropped if it is not a placebo. +pub struct MaybePlacebo(Option); +impl MaybePlacebo { + #[inline] + pub fn read(&self) -> T { + // safety: Dafny will guarantee we will never read a placebo value + unsafe { self.0.clone().unwrap_unchecked() } + } +} + +impl MaybePlacebo { + #[inline] + pub fn new() -> Self { + MaybePlacebo(None) + } + #[inline] + pub fn from(v: T) -> Self { + MaybePlacebo(Some(v)) } } +#[macro_export] +macro_rules! tuple_extract_index { + ($x:expr, $i:expr) => { + $x.$i + }; +} + +// A macro that maps tuple (a, b, c...) to produce (MaybePlacebo::from(a), MaybePlacebo::from(b), MaybePlacebo::from(c)) +// maybe_placebos_from!(expr, 0, 1, 2, 3) +// = let x = expr; +// (MaybePlacebo::from(x.0), MaybePlacebo::from(x.1), MaybePlacebo::from(x.2), MaybePlacebo::from(x.3)) +#[macro_export] +macro_rules! maybe_placebos_from { + ($x:expr, $($i:tt), *) => { + { + let x = $x; + ( + $( $crate::MaybePlacebo::from(x.$i), )* + ) + } + } +} + +//////////////// +// Coercion +//////////////// + +pub trait UpcastTo { + fn upcast_to(&self) -> U; +} + +#[macro_export] +macro_rules! UpcastTo { + ($from:ty, $to:ty) => { + impl $crate::UpcastTo<*mut $to> for &mut $from { + fn upcast_to(&self) -> *mut $to { + (*self) as *const $to as *mut $to + } + } + }; +} + +// UpcastTo for pointers +impl UpcastTo<*mut dyn Any> for *mut T { + fn upcast_to(&self) -> *mut dyn Any { + (*self) as *const dyn Any as *mut dyn Any + } +} + +// UpcastTo for objects +#[macro_export] +macro_rules! UpcastToObject { + ($from:ty, $to:ty) => { + impl $crate::UpcastTo> for Object<$from> { + fn upcast_to(&self) -> Object<$to> { + Some((*self).clone().unwrap()as Rc>) + } + } + }; +} + + +// UpcastTo for sets +impl UpcastTo> for Set +where + V: DafnyTypeEq, + U: DafnyTypeEq + UpcastTo, +{ + fn upcast_to(&self) -> Set { + // We need to upcast individual elements + let mut new_set: HashSet = HashSet::::default(); + for value in self.data.iter() { + new_set.insert(value.upcast_to()); + } + Set::from_hashset_owned(new_set) + } +} + +// UpcastTo for sequences +impl UpcastTo> for Sequence +where + V: DafnyTypeEq, + U: DafnyTypeEq + UpcastTo, +{ + fn upcast_to(&self) -> Sequence { + // We need to upcast individual elements + let mut new_seq: Vec = Vec::::default(); + for value in self.to_array().iter() { + new_seq.push(value.upcast_to()); + } + Sequence::from_array_owned(new_seq) + } +} + +// Upcast for multisets +impl UpcastTo> for Multiset +where + V: DafnyTypeEq, + U: DafnyTypeEq + UpcastTo, +{ + fn upcast_to(&self) -> Multiset { + // We need to upcast individual elements + let mut new_multiset: HashMap = HashMap::::default(); + for (value, count) in self.data.iter() { + new_multiset.insert(value.upcast_to(), count.clone()); + } + Multiset::from_hashmap_owned(new_multiset) + } +} + +// Upcast for Maps +impl UpcastTo> for Map +where + K: DafnyTypeEq, + U: DafnyTypeEq + UpcastTo, + V: DafnyTypeEq, +{ + fn upcast_to(&self) -> Map { + // We need to upcast individual elements + let mut new_map: HashMap = HashMap::::default(); + for (key, value) in self.data.iter() { + new_map.insert(key.clone(), value.upcast_to()); + } + Map::from_hashmap_owned(new_map) + } +} diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index ef8cb7838..23e33ff93 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -1,8 +1,25 @@ // Test module #[cfg(test)] mod tests { + use crate::rcmut::RcMut; + use crate::*; + #[test] + fn test_int() { + let x = int!(37); + assert_eq!(x.to_u8().unwrap(), truncate!(x.clone(), u8)); + assert_eq!(x.to_u16().unwrap(), truncate!(x.clone(), u16)); + assert_eq!(x.to_u32().unwrap(), truncate!(x.clone(), u32)); + assert_eq!(x.to_u64().unwrap(), truncate!(x.clone(), u64)); + assert_eq!(x.to_u128().unwrap(), truncate!(x.clone(), u128)); + assert_eq!(x.to_i8().unwrap(), truncate!(x.clone(), i8)); + assert_eq!(x.to_i16().unwrap(), truncate!(x.clone(), i16)); + assert_eq!(x.to_i32().unwrap(), truncate!(x.clone(), i32)); + assert_eq!(x.to_i64().unwrap(), truncate!(x.clone(), i64)); + assert_eq!(x.to_i128().unwrap(), truncate!(x.clone(), i128)); + } + #[test] fn test_sequence() { let values = vec![1, 2, 3]; @@ -22,7 +39,7 @@ mod tests { boxed, length, left, - right, + .. } => { assert_eq!(*length, 6); assert_eq!(unsafe { &*left.get() }.cardinality_usize(), 3); @@ -31,15 +48,10 @@ mod tests { } _ => panic!("This should never happen"), } - let value = concat.select(0); + let value = concat.get_usize(0); assert_eq!(value, 1); match &concat { - crate::Sequence::ConcatSequence { - boxed, - length, - left, - right, - } => { + crate::Sequence::ConcatSequence { boxed, .. } => { assert_eq!( *boxed.as_ref().clone().borrow().as_ref().unwrap().as_ref(), vec![1, 2, 3, 4, 5, 6] @@ -57,7 +69,7 @@ mod tests { #[test] fn test_dafny_sequence_print() { - let hello = seq![ + let hello: DafnyString = seq![ DafnyChar('H'), DafnyChar('e'), DafnyChar('l'), @@ -65,7 +77,7 @@ mod tests { DafnyChar('o') ]; assert_eq!(DafnyPrintWrapper(&hello).to_string(), "Hello"); - let hello = seq![ + let hello: DafnyStringUTF16 = seq![ DafnyCharUTF16(0x0048), DafnyCharUTF16(0x0065), DafnyCharUTF16(0x006c), @@ -193,5 +205,552 @@ mod tests { assert_eq!(m_4b.cardinality_usize(), 4); assert_eq!(m_4b.contains(&3), false) } + + #[test] + fn test_dafny_array() { + let a = array![1, 2, 3]; + assert_eq!(crate::array::length_usize(a), 3); + assert_eq!(crate::array::length(a), int!(3)); + assert_eq!(array::get_usize(a, 0), 1); + assert_eq!(array::get_usize(a, 1), 2); + assert_eq!(array::get_usize(a, 2), 3); + array::update_usize(a, 0, 4); + array::update_usize(a, 1, 5); + array::update_usize(a, 2, 6); + assert_eq!(array::get_usize(a, 0), 4); + assert_eq!(array::get_usize(a, 1), 5); + assert_eq!(array::get_usize(a, 2), 6); + deallocate(a); + } + + #[test] + fn test_dafny_array_init() { + // test from_vec, and initialize + let mut v = Vec::new(); + v.push(1); + v.push(2); + v.push(3); + let a = array::from_vec(v); + assert_eq!(array::length_usize(a), 3); + assert_eq!(array::get_usize(a, 0), 1); + let v2 = array::initialize_usize(3, Rc::new(|i| i + 1)); + assert_eq!(array::length_usize(v2), 3); + assert_eq!(array::get_usize(v2, 0), 1); + assert_eq!(array::get_usize(v2, 1), 2); + assert_eq!(array::get_usize(v2, 2), 3); + array::update_usize(v2, 1, 10); + assert_eq!(array::get_usize(v2, 1), 10); + + let v3 = array::initialize(&int!(3), Rc::new(|i| i.clone() + int!(1))); + assert_eq!(array::length_usize(v3), 3); + assert_eq!(array::get_usize(v3, 0), int!(1)); + assert_eq!(array::get_usize(v3, 1), int!(2)); + assert_eq!(array::get_usize(v3, 2), int!(3)); + array::update(v3, &int!(1), int!(10)); + assert_eq!(array::get_usize(v3, 1), int!(10)); + } + + #[test] + fn test_array2() { + let p = Array2::::placebos(&int!(3), &int!(4)); + for i in 0..3 { + for j in 0..4 { + modify!(p).data[i][j] = MaybeUninit::new(int!(i + j)); + } + } + let p = Array2::construct(p); + let p = unsafe { &*p }; + assert_eq!(p.length0_usize(), 3); + assert_eq!(p.length1_usize(), 4); + deallocate(p); + // Allocate an array whose first dimension is zero + let p = Array2::::placebos(&int!(0), &int!(4)); + let p = Array2::construct(p); + assert_eq!(read!(p).length0_usize(), 0); + assert_eq!(read!(p).length1_usize(), 4); + deallocate(p); + } + + #[test] + fn test_array3() { + let a = Array3::::placebos(&int!(3), &int!(2), &int!(4)); + for i in 0..3 { + for j in 0..2 { + for k in 0..4 { + modify!(a).data[i][j][k] = MaybeUninit::new(DafnyInt::from(i * j + k)); + } + } + } + let a = Array3::construct(a); + assert_eq!(read!(a).length0(), int!(3)); + assert_eq!(read!(a).length1(), int!(2)); + assert_eq!(read!(a).length2(), int!(4)); + for i in 0..3 { + for j in 0..2 { + for k in 0..4 { + assert_eq!(read!(a).data[i][j][k], DafnyInt::from(i * j + k)); + } + } + } + deallocate(a); + // Even if the first two dimensions are zero, the third dimension should not be zero + let a = Array3::::placebos(&int!(0), &int!(0), &int!(4)); + let a = Array3::construct(a); + assert_eq!(read!(a).length0(), int!(0)); + assert_eq!(read!(a).length1(), int!(0)); + assert_eq!(read!(a).length2(), int!(4)); + deallocate(a); + } + + struct ClassWrapper { + /*var*/ t: T, + /*var*/ x: crate::DafnyInt, + /*const*/ next: *mut ClassWrapper, + /*const*/ constant: crate::DafnyInt, + } + impl AsAny for ClassWrapper + where + T: 'static, + { + fn as_any(&self) -> &dyn Any { + self + } + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + } + impl ClassWrapper { + fn constant_plus_x(&self) -> crate::DafnyInt { + self.constant.clone() + self.x.clone() + } + fn increment_x(&mut self) { + self.x = self.x.clone() + int!(1); + } + } + + impl ClassWrapper { + fn constructor(t: T) -> *mut ClassWrapper { + let this = crate::allocate::>(); + update_field_nodrop!(this, t, t); + update_field_nodrop!(this, next, this); + // If x is assigned twice, we need to keep track of whether it's assigned + // like in methods. + let mut x_assigned = false; + update_field_uninit!(this, x, x_assigned, int!(2)); + update_field_uninit!(this, x, x_assigned, int!(1)); + // If we can prove that x is assigned, we can even write this + modify!(this).x = int!(0); + update_field_nodrop!(this, constant, int!(42)); + this + } + } + + #[test] + #[allow(unused_unsafe)] + fn test_class_wrapper() { + let c: *mut ClassWrapper = ClassWrapper::constructor(53); + assert_eq!(read!(c).constant, int!(42)); + assert_eq!(read!(c).t, 53); + assert_eq!(read!(c).x, int!(0)); + assert_eq!(read!(read!(c).next).t, 53); + assert_eq!(read!(c).constant_plus_x(), int!(42)); + modify!(c).increment_x(); + assert_eq!(read!(c).constant_plus_x(), int!(43)); + modify!(c).x = int!(40); + assert_eq!(read!(c).constant_plus_x(), int!(82)); + modify!(c).t = 54; + assert_eq!(read!(c).t, 54); + let x_copy = read!(c).x.clone(); + assert_eq!(Rc::strong_count(&x_copy.data), 2); + deallocate(c); + 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 + fn assign_lazy_in_method(test1: bool, test2: bool) -> Rc { + let mut t = MaybePlacebo::>::new(); + if test1 { + t = MaybePlacebo::from(Rc::new(5 as i32)); + } + if test2 { + t = MaybePlacebo::from(Rc::new( + 7 as i32 + if test1 { *MaybePlacebo::read(&t) } else { 0 }, + )); + } + println!("{}", MaybePlacebo::read(&t)); + MaybePlacebo::read(&t) + } + + #[test] + fn assign_lazy_in_method_test() { + let mut t = assign_lazy_in_method(true, false); + assert_eq!(*t, 5); + t = assign_lazy_in_method(false, true); + assert_eq!(*t, 7); + t = assign_lazy_in_method(true, true); + assert_eq!(*t, 12); + } + + fn override_placebo(o: T, do_override: bool) { + let mut x: MaybePlacebo = MaybePlacebo::::new(); + if do_override { + x = MaybePlacebo::from(o.clone()); + } + } + + #[test] + fn test_placebo() { + override_placebo::>(Rc::new(BigInt::from(1)), false); + 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 mut f: Rc Class> = Class> as Placebo>::new(); + } + + #[test] + fn test_maybe_placebos_from() { + let x = (1, 2, 3, 4); + let (a, b, c, d) = maybe_placebos_from!(x, 0, 1, 2, 3); + assert_eq!(a.read(), 1); + assert_eq!(b.read(), 2); + assert_eq!(c.read(), 3); + assert_eq!(d.read(), 4); + } + + #[test] + fn test_coercion_immutable() { + let o = ClassWrapper::::constructor(1); + let a = UpcastTo::<*mut dyn Any>::upcast_to(&o); + assert_eq!(cast!(a, ClassWrapper), o); + let seq_o = seq![o]; + let seq_a = UpcastTo::>::upcast_to(&seq_o); + assert_eq!(cast!(seq_a.get_usize(0), ClassWrapper), o); + let set_o = set! {o}; + let set_a = UpcastTo::>::upcast_to(&set_o); + assert_eq!(cast!(set_a.peek(), ClassWrapper), o); + let multiset_o = multiset! {o, o}; + let multiset_a = UpcastTo::>::upcast_to(&multiset_o); + assert_eq!(cast!(multiset_a.peek(), ClassWrapper), o); + let map_o = map![1 => o, 2 => o]; + let map_a = UpcastTo::>::upcast_to(&map_o); + assert_eq!(cast!(map_a.get(&1), ClassWrapper), o); + } + + #[test] + fn test_defaults() { + let set_i32 = as Default>::default(); + let seq_i32 = as Default>::default(); + let map_i32 = as Default>::default(); + let multiset_i32 = as Default>::default(); + assert_eq!(set_i32.cardinality_usize(), 0); + assert_eq!(seq_i32.cardinality_usize(), 0); + assert_eq!(map_i32.cardinality_usize(), 0); + assert_eq!(multiset_i32.cardinality_usize(), 0); + } + + #[test] + fn test_nontrivial_defaults() { + let set_i32 = as NontrivialDefault>::nontrivial_default(); + let seq_i32 = as NontrivialDefault>::nontrivial_default(); + let map_i32 = as NontrivialDefault>::nontrivial_default(); + let multiset_i32 = as NontrivialDefault>::nontrivial_default(); + assert_eq!(set_i32.cardinality_usize(), 0); + 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()); + } + + #[test] + fn test_function_wrappers() { + let f: Rc i32> = Rc::new(|i: i32| i + 1); + let g = f.clone(); + let _h = seq![g]; + } + + #[test] + fn test_forall_exists() { + assert!(integer_range(int!(0), int!(10)) + .all(Rc::new(|i: DafnyInt| i.clone() < int!(10)).as_ref())); + assert!(!integer_range(int!(0), int!(11)) + .all(Rc::new(|i: DafnyInt| i.clone() < int!(10)).as_ref())); + assert!(!integer_range(int!(0), int!(10)) + .any(Rc::new(|i: DafnyInt| i.clone() >= int!(10)).as_ref())); + assert!(integer_range(int!(0), int!(11)) + .any(Rc::new(|i: DafnyInt| i.clone() >= int!(10)).as_ref())); + + assert!(integer_range(int!(0), int!(10)).all( + Rc::new(|i: DafnyInt| !(i.clone() % int!(4) == int!(0)) + || i.clone() < int!(10) && i.clone() % int!(2) == int!(0)) + .as_ref() + )); + assert!(integer_range(int!(0), int!(11)).all( + Rc::new(|i: DafnyInt| !(i.clone() % int!(4) == int!(0)) + || i.clone() < int!(10) && i.clone() % int!(2) == int!(0)) + .as_ref() + )); + assert!(!integer_range(int!(0), int!(10)).any( + Rc::new(|i: DafnyInt| i.clone() % int!(4) == int!(0) + && i.clone() >= int!(10) + && i.clone() % int!(2) == int!(0)) + .as_ref() + )); + assert!(!integer_range(int!(0), int!(11)).any( + Rc::new(|i: DafnyInt| i.clone() % int!(4) == int!(0) + && i.clone() >= int!(10) + && i.clone() % int!(2) == int!(0)) + .as_ref() + )); + + assert!(exact_range(10).all(Rc::new(|i: i32| i == 10).as_ref())); + assert!(exact_range(10).any(Rc::new(|i: i32| i == 10).as_ref())); + assert!(!exact_range(10).all(Rc::new(|i: i32| i != 10).as_ref())); + assert!(!exact_range(10).any(Rc::new(|i: i32| i != 10).as_ref())); + + assert!(seq![1, 3, 5, 7] + .iter() + .all(Rc::new(|i: u32| i % 2 == 1).as_ref())); + assert!(!seq![1, 3, 5, 7] + .iter() + .any(Rc::new(|i: u32| i % 2 == 0).as_ref())); + assert!(!seq![1, 3, 5, 7, 8] + .iter() + .all(Rc::new(|i: u32| i % 2 == 1).as_ref())); + assert!(seq![1, 3, 5, 7, 8] + .iter() + .any(Rc::new(|i: u32| i % 2 == 0).as_ref())); + + assert!(set! {1, 3, 5, 7} + .iter() + .cloned() + .all(Rc::new(|i: u32| i % 2 == 1).as_ref())); + assert!(!set! {1, 3, 5, 7} + .iter() + .cloned() + .any(Rc::new(|i: u32| i % 2 == 0).as_ref())); + assert!(!set! {1, 3, 5, 7, 8} + .iter() + .cloned() + .all(Rc::new(|i: u32| i % 2 == 1).as_ref())); + assert!(set! {1, 3, 5, 7, 8} + .iter() + .cloned() + .any(Rc::new(|i: u32| i % 2 == 0).as_ref())); + + for i in set! {1, 3, 5, 7}.iter() { + println!("{}", i); + } + + assert!(multiset! {1, 1, 5, 7} + .iter() + .all(Rc::new(|i: u32| i % 2 == 1).as_ref())); + assert!(!multiset! {1, 1, 5, 7} + .iter() + .any(Rc::new(|i: u32| i % 2 == 0).as_ref())); + assert!(!multiset! {1, 1, 5, 7, 8} + .iter() + .all(Rc::new(|i: u32| i % 2 == 1).as_ref())); + assert!(multiset! {1, 1, 5, 7, 8} + .iter() + .any(Rc::new(|i: u32| i % 2 == 0).as_ref())); + + let m = map![1 => 4, 3 => 6, 5 => 8]; + let m2 = m.clone(); + let m3 = m.clone(); + assert!(m + .clone() + .iter() + .all(Rc::new(move |i: u32| i + 3 == m2.get(&i)).as_ref())); + assert!(!m + .iter() + .any(Rc::new(move |i: u32| i + 2 == m3.get(&i)).as_ref())); + let m = map![1 => 4, 3 => 7, 5 => 7]; + let m2 = m.clone(); + let m3 = m.clone(); + assert!(!m + .clone() + .iter() + .all(Rc::new(move |i: u32| i + 3 == m2.get(&i)).as_ref())); + assert!(m + .iter() + .any(Rc::new(move |i: u32| i + 2 == m3.get(&i)).as_ref())); + } + + #[test] + fn test_for_loops() { + let mut sum: i32 = 0; + for i in integer_range(1, 11) { + sum += i; + } + assert_eq!(sum, 55); + + let mut sum: i32 = 0; + for i in integer_range_down(11, 1) { + sum += i; + } + assert_eq!(sum, 55); + + let mut sum: i32 = 0; + for i in integer_range_unbounded(1) { + sum += i; + if i == 10 { + break; + } + } + assert_eq!(sum, 55); + + let mut sum: i32 = 0; + for i in integer_range_down_unbounded(11) { + sum += i; + if i == 1 { + break; + } + } + assert_eq!(sum, 55); + } + + trait NodeRcMutTrait: AsAny {} + + pub struct NodeRcMut { + val: DafnyInt, + next: Object, + } + impl AsAny for NodeRcMut { + fn as_any(&self) -> &dyn Any { + self + } + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + } + impl NodeRcMut { + fn _ctor(this: Object, val: DafnyInt) { + let mut val_assign = false; + let mut next_assign = false; + update_field_uninit_rcmut!(this.clone(), val, val_assign, val); + update_field_if_uninit_rcmut!(this.clone(), next, next_assign, None); + } + } + impl NodeRcMutTrait for NodeRcMut {} + + UpcastToObject!(NodeRcMut, dyn NodeRcMutTrait); + + #[test] + fn test_rcmut() { + let x: Object = allocate_rcmut::(); + NodeRcMut::_ctor(x.clone(), int!(42)); + assert_eq!(refcount!(x.clone()), 2); + assert_eq!(rd!(x.clone()).val, int!(42)); + md!(x.clone()).next = x.clone(); + assert_eq!(refcount!(x.clone()), 3); + assert_eq!(rd!(rd!(x.clone()).next.clone()).val, int!(42)); + md!(rd!(x.clone()).next.clone()).next = None; + assert_eq!(refcount!(x.clone()), 2); + let y: Object = x.upcast_to(); + assert_eq!(refcount!(x.clone()), 3); + let z: Object = x.upcast_to(); + assert_eq!(refcount!(x.clone()), 4); + let a2: Object = cast_object!(y.clone(), NodeRcMut); + assert_eq!(refcount!(x.clone()), 5); + assert_eq!(rd!(a2.clone()).val, int!(42)); + let a3: Object = cast_object!(z.clone(), NodeRcMut); + assert_eq!(refcount!(x.clone()), 6); + assert_eq!(rd!(a3.clone()).val, int!(42)); + + let a: Object<[i32]> = rcmut::array_from_rc(Rc::new([42, 43, 44])); + assert_eq!(rd!(a.clone()).len(), 3); + assert_eq!(rd!(a.clone())[0], 42); + assert_eq!(rd!(a.clone())[1], 43); + assert_eq!(rd!(a.clone())[2], 44); + let b = a.clone(); + md!(b.clone())[0] = 45; + assert_eq!(rd!(a.clone())[0], 45); + } + + pub struct NodeRawMut { + val: DafnyInt, + next: *mut NodeRawMut, + } + impl NodeRawMut { + fn _ctor(this: *mut NodeRawMut, val: DafnyInt) { + let mut val_assign = false; + update_field_uninit!(this, val, val_assign, val); + } + } + impl AsAny for NodeRawMut { + fn as_any(&self) -> &dyn Any { + self + } + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + } + impl NodeRcMutTrait for NodeRawMut {} + + UpcastTo!(NodeRawMut, dyn NodeRcMutTrait); + + #[test] + fn test_rawmut() { + let x: *mut NodeRawMut = allocate::(); + NodeRawMut::_ctor(x.clone(), int!(42)); + //assert_eq!(refcount!(x.clone()), 2); + assert_eq!(read!(x.clone()).val, int!(42)); + modify!(x.clone()).next = x.clone(); + //assert_eq!(refcount!(x.clone()), 3); + assert_eq!(read!(read!(x.clone()).next.clone()).val, int!(42)); + modify!(read!(x.clone()).next.clone()).next = std::ptr::null_mut(); + //assert_eq!(refcount!(x.clone()), 2); + let y = x.upcast_to(); + let z: *mut dyn NodeRcMutTrait = modify!(x).upcast_to(); + let a2: *mut NodeRawMut = cast!(y, NodeRawMut); + let a3: *mut NodeRawMut = cast!(z, NodeRawMut); + //assert_eq!(refcount!(x.clone()), 3); + deallocate(x); + + let a = array::from_native(Box::new([42, 43, 44])); + assert_eq!(read!(a.clone()).len(), 3); + assert_eq!(read!(a.clone())[0], 42); + assert_eq!(read!(a.clone())[1], 43); + assert_eq!(read!(a.clone())[2], 44); + let b = a.clone(); + modify!(b.clone())[0] = 45; + assert_eq!(read!(a.clone())[0], 45); + } } -// Struct containing two reference-counted fields diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/VerifyThis2015/Problem3.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/VerifyThis2015/Problem3.dfy.rs.check index 5b69a8203..4f94dbab1 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/VerifyThis2015/Problem3.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/VerifyThis2015/Problem3.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the trait bound `Rc: DafnyType` is not satisfied \ No newline at end of file +// CHECK-L: error[E0369]: binary operation `!=` cannot be applied to type `Sequence>` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/arrays.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/arrays.dfy.rs.check index b87489fa2..415a49da1 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/arrays.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/arrays.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0433]: failed to resolve: use of undeclared crate or module `num` \ No newline at end of file +// CHECK-L: error[E0277]: the type `[u32]` cannot be indexed by `&u32` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/bit-vectors.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/bit-vectors.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/bit-vectors.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/bit-vectors.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/class.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/class.dfy.rs.check index b87489fa2..b69d43029 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/class.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/class.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0433]: failed to resolve: use of undeclared crate or module `num` \ No newline at end of file +// CHECK-L: error[E0599]: no method named `borrow` found for type `u32` in the current scope \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/generic.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/generic.dfy.rs.check index a9c36a137..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/generic.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/generic.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the trait bound `T: Default` is not satisfied \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/maps.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/maps.dfy.rs.check index 7ba64d0e8..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/maps.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/maps.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/recursion.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/recursion.dfy.rs.check deleted file mode 100644 index b87489fa2..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/recursion.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0433]: failed to resolve: use of undeclared crate or module `num` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/seqs.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/seqs.dfy.rs.check index 4101aaa45..3d586af71 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/seqs.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/seqs.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*use of undeclared crate or module `num`.* \ No newline at end of file +// CHECK-L: error[E0061]: this function takes 1 argument but 0 arguments were supplied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/sets.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/sets.dfy.rs.check index b87489fa2..45feb2e6a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/sets.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/sets.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0433]: failed to resolve: use of undeclared crate or module `num` \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `Example0: Hash` is not satisfied \ No newline at end of file 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 8301cc8e9..9b64d3494 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-L: Unhandled exception: System.InvalidOperationException: Unknown buildable type: NULL +// CHECK: .*Unsupported:\ DAST_dBinOp_dPlus\ with\ not\ 2\ elements.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/BuiltIns.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/BuiltIns.dfy.rs.check index d59836f7d..9fa1b1dc3 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/BuiltIns.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/BuiltIns.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0308]: mismatched types \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `dyn Fn() -> DafnyInt: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/BuiltIns_Unsupported.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/BuiltIns_Unsupported.dfy.rs.check index dae9bb332..cb5fc62eb 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/BuiltIns_Unsupported.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/BuiltIns_Unsupported.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0308]: mismatched types +// CHECK-L: error[E0277]: the trait bound `dyn for<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l, 'm, 'n, 'o, 'p, 'q> Fn(&'a bool, &'b bool, &'c bool, &'d bool, &'e bool, &'f bool, &'g bool, &'h bool, &'i bool, &'j bool, &'k bool, &'l bool, &'m bool, &'n bool, &'o bool, &'p bool, &'q bool) -> DafnyInt: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/CovariantCollections.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/CovariantCollections.dfy.rs.check index 113294900..bc1f6f09a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/CovariantCollections.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/CovariantCollections.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Cannot\ assign\ null\ value\ to\ variable.* \ No newline at end of file +// CHECK: .*Unsupported:\ DAST_dBinOp_dEuclidianMod\ with\ not\ 2\ elements.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/ErasableTypeWrappers.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/ErasableTypeWrappers.dfy.rs.check index 54c971c04..d831924e7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/ErasableTypeWrappers.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/ErasableTypeWrappers.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: Unhandled exception: System.InvalidOperationException: Unknown buildable type: NULL \ No newline at end of file +// CHECK-L: error: expected identifier, found `<` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/NativeNumbers.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/NativeNumbers.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/NativeNumbers.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/NativeNumbers.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/UnicodeStrings.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/UnicodeStrings.dfy.rs.check index c17262a42..7d2d31cd8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/UnicodeStrings.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/UnicodeStrings.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*ForLoops.* \ No newline at end of file +// CHECK: .*Unsupported:\ Cannot\ emit\ literal\ expression\ 0\ outside\ of\ expression\ context:\ Microsoft_dDafny_dCompilers_dBuilderSyntaxTree'1\[Microsoft_dDafny_dCompilers_dStatementContainer].* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/UnoptimizedErasableTypeWrappers.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/UnoptimizedErasableTypeWrappers.dfy.rs.check index d59836f7d..13112028f 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/UnoptimizedErasableTypeWrappers.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/UnoptimizedErasableTypeWrappers.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0308]: mismatched types \ No newline at end of file +// CHECK-L: error[E0609]: no field `0` on type `DafnyInt` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/Variance.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/Variance.dfy.rs.check index 113294900..f12da961e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/Variance.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/Variance.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Cannot\ assign\ null\ value\ to\ variable.* \ No newline at end of file +// CHECK: .*Traits.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/Various.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/Various.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/Various.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/Various.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/1_Calls-F.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/1_Calls-F.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/1_Calls-F.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/3_Calls-As.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/3_Calls-As.dfy.rs.check deleted file mode 100644 index a57b83bec..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/3_Calls-As.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0614]: type `DafnyInt` cannot be dereferenced \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/5_Calls-FunctionsValues-Dt.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/5_Calls-FunctionsValues-Dt.dfy.rs.check index b216498bb..9fa1b1dc3 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/5_Calls-FunctionsValues-Dt.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/firstSteps/5_Calls-FunctionsValues-Dt.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0782]: trait objects must include the `dyn` keyword \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `dyn Fn() -> DafnyInt: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/replaceables/replaceableHappyflow.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/replaceables/replaceableHappyflow.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/replaceables/replaceableHappyflow.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy new file mode 100644 index 000000000..f89e6a2c2 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy @@ -0,0 +1,174 @@ +// NONUNIFORM: Demonstration of the use of the external Rust Option<> type +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +module {:compile false} {:extern "std"} RustStd { + // Define the Rust option type + datatype {:extern "option::Option"} {:compile false} {:rust_rc false} Option = + Some({:extern "0"} {:extern_extract "unwrap"} value: T) | None { + } +} + +module RustStdCompare { + // Define the Rust option type + datatype {:rust_rc false} Option = + Some({:extern "0"} {:extern_extract "unwrap"} value: T) | None { + } +} + +module DatatypeTests { + import opened RustStd + import RustStdCompare + + newtype u8 = x: int | 0 <= x < 255 + + // Raw Rust enum + datatype {:rust_rc false} NoArg = OptionA | OptionB | OptionC + + // Raw Rust enum + datatype {:rust_rc false} AlmostOption = Nothing | ThereItIs(u: u8) { + static function default(): AlmostOption { + ThereItIs(0 as u8) + } + } + + // Raw Rust enum + datatype {:rust_rc false} AlmostOptionWrapper = StillNothing | AlmostThere(u: AlmostOption) + + // Raw Rust enum + datatype {:rust_rc false} GenericOption = GenericNothing | GenericSome(value: T) + + // Putting {:rust_rc false} would create a compilation issue because there should be an indirection + datatype Peano = Zero | One(p: Peano) + + // Raw Rust struct + datatype {:rust_rc false} Struct = StructConstructor(a: u8, b: bool) { + function BTrue(): Struct { + if b then this else this.(b := true) + } + } + + // Raw Rust enum + datatype {:rust_rc false} Multiple = + | ConstructorA(a: u8) + | ConstructorB(b: bool) + | ConstructorAB(a: u8, b: bool) + { + function Gather(other: Multiple): Multiple { + match this { + case ConstructorAB(a, b) => this + case ConstructorA(a) => + if other.ConstructorB? then + ConstructorAB(a, other.b) + else + this + case ConstructorB(b) => + if other.ConstructorA? then + ConstructorAB(other.a, b) + else + this + } + } + } + + // Rc-wrapped Rust struct + datatype RcStruct = RcStructConstructor(a: u8, b: bool) { + function BTrue(): RcStruct { + if b then this else this.(b := true) + } + } + + // Rc-wrapped Rust enum + datatype RcMultiple = + | RcConstructorA(a: u8) + | RcConstructorB(b: bool) + | RcConstructorAB(a: u8, b: bool) + { + function Gather(other: RcMultiple): RcMultiple { + if RcConstructorAB? then this + else if RcConstructorA? then + if other.RcConstructorB? then + RcConstructorAB(a, other.b) + else + this + else if RcConstructorB? then + if other.RcConstructorA? then + RcConstructorAB(other.a, b) + else + this + else + this + } + } + + // Rc-wrapped struct + datatype Recursive = Recursive(head: int, tail: Option) + + method PrintOption(o: Option) { + match o { + case Some(u) => print u, "\n"; + case None => print "None\n"; + } + } + + method Main() { + var n: NoArg := OptionA; + n := OptionB; + expect !n.OptionC?; + + var d: AlmostOption := Nothing; + d := ThereItIs(4 as u8); + + var p: Peano := Zero; + p := One(p); + var q: Peano := p; + p := One(p); + q := One(q); + expect p == q; + + var c := ConstructorA(0); // Raw struct creation + c := c.(a := 2); // Since the variable is the same and c owns the value, we can update in place. + c := c.Gather(ConstructorA(1)); // Ignored + expect c.ConstructorA? && !c.ConstructorB? && !c.ConstructorAB?; + expect c.a == 2; + c := c.Gather(ConstructorB(true)); + expect c.ConstructorAB? && !c.ConstructorA? && !c.ConstructorB?; + expect c.a == 2 && c.b; + var a := StructConstructor(1, false); + expect a.BTrue() == StructConstructor(1, true); + + var c2 := RcConstructorA(0); // Raw struct creation + c2 := c2.(a := 2); // Since the variable is the same and c owns the value, we can update in place. + c2 := c2.Gather(RcConstructorA(1)); // Ignored + expect c2.RcConstructorA? && !c2.RcConstructorB? && !c2.RcConstructorAB?; + c2 := c2.Gather(RcConstructorB(true)); + expect c2.RcConstructorAB? && !c2.RcConstructorA? && !c2.RcConstructorB?; + var rc_a := RcStructConstructor(1, false); + expect rc_a.BTrue() == RcStructConstructor(1, true); + + var r := Recursive(0, None); + r := Recursive(1, Some(r)); + print r, "\n"; // Recursive(1, Some(Recursive(0, None))) + + // Interfacing with native types + var x := Some(3 as u8); + var u := x.value; + expect u == 3; + match x { + case Some(i) => + expect i == 3; + } + expect x.value == 3; + PrintOption(x); + PrintOption(None); + print x, "\n"; + var no: Option := None; + print no, "\n"; + + var homeMadeOption := RustStdCompare.Some(3); + if homeMadeOption.Some? { + print homeMadeOption.value, "\n"; + } + homeMadeOption := RustStdCompare.None; + } +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy.expect new file mode 100644 index 000000000..30316b151 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy.expect @@ -0,0 +1,8 @@ + +Dafny program verifier finished with 5 verified, 0 errors +DatatypeTests.Recursive.Recursive(1, DatatypeTests.Recursive.Recursive(0, null)) +3 +None +3 +null +3 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy new file mode 100644 index 000000000..aa3d2180f --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy @@ -0,0 +1,228 @@ +// NONUNIFORM: Temporary development of the Rust compiler +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +newtype NativeNotZero = x: int | 1 <= x < 255 witness 1 + +// k0 is initialized using var_init! +// A tracker starts before the second if to determine if k needs to be cleaned up +method TestResourceCleanup(return_first: bool, update_value: bool, thn: T) + requires return_first ==> !update_value +{ + var k0: T; + if return_first { + return; // No assignment, need to forget unconditionally about k0; + } + if update_value { + k0 := thn; + } + // Need to forget conditionally about k0 using the tracker +} + + +// j1 and k1 are initialized using var_init! +// Both j1 and k1 use assign_nodrop! the first time and regular assignment the second time. +// No cleanup is necessary +method TakeAssignNoDrop(b: bool, thn: T, els: T) returns (j1: T, k1: T) +{ + if b { + var x: T; + k1 := thn; + // Here x must be forgotten + } else { + var y: T; + k1 := els; + // Here y must be forgotten + } + j1 := k1; + // Regular assignments + k1 := j1; + j1 := k1; + // No cleanup necessary +} + +// k02 are initialized using var_init! +// A tracker starts before the second if to determine if k needs to be cleaned up +method TestResourceCleanupLoop(return_first: bool, update_value: bool, thn: T) +{ + var k2: T; + var tmp := update_value; + while return_first { + return; // No assignment, need to forget unconditionally about k2; + } + while tmp decreases tmp { + k2 := thn; + tmp := false; + } + // Need to forget conditionally about k0 using the tracker +} + + +// k02 are initialized using var_init! +// A tracker starts before the second if to determine if k needs to be cleaned up +method TestResourceCleanupLoopComplex(return_first: bool, update_value: bool, thn: T) +{ + var k2: T; + var tmp := update_value; + var i := 1; + // The assignment tracker should be emitted before the while statement. + while return_first && i >= 0 decreases i { + if i == 0 { + return; // No assignment, need to forget unconditionally about k0; + } else { + k2 := thn; + } + i := i -1; + } + i := 2; + while i >= 0 decreases i { + var local_var: T; + if i == 1 { + local_var := thn; + } + if(!update_value) { // Here both k2 and local_var must be forgotten + return; + } + k2 := thn; + i := i - 1; + // local_var should be forgotten if it was never assigned here. + } + // Need to forget conditionally about k0 using the tracker +} + + + + +// k3 is initialized using 0. We don't care because we won't read this value before it's written to. +// A tracker starts before the second if to determine if k needs to be cleaned up +method TestResourceCleanupNative(return_first: bool, update_value: bool, thn: NativeNotZero) +{ + var k3: NativeNotZero; + if return_first { + return; //No need to forget numbers + } + if update_value { + k3 := thn; + } + // No need to forget conditionally +} + + +// No tracking, no initialization needed. +method TakeAssignNoDropNative(b: bool, thn: NativeNotZero, els: NativeNotZero) returns (j4: NativeNotZero) +{ + var k4: NativeNotZero; + if b { + k4 := thn; + } else { + k4 := els; + } + j4 := k4; + // Regular assignments + k4 := j4; + j4 := k4; + // No cleanup necessary +} + +// k0 are initialized using var_init! +// A tracker starts before the second if to determine if k needs to be cleaned up +method TestResourceCleanupLoopNative(return_first: bool, update_value: bool, thn: NativeNotZero) +{ + var k5: NativeNotZero; + var tmp := update_value; + while return_first { + return; // No assignment, need to forget unconditionally about k0; + } + while tmp decreases tmp { + k5 := thn; + tmp := false; + } + // Need to forget conditionally about k0 using the tracker +} + +// j1 is a DafnyInt which uses the default value of a . +method AssignNoDropTwice(x: bool) returns (j6: int) +{ + if x { + j6 := 3; // Assigned with assign_nodrop! + return; // No need to clean up + } + j6 := 1; // Assigned with assign_nodrop! + // No need to clean up +} + +method AssignNoDropTwiceNative(x: bool) returns (j7: NativeNotZero) +{ + if x { + j7 := 3; // Assigned with regular assignment + return; + } + j7 := 1; +} + +method InitiateInt(x: bool, y: bool) returns (j8: int) + requires x == y +{ + var k8: int; + // Assignment tracking starts here for k + if x { + k8 := 3; + } + // Assignment tracking starts here for j + if y { + j8 := k8; + return; + } else { + j8 := 3; + } + // J determined to be deterministically assigned here. + // Normal assignment + j8 := 1; +} + +method Main() { + TestResourceCleanup(true, false, 1); + TestResourceCleanup(false, true, 1); + TestResourceCleanup(false, false, 1); + + TestResourceCleanupLoop(true, false, 1); + TestResourceCleanupLoop(false, true, 1); + TestResourceCleanupLoop(false, false, 1); + + TestResourceCleanupLoopComplex(true, false, 1); + TestResourceCleanupLoopComplex(false, true, 1); + TestResourceCleanupLoopComplex(false, false, 1); + + TestResourceCleanupNative(true, false, 1); + TestResourceCleanupNative(false, true, 1); + TestResourceCleanupNative(false, false, 1); + + TestResourceCleanupLoopNative(true, false, 1); + TestResourceCleanupLoopNative(false, true, 1); + TestResourceCleanupLoopNative(false, false, 1); + + var x: int, x2: int := TakeAssignNoDrop(true, 2, 3); + expect x == 2 == x2; + x, x2 := TakeAssignNoDrop(false, 2, 3); + expect x == 3; + + var y: NativeNotZero := TakeAssignNoDropNative(true, 2, 3); + expect y == 2; + y := TakeAssignNoDropNative(false, 2, 3); + expect y == 3; + + x := AssignNoDropTwice(true); + expect x == 3; + x := AssignNoDropTwice(false); + expect x == 1; + y := AssignNoDropTwiceNative(true); + expect y == 3; + y := AssignNoDropTwiceNative(false); + expect y == 1; + + x := InitiateInt(true, true); + expect x == 3; + x := InitiateInt(false, false); + expect x == 1; + print "Everything ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy.expect new file mode 100644 index 000000000..cf2265d57 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 10 verified, 0 errors +Everything ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings-unicode.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings-unicode.check new file mode 100644 index 000000000..b04771415 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings-unicode.check @@ -0,0 +1,2 @@ +// CHECK: .*DafnyChar\(.* +// CHECK-NOT: .*DafnyCharUTF16\(.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings-utf16.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings-utf16.check new file mode 100644 index 000000000..0c277a421 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings-utf16.check @@ -0,0 +1,2 @@ +// CHECK: .*DafnyCharUTF16\(.* +// CHECK-NOT: .*DafnyChar\(.* diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy new file mode 100644 index 000000000..44b1a168f --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy @@ -0,0 +1,20 @@ +// NONUNIFORM: Test of the output of the Rust translation +// RUN: %baredafny run --target=rs --unicode-char=true "%s" > "%t" +// RUN: %diff "%s.expect" "%t" +// RUN: %OutputCheck --file-to-check "%S/strings-rust/src/strings.rs" "%S/strings-unicode.check" +// RUN: %baredafny run --target=rs --unicode-char=false "%s" +// RUN: %diff "%s.expect" "%t" +// RUN: %OutputCheck --file-to-check "%S/strings-rust/src/strings.rs" "%S/strings-utf16.check" + +newtype uint8 = x: int | 0 <= x < 255 +newtype uint7 = x: int | 0 <= x < 128 + +method Main() { + print 'H', 'e', "llo\n"; + var x8 := 'H' as uint8; + var x7 := x8 as uint7; + print x7; + var y8 := x7 as uint8; + var h := y8 as char; + expect h == 'H'; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy.expect new file mode 100644 index 000000000..03d00c088 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy.expect @@ -0,0 +1,4 @@ + +Dafny program verifier finished with 3 verified, 0 errors +'H''e'llo +72 \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Constant.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Constant.dfy.rs.check index f12da961e..323dbedba 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Constant.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Constant.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Traits.* \ No newline at end of file +// CHECK-L: Unhandled exception: System.InvalidOperationException: Operation is not valid due to the current state of the object. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/DiscoverBounds.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/DiscoverBounds.dfy.rs.check index 7ba64d0e8..9aef9ec31 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/DiscoverBounds.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/DiscoverBounds.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Unsupported:\ Cannot\ assign\ null\ value\ to\ variable.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/EqualityTypesCompile.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/EqualityTypesCompile.dfy.rs.check index 00ff9dc92..cf9f9aeea 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/EqualityTypesCompile.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/EqualityTypesCompile.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Type parameter Equality support Required not supported for type parameters.* \ No newline at end of file +// CHECK-L: error[E0369]: binary operation `==` cannot be applied to type `Rc>` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/GhostITECompilation.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/GhostITECompilation.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/GhostITECompilation.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/GhostITECompilation.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/RangeCompilation.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/RangeCompilation.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/RangeCompilation.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/RangeCompilation.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/SharedDestructorsCompile.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/SharedDestructorsCompile.dfy.rs.check index 1780a1091..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/SharedDestructorsCompile.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/SharedDestructorsCompile.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the trait bound `Rc
: DafnyType` is not satisfied \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/SiblingImports.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/SiblingImports.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/SiblingImports.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Strings.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Strings.dfy.rs.check index 84e78c23b..294d69868 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Strings.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Strings.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Char literal without unicode char enabled.* \ No newline at end of file +// CHECK: .*EmitCharBoundedPool.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/MinWindowMax.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/MinWindowMax.dfy.rs.check index 186e8dcb2..2f52477d3 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/MinWindowMax.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/MinWindowMax.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0070]: invalid left-hand side of assignment \ No newline at end of file +// CHECK-L: error[E0277]: the type `[DafnyInt]` cannot be indexed by `&DafnyInt` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/SmallestMissingNumber-functional.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/SmallestMissingNumber-functional.dfy.rs.check index 7ba64d0e8..172ffa950 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/SmallestMissingNumber-functional.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/SmallestMissingNumber-functional.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Coercion\ from\ ::std::rc::Rc>\ to\ ::std::rc::Rc>.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/StoreAndRetrieve.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/StoreAndRetrieve.dfy.rs.check index 00ff9dc92..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/StoreAndRetrieve.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/StoreAndRetrieve.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Type parameter Equality support Required not supported for type parameters.* \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/pq-intrinsic-extrinsic.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/pq-intrinsic-extrinsic.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/pq-intrinsic-extrinsic.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny2/pq-intrinsic-extrinsic.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny3/Abstemious.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny3/Abstemious.dfy.rs.check index 7ba64d0e8..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny3/Abstemious.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny3/Abstemious.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny3/CachedContainer.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny3/CachedContainer.dfy.rs.check index 00ff9dc92..a9c36a137 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny3/CachedContainer.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny3/CachedContainer.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Type parameter Equality support Required not supported for type parameters.* \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `T: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Ackermann.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Ackermann.dfy.rs.check index 3735a1af9..36fc3c768 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Ackermann.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Ackermann.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: arguments to this function are incorrect \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug107.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug107.dfy.rs.check index 3735a1af9..d3aeb8ed7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug107.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug107.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `dyn for<'a> Fn(&'a DafnyInt) -> DafnyInt: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug116.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug116.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug116.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug116.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug140.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug140.dfy.rs.check index 7ba64d0e8..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug140.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug140.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug67.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug67.dfy.rs.check deleted file mode 100644 index 692bbaa56..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug67.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0277]: the trait bound `Sequence: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug94.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug94.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Bug94.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/ExpandedGuardedness.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/ExpandedGuardedness.dfy.rs.check index 2ab0d5f70..d2c004c65 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/ExpandedGuardedness.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/ExpandedGuardedness.dfy.rs.check @@ -1 +1 @@ -//CHECK: .*Coercion.* \ No newline at end of file +//CHECK: .*Unsupported: Datatype constructor ML expects 2 arguments, but 3 were provided.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/FlyingRobots.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/FlyingRobots.dfy.rs.check index 705ca2e50..0a3c45987 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/FlyingRobots.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/FlyingRobots.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the trait bound `Rc: DafnyType` is not satisfied \ No newline at end of file +// CHECK-L: error[E0369]: binary operation `!=` cannot be applied to type `Sequence>` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Leq.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Leq.dfy.rs.check new file mode 100644 index 000000000..a3387c444 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Leq.dfy.rs.check @@ -0,0 +1 @@ +// CHECK-L: error[E0277]: the trait bound `LazyFieldWrapper>: Clone` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/McCarthy91.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/McCarthy91.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/McCarthy91.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/McCarthy91.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/NatList.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/NatList.dfy.rs.check index 7ba64d0e8..ed0f17738 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/NatList.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/NatList.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Type\ variance\ Co\ not\ supported.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression2.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression2.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression2.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression2.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression4.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression4.dfy.rs.check deleted file mode 100644 index 7ba64d0e8..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression4.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK: .*Coercion.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression6.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression6.dfy.rs.check index 3735a1af9..2f52477d3 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression6.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression6.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0277]: the type `[DafnyInt]` cannot be indexed by `&DafnyInt` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression7.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression7.dfy.rs.check index 7ba64d0e8..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression7.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression7.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression9.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression9.dfy.rs.check index 3735a1af9..2aa97fc72 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression9.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/Regression9.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `dyn for<'a> Fn(&'a DafnyInt) -> DafnyChar: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/UnionFind.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/UnionFind.dfy.rs.check index 792d0d186..7259f2ea2 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/UnionFind.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/UnionFind.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0369]: binary operation `<` cannot be applied to type `&nat` \ No newline at end of file +// CHECK-L: error[E0599]: no method named `borrow` found for struct `Rc` in the current scope \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/git-issue15.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/git-issue15.dfy.rs.check index 47ba6be61..0fbad1462 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/git-issue15.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/git-issue15.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the trait bound `Rc: DafnyTypeEq` is not satisfied \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `foo: Hash` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/git-issue4.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/git-issue4.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/git-issue4.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny4/git-issue4.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exceptions/Exceptions1Expressions.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/exceptions/Exceptions1Expressions.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exceptions/Exceptions1Expressions.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/exceptions/Exceptions1Expressions.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/FIFO.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/FIFO.dfy.rs.check deleted file mode 100644 index 692bbaa56..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/FIFO.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0277]: the trait bound `Sequence: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/LIFO.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/LIFO.dfy.rs.check deleted file mode 100644 index 692bbaa56..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/LIFO.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0277]: the trait bound `Sequence: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/xrefine2.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/xrefine2.dfy.rs.check index 3735a1af9..0cba51517 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/xrefine2.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/xrefine2.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0369]: cannot add `DafnyInt` to `nat` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/xrefine3.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/xrefine3.dfy.rs.check deleted file mode 100644 index 87cdbc387..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/exports/xrefine3.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0277]: the trait bound `Sequence: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/ghost/Comp.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/ghost/Comp.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/ghost/Comp.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/ghost/Comp.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1029.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1029.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1029.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1029.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/const.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1130.dfy.rs.check similarity index 100% rename from Source/IntegrationTests/TestFiles/LitTests/LitTest/c++/const.dfy.rs.check rename to Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1130.dfy.rs.check diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1185.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1185.dfy.rs.check index 0d3fae2af..023f6254d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1185.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1185.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Type\ parameter\ Equality\ support\ InferredRequired\ not\ supported\ for\ type\ parameters.* \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `_T0: Hash` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514.dfy.rs.check index 7ba64d0e8..7d2d31cd8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Unsupported:\ Cannot\ emit\ literal\ expression\ 0\ outside\ of\ expression\ context:\ Microsoft_dDafny_dCompilers_dBuilderSyntaxTree'1\[Microsoft_dDafny_dCompilers_dStatementContainer].* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514b.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514b.dfy.rs.check index 7ba64d0e8..7d2d31cd8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514b.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514b.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Unsupported:\ Cannot\ emit\ literal\ expression\ 0\ outside\ of\ expression\ context:\ Microsoft_dDafny_dCompilers_dBuilderSyntaxTree'1\[Microsoft_dDafny_dCompilers_dStatementContainer].* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514c.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514c.dfy.rs.check index 7ba64d0e8..7d2d31cd8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514c.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1514c.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Unsupported:\ Cannot\ emit\ literal\ expression\ 0\ outside\ of\ expression\ context:\ Microsoft_dDafny_dCompilers_dBuilderSyntaxTree'1\[Microsoft_dDafny_dCompilers_dStatementContainer].* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1553.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1553.dfy.rs.check index 6827d5975..feefa7e7f 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1553.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1553.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the trait bound `_R: DafnyType` is not satisfied \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `_R: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1604.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1604.dfy.rs.check index 54c971c04..9aef9ec31 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1604.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1604.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: Unhandled exception: System.InvalidOperationException: Unknown buildable type: NULL \ No newline at end of file +// CHECK: .*Unsupported:\ Cannot\ assign\ null\ value\ to\ variable.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1607.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1607.dfy.rs.check deleted file mode 100644 index 24900e91f..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1607.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0277]: the trait bound `&bool: DafnyPrint` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1714.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1714.dfy.rs.check index 54c971c04..f12da961e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1714.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1714.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: Unhandled exception: System.InvalidOperationException: Unknown buildable type: NULL \ No newline at end of file +// CHECK: .*Traits.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1852.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1852.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1852.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1903.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1903.dfy.rs.check deleted file mode 100644 index 0cb072c6d..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1903.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0277]: the trait bound `_T: DafnyType` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1909.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1909.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-1909.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2510.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2510.dfy.rs.check index 7ba64d0e8..ed0f17738 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2510.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2510.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Type\ variance\ Co\ not\ supported.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-258.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-258.dfy.rs.check index 84e78c23b..3d586af71 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-258.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-258.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Char literal without unicode char enabled.* \ No newline at end of file +// CHECK-L: error[E0061]: this function takes 1 argument but 0 arguments were supplied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2581.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2581.dfy.rs.check index 3735a1af9..bdbb19a60 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2581.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2581.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0369]: binary operation `==` cannot be applied to type `Sequence<_T>` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-261.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-261.dfy.rs.check index 7ba64d0e8..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-261.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-261.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-262.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-262.dfy.rs.check index 3735a1af9..0cba51517 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-262.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-262.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0369]: cannot add `DafnyInt` to `nat` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2708.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2708.dfy.rs.check deleted file mode 100644 index 186e8dcb2..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2708.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0070]: invalid left-hand side of assignment \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2726a.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2726a.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2726a.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2792.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2792.dfy.rs.check index 113294900..c6d479b29 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2792.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2792.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Cannot\ assign\ null\ value\ to\ variable.* \ No newline at end of file +// CHECK: .*Static\ functions\ with\ type\ arguments.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2173.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-332.dfy.rs.check similarity index 100% rename from Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-2173.dfy.rs.check rename to Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-332.dfy.rs.check diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-356.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-356.dfy.rs.check index 84e78c23b..7d6c2fd33 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-356.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-356.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Char literal without unicode char enabled.* \ No newline at end of file +// CHECK: .*Type name for ORDINAL \(Microsoft_dDafny_dBigOrdinalType\).* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3734.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3734.dfy.rs.check index b87489fa2..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3734.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3734.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0433]: failed to resolve: use of undeclared crate or module `num` \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-283f.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-374.dfy.rs.check similarity index 100% rename from Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-283f.dfy.rs.check rename to Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-374.dfy.rs.check diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3868.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3868.dfy.rs.check index 7ba64d0e8..ed0f17738 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3868.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3868.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Type\ variance\ Co\ not\ supported.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3956.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3956.dfy.rs.check new file mode 100644 index 000000000..b684d0589 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3956.dfy.rs.check @@ -0,0 +1 @@ +// CHECK-L: error[E0277]: the trait bound `DafnyChar: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4141.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4141.dfy.rs.check index 00ff9dc92..b0832adda 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4141.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4141.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Type parameter Equality support Required not supported for type parameters.* \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `RefCell>: Hash` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-684.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4309.dfy.rs.check similarity index 100% rename from Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-684.dfy.rs.check rename to Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4309.dfy.rs.check diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-443.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-443.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-443.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-784.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4449.dfy.rs.check similarity index 100% rename from Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-784.dfy.rs.check rename to Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4449.dfy.rs.check diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446.dfy.rs.check deleted file mode 100644 index 7ba64d0e8..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK: .*Coercion.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446a.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446a.dfy.rs.check index 7ba64d0e8..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446a.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446a.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446b.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446b.dfy.rs.check deleted file mode 100644 index 7ba64d0e8..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-446b.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK: .*Coercion.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-452.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-452.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-452.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-452c.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-452c.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-452c.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5065.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5065.dfy.rs.check index d59836f7d..efeb4f10e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5065.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5065.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0308]: mismatched types \ No newline at end of file +// CHECK-L: error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5092.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5092.dfy.rs.check index 3735a1af9..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5092.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5092.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5238.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5238.dfy.rs.check deleted file mode 100644 index bcc0c6e54..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5238.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0277]: the trait bound `Sequence: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy index 905e63e3d..1c8afbdf5 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy @@ -16,5 +16,7 @@ const someMap := method Main() { print someSet, "\n"; - print someMap, "\n"; + // Avoid non-determinism in map printing + print someMap - {2}, "\n"; + print someMap - {1}, "\n"; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy.expect index c7b79cf39..66be4a9c3 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy.expect @@ -1,2 +1,3 @@ {'D'} -map[1 := 1, 2 := 4] +map[1 := 1] +map[2 := 4] diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5285.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5469.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5469.dfy.rs.check deleted file mode 100644 index 2e0db5d53..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5469.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -CHECK: error \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5523.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5523.dfy.rs.check index e0bece18b..1bbaea9d8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5523.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5523.dfy.rs.check @@ -1 +1 @@ -CHECK: error\[E0277\]: the trait bound \ No newline at end of file +// CHECK-L: error[E0631]: type mismatch in closure arguments \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/git-issues/github-issue-2928.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-588.dfy.rs.check similarity index 100% rename from Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/git-issues/github-issue-2928.dfy.rs.check rename to Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-588.dfy.rs.check diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-686.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-686.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-686.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697b.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697b.dfy.rs.check index 7ba64d0e8..9aef9ec31 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697b.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697b.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Unsupported:\ Cannot\ assign\ null\ value\ to\ variable.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697f.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697f.dfy.rs.check index 3735a1af9..05679bb36 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697f.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697f.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `EvenCell: num_traits::sign::Signed` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697k.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697k.dfy.rs.check index 113294900..f12da961e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697k.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-697k.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Cannot\ assign\ null\ value\ to\ variable.* \ No newline at end of file +// CHECK: .*Traits.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-701.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-701.dfy.rs.check index f12da961e..323dbedba 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-701.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-701.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Traits.* \ No newline at end of file +// CHECK-L: Unhandled exception: System.InvalidOperationException: Operation is not valid due to the current state of the object. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-731.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-731.dfy.rs.check index f12da961e..323dbedba 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-731.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-731.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Traits.* \ No newline at end of file +// CHECK-L: Unhandled exception: System.InvalidOperationException: Operation is not valid due to the current state of the object. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-817a.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-817a.dfy.rs.check index 7ba64d0e8..f67d57ed0 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-817a.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-817a.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK-L: error[E0599]: no method named `borrow_mut` found for struct `DafnyInt` in the current scope \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-864rr.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-864rr.dfy.rs.check deleted file mode 100644 index 3735a1af9..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-864rr.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error: missing angle brackets in associated item path \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-a.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-a.dfy.rs.check index 245a2e0f9..50ba52337 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-a.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-a.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the trait bound `Rc: DafnyType` is not satisfied \ No newline at end of file +// CHECK-L: error[E0369]: binary operation `==` cannot be applied to type `Sequence>` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-b.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-b.dfy.rs.check index 245a2e0f9..50ba52337 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-b.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-b.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the trait bound `Rc: DafnyType` is not satisfied \ No newline at end of file +// CHECK-L: error[E0369]: binary operation `==` cannot be applied to type `Sequence>` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-c.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-c.dfy.rs.check index 245a2e0f9..50ba52337 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-c.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3766-c.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the trait bound `Rc: DafnyType` is not satisfied \ No newline at end of file +// CHECK-L: error[E0369]: binary operation `==` cannot be applied to type `Sequence>` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3871.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3871.dfy.rs.check index 186e8dcb2..86f268872 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3871.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-3871.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0070]: invalid left-hand side of assignment \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `RefCell>: Hash` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-4483.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-4483.dfy.rs.check deleted file mode 100644 index b87489fa2..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/github-issue-4483.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0433]: failed to resolve: use of undeclared crate or module `num` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Compilation.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Compilation.dfy.rs.check index 660756ad5..d3aeb8ed7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Compilation.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Compilation.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0277]: the size for values of type `(dyn for<'a> Fn(&'a DafnyInt) -> DafnyInt + 'static)` cannot be known at compilation time \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `dyn for<'a> Fn(&'a DafnyInt) -> DafnyInt: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Fold.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Fold.dfy.rs.check index 7ba64d0e8..e8341277b 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Fold.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Fold.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `dyn for<'a, 'b> Fn(&'a Rc, &'b Rc) -> Rc: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Renaming.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Renaming.dfy.rs.check index b216498bb..1bbaea9d8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Renaming.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/Renaming.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: error[E0782]: trait objects must include the `dyn` keyword \ No newline at end of file +// CHECK-L: error[E0631]: type mismatch in closure arguments \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/TreeMapSimple.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/TreeMapSimple.dfy.rs.check index 7ba64d0e8..d3aeb8ed7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/TreeMapSimple.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/hofs/TreeMapSimple.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK-L: error[E0277]: the trait bound `dyn for<'a> Fn(&'a DafnyInt) -> DafnyInt: Default` is not satisfied \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/patterns/OrPatterns.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/patterns/OrPatterns.dfy.rs.check deleted file mode 100644 index 347af0cf8..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/patterns/OrPatterns.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0277]: can't compare `&DafnyInt` with `DafnyInt` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/patterns/PatternMatching.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/patterns/PatternMatching.dfy.rs.check index 7ba64d0e8..172ffa950 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/patterns/PatternMatching.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/patterns/PatternMatching.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Coercion\ from\ ::std::rc::Rc>\ to\ ::std::rc::Rc>.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/stdlibs/StandardLibraries.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/stdlibs/StandardLibraries.dfy.rs.check index 7ba64d0e8..7d2d31cd8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/stdlibs/StandardLibraries.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/stdlibs/StandardLibraries.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Coercion.* \ No newline at end of file +// CHECK: .*Unsupported:\ Cannot\ emit\ literal\ expression\ 0\ outside\ of\ expression\ context:\ Microsoft_dDafny_dCompilers_dBuilderSyntaxTree'1\[Microsoft_dDafny_dCompilers_dStatementContainer].* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/traits/GeneralTraitsCompile.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/traits/GeneralTraitsCompile.dfy.rs.check index 54c971c04..323dbedba 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/traits/GeneralTraitsCompile.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/traits/GeneralTraitsCompile.dfy.rs.check @@ -1 +1 @@ -// CHECK-L: Unhandled exception: System.InvalidOperationException: Unknown buildable type: NULL \ No newline at end of file +// CHECK-L: Unhandled exception: System.InvalidOperationException: Operation is not valid due to the current state of the object. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Arrays.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Arrays.dfy.rs.check deleted file mode 100644 index 66736e40d..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Arrays.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK: .*MultiSelectLValue.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Collections.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Collections.dfy.rs.check deleted file mode 100644 index 3dec7f442..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Collections.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK: .*EmitIndexCollectionUpdate for multiset.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Comprehensions.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Comprehensions.dfy.rs.check deleted file mode 100644 index 323dbedba..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Comprehensions.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: Unhandled exception: System.InvalidOperationException: Operation is not valid due to the current state of the object. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/NativeNumbers.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/NativeNumbers.dfy.rs.check deleted file mode 100644 index b87489fa2..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/NativeNumbers.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: error[E0433]: failed to resolve: use of undeclared crate or module `num` \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Numbers.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Numbers.dfy.rs.check deleted file mode 100644 index fbb03b771..000000000 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodechars/comp/Numbers.dfy.rs.check +++ /dev/null @@ -1 +0,0 @@ -// CHECK-L: Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodecharsFalse/comp/NativeNumbers.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodecharsFalse/comp/NativeNumbers.dfy.rs.check index 113294900..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodecharsFalse/comp/NativeNumbers.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodecharsFalse/comp/NativeNumbers.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Cannot\ assign\ null\ value\ to\ variable.* \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodecharsFalse/git-issues/github-issue-2928.dfy.rs.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodecharsFalse/git-issues/github-issue-2928.dfy.rs.check index 113294900..d59836f7d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodecharsFalse/git-issues/github-issue-2928.dfy.rs.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/unicodecharsFalse/git-issues/github-issue-2928.dfy.rs.check @@ -1 +1 @@ -// CHECK: .*Cannot\ assign\ null\ value\ to\ variable.* \ No newline at end of file +// CHECK-L: error[E0308]: mismatched types \ No newline at end of file diff --git a/Source/TestDafny/MultiBackendTest.cs b/Source/TestDafny/MultiBackendTest.cs index f6680e499..cbc299683 100644 --- a/Source/TestDafny/MultiBackendTest.cs +++ b/Source/TestDafny/MultiBackendTest.cs @@ -394,7 +394,7 @@ private async Task RunWithCompiler(ForEachCompilerOptions options, IExecuta var diffMessage = exitCode == 0 ? AssertWithDiff.GetDiffMessage(expectedOutput, outputString) : null; if (checkFile == null && exitCode != 0) { - if (UpdateTargetExpectFile) { + if (UpdateTargetExpectFile && backend.TargetName != "dfy") { if (string.IsNullOrEmpty(IntegrationTestsRootDir)) { await output.WriteLineAsync( "DAFNY_INTEGRATION_TESTS_UPDATE_EXPECT_FILE is true but DAFNY_INTEGRATION_TESTS_ROOT_DIR is not set");